This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pylab import * | |
import numpy as np | |
n=17 | |
cmap = cm.get_cmap('magma', n) | |
for i,j in zip(range(cmap.N), np.arange(0,0.425,0.025)): | |
rgba = cmap(i) | |
# rgb2hex accepts rgb or rgba | |
print("{'value': "+str(round(j,3))+", 'color': "+"'"+ matplotlib.colors.rgb2hex(rgba)+"'"+"},") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import odc.algo | |
#Extract boolean mask | |
mask = odc.algo.enum_to_bool(ds.SCL, | |
categories=['cloud shadows', 'cloud medium probability', | |
'cloud high probability', 'thin cirrus']) | |
# Close mask to remove small holes in cloud, open mask to | |
# remove narrow false positive cloud, then dilate | |
mask = odc.algo.binary_closing(mask, 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xarray as xr | |
import numpy as np | |
import dask | |
import hdstats | |
from odc.algo import randomize | |
from odc.algo._dask import reshape_yxbt | |
from odc.geo.xr import assign_crs | |
def xr_geomad_dask(ds, **kw): | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xarray as xr | |
import numpy as np | |
import dask | |
import hdstats | |
from odc.algo import randomize, reshape_for_geomedian | |
from odc.algo._dask import reshape_yxbt | |
from datacube.utils.geometry import assign_crs | |
def xr_geomad(ds, axis='time', where=None, **kw): | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xarray as xr | |
import geopandas as gpd | |
from dea_tools.spatial import xr_rasterize | |
#read shapefile | |
mask_vector = gpd.read_file('mask.shp') | |
#import xarray ds | |
ds = xr.open_dataset('testing.nc') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datacube | |
import numpy as np | |
import xarray as xr | |
from odc.algo import xr_reproject | |
from pyproj import Proj, transform | |
from datacube.utils.geometry import assign_crs | |
from datacube.testutils.io import rio_slurp_xarray | |
from deafrica_tools.bandindices import calculate_indices | |
def common_ops(ds, era): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import datacube | |
import xarray as xr | |
import geopandas as gpd | |
from datacube.utils import geometry | |
sys.path.append('../Scripts') | |
from deafrica_datahandling import load_ard | |
from deafrica_spatialtools import xr_rasterize |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xarray as xr | |
import numpy as np | |
import joblib | |
import dask.array as da | |
from datacube.utils.geometry import assign_crs | |
from dask_ml.wrappers import ParallelPostFit | |
def predict_xr(model, | |
input_xr, | |
chunk_size=None, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import xarray as xr | |
from scipy import stats | |
def significance_tests(xarray_a, xarray_b, t_test=False, levene_test=False, | |
equal_variance = False, nan_policy= 'omit', mask_not_sig = False, | |
level_of_sig = 0.05, center='mean'): | |
""" | |
This function operates on a per-pixel basis and contains two types of significance tests: | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cartopy.crs as ccrs | |
def plot_towns(ax, lats, lons, resolution='10m', transform=ccrs.PlateCarree(), zorder=3): | |
""" | |
This function will download the 'populated_places' shapefile from | |
NaturalEarth, trim the shapefile based on the limits of the provided | |
lat & long coords, and then plot the locations and names of the towns | |
on a given GeoAxes. | |
NewerOlder