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-687 - A new loader to read GPM precipitation data with a file list
Date Thu, 22 Oct 2015 00:55:37 GMT
Repository: climate
Updated Branches:
  refs/heads/master 6d5c7f8aa -> 360b5728f


CLIMATE-687 - A new loader to read GPM precipitation data with a file list

- ocw.data_source.local.load_GPM_IMERG_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/74a8bffa
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/74a8bffa
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/74a8bffa

Branch: refs/heads/master
Commit: 74a8bffa0313f16a562f3355f0332351a4f7770d
Parents: ece260d
Author: huikyole <huikyole@argo.jpl.nasa.gov>
Authored: Thu Oct 8 18:07:50 2015 -0700
Committer: huikyole <huikyole@argo.jpl.nasa.gov>
Committed: Thu Oct 8 18:07:50 2015 -0700

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


http://git-wip-us.apache.org/repos/asf/climate/blob/74a8bffa/ocw/data_source/local.py
----------------------------------------------------------------------
diff --git a/ocw/data_source/local.py b/ocw/data_source/local.py
index 60fcb50..272402e 100644
--- a/ocw/data_source/local.py
+++ b/ocw/data_source/local.py
@@ -330,3 +330,59 @@ def load_multiple_files(file_path,
                         lat_name=lat_name, lon_name=lon_name, time_name=time_name))
     
     return datasets, data_name
+
+def load_GPM_IMERG_files(file_path=None,
+                      filename_pattern=None,
+                      filelist=None,
+                      variable_name='precipitationCal',
+                      name='GPM_IMERG'):
+    ''' Load multiple GPM Level 3 IMEGE files containing calibrated precipitation and generate
an OCW Dataset obejct.
+    :param file_path: Directory to the HDF files to load.
+    :type file_path: :mod:`string`
+    :param filename_pattern: Path to the HDF files 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 HDF 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 HDF file.
+    :rtype: :class:`dataset.Dataset`
+    :raises ValueError:
+    '''
+
+    if not filelist:
+        GPM_files = []
+        for pattern in filename_pattern:
+            GPM_files.extend(glob(file_path + pattern))
+    else:
+        GPM_files = [line.rstrip('\n') for line in open(filelist)]
+
+    GPM_files.sort()
+
+    file_object_first = h5py.File(GPM_files[0])
+    lats = file_object_first['Grid']['lat'][:]
+    lons = file_object_first['Grid']['lon'][:]
+
+    lons, lats = numpy.meshgrid(lons, lats)
+
+    variable_unit = "mm/hr"
+
+    times = []
+    nfile = len(GPM_files)
+    for ifile, file in enumerate(GPM_files):
+        print 'Reading file '+str(ifile+1)+'/'+str(nfile), file
+        file_object = h5py.File(file)
+        time_struct_parsed = strptime(file[-39:-23],"%Y%m%d-S%H%M%S")
+        times.append(datetime(*time_struct_parsed[:6]))
+        values0= numpy.transpose(ma.masked_less(file_object['Grid'][variable_name][:], 0.))
+        values0= numpy.expand_dims(values0, axis=0)
+        if ifile == 0:
+            values = values0
+        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)


Mime
View raw message