Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…sisTool

Conflicts:
	src/application/generate_reports.py
  • Loading branch information
Dave Thau committed Feb 21, 2012
2 parents ee2fe48 + a07fe7e commit efa77f6
Show file tree
Hide file tree
Showing 13 changed files with 133 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/app.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
application: imazon-sad-tool
version: v01
application: imazon-prototype
version: v03
runtime: python
api_version: 1

Expand Down
3 changes: 2 additions & 1 deletion src/application/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
CellAPI.add_custom_url(app, '/api/v0/report/<report_id>/cell/<id>/ndfi_change', 'ndfi_change')
CellAPI.add_custom_url(app, '/api/v0/report/<report_id>/cell/<id>/bounds', 'bounds')
CellAPI.add_custom_url(app, '/api/v0/report/<report_id>/cell/<id>/landsat', 'landsat')
CellAPI.add_custom_url(app, '/api/v0/report/<report_id>/cell/<id>/rgb/<r>/<g>/<b>', 'rgb_mapid')
CellAPI.add_custom_url(app, '/api/v0/report/<report_id>/cell/<id>/rgb/<r>/<g>/<b>/sensor/<sensor>', 'rgb_mapid')
#CellAPI.add_custom_url(app, '/api/v0/report/<report_id>/cell/<id>/rgb/<r>/<g>/<b>/sensor', 'sensor')

NDFIMapApi.add_urls(app, '/api/v0/report/<report_id>/map')
PolygonAPI.add_urls(app, '/api/v0/report/<report_id>/cell/<cell_pos>/polygon')
Expand Down
107 changes: 98 additions & 9 deletions src/application/ee.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import settings
import simplejson as json
import collections
import urllib

from earthengine.connector import EarthEngine

from time_utils import timestamp
from datetime import timedelta

METER2_TO_KM2 = 1.0/(1000*1000)
CALL_SCOPE = "SAD"
Expand Down Expand Up @@ -179,15 +181,58 @@ def mapid(self, start, end):
'bands': ','.join(MAP_IMAGE_BANDS), #'30,20,10',
'gain': PREVIEW_GAIN
}

return self._execute_cmd("/mapid", cmd)

def _execute_cmd(self, url, cmd):
params = "&".join(("%s=%s"% v for v in cmd.iteritems()))
return self.ee.post(url, params)
#http://earthengine.googleapis.com/api/list?id=LANDSAT/L5_L1T&bbox=72.6,18.8,73.1,19.18


#class EEMODIS(object):
#
# def __init__(self, resource):
# self.resource = resource
# self.ee = EarthEngine(settings.EE_TOKEN)
#
# def list(self, start, end, params={}):
# images = self.ee.get("/list?id=%s&starttime=%s&endtime=%s" % (self.resource, start, end))
# logging.info(images)
# if 'data' in images:
# return [x['id'] for x in images['data']]
# return []
#
# def mapid(self, start, end):
# MAP_IMAGE1 = {
# 'creator':'MODIS/MOD09GA',
# 'input':'LANDSAT/L7_L1T',
# 'bands':[{'id':'10','data_type':'float'},{'id':'20','data_type':'float'},{'id':'30','data_type':'float'}],
# 'start_time': start,
# 'end_time': end
# };
# MAP_IMAGE = {
# "creator": "SimpleMosaic",
# "args": [MAP_IMAGE1]
# }
# #PREVIEW_GAIN = 500;
# MAP_IMAGE_BANDS = [
# 'sur_refl_b01_250m', 'sur_refl_b02_250m', 'sur_refl_b03_500m',
# 'sur_refl_b04_500m', 'sur_refl_b06_500m', 'sur_refl_b07_500m'];
# cmd = {
# 'image': json.dumps(MAP_IMAGE), #json.dumps(modis)
# 'bands': ','.join(MAP_IMAGE_BANDS),
# 'gain': PREVIEW_GAIN
# }
#
# return self._execute_cmd("/mapid", cmd)#
#
# def _execute_cmd(self, url, cmd):
# params = "&".join(("%s=%s"% v for v in cmd.iteritems()))
# return self.ee.post(url, params)
#http://earthengine.googleapis.com/api/list?id=MODIS09GA&starttime=1254305000000&endtime=1256900200000


