climate-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From huiky...@apache.org
Subject [1/2] climate git commit: CLIMATE-850 - Precipitation intensity and duration analyzer using hourly data
Date Tue, 16 Aug 2016 15:51:04 GMT
Repository: climate
Updated Branches:
  refs/heads/master 43b04e4f0 -> 817c854ba


CLIMATE-850 - Precipitation intensity and duration analyzer using hourly data

- metrics.wet_spell_analysis 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/111d3a4b
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/111d3a4b
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/111d3a4b

Branch: refs/heads/master
Commit: 111d3a4bce322226807e334b0a35ba8bbec9e4f5
Parents: 9115096
Author: huikyole <huikyole@argo.jpl.nasa.gov>
Authored: Mon Aug 15 21:04:28 2016 -0700
Committer: huikyole <huikyole@argo.jpl.nasa.gov>
Committed: Mon Aug 15 21:04:28 2016 -0700

----------------------------------------------------------------------
 ocw/metrics.py | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/111d3a4b/ocw/metrics.py
----------------------------------------------------------------------
diff --git a/ocw/metrics.py b/ocw/metrics.py
index 62f4e3d..e29dc74 100644
--- a/ocw/metrics.py
+++ b/ocw/metrics.py
@@ -346,3 +346,47 @@ def calc_rmse(target_array, reference_array):
     '''
 
     return (ma.mean((calc_bias(target_array, reference_array))**2))**0.5 
+
+def wet_spell_analysis(reference_array, threshold=0.1, nyear=1, dt=3.):
+    ''' Characterize wet spells using sub-daily (hourly) data
+
+    :param reference_array: an array to be analyzed
+    :type reference_array: :class:'numpy.ma.core.MaskedArray'
+
+    :param threshold: the minimum amount of rainfall [mm/hour] 
+    :type threshold: 'float'
+
+    :param nyear: the number of discontinous periods 
+    :type nyear: 'int'
+
+    :param dt: the temporal resolution of reference_array
+    :type dt: 'float'
+    '''
+    nt = reference_array.shape[0]
+    if reference_array.ndim == 3:
+        reshaped_array = reference_array.reshape[nt, reference_array.size/nt]
+    else:
+        reshaped_array = reference_array
+    xy_indices = np.where(reshaped_array.mask[0,:] == False)[0]
+
+    nt_each_year = nt/nyear 
+    spell_duration = []
+    peak_rainfall = []
+    total_rainfall = []
+   
+    for index in xy_indices:
+        for iyear in np.arange(nyear):
+            data0_temp = reshaped_array[nt_each_year*iyear:nt_each_year*(iyear+1),
+                                        index] 
+            # time indices when precipitation rate is smaller than the threshold [mm/hr]
+            t_index = np.where((data0_temp <= threshold) & (data0_temp.mask ==False))[0]
+            t_index = np.insert(t_index, 0, 0)
+            t_index = t_index + nt_each_year*iyear
+            for it in np.arange(t_index.size-1):
+                if t_index[it+1] - t_index[it] >1:
+                    data1_temp = data0_temp[t_index[it]+1:t_index[it+1]]
+                    if not ma.is_masked(data1_temp):
+                        spell_duration.append((t_index[it+1]-t_index[it]-1)*dt)
+                        peak_rainfall.append(data1_temp.max())
+                        total_rainfall.append(data1_temp.sum())
+    return np.array(spell_duration), np.array(peak_rainfall), np.array(total_rainfall)


Mime
View raw message