You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@climate.apache.org by hu...@apache.org on 2015/10/14 08:48:54 UTC

[1/2] climate git commit: CLIMATE-692 - A new loader to read NLDAS data with a file list

Repository: climate
Updated Branches:
  refs/heads/master 4b37b125c -> 799fde64b


CLIMATE-692 - A new loader to read NLDAS data with a file list

- ocw.data_source.local.load_NLDAS_forcingA_files is added


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

Branch: refs/heads/master
Commit: 14a86a6c47c562702b3760d7a10b7fb0b3713b35
Parents: 4b37b12
Author: huikyole <hu...@argo.jpl.nasa.gov>
Authored: Tue Oct 13 16:40:56 2015 -0700
Committer: huikyole <hu...@argo.jpl.nasa.gov>
Committed: Tue Oct 13 16:40:56 2015 -0700

----------------------------------------------------------------------
 ocw/data_source/local.py | 55 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/14a86a6c/ocw/data_source/local.py
----------------------------------------------------------------------
diff --git a/ocw/data_source/local.py b/ocw/data_source/local.py
index ff99aab..3560b99 100644
--- a/ocw/data_source/local.py
+++ b/ocw/data_source/local.py
@@ -477,3 +477,58 @@ def load_dataset_from_multiple_netcdf_files(file_list, variable_name,
     times = numpy.array(times)
     return Dataset(lats, lons, times, data_values, variable_name, name=name)
 
+def load_NLDAS_forcingA_files(file_path=None,
+                      filename_pattern=None,
+                      filelist=None,
+                      variable_name='APCPsfc_110_SFC_acc1h',
+                      name=''):
+    ''' Load multiple NLDAS2 forcingAWRF files containing 2D fields such as precipitation and surface variables into a Dataset.
+    The dataset can be spatially subset.
+    :param file_path: Directory to the NetCDF file to load.
+    :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.
+    :type name: :mod:`string`
+    :returns: An OCW Dataset object with the requested variable's data from
+        the NetCDF file.
+    :rtype: :class:`dataset.Dataset`
+    :raises ValueError:
+    '''
+ 
+    if not filelist:
+        NLDAS_files = []
+        for pattern in filename_pattern:
+            NLDAS_files.extend(glob(file_path + pattern))
+    else:
+        NLDAS_files = [line.rstrip('\n') for line in open(filelist)]
+
+    NLDAS_files.sort()
+
+    file_object_first = netCDF4.Dataset(NLDAS_files[0])
+    lats = file_object_first.variables['lat_110'][:]
+    lons = file_object_first.variables['lon_110'][:]
+    lons, lats = numpy.meshgrid(lons, lats)
+
+    times = []
+    nfile = len(NLDAS_files)
+    for ifile, file in enumerate(NLDAS_files):
+        print 'Reading file '+str(ifile+1)+'/'+str(nfile), file
+        file_object = netCDF4.Dataset(file)
+        time_struct_parsed = strptime(file[-20:-7],"%Y%m%d.%H%M")
+        times.append(datetime(*time_struct_parsed[:6]))
+        
+        values0 = file_object.variables[variable_name][:]
+        values0 = numpy.expand_dims(values0, axis=0)
+        if ifile == 0:
+            values = values0
+            variable_unit = file_object.variables[variable_name].units
+        else:
+            values = numpy.concatenate((values, values0))
+        file_object.close()
+    times = numpy.array(times)
+    return Dataset(lats, lons, times, values, variable_name, units=variable_unit, name=name)


[2/2] climate git commit: CLIMATE-692 - A new loader to read NLDAS data with a file list

Posted by hu...@apache.org.
CLIMATE-692 - A new loader to read NLDAS data with a file list

- ocw.data_source.local.load_NLDAS_forcingA_files is added


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

Branch: refs/heads/master
Commit: 799fde64b16882ace6e6d7c595c1c84bb4479b79
Parents: 4b37b12 14a86a6
Author: huikyole <hu...@argo.jpl.nasa.gov>
Authored: Tue Oct 13 23:48:17 2015 -0700
Committer: huikyole <hu...@argo.jpl.nasa.gov>
Committed: Tue Oct 13 23:48:17 2015 -0700

----------------------------------------------------------------------
 ocw/data_source/local.py | 55 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)
----------------------------------------------------------------------