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
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 @@
: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`
'''
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 @@
'''
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