def ndfi_map(): """ return map_id for specified ndfi range date if date range is not specified only ndfi from 1st of the month are computed returns a json with mapid and token an example request look like this /api/v0/ndfi&starttime=1254305000000&endtime=1256900200000 starttime and endtime are timestamp in milliseconds """ # parse params now = datetime.now() starttime = request.args.get('starttime', first_of_current_month()) endtime = request.args.get('endtime', timestamp(now)) try: starttime = float(starttime) endtime = float(endtime) except ValueError: # try to parse as normal format (not timestamp) starttime = timestamp(parse(request.args.get('starttime'))) endtime = timestamp(parse(request.args.get('endtime'))) ee_resource = 'MOD09GA' ndfi = NDFI(ee_resource, past_month_range(datetime.fromtimestamp(starttime/1000)), (starttime, endtime)) ne = amazon_bounds[0] sw = amazon_bounds[1] polygons = [[ (sw[1], sw[0]), (sw[1], ne[0]), (ne[1], ne[0]), (ne[1], sw[0]) ]] #return jsonify(ndfi.mapid()) return jsonify(ndfi.ndfi_change_value(polygons))
def as_dict(self): return { 'id': str(self.key()), 'fusion_tables_id': str(self.key().id()), 'start': timestamp(self.start), 'end': timestamp(self.end or date.today()), 'finished': self.finished, 'cells_finished': self.cells_finished(), 'total_cells': self.total_cells, 'str': self.start.strftime("%Y-%b-%d"), 'str_end': (self.end or date.today()).strftime("%Y-%b-%d"), 'assetid': self.assetid, 'deforestation': self.deforestation, 'degradation': self.degradation }
def AuthenticatedGet(self, org, event): filename = all_event_timeless_filename(event) bucket_path = BUCKET_NAME + '/' + filename try: file_stat = cloudstorage.stat(bucket_path) except cloudstorage.NotFoundError: self.abort(404) # rewrite filename to include timestamp custom_timestamp = timestamp( datetime.datetime.utcfromtimestamp(file_stat.st_ctime)) filename_to_serve = file_stat.filename.replace( '.csv', '-%s.csv' % custom_timestamp ) # serve the file as an attachment, forcing download gcs_fd = cloudstorage.open(bucket_path) if file_stat.content_type: self.response.headers['Content-Type'] = file_stat.content_type self.response.headers['Content-Disposition'] = ( str('attachment; filename="%s"' % filename_to_serve) ) self.response.write(gcs_fd.read())
def _MakeMosaic(self, period): return { "creator": CALL_SCOPE + '/com.google.earthengine.examples.sad.MakeMosaic', "args": ["MODIS/MOD09GA","MODIS/MOD09GQ", {'type':'FeatureCollection','table_id':1868251, 'mark': str(timestamp())}, #this number is an special fusion tables id but i have no idea what it is supposed to do period['start'], period['end']] }
def get_stats_for_table(self, report_id, frozen_image, table_id, key_name='name'): return self._execute_cmd("/value", { "image": json.dumps({ "creator":CALL_SCOPE + "/com.google.earthengine.examples.sad.GetStats", "args":[ { "creator": CALL_SCOPE + "/com.google.earthengine.examples.sad.HistoricalFreeze", "args":[ frozen_image, { "table_id": int(settings.FT_TABLE_ID), "type":"FeatureCollection", 'mark': str(timestamp()), "filters":[ { "metadata":"report_id", "equals": int(report_id) } ] }, "type" ], "type":"Image", }, { "table_id": int(table_id), "type":"FeatureCollection" }, "name" ] }), "fields": "classHistogram" })
def as_dict(self): return { 'id': str(self.key()), 'msg': self.msg, 'author': self.added_by.nickname(), 'date': timestamp(self.added_on) }
def as_dict(self): return { 'id': str(self.key()), 'start': timestamp(self.start), #'end': timestamp(self.end), 'finished': self.finished, 'cells_finished': self.cells_finished(), 'total_cells': self.total_cells, 'str': self.start.strftime("%Y-%b-%d"), 'assetid': self.assetid }
def as_dict(self): return { 'id': str(self.key()), 'key': str(self.key()), 'cell': str(self.cell.key()), 'paths': json.loads(self.geo), 'type': self.type, 'fusion_tables_id': self.fusion_tables_id, 'added_on': timestamp(self.added_on), 'added_by': str(self.added_by.nickname()) }
def mapid2_cmd(self, asset_id, polygon=None, rows=5, cols=5): year_msec = 1000 * 60 * 60 * 24 * 365 month_msec = 1000 * 60 * 60 * 24 * 30 six_months_ago = self.work_period['end'] - month_msec * 6 one_month_ago = self.work_period['end'] - month_msec last_month = time.gmtime(int(six_months_ago / 1000))[1] last_year = time.gmtime(int(six_months_ago / 1000))[0] previous_month = time.gmtime(int(one_month_ago / 1000))[1] previous_year = time.gmtime(int(one_month_ago / 1000))[0] work_month = self.getMidMonth(self.work_period['start'], self.work_period['end']) work_year = self.getMidYear(self.work_period['start'], self.work_period['end']) end = "%04d%02d" % (work_year, work_month) start = "%04d%02d" % (last_year, last_month) previous = "%04d%02d" % (previous_year, previous_month) start_filter = [{'property':'compounddate','greater_than':start},{'property':'compounddate','less_than':end}] deforested_asset = self.paint_deforestation(asset_id, work_month, work_year) # 1zqKClXoaHjUovWSydYDfOvwsrLVw-aNU4rh3wLc was 1868251 json_cmd = {"creator":CALL_SCOPE + "/com.google.earthengine.examples.sad.GetNDFIDelta","args": [ self.last_period['start'] - year_msec, self.last_period['end'], self.work_period['start'], self.work_period['end'], "MODIS/MOD09GA", "MODIS/MOD09GQ", {'type':'FeatureCollection','id': 'ft:1zqKClXoaHjUovWSydYDfOvwsrLVw-aNU4rh3wLc', 'mark': str(timestamp()), 'filter':start_filter}, {'type':'FeatureCollection','id': 'ft:1zqKClXoaHjUovWSydYDfOvwsrLVw-aNU4rh3wLc', 'mark': str(timestamp()), 'filter':[{"property":"month","equals":work_month},{"property":"year","equals":work_year}]}, {'type':'FeatureCollection','table_id': 4468280, 'mark': str(timestamp()), 'filter':[{"property":"Compounddate","equals":int(previous)}]}, {'type':'FeatureCollection','table_id': 4468280, 'mark': str(timestamp()), 'filter':[{"property":"Compounddate","equals":int(end)}]}, deforested_asset, polygon, rows, cols] } logging.info("GetNDFIDelta") logging.info(json_cmd) return json_cmd
def _RGB_image_command(self, period): """ commands for RGB image """ filter = self._krig_filter(period) return { "image": json.dumps({ "creator": KRIGING, "args": [ self._MakeMosaic(period),{'type':'FeatureCollection','table_id':4468280, 'filter':filter,'mark':str(timestamp())} ] }), "bands": 'sur_refl_b01,sur_refl_b04,sur_refl_b03', "gain": 0.1, "bias": 0.0, "gamma": 1.6 };
def mapid2_cmd(self, asset_id, polygon=None, rows=10, cols=10): return {"creator":CALL_SCOPE + "/com.google.earthengine.examples.sad.GetNDFIDelta","args": [ self.last_perdiod['start'], self.last_perdiod['end'], self.work_period['start'], self.work_period['end'], "MODIS/MOD09GA", "MODIS/MOD09GQ", {'type':'FeatureCollection','table_id': 1868251, 'mark': str(timestamp())}, {"creator":CALL_SCOPE + "/com.google.earthengine.examples.sad.ProdesImage","args":[asset_id]}, polygon, rows, cols] }
def _NDFI_image(self, period, long_span=0): """ given image list from EE, returns the operator chain to return NDFI image """ filter = self._krig_filter(period) return { "creator": CALL_SCOPE + '/com.google.earthengine.examples.sad.NDFIImage', "args": [{ "creator": CALL_SCOPE + '/com.google.earthengine.examples.sad.UnmixModis', "args": [{ "creator": KRIGING, "args": [ self._MakeMosaic(period, long_span), {'type':'FeatureCollection','table_id':4468280, 'filter':filter,'mark':str(timestamp())} ] }] }] }
def as_dict(self): #latest = self.latest_polygon() t = 0 by = 'Nobody' """ if latest: t = timestamp(latest.added_on) by = latest.added_by.nickname() """ try: self.key() note_count = self.note_set.count() t = timestamp(self.last_change_on) if self.last_change_by: by = self.last_change_by.nickname() children_done = self.children_done() except: note_count = 0 t = 0 children_done = 0 return { #'key': str(self.key()), 'id': self.external_id(), 'z': self.z, 'x': self.x, 'y': self.y, 'report_id': str(self.report.key()), 'ndfi_low': self.ndfi_low, 'ndfi_high': self.ndfi_high, 'ndfi_change_value': self.ndfi_change_value, 'compare_view': self.compare_view, 'map_one_layer_status': self.map_one_layer_status, 'map_two_layer_status': self.map_two_layer_status, 'map_three_layer_status': self.map_three_layer_status, 'map_four_layer_status': self.map_four_layer_status, 'done': self.done, 'latest_change': t, 'added_by': by, 'polygon_count': self.polygon_count(), 'note_count': note_count, 'children_done': children_done, 'blocked': self.external_id() in CELL_BLACK_LIST }
def as_dict(self): #latest = self.latest_polygon() t = 0 by = 'Nobody' """ if latest: t = timestamp(latest.added_on) by = latest.added_by.nickname() """ try: self.key() note_count = self.note_set.count() t = timestamp(self.last_change_on) if self.last_change_by: by = self.last_change_by.nickname() children_done = self.children_done() except: note_count = 0 t = 0 children_done = 0 return { #'key': str(self.key()), 'id': self.external_id(), 'z': self.z, 'x': self.x, 'y': self.y, 'report_id': str(self.report.key()), 'ndfi_low': self.ndfi_low, 'ndfi_high': self.ndfi_high, 'ndfi_change_value': self.ndfi_change_value, 'compare_view':self.compare_view, 'map_one_layer_status': self.map_one_layer_status, 'map_two_layer_status': self.map_two_layer_status, 'map_three_layer_status': self.map_three_layer_status, 'map_four_layer_status': self.map_four_layer_status, 'done': self.done, 'latest_change': t, 'added_by': by, 'polygon_count': self.polygon_count(), 'note_count': note_count, 'children_done': children_done, 'blocked': self.external_id() in CELL_BLACK_LIST }
def AuthenticatedGet(self, org, event): filename = all_event_timeless_filename(event) bucket_path = BUCKET_NAME + '/' + filename try: file_stat = cloudstorage.stat(bucket_path) except cloudstorage.NotFoundError: self.abort(404) # rewrite filename to include timestamp custom_timestamp = timestamp( datetime.datetime.utcfromtimestamp(file_stat.st_ctime)) filename_to_serve = file_stat.filename.replace( '.csv', '-%s.csv' % custom_timestamp) # serve the file as an attachment, forcing download gcs_fd = cloudstorage.open(bucket_path) if file_stat.content_type: self.response.headers['Content-Type'] = file_stat.content_type self.response.headers['Content-Disposition'] = (str( 'attachment; filename="%s"' % filename_to_serve)) self.response.write(gcs_fd.read())
def freeze_map(self, asset_id, table, report_id): """ """ cmd ={ "value": json.dumps({ "creator": CALL_SCOPE + "/com.google.earthengine.examples.sad.FreezeMap", "args":[{ "creator":CALL_SCOPE + "/com.google.earthengine.examples.sad.ProdesImage", "args":[asset_id] }, {'type':'FeatureCollection','table_id':1228540,'mark': str(timestamp())}, #{ #"type":"FeatureCollection", #"table_id": table, "filters":[ #{"metadata":"report_id", "equals": report_id} #] #}, "type" ], "type":"Image" }), } return self._execute_cmd('/create', cmd)
def as_dict(self): return {'id': str(self.key()), 'msg': self.msg, 'author': self.added_by.nickname(), 'date': timestamp(self.added_on)}