Changeset 1750 in lmdz_wrf


Ignore:
Timestamp:
Dec 18, 2017, 3:02:22 AM (7 years ago)
Author:
lfita
Message:

Final working version of the script with multiple attributes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/ORforcing_reconstruct.py

    r1749 r1750  
    1515
    1616parser = OptionParser()
     17parser.add_option("-f", "--fileHEader", dest="fh", help="header of files",           \
     18  metavar="VALUE")
     19parser.add_option("-L", "--latitude", dest="latn", help="name of the variable latitiude", \
     20  metavar="VALUE")
     21parser.add_option("-l", "--longitude", dest="lonn", help="name of the variable longitiude", \
     22  metavar="VALUE")
     23parser.add_option("-v", "--Variables", dest="varns", help="',' separated list of variables", \
     24  metavar="VALUE")
    1725parser.add_option("-y", "--year", dest="year", help="year to process",               \
    1826  metavar="VALUE")
     
    2230####### ###### ##### #### ### ## #
    2331
    24 filen = 'cruncep_halfdeg_' + opts.year + '.nc'
     32filen = opts.fh + opts.year + '.nc'
    2533
    2634# Variable whcih provides the indices of a 1D vector from the dimy, dimx space
     
    2836
    2937# 2D longitude, latitude matrices
    30 lonvar = 'nav_lon'
    31 latvar = 'nav_lat'
     38lonvar = opts.lonn
     39latvar = opts.latn
    3240
    3341# Range to retrieve
     
    4048# Variables to reconstruct
    4149#variable = 'all'
    42 variable = 'time,LWdown,Qair,PSurf,SWdown,Tair,Wind_E,Wind_N,Snowf,Rainf'
     50variable = opts.varns
    4351
    4452# Resolution
     
    7987olat = onc.variables[latvar]
    8088
    81 vecdimn = oind.dimensions[0]
    82 Xdimn = olon.dimensions[1]
    83 Ydimn = olon.dimensions[0]
    84 
    85 # Fortran indices, first 1
    8689indv = oind[:]
    8790lonv = olon[:]
    8891latv = olat[:]
     92
     93vecdimn = oind.dimensions[0]
     94if len(olon.dimensions) == 2:
     95    Xdimn = olon.dimensions[1]
     96    Ydimn = olon.dimensions[0]
     97    dimx = lonv.shape[1]
     98    dimy = lonv.shape[0]
     99elif len(olon.dimensions) == 1:
     100    Xdimn = olon.dimensions[0]
     101    Ydimn = olat.dimensions[0]
     102    dimx = lonv.shape[0]
     103    dimy = latv.shape[0]
     104    lonv, latv = np.meshgrid(lonv, latv)
     105
     106# Fortran indices, first 1
    89107indv = indv - 1
    90 
    91 dimx = lonv.shape[1]
    92 dimy = lonv.shape[0]
    93108
    94109veclon = np.zeros((len(indv)), dtype=np.float)
     
    98113for iid in range(len(indv)):
    99114    iy = int((indv[iid]-1)/dimx)
    100     ix = indv[iid] - iy*dimx - 1
     115    ix = int(indv[iid] - iy*dimx - 1)
    101116    veclon[iid] = lonv[iy,ix]
    102117    veclat[iid] = latv[iy,ix]
     
    117132        if not gen.searchInlist(ncvars, vn):
    118133            print gen.errormsg
    119             print '  ' + fname + ": file '" + ncfile + "' does not have " +          \
     134            print '  ' + fname + ": file '" + filen + "' does not have " +           \
    120135              " variable '" + vn + "' !!"
    121136            print '  available ones:', ncvars
Note: See TracChangeset for help on using the changeset viewer.