当前位置: 首页>>代码示例>>Python>>正文


Python models.Cell类代码示例

本文整理汇总了Python中application.models.Cell的典型用法代码示例。如果您正苦于以下问题:Python Cell类的具体用法?Python Cell怎么用?Python Cell使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Cell类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ndfi_change

    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 
        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'] #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')
开发者ID:Brackets,项目名称:DeforestationAnalysisTool,代码行数:26,代码来源:report.py

示例2: landsat

 def landsat(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)
     bounds = cell.bounds(amazon_bounds)
     bounds = "%f,%f,%f,%f" % (bounds[1][1], bounds[1][0], bounds[0][1], bounds[0][0])
     ee = EELandsat(LANDSAT7)
     d = ee.list(bounds=bounds)
     data = {}
     if len(d) >= 1:
         x = d[-1]
         img_info = x.split('/')[2][3:]
         path = img_info[:3]
         row = img_info[3:6]
         year = int(img_info[6: 10])
         julian_date =  img_info[10: 13]
         date = date_from_julian(int(julian_date), year)
         data = {
             'info': img_info,
             'path': path,
             'row': row,
             'year': year,
             'timestamp': timestamp(date),
             'date': date.isoformat()
         }
     return Response(json.dumps(data), mimetype='application/json')
开发者ID:Brackets,项目名称:DeforestationAnalysisTool,代码行数:26,代码来源:report.py

示例3: NotesApiTest

class NotesApiTest(unittest.TestCase, GoogleAuthMixin):
    def setUp(self):
        app.config['TESTING'] = True
        self.app = app.test_client()
        self.login('[email protected]', 'testuser')
        r = Report(start=date.today(), finished=False)
        r.put()
        self.r = r
        self.cell = Cell(x=0, y=0, z=2, report=self.r, ndfi_high=1.0, ndfi_low=0.0)
        self.cell.put()
        for x in Note.all():
            x.delete()
        self.when = datetime.now()
        self.note = Note(msg='test msg', added_by=users.get_current_user(), cell=self.cell, added_on=self.when)
        self.note.put()

    def test_note_list(self):
        rv = self.app.get('/api/v0/report/' + str(self.r.key()) + '/cell/2_0_0/note')
        self.assertEquals(200, rv.status_code)
        js = json.loads(rv.data)
        self.assertEquals(1, len(js))
        n = js[0]
        self.assertEquals('test msg', n['msg'])
        self.assertEquals('test', n['author'])
        self.assertEquals(timestamp(self.when), n['date'])
        self.assertEquals(1, Note.all().count())

    def test_notes_create(self):
        rv = self.app.post('/api/v0/report/' + str(self.r.key()) + '/cell/2_0_0/note', data='{"msg": "test"}')
        self.assertEquals(200, rv.status_code)
        self.assertEquals(2, Note.all().count())
        self.assertEquals(2, self.cell.note_set.count())
开发者ID:Brackets,项目名称:DeforestationAnalysisTool,代码行数:32,代码来源:tests.py

示例4: landsat

 def landsat(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)
     bounds = cell.bounds(amazon_bounds)
     bounds = "%f,%f,%f,%f" % (bounds[1][1], bounds[1][0], bounds[0][1], bounds[0][0])
     ee = EELandsat(LANDSAT7)
     d = ee.list(bounds=bounds)
     data = {}
     if len(d) >= 1:
         x = d[-1]
         img_info = x.split("/")[2][3:]
         path = img_info[:3]
         row = img_info[3:6]
         year = int(img_info[6:10])
         julian_date = img_info[10:13]
         date = date_from_julian(int(julian_date), year)
         data = {
             "info": img_info,
             "path": path,
             "row": row,
             "year": year,
             "timestamp": timestamp(date),
             "date": date.isoformat(),
         }
     return Response(json.dumps(data), mimetype="application/json")
开发者ID:ImazonSadGoogle,项目名称:DeforestationAnalysisTool,代码行数:26,代码来源:report.py

示例5: PolygonApi

