Example #1
0
DirO = DirO + '/' + name + '_' + str(startyr) + '-' + str(endyr) + '/'

# Convert thresholds if necessary

nThresh = len(Threshold)
if precipunit == 'mm/day':
    Thresh = Threshold
elif precipunit == 'mm/hr':
    Thresh = [x / 24.0 for x in Threshold]  # convert to mm/hr
else:
    exit("unexpected precipunit " + precipunit)

# Read in precip data
print Dir + Filein
precipin = xrayOpen(Dir + Filein)

latsin = precipin[latvar][:]
lonsin = precipin[lonvar][:]
precipnew = precipin[precipvar]

nlons = len(lonsin)
nlats = len(latsin)
ntimes = len(precipnew.time)
print ntimes
chunksize = 10000

print "Hold on, I'm calculating the total amount of precip missed by your chosen thresholds, estimating the value using the first year"
check = query_yes_no("Do you want to confirm whether or not it's acceptable?")

lowestTH = Thresh[0]
    DirI = ('/home/disk/eos4/rachel/EventTracking/FiT_RW_ERA/CESM_output/' +
            Version + str(startyr) + '/proc/')
    FileInLats = ('/home/disk/eos4/rachel/EventTracking/Inputs/CESM/'
                    'f.e13.FAMPIC5.ne120_ne120.1979_2012.001/'
                    'f.e13.FAMIPC5.ne120_ne120_TotalPrecip_1979-2012.nc')
else:
    print("unexpected data type")
    exit()

DirO = DirI + diradd + '/'


# In[4]:

#Get lons and lats
FileIn = xrayOpen(FileInLats)

if Data == "CESM":
    lats = FileIn['lat'].values
    lons = FileIn['lon'].values
elif Data in ["ERA20C","TRMMERAIgd"]:
        lats = FileIn['latitude'].values
        lons = FileIn['longitude'].values
else:
    lats = FileIn['Latitude'].values
    lons = FileIn['Longitude'].values

nlats = len(lats)
nlons = len(lons)

# initialize data
Example #3
0
def initialize(name, dims, atype):
    # globals used to create global object
    globals()[name] = np.zeros(dims, atype)


def resetvar(name):
    globals()[name][...] = 0


def delvar(name):
    del (name)


# Common to all tbounds
griddata = xrayOpen(DirP + Filegrid)
SurfA = griddata['SurfaceArea']

eventsdata = xrayOpen(DirEv + FileEv)
eventsin = eventsdata['value']
ntimes = eventsdata.time.size

precipdata = xrayOpen(DirP + FileP)
if Data in ["TRMM", "TRMMERAIgd"]:
    precipin = precipdata['pcp']

elif Data in ["ERAI", "ERA20C"]:
    precipin = precipdata['tpnew']
elif Data == "CESM":
    precipin = precipdata['PRECT'].sel(time=slice(str(startyr), str(endyr)))
DirO = '/home/disk/eos4/rachel/EventTracking/FiT_RW_ERA/' + Data + '_output/' + Version + str(
    startyr) + '/proc/'
FileO = 'All_Precip_' + str(startyr) + '-' + str(
    endyr) + '_' + Data + '_' + Version + '.nc'

# If output directory doesn't exist, create it!
if not os.path.exists(DirO):
    os.makedirs(DirO)

if args.test == 1:
    FileO = FileO + "_test.nc"

print FileO

precipdata = xrayOpen(DirP + FileP)
# Open surface area grid:
griddata = xrayOpen(DirP + Filegrid)
SurfA = griddata['SurfaceArea']

# Open precip file for latitudes
if Data in ["CESM", 'GPCP']:
    lons = precipdata['lon'].values
    lats = precipdata['lat'].values
else:
    lons = precipdata['longitude'].values
    lats = precipdata['latitude'].values

nlats = lats.shape[0]
nlons = lons.shape[0]
Example #5
0
# pre-defined variables, including file names and directories
startyr = 1979
endyr = 2015
nyears = endyr - startyr + 1

Dir = '/home/disk/eos4/rachel/Obs/ERAI/'
filename = ('ERAI_monthlymeans_DJF_' + str(startyr) + '-' + str(endyr) + '.nc')

# constants
a = 6.37122e06  # radius of Earth
a2 = math.pow(a, 2)
omega = 7.2921e-5  # rotation rate of earth
g = 9.80616

datain = xrayOpen(Dir + filename)
uIn = datain['u'].sel(level=ilev)  # read in U at level ilev
latsIn = uIn.coords['latitude']
lonsIn = uIn.coords['longitude']
if lonsIn[-1] - lonsIn[1] < 358:
    exit('caution, not a global grid, and this could cause things to break')
print uIn.shape
# Calculate trigonometric functions
phi = np.radians(latsIn)
cphi = np.cos(phi)
sphi = np.sin(phi)
c2phi = np.power(cphi, 2)
acphi = a * cphi
asphi = a * sphi
# Calculate coriolis parameter f
f = 2 * omega * sphi

elif Data == "CESM":
    Fstartyr = 1990
    Fendyr = 2014
    DirIn = '/home/disk/eos4/rachel/EventTracking/FiT_RW_ERA/CESM_output/' + Version + str(Fstartyr) + '/proc/'
 
    PrecipClimDir = '/home/disk/eos4/rachel/EventTracking/Inputs/CESM/f.e13.FAMPIC5.ne120_ne120.1979_2012.001/'
    if sumlats > 0:
        PrecipClimFile = 'Regrid_' + str(sumlats) + '_' + str(sumlons) + '_ncra_f.e13.FAMIPC5.ne120_ne120_TotalPrecip_1979-2012.nc'
    else:
        PrecipClimFile = 'ncra_f.e13.FAMIPC5.ne120_ne120_TotalPrecip_1979-2012.nc'

DirIn = '/home/disk/eos4/rachel/EventTracking/FiT_RW_ERA/' + Data + '_output/' + Version + str(Fstartyr) + '/proc/'

FileInPrecip = xrayOpen(PrecipClimDir + PrecipClimFile)

if Data in ['TRMM']:
    if sumlats > 0:
        latin = FileInPrecip['lat']
        invar = 'PrecipAnnClim'
    else:
        latin = FileInPrecip['latitude']
        invar = 'pcp'

elif Data in ['TRMMERAIgd']:
    latin = FileInPrecip['lat']
    invar = 'pcp'

elif Data in ["ERAI"]:
    print PrecipClimDir + PrecipClimFile
DirO = DirI + diradd + '/'

# Check directory exists and create if not

try:
    os.stat(DirO)
except:
    os.mkdir(DirO)

# open files: 
# dataIn is list of all precip events
# eventsIn is maps of each timestep with event id number
#eventsIn = xrayOpen(DirRaw + '/ts_' + Data +  str(startyr) + '-' + str(endyr) + '_' + Version + '_4Dobjects.nc')
eventsIn = xrayOpen(DirRaw + '/ts_' + Data + '_' + Version + '_' + 
                    str(startyr) + '-' + str(endyr)
                    + '_4Dobjects.nc')

dataIn = xrayOpen(DirI + '/All_Precip_' + str(startyr) + '-' + str(endyr) + '_' + Data + '_' + Version + '.nc',decodetimes=False)

#Get lons and lats
#print FileInLats
FileIn = xrayOpen(FileInLats)

if Data in ["CESM",'GPCP']:
    lats = FileIn['lat'].values
    lons = FileIn['lon'].values
elif Data in ["ERA20C","TRMMERAIgd"]:
        lats = FileIn['latitude'].values
        lons = FileIn['longitude'].values
else: