Changeset 2246 in lmdz_wrf
- Timestamp:
- Nov 26, 2018, 2:44:21 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r2243 r2246 2150 2150 print ' ' + fname + ": File '" + ncfile + "' does not have variable: '" + \ 2151 2151 varn + "' !!" 2152 varns = list(ncvars) 2153 varns.sort 2154 print ' available ones:', varns 2152 2155 ncf.close() 2153 2156 quit(-1) … … 11072 11075 if not wrfnc.dimensions.has_key('time'): 11073 11076 newdim = wrfnc.createDimension('time', None) 11077 tdimn='time' 11078 else: 11079 for idim in range(10): 11080 tS = str(idim) 11081 if not wrfnc.dimensions.has_key('time'+tS): 11082 print warnmsg 11083 print ' ' + fname + ": file already has dimension 'time' " + \ 11084 "adding 'time" + tS + "' instead !!" 11085 newdim = wrfnc.createDimension('time'+tS, None) 11086 tdimn='time'+tS 11087 break 11088 11074 11089 11075 11090 if wrfnc.variables.has_key(varn): 11076 11091 newvar = wrfnc.variables[varn] 11077 11092 else: 11078 newvar = wrfnc.createVariable( 'time','f8',('time'))11093 newvar = wrfnc.createVariable(varn,'f8',(tdimn)) 11079 11094 11080 11095 newattr = basicvardef(newvar, 'time','time',tunits) … … 26988 27003 #same_deltasign(values, '/home/lluis/PY/wrfout_d01_1995-01-01_00:00:00', 'T2,Q2,XLAT,XLONG') 26989 27004 26990 def compute_Koeppen_Geiger_clims(values , ncfile, variable):27005 def compute_Koeppen_Geiger_clims(values): 26991 27006 """ Function to compute the Kooeppen-Geiger climatological classification 26992 values= [slicedims] 26993 [slicedims]: '|' separated list of [dimname]:[valdim] with he values to the 26994 dimensions with which perform a slice of the variables 26995 [valdim]: 26996 * [integer]: which value of the dimension 26997 * -1: all along the dimension 26998 * -9: last value of the dimension 26999 * [beg]@[end]@[freq] slice from [beg] to [end] every [freq] 27000 * NOTE, no dim name all the dimension size 27001 ncfile= netCDF file to use 27002 variable: ',' list of variables ('all' for all variables) 27007 values= [tasvalues]:[prvalues] 27008 [tasvalues]: '|' separated list of [ncfilen]|[varn]|[timevarn] for tas (2m temperature) 27009 [ncfilen]: name of the netCDF file with tas values 27010 [varn]: name of the variable tas 27011 [timevarn]: name of the variable time ('None' for not present) 27012 [prvalues]: '|' separated list of [ncfilen]|[varn]|[timevarn] for pr (precipitation) 27013 [ncfilen]: name of the netCDF file with pr values 27014 [varn]: name of the variable pr 27015 [timevarn]: name of the variable time ('None' for not present) 27003 27016 """ 27004 fname = ' same_deltasign'27017 fname = 'compute_Koeppen_Geiger_clims' 27005 27018 27006 27019 if values == 'h': … … 27009 27022 quit() 27010 27023 27011 expectargs = '[slicedims]' 27012 gen.check_arguments(fname, values, expectargs, ',') 27013 27014 slicedims = values.split(',')[0] 27024 expectargs = '[tasvalues]:[prvalues]' 27025 gen.check_arguments(fname, values, expectargs, ':') 27026 27027 tasvalues = values.split(':')[0].split('|') 27028 prvalues = values.split(':')[1].split('|') 27029 27030 print " uploading 'tas' values ..." 27031 if not os.path.isfile(tasvalues[0]): 27032 print errormsg 27033 print ' ' + fname + ": file with tas values '" + tasvalues[0] + "' does " + \ 27034 "not exist !!" 27035 quit(-1) 27036 onctas = NetCDFFile(tasvalues[0], 'r') 27037 if not onctas.variables.has_key(tasvalues[1]): 27038 print errormsg 27039 print ' '+fname+": tas file has not tas values as '" + tasvalues[1] + "' !!" 27040 quit(-1) 27041 otas = onctas.variables[tasvalues[1]] 27042 if not len(otas.shape) == 3: 27043 print errormsg 27044 print ' ' + fname + ": tas must be rank 3 and it is: '" + otas.shape + "' !!" 27045 quit(-1) 27046 tas = otas[:] 27047 27048 if tasvalues[2] != 'None': 27049 if not onctas.variables.has_key(tasvalues[2]): 27050 print errormsg 27051 print ' '+fname+": tas file has not time values as '" +tasvalues[2] + "' !!" 27052 quit(-1) 27053 otimetas = onctas.variables[tasvalues[2]] 27054 timetas = otimetas[:] 27055 else: 27056 timetas = None 27057 27058 print " uploading 'pr' values ..." 27059 if not os.path.isfile(prvalues[0]): 27060 print errormsg 27061 print ' ' + fname + ": file with pr values '" + tasvalues[0] + "' does " + \ 27062 "not exist !!" 27063 quit(-1) 27064 oncpr = NetCDFFile(prvalues[0], 'r') 27065 if not oncpr.variables.has_key(prvalues[1]): 27066 print errormsg 27067 print ' ' + fname + ": pr file has not pr values as '" + prvalues[1] + "' !!" 27068 quit(-1) 27069 opr = oncpr.variables[prvalues[1]] 27070 pr = opr[:] 27071 27072 if prvalues[2] != 'None': 27073 if not oncpr.variables.has_key(prvalues[2]): 27074 print errormsg 27075 print ' ' +fname+ ": pr file has not time values as '" + prvalues[2] + "' !!" 27076 quit(-1) 27077 otimepr = oncpr.variables[prvalues[2]] 27078 timepr = otimepr[:] 27079 else: 27080 timepr = None 27081 27082 # Checking dimensions conssitency 27083 gen.same_shape(tas,pr) 27084 27085 if timetas is not None and timepr is not None: 27086 if timetas.shape[0] != timepr.shape[0]: 27087 print errormsg2 27088 print ' '+fname+": length 'timetas':",timetas.shape[0]," and 'timepr':",\ 27089 timepr.shape[0]," do not coincide !!" 27090 quit(-1) 27091 timeu = timetas.units 27092 timec = timetas.calendar 27093 tastdesc = gen.temporal_desc(timetas, timeu, timec) 27094 27095 if timetas is None: 27096 if tas.shape[0] != timepr.shape[0]: 27097 print errormsg 27098 print ' ' + fname + ": length time-dimension from 'tas':", tas.shape[0],\ 27099 " and 'timepr':", timepr.shape[0], " do not coincide !!" 27100 quit(-1) 27101 timeu = timepr.units 27102 timec = timepr.calendar 27103 tastdesc = gen.temporal_desc(timepr, timeu, timec) 27104 27105 if timepr is None: 27106 if pr.shape[0] != timetas.shape[0]: 27107 print errormsg 27108 print ' ' + fname + ": length time-dimension from 'pr':", pr.shape[0], \ 27109 " and 'timetas':", timetas.shape[0], " do not coincide !!" 27110 quit(-1) 27111 timeu = timetas.units 27112 timec = timetas.calendar 27113 tastdesc = gen.temporal_desc(timetas, timeu, timec) 27114 27115 # Starting statistics 27116 tasn = np.min(tas) 27117 tasx = np.max(tas) 27118 27119 prn = np.min(pr) 27120 prx = np.max(pr) 27121 27122 27123 return 27015 27124 27016 27125
Note: See TracChangeset
for help on using the changeset viewer.