Changeset 2511 in lmdz_wrf for trunk/tools
- Timestamp:
- May 6, 2019, 9:21:50 PM (7 years ago)
- File:
-
- 1 edited
-
trunk/tools/nc_var_tools.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r2510 r2511 2614 2614 self.firstTt = gen.timeref_datetime(self.refdate, self.firstTu, \ 2615 2615 self.units, cal) 2616 self.firstTS = self.firstTt.strftime("%Y%m%d%H%M%S") 2617 self.firstTm = gen.timeref_datetime_mat(self.refdate, self.firstTu, \ 2618 self.units) 2616 if self.firsTt.year >= 1900: 2617 self.firstTS = self.firstTt.strftime("%Y%m%d%H%M%S") 2618 self.firstTm = gen.timeref_datetime_mat(self.refdate, \ 2619 self.firstTu, self.units) 2620 else: 2621 print warnmsg 2622 print ' first time step:', self.firsTt, 'below 1900 !!' 2623 self.firstTs = str(self.firstTt.year) + str(self.firstTt.month)+ \ 2624 str(self.firstTt.day) + str(self.firstTt.hour) + \ 2625 str(self.firstTt.minute) + str(self.firstTt.second) 2619 2626 self.lastTu = timev[self.dimt-1] 2620 2627 self.lastTt = gen.timeref_datetime(self.refdate, self.lastTu, \ 2621 2628 self.units, cal) 2622 self.lastTS = self.lastTt.strftime("%Y%m%d%H%M%S") 2623 self.lastTm = gen.timeref_datetime_mat(self.refdate, self.lastTu, \ 2624 self.units) 2629 if self.lasTt.year >= 1900: 2630 self.lastTS = self.lastTt.strftime("%Y%m%d%H%M%S") 2631 self.lastTm = gen.timeref_datetime_mat(self.refdate, self.lastTu,\ 2632 self.units) 2633 else: 2634 print warnmsg 2635 print ' last time step:', self.lastTt, 'below 1900 !!' 2636 self.lastTs = str(self.lastTt.year) + str(self.lastTt.month) + \ 2637 str(self.lastTt.day) + str(self.lastTt.hour) + \ 2638 str(self.lastTt.minute) + str(self.lastTt.second) 2625 2639 2626 2640 return … … 23186 23200 onc2 = NetCDFFile(filen2, 'r') 23187 23201 23188 dimn1 = onc1.dimensions 23189 dimn2 = onc2.dimensions 23202 dimn1 = onc1.dimensions.keys() 23203 dimn2 = onc2.dimensions.keys() 23190 23204 varn1 = onc1.variables.keys() 23191 23205 varn2 = onc2.variables.keys() 23192 23193 # Getting dimension variables23194 dimvar = {}23195 23196 for dimvarn in dimvarns:23197 dimn = dimvarn.split('|')[0]23198 dvn = dimvarn.split('|')[1]23199 23200 if not gen.searchInlist(dimn1, dimn):23201 print errormsg23202 print ' ' +fname+ ": file '" + filen1 + "' does not have dimension: '"+ \23203 dimn23204 print ' available ones:', dimn123205 quit(-1)23206 23207 if not gen.searchInlist(dimn2, dimn):23208 print errormsg23209 print ' ' +fname+ ": file '" + filen2 + "' does not have dimension: '"+ \23210 dimn23211 print ' available ones:', dimn223212 quit(-1)23213 23214 if not gen.searchInlist(varn1, dvn):23215 print errormsg23216 print ' ' +fname+ ": file '" + filen1 + "' does not have variable: '" + \23217 dimn23218 print ' available ones:', varn123219 quit(-1)23220 23221 if not gen.searchInlist(varn2, dvn):23222 print errormsg23223 print ' ' +fname+ ": file '" + filen2 + "' does not have variable: '" + \23224 dimn23225 print ' available ones:', varn223226 quit(-1)23227 23228 dimvar[dimn] = dvn23229 23206 23230 23207 if variable == 'all': … … 23233 23210 setvarn2 = set(varn2) 23234 23211 coincidentvarn = list(setvarn1.intersection(setvarn2)) 23212 notcoincidentvarn = list(setvarn1.difference(setvarn2)) 23213 notcoincidentvarn = notcoincidentvarn + list(setvarn2.difference(setvarn1)) 23235 23214 else: 23236 coincidentvarn = gen.str_list(variable, ',') 23215 lvariable = gen.str_list(variable, ',') 23216 coincidentvarn = [] 23217 notcoincidentvarn = [] 23218 for lvarn in lvariable: 23219 if gen.searchInlist(varn2, lvarn): coincidentvarn.append(lvarn) 23220 else: notcoincidentvarn.append(lvarn) 23221 23222 print 'coincident variables:', coincidentvarn 23223 print 'not coincident variables:', notcoincidentvarn 23237 23224 23238 23225 # Creation of merged file 23239 23226 onewnc = NetCDFFile(mergedfilen, 'w') 23227 23228 # Getting dimension variables 23229 dimvar = {} 23230 23231 if len(coincidentvarn) != 0: 23232 for dimvarn in dimvarns: 23233 dimn = dimvarn.split('|')[0] 23234 dvn = dimvarn.split('|')[1] 23235 23236 if not gen.searchInlist(dimn1, dimn): 23237 print errormsg 23238 print ' ' +fname+ ": file '" + filen1 + "' does not have dimension: '"+ \ 23239 dimn 23240 print ' available ones:', dimn1 23241 #quit(-1) 23242 23243 if not gen.searchInlist(dimn2, dimn): 23244 print errormsg 23245 print ' ' +fname+ ": file '" + filen2 + "' does not have dimension: '"+ \ 23246 dimn 23247 print ' available ones:', dimn2 23248 #quit(-1) 23249 23250 if not gen.searchInlist(varn1, dvn): 23251 print errormsg 23252 print ' ' +fname+ ": file '" + filen1 + "' does not have variable: '" + \ 23253 dimn 23254 print ' available ones:', varn1 23255 #quit(-1) 23256 23257 if not gen.searchInlist(varn2, dvn): 23258 print errormsg 23259 print ' ' +fname+ ": file '" + filen2 + "' does not have variable: '" + \ 23260 dimn 23261 print ' available ones:', varn2 23262 #quit(-1) 23263 23264 dimvar[dimn] = dvn 23240 23265 23241 23266 # Looping on coincident variables … … 23368 23393 onewnc.sync() 23369 23394 23395 # Looping on not coincident variables 23396 for varn in notcoincidentvarn: 23397 print ' ' + fname + ": merging on variable '" + varn + "' ...." 23398 if onc1.variables.has_key(varn): 23399 add_vars(onc1,onewnc,[varn]) 23400 ovar = onc1.variables[varn] 23401 elif onc2.variables.has_key(varn): 23402 add_vars(onc2,onewnc,[varn]) 23403 else: 23404 print errormsg 23405 print ' ' + fname + ": any file has '" + varn + "' variable !!" 23406 print " available ones from file 1 '" + filen1 + "': ", varn1 23407 print " available ones from file 2 '" + filen2 + "': ", varn2 23408 quit(-1) 23409 23410 onewnc.sync() 23411 23370 23412 # Global attributes 23371 23413 gattrs = onc1.ncattrs() … … 23376 23418 23377 23419 # Adding PyNCplot 23378 add_global_PyNCplot(onewnc, main, fname, '0. 1')23420 add_global_PyNCplot(onewnc, main, fname, '0.2') 23379 23421 onewnc.sync() 23380 23422
Note: See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/LMDZ_WRF/chrome/site/your_project_logo.png)