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: Added: ocw.dataset_processor.variable_unit_conversion
Date Mon, 03 Aug 2015 03:38:21 GMT
Repository: climate
Updated Branches:
  refs/heads/master 536aa3e64 -> d4eeb03ee


Added: ocw.dataset_processor.variable_unit_conversion


Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/3b297dbf
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/3b297dbf
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/3b297dbf

Branch: refs/heads/master
Commit: 3b297dbf29e789f4aec46e5f2f3ea151d9e14372
Parents: 83d83ba
Author: huikyole <huikyole@argo.jpl.nasa.gov>
Authored: Thu Jul 30 16:37:34 2015 -0700
Committer: huikyole <huikyole@argo.jpl.nasa.gov>
Committed: Thu Jul 30 16:37:34 2015 -0700

----------------------------------------------------------------------
 ocw/dataset_processor.py | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/3b297dbf/ocw/dataset_processor.py
----------------------------------------------------------------------
diff --git a/ocw/dataset_processor.py b/ocw/dataset_processor.py
index 984e142..2a8602c 100755
--- a/ocw/dataset_processor.py
+++ b/ocw/dataset_processor.py
@@ -421,7 +421,42 @@ def water_flux_unit_conversion(dataset):
                 dataset.units = 'mm/day'
 
     return dataset
+def variable_unit_conversion(dataset):
+    ''' Convert water flux or temperature variables units as necessary
+    
+    For water flux variables, convert full SI units water flux units to more common units.
+    For temperature, convert Celcius to Kelvin.
+
+    :param dataset: The dataset to convert.
+    :type dataset: :class:`dataset.Dataset`
 
+    :returns: A Dataset with values converted to new units.
+    :rtype: :class:`dataset.Dataset`
+    '''
+
+    water_flux_variables = ['pr', 'prec','evspsbl', 'mrro', 'swe']
+    temperature_variables = ['temp','tas','tasmax','taxmin','T']
+    variable = dataset.variable.lower()
+
+    if any(subString in variable for subString in water_flux_variables):
+        dataset_units = dataset.units.lower()
+        if variable in 'swe':
+            if any(unit in dataset_units for unit in ['m', 'meter']):
+                dataset.values = 1.e3 * dataset.values
+                dataset.units = 'km'
+        else:
+            if any(unit in dataset_units
+                for unit in ['kg m-2 s-1', 'mm s-1', 'mm/sec']):
+                    dataset.values = 86400. * dataset.values
+                    dataset.units = 'mm/day'
+
+    if any(subString in variable for subString in temperature_variables):
+        dataset_units = dataset.units.lower()
+        if dataset_units == 'c':
+            dataset.values = 273.15+dataset.values
+            dataset.units = 'K'
+
+    return dataset
 
 def _rcmes_normalize_datetimes(datetimes, timestep):
     """ Normalize Dataset datetime values.


Mime
View raw message