def __init__(self, **kw): logger = daiquiri.getLogger(__name__, subsystem="algorithms") self.logger = logger self._name = "NBWP" try: if not kw.has_key("season"): self.coll_t_y = EEImageCollection( kw["src_coll"].replace("AGBP", "T") ) else: self.season = kw["season"] self.coll_t_y = EEImageCollection( kw["src_coll"].replace("AGBP_S", "T_D") ) self.coll_agbp_s = EEImageCollection( kw["src_coll"] ) except EEException as e: self.logger.error( "Failed to handle Google Earth Engine object", exc_info=True ) raise # parallelize items computation for input component try: self.logger.debug( "Named arguments kw are =====> {0}".format(kw) ) self.logger.info( "==========INIT Common Algorithm for {0}===========".format( kw["src_coll"] ) ) # @TODO see why dask compute no longer works # colls = [self._inputColl( # self, # coll_id # ) for coll_id in [kw["src_coll"]]] # dask.compute(colls) # import ipdb; ipdb.set_trace() colls = [self._inputColl(kw["src_coll"])] self._inputs = colls except (EEException, KeyError) as (eee, exc): if eee: self.logger.error( "Failed to handle Google Earth Engine object", exc_info=True ) elif exc: self.logger.error( "Fail to handle key from dictionary", exc_info=True ) raise
def _joinFilteredETI(self, et, i): time_filter = EEFilter.equals(leftField="system:time_start", rightField="system:time_start") join = ee.Join.inner() joinCollETI = EEImageCollection(join.apply(et, i, time_filter)) return joinCollETI.map(lambda element: EEImage.cat( element.get('primary'), element.get('secondary'))).sort( 'system:time_start')
class GBWP(Marmee): def __init__(self, **kw): logger = daiquiri.getLogger(__name__, subsystem="algorithms") self.logger = logger self._name = "GBWP" try: if "season" not in kw: self.coll_aeti_y = EEImageCollection(kw["src_coll"].replace( "AGBP", "AETI")) self.season = None else: self.season = kw["season"] self.coll_aeti_y = EEImageCollection(kw["src_coll"].replace( "AGBP_S", "AETI_D")) self.coll_agbp_s = EEImageCollection(kw["src_coll"]) if "level" in kw: self.level = kw["level"] except EEException as e: self.logger.error("Failed to handle Google Earth Engine object", exc_info=True) raise # parallelize items computation for input component try: self.logger.debug("Named arguments kw are =====> {0}".format(kw)) self.logger.info( "==========INIT Common Algorithm for {0}===========".format( kw["src_coll"])) # @TODO see why dask compute no longer works # colls = [self._inputColl( # self, # coll_id # ) for coll_id in [kw["src_coll"]]] # dask.compute(colls) colls = [self._inputColl(kw["src_coll"])] self._inputs = colls except (EEException, KeyError) as (eee, exc): if eee: self.logger.error( "Failed to handle Google Earth Engine object", exc_info=True) elif exc: self.logger.error("Fail to handle key from dictionary", exc_info=True) raise # temporal filter for input component try: self.year = kw["year"] self.config = dict(export=kw["to_asset"], intermediate=kw["intermediate_outputs"], assetid=kw["dst_asset"], ndvalue=kw["nodatavalue"]) if self.season: self.config.update(season=self.season) if self.level: self.config.update(level=self.level) if self.level in ["L2", "L3"]: try: if kw["area_code"] and (not kw["area_code"] == "NA"): self.area = kw["area_code"] else: self.area = None except KeyError: raise Exception("You have to provide an area code!") self.config.update(area=self.area) except KeyError as exc: self.logger.error("Error with dictionary key", exc_info=True) raise annualrule = self._inputAnnualTemporalRule(int(self.year)) temporal_filter = self._inputTemporalFilter("temporal", annualrule) self._filters = temporal_filter # initialize outputs self._outputs = [] self.errors = {} # Create dicts of EE ImageCollection for input component flt_dict = {} inpt_dict = {} config_dict = {} self.logger.debug( "Received inputs in STAC format are =====>\n{0}".format( self.inputs)) for inpt in self.inputs: self.logger.debug("Stac object {0} is of type {1}".format( inpt.stacobject.id, inpt.stacobject.type)) if inpt.stacobject.type == "FeatureCollection": try: inpt_dict["collection"] = EEImageCollection( inpt.stacobject.id) self.logger.debug( "ImageCollection info for {0} is =====>\n{1}".format( inpt.stacobject.id, inpt_dict["collection"].getInfo())) except EEException as eee: self.logger.error( "Failed to create ImageCollection {0}".format( inpt.stacobject.id), exc_info=True) raise # it works for just one filter with only one temporal rule self.logger.debug("Received filters are =====>\n{0}".format( self.filters.json)) for rul in self.filters.rules: for ext in rul.rule: if ext['type'] in 'temporal': date_range = ext['daterange'] flt_dict['temporal_filter'] = self._eeDaterangeObj( **date_range) self.coll = inpt_dict self.filter = flt_dict self.config.update(config_dict)
class AETI(Marmee): def __init__(self, **kw): logger = daiquiri.getLogger(__name__, subsystem="algorithms") self.logger = logger self._name = "AETI" # parallelize items computation for ETI inputs try: self.logger.info("==========INIT AETI Algorithm===========") self.logger.debug("Named arguments kw =====> {0}".format(kw)) colls = [ self._inputColl(coll_id).compute() for coll_id in [kw["collE"], kw["collT"], kw["collI"]] ] self._inputs = colls except (EEException, KeyError) as (eee, exc): if eee: self.logger.error( "Failed to handle Google Earth Engine object", exc_info=True) elif exc: self.logger.error("Fail to handle key from dictionary", exc_info=True) raise # temporal filter for AETI try: self.year = kw["year"] if kw["area_code"] and (not kw["area_code"] == "NA"): self.area = kw["area_code"] else: self.area = None self.config = dict(export=kw["to_asset"], intermediate=kw["intermediate_outputs"], assetids=kw["dst_assets"]) except KeyError as exc: self.logger.error("Fail to handle key from dictionary", exc_info=True) raise annualrule = self._inputAnnualTemporalRule(int(self.year)) temporal_filter = self._inputTemporalFilter("temporal", annualrule) self._filters = temporal_filter # initialize outputs self._outputs = [] self.errors = {} # Create a dict of EE ImageCollection for ETI flt_dict = {} inpt_dict = {} config_dict = {} self.logger.debug( "Received inputs in STAC format are =====>\n{0}".format( self.inputs)) for inpt in self.inputs: self.logger.debug("Item {0} is of type {1}".format( inpt.stacobject.id, inpt.stacobject.type)) if inpt.stacobject.type == "FeatureCollection": try: if "E_D" in inpt.stacobject.id: inpt_dict["cE"] = EEImageCollection(inpt.stacobject.id) self.logger.debug( "ImageCollection info for {0} is =====>\n{1}". format(inpt.stacobject.id, inpt_dict["cE"].getInfo())) elif "T_D" in inpt.stacobject.id: inpt_dict["cT"] = EEImageCollection(inpt.stacobject.id) self.logger.debug( "ImageCollection info for {0} is =====>\n{1}". format(inpt.stacobject.id, inpt_dict["cT"].getInfo())) elif "I_D" in inpt.stacobject.id: inpt_dict["cI"] = EEImageCollection(inpt.stacobject.id) self.logger.debug( "ImageCollection info for {0} is =====>\n{1}". format(inpt.stacobject.id, inpt_dict["cI"].getInfo())) except EEException as eee: self.logger.error( "Failed to create ImageCollection {0}".format( inpt.stacobject.id), exc_info=True) raise # it works for just one filter with only one temporal rule self.logger.debug("Received filters are =====>\n{0}".format( self.filters.json)) for rul in self.filters.rules: for ext in rul.rule: if ext['type'] in 'temporal': date_range = ext['daterange'] flt_dict['temporal_filter'] = self._eeDaterangeObj( **date_range) self.coll = inpt_dict self.filter = flt_dict self.config.update(config_dict)