Example #1
0
        
    elif mode == 'convert_climatology':      
      
      
      # load dataset
      dataset = loadGPCC_LTM(varlist=['stations','precip'],resolution=res)
      # change meta-data
      dataset.name = 'GPCC'
      dataset.title = 'GPCC Long-term Climatology'
      dataset.atts.resolution = res      
      # load data into memory
      dataset.load()

      # add landmask
      addLandMask(dataset) # create landmask from precip mask
      dataset.mask(dataset.landmask) # mask all fields using the new landmask      
      # add length and names of month
      addLengthAndNamesOfMonth(dataset, noleap=False) 
      
      # figure out a different filename
      filename = getFileName(grid=res, period=None, name='GPCC', filepattern=avgfile)
      print('\n'+filename+'\n')      
      if os.path.exists(avgfolder+filename): os.remove(avgfolder+filename)      
      # write data and some annotation
      ncset = writeNetCDF(dataset, avgfolder+filename, close=False)
#       add_var(ncset,'name_of_month', name_of_month, 'time', # add names of month
#                  atts=dict(name='name_of_month', units='', long_name='Name of the Month')) 
       
      # close...
      ncset.close()
Example #2
0
    source = loadPCIC_LTM()
    # change meta-data
    source.name = 'PCIC'
    source.title = 'PCIC PRISM Climatology'
    # load data into memory (and ignore last time step, which is just the annual average)
#     source.load(time=(0,12)) # exclusive the last index
    source.load(time=(0,12)) # for testing
    # make normal dataset
    dataset = source.copy()
    source.close()
    
    ## add new variables
    # add landmask (it's not really a landmask, thought)
    maskatts = dict(name='datamask', units='', long_name='Mask for Climatology Fields', 
                description='where this mask is non-zero, no data is available')
    addLandMask(dataset, maskname='datamask',atts=maskatts) # create mask from precip mask
    dataset.mask(dataset.datamask) # mask all fields using the new data mask      
    # add length and names of month
    addLengthAndNamesOfMonth(dataset, noleap=False)       
    # add mean temperature
    T2 = dataset.Tmin + dataset.Tmax # average temperature is just the average between min and max
    T2 /= 2.
    T2.name = 'T2'; T2.atts.long_name='Average 2m Temperature'
    print(T2)
    dataset += T2 # add to dataset
    # rewrite time axis
    time = dataset.time
    time.load(data=np.arange(1,13))
    time.units = 'month'; time.atts.long_name='Month of the Year'
    print(time)
    # print diagnostic
Example #3
0
        # source.load(time=(0,12)) # exclusive the last index
        # N.B.: now we need to trim the files beforehand...
        # make normal dataset
        dataset = source.copy()
        source.close()

        ## add new variables
        # add landmask (it's not really a landmask, thought)
        dataset.precip.mask(
            maskValue=-9999.)  # mask all fields using the missing value flag
        maskatts = dict(
            name='datamask',
            units='',
            long_name='Mask for Climatology Fields',
            description='where this mask is non-zero, no data is available')
        addLandMask(dataset, maskname='datamask',
                    atts=maskatts)  # create mask from precip mask
        # add length and names of month
        addLengthAndNamesOfMonth(dataset, noleap=False)
        # add mean temperature
        T2 = dataset.Tmin + dataset.Tmax  # average temperature is just the average between min and max
        T2 /= 2.
        T2.name = 'T2'
        T2.atts.long_name = 'Average 2m Temperature'
        print(T2)
        dataset += T2  # add to dataset
        # rewrite time axis
        time = dataset.time
        time.load(data=np.arange(
            1, 13, dtype=time.dtype))  # 1 to 12 (incl.) for climatology
        time.units = 'month'
        time.atts.long_name = 'Month of the Year'
Example #4
0
            assert dataset.shape[0] == 1

        elif mode == 'convert_climatology':

            # load dataset
            dataset = loadGPCC_LTM(varlist=['stations', 'precip'],
                                   resolution=res)
            # change meta-data
            dataset.name = 'GPCC'
            dataset.title = 'GPCC Long-term Climatology'
            dataset.atts.resolution = res
            # load data into memory
            dataset.load()

            # add landmask
            addLandMask(dataset)  # create landmask from precip mask
            dataset.mask(
                dataset.landmask)  # mask all fields using the new landmask
            # add length and names of month
            addLengthAndNamesOfMonth(dataset, noleap=False)

            # figure out a different filename
            filename = getFileName(grid=res,
                                   period=None,
                                   name='GPCC',
                                   filepattern=avgfile)
            print('\n' + filename + '\n')
            if os.path.exists(avgfolder + filename):
                os.remove(avgfolder + filename)
            # write data and some annotation
            ncset = writeNetCDF(dataset, avgfolder + filename, close=False)