- Timestamp:
- Mar 31, 2015, 10:37:35 AM (10 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var.py
r311 r386 21 21 'compute_opervaralltime', 'compute_opervartimes', 'compute_tevolboxtraj', \ 22 22 'DataSetSection', 'DataSetSection_multidims', 'dimVar_creation', 'fattradd', \ 23 'fdimadd', 'fgaddattr', 'field_stats', 'file_oper_alongdims', 'filter_2dim', \ 23 'fdimadd', 'fgaddattr', 'field_stats', 'file_creation', 'file_oper_alongdims', \ 24 'filter_2dim', \ 24 25 'flipdim', 'fvaradd', 'gaddattrk', 'gaddattr', 'get_namelist_vars', 'grattr', \ 25 26 'grmattr', 'igattrs', 'isgattrs', 'isvattrs', 'ivars', 'ivattrs', 'maskvar', \ … … 77 78 78 79 # Operations which file name is not a real file 79 NotCheckingFile = [' list_operations', 'netcdf_concatenation', 'netcdf_fold_concatenation']80 NotCheckingFile = ['file_creation', 'list_operations', 'netcdf_concatenation', 'netcdf_fold_concatenation'] 80 81 81 82 ####### ###### ##### #### ### ## # … … 127 128 elif oper == 'fgaddattr': 128 129 ncvar.fgaddattr(opts.values, opts.ncfile) 130 elif oper == 'file_creation': 131 ncvar.file_creation(opts.values, opts.ncfile, opts.varname) 129 132 elif oper == 'file_oper_alongdims': 130 133 ncvar.file_oper_alongdims(opts.values, opts.ncfile, opts.varname) -
trunk/tools/nc_var_tools.py
r377 r386 13745 13745 #ncstepdiff('Time,Times', '/home/lluis/PY/wrfout_d01_2001-11-11_00:00:00.tests', 'Q2,T2') 13746 13746 13747 def file_creation(values, ncfile, varn): 13748 """ Operation to create a file with one variable with a given set of dimensions 13749 values= [dimensions]|[varattributes]|[kind] 13750 [dimensions]: [dimn1]:[dsize1],...,[dimnN]:[dsizeN], ',' pairs of variable name [dimn] and [size] 13751 if [dsize] = 'None', give a third value with the real size 13752 [attributes]: [std_name]@[long_name]@[units], standard name, long name and units of the variable 13753 [kind]: type of variable (standard netCDF4/C-like values, 'c', 'i', 'f', 'f8',...) 13754 ncfile= name of the file 13755 varn= name of the variables 13756 """ 13757 fname = 'file_creation' 13758 13759 if values == 'h': 13760 print fname + '_____________________________________________________________' 13761 print file_creation.__doc__ 13762 quit() 13763 13764 expectargs = '[dimensions]|[varattributes]|[kind]' 13765 13766 check_arguments(fname,len(expectargs.split('|')),values,'|',expectargs) 13767 13768 dimensions = values.split('|')[0].split(',') 13769 attributes = values.split('|')[1] 13770 kind = values.split('|')[2] 13771 13772 onc = NetCDFFile(ncfile, 'w') 13773 13774 # Dimensions 13775 dnames = [] 13776 dsize = [] 13777 for dim in dimensions: 13778 # print " Adding: '" + dim + "' ..." 13779 dimn = dim.split(':')[0] 13780 dimv = dim.split(':')[1] 13781 if dimv == 'None': 13782 if len(dim.split(':')) != 3: 13783 print errormsg 13784 print ' ' + fname + ": dimension '" + dimn + "' is None but the " + \ 13785 'size is requried!!' 13786 quit(-1) 13787 else: 13788 dv = None 13789 dsize.append(int(dim.split(':')[2])) 13790 else: 13791 dv = int(dimv) 13792 dsize.append(dv) 13793 13794 dnames.append(dimn) 13795 13796 newdim = onc.createDimension(dimn, dv) 13797 13798 onc.sync() 13799 13800 # Variable 13801 if kind == 'c': 13802 newvar = onc.createVariable(varn, 'c', tuple(dnames)) 13803 # newvar[:] = np.zeros(tuple(dsize), dtype=np.float) 13804 if kind == 'f4': 13805 newvar = onc.createVariable(varn, 'f4', tuple(dnames)) 13806 newvar[:] = np.zeros(tuple(dsize), dtype=np.float) 13807 elif kind == 'f8': 13808 newvar = onc.createVariable(varn, 'f8', tuple(dnames)) 13809 newvar[:] = np.zeros(tuple(dsize), dtype=np.float64) 13810 elif kind == 'i': 13811 newvar = onc.createVariable(varn, 'i', tuple(dnames)) 13812 newvar[:] = np.zeros(tuple(dsize), dtype=int) 13813 else: 13814 print errormsg 13815 print ' ' + fname + ": variable kind '" + kind + "' not ready!!" 13816 quit(-1) 13817 13818 sname = attributes.split('@')[0] 13819 lname = attributes.split('@')[1] 13820 u = attributes.split('@')[2] 13821 13822 newattr = basicvardef(newvar, sname, lname, u) 13823 13824 onc.sync() 13825 13826 # Global attributes 13827 newattr = set_attribute(onc, 'description', "file creation using " + fname ) 13828 onc.sync() 13829 onc.close() 13830 13831 #file_creation('time_counter:12,sizes:24|time@time@seconds since 1949-12-01 00:00:00|f8', 'test.nc', 't_instant') 13832 13747 13833 #quit() 13748 13834
Note: See TracChangeset
for help on using the changeset viewer.