Changeset 1879 in lmdz_wrf for trunk/tools
- Timestamp:
- Apr 3, 2018, 4:45:50 PM (7 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var.py
r1857 r1879 87 87 # DataSetSection_multivars: Function to get a section (values along multiple variables) of a given data-set 88 88 # DYNAMICO_toCF: Function to pass a DYNAMICO original file to CF-conventions 89 # dimrm: Removing a dimension from a file 89 90 # dimToUnlimited: Operation to create an unlimited dimension from an existing one 90 91 # dimVar_creation: Function to add a 1D variable with the size of a given dimension in a file … … 183 184 'computevar_model', 'curve_section', 'DatesFiles', \ 184 185 'DataSetSection', 'DataSetSection_multidims', 'DataSetSection_multivars', \ 185 'DYNAMICO_toCF', 'dim ToUnlimited', 'dimVar_creation',\186 'DYNAMICO_toCF', 'dimrm', 'dimToUnlimited', 'dimVar_creation', \ 186 187 'fattradd', \ 187 188 'fdimadd', 'fgaddattr', 'field_stats', 'field_stats_dim', 'file_creation', \ … … 332 333 elif oper == 'DYNAMICO_toCF': 333 334 ncvar.DYNAMICO_toCF(opts.values, opts.ncfile) 335 elif oper == 'dimrm': 336 ncvar.dimrm(opts.ncfile, opts.values, opts.varname) 334 337 elif oper == 'dimToUnlimited': 335 338 ncvar.dimToUnlimited(opts.values, opts.ncfile) -
trunk/tools/nc_var_tools.py
r1878 r1879 57 57 # DataSetSection_multivars: Function to get a section (values along multiple variables) of a given data-set 58 58 # DatesFiles: Function to find different time values on a series of WRF files in a folder 59 # dimrm: Removing a dimension from a file 59 60 # DimsLoop: Function to provide the shape of the dimensions which are not selected 60 61 # DYNAMICO_toCF: Function to pass a DYNAMICO original file to CF-conventions … … 1635 1636 fname = 'varrm' 1636 1637 1637 if var == 'h' :1638 if var == 'h' or var is None: 1638 1639 print fname + '_____________________________________________________________' 1639 1640 print varrm.__doc__ … … 1665 1666 return 1666 1667 1668 def dimrm(ncfile, values, dimn): 1669 """ Removing a dimension from a file 1670 ncfile = netCDF object file 1671 values= [varsAction], which action to be done on that variables which contain the 1672 given dimension 1673 'renamedim',[newname]: create a new dimension and its varibale-dimension with 1674 name [newname] for that varibales with the diemnsion to remove 1675 'removevar': remove varibale with the given dimension 1676 dimn = dimension name to remove 1677 """ 1678 import shutil as shu 1679 fname = 'dimrm' 1680 1681 if values == 'h': 1682 print fname + '_____________________________________________________________' 1683 print dimrm.__doc__ 1684 quit() 1685 1686 ncf = NetCDFFile(ncfile,'a') 1687 dims = ncf.dimensions 1688 ncvars = ncf.variables.keys() 1689 ncf.close() 1690 1691 if not gen.searchInlist(dims, var): 1692 print ' ' + fname + ": File '" + ncfile + "' does not have dimension: '" + \ 1693 dimn + "' !!" 1694 print ' dimensions:', dims 1695 quit(-1) 1696 1697 if values[0:9] == 'renamedim': 1698 newdimn = values.split(',')[1] 1699 ncf = NetCDFFile(ncfile,'a') 1700 if gen.searchInlist(dims,newdimn): 1701 print errormsg 1702 print ' ' + fname + ": file '" + ncfile + "' already has a " + \ 1703 "dimension labelled '" + newdimn + "' !!" 1704 print ' pick up another name' 1705 ncf.close() 1706 quit() 1707 newdim = ncf.renameDimension(dimn, newdimn) 1708 ncf.sync() 1709 # Checking for the existence of a dimension-variable of the same name 1710 if gen.searchInlist(ncvars, dimn): 1711 if gen.searchInlist(ncvars,newdimn): 1712 print errormsg 1713 print ' ' + fname + ": file '" + ncfile + "' already has a " + \ 1714 "variable labelled '" + newdimn + "' !!" 1715 print ' pick up another name' 1716 ncf.close() 1717 quit() 1718 newvar = ncf.renameVariable(dimn, newdimn) 1719 ncf.sync() 1720 elif values[0:9] == 'removevar': 1721 ncf = NetCDFFile(ncfile,'r') 1722 tmpncf = NetCDFFile('tmp_py.nc' , 'w') 1723 gtmpattr = set_attribute(tmpncf, 'copy', 'temporal') 1724 tmpncf.sync() 1725 1726 for varn in ncf.variables.keys(): 1727 vdimn = varn.dimensions 1728 if not gen.searchInlist(vdimn,dimn): 1729 ncf.close() 1730 fvaradd(ncfile + ',' + varn, 'tmp_py.nc') 1731 ncf = NetCDFFile(ncfile,'r') 1732 ncf.close() 1733 fgaddattr(ncfile, 'tmp_py.nc') 1734 shu.copyfile('tmp_py.nc', ncfile) 1735 os.remove('tmp_py.nc') 1736 1737 return 1738 1667 1739 def seasmean(timename, filename, varn): 1668 1740 """ Function to compute the seasonal mean of a variable
Note: See TracChangeset
for help on using the changeset viewer.