#http://earthengine.googleapis.com/api/list?id=LANDSAT/L5_L1T&bbox=72.6,18.8,73.1,19.18
class NDFI(object):
""" ndfi info for a period of time
"""
Expand Down Expand Up @@ -284,15 +329,18 @@ def ndfi1id(self):
params = self._NDFI_period_image_command(self.work_period)
return self._execute_cmd('/mapid', params)

def rgb_strech(self, polygon, bands):
def rgb_strech(self, polygon, sensor, bands):
# this is an special call, the application needs to call /value
# before call /mapid in order to google earthn engine makes his work
cmd = self._RGB_streched_command(self.work_period, polygon, bands)
cmd = self._RGB_streched_command(self.work_period, polygon, sensor, bands)
del cmd['bands']
cmd['fields'] = 'stats_sur_refl_b01,stats_sur_refl_b02,stats_sur_refl_b03,stats_sur_refl_b04,stats_sur_refl_b05'
if (sensor=="modis"):
cmd['fields'] = 'stats_sur_refl_b01,stats_sur_refl_b02,stats_sur_refl_b03,stats_sur_refl_b04,stats_sur_refl_b05'
else:
cmd['fields'] = 'stats_30,stats_20,stats_10'

self._execute_cmd('/value', cmd)
cmd = self._RGB_streched_command(self.work_period, polygon, bands)
cmd = self._RGB_streched_command(self.work_period, polygon, sensor, bands)
return self._execute_cmd('/mapid', cmd)

def _get_polygon_bbox(self, polygon):
Expand Down Expand Up @@ -468,7 +516,8 @@ def _SMA_image_command(self, period):
"gamma": 1.6
};

def _RGB_streched_command(self, period, polygon, bands):
def _RGB_streched_command(self, period, polygon, sensor, bands):
if(sensor=="modis"):
""" bands in format (1, 2, 3) """
bands = "sur_refl_b0%d,sur_refl_b0%d,sur_refl_b0%d" % bands
return {
Expand All @@ -488,7 +537,47 @@ def _RGB_streched_command(self, period, polygon, bands):
}),
"bands": bands
}
else:
three_months = timedelta(days=90)
work_period_end = self.work_period['end']
work_period_start = self.work_period['start'] - 7776000000 #three_months
bands = "%d,%d,%d" % bands
return {
"image": json.dumps({
"creator":CALL_SCOPE + "/com.google.earthengine.examples.sad.StretchImage",
"args":[{
"creator":"ClipToMultiPolygon",
"args":[{
"creator":"SimpleMosaic",
"args":[{
"creator":"LANDSAT/LandsatTOA",
"input":"LANDSAT/L7_L1T",
"bands":[{"id":"30","data_type":"float"},
{"id":"20","data_type":"float"},
{"id":"10","data_type":"float"}],
"start_time": work_period_start, #131302801000
"end_time": work_period_end }] #1313279999000
},polygon]
},
["30","20","10"],
2 #EPIC
]
}),
"bands": bands
}




class Thumbnail(object):
def __init__(self):
self.ee = EarthEngine(settings.EE_TOKEN)
def thumbid(self, id):
MAP_IMAGE = {'id':id};
MAP_IMAGE_BANDS = ['30','20','10'];
cmd = {
'getid':1,
'image':urllib.quote_plus(json.dumps(MAP_IMAGE)),
'bands':','.join(MAP_IMAGE_BANDS), #'30,20,10'
}
return self._execute_cmd("/thumb", cmd)
def _execute_cmd(self, url, cmd):
params = "&".join(("%s=%s"% v for v in cmd.iteritems()))
return self.ee.get(url, params)
1 change: 0 additions & 1 deletion src/application/generate_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
]

print "assetid,report_id"
#for r in assets_id[-1:]:
for r in assets_id:
first, last = month_range(*reversed(map(int, r.split('_')[-2:])))
url = "http://%s/_ah/cmd/create_report?year=%d&month=%d&day=%d&assetid=%s&fyear=%d&fmonth=%d&fday=%d""" % (sys.argv[1], first.year, first.month, first.day, r, last.year, last.month, last.day)
Expand Down
4 changes: 2 additions & 2 deletions src/application/resources/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,15 @@ def landsat(self, report_id, id):
}
return Response(json.dumps(data), mimetype='application/json')

