Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@decorators.carryMetadata
def applyEdge(img):
# get preliminary water
binary = img.lt(initialThreshold).rename('binary');
# get canny edges
canny = ee.Algorithms.CannyEdgeDetector(binary,canny_threshold,canny_sigma)
# process canny edges
connected = canny.mask(canny).lt(canny_lt).connectedPixelCount(connected_pixels, True)
edges = connected.gte(edge_length)
edgeBuffer = edges.focal_max(smooth_edges, 'square', 'meters')
# mask out areas to get histogram for Otsu
histogram_image = img.updateMask(edgeBuffer)
histogram = histogram_image.reduceRegion(ee.Reducer.histogram(255, 2)\
.combine('mean', None, True)\
@decorators.carryMetadata
def addIndices(img):
ndvi = img.normalizedDifference(['nir','red']).rename('ndvi')
mndwi = img.normalizedDifference(['green','swir2']).rename('mndwi')
nwi = img.expression('((b-(n+s+w))/(b+(n+s+w))*100)',{
'b':img.select('blue'),
'n':img.select('nir'),
's':img.select('swir1'),
'w':img.select('swir2')
}).rename('nwi')
aewinsh = img.expression('4.0 * (g-s) - ((0.25*n) + (2.75*w))',{
'g':img.select('green'),
's':img.select('swir1'),
'n':img.select('nir'),
'w':img.select('swir2')
}).rename('aewinsh')
aewish = img.expression('b+2.5*g-1.5*(n+s)-0.25*w',{
@decorators.carryMetadata
def apply_starfm(img):
t = ee.Date(img.get('system:time_start'))
Tijk = img.select('time').subtract(base.select('time_first'))
Sijk = img.subtract(slv).abs().convolution(Dijk)\
.rename(bandList)
Cijk = Sijk.multiply(Tijk).convolve(Dijk)
Wijk = one.divide(Cijk).divide(one.divide(Cijk)\
.convolve(Dijk))
nBands = ee.Number(base.bandNames().length())
expected = ee.Number(len(bandList))
outImg = ee.Algorithms.If(nBands.neq(expected), None,
@decorators.carryMetadata
def applyFilter(img):
img = geeutils.dbToPower(img)
# MMSE estimator
mmseMask = img.gte(a1).Or(img.lte(a2))
mmseIn = img.updateMask(mmseMask)
oneImg = ee.Image(1)
z = mmseIn.reduceNeighborhood(ee.Reducer.mean(), kernel, None, True)
varz = mmseIn.reduceNeighborhood(ee.Reducer.variance(), kernel)
varx = (varz.subtract(z.abs().pow(2).multiply(eta))).divide(oneImg.add(eta))
b = varx.divide(varz)
mmse = oneImg.subtract(b).multiply(z.abs()).add(b.multiply(mmseIn))
# workflow
z99 = ee.Dictionary(img.reduceRegion(
reducer= ee.Reducer.percentile([99], None, 255, 0.001, 1e6),