Exemple #1
0
 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()
     self.ndfi = NDFI(self.r.comparation_range(), self.r.range())
     self.stats = Stats()
Exemple #2
0
 def rgb_mapid(self, report_id, id, r, g, b, sensor):
     report = Report.get(Key(report_id))
     z, x, y = Cell.cell_id(id)
     cell = Cell.get_or_default(report, x, y, z)
     ndfi = NDFI(report.comparation_range(), report.range())
     poly = cell.bbox_polygon(amazon_bounds)
     mapid = ndfi.rgb_stretch(poly, sensor, tuple(map(int, (r, g, b))))
     if not mapid:
         abort(404)
     return Response(json.dumps(mapid), mimetype='application/json')
Exemple #3
0
 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))
         ndfi = NDFI(r.comparation_range(), r.range())
         data = ndfi.mapid2(r.base_map())
         if not data:
             abort(404)
         memcache.add(key=cache_key, value=data, time=3600)
     return jsonify(data)
Exemple #4
0
 def close(self, report_id):
     """ close current and create new one """
     r = Report.get(Key(report_id))
     if not r.finished:
         ndfi = NDFI(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"
Exemple #5
0
    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(r.comparation_range(), r.range())

        bounds = cell.bounds(amazon_bounds)
        ne = bounds[0]
        sw = bounds[1]
        # spcify lon, lat
        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 = 5
        data = ndfi.ndfi_change_value(r.base_map(), {
            "type": "Polygon",
            "coordinates": [polygons]
        }, rows, cols)
        logging.info(data)
        ndfi = data  #data['properties']['ndfiSum']['values']
        return Response(json.dumps(ndfi), mimetype='application/json')
Exemple #6
0
def default_maps():
    maps = []
    r = Report.current()
    logging.info("report " + unicode(r))
    landsat = EELandsat()
    ndfi = NDFI(past_month_range(r.start), r.range())

    d = landsat.mapid(timestamp(r.start), datetime.datetime.now())
    maps.append({'data': d, 'info': 'LANDSAT/LE7_L1T'})
    #d = ndfi.mapid2()
    #if d: maps.append({'data' :d, 'info': 'ndfi difference'})
    d = ndfi.smaid()
    if d: maps.append({'data': d, 'info': 'SMA'})
    d = ndfi.rgb1id()
    if d: maps.append({'data': d, 'info': 'RGB'})
    d = ndfi.ndfi0id()
    if d: maps.append({'data': d, 'info': 'NDFI T0'})
    d = ndfi.ndfi1id()
    if d: maps.append({'data': d, 'info': 'NDFI T1'})
    d = ndfi.baseline(r.base_map())
    if d: maps.append({'data': d, 'info': 'Baseline'})
    d = ndfi.rgb0id()
    if d: maps.append({'data': d, 'info': 'Previous RGB'})
    return maps