Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def load(self,files,gcsBucket='',eeAsset=''):
if gcsBucket[-1] != '/':
gcsBucket += '/'
if eeAsset[-1] != '/':
eeAsset += '/'
for f in files:
fName = os.path.basename(f)
utils.push_to_gcs(f,gcsBucket)
bso = gcsBucket + fName
tstr = fName.split('.')[3]
t = '{0}-{1}-{2}:{3}:00'.format(tstr[:4],tstr[4:6],tstr[6:11],tstr[11:])
utils.push_to_gee(bso,eeAsset,properties={'time_start':t})
return
def load(self, files, gcsBucket='', eeAsset=''):
if gcsBucket[-1] != '/':
gcsBucket += '/'
if eeAsset[-1] != '/':
eeAsset += '/'
for f in files:
fName = os.path.basename(f)
utils.push_to_gcs(f, gcsBucket)
bso = gcsBucket + fName
tstr = fName.split('.')[3]
t = '{0}-{1}-{2}:{3}:00'.format(tstr[:4],
tstr[4:6], tstr[6:11], tstr[11:])
utils.push_to_gee(bso, eeAsset, properties={'time_start': t})
return
def load(self, files, gcsBucket='', eeAsset=''):
if gcsBucket[-1] != '/':
gcsBucket += '/'
if eeAsset[-1] != '/':
eeAsset += '/'
for f in files:
fName = os.path.basename(f)
utils.push_to_gcs(f, gcsBucket)
bso = gcsBucket + fName
tstr = fName.split('.')[3]
t = '{0}-{1}-{2}:{3}:00'.format(tstr[:4],
tstr[4:6], tstr[6:11], tstr[11:])
utils.push_to_gee(bso, eeAsset, properties={'time_start': t})
return
def load(self,files,gcsBucket='',eeAsset=''):
if gcsBucket[-1] != '/':
gcsBucket += '/'
if eeAsset[-1] != '/':
eeAsset += '/'
for f in files:
fName = os.path.basename(f)
utils.push_to_gcs(f,gcsBucket)
bso = gcsBucket + fName
tstr = fName.split('.')[3]
t = '{0}-{1}-{2}:{3}:00'.format(tstr[:4],tstr[4:6],tstr[6:11],tstr[11:])
utils.push_to_gee(bso,eeAsset,properties={'time_start':t})
return
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),
geometry= img.geometry(),
scale= 10,
i = ee.Number(iteration)
sim = geeutils.globalOtsu(self.downscaled,target_date,self.region,seed=i,**kwargs)
return sim.And(hand.lt(30))
tDate = ee.Date(target_date)
if probablistic:
iters = ee.List.sequence(0,nIters-1)
sims = ee.ImageCollection(iters.map(_threholdWrapper))
probs = sims.sum().divide(nIters).rename(['probability'])
water = probs.select(['probability']).gt(probTreshold).rename('water')
mapResult = water.addBands(probs.multiply(10000).uint16())
else:
mapResult = geeutils.globalOtsu(self.downscaled,target_date,self.region,**kwargs)\
.And(hand.lt(30))
return mapResult
def _threholdWrapper(iteration):
i = ee.Number(iteration)
sim = geeutils.globalOtsu(
self.downscaled, target_date, self.region, seed=i, **kwargs)
return sim.And(hand.lt(30))
def __init__(self, *args, assetid='MODIS/006/MOD09GA', **kwargs):
super(Modis, self).__init__(*args, assetid=assetid, **kwargs)
if self.useQa:
self.collection = self.collection.map(self._qa)
self.collection = self.collection\
.select(BANDREMAP.get('modis'), BANDREMAP.get('new'))\
.map(geeutils.addIndices)
self.clipToRegion(inplace=True)
return
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),
geometry= img.geometry(),
scale= 10,
bestEffort= True
)).toImage()
overThresh = img.gte(z99)
K = overThresh.reduceNeighborhood(ee.Reducer.sum(), targetKernel, None, True)
retainPixel = K.gte(Tk)
xHat = geeutils.powerToDb(img.updateMask(retainPixel).unmask(mmse))
return ee.Image(xHat).rename(bandNames)
def __init__(self,*args,**kwargs):
super(Modis, self).__init__(*args,**kwargs)
self.collection = self.collection.map(self._qaMask)\
.select(BANDREMAP.get('modis'),BANDREMAP.get('new'))\
.map(self.clip)\
.map(geeutils.addIndices)
return