def ndfi_change(self, report_id, id): r = Report.get(Key(report_id)) z, x, y = Cell.cell_id(id) cell = Cell.get_or_default(r, x, y, z) ee = ndfi = NDFI('MOD09GA', r.comparation_range(), r.range()) bounds = cell.bounds(amazon_bounds) ne = bounds[0] sw = bounds[1] # spcify lon, lat F**K, MONKEY BALLS polygons = [[(sw[1], sw[0]), (sw[1], ne[0]), (ne[1], ne[0]), (ne[1], sw[0])]] cols = 1 rows = 1 if z < 2: cols = rows = 10 data = ndfi.ndfi_change_value(r.base_map(), [polygons], rows, cols) logging.info(data) ndfi = data['data'] #data['data']['properties']['ndfiSum']['values'] if request.args.get('_debug', False): ndfi['debug'] = { 'request': ee.ee.last_request, 'response': ee.ee.last_response } return Response(json.dumps(ndfi), mimetype='application/json')
def default_maps(): maps = [] r = Report.current() logging.info("report " + unicode(r)) ee_resource = 'MOD09GA' landsat = EELandsat('LANDSAT/L7_L1T') ndfi = NDFI(ee_resource, past_month_range(r.start), r.range()) d = landsat.mapid(*r.range()) if 'data' in d: maps.append({'data' :d['data'], 'info': 'LANDSAT/L7_L1T'}) """ d = landsat.mapid(*past_month_range(r.start)) if 'data' in d: maps.append({'data' :d['data'], 'info': 'LANDSAT/L7_L1T-old'}) """ #d = ndfi.mapid2() #if 'data' in d: #maps.append({'data' :d['data'], 'info': 'ndfi difference'}) d = ndfi.smaid() if 'data' in d: maps.append({'data': d['data'], 'info': 'SMA'}) d = ndfi.rgbid() if 'data' in d: maps.append({'data': d['data'], 'info': 'RGB'}) d = ndfi.ndfi0id() if 'data' in d: maps.append({'data': d['data'], 'info': 'NDFI t0'}) d = ndfi.ndfi1id() if 'data' in d: maps.append({'data' :d['data'], 'info': 'NDFI t1'}) return maps
def rgb_mapid(self, report_id, id, r, g, b): report = Report.get(Key(report_id)) z, x, y = Cell.cell_id(id) cell = Cell.get_or_default(report, x, y, z) ndfi = NDFI('MOD09GA', report.comparation_range(), report.range()) poly = cell.bbox_polygon(amazon_bounds) mapid = ndfi.rgb_strech(poly, tuple(map(int, (r, g, b)))) if 'data' not in mapid: abort(404) return Response(json.dumps(mapid['data']), mimetype='application/json')
def list(self, report_id): cache_key = self._cache_key(report_id) data = memcache.get(cache_key) if not data: r = Report.get(Key(report_id)) ee_resource = 'MOD09GA' ndfi = NDFI(ee_resource, r.comparation_range(), r.range()) data = ndfi.mapid2(r.base_map()) logging.info(data) if 'data' not in data: abort(404) data = data['data'] memcache.add(key=cache_key, value=data, time=3600) return jsonify(data)
def setUp(self): # create resources self.polygon = [[[-63.154907226557498, -4.8118385341739005], [-64.143676757807498, -4.8118385341739005], [-64.132690429682498, -6.2879986723276584], [-62.814331054682498, -6.3535159310087908]]] self.inv_polygon = [[[y, x] for x, y in self.polygon[0]]] self.r = Report(start=date(year=2011, month=2, day=1), end=date(year=2011, month=3, day=1), finished=True) self.r.put() self.cell = Cell(x=0, y=0, z=2, report=self.r, ndfi_high=1.0, ndfi_low=0.0) self.cell.put() self.area = Area(geo=json.dumps(self.inv_polygon), added_by=None, type=1, cell=self.cell) self.area.put() self.area.create_fusion_tables() ee_resource = 'MOD09GA' self.ndfi = NDFI(ee_resource, self.r.comparation_range(), self.r.range()) self.stats = Stats()
def close(self, report_id): """ close current and create new one """ r = Report.get(Key(report_id)) if not r.finished: ee_resource = 'MOD09GA' ndfi = NDFI(ee_resource, r.comparation_range(), r.range()) data = ndfi.freeze_map(r.base_map(), int(settings.FT_TABLE_ID), r.key().id()) logging.info(data) if 'data' not in data: abort(400) data = data['data']['id'] r.close(data) cache_key = NDFIMapApi._cache_key(report_id) memcache.delete(cache_key) # open new report new_report = Report(start=date.today()) new_report.put() return str(new_report.key()) return "already finished"