Changeset 689 in lmdz_wrf for trunk/tools/nc_var_tools.py
- Timestamp:
- Jan 28, 2016, 2:48:41 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r686 r689 17719 17719 dyres= resolution on the SN axis [m] 17720 17720 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 17722 17723 wfile= Should an output file be written (True/False) 17723 17724 """ … … 17730 17731 RadDeg = 180./np.pi 17731 17732 17732 Npts = 017733 Npts = 1 17733 17734 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': 17734 17750 lonProj = [] 17735 17751 latProj = [] … … 17746 17762 while lon <= 2.*np.pi: 17747 17763 # print lonarc, latarc, lon, lat, [lon*RadDeg, lat*RadDeg] 17748 lonProj.append( lon*RadDeg)17764 lonProj.append(-180. + lon*RadDeg) 17749 17765 latProj.append(lat*RadDeg) 17750 17766 lon = lon + lonarc … … 17752 17768 lonProj.append(0.) 17753 17769 latProj.append(90.) 17754 17770 Npts = Npts + 1 17771 17772 dimx = Npts 17773 dimy = Npts 17774 Npoints = np.arange(Npts) 17755 17775 else: 17756 17776 print errormsg … … 17764 17784 17765 17785 # 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) 17768 17789 newdim = onewnc.createDimension('Ncoord', 2) 17769 17790 17770 17791 # Variables 17771 newvar = onewnc.createVariable('lon', 'f8', (' Npts'))17792 newvar = onewnc.createVariable('lon', 'f8', ('x')) 17772 17793 basicvardef(newvar, 'longitude', 'Longitude', 'degress_East') 17773 newvar[:] = lonProj [:]17794 newvar[:] = lonProj 17774 17795 newvar.setncattr('axis', 'X') 17775 17796 newvar.setncattr('_CoordinateAxisType', 'Lon') 17776 17797 17777 newvar = onewnc.createVariable('lat', 'f8', (' Npts'))17798 newvar = onewnc.createVariable('lat', 'f8', ('y')) 17778 17799 basicvardef(newvar, 'latitude', 'Latitude', 'degress_North') 17779 newvar[:] = latProj [:]17800 newvar[:] = latProj 17780 17801 newvar.setncattr('axis', 'Y') 17781 17802 newvar.setncattr('_CoordinateAxisType', 'Lat') 17782 17803 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 17784 17809 basicvardef(newvar, 'points', '# point of the projection', '-') 17785 newvar[:] = np.int64(np.arange(Npoints))17810 newvar[:] = Npoints 17786 17811 newvar.setncattr('coordinates', 'lon lat') 17812 print Npoints.shape 17787 17813 17788 17814 … … 17801 17827 print fname + "Successfull written of '" + ofile + "' !!'" 17802 17828 17803 return lon latProj17829 return lonProj, latProj 17804 17830 17805 17831 #lonlatProj(100000.,100000.,'lonlat',True)
Note: See TracChangeset
for help on using the changeset viewer.