예제 #1
0
    def doStuff(self):
        
        self.outputGrid = np.zeros( ( len( self.years) * len( self.months),\
                                      self.nYOut, self.nXOut ), np.float32 )

        
        count = 0
        for self.year in self.years:
            self.leap = isLeap(self.year)
            for self.month in self.months:
                outputCount = np.zeros( ( self.nYOut, self.nXOut ), np.float32 )
                inputGrid = np.zeros( ( self.nYOut, self.nXOut ), np.uint16 )
                for self.day in daysAsNumbers( self.month, self.leap ):

                    self.inputGrid = self.readInput()
                    sliced = self.takeASlice() 
                    inputGrid += np.where(  sliced< 255,\
                                            sliced, 0)
                    outputCount += np.where( sliced < 255,\
                                             1.0, 0.0)

                self.outputGrid[ count, :, : ] = \
                                 np.where( outputCount > 0, \
                                           inputGrid.astype( np.float32)/\
                                           outputCount  / 200.0, -999.0)
                                               
                count += 1
        self.writeCDF()
예제 #2
0
    def mkTimeStamp(self):

        self.timeStamp = []

        for year in self.years:
            if isLeap( year): 
                nDaysYear = 366.0
            else:
                nDaysYear = 365.0
            daysSoFar = 1.0
            for month in self.months():
                if month in [ '01', '02', '11', '12']:
                    daysSoFar += \
                              len(daysAsNumbers(month,isLeap( year)))
                else:
                    for day in xrange( len( \
                        daysAsNumbers(month, isLeap( int(year)) ))):
                        self.timeStamp.append( year + str( daysSoFar / nDaysYear)[1:7])
                        daysSoFar += 1.0
예제 #3
0
    def doStuff(self):
        
        self.outputGrid = np.zeros( ( self.nTimesIn, self.nYOut, \
                                      self.nXOut ), np.uint8 )
        count = 0
        for self.year in self.years:
            self.leap = isLeap(self.year)
            for self.month in self.months:
                for self.day in daysAsNumbers( self.month, self.leap ):

                    self.inputGrid = self.readInput()

                    print( self.outputGrid[ count, :, : ].shape)
                    print( self.takeASlice().shape)

                    self.outputGrid[ count, :, : ] = self.takeASlice()

                    count += 1
        self.writeCDF()
예제 #4
0
    def doStuff(self):
        if self.fromScratch:
            self.readPoints()
            self.readPdef()
            self.allLST = self.outputArrayBig.copy()
            self.allCount = self.outputArrayBig.copy()
            self.tAirVec = np.zeros( ( self.nTimesIn,\
                                        len( self.points) ))
            self.tAir = self.outputArray.copy()
        
            count = 0
            for self.year in self.years:
            
                leap = isLeap(self.year)
            
                for self.month in self.months:

                    for self.day in daysAsNumbers( self.month, leap ):
## ##
## ##
                        outputGrid, outputCount, \
                                    forestGrid, forestCount,\
                                    urbanGrid, urbanCount,\
                                    cropGrid, cropCount,\
                                    otherGrid, otherCount\
                                    = self.readInput()
                        if  outputGrid.max() > 0.0:
                            self.allLST[count, :, :] += np.where( outputGrid > 0.0,\
                                                                  outputGrid, 0.0)
                            self.allCount[count, :, :] += np.where( outputGrid > 0.0,\
                                                                    1.0, 0.0)
                    
                    self.tAirVec[count, :] = self.readTair()
##                    printUsual( self.tAirVec[count, :])
                    count += 1
        self.regridTair()
        self.writeTairCDF()
        self.allLST = self.allLST / self.allCount
        self.writeModisCDF()
예제 #5
0
    forestGrid = np.zeros( ( p.nTimesIn, p.nYOut, p.nXOut ), np.float32 )
    forestCount = np.zeros( ( p.nTimesIn, p.nYOut, p.nXOut ), np.float32 )

    urbanGrid = np.zeros( ( p.nTimesIn, p.nYOut, p.nXOut ), np.float32 )
    urbanCount = np.zeros( ( p.nTimesIn, p.nYOut, p.nXOut ), np.float32 )

    cropGrid = np.zeros( ( p.nTimesIn, p.nYOut, p.nXOut ), np.float32 )
    cropCount = np.zeros( ( p.nTimesIn, p.nYOut, p.nXOut ), np.float32 )

    otherGrid = np.zeros( ( p.nTimesIn, p.nYOut, p.nXOut ), np.float32 )
    otherCount = np.zeros( ( p.nTimesIn, p.nYOut, p.nXOut ), np.float32 )
    
    count = 0
    for year in p.years:

        leap = isLeap(year)
        for month in p.months:
            for day in daysAsNumbers( month, leap ):
##
##

                print( count, p.nTimesIn)
                
                outputGrid[ count, :, : ], outputCount[ count, :, : ],\
                forestGrid[ count, :, : ], forestCount[ count, :, : ],\
                urbanGrid[ count, :, : ], urbanCount[ count, :, : ],\
                cropGrid[ count, :, : ], cropCount[ count, :, : ],\
                otherGrid[ count, :, : ], otherCount[ count, :, : ]\
                            = readInput()

예제 #6
0
    def gridData(self):
##
##  All Graham's files have the same start and end with
##  a combination of year and month in the middle        
        prefix = "Tair_EIHDEC_land_"
        suffix = ".nc"
##
        self.nDaysTotal = 0
        for year in self.years:
            self.griddedData[year] = {}
            for month in xrange(len(self.months)):
##            for month in xrange( 1):                
                self.griddedData[year][month] = []
                fName = self.dataRoot + \
                       prefix + year + self.months[month] + suffix
                print( fName)
## Does the file exist?
                try:
                    fid = Dataset( fName, "r")
##
## This will go in the try when it works
##                    
                    nDays = len(daysAsNumbers( self.months[month],\
                                       isLeap( int(year))))
                    localArray = np.zeros( (nDays, self.nYOut, self.nXOut)) - 999.0
##
                    for day in xrange( nDays):
                        self.nDaysTotal += 1
## there are eight timesteps in a day
## 0000 0300 0600 0900 1200 1500 1800 2100
###  0    1    2    3    4    5    6   7                        
##          and we are interested in the
##
##    0600, 0900 and 1200 steps.                    
                        startTime = day * 8 + 3
                        for point in xrange( len(self.mapping)):
##
## read the values in locally to make it explicit
                            inputVar = fid.variables["Tair"][ startTime: startTime + 3,self.mapping[point][4]]
##
## every three hours (the timestep of the input data) corresponds to 45 deg Longitude
## if the longitude is 0.0E then the required value is the mean of the 0900 and 1200
##  values                        

                            weight = 0.5 + self.mapping[point][3] / 45.0
                        
                            if self.mapping[point][3] <= 22.5:

                                localArray[ day, self.mapping[point][0],\
                                            self.mapping[point][1]] = \
                                            inputVar[1] *  weight + \
                                            inputVar[2] *  (1.0 - weight)
                            else:

                                weight = weight - np.fix( weight)
                            

                                localArray[ day, self.mapping[point][0],\
                                            self.mapping[point][1]] = \
                                            inputVar[1] *  ( 1.0- weight ) + \
                                            inputVar[0] *  weight

                    self.griddedData[year][month] = np.flipud(localArray)
  ##                  print( year, month, self.griddedData[year][month].shape)
                    fid.close()
                except:
                    print( "file not found")