You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@climate.apache.org by go...@apache.org on 2017/04/17 20:52:05 UTC
climate git commit: ntime % nmonth should always be 0 for reshape /
rebin
Repository: climate
Updated Branches:
refs/heads/master 0ed13a19c -> 169f182b2
ntime % nmonth should always be 0 for reshape / rebin
Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/169f182b
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/169f182b
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/169f182b
Branch: refs/heads/master
Commit: 169f182b29191f9190ca4aa2a388005568556f18
Parents: 0ed13a1
Author: Alex Goodman <ag...@users.noreply.github.com>
Authored: Mon Apr 17 13:36:45 2017 -0700
Committer: Alex Goodman <ag...@users.noreply.github.com>
Committed: Mon Apr 17 13:36:45 2017 -0700
----------------------------------------------------------------------
ocw/dataset_processor.py | 9 +++++++--
ocw/utils.py | 33 +++++++++++++++++++--------------
2 files changed, 26 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/climate/blob/169f182b/ocw/dataset_processor.py
----------------------------------------------------------------------
diff --git a/ocw/dataset_processor.py b/ocw/dataset_processor.py
index a99cba9..db4a54f 100755
--- a/ocw/dataset_processor.py
+++ b/ocw/dataset_processor.py
@@ -77,7 +77,12 @@ def temporal_subset(target_dataset, month_start, month_end,
if average_each_year:
nmonth = len(month_index)
ntime = new_dataset.times.size
- nyear = ntime/nmonth
+ nyear = ntime // nmonth
+ if ntime % nmonth != 0:
+ raise ValueError("Number of times in dataset ({}) does not "
+ "divide evenly into {} year(s)."
+ .format(ntime, nyear))
+
averaged_time = []
ny, nx = target_dataset.values.shape[1:]
averaged_values = ma.zeros([nyear, ny, nx])
@@ -536,7 +541,7 @@ def temporal_slice(target_dataset, start_time, end_time):
target_dataset.lats,
target_dataset.lons,
new_times,
- new_values,
+ new_values,
variable=target_dataset.variable,
units=target_dataset.units,
origin=target_dataset.origin)
http://git-wip-us.apache.org/repos/asf/climate/blob/169f182b/ocw/utils.py
----------------------------------------------------------------------
diff --git a/ocw/utils.py b/ocw/utils.py
index 0d9eb4e..e9d8d75 100755
--- a/ocw/utils.py
+++ b/ocw/utils.py
@@ -272,7 +272,12 @@ def reshape_monthly_to_annually(dataset):
values = dataset.values[:]
data_shape = values.shape
num_total_month = data_shape[0]
- num_year = num_total_month/12
+ num_year = num_total_month // 12
+ if num_total_month % 12 != 0:
+ raise ValueError("Number of months in dataset ({}) does not "
+ "divide evenly into {} year(s)."
+ .format(num_total_month, num_year))
+
num_month = 12
year_month_shape = num_year, num_month
lat_lon_shape = data_shape[1:]
@@ -600,12 +605,12 @@ def propagate_spatial_mask_over_time(data_array, mask):
new_mask = mask
for it in np.arange(nt):
new_data_array[it,:] = ma.array(data_array[it,:],
- mask=new_mask)
+ mask=new_mask)
else:
for it in np.arange(nt):
new_mask = data_array[it, :].mask | mask
new_data_array[it,:] = ma.array(data_array[it,:],
- mask=new_mask)
+ mask=new_mask)
return new_data_array
@@ -628,7 +633,7 @@ def _force_unicode(s, encoding='utf-8'):
def calculate_temporal_trends(dataset):
''' Calculate temporal trends in dataset.values
:param dataset: The dataset from which time values should be extracted.
- :type dataset: :class:`dataset.Dataset'
+ :type dataset: :class:`dataset.Dataset'
:returns: Arrays of the temporal trend and standard error
:rtype: :class:`numpy.ma.core.MaskedArray`
@@ -640,19 +645,19 @@ def calculate_temporal_trends(dataset):
trend = np.zeros([ny, nx])-999.
slope_err = np.zeros([ny, nx])-999.
for iy in np.arange(ny):
- for ix in np.arange(nx):
- if dataset.values[:,iy,ix].count() == nt:
+ for ix in np.arange(nx):
+ if dataset.values[:,iy,ix].count() == nt:
trend[iy,ix], slope_err[iy,ix] = calculate_temporal_trend_of_time_series(
- x, dataset.values[:,iy,ix])
+ x, dataset.values[:,iy,ix])
- return ma.masked_equal(trend, -999.), ma.masked_equal(slope_err, -999.)
+ return ma.masked_equal(trend, -999.), ma.masked_equal(slope_err, -999.)
def calculate_ensemble_temporal_trends(timeseries_array, number_of_samples=1000):
- ''' Calculate temporal trends in an ensemble of time series
- :param timeseries_array: Two dimensional array. 1st index: model, 2nd index: time.
+ ''' Calculate temporal trends in an ensemble of time series
+ :param timeseries_array: Two dimensional array. 1st index: model, 2nd index: time.
:type timeseries_array: :class:`numpy.ndarray'
- :param sampling: A list whose elements are one-dimensional numpy arrays
+ :param sampling: A list whose elements are one-dimensional numpy arrays
:type timeseries_array: :class:`list'
:returns: temporal trend and estimated error from bootstrapping
@@ -676,13 +681,13 @@ def calculate_ensemble_temporal_trends(timeseries_array, number_of_samples=1000)
def calculate_temporal_trend_of_time_series(x,y):
''' Calculate least-square trends (a) in y = ax+b and a's standard error
:param x: time series
- :type x: :class:`numpy.ndarray'
+ :type x: :class:`numpy.ndarray'
:param x: time series
- :type x: :class:`numpy.ndarray'
+ :type x: :class:`numpy.ndarray'
:returns: temporal trend and standard error
:rtype: :float:`float','float'
'''
slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)
- return slope, std_err
+ return slope, std_err