コード例 #1
0
ファイル: functions_06.py プロジェクト: Potopoles/MScTh
 def loadField(self, fileName, varName):
     inpFilePath = self.inpPath + '/' + self.res + self.mode + '/' + fileName
     VAR = ncObject.ncObject(inpFilePath, varName, self.res)
     VAR.selField(varName)
     VAR.selSubspace(self.subSpaceInds)
     VAR.loadField()
     var = VAR.curFld.vals
     return (VAR, var)
コード例 #2
0
    def run(self):
        self.set_resolutions()
        
        # CREATE KEYS OF ALL ncObjects TO CREATE FOR EACH VARIABLE.
        self.ncoKeys = []
        self.dxs = []
        for res in self.resolutions:
            for mode in self.modes:
                self.ncoKeys.append(mode+res)
                self.dxs.append(float(res))

        # LOOP THROUGH VARIABLE NAMES TO FILL variables WITH ncObjects
        for i,vN in enumerate(self.varNames):
            starttimeVar = timer()
            
            if self.i_info >= 1:
                print(vN)
                
            ## LOOP THROUGH ncoKeys TO CREATE ncObjects
            for j,ncoKey in enumerate(self.ncoKeys):
                
                if self.i_info >= 2:
                    print('\t'+ncoKey)
                
                # LOAD ncObject
                if self.i_info >= 3:
                    print('\t\tload models')

                # TODO quick fix
                #if ncoKey in ['SM1', 'RAW1']:
                #    #inpFilePath = self.inpPath + '/' + ncoKey+'_1' + '/' + self.inpFileNames[i]
                #    #inpFilePath = self.inpPath + '/' + ncoKey+'_2' + '/' + self.inpFileNames[i]
                #    inpFilePath = self.inpPath + '/' + ncoKey+'_3' + '/' + self.inpFileNames[i]
                #else:
                #    inpFilePath = self.inpPath + '/' + ncoKey + '/' + self.inpFileNames[i]
                # TODO old version
                inpFilePath = self.inpPath + '/' + ncoKey + '/' + self.inpFileNames[i]
                name = ncoKey
                self.vars[vN].ncos[ncoKey] = ncObject.ncObject(inpFilePath,
                                                self.dxs[j], fieldName=vN[1:])
                nco = self.vars[vN].ncos[ncoKey]

                if self.i_info >= 3:
                    print('\t\tdim subspace')
                nco.subSpaceInds = self._setSubspaceInds(
                                            self.subSpaceInds, self.dxs[j])
                nco.cutDimsToSubSpace() 

                # AGGREGATE
                if self.i_info >= 3:
                    print('\t\taggregate')
                nco.prepareAggregate(self.ag_commnds)
        
                # LOAD FIELDS
                if self.i_info >= 3:
                    print('\t\tload fields')
                nco.loadValuesOfField()

        if self.i_info >= 1:
            endtimeVar = timer()
            print('#######################################################')
            print('elapsed time:\t\t\t\t\t' + str(np.round(endtimeVar - starttimeVar)) + ' s')
コード例 #3
0
elif i_resolution == 3:
    ress = ['4.4', '2.2', '1.1']

subSpaceIndsIN = {}
from shutil import copyfile

for fieldName in fieldNames:
    print(fieldName)
    inpFileName = fieldName + '.nc'

    for res in ress:
        for mode in modes:
            print(str(res) + mode)

            varName = fieldName[1:]

            inpFilePath = inpPath + '/' + res + mode + '/' + fieldName + '.nc'
            inpTopoFilePath = inpPath + '/' + res + mode + '/' + 'cHSURF' + '.nc'
            outFilePath = outPath + '/' + res + mode + '/' + fieldName + '.nc'

            if i_copy:
                print('\tCOPY')
                copyfile(inpFilePath, outFilePath)

            print('\tPROCESS')
            nco = ncObject.ncObject(outFilePath, fieldName, res)
            topo = ncObject.ncObject(inpTopoFilePath, 'cHSURF', res)
            nco.selField(varName)
            topo.selField('HSURF')
            nco.cutOutTopo(topo)
コード例 #4
0
    'RAW1_1': 1.1,
    'SM1_1': 1.1,
    'RAW1_2': 1.1,
    'SM1_2': 1.1,
    'RAW1_3': 1.1,
    'SM1_3': 1.1,
    'OBS1': 1.1,
}

for fieldName in fieldNames:
    print(fieldName)
    for model in models:
        print(model)

        varName = fieldName[1:]

        inpFilePath = inpPath + '/' + model + '/' + fieldName + '.nc'
        outFilePath = outPath + '/' + model + '/' + fieldName + '.nc'

        nco = ncObject.ncObject(inpFilePath, dx[model], fieldName[1:])

        #nco.selField(varName)
        if fieldName in 'nTOT_PREC':
            nco.load_as_diurnal('SUM')
        else:
            nco.load_as_diurnal('MEAN')
        # SAVE FILE
        if os.path.exists(outFilePath):
            os.remove(outFilePath)
        nco.saveToNewNC(outFilePath)