Changeset 2247 in lmdz_wrf for trunk/tools
- Timestamp:
- Nov 26, 2018, 3:10:55 PM (6 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var.py
r2225 r2247 66 66 ## e.g. # nc_var.py -o same_deltasign -f wrfout_d01_1995-01-01_00:00:00 -S 'Time:0|south_north:60|west_east:-1' -v T2,Q2,XLAT,XLONG 67 67 ## e.g. # nc_var.py -o compute_slices_stats -S 'XLONG,-74.,-36.,4.;XLAT,-62.,18.,2.;HGT,500.,7000.,500.@Time|Times:west_east|XLONG:south_north|XLAT@Time' -f wrfout_d01_1995-01-01_00:00:00 -v T2,Q2 68 ## e.g. # nc_var.py -o dimrename -f /media/lluis/ExtDiskC_ext3/DATA/estudios/FPS_Alps/additional/IOP/select/out_irene/simcdx_vars_cape_120lev_cdxwrf2.nc -S Time -v time0 68 69 69 70 from optparse import OptionParser … … 104 105 # DataSetSection_multivars: Function to get a section (values along multiple variables) of a given data-set 105 106 # DYNAMICO_toCF: Function to pass a DYNAMICO original file to CF-conventions 107 # dimrename: Renaming a dimension from a file 106 108 # dimrm: Removing a dimension from a file 107 109 # dimToUnlimited: Operation to create an unlimited dimension from an existing one … … 217 219 'computevar_model', 'curve_section', 'DatesFiles', \ 218 220 'DataSetSection', 'DataSetSection_multidims', 'DataSetSection_multivars', \ 219 'DYNAMICO_toCF', 'dimr m', 'dimToUnlimited', 'dimVar_creation',\221 'DYNAMICO_toCF', 'dimrename', 'dimrm', 'dimToUnlimited', 'dimVar_creation', \ 220 222 'fattradd', \ 221 223 'fdimadd', 'fgaddattr', 'field_stats', 'field_stats_dim', 'file_creation', \ … … 373 375 elif oper == 'DYNAMICO_toCF': 374 376 ncvar.DYNAMICO_toCF(opts.values, opts.ncfile) 377 elif oper == 'dimrename': 378 ncvar.dimrename(opts.ncfile, opts.values, opts.varname) 375 379 elif oper == 'dimrm': 376 380 ncvar.dimrm(opts.ncfile, opts.values, opts.varname) -
trunk/tools/nc_var_tools.py
r2246 r2247 61 61 # DataSetSection_multivars: Function to get a section (values along multiple variables) of a given data-set 62 62 # DatesFiles: Function to find different time values on a series of WRF files in a folder 63 # dimrename: Renaming a dimension from a file 63 64 # dimrm: Removing a dimension from a file 64 65 # DimsLoop: Function to provide the shape of the dimensions which are not selected … … 1754 1755 1755 1756 return 1757 1758 1759 def dimrename(ncfile, newdimn, dimn): 1760 """ Renaming a dimension from a file 1761 ncfile = netCDF object file 1762 values= [newdimn], new name for the dimension 1763 dimn = dimension name to change 1764 """ 1765 import shutil as shu 1766 fname = 'dimrename' 1767 1768 if newdimn == 'h': 1769 print fname + '_____________________________________________________________' 1770 print dimrename.__doc__ 1771 quit() 1772 1773 ncf = NetCDFFile(ncfile,'a') 1774 if not ncf.dimensions.has_key(dimn): 1775 print errormsg 1776 print ' ' + fname + ": file does not have dimension name '" + dimn+ "' !!" 1777 dimns = ncf.dimensions 1778 dimns.sort() 1779 print ' available ones:', dimns 1780 ncf.close() 1781 quit(-1) 1782 1783 if ncf.dimensions.has_key(newdimn): 1784 print warnmsg 1785 print ' ' + fname + ": file already have dimension name '" + newdimn+ "' !!" 1786 print " looping all over that variables with dimension name '"+dimn+"' !!" 1787 for varn in ncf.variables.keys(): 1788 ovar = ncf.variables[varn] 1789 if gen.searchInlist(ovar.dimensions,dimn): 1790 vardims = list(ovar.dimensions) 1791 idim = vardims.index(dimn) 1792 vardims[idim] = newdimn 1793 1794 newvar = ncf.createVariable(varn+'tmp', ovar.dtype, tuple(vardims)) 1795 newvar[:] = ovar[:] 1796 for ncattr in ovar.ncattrs(): 1797 attrv = ovar.getncattr(ncattr) 1798 newvar.setncattr(ncattr, attrv) 1799 ncf.sync() 1800 ncf.renameVariable(varn, varn+'old') 1801 ncf.renameVariable(varn+'tmp', varn) 1802 ncf.sync() 1803 else: 1804 newdim = ncf.renameDimension(dimn, newdimn) 1805 ncf.sync() 1806 ncf.close() 1807 1808 return 1756 1809 1757 1810 def dimrm(ncfile, values, dimn):
Note: See TracChangeset
for help on using the changeset viewer.