You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@climate.apache.org by jo...@apache.org on 2013/09/11 22:26:13 UTC
svn commit: r1522023 - in /incubator/climate/trunk: ocw/dataset_processor.py
rcmet/src/main/python/rcmes/toolkit/process.py
Author: joyce
Date: Wed Sep 11 20:26:13 2013
New Revision: 1522023
URL: http://svn.apache.org/r1522023
Log:
CLIMATE-294 - Move datetime normalization code to dataset processor
Modified:
incubator/climate/trunk/ocw/dataset_processor.py
incubator/climate/trunk/rcmet/src/main/python/rcmes/toolkit/process.py
Modified: incubator/climate/trunk/ocw/dataset_processor.py
URL: http://svn.apache.org/viewvc/incubator/climate/trunk/ocw/dataset_processor.py?rev=1522023&r1=1522022&r2=1522023&view=diff
==============================================================================
--- incubator/climate/trunk/ocw/dataset_processor.py (original)
+++ incubator/climate/trunk/ocw/dataset_processor.py Wed Sep 11 20:26:13 2013
@@ -180,6 +180,64 @@ def subset(subregion, target_dataset):
target_dataset.name
)
+def normalize_dataset_datetimes(dataset, timestep):
+ ''' Normalize Dataset datetime values.
+
+ Force daily to an hour time value of 00:00:00.
+ Force monthly data to the first of the month at midnight.
+
+ :param dataset: The Dataset which will have its' time value normalized.
+ :type dataset: Dataset
+ :param timestep: The timestep of the Dataset's values. Either 'daily' or
+ 'monthly'.
+ :type timestep: String
+
+ :returns: A new Dataset with normalized datetimes.
+ '''
+ new_times = _rcmes_normalize_datetimes(dataset.times, timestep)
+ return ds.Dataset(
+ dataset.lats,
+ dataset.lons,
+ np.array(new_times),
+ dataset.values,
+ dataset.variable,
+ dataset.name
+ )
+
+def _rcmes_normalize_datetimes(datetimes, timestep):
+ """ Normalize Dataset datetime values.
+
+ Force daily to an hour time value of 00:00:00.
+ Force monthly data to the first of the month at midnight.
+
+ :param datetimes: The datetimes to normalize.
+ :type datetimes: List of `datetime` values.
+ :param timestep: The flag for how to normalize the datetimes.
+ :type timestep: String
+ """
+ normalDatetimes = []
+ if timestep.lower() == 'monthly':
+ for inputDatetime in datetimes:
+ if inputDatetime.day != 1:
+ # Clean the inputDatetime
+ inputDatetimeString = inputDatetime.strftime('%Y%m%d')
+ normalInputDatetimeString = inputDatetimeString[:6] + '01'
+ inputDatetime = datetime.datetime.strptime(normalInputDatetimeString, '%Y%m%d')
+
+ normalDatetimes.append(inputDatetime)
+
+ elif timestep.lower() == 'daily':
+ for inputDatetime in datetimes:
+ if inputDatetime.hour != 0 or inputDatetime.minute != 0 or inputDatetime.second != 0:
+ datetimeString = inputDatetime.strftime('%Y%m%d%H%M%S')
+ normalDatetimeString = datetimeString[:8] + '000000'
+ inputDatetime = datetime.datetime.strptime(normalDatetimeString, '%Y%m%d%H%M%S')
+
+ normalDatetimes.append(inputDatetime)
+
+
+ return normalDatetimes
+
def _rcmes_spatial_regrid(spatial_values, lat, lon, lat2, lon2, order=1):
'''
Spatial regrid from one set of lat,lon values onto a new set (lat2,lon2)
Modified: incubator/climate/trunk/rcmet/src/main/python/rcmes/toolkit/process.py
URL: http://svn.apache.org/viewvc/incubator/climate/trunk/rcmet/src/main/python/rcmes/toolkit/process.py?rev=1522023&r1=1522022&r2=1522023&view=diff
==============================================================================
--- incubator/climate/trunk/rcmet/src/main/python/rcmes/toolkit/process.py (original)
+++ incubator/climate/trunk/rcmet/src/main/python/rcmes/toolkit/process.py Wed Sep 11 20:26:13 2013
@@ -434,39 +434,9 @@ def ignore_boundaries(data, rim=10):
return data
def normalizeDatetimes(datetimes, timestep):
- """
- Input::
- datetimes - list of datetime objects that need to be normalized
- timestep - string of value ('daily' | 'monthly')
- Output::
- normalDatetimes - list of datetime objects that have been normalized
-
- Normalization Rules::
- Daily data will be forced to an hour value of 00:00:00
- Monthly data will be forced to the first of the month at midnight
- """
- normalDatetimes = []
- if timestep.lower() == 'monthly':
- for inputDatetime in datetimes:
- if inputDatetime.day != 1:
- # Clean the inputDatetime
- inputDatetimeString = inputDatetime.strftime('%Y%m%d')
- normalInputDatetimeString = inputDatetimeString[:6] + '01'
- inputDatetime = datetime.datetime.strptime(normalInputDatetimeString, '%Y%m%d')
-
- normalDatetimes.append(inputDatetime)
-
- elif timestep.lower() == 'daily':
- for inputDatetime in datetimes:
- if inputDatetime.hour != 0 or inputDatetime.minute != 0 or inputDatetime.second != 0:
- datetimeString = inputDatetime.strftime('%Y%m%d%H%M%S')
- normalDatetimeString = datetimeString[:8] + '000000'
- inputDatetime = datetime.datetime.strptime(normalDatetimeString, '%Y%m%d%H%M%S')
-
- normalDatetimes.append(inputDatetime)
-
-
- return normalDatetimes
+ """ This function has been moved to the ocw/dataset_processor module """
+ from ocw import dataset_processor as dsp
+ return dsp._rcmes_normalize_datetimes(datetimes, timestep)
def getModelTimes(modelFile, timeVarName):
'''