Repository: climate Updated Branches: refs/heads/master aa7b8f4ce -> 434752cb5
CLIMATE-953 - Separate the module to calculate daily climatology from datast_processor.deseasonalize_dataset - An error about the output of dataset_processor.deseasonalize_dataset has been corrected - utils.calculate_daily_climatology 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/8a6bd201 Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/8a6bd201 Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/8a6bd201 Branch: refs/heads/master Commit: 8a6bd201eaa0d5ab1997ffbe2cf63d14c7771ef9 Parents: aa7b8f4 Author: huikyole <huiky...@argo.jpl.nasa.gov> Authored: Sat Jun 16 18:21:00 2018 -0700 Committer: huikyole <huiky...@argo.jpl.nasa.gov> Committed: Sat Jun 16 18:21:00 2018 -0700 ---------------------------------------------------------------------- ocw/dataset_processor.py | 2 +- ocw/utils.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/climate/blob/8a6bd201/ocw/dataset_processor.py ---------------------------------------------------------------------- diff --git a/ocw/dataset_processor.py b/ocw/dataset_processor.py index 423682c..8f3f82a 100755 --- a/ocw/dataset_processor.py +++ b/ocw/dataset_processor.py @@ -909,7 +909,7 @@ def deseasonalize_dataset(dataset): :param dataset: The dataset to convert. :type dataset: :class:`dataset.Dataset` - :returns: A Dataset with values converted to new units. + :returns: A Dataset with values deseasonalized. :rtype: :class:`dataset.Dataset` ''' http://git-wip-us.apache.org/repos/asf/climate/blob/8a6bd201/ocw/utils.py ---------------------------------------------------------------------- diff --git a/ocw/utils.py b/ocw/utils.py index 8f2c8c1..455c26d 100755 --- a/ocw/utils.py +++ b/ocw/utils.py @@ -711,3 +711,21 @@ def calculate_temporal_trend_of_time_series(x,y): ''' slope, intercept, r_value, p_value, std_err = stats.linregress(x,y) return slope, std_err + +def calculate_daily_climatology(dataset): + '''Calculate daily climatology from the input dataset + :param dataset: The dataset to convert. + :type dataset: :class:`dataset.Dataset` + :returns: values_clim + :rtype: 3d masked numpy array.shape (number of unique days, y, x) + ''' + + days = [d.month * 100. + d.day for d in dataset.times] + days_sorted = np.unique(days) + ndays = days_sorted.size + nt, ny, nx = dataset.values.shape + values_clim = ma.zeros([ndays, ny, nx]) + for iday, day in enumerate(days_sorted): + t_index = np.where(days == day)[0] + values_clim[iday, :] = ma.mean(dataset.values[t_index, :], axis=0) + return values_clim