- Timestamp:
- Mar 14, 2016, 6:30:50 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r699 r700 9852 9852 # newval = float32(val) 9853 9853 elif vtype == type(np.int(1)): 9854 newval = np.int(val) 9854 typeinf = np.iinfo(np.int) 9855 if (abs(np.float64(val)) > typeinf.max): 9856 newval = abs(np.float64(val))/np.float64(val) * np.int(typeinf.max) 9855 9857 elif vtype == type(np.int16(1)): 9856 newval = np.int16(val) 9858 typeinf = np.iinfo(np.int16) 9859 if (abs(np.float64(val)) > typeinf.max): 9860 newval = abs(np.float64(val))/np.float64(val) * np.int16(typeinf.max) 9857 9861 elif vtype == type(np.int32(1)): 9858 newval = np.int32(val) 9862 typeinf = np.iinfo(np.int32) 9863 if (abs(np.float64(val)) > typeinf.max): 9864 newval = abs(np.float64(val))/np.float64(val) * np.int32(typeinf.max) 9859 9865 elif vtype == type(np.int64(1)): 9860 9866 newval = np.int64(val) 9861 9867 elif vtype == type(np.float(1)): 9862 9868 newval = np.float(val) 9863 elif vtype == type(np.float16(1)):9864 newval = np.float16(val)9869 # elif vtype == type(np.float16(1)): 9870 # newval = np.float16(val) 9865 9871 elif vtype == type(np.float32(1)): 9866 9872 newval = np.float32(val) … … 13609 13615 """ Function to retrieve statistics from a field 13610 13616 field_stats(values, ncfile, varn) 13611 [values]= kind of statistics 13612 'full': all statistics given variable 13617 [values]= [stats],[fillVals] 13618 [stats]: kind of statistics 13619 'full': all statistics given variable 13620 [fillVals]: ':' list of _fillValues ('None' for any) 13613 13621 [ncfile]= name of the netCDF file to use 13614 13622 [varn]= variable name to use ('all' for all variables) 13615 13623 """ 13616 13624 import numpy.ma as ma 13617 13625 fname='field_stats' 13618 13626 … … 13621 13629 print field_stats.__doc__ 13622 13630 quit() 13631 13632 13633 arguments = '[stats],[fillVals]' 13634 check_arguments(fname,values,arguments,',') 13635 13636 stats=values.split(',')[0] 13637 fillVals=values.split(',')[1] 13638 13639 if fillVals == 'None': 13640 fillV = None 13641 else: 13642 if fillVals.find(':') != -1: 13643 fillV = fillVals.split(':') 13644 NfillV = len(fillV) 13645 else: 13646 fillV = [fillVals] 13647 NfillV = 1 13623 13648 13624 13649 ncobj = NetCDFFile(ncfile, 'r') … … 13639 13664 objfield = ncobj.variables[vn] 13640 13665 field = objfield[:] 13666 dtype = objfield.dtype 13667 print 'Lluis dtype:',dtype,'fillVals:',fillV 13668 if fillVals is not None: 13669 for ifV in range(NfillV): 13670 print 'fV:', fillV[ifV] 13671 fillval = retype(fillV[ifV], dtype) 13672 field = ma.masked_equal(field, fillval) 13641 13673 13642 13674 print ' ' + vn + '... .. .' 13643 if values == 'full':13675 if stats == 'full': 13644 13676 minv = np.min(field) 13645 13677 maxv = np.max(field)
Note: See TracChangeset
for help on using the changeset viewer.