35
35
from py_eddy_tracker_classes import plt , np , dt , Dataset , ndimage , time , \
36
36
datestr2datetime , gaussian_resolution , \
37
37
get_cax , collection_loop , track_eddies , \
38
- anim_figure
38
+ anim_figure , interpolate
39
39
import make_eddy_tracker_list_obj as eddy_tracker
40
40
from dateutil import parser
41
41
from mpl_toolkits .basemap import Basemap
@@ -505,8 +505,8 @@ def __init__(self, AVISO_FILE, LONMIN, LONMAX, LATMIN, LATMAX,
505
505
self .set_u_v_eke ()
506
506
pad2 = 2 * self .pad
507
507
self .shape = (self .f ().shape [0 ] - pad2 , self .f ().shape [1 ] - pad2 )
508
+
508
509
509
-
510
510
def get_AVISO_data (self , AVISO_FILE ):
511
511
"""
512
512
Read nc data from AVISO file
@@ -517,7 +517,7 @@ def get_AVISO_data(self, AVISO_FILE):
517
517
ssh1 = self .read_nc (AVISO_FILE , 'SLA' ,
518
518
indices = '[:, self.jp0:self.jp1, :self.ip0]' )
519
519
ssh0 = self .read_nc (AVISO_FILE , 'SLA' ,
520
- indices = '[:,self.jp0:self.jp1, self.ip1:]' )
520
+ indices = '[:, self.jp0:self.jp1, self.ip1:]' )
521
521
ssh0 , ssh1 = ssh0 .squeeze (), ssh1 .squeeze ()
522
522
ssh0 *= 100. # m to cm
523
523
ssh1 *= 100. # m to cm
@@ -526,7 +526,7 @@ def get_AVISO_data(self, AVISO_FILE):
526
526
ssh1 = self .read_nc (AVISO_FILE , 'Grid_0001' ,
527
527
indices = '[:self.ip0, self.jp0:self.jp1]' ).T
528
528
ssh0 = self .read_nc (AVISO_FILE , 'Grid_0001' ,
529
- indices = '[self.ip1:,self.jp0:self.jp1]' ).T
529
+ indices = '[self.ip1:, self.jp0:self.jp1]' ).T
530
530
531
531
zeta = np .ma .concatenate ((ssh0 , ssh1 ), axis = 1 )
532
532
@@ -591,19 +591,19 @@ def fillmask(self, x, mask):
591
591
592
592
# Multiply the queried good points by the weight, selecting only the
593
593
# nearest points. Divide by the number of nearest points to get average
594
- xfill = weight * x [igood [:,0 ][iquery ], igood [:,1 ][iquery ]]
595
- xfill = (xfill / weight .sum (axis = 1 )[:,np .newaxis ]).sum (axis = 1 )
594
+ xfill = weight * x [igood [:, 0 ][iquery ], igood [:,1 ][iquery ]]
595
+ xfill = (xfill / weight .sum (axis = 1 )[:, np .newaxis ]).sum (axis = 1 )
596
596
597
597
# Place average of nearest good points, xfill, into bad point locations
598
- x [ibad [:,0 ], ibad [:,1 ]] = xfill
598
+ x [ibad [:, 0 ], ibad [:, 1 ]] = xfill
599
599
return x
600
600
601
601
602
602
def lon (self ):
603
603
if self .ZERO_CROSSING :
604
604
# TO DO: These concatenations are possibly expensive, they
605
605
# shouldn't need to happen with every call to self.lon()
606
- lon0 = self ._lon [self .j0 :self .j1 , self .i1 :]
606
+ lon0 = self ._lon [self .j0 :self .j1 , self .i1 :]
607
607
lon1 = self ._lon [self .j0 :self .j1 , :self .i0 ]
608
608
print 'fix this so called only once'
609
609
return np .concatenate ((lon0 - 360. , lon1 ), axis = 1 )
@@ -612,23 +612,23 @@ def lon(self):
612
612
613
613
def lat (self ):
614
614
if self .ZERO_CROSSING :
615
- lat0 = self ._lat [self .j0 :self .j1 , self .i1 :]
615
+ lat0 = self ._lat [self .j0 :self .j1 , self .i1 :]
616
616
lat1 = self ._lat [self .j0 :self .j1 , :self .i0 ]
617
617
return np .concatenate ((lat0 , lat1 ), axis = 1 )
618
618
else :
619
619
return self ._lat [self .j0 :self .j1 , self .i0 :self .i1 ]
620
620
621
621
def lonpad (self ):
622
622
if self .ZERO_CROSSING :
623
- lon0 = self ._lon [self .jp0 :self .jp1 , self .ip1 :]
623
+ lon0 = self ._lon [self .jp0 :self .jp1 , self .ip1 :]
624
624
lon1 = self ._lon [self .jp0 :self .jp1 , :self .ip0 ]
625
625
return np .concatenate ((lon0 - 360. , lon1 ), axis = 1 )
626
626
else :
627
627
return self ._lon [self .jp0 :self .jp1 , self .ip0 :self .ip1 ]
628
628
629
629
def latpad (self ):
630
630
if self .ZERO_CROSSING :
631
- lat0 = self ._lat [self .jp0 :self .jp1 , self .ip1 :]
631
+ lat0 = self ._lat [self .jp0 :self .jp1 , self .ip1 :]
632
632
lat1 = self ._lat [self .jp0 :self .jp1 , :self .ip0 ]
633
633
return np .concatenate ((lat0 , lat1 ), axis = 1 )
634
634
else :
@@ -665,7 +665,7 @@ def pn(self): # Reciprocal of dy
665
665
666
666
def get_resolution (self ):
667
667
return np .sqrt (np .diff (self .lon ()[1 :], axis = 1 ) *
668
- np .diff (self .lat ()[:,1 :], axis = 0 )).mean ()
668
+ np .diff (self .lat ()[:, 1 :], axis = 0 )).mean ()
669
669
670
670
671
671
def boundary (self ):
@@ -676,10 +676,10 @@ def boundary(self):
676
676
Returns:
677
677
lon/lat boundary points
678
678
"""
679
- lon = np .r_ [(self .lon ()[:,0 ], self .lon ()[- 1 ],
680
- self .lon ()[::- 1 ,- 1 ], self .lon ()[0 ,::- 1 ])]
681
- lat = np .r_ [(self .lat ()[:,0 ], self .lat ()[- 1 ],
682
- self .lat ()[::- 1 ,- 1 ], self .lat ()[0 ,::- 1 ])]
679
+ lon = np .r_ [(self .lon ()[:, 0 ], self .lon ()[- 1 ],
680
+ self .lon ()[::- 1 , - 1 ], self .lon ()[0 , ::- 1 ])]
681
+ lat = np .r_ [(self .lat ()[:, 0 ], self .lat ()[- 1 ],
682
+ self .lat ()[::- 1 , - 1 ], self .lat ()[0 , ::- 1 ])]
683
683
return lon , lat
684
684
685
685
@@ -693,32 +693,15 @@ def brypath(self, imin=0, imax=-1, jmin=0, jmax=-1):
693
693
return path .Path (brypath )
694
694
695
695
696
- #def pcol_2dxy(self, x, y):
697
- #"""
698
- #Function to shift x, y for subsequent use with pcolor
699
- #by Jeroen Molemaker UCLA 2008
700
- #"""
701
- #Mp, Lp = x.shape
702
- #M = Mp - 1
703
- #L = Lp - 1
704
- #x_pcol = np.zeros((Mp, Lp))
705
- #y_pcol = np.zeros((Mp, Lp))
706
- #x_tmp = self.half_interp(x[:,:L], x[:,1:Lp])
707
- #x_pcol[1:Mp,1:Lp] = self.half_interp(x_tmp[0:M,:], x_tmp[1:Mp,:])
708
- #x_pcol[0,:] = 2. * x_pcol[1,:] - x_pcol[2,:]
709
- #x_pcol[:,0] = 2. * x_pcol[:,1] - x_pcol[:,2]
710
- #y_tmp = self.half_interp(y[:,0:L], y[:,1:Lp] )
711
- #y_pcol[1:Mp,1:Lp] = self.half_interp(y_tmp[0:M,:], y_tmp[1:Mp,:])
712
- #y_pcol[0,:] = 2. * y_pcol[1,:] - y_pcol[2,:]
713
- #y_pcol[:,0] = 2. * y_pcol[:,1] - y_pcol[:,2]
714
- #return x_pcol, y_pcol
715
-
716
-
717
-
718
-
719
-
720
-
721
-
696
+
697
+ def set_interp_coeffs (self , sla , uspd ):
698
+ """
699
+ """
700
+ self .sla_coeffs = interpolate .RectBivariateSpline (
701
+ self .lat ()[:, 0 ], self .lon ()[0 ], sla , kx = 1 , ky = 1 )
702
+ self .uspd_coeffs = interpolate .RectBivariateSpline (
703
+ self .lat ()[:, 0 ], self .lon ()[0 ], uspd , kx = 1 , ky = 1 )
704
+ return self
722
705
723
706
724
707
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@@ -840,16 +823,16 @@ def brypath(self, imin=0, imax=-1, jmin=0, jmax=-1):
840
823
#--------------------------------------------------------------------------
841
824
842
825
assert DATE_STR < DATE_END , 'DATE_END must be larger than DATE_STR'
843
- assert DIAGNOSTIC_TYPE in ('Q' , 'SLA' ), 'DIAGNOSTIC_TYPE not properly defined '
826
+ assert DIAGNOSTIC_TYPE in ('Q' , 'SLA' ), 'Undefined DIAGNOSTIC_TYPE '
844
827
845
828
thestartdate = dt .date2num (datestr2datetime (str (DATE_STR )))
846
829
theenddate = dt .date2num (datestr2datetime (str (DATE_END )))
847
830
848
831
# Get complete AVISO file list
849
832
AVISO_FILES = sorted (glob .glob (DATA_DIR + AVISO_FILES ))
850
833
851
- # Use this for subsampling to get identical list as old_AVISO
852
- #AVISO_FILES = AVISO_FILES[5:-5:7]
834
+ # For subsampling to get identical list as old_AVISO use:
835
+ # AVISO_FILES = AVISO_FILES[5:-5:7]
853
836
if AVISO_DT14 and AVISO_DT14_SUBSAMP :
854
837
AVISO_FILES = AVISO_FILES [5 :- 5 :np .int (DAYS_BTWN_RECORDS )]
855
838
@@ -1118,14 +1101,20 @@ def brypath(self, imin=0, imax=-1, jmin=0, jmax=-1):
1118
1101
C_eddy .slacopy = sla .copy ()
1119
1102
1120
1103
# Get scalar speed
1121
- Uspd = np .sqrt (sla_grd .u ** 2 + sla_grd .v ** 2 )
1122
- Uspd = np .ma .masked_where (
1104
+ uspd = np .sqrt (sla_grd .u ** 2 + sla_grd .v ** 2 )
1105
+ uspd = np .ma .masked_where (
1123
1106
sla_grd .mask [sla_grd .jup0 :sla_grd .jup1 ,
1124
1107
sla_grd .iup0 :sla_grd .iup1 ] == False ,
1125
- Uspd )
1126
- A_eddy .Uspd = Uspd .copy ()
1127
- C_eddy .Uspd = Uspd .copy ()
1108
+ uspd )
1109
+ A_eddy .uspd = uspd .copy ()
1110
+ C_eddy .uspd = uspd .copy ()
1128
1111
1112
+ # Set interpolation coefficients
1113
+ sla_grd .set_interp_coeffs (sla , uspd )
1114
+ A_eddy .sla_coeffs = sla_grd .sla_coeffs
1115
+ A_eddy .uspd_coeffs = sla_grd .uspd_coeffs
1116
+ C_eddy .sla_coeffs = sla_grd .sla_coeffs
1117
+ C_eddy .uspd_coeffs = sla_grd .uspd_coeffs
1129
1118
1130
1119
# Get contours of Q/sla parameter
1131
1120
if 'first_record' not in locals ():
0 commit comments