Changeset 2511 in lmdz_wrf for trunk/tools


Ignore:
Timestamp:
May 6, 2019, 9:21:50 PM (7 years ago)
Author:
lfita
Message:

Adding execption when year < 1900

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/nc_var_tools.py

    r2510 r2511  
    26142614                self.firstTt = gen.timeref_datetime(self.refdate, self.firstTu,      \
    26152615                  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)
    26192626                self.lastTu = timev[self.dimt-1]
    26202627                self.lastTt = gen.timeref_datetime(self.refdate, self.lastTu,        \
    26212628                  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)
    26252639
    26262640        return
     
    2318623200    onc2 = NetCDFFile(filen2, 'r')
    2318723201
    23188     dimn1 = onc1.dimensions
    23189     dimn2 = onc2.dimensions
     23202    dimn1 = onc1.dimensions.keys()
     23203    dimn2 = onc2.dimensions.keys()
    2319023204    varn1 = onc1.variables.keys()
    2319123205    varn2 = onc2.variables.keys()
    23192 
    23193     # Getting dimension variables
    23194     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 errormsg
    23202             print '  ' +fname+ ": file '" + filen1 + "' does not have dimension: '"+ \
    23203               dimn
    23204             print '    available ones:', dimn1
    23205             quit(-1)
    23206 
    23207         if not gen.searchInlist(dimn2, dimn):
    23208             print errormsg
    23209             print '  ' +fname+ ": file '" + filen2 + "' does not have dimension: '"+ \
    23210               dimn
    23211             print '    available ones:', dimn2
    23212             quit(-1)
    23213 
    23214         if not gen.searchInlist(varn1, dvn):
    23215             print errormsg
    23216             print '  ' +fname+ ": file '" + filen1 + "' does not have variable: '" + \
    23217               dimn
    23218             print '    available ones:', varn1
    23219             quit(-1)
    23220 
    23221         if not gen.searchInlist(varn2, dvn):
    23222             print errormsg
    23223             print '  ' +fname+ ": file '" + filen2 + "' does not have variable: '" + \
    23224               dimn
    23225             print '    available ones:', varn2
    23226             quit(-1)
    23227 
    23228         dimvar[dimn] = dvn
    2322923206
    2323023207    if variable == 'all':
     
    2323323210        setvarn2 = set(varn2)
    2323423211        coincidentvarn = list(setvarn1.intersection(setvarn2))
     23212        notcoincidentvarn = list(setvarn1.difference(setvarn2))
     23213        notcoincidentvarn = notcoincidentvarn + list(setvarn2.difference(setvarn1))
    2323523214    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
    2323723224
    2323823225    # Creation of merged file
    2323923226    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
    2324023265
    2324123266    # Looping on coincident variables
     
    2336823393        onewnc.sync()
    2336923394
     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
    2337023412    # Global attributes
    2337123413    gattrs = onc1.ncattrs()
     
    2337623418
    2337723419    # Adding PyNCplot
    23378     add_global_PyNCplot(onewnc, main, fname, '0.1')
     23420    add_global_PyNCplot(onewnc, main, fname, '0.2')
    2337923421    onewnc.sync()
    2338023422
Note: See TracChangeset for help on using the changeset viewer.