Changeset 689 in lmdz_wrf for trunk/tools/nc_var_tools.py


Ignore:
Timestamp:
Jan 28, 2016, 2:48:41 PM (9 years ago)
Author:
lfita
Message:

Fixing right computation of `Npoints' in 'lonlatProj'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/nc_var_tools.py

    r686 r689  
    1771917719     dyres= resolution on the SN axis [m]
    1772017720     project= projection
    17721        'lonlat': regular lon/lat projection
     17721       'lonlat': standard lon/lat projection tacking number of points from [dx/dy]res at the Equator
     17722       'lonlat_dxdyFix': projection with a fixed grid distance
    1772217723     wfile= Should an output file be written (True/False)
    1772317724    """
     
    1773017731    RadDeg = 180./np.pi
    1773117732
    17732     Npts = 0
     17733    Npts = 1
    1773317734    if project == 'lonlat':
     17735        Nlon = int(2. * np.pi * EarthR / dxres) + 1
     17736        Nlat = int(np.pi * EarthR / dxres) + 1
     17737
     17738        lonProj = np.zeros((Nlon), dtype=np.float)
     17739        latProj = np.zeros((Nlat), dtype=np.float)
     17740
     17741        lonProj = -180. + np.arange(Nlon) * 2. * np.pi * RadDeg / (Nlon - 1)
     17742        latProj = -90. + np.arange(Nlat) * np.pi * RadDeg / (Nlat - 1)
     17743
     17744        dimx = Nlon
     17745        dimy = Nlat
     17746        Npts = dimx*dimy
     17747        Npoints = np.arange((Npts)).reshape(dimy,dimx)
     17748
     17749    elif project == 'lonlat_dxdyFix':
    1773417750        lonProj = []
    1773517751        latProj = []
     
    1774617762            while lon <= 2.*np.pi:
    1774717763#                print lonarc, latarc, lon, lat, [lon*RadDeg, lat*RadDeg]
    17748                 lonProj.append(lon*RadDeg)
     17764                lonProj.append(-180. + lon*RadDeg)
    1774917765                latProj.append(lat*RadDeg)
    1775017766                lon = lon + lonarc
     
    1775217768        lonProj.append(0.)
    1775317769        latProj.append(90.)
    17754 
     17770        Npts = Npts + 1
     17771
     17772        dimx = Npts
     17773        dimy = Npts
     17774        Npoints = np.arange(Npts)
    1775517775    else:
    1775617776        print errormsg
     
    1776417784
    1776517785# Dimensions
    17766         Npoints = len(lonProj)
    17767         newdim = onewnc.createDimension('Npts', Npoints)
     17786        newdim = onewnc.createDimension('x', dimx)
     17787        newdim = onewnc.createDimension('y', dimy)
     17788        newdim = onewnc.createDimension('Npts', Npts)
    1776817789        newdim = onewnc.createDimension('Ncoord', 2)
    1776917790
    1777017791# Variables
    17771         newvar = onewnc.createVariable('lon', 'f8', ('Npts'))
     17792        newvar = onewnc.createVariable('lon', 'f8', ('x'))
    1777217793        basicvardef(newvar, 'longitude', 'Longitude', 'degress_East')
    17773         newvar[:] = lonProj[:]
     17794        newvar[:] = lonProj
    1777417795        newvar.setncattr('axis', 'X')
    1777517796        newvar.setncattr('_CoordinateAxisType', 'Lon')   
    1777617797
    17777         newvar = onewnc.createVariable('lat', 'f8', ('Npts'))
     17798        newvar = onewnc.createVariable('lat', 'f8', ('y'))
    1777817799        basicvardef(newvar, 'latitude', 'Latitude', 'degress_North')
    17779         newvar[:] = latProj[:]
     17800        newvar[:] = latProj
    1778017801        newvar.setncattr('axis', 'Y')
    1778117802        newvar.setncattr('_CoordinateAxisType', 'Lat')   
    1778217803
    17783         newvar = onewnc.createVariable('points', 'i8', ('Npts'))
     17804        if len(Npoints.shape) == 2:
     17805            newvar = onewnc.createVariable('points', 'i8', ('y', 'x'))
     17806        else:
     17807            newvar = onewnc.createVariable('points', 'i8', ('Npts'))
     17808
    1778417809        basicvardef(newvar, 'points', '# point of the projection', '-')
    17785         newvar[:] = np.int64(np.arange(Npoints))
     17810        newvar[:] = Npoints
    1778617811        newvar.setncattr('coordinates',  'lon lat')
     17812        print Npoints.shape
    1778717813   
    1778817814
     
    1780117827        print fname + "Successfull written of '" + ofile + "' !!'"
    1780217828
    17803     return lonlatProj
     17829    return lonProj, latProj
    1780417830
    1780517831#lonlatProj(100000.,100000.,'lonlat',True)
Note: See TracChangeset for help on using the changeset viewer.