You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@climate.apache.org by go...@apache.org on 2013/08/13 03:47:53 UTC

svn commit: r1513313 - /incubator/climate/branches/RefactorInput/rcmet/src/main/python/rcmes/toolkit/do_data_prep.py

Author: goodale
Date: Tue Aug 13 01:47:53 2013
New Revision: 1513313

URL: http://svn.apache.org/r1513313
Log:
Patching the Refactor Branch with CLIMATE-250 Fix.

Modified:
    incubator/climate/branches/RefactorInput/rcmet/src/main/python/rcmes/toolkit/do_data_prep.py

Modified: incubator/climate/branches/RefactorInput/rcmet/src/main/python/rcmes/toolkit/do_data_prep.py
URL: http://svn.apache.org/viewvc/incubator/climate/branches/RefactorInput/rcmet/src/main/python/rcmes/toolkit/do_data_prep.py?rev=1513313&r1=1513312&r2=1513313&view=diff
==============================================================================
--- incubator/climate/branches/RefactorInput/rcmet/src/main/python/rcmes/toolkit/do_data_prep.py (original)
+++ incubator/climate/branches/RefactorInput/rcmet/src/main/python/rcmes/toolkit/do_data_prep.py Tue Aug 13 01:47:53 2013
@@ -244,29 +244,14 @@ def prep_data(settings, obsDatasetList, 
 
     obsData = ma.array(regObsData)
     obsTimes = newObsTimes
-    regObsData = 0
-    oldObsTimes = 0
-    nT = len(obsTimes)
 
-    # TODO:  Refactor this into a function within the toolkit module
     # compute the simple multi-obs ensemble if multiple obs are used
     if numOBSs > 1:
-        print 'numOBSs = ', numOBSs
-        oData = obsData
-        print 'oData shape = ', oData.shape
-        obsData = ma.zeros((numOBSs + 1, nT, ngrdY, ngrdX))
-        print 'obsData shape = ', obsData.shape
-        avg = ma.zeros((nT, ngrdY, ngrdX))
-        
-        for i in np.arange(numOBSs):
-            obsData[i, :, :, :] = oData[i, :, :, :]
-            avg[:, :, :] = avg[:, :, :] + oData[i, :, :, :]
-
-        avg = avg / float(numOBSs)
-        obsData[numOBSs, :, :, :] = avg[:, :, :]     # store the model-ensemble data
-        numOBSs = numOBSs + 1                     # update the number of obs data to include the model ensemble
+        ensemble = np.mean(regObsData, axis=0)
+        regObsData.append(ensemble)
+        numOBSs = len(regObsData)
         obsList.append('ENS-OBS')
-    print 'OBS regridded: ', obsData.shape
+        obsData = ma.array(regObsData) # Cast to a masked array
 
 
     ## Part 2: load in and regrid model data from file(s)
@@ -311,11 +296,7 @@ def prep_data(settings, obsDatasetList, 
    
         # determine the dimension size from the model time and latitude data.
         nT = len(modelTimes)
-        
-        # UNUSED VARIABLES - WILL DELETE AFTER TESTING
-        # nmdlY=modelLats.shape[0]
-        # nmdlX=modelLats.shape[1]
-        #print 'nT, ngrdY, ngrdX = ',nT,ngrdY, ngrdX,min(modelTimes),max(modelTimes)
+
         print '  The shape of model data to be processed= ', mData.shape, ' for the period ', min(modelTimes), max(modelTimes)
         # spatial regridding of the modl data
         tmpMDL = ma.zeros((nT, ngrdY, ngrdX))
@@ -345,10 +326,7 @@ def prep_data(settings, obsDatasetList, 
         regridMdlData.append(mData)
 
     modelData = ma.array(regridMdlData)
-    modelTimes = newMdlTimes
-    regridMdlData = 0
-    oldMdlTimes = 0
-    newMdlTimes = 0
+
     if (precipFlag == True) & (mvUnit == 'KG M-2 S-1'):
         print 'convert model variable unit from mm/s to mm/day'
         modelData = 86400.*modelData
@@ -370,25 +348,15 @@ def prep_data(settings, obsDatasetList, 
 
     print 'Reading and regridding model data are completed'
     print 'numMDLs, modelData.shape= ', numMDLs, modelData.shape
-    
-    # TODO: Do we need to make this a user supplied flag, or do we just create an ensemble ALWAYS
-    # TODO: Add in Kyo's code here as well
+
     # TODO:  Commented out until I can talk with Jinwon about this
     # compute the simple multi-model ensemble if multiple models are evaluated
     if numMDLs > 1:
-        mdlData=modelData
-        modelData=ma.zeros((numMDLs+1,nT,ngrdY,ngrdX))
-        avg=ma.zeros((nT,ngrdY,ngrdX))
-        for i in np.arange(numMDLs):
-            modelData[i,:,:,:]=mdlData[i,:,:,:]
-            avg[:,:,:]=avg[:,:,:]+mdlData[i,:,:,:]
-        avg=avg/float(numMDLs)
-        modelData[numMDLs,:,:,:]=avg[:,:,:]     # store the model-ensemble data
-        # THESE ARE NOT USED.  WILL DELETE AFTER TESTING
-        # i0mdl=0
-        # i1mdl=numMDLs
-        numMDLs=numMDLs+1
-        mdlList.append('ENS-MODEL')
+        model_ensemble = np.mean(regridMdlData, axis=0)
+        regridMdlData.append(model_ensemble)
+        numMDLs = len(regridMdlData)
+        modelData = ma.array(regridMdlData)
+        mdlName.append('ENS-MODEL')
         print 'Eval mdl-mean timeseries for the obs periods: modelData.shape= ',modelData.shape
     # GOODALE:  This ensemble code should be refactored into process.py module since it's purpose is data processing