Changeset 1746 in lmdz_wrf


Ignore:
Timestamp:
Dec 17, 2017, 4:07:39 PM (8 years ago)
Author:
lfita
Message:

Working version of the script!!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/ORforcing_reconstruct.py

    r1745 r1746  
    2525Xmin=-90.25
    2626#Xmin='all'
    27 Xmax=-5.25
     27Xmax=-33.25
    2828Ymin=-67.25
    2929Ymax=15.25
     
    3131# Variables to reconstruct
    3232#variable = 'all'
    33 variable = 'LWdown'
     33variable = 'time,LWdown,Qair,PSurf,SWdown,Tair,Wind_E,Wind_N,Snowf,Rainf'
    3434
    3535# Resolution
     
    8686veclat = np.zeros((len(indv)), dtype=np.float)
    8787
    88 # Construct veclon, veclat  (Fortran like, First 1)
     88# Construct veclon, veclat
    8989for iid in range(len(indv)):
    9090    iy = int((indv[iid]-1)/dimx)
     
    107107    for vn in varns:
    108108        if not gen.searchInlist(ncvars, vn):
    109             print errormsg
     109            print gen.errormsg
    110110            print '  ' + fname + ": file '" + ncfile + "' does not have " +          \
    111111              " variable '" + vn + "' !!"
     
    138138
    139139matind = matindt.transpose()
    140 
    141 print 'Lluis veclon:', veclon[0:10]
    142 print 'Lluis matind: ___'
    143 for i in range(3):
    144     print matind[50+i,50:55]
    145 
    146 print 'matind n:', np.min(matind), 'x:', np.max(matind), 'L1Dvec:', veclon.shape[0], 'vecind: n', np.min(indv), 'x:', np.max(indv)
    147 print 'vecind[matind]:', indv[matind[50:53,0]]
    148 quit()
     140# Fortran like, First 1
     141matind = np.where(matind != -1, matind - 1, matind)
    149142
    150143# Creation of file
     
    166159
    167160# Variable indices
    168 newvar = onewnc.createVariable('lonlat_matind', 'i', ('y', 'x'), fill_value=-1)
     161newvar = onewnc.createVariable('vec1D_matind', 'i', ('y', 'x'), fill_value=-1)
    169162newvar[:] = matind
    170 ncvar.basicvardef(newvar, 'lonlat_matind', 'matrix with the equivalencies from ' +   \
    171   '2D lon, lat matrices', '-')
     163ncvar.basicvardef(newvar, 'vec1D_matind', 'matrix with the equivalencies from 1D ' + \
     164  'vector indices', '-')
     165ncvar.set_attribute(newvar, 'coordinates', 'lon lat')
    172166
    173167# Looking for equivalencies in the 1D vector
    174 lind = list(indv)
    175 vec1Dind = matind
     168matlonlat = matind.copy()
    176169for j in range(dimy):
    177170    for i in range(dimx):
    178171        if matind[j,i] != -1:
    179             vec1Dind[j,i] = lind.index(matind[j,i])
    180 
    181 newvar = onewnc.createVariable('vec1D_matind', 'i', ('y', 'x'), fill_value=-1)
    182 newvar[:] = vec1Dind
    183 ncvar.basicvardef(newvar, 'vec1D_matind', 'matrix with the equivalencies from 1D ' + \
    184   'vector indices', '-')
    185 
    186 onewnc.sync()
    187 onc.clsoe()
    188 onewnc.close()
    189 quit()
     172            matlonlat[j,i] = indv[matind[j,i]]
     173
     174newvar = onewnc.createVariable('lonlat_matind', 'i', ('y', 'x'), fill_value=-1)
     175newvar[:] = matlonlat
     176ncvar.basicvardef(newvar, 'lonlat_matind', 'matrix with the equivalencies from ' +   \
     177  '2D lon, lat matrices', '-')
     178ncvar.set_attribute(newvar, 'coordinates', 'lon lat')
     179onewnc.sync()
    190180
    191181# Getting variables
     
    245235            iix = vardims.index('x')
    246236            iiy = vardims.index('y')
     237            iislc = 0
     238            Nslices = len(slices)
    247239            for slc in slices:
     240                gen.percendone(iislc,Nslices,0.25,vn + ' reconstructed:')
    248241                ival = slc[iix]
    249242                jval = slc[iiy]
     
    257250                            oldvarslice.append(slc[iid])
    258251
    259                     print vn, 'Slice new:', slc, 'old:', oldvarslice, 'shape:', newvar.shape, 'oldshape:', ovar.shape
    260252                    newvar[tuple(slc)] = ovar[tuple(oldvarslice)]
    261253                else:
Note: See TracChangeset for help on using the changeset viewer.