class PolygonApi(unittest.TestCase, GoogleAuthMixin):
    def setUp(self):
        app.config['TESTING'] = True
        self.app = app.test_client()
        self.login('[email protected]', 'testuser')
        for x in Area.all():
            x.delete()
        for x in Cell.all():
            x.delete()
        r = Report(start=date.today(), finished=False)
        r.put()
        self.r = r
        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='[]', added_by=users.get_current_user(), type=1, cell=self.cell)
        self.area.put()

    def test_list(self):
        rv = self.app.get('/api/v0/report/' + str(self.r.key()) + '/cell/2_0_0/polygon')
        js = json.loads(rv.data)
        self.assertEquals(1, len(js))

    def test_create_non_existing_cell(self):
        rv = self.app.post('/api/v0/report/' + str(self.r.key()) + '/cell/2_1_0/polygon',
            data='{"paths": "test", "type": 1}'
        )
        self.assertEquals(2, Area.all().count())
        self.assertEquals(4, Cell.all().count())
        # check parents exists
        cell = Cell.all().filter('report =', self.r).filter('x =', 1).filter('y =', 0).filter('z =', 2).fetch(1)[0]
        self.assertEquals('test', cell.get_parent().last_change_by.nickname())
        self.assertEquals('test', cell.get_parent().get_parent().last_change_by.nickname())
        self.assertNotEquals(0, cell.get_parent().last_change_on)
        

    def test_create(self):
        rv = self.app.post('/api/v0/report/' + str(self.r.key()) + '/cell/2_0_0/polygon',
            data='{"paths": "[]", "type": 1}'
        )
        self.assertEquals(2, Area.all().count())
        rv = self.app.get('/api/v0/report/' + str(self.r.key()) + '/cell/2_0_0/polygon')
        js = json.loads(rv.data)
        self.assertEquals(2, len(js))

    def test_update(self):
        rv = self.app.put('/api/v0/report/' + str(self.r.key()) + '/cell/2_0_0/polygon/' + str(self.area.key()),
            data='{"paths": "[[1, 2, 3]]", "type": 100}'
        )
        self.assertEquals(1, Area.all().count())
        a = Area.get(self.area.key())
        self.assertEquals(100, a.type)
        self.assertEquals("\"[[1, 2, 3]]\"", a.geo)
        js = json.loads(rv.data)
        self.assertEquals(100, js['type'])
        self.assertEquals("[[1, 2, 3]]", js['paths'])

    def test_delete(self):
        rv = self.app.delete('/api/v0/report/' + str(self.r.key()) + '/cell/2_0_0/polygon/' + str(self.area.key()))

        self.assertEquals(0, Area.all().count())
开发者ID:Brackets,项目名称:DeforestationAnalysisTool,代码行数:60,代码来源:tests.py

示例6: list

 def list(self, report_id, cell_pos):
     r = Report.get(Key(report_id))
     z, x, y = Cell.cell_id(cell_pos)
     cell = Cell.get_cell(r, x, y, z)
     if not cell:
         return self._as_json([])
     else:
         return self._as_json([x.as_dict() for x in cell.area_set])
开发者ID:Brackets,项目名称:DeforestationAnalysisTool,代码行数:8,代码来源:report.py

