climate-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From huiky...@apache.org
Subject [1/3] climate git commit: CLIMATE-681 - Update the loader to read WRF data (other than precipitation)
Date Tue, 13 Oct 2015 21:10:34 GMT
Repository: climate
Updated Branches:
  refs/heads/master 38a38ff5f -> d49c5677d


CLIMATE-681 - Update the loader to read WRF data (other than precipitation)

- ocw.data_source.local.load_WRF_2d_files updated


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

Branch: refs/heads/master
Commit: b471b459c1f2017ea16bcaf67cd86b93aac2c390
Parents: 9263dc6
Author: Huikyo Lee <hlee21@discover25.prv.cube>
Authored: Wed Oct 7 03:06:39 2015 -0400
Committer: Huikyo Lee <hlee21@discover25.prv.cube>
Committed: Wed Oct 7 03:06:39 2015 -0400

----------------------------------------------------------------------
 ocw/data_source/local.py | 32 +++++++++++++++++++++-----------
 1 file changed, 21 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/b471b459/ocw/data_source/local.py
----------------------------------------------------------------------
diff --git a/ocw/data_source/local.py b/ocw/data_source/local.py
index 60fcb50..1c83d8f 100644
--- a/ocw/data_source/local.py
+++ b/ocw/data_source/local.py
@@ -112,9 +112,10 @@ def _get_netcdf_variable_name(valid_var_names, netcdf, netcdf_var):
     )
     raise ValueError(error)
 
-def load_WRF_2d_files(file_path,
-                      filename_pattern,
-                      variable_name,
+def load_WRF_2d_files(file_path=None,
+                      filename_pattern=None,
+                      filelist=None,
+                      variable_name='T2',
                       name=''):
     ''' Load multiple WRF (or nuWRF) original output files containing 2D fields such as precipitation
and surface variables into a Dataset.
     The dataset can be spatially subset.
@@ -122,6 +123,8 @@ def load_WRF_2d_files(file_path,
     :type file_path: :mod:`string`
     :param filename_pattern: Path to the NetCDF file to load.
     :type filename_pattern: :list:`string`
+    :param filelist: A list of filenames
+    :type filelist: :list:`string`
     :param variable_name: The variable name to load from the NetCDF file.
     :type variable_name: :mod:`string`
     :param name: (Optional) A name for the loaded dataset.
@@ -129,20 +132,26 @@ def load_WRF_2d_files(file_path,
     :returns: An OCW Dataset object with the requested variable's data from
         the NetCDF file.
     :rtype: :class:`dataset.Dataset`
-    :raises ValueError: 
-    '''                  
-    
-    WRF_files = []
-    for pattern in filename_pattern:
-        WRF_files.extend(glob(file_path + pattern))
+    :raises ValueError:
+    '''
+
+    if not filelist:
+        WRF_files = []
+        for pattern in filename_pattern:
+            WRF_files.extend(glob(file_path + pattern))
+    else:
+        WRF_files = [line.rstrip('\n') for line in open(filelist)]
+
     WRF_files.sort()
-  
+
     file_object_first = netCDF4.Dataset(WRF_files[0])
     lats = file_object_first.variables['XLAT'][0,:]
     lons = file_object_first.variables['XLONG'][0,:]
 
     times = []
+    nfile = len(WRF_files)
     for ifile, file in enumerate(WRF_files):
+        print 'Reading file '+str(ifile+1)+'/'+str(nfile), file
         file_object = netCDF4.Dataset(file)
         time_struct_parsed = strptime(file[-19:],"%Y-%m-%d_%H:%M:%S")     
         for ihour in numpy.arange(24):
@@ -150,11 +159,12 @@ def load_WRF_2d_files(file_path,
         values0= file_object.variables[variable_name][:]
         if ifile == 0:
             values = file_object.variables[variable_name][:]
+            variable_unit = file_object.variables[variable_name].units
         else:
             values = numpy.concatenate((values, file_object.variables[variable_name][:]))

         file_object.close()
     times = numpy.array(times)
-    return Dataset(lats, lons, times, values, variable_name, name=name)
+    return Dataset(lats, lons, times, values, variable_name, units=variable_unit, name=name)
 
 def load_file(file_path,
               variable_name,


Mime
View raw message