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/13 23:09:14 UTC
[1/3] climate git commit: CLIMATE-680 - A new loader to read WRF
precipitation data with a file list
Repository: climate
Updated Branches:
refs/heads/master ece260d1c -> 38a38ff5f
CLIMATE-680 - A new loader to read WRF precipitation data with a file list
- ocw.data_source.local.load_WRF_2d_files_RAIN has been added
Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/26c977a3
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/26c977a3
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/26c977a3
Branch: refs/heads/master
Commit: 26c977a3403e936111f9212286a7fdad00e1f84b
Parents: 9263dc6
Author: Huikyo Lee <hl...@discover25.prv.cube>
Authored: Wed Oct 7 01:51:24 2015 -0400
Committer: Huikyo Lee <hl...@discover25.prv.cube>
Committed: Wed Oct 7 01:51:24 2015 -0400
----------------------------------------------------------------------
ocw/data_source/local.py | 64 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 64 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/climate/blob/26c977a3/ocw/data_source/local.py
----------------------------------------------------------------------
diff --git a/ocw/data_source/local.py b/ocw/data_source/local.py
index 60fcb50..bbc0216 100644
--- a/ocw/data_source/local.py
+++ b/ocw/data_source/local.py
@@ -330,3 +330,67 @@ def load_multiple_files(file_path,
lat_name=lat_name, lon_name=lon_name, time_name=time_name))
return datasets, data_name
+
+def load_WRF_2d_files_RAIN(file_path=None,
+ filename_pattern=None,
+ filelist=None,
+ 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.
+ :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 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:
+ WRF_files = []
+ for pattern in filename_pattern:
+ WRF_files.extend(glob(file_path + pattern))
+ WRF_files.sort()
+ else:
+ WRF_files=[line.rstrip('\n') for line in open(filelist)]
+
+ 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 'NC file '+str(ifile+1)+'/'+str(nfile)
+ file_object = netCDF4.Dataset(file)
+ time_struct_parsed = strptime(file[-19:],"%Y-%m-%d_%H:%M:%S")
+ for ihour in range(24):
+ times.append(datetime(*time_struct_parsed[:6]) + timedelta(hours=ihour))
+ if ifile == 0:
+ values0= file_object.variables['RAINC'][:]+file_object.variables['RAINNC'][:]
+ else:
+ values0= numpy.concatenate((values0, file_object.variables['RAINC'][:]+file_object.variables['RAINNC'][:]))
+ file_object.close()
+ times= numpy.array(times)
+ years = numpy.array([d.year for d in times])
+ ncycle = numpy.unique(years).size
+ print 'ncycle=',ncycle
+ nt, ny, nx = values0.shape
+ values = numpy.zeros([nt-ncycle*24, ny, nx])
+ times2 = []
+ nt2 = nt/ncycle
+ # remove the first day in each year
+ nt3 = nt2-24
+ t_index = 0
+ for icycle in numpy.arange(ncycle):
+ for it in numpy.arange(nt3)+24:
+ values[t_index,:] = values0[icycle*nt2+it,:]-values0[icycle*nt2+it-1,:]
+ times2.append(times[icycle*nt2+it])
+ t_index = t_index +1
+ variable_name = 'PREC'
+ variable_unit= 'mm/hr'
+ times2 = numpy.array(times2)
+ return Dataset(lats, lons, times2, values, variable_name, units=variable_unit, name=name)
[3/3] climate git commit: CLIMATE-680 - A new loader to read WRF
precipitation data with a filelist
Posted by hu...@apache.org.
CLIMATE-680 - A new loader to read WRF precipitation data with a filelist
- ocw.data_source.local.load_WRF_2d_files_RAIN has been added
Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/38a38ff5
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/38a38ff5
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/38a38ff5
Branch: refs/heads/master
Commit: 38a38ff5f007b5bfd71bc3ea4bfdd0b199eacf41
Parents: ece260d 7ce0e83
Author: huikyole <hu...@argo.jpl.nasa.gov>
Authored: Tue Oct 13 14:08:41 2015 -0700
Committer: huikyole <hu...@argo.jpl.nasa.gov>
Committed: Tue Oct 13 14:08:41 2015 -0700
----------------------------------------------------------------------
ocw/data_source/local.py | 64 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 64 insertions(+)
----------------------------------------------------------------------
[2/3] climate git commit: modified the message showing reading
progress
Posted by hu...@apache.org.
modified the message showing reading progress
Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/7ce0e83f
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/7ce0e83f
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/7ce0e83f
Branch: refs/heads/master
Commit: 7ce0e83f476f4a31596bc9acbb41e5762716af84
Parents: 26c977a
Author: Huikyo Lee <hl...@discover25.prv.cube>
Authored: Wed Oct 7 03:16:08 2015 -0400
Committer: Huikyo Lee <hl...@discover25.prv.cube>
Committed: Wed Oct 7 03:16:08 2015 -0400
----------------------------------------------------------------------
ocw/data_source/local.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/climate/blob/7ce0e83f/ocw/data_source/local.py
----------------------------------------------------------------------
diff --git a/ocw/data_source/local.py b/ocw/data_source/local.py
index bbc0216..63f70c0 100644
--- a/ocw/data_source/local.py
+++ b/ocw/data_source/local.py
@@ -364,7 +364,7 @@ def load_WRF_2d_files_RAIN(file_path=None,
times = []
nfile = len(WRF_files)
for ifile, file in enumerate(WRF_files):
- print 'NC file '+str(ifile+1)+'/'+str(nfile)
+ 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 range(24):