Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
class Landsat(hfCollection):
def __init__(self,*args,**kwargs):
super(Landsat, self).__init__(*args,**kwargs)
self.collection = self.collection.map(self._qaMask)\
.select(BANDREMAP.get('landsat'),BANDREMAP.get('new'))\
.map(geeutils.addIndices)
return
def _qaMask(self,img):
qaCloud = geeutils.extractBits(img.select('pixel_qa'),5,5,'qa').neq(1)
qaShadow = geeutils.extractBits(img.select('pixel_qa'),3,3,'qa').neq(1)
mask = qaCloud.And(qaShadow)
t = ee.Date(img.get('system:time_start'))
nDays = t.difference(INITIME,'day')
time = ee.Image(nDays).int16().rename('time')
self.iniTime = time_start
self.endTime = time_end
self.id = collectionid
self.collection = ee.ImageCollection(self.id)\
.filterBounds(self.region)\
.filterDate(self.iniTime,self.endTime)
return
def clip(self,img):
return img.clip(self.region)
class Sentinel1(hfCollection):
def __init__(self,*args,**kwargs):
super(Sentinel1, self).__init__(*args,**kwargs)
self.collection = self.collection\
.filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VV'))\
.select('VV')
return
def waterMap(self,target_date,**kwargs):
mapResult = geeutils.bootstrapOtsu(self.collection,target_date,**kwargs)
return mapResult
def _maskEdges(self,img):
if probablistic:
iters = ee.List.sequence(0,nIters-1)
sims = ee.ImageCollection(iters.map(_downscaleWrapper))
probs = sims.sum().divide(nIters).rename(['probability','error'])
water = probs.select(['probability'],['water']).gt(probTreshold)
mapResult = water.addBands(probs.multiply(10000).uint16())
else:
mapResult = downscale.bathtub(inImage,hand,permanent)
return mapResult
class Viirs(hfCollection):
def __init__(self,*args,**kwargs):
super(Viirs, self).__init__(*args,**kwargs)
self.collection = self.collection.map(self._qaMask)\
.select(BANDREMAP.get('viirs'),BANDREMAP.get('new'))\
.map(self.clip)\
.map(geeutils.addIndices)
return
def _qaMask(self,img):
viewing = img.select('SensorZenith').abs().multiply(0.01).lt(45)
clouds = geeutils.extractBits(img.select('QF1'),2,3,'cloud_qa').lte(2)
shadows = geeutils.extractBits(img.select('QF2'),3,3,'shadow_qa').eq(0)
aerosols = geeutils.extractBits(img.select('QF2'),4,4,'aerosol_qa').eq(0)
snows = geeutils.extractBits(img.select('QF2'),5,5,'snow_qa').eq(0)
return
def waterMap(self,target_date,**kwargs):
mapResult = geeutils.bootstrapOtsu(self.collection,target_date,**kwargs)
return mapResult
def _maskEdges(self,img):
angles = img.select('angle')
return img.updateMask(angles.lt(45).And(angles.gt(31)))
class Atms(hfCollection):
def __init__(self,*args,**kwargs):
super(Atms, self).__init__(*args,**kwargs)
return
def extract(self,date,region,outdir='./',creds=None,gridding_radius=50000):
files = fetch.atms(date,region,outdir,creds)
geotiffs = list(map(lambda x: preprocess.atms(x,gridding_radius), files))
return geotiffs
def load(self,files,gcsBucket='',eeAsset=''):
if gcsBucket[-1] != '/':
gcsBucket += '/'
if eeAsset[-1] != '/':
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
class Modis(hfCollection):
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
def _qaMask(self,img):
viewing = img.select('SensorZenith').abs().multiply(0.01).lt(45)
clouds = geeutils.extractBits(img.select('state_1km'),10,10,'cloud_qa').neq(1)
shadows = geeutils.extractBits(img.select('state_1km'),2,2,'shadow_qa').eq(0)
aerosols = geeutils.extractBits(img.select('state_1km'),6,7,'aerosol_qa').neq(0)
snows = geeutils.extractBits(img.select('state_1km'),15,15,'snow_qa').eq(0)
return
def _qaMask(self,img):
qaCloud = geeutils.extractBits(img.select('pixel_qa'),5,5,'qa').neq(1)
qaShadow = geeutils.extractBits(img.select('pixel_qa'),3,3,'qa').neq(1)
mask = qaCloud.And(qaShadow)
t = ee.Date(img.get('system:time_start'))
nDays = t.difference(INITIME,'day')
time = ee.Image(nDays).int16().rename('time')
return img.updateMask(mask).addBands(time).uint16()
class Sentinel2(hfCollection):
def __init__(self,*args,**kwargs):
super(Sentinel2, self).__init__(*args,**kwargs)
self.collection = self.collection.map(self._qaMask)\
.select(BANDREMAP.get('sen2'),BANDREMAP.get('new'))\
.map(geeutils.addIndices)
return
def _qaMask(self,img):
sclImg = img.select('SCL') # Scene Classification Map
mask = sclImg.gte(4).And(sclImg.lte(6))
t = ee.Date(img.get('system:time_start'))
nDays = t.difference(INITIME,'day')
time = ee.Image(nDays).int16().rename('time')
return img.updateMask(mask).addBands(time).uint16()