Skip to content

Instantly share code, notes, and snippets.

View cbur24's full-sized avatar

Chad Burton cbur24

View GitHub Profile
@cbur24
cbur24 / xr_geomad_dask.py
Last active February 9, 2024 01:32
Same as "xr_geomad.py" but optimized for dask
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):
"""
@cbur24
cbur24 / cloud_buffering.py
Last active March 2, 2021 02:48
Improve the Sentinel-2 cloud mask using morpholigical operations
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)
@cbur24
cbur24 / hex_codes_for_colour_ramp.py
Created January 21, 2022 03:25
Print hex codes for matplotlib colour ramps
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)+"'"+"},")