Changeset 1390 in lmdz_wrf for trunk/tools
- Timestamp:
- Dec 15, 2016, 4:26:53 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r1388 r1390 30 30 fillValueF64 = 1.e20 31 31 fillValueI32 = -99999 32 33 # 12 Months 34 shortmon = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] 32 35 33 36 # For variables_values … … 10827 10830 return linearwgt 10828 10831 10829 def linearint_3x3weights(xvals, yvals, intval ):10832 def linearint_3x3weights(xvals, yvals, intval0): 10830 10833 """ Function to provide the weights for a linear interpolation of a value inside a 3x3 matrix of values as a weighted distance mean 10831 10834 xvals: 3x3 matrix of x-values … … 10857 10860 fname = 'linear_wegiths' 10858 10861 10862 intval = np.array(intval0, dtype=np.float) 10863 print 'type xvals:', xvals.dtype 10864 10859 10865 # Assuming that values come from `vals_around' function (None, when outside matrix size) 10860 10866 xvalsma = ma.masked_equal(xvals,None) … … 10880 10886 quit(-1) 10881 10887 10882 dist = np.sqrt( (xvalsma-intval[1])**2 + (yvalsma-intval[0])**2) 10888 print 'Lluis intval:', intval 10889 print ' ' + fname + ' Lluis xvalsma ____' 10890 print xvalsma 10891 10892 print ' ' + fname + ' Lluis yvalsma ____' 10893 print yvalsma 10894 10895 dist = np.sqrt( (xvals-intval[1])**2 + (yvals-intval[0])**2) 10883 10896 inc = np.sum(dist) 10884 10897 print 'inc:', inc, 'intval', intval … … 10909 10922 iijj = iijj + 1 10910 10923 10911 # Normalizing values (only lthe first 4)10924 # Normalizing values (only the first 4) 10912 10925 if iijj >= 3: 10913 10926 inc = np.sum(sortdist[0:4]) … … 10943 10956 yvals= 2D matrix of y-coordinate values 10944 10957 RETURNS: 10945 curvloc = [2,Npts] matrix with the closest i,j grid point in the 2D space of the field positions 10946 curvweights = [3,3,Npts] 3x3 matrix weights around the curve position 10958 curvloc= [2,Npts] matrix with the closest i,j grid point in the 2D space of the field positions 10959 curvweights= [Npts,3,3] 3x3 matrix weights around the curve position 10960 Nwgt= Number of weights 10961 ijaorund3x3= [2,9] distance (in xval, yval units) to the curve position 10947 10962 """ 10948 10963 fname = 'curvelocalize_2D' … … 10959 10974 mindist = np.min(dist) 10960 10975 ijloc = index_mat(dist,mindist) 10961 iloc[icv] = ijloc[1] 10962 jloc[icv] = ijloc[0] 10976 10977 curvloc[0,icv] = ijloc[0] 10978 curvloc[1,icv] = ijloc[1] 10963 10979 10964 10980 # Values around the nearest 2D-point to the curve point 10965 10981 xaroundvls = vals_around(xvals,ijloc) 10966 10982 yaroundvls = vals_around(yvals,ijloc) 10967 10968 curveweights[icv,:,:], Npts, ijaorund3x3= linearint_3x3weights(xvals, yvals, \ 10969 intval) 10983 print 'Lluis type xaroundvls:', type(xaroundvls) 10984 10985 curveweights[icv,:,:], Nwgt, ijaorund3x3= linearint_3x3weights(xaroundvls, \ 10986 yaroundvls, curve[:,icv]) 10970 10987 10971 10972 return 10973 10974 10988 return curvloc, curveweights, Nwgt, ijaround3x3 10989 10990 #lon1d = np.arange(10) 10991 #lat1d = np.arange(-5,5) 10992 #dx = lon1d.shape[0] 10993 #dy = lat1d.shape[0] 10994 10995 #lons = np.zeros((dy,dx), dtype=np.float) 10996 #lats = np.zeros((dy,dx), dtype=np.float) 10997 10998 #for iy in range(dy): 10999 # lons[iy,:] = lon1d 11000 #for ix in range(dx): 11001 # lats[:,ix] = lat1d 11002 11003 #Ncurve = 12 11004 #iicurve = 0 11005 #eicurve = dx-1 11006 #ijcurve = 1 11007 #ejcurve = dy-3 11008 #iloncurve = lon1d[iicurve] 11009 #eloncurve = lon1d[eicurve] 11010 #ilatcurve = lat1d[ijcurve] 11011 #elatcurve = lat1d[ejcurve] 11012 #Dxcurve = (eloncurve-iloncurve)/(Ncurve-1.) 11013 #Dycurve = (elatcurve-ilatcurve)/(Ncurve-1.) 11014 11015 #curve = np.zeros((2,Ncurve), dtype=np.float) 11016 #for icv in range(Ncurve): 11017 # curve[0,icv] = ilatcurve + Dycurve*icv 11018 # curve[1,icv] = iloncurve + Dxcurve*icv 11019 11020 #print 'Curve origin:', ilatcurve, ',', iloncurve 11021 #print 'Curve ending:', elatcurve, ',', eloncurve 11022 11023 #print curve 11024 11025 #loccurve, wgts, Nwgts, loc3x3 = curvelocalize_2D(curve,lons,lats) 11026 #print loccurve 10975 11027 #quit()
Note: See TracChangeset
for help on using the changeset viewer.