示例7: rgb_mapid

 def rgb_mapid(self, report_id, operation, id, r, g, b, sensor):
     report = Report.get(Key(report_id))
     z, x, y = Cell.cell_id(id)
     cell = Cell.get_or_default(report, operation, 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')
开发者ID:dyeden,项目名称:DeforestationAnalysisTool,代码行数:10,代码来源:report.py

示例8: create

 def create(self, report_id, cell_pos):
     r = Report.get(Key(report_id))
     z, x, y = Cell.cell_id(cell_pos)
     cell = Cell.get_or_create(r, x, y, z)
     data = json.loads(request.data)
     if "msg" not in data:
         abort(400)
     a = Note(msg=data["msg"], added_by=users.get_current_user(), cell=cell)
     a.save()
     return Response(a.as_json(), mimetype="application/json")
开发者ID:ImazonSadGoogle,项目名称:DeforestationAnalysisTool,代码行数:10,代码来源:report.py

示例9: rgb_mapid

 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")
开发者ID:ImazonSadGoogle,项目名称:DeforestationAnalysisTool,代码行数:10,代码来源:report.py

示例10: test_create_non_existing_cell

 def test_create_non_existing_cell(self):
     rv = self.app.post('/api/v0/report/' + str(self.r.key()) + '/cell/2_1_0/polygon',
         data='{"paths": "test", "type": 1}'
     )
     self.assertEquals(2, Area.all().count())
     self.assertEquals(4, Cell.all().count())
     # check parents exists
     cell = Cell.all().filter('report =', self.r).filter('x =', 1).filter('y =', 0).filter('z =', 2).fetch(1)[0]
     self.assertEquals('test', cell.get_parent().last_change_by.nickname())
     self.assertEquals('test', cell.get_parent().get_parent().last_change_by.nickname())
     self.assertNotEquals(0, cell.get_parent().last_change_on)
开发者ID:Brackets,项目名称:DeforestationAnalysisTool,代码行数:11,代码来源:tests.py

示例11: CellTest

class CellTest(unittest.TestCase):

    def setUp(self):
        r = Report(start=date.today(), finished=False)
        r.put()
        self.r = r
        self.cell = Cell(x=11, y=11, z=2, report=self.r, ndfi_high=1.0, ndfi_low=0.0)
        self.cell.put()

    def test_parent_id(self):
        self.assertEquals('1_1_1', self.cell.parent_id)
开发者ID:Brackets,项目名称:DeforestationAnalysisTool,代码行数:11,代码来源:tests.py

示例12: update

    def update(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)
        cell.report = r

        data = json.loads(request.data)
        cell.ndfi_low = float(data['ndfi_low'])
        cell.ndfi_high = float(data['ndfi_high'])
        cell.done = data['done']
        cell.last_change_by = users.get_current_user()
        cell.put()

        return Response(cell.as_json(), mimetype='application/json')
开发者ID:netconstructor,项目名称:DeforestationAnalysisTool,代码行数:14,代码来源:report.py

示例13: setUp

 def setUp(self):
     app.config['TESTING'] = True
     self.app = app.test_client()
     self.login('[email protected]', 'testuser')
     for x in Area.all():
         x.delete()
     for x in Cell.all():
         x.delete()
     r = Report(start=date.today(), finished=False)
     r.put()
     self.r = r
     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='[]', added_by=users.get_current_user(), type=1, cell=self.cell)
     self.area.put()
开发者ID:Brackets,项目名称:DeforestationAnalysisTool,代码行数:15,代码来源:tests.py

示例14: ndfi_value_for_cells

def ndfi_value_for_cells(cell_key):

    cell = Cell.get(Key(cell_key))

    ndfi = NDFI('MOD09GA',
            cell.report.comparation_range(),
            cell.report.range())

    bounds = cell.bounds(amazon_bounds)
    logging.info(bounds)
    ne = bounds[0]
    sw = bounds[1]
    polygons = [[ (sw[1], sw[0]), (sw[1], ne[0]), (ne[1], ne[0]), (ne[1], sw[0]) ]]
    data = ndfi.ndfi_change_value(cell.report.base_map(), [polygons])
    logging.info(data)
    if 'data' not in data:
        logging.error("can't get ndfi change value")
        return
    ndfi = data['data']['properties']['ndfiSum']['values']
    for row in xrange(10):
        for col in xrange(10):
            idx = row*10 + col
            count = float(ndfi['count'][idx])
            s = float(ndfi['sum'][idx])
            if count > 0.0:
                ratio = s/count
            else:
                ratio = 0.0
            ratio = ratio/10.0 #10 value is experimental
            # asign to cell
            logging.info('cell ndfi (%d, %d): %f' % (row, col, ratio))
            c = cell.child(row, col)
            c.ndfi_change_value = ratio
            c.put()
开发者ID:ImazonSadGoogle,项目名称:DeforestationAnalysisTool,代码行数:34,代码来源:commands.py

示例15: update_cells_ndfi

def update_cells_ndfi():
    r = Report.current()
    cell = Cell.get_or_default(r, 0, 0, 0)
    for c in iter(cell.children()):
        c.put()
        deferred.defer(ndfi_value_for_cells, str(c.key()), _queue="ndfichangevalue")
    return 'working'
开发者ID:ImazonSadGoogle,项目名称:DeforestationAnalysisTool,代码行数:7,代码来源:commands.py


注:本文中的application.models.Cell类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。