Merge branch 'CLIMATE-652'
Conflicts:
ocw/utils.py
Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/536aa3e6
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/536aa3e6
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/536aa3e6
Branch: refs/heads/master
Commit: 536aa3e64c84b8290d77204df2a58f3f9fea7ba1
Parents: 8656e32 3e9c310
Author: huikyole <[email protected]>
Authored: Sun Aug 2 20:37:24 2015 -0700
Committer: huikyole <[email protected]>
Committed: Sun Aug 2 20:37:24 2015 -0700
----------------------------------------------------------------------
ocw/utils.py | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/climate/blob/536aa3e6/ocw/utils.py
----------------------------------------------------------------------
diff --cc ocw/utils.py
index 0b2f9da,cc77437..3c7beb0
--- a/ocw/utils.py
+++ b/ocw/utils.py
@@@ -344,51 -344,28 +344,75 @@@ def calc_time_series(dataset)
return t_series
+def get_temporal_overlap(dataset_array):
+ ''' Find the maximum temporal overlap across the observation and model
datasets
+
+ :param dataset_array: an array of OCW datasets
+ '''
+ start_time =[]
+ end_time =[]
+ for dataset in dataset_array:
+ start_time.append(dataset.time_range()[0])
+ end_time.append(dataset.time_range()[1])
+
+ return np.max(start_time), np.min(end_time)
+
+def calc_subregion_area_mean_and_std(dataset_array, subregions):
+ ''' Calculate area mean and standard deviation values for a given
subregions using datasets on common grid points
+ :param dataset_array: An array of OCW Dataset Objects
+ :type list:
+ :param subregions: list of subregions
+ :type subregions: :class:`numpy.ma.array`
+ :returns: area averaged time series for the dataset of shape (ntime,
nsubregion)
+ '''
+
+ ndata = len(dataset_array)
+ dataset0 = dataset_array[0]
+ if dataset0.lons.ndim == 1:
+ lons, lats = np.meshgrid(dataset0.lons, dataset0.lats)
+ else:
+ lons = dataset0.lons
+ lats = dataset0.lats
+ subregion_array = np.zeros(lons.shape)
+ mask_array = dataset_array[0].values[0,:].mask
+ # dataset0.values.shsape[0]: length of the time dimension
+ # spatial average
+ t_series =ma.zeros([ndata, dataset0.values.shape[0], len(subregions)])
+ # spatial standard deviation
+ spatial_std =ma.zeros([ndata, dataset0.values.shape[0], len(subregions)])
+
+ for iregion, subregion in enumerate(subregions):
+ lat_min, lat_max, lon_min, lon_max = subregion[1]
+ y_index,x_index = np.where((lats >= lat_min) & (lats <= lat_max) &
(lons >= lon_min) & (lons <= lon_max))
+ subregion_array[y_index,x_index] = iregion+1
+ for idata in np.arange(ndata):
+ t_series[idata, :, iregion] =
ma.mean(dataset_array[idata].values[:,y_index, x_index], axis=1)
+ spatial_std[idata, :, iregion] =
ma.std(dataset_array[idata].values[:,y_index, x_index], axis=1)
+ subregion_array = ma.array(subregion_array, mask=mask_array)
+ return t_series, spatial_std, subregion_array
+
- >>>>>>> CLIMATE-651
+ def calc_area_weighted_spatial_average(dataset, area_weight=False):
+ '''Calculate area weighted average of the values in OCW dataset
+
+ :param dataset: Dataset object
+ :type dataset: :class:`dataset.Dataset`
+
+ :returns: time series for the dataset of shape (nT)
+ '''
+
+ if dataset.lats.ndim ==1:
+ lons, lats = np.meshgrid(dataset.lons, dataset.lats)
+ else:
+ lons = dataset.lons
+ lats = dataset.lats
+ weights = np.cos(lats*np.pi/180.)
+
+ nt, ny, nx = dataset.values.shape
+ spatial_average = ma.zeros(nt)
+ for it in np.arange(nt):
+ if area_weight:
+ spatial_average[it] = ma.average(dataset.values[it,:], weights =
weights)
+ else:
+ spatial_average[it] = ma.average(dataset.values[it,:])
+
+ return spatial_average