Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VV'))
return
def _qa(self, img):
angles = img.select('angle')
return img.updateMask(angles.lt(45).And(angles.gt(31)))
def waterMap(self, target_date, **kwargs):
mapResult = thresholding.bmaxOtsu(
self.collection, target_date, self.region, **kwargs)
return mapResult
class Atms(hfCollection):
def __init__(self, *args, **kwargs):
super(Atms, self).__init__(*args, useQa=False,**kwargs)
return
def _qa(self, img):
return
def extract(self, date, region, credentials, outDir='./', gridding_radius=50000):
files = fetch.atms(credentials, startTime=date,
endTime=None, region=region, outDir=outDir)
geotiffs = list(
map(lambda x: preprocess.atms(x, gridding_radius), files))
return geotiffs
def load(self, files, gcsBucket='', eeAsset=''):
inImage = self.collection.mean().divide(10000)
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, assetid='NOAA/VIIRS/001/VNP09GA', **kwargs):
super(Viirs, self).__init__(*args, assetid=assetid, **kwargs)
self.collection = self.collection\
.select(BANDREMAP.get('viirs'), BANDREMAP.get('new'))\
.map(geeutils.addIndices)
self.clipToRegion(inplace=True)
return
def _qa(self, img):
cloudBit = int(math.pow(2, 2))
shadowBit = int(math.pow(2, 3))
snowBit = int(math.pow(2, 5))
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 Landsat8(hfCollection):
def __init__(self, *args, assetid='LANDSAT/LC08/C01/T1_SR', **kwargs):
super(Landsat8, self).__init__(*args, assetid=assetid, **kwargs)
if self.useQa:
self.collection = self.collection.map(self._qa)
self.collection = self.collection\
.select(BANDREMAP.get('landsat'), BANDREMAP.get('new'))\
.map(geeutils.addIndices)
return
def waterMap(self, target_date, **kwargs):
mapResult = thresholding.bmaxOtsu(
self.collection, target_date, self.region, **kwargs)
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, 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
def _qa(self, img):
cloudBit = int(math.pow(2, 10))
outCls = self.copy()
outCls.collection = func(self.collection, **kwargs)
return outCls
def merge(self,collection,interleave=False,inplace=False):
merged = self.collection.merge(collection.collection)
if inplace:
self.collection = merged
return
else:
outCls = self.copy()
outCls.collection = merged
return outCls
class Sentinel1(hfCollection):
def __init__(self, *args, assetid='COPERNICUS/S1_GRD', **kwargs):
super(Sentinel1, self).__init__(*args,assetid=assetid, **kwargs)
self.collection = self.collection\
.filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VV'))
return
def _qa(self, img):
angles = img.select('angle')
return img.updateMask(angles.lt(45).And(angles.gt(31)))
def waterMap(self, target_date, **kwargs):
mapResult = thresholding.bmaxOtsu(
self.collection, target_date, self.region, **kwargs)
return mapResult
def _qa(self, img):
cloudBit = int(math.pow(2, 5))
shadowBit = int(math.pow(2, 3))
snowBit = int(math.pow(2, 4))
qaCloud = img.select('pixel_qa').bitwiseAnd(cloudBit).eq(0)
qaShadow = img.select('pixel_qa').bitwiseAnd(shadowBit).eq(0)
qaSnow = img.select('pixel_qa').bitwiseAnd(snowBit).eq(0)
mask = qaCloud.And(qaShadow).And(qaSnow)
return img.updateMask(mask)
class Sentinel2(hfCollection):
def __init__(self, *args, assetid='COPERNICUS/S2_SR', **kwargs):
super(Sentinel2, self).__init__(*args,assetid=assetid, **kwargs)
if self.useQa:
self.collection = self.collection.map(self._qa)
self.collection = self.collection\
.select(BANDREMAP.get('sen2'), BANDREMAP.get('new'))\
.map(geeutils.addIndices)
return
def _qa(self, img):
sclImg = img.select('SCL') # Scene Classification Map
mask = sclImg.gte(4).And(sclImg.lte(6))
return img.updateMask(mask)