18
18
You should have received a copy of the GNU General Public License
19
19
along with py-eddy-tracker. If not, see <http://www.gnu.org/licenses/>.
20
20
21
- Copyright (c) 2014 by Evan Mason
21
+ Copyright (c) 2014-2015 by Evan Mason
22
22
23
23
===========================================================================
24
24
25
25
26
26
make_eddy_tracker_list_obj.py
27
27
28
- Version 1.4.2
28
+ Version 2.0.0
29
29
30
30
31
31
===========================================================================
@@ -164,23 +164,22 @@ def __init__(self, PRODUCT, lon, lat, time, uavg, teke,
164
164
uavg_profile = None , shape_error = None ):
165
165
166
166
#self.eddy_index = eddy_index
167
- self .PRODUCT = PRODUCT
168
- self .lon = [lon ]
169
- self .lat = [lat ]
167
+ self .PRODUCT = PRODUCT
168
+ self .lon = [lon ]
169
+ self .lat = [lat ]
170
170
self .ocean_time = [time ]
171
- self .uavg = [uavg ]
172
- self .teke = [teke ]
173
- self .radius_s = [radius_s ] # speed-based eddy radius
174
- self .radius_e = [radius_e ] # effective eddy radius
175
- self .amplitude = [amplitude ]
171
+ self .uavg = [uavg ]
172
+ self .teke = [teke ]
173
+ self .radius_s = [radius_s ] # speed-based eddy radius
174
+ self .radius_e = [radius_e ] # effective eddy radius
175
+ self .amplitude = [amplitude ]
176
176
if 'ROMS' in self .PRODUCT :
177
- #self.temp = [temp]
177
+ #self.temp = [temp]
178
+ #self.salt = [salt]
178
179
pass
179
- #self.salt = [salt]
180
- #self.bounds = np.atleast_2d(bounds)
181
- self .alive = True
182
- self .dayzero = True
183
- self .saved2nc = False
180
+ self .alive = True
181
+ self .dayzero = True
182
+ self .saved2nc = False
184
183
self .save_extras = save_extras
185
184
if self .save_extras :
186
185
self .contour_e = [contour_e ]
@@ -222,7 +221,9 @@ def _is_alive(self, rtime):
222
221
If not active, kill it
223
222
"""
224
223
# The eddy...
225
- if self .alive is False : # is already dead
224
+ #print not self.alive, self.dayzero, self.ocean_time[-1] == rtime
225
+ if not self .alive : # is already dead
226
+ #print '--AAA'
226
227
return self .alive
227
228
elif self .dayzero : # has just been initiated
228
229
self .dayzero = False
@@ -367,7 +368,7 @@ def __getstate__(self):
367
368
"""pops = ('uspd', 'uspd_coeffs', 'sla_coeffs', 'points',
368
369
'circlon', 'circlat', 'sla', 'slacopy', 'swirl',
369
370
'mask_eff', 'mask_eff_sum', 'mask_eff_1d')"""
370
- pops = ('uspd' , 'uspd_coeffs' , 'sla_coeffs' , 'points' ,
371
+ pops = ('uspd' , 'uspd_coeffs' , 'sla_coeffs' , 'points' ,
371
372
'sla' , 'slacopy' , 'swirl' ,
372
373
'mask_eff' , 'mask_eff_sum' , 'mask_eff_1d' )
373
374
result = self .__dict__ .copy ()
@@ -479,8 +480,8 @@ def get_active_tracks(self, rtime):
479
480
inactive tracks.
480
481
"""
481
482
active_tracks = []
482
- for i , item in enumerate (self .tracklist ):
483
- if item ._is_alive (rtime ):
483
+ for i , track in enumerate (self .tracklist ):
484
+ if track ._is_alive (rtime ):
484
485
active_tracks .append (i )
485
486
return active_tracks
486
487
@@ -491,8 +492,8 @@ def get_inactive_tracks(self, rtime):
491
492
inactive tracks
492
493
"""
493
494
inactive_tracks = []
494
- for i , item in enumerate (self .tracklist ):
495
- if not item ._is_alive (rtime ):
495
+ for i , track in enumerate (self .tracklist ):
496
+ if not track ._is_alive (rtime ):
496
497
inactive_tracks .append (i )
497
498
return inactive_tracks
498
499
@@ -715,13 +716,11 @@ def _reduce_inactive_tracks(self):
715
716
if not track .alive :
716
717
track .lon = []
717
718
track .lat = []
718
- track .qparameter = []
719
719
track .amplitude = []
720
720
track .uavg = []
721
721
track .teke = []
722
722
track .radius_s = []
723
723
track .radius_e = []
724
- #track.bounds = []
725
724
track .ocean_time = []
726
725
if self .TRACK_EXTRA_VARIABLES :
727
726
track .contour_e = []
@@ -730,6 +729,21 @@ def _reduce_inactive_tracks(self):
730
729
track .shape_error = []
731
730
return
732
731
732
+ def _remove_inactive_tracks (self ):
733
+ """
734
+ Remove dead tracks from self.tracklist and
735
+ return indices to active tracks.
736
+ """
737
+ new_tracklist = []
738
+ for track in self .tracklist :
739
+ new_tracklist .append (track .alive )
740
+ #print new_tracklist
741
+ alive_inds = np .nonzero (new_tracklist )[0 ]
742
+ #print alive_inds.shape
743
+ tracklist = np .array (self .tracklist )[alive_inds ]
744
+ self .tracklist = tracklist .tolist ()
745
+ return alive_inds
746
+
733
747
def write2netcdf (self , rtime ):
734
748
"""
735
749
Write inactive tracks to netcdf file.
@@ -823,27 +837,29 @@ def write2netcdf(self, rtime):
823
837
nc .sync ()
824
838
825
839
# Get index to first currently active track
826
- try :
827
- lasti = self .get_active_tracks (rtime )[0 ]
828
- except Exception :
829
- lasti = None
840
+ # try:
841
+ # lasti = self.get_active_tracks(rtime)[0]
842
+ # except Exception:
843
+ # lasti = None
830
844
845
+ # Remove inactive tracks
846
+ # NOTE: line below used to be below clipping lines below
847
+ #self._reduce_inactive_tracks()
848
+ alive_i = self ._remove_inactive_tracks ()
831
849
# Clip the tracklist,
832
850
# removes all dead tracks preceding first currently active track
833
- self .tracklist = self .tracklist [lasti :]
851
+ # self.tracklist = self.tracklist[alive_i :]
834
852
self .index = len (self .tracklist ) # adjust index accordingly
835
853
836
- # Remove inactive tracks
837
- self ._reduce_inactive_tracks ()
838
854
839
855
# Update old_lon and old_lat...
840
- self .old_lon = self .new_lon [ lasti :]
841
- self .old_lat = self .new_lat [ lasti :]
842
- self .old_radii_s = self .new_radii_s [ lasti :]
843
- self .old_radii_e = self .new_radii_e [ lasti :]
844
- self .old_amp = self .new_amp [ lasti :]
845
- self .old_uavg = self .new_uavg [ lasti :]
846
- self .old_teke = self .new_teke [ lasti :]
856
+ self .old_lon = np . array ( self .new_lon )[ alive_i ]. tolist ()
857
+ self .old_lat = np . array ( self .new_lat )[ alive_i ]. tolist ()
858
+ self .old_radii_s = np . array ( self .new_radii_s )[ alive_i ]. tolist ()
859
+ self .old_radii_e = np . array ( self .new_radii_e )[ alive_i ]. tolist ()
860
+ self .old_amp = np . array ( self .new_amp )[ alive_i ]. tolist ()
861
+ self .old_uavg = np . array ( self .new_uavg )[ alive_i ]. tolist ()
862
+ self .old_teke = np . array ( self .new_teke )[ alive_i ]. tolist ()
847
863
848
864
self .new_lon = []
849
865
self .new_lat = []
@@ -855,17 +871,17 @@ def write2netcdf(self, rtime):
855
871
self .new_time = []
856
872
857
873
if 'ROMS' in self .PRODUCT :
858
- #self.old_temp = self.new_temp[lasti :]
859
- #self.old_salt = self.new_salt[lasti :]
874
+ #self.old_temp = self.new_temp[alive_i :]
875
+ #self.old_salt = self.new_salt[alive_i :]
860
876
pass
861
877
#self.new_temp = []
862
878
#self.new_salt = []
863
879
864
880
if self .TRACK_EXTRA_VARIABLES :
865
- self .old_contour_e = list (self .new_contour_e [lasti : ])
866
- self .old_contour_s = list (self .new_contour_s [lasti : ])
867
- self .old_uavg_profile = list (self .new_uavg_profile [lasti : ])
868
- self .old_shape_error = self .new_shape_error [lasti : ]
881
+ self .old_contour_e = list (self .new_contour_e [alive_i ])
882
+ self .old_contour_s = list (self .new_contour_s [alive_i ])
883
+ self .old_uavg_profile = list (self .new_uavg_profile [alive_i ])
884
+ self .old_shape_error = self .new_shape_error [alive_i ]
869
885
870
886
self .new_contour_e = []
871
887
self .new_contour_s = []
@@ -968,6 +984,7 @@ def __init__(self, THE_DOMAIN, grd, RW_PATH=None):
968
984
self .beta = np .empty (1 )
969
985
self .r_spd_long = np .empty (1 )
970
986
self .start = True
987
+ self .pio180 = np .pi / 180.
971
988
972
989
def __getstate__ (self ):
973
990
"""
@@ -1087,7 +1104,7 @@ def _get_rlongwave_spd(self, xpt, ypt):
1087
1104
self .r_spd_long **= 2
1088
1105
self .beta [:] = np .average (self ._lat [self .i ],
1089
1106
weights = self ._weights ) # lat
1090
- self .beta [:] = np .cos (np . deg2rad ( self .beta ) )
1107
+ self .beta [:] = np .cos (self . pio180 * self .beta )
1091
1108
self .beta *= 1458e-7 # 1458e-7 ~ (2 * 7.29*10**-5)
1092
1109
self .beta /= self .EARTH_RADIUS
1093
1110
self .r_spd_long *= - self .beta
0 commit comments