Changeset 1295 in lmdz_wrf
- Timestamp:
- Nov 9, 2016, 8:36:07 PM (9 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var.py
r1275 r1295 64 64 # DataSetSection_multidims: Function to get a section (values along multiple dimensions) of a given data-set 65 65 # DataSetSection_multivars: Function to get a section (values along multiple variables) of a given data-set 66 # DYNAMICO_toCF: Function to pass a DYNAMICO original file to CF-conventions 66 67 # dimToUnlimited: Operation to create an unlimited dimension from an existing one 67 68 # dimVar_creation: Function to add a 1D variable with the size of a given dimension in a file … … 151 152 'computevar_model', 'DatesFiles', \ 152 153 'DataSetSection', 'DataSetSection_multidims', 'DataSetSection_multivars', \ 153 ' dimToUnlimited', 'dimVar_creation',\154 'DYNAMICO_toCF', 'dimToUnlimited', 'dimVar_creation', \ 154 155 'fattradd', \ 155 156 'fdimadd', 'fgaddattr', 'field_stats', 'field_stats_dim', 'file_creation', \ … … 286 287 elif oper == 'DatesFiles': 287 288 ncvar.DatesFiles(opts.values, opts.ncfile, opts.varname) 289 elif oper == 'DYNAMICO_toCF': 290 ncvar.DYNAMICO_toCF(opts.values, opts.ncfile) 288 291 elif oper == 'dimToUnlimited': 289 292 ncvar.dimToUnlimited(opts.values, opts.ncfile) -
trunk/tools/nc_var_tools.py
r1293 r1295 48 48 # DatesFiles: Function to find different time values on a series of WRF files in a folder 49 49 # DimsLoop: Function to provide the shape of the dimensions which are not selected 50 # DYNAMICO_toCF: Function to pass a DYNAMICO original file to CF-conventions 50 51 # dimToUnlimited: Operation to create an unlimited dimension from an existing one 51 52 # dimVar_creation: Function to add a 1D variable with the size of a given dimension in a file … … 17642 17643 return 17643 17644 17645 17646 def DYNAMICO_toCF(values,ncfile): 17647 """ Function to pass a DYNAMICO original file to CF-conventions 17648 values= [CFtimeUnits] 17649 [CFtimeUnits]: [tunits] since [YYYYMMDDHHMISS], CF time-units to which variable time should be used ('!' for spaces) 17650 ncfile= file to transform 17651 """ 17652 fname = 'DYNAMICO_toCF' 17653 17654 if ncfile == 'h': 17655 print fname + '_____________________________________________________________' 17656 print DYNAMICO_toCF.__doc__ 17657 quit() 17658 17659 CFT = values.replace('!',' ') 17660 17661 ofile = 'CF_DYNAMICO.nc' 17662 17663 ncf = NetCDFFile(ncfile,'a') 17664 ncdims = ncf.dimensions.keys() 17665 ncvars = ncf.variables.keys() 17666 17667 # CFing variable 'pres' 17668 if gen.searchInlist(ncvars,'pres'): 17669 print warnmsg 17670 print fname + ": renaming variable 'pres' as 'p' !!" 17671 newname = ncf.renameVariable('pres','p') 17672 ncf.sync() 17673 17674 # Re-aranging time-axis 17675 tvaro = ncf.variables['time_counter'] 17676 tvals = tvaro[:] 17677 tunits = tvaro.getncattr('units') 17678 17679 RefDate = CFT.split(' ')[2] 17680 RefDateS = RefDate[0:4] + '-' + RefDate[4:6] + '-' + RefDate[6:8] + ' ' + \ 17681 RefDate[8:10] + ':' + RefDate[10:12] + ':' + RefDate[12:14] 17682 CFtimeUnits = ' '.join(CFT.split(' ')[0:2]) + ' '+ RefDateS 17683 17684 newtvals = gen.coincident_CFtimes(tvals, CFtimeUnits, tunits) 17685 tvaro[:] = newtvals 17686 newattr = set_attribute(tvaro, 'units', CFtimeUnits) 17687 newattr = set_attribute(tvaro, 'time_origin', CFtimeUnits) 17688 17689 ncf.sync() 17690 17691 # CFing dimensions 17692 CFdims = {'time_counter': 'time', 'presnivs': 'pres'} 17693 for dimn in CFdims.keys(): 17694 if gen.searchInlist(ncdims,dimn): 17695 # Making sure CF dimension is not in the file 17696 if not gen.searchInlist(ncdims,CFdims[dimn]): 17697 newname = ncf.renameDimension(dimn,CFdims[dimn]) 17698 ncf.sync() 17699 17700 ncvars = ncf.variables.keys() 17701 # Re-arranging coordinates attribute for all the variables 17702 for varn in ncvars: 17703 varobj = ncf.variables[varn] 17704 varattrs = varobj.ncattrs() 17705 if gen.searchInlist(varattrs, unicode('coordinates')): 17706 attrv = varobj.getncattr('coordinates') 17707 newcoord = str(attrv) 17708 for dimn in CFdims.keys(): 17709 newcoord = newcoord.replace(dimn, CFdims[dimn]) 17710 newattr = set_attribute(varobj, 'coordinates', newcoord) 17711 17712 ncf.sync() 17713 ncf.close() 17714 17715 print fname + ": succesfull CFication of DYNAMICO file '" + ncfile + "' !!" 17716 17717 return 17718 17644 17719 def CDO_toCF(ncfile): 17645 17720 """ Function to pass a CDO output file to CF-conventions
Note: See TracChangeset
for help on using the changeset viewer.