climate-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From good...@apache.org
Subject [1/3] git commit: CLIMATE-400: Added backend wrapper to rcmed.get_parameters_metadata()
Date Sun, 06 Apr 2014 20:48:00 GMT
Repository: climate
Updated Branches:
  refs/heads/master 0742e68e8 -> a8054c4af


CLIMATE-400: Added backend wrapper to rcmed.get_parameters_metadata()


Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/97ef16cd
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/97ef16cd
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/97ef16cd

Branch: refs/heads/master
Commit: 97ef16cd4366790bd8ae3fd949f2860c2fb638b6
Parents: 0742e68
Author: cgoodale <sigep311@gmail.com>
Authored: Sun Apr 6 13:03:02 2014 -0700
Committer: cgoodale <sigep311@gmail.com>
Committed: Sun Apr 6 13:03:02 2014 -0700

----------------------------------------------------------------------
 ocw-ui/backend/rcmed_helpers.py | 82 ++++++++++++++++++++++++++++++++++++
 1 file changed, 82 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/97ef16cd/ocw-ui/backend/rcmed_helpers.py
----------------------------------------------------------------------
diff --git a/ocw-ui/backend/rcmed_helpers.py b/ocw-ui/backend/rcmed_helpers.py
index f666850..2773358 100644
--- a/ocw-ui/backend/rcmed_helpers.py
+++ b/ocw-ui/backend/rcmed_helpers.py
@@ -17,6 +17,8 @@
 
 ''' Services for interacting with NASA JPL's Regional Climate Model Evaluation Database.
'''
 
+import ocw.data_source.rcmed as rcmed
+
 from bottle import Bottle, request, response
 
 import requests
@@ -79,6 +81,86 @@ def get_dataset_parameters():
         return "%s(%s)" % (request.query.callback, r.text)
     return r.text
 
+
+def extract_bounds(parameter):
+    ''' This will take a parameter dictionary and return the spatial and temporal bounds.
+
+    :param parameter: Single parameter that is returned from rcmed.get_parameters_metadata().
+    :type parameter: dictionary:
+
+    :returns: parameter_id and bounds dictionary of format
+            {
+              "start_date": "1901-01-15",
+              "end_date": "2009-12-15",
+              "lat_max": 89.75,
+              "lat_min": -89.75,
+              "lon_max": 179.75,
+              "lon_min": -179.75
+            }
+    '''
+    bounds_data = {}
+    bounds_data['start_date'] = str(parameter['start_date'])
+    bounds_data['end_date'] = str(parameter['end_date'])
+    spatial_bounds = parameter['bounding_box'].replace('(','').replace(')','')
+    spatial_bounds = spatial_bounds.split(',')
+    # spatial_bounds is in format:
+    # [<lat_max>, <lon_max>, <lat_min>, <lon_max>, <lat_min>,
<lon_min>, <lat_max>, <lon_min>]
+    # ['49.875', '179.875', '-49.875', '179.875', '-49.875', '-179.875', '49.875', '-179.875']
+    bounds_data['lat_max'] = float(spatial_bounds[0])
+    bounds_data['lat_min'] = float(spatial_bounds[2])
+    bounds_data['lon_max'] = float(spatial_bounds[1])
+    bounds_data['lon_min'] = float(spatial_bounds[5])
+    param_id =str(parameter['parameter_id'])
+    return param_id, bounds_data
+
+
+@rcmed_app.route('/parameters/bounds/')
+@rcmed_app.route('/parameters/bounds')
+def get_parameters_bounds():
+    ''' Return temporal and spatial bounds metadata for all of JPL's RCMED parameters.
+
+    **Example Call Format**
+
+    .. sourcecode:: javascript
+
+        /parameters/bounds/
+
+    **Example Return JSON Format**
+
+    .. sourcecode:: javascript
+        {
+          "data": {
+            "38": {
+              "start_date": "1901-01-15",
+              "end_date": "2009-12-15",
+              "lat_max": 89.75,
+              "lat_min": -89.75,
+              "lon_max": 179.75,
+              "lon_min": -179.75
+            },
+            "39": {
+              "start_date": "1901-01-15",
+              "end_date": "2009-12-15",
+              "lat_max": 89.75,
+              "lat_min": -89.75,
+              "lon_max": 179.75,
+              "lon_min": -179.75
+            }
+          }
+        }
+
+    '''
+    parameter_bounds = { "data": {}}
+    raw_parameters = rcmed.get_parameters_metadata()
+    for parameter in raw_parameters:
+        if parameter['bounding_box'] != None:
+            param_id, bounds_data = extract_bounds(parameter)
+            parameter_bounds['data'][param_id] = bounds_data
+
+
+    return parameter_bounds
+
+
 @rcmed_app.hook('after_request')
 def enable_cors():
     ''' Allow Cross-Origin Resource Sharing for all URLs. '''


Mime
View raw message