You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@climate.apache.org by jo...@apache.org on 2014/11/08 00:33:38 UTC

[2/4] climate git commit: CLIMATE-371 - Allow user to pass variable names to local.py

CLIMATE-371 - Allow user to pass variable names to local.py


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

Branch: refs/heads/master
Commit: e3e59787667e8a360c5e43d93111625e6b8ffafc
Parents: 227b5de
Author: Michael Joyce <jo...@apache.org>
Authored: Fri Nov 7 14:20:02 2014 -0800
Committer: Michael Joyce <jo...@apache.org>
Committed: Fri Nov 7 14:26:16 2014 -0800

----------------------------------------------------------------------
 ocw/data_source/local.py | 38 ++++++++++++++++++++++++++++----------
 1 file changed, 28 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/e3e59787/ocw/data_source/local.py
----------------------------------------------------------------------
diff --git a/ocw/data_source/local.py b/ocw/data_source/local.py
index 0cbecad..18b053d 100644
--- a/ocw/data_source/local.py
+++ b/ocw/data_source/local.py
@@ -109,19 +109,34 @@ def _get_netcdf_variable_name(valid_var_names, netcdf, netcdf_var):
     )
     raise ValueError(error)
 
-def load_file(file_path, variable_name, elevation_index=0):
+def load_file(file_path,
+              variable_name,
+              elevation_index=0,
+              lat_name=None,
+              lon_name=None,
+              time_name=None):
     ''' Load a NetCDF file into a Dataset.
 
     :param file_path: Path to the NetCDF file to load.
     :type file_path: String
     :param variable_name: The variable name to load from the NetCDF file.
     :type variable_name: String
-    :param elevation_index: The elevation index for which data should be
-        returned. Climate data is often times 4 dimensional data. Some datasets
-        will have readins at different height/elevation levels. OCW expects
-        3D data so a single layer needs to be stripped out when loading. By
-        default, the first elevation layer is used. If desired you may specify
-        the elevation value to use.
+    :param elevation_index: (Optional) The elevation index for which data should
+        be returned. Climate data is often times 4 dimensional data. Some
+        datasets will have readins at different height/elevation levels. OCW
+        expects 3D data so a single layer needs to be stripped out when loading.
+        By default, the first elevation layer is used. If desired you may
+        specify the elevation value to use.
+    :type elevation_index: Integer
+    :param lat_name: (Optional) The latitude variable name to extract from the
+        dataset.
+    :type lat_name: String
+    :param lon_name: (Optional) The longitude variable name to extract from the
+        dataset.
+    :type lon_name: String
+    :param time_name: (Optional) The time variable name to extract from the
+        dataset.
+    :type time_name: String
 
     :returns: An OCW Dataset object with the requested variable's data from
         the NetCDF file.
@@ -141,9 +156,12 @@ def load_file(file_path, variable_name, elevation_index=0):
         )
         raise ValueError(err)
 
-    lat_name = _get_netcdf_variable_name(LAT_NAMES, netcdf, variable_name)
-    lon_name = _get_netcdf_variable_name(LON_NAMES, netcdf, variable_name)
-    time_name = _get_netcdf_variable_name(TIME_NAMES, netcdf, variable_name)
+    if not lat_name:
+        lat_name = _get_netcdf_variable_name(LAT_NAMES, netcdf, variable_name)
+    if not lon_name:
+        lon_name = _get_netcdf_variable_name(LON_NAMES, netcdf, variable_name)
+    if not time_name:
+        time_name = _get_netcdf_variable_name(TIME_NAMES, netcdf, variable_name)
 
     lats = netcdf.variables[lat_name][:]    
     lons = netcdf.variables[lon_name][:]