Changeset 1963 in lmdz_wrf
- Timestamp:
- Jul 24, 2018, 5:42:09 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r1961 r1963 151 151 # splitfile_dim: Function to split a file along a given dimension with a new file for each different value along the dimension (assuming resultant vardim of rank-1) 152 152 # statcompare_files: Python script to statistically compare two different files 153 # stats_lonlat_box: Function to provide the statistics of a variable from a lon,lat box 153 154 # submns: Function to retrieve a series of months from a file 154 155 # subyrs: Function to retrieve a series of years from a file … … 1462 1463 print errormsg 1463 1464 print ' ' + fname + ': File "' + refnc + '" does not have variable: ' + refvar 1465 refvarssort = ncref.variables.keys() 1466 refvarssort.sort() 1467 print ' available ones:', refvarssort 1464 1468 ncf.close() 1465 1469 ncref.close() … … 24824 24828 return 24825 24829 24830 def stats_lonlat_box(vals, lonv, latv, nlon, xlon, nlat, xlat): 24831 """ Function to provide the statistics of a variable from a lon,lat box 24832 vals= values (2D matrix) 24833 lonv= longitude values(2D matrix) 24834 latv= latitude values (2D matrix) 24835 nlon,xlon= minimum and maximum of longitudes 24836 nlat,xlat= minimum and maximum of latitudes 24837 * Returns: [minval, maxval, meanval, stdval], [isw, jsw, ine, jne] 24838 >>> mat = np.arange(40).reshape(10,4) 24839 >>> lon1D = np.arange(-5.,5.,1) 24840 >>> lat1D = np.arange(-35.,-31.,1.) 24841 >>> lat2D, lon2D = np.meshgrid(lat1D, lon1D) 24842 >>> stats_lonlat_box(mat, lon2D, lat2D, -4., 0., -35., -33.) 24843 [4, 39, 21.5, 10.388294694831615] [0, 1, 5, 11] 24844 """ 24845 fname = 'stats_lonlat_box' 24846 24847 # Distance to vertex 24848 SWdist = np.sqrt((lonv-nlon)**2 + (latv-nlat)**2) 24849 NEdist = np.sqrt((lonv-xlon)**2 + (latv-xlat)**2) 24850 24851 nSWdist = np.min(SWdist) 24852 nNEdist = np.min(NEdist) 24853 24854 # indices of vertices 24855 jsw, isw = gen.index_mat(SWdist, nSWdist) 24856 jne, ine = gen.index_mat(NEdist, nNEdist) 24857 24858 ine = np.max([ine+1, vals.shape[1]+1]) 24859 jne = np.max([jne+1, vals.shape[0]+1]) 24860 24861 minval = np.min(vals[jsw:jne,isw:ine]) 24862 maxval = np.max(vals[jsw:jne,isw:ine]) 24863 meanval = np.mean(vals[jsw:jne,isw:ine]) 24864 stdval = np.std(vals[jsw:jne,isw:ine]) 24865 24866 return [minval, maxval, meanval, stdval], [isw, jsw, ine, jne] 24867 24826 24868 #quit()
Note: See TracChangeset
for help on using the changeset viewer.