def rgb_mapid(self, report_id, id, r, g, b):
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('MOD09GA',
report.comparation_range(),
report.range())
poly = cell.bbox_polygon(amazon_bounds)
mapid = ndfi.rgb_strech(poly, tuple(map(int, (r, g, b))))
mapid = ndfi.rgb_strech(poly, sensor, tuple(map(int, (r, g, b))))
if 'data' not in mapid:
abort(404)
return Response(json.dumps(mapid['data']), mimetype='application/json')
Expand Down
15 changes: 12 additions & 3 deletions src/application/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from decorators import login_required, admin_required
from forms import ExampleForm
from application.ee import NDFI, EELandsat
from application.ee import NDFI, EELandsat, Thumbnail

from app import app

Expand Down Expand Up @@ -52,10 +52,10 @@ def default_maps():
maps.append({'data': d['data'], 'info': 'RGB'})
d = ndfi.ndfi0id()
if 'data' in d:
maps.append({'data': d['data'], 'info': 'NDFI t0'})
maps.append({'data': d['data'], 'info': 'NDFI T0'})
d = ndfi.ndfi1id()
if 'data' in d:
maps.append({'data' :d['data'], 'info': 'NDFI t1'})
maps.append({'data' :d['data'], 'info': 'NDFI T1'})
return maps

def get_or_create_user():
Expand Down Expand Up @@ -171,3 +171,12 @@ def warmup():
"""
return ''

@app.route('/picker')
def picker():
scene = request.args.get('scene','')
if scene:
thumb = Thumbnail()
result = thumb.thumbid(scene)
else:
result = "{}"
return render_template('picker.html', thumbid=result['data']['thumbid'], token=result['data']['token'])
3 changes: 2 additions & 1 deletion src/content/css/_map.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ body, html {
overflow: hidden;
}


#workarea{
position: absolute;
width: 100%;
Expand All @@ -13,7 +14,7 @@ body, html {

.map_container {
position: absolute;
width: 100%;
width: 99%;
height: 100%;
.map {
width: 100%;
Expand Down
2 changes: 1 addition & 1 deletion src/content/templates/_header.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ <h3>Are you sure?</h3>
<div class="content">

<div id="range_select">
<p>Range analyzed: <strong id="report-date"></strong> - <strong id="report-date-end"></strong></p>
<p>Ranges analyzed: <strong id="report-date"></strong> - <strong id="report-date-end"></strong></p>
<!-- <a href="#download" id="select_range">reports</a> -->
</div> <!-- range_select -->

Expand Down
Empty file modified src/content/templates/home.html
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion src/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,7 @@ body, html {
}
#workarea .map_container {
position: absolute;
width: 100%;
width: 99%;
height: 100%;
}
#workarea .map_container .map {
Expand Down
2 changes: 1 addition & 1 deletion src/static/css/vis.css
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ body, html {
}
#workarea .map_container {
position: absolute;
width: 100%;
width: 99%;
height: 100%;
}
#workarea .map_container .map {
Expand Down
2 changes: 1 addition & 1 deletion src/static/js/models/layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var RGBStrechLayer = LayerModel.extend({
url: function() {
var cell_id = this.get('z') + "_" + this.get('x') + "_" + this.get('y');
var mapid = this.get('r') + "/" + this.get('g') + '/' + this.get('b');
return "/api/v0/report/" + this.get('report_id') + "/cell/" + cell_id + "/rgb/" + mapid;
return "/api/v0/report/" + this.get('report_id') + "/cell/" + cell_id + "/rgb/" + mapid + "/sensor/" + this.get('sensor');
},

//parses token and mapid response from server and creates tile url
Expand Down
11 changes: 11 additions & 0 deletions src/static/js/rgb_layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,29 @@ var RGB_layers = [
r: 1,
g: 4,
b: 3,
sensor: 'modis',
description: 'True color RGB141'
},
{
r: 5,
g: 2,
b: 1,
sensor: 'modis',
description: 'False color RGB421'
},
{
r: 2,
g: 1,
b: 4,
sensor: 'modis',
description: 'F color infrared RGB214'
},
{
r: 30,
g: 20,
b: 10,
sensor: 'landsat',
description: 'Landsat Stretch'
}
];

Expand All @@ -32,6 +42,7 @@ function add_rgb_layers(layers, gridstack, report_id) {
r: layer.r,
g: layer.g,
b: layer.b,
sensor: layer.sensor,
report_id: report_id,
description: layer.description
});
Expand Down

0 comments on commit efa77f6

Please # to comment.