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()
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()
def ndfi_value_for_cells_dummy(cell_key): cell = Cell.get(Key(cell_key)) bounds = cell.bounds(amazon_bounds) logging.info(bounds) ne = bounds[0] sw = bounds[1] polygons = [[sw, (sw[0], ne[1]), ne, (ne[0], sw[1])]] for row in xrange(10): for col in xrange(10): c = cell.child(row, col) c.ndfi_change_value = random.random() c.put() cell.calculate_ndfi_change_from_childs()
def ndfi_value_for_cells_dummy(cell_key): cell = Cell.get(Key(cell_key)) bounds = cell.bounds(amazon_bounds) logging.info(bounds) ne = bounds[0] sw = bounds[1] polygons = [[ sw, (sw[0], ne[1]), ne, (ne[0], sw[1]) ]] for row in xrange(10): for col in xrange(10): c = cell.child(row, col) c.ndfi_change_value = random.random() c.put() cell.calculate_ndfi_change_from_childs()