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:10:34 UTC
[1/3] climate git commit: CLIMATE-681 - Update the loader to read WRF
data (other than precipitation)
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 <hl...@discover25.prv.cube>
Authored: Wed Oct 7 03:06:39 2015 -0400
Committer: Huikyo Lee <hl...@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,
[2/3] climate git commit: code clean up
Posted by hu...@apache.org.
code clean up
Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/6b9df272
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/6b9df272
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/6b9df272
Branch: refs/heads/master
Commit: 6b9df272374690a87458f87fe66cb4a6bf8cb040
Parents: b471b45
Author: Huikyo Lee <hl...@discover28.prv.cube>
Authored: Wed Oct 7 19:47:01 2015 -0400
Committer: Huikyo Lee <hl...@discover28.prv.cube>
Committed: Wed Oct 7 19:47:01 2015 -0400
----------------------------------------------------------------------
ocw/data_source/local.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/climate/blob/6b9df272/ocw/data_source/local.py
----------------------------------------------------------------------
diff --git a/ocw/data_source/local.py b/ocw/data_source/local.py
index 1c83d8f..a12841c 100644
--- a/ocw/data_source/local.py
+++ b/ocw/data_source/local.py
@@ -158,10 +158,10 @@ def load_WRF_2d_files(file_path=None,
times.append(datetime(*time_struct_parsed[:6]) + timedelta(hours=ihour))
values0= file_object.variables[variable_name][:]
if ifile == 0:
- values = file_object.variables[variable_name][:]
+ values = values0
variable_unit = file_object.variables[variable_name].units
else:
- values = numpy.concatenate((values, file_object.variables[variable_name][:]))
+ 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)
[3/3] climate git commit: CLIMATE-681 - Update the loader to read WRF
data
Posted by hu...@apache.org.
CLIMATE-681 - Update the loader to read WRF data
- 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/d49c5677
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/d49c5677
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/d49c5677
Branch: refs/heads/master
Commit: d49c5677d6ad485149c1cb487b87ae72eb3ab142
Parents: 38a38ff 6b9df27
Author: huikyole <hu...@argo.jpl.nasa.gov>
Authored: Tue Oct 13 14:10:00 2015 -0700
Committer: huikyole <hu...@argo.jpl.nasa.gov>
Committed: Tue Oct 13 14:10:00 2015 -0700
----------------------------------------------------------------------
ocw/data_source/local.py | 36 +++++++++++++++++++++++-------------
1 file changed, 23 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/climate/blob/d49c5677/ocw/data_source/local.py
----------------------------------------------------------------------