2424
2525make_eddy_track_AVISO.py
2626
27- Version 1.2.0
27+ Version 1.2.1
2828
2929
3030Scroll down to line ~640 to get started
@@ -61,8 +61,8 @@ def __init__(self):
6161 '''
6262 Set some constants
6363 '''
64- gravity = 9.81
65- earth_radius = 6371315.0
64+ self . gravity = 9.81
65+ self . earth_radius = 6371315.0
6666
6767
6868 def read_nc (self , varfile , varname , indices = "[:]" ):
@@ -241,7 +241,7 @@ def get_AVISO_f_pm_pn(self):
241241 self ._gof *= 4.
242242 self ._gof *= np .pi
243243 self ._gof /= 86400.
244- self ._gof = 9.81 / self ._gof
244+ self ._gof = self . gravity / self ._gof
245245
246246 lonu = self .half_interp (self .lonpad ()[:,:- 1 ], self .lonpad ()[:,1 :])
247247 latu = self .half_interp (self .latpad ()[:,:- 1 ], self .latpad ()[:,1 :])
@@ -375,6 +375,7 @@ def __init__(self, AVISO_file, lonmin, lonmax, latmin, latmax, with_pad=True, us
375375 self .lonmax = lonmax
376376 self .latmin = latmin
377377 self .latmax = latmax
378+ self .gravity = 9.81
378379
379380 try : # new AVISO (2014)
380381 self ._lon = self .read_nc (AVISO_file , 'lon' )
@@ -438,7 +439,7 @@ def get_AVISO_data(self, AVISO_file):
438439 #zeta = fillmask(zeta, 1 + (-1 * zeta.mask))
439440 except Exception : # In case no landpoints
440441 zeta = np .ma .masked_array (zeta )
441- return zeta
442+ return zeta . astype ( np . float64 )
442443
443444
444445
@@ -470,7 +471,7 @@ def fillmask(self, x, mask):
470471 # Points greater than one are then set to zero
471472 weight = dist / (dist .min (axis = 1 )[:,np .newaxis ])
472473 weight *= np .ones_like (dist )
473- np .place (weight , weight > 1. , 0. )
474+ np .place (weight , weight > 1. , 0. )
474475
475476 # Multiply the queried good points by the weight, selecting only the
476477 # nearest points. Divide by the number of nearest points to get average
@@ -653,41 +654,51 @@ def pcol_2dxy(self, x, y):
653654 # Specify use of new AVISO 2014 data
654655 new_AVISO = True
655656
657+ # Specify subsampling new AVISO 2014 data; i.e. you may
658+ # prefer to use every second day rather than every day
659+ if new_AVISO :
660+ new_AVISO_SUBSAMP = True
661+ if new_AVISO_SUBSAMP :
662+ days_btwn_recs = 7. # put sampling rate (days) here
663+ else :
664+ days_btwn_recs = 1.
665+ else : # old seven day AVISO
666+ days_btwn_recs = 7.
667+
656668 # Set path(s) to directory where SSH data are stored...
657669 if 'Global' in the_domain :
658670 if new_AVISO :
659- directory = '/path/to/your/aviso_data/'
671+ # directory = '/path/to/your/aviso_data/'
660672 #directory = '/shared/Altimetry/global/delayed-time/grids/msla/all-sat-merged/h/'
661- AVISO_files = 'dt_global_allsat_msla_h_????????_20140106.nc'
662- days_btwn_recs = 1.
673+ #AVISO_files = 'dt_global_allsat_msla_h_????????_20140106.nc'
674+ directory = '/shared/Altimetry/global/delayed-time/grids/msla/two-sat-merged/h/'
675+ AVISO_files = 'dt_global_twosat_msla_h_????????_20140106.nc'
663676 else :
664677 directory = '/path/to/your/aviso_data/'
665678 #directory = '/marula/emason/data/altimetry/MSLA/GLOBAL/DT/REF/'
666679 AVISO_files = 'dt_ref_global_merged_msla_h_qd_????????_*.nc'
667- days_btwn_recs = 7.
668680
669681 elif 'MedSea' in the_domain :
670682 if new_AVISO :
671- directory = '/path/to/your/aviso_data/'
672- # directory = '/shared/Altimetry/regional-mediterranean/delayed-time/grids/msla/all-sat-merged/h/'
683+ # directory = '/path/to/your/aviso_data/'
684+ directory = '/shared/Altimetry/regional-mediterranean/delayed-time/grids/msla/all-sat-merged/h/'
673685 AVISO_files = 'dt_blacksea_allsat_msla_h_????????_*.nc'
674686 else :
675687 pass
676688
677689 elif 'BlackSea' in the_domain :
678690 if new_AVISO :
679- directory = '/path/to/your/aviso_data/'
680- #irectory = '/shared/Altimetry/regional-blacksea/delayed-time/grids/msla/all-sat-merged/h/'
691+ # directory = '/path/to/your/aviso_data/'
692+ directory = '/shared/Altimetry/regional-blacksea/delayed-time/grids/msla/all-sat-merged/h/'
681693 AVISO_files = 'dt_blacksea_allsat_msla_h_????????_*.nc'
682- days_btwn_recs = 1.
683694 else :
684695 Exception #no_domain_specified
685696
686697
687698 # Set date range (YYYYMMDD)
688- date_str , date_end = 19980107 , 19991110 #
699+ # date_str, date_end = 19980107, 19991110 #
689700 #date_str, date_end = 20081107, 20100110 #
690- # date_str, date_end = 19930101, 20121231 #
701+ date_str , date_end = 19930101 , 20121231 #
691702
692703 # Choose type of diagnostic: either q-parameter ('Q') or sea level anomaly ('sla')
693704 #diag_type = 'Q' <<< not implemented in 1.2.0
@@ -697,12 +708,13 @@ def pcol_2dxy(self, x, y):
697708 # Path to directory where outputs are to be saved...
698709 #savedir = directory
699710 #savedir = '/marula/emason/aviso_eddy_tracking/pablo_exp/'
700- # savedir = '/marula/emason/aviso_eddy_tracking/new_AVISO_test/'
711+ savedir = '/marula/emason/aviso_eddy_tracking/new_AVISO_test/'
701712 #savedir = '/marula/emason/aviso_eddy_tracking/new_AVISO_test_0.35/'
702713 #savedir = '/marula/emason/aviso_eddy_tracking/new_AVISO_test_0.3/'
714+ #savedir = '/marula/emason/aviso_eddy_tracking/new_AVISO/CEC/'
703715 #savedir = '/shared/emason/eddy_tracks/Barbara/2009/'
704716 #savedir = '/marula/emason/aviso_eddy_tracking/new_AVISO_test/BlackSea/'
705- savedir = '/path/to/save/your/outputs/'
717+ # savedir = '/path/to/save/your/outputs/'
706718
707719
708720 # True to save outputs in same style as Chelton
@@ -724,7 +736,7 @@ def pcol_2dxy(self, x, y):
724736 ampmax = 100.
725737
726738 elif 'sla' in diag_type :
727- radmin = 0.3 # degrees (Chelton recommends ~50 km minimum)
739+ radmin = 0.35 # degrees (Chelton recommends ~50 km minimum)
728740 radmax = 4.461 # degrees
729741 ampmin = 1. # cm
730742 ampmax = 150.
@@ -769,15 +781,16 @@ def pcol_2dxy(self, x, y):
769781
770782 subdomain = True
771783 if the_domain in 'Global' :
772- lonmin = - 36. # Canary
773- lonmax = - 7.5
774- latmin = 18.
775- latmax = 33.2
784+
785+ #lonmin = -36. # Canary
786+ #lonmax = -7.5
787+ #latmin = 18.
788+ #latmax = 33.2
776789
777- # lonmin = -65. # Corridor
778- # lonmax = -5.5
779- # latmin = 11.5
780- # latmax = 38.5
790+ lonmin = - 65. # Corridor
791+ lonmax = - 5.5
792+ latmin = 11.5
793+ latmax = 38.5
781794
782795 #lonmin = -179. # SEP
783796 #lonmax = -65
@@ -794,18 +807,22 @@ def pcol_2dxy(self, x, y):
794807 #latmin = -47.
795808 #latmax = -24.
796809
810+
797811 elif the_domain in 'MedSea' :
812+
798813 lonmin = 354. # SEP
799814 lonmax = 396
800815 latmin = 30.
801816 latmax = 46.
802817
803818 elif the_domain in 'BlackSea' :
804- lonmin = 27. # SEP
819+
820+ lonmin = 27. # Black Sea
805821 lonmax = 42.
806822 latmin = 40.
807823 latmax = 47.
808824
825+
809826 # Typical parameters
810827 dist0 = 25000. # m separation distance after ~7 days (see CSS11 fig 22)
811828 if 'Q' in diag_type :
@@ -818,10 +835,10 @@ def pcol_2dxy(self, x, y):
818835
819836 # Parameters used by Chelton etal and Kurian etal (Sec. 3.2) to ensure the slow evolution
820837 # of the eddies over time; they use min and max values of 0.25 and 2.5
821- evolve_ammin = 0.05 # 0.25 # min change in amplitude
822- evolve_ammax = 5 #2.5 # max change in amplitude
823- evolve_armin = 0.05 # 0.25 # min change in area
824- evolve_armax = 5 # max change in area
838+ evolve_ammin = 0.01 # 0.25 # min change in amplitude
839+ evolve_ammax = 10 #2.5 # max change in amplitude
840+ evolve_armin = 0.01 # 0.25 # min change in area
841+ evolve_armax = 10 # max change in area
825842
826843
827844 separation_method = 'ellipse' # see CSS11
@@ -854,6 +871,9 @@ def pcol_2dxy(self, x, y):
854871 # Get complete AVISO file list
855872 AVISO_files = sorted (glob .glob (directory + AVISO_files ))
856873
874+ # Use this for subsampling to get identical list as old_AVISO
875+ #AVISO_files = AVISO_files[5:-5:7]
876+
857877 # Set up a grid object using first AVISO file in the list
858878 sla_grd = AVISO_grid (AVISO_files [0 ], lonmin , lonmax , latmin , latmax )
859879
@@ -1020,20 +1040,25 @@ def pcol_2dxy(self, x, y):
10201040 # Loop through the AVISO files...
10211041 start = True
10221042 start_time = time .time ()
1043+
10231044 print '\n Start tracking'
1045+
10241046 for AVISO_file in AVISO_files :
10251047
1026-
10271048 with netcdf .Dataset (AVISO_file ) as nc :
1028-
1049+
10291050 try :
10301051 thedate = nc .OriginalName
1031- thedate = thedate .partition ('qd_' )[2 ].partition ('_' )[0 ]
1052+ if 'qd_' in thedate :
1053+ thedate = thedate .partition ('qd_' )[2 ].partition ('_' )[0 ]
1054+ else :
1055+ thedate = thedate .partition ('h_' )[2 ].partition ('_' )[0 ]
10321056 thedate = datestr2datetime (thedate )
10331057 thedate = dt .date2num (thedate )
10341058 except Exception :
10351059 thedate = nc .variables ['time' ][:]
10361060 thedate += sla_grd .base_date
1061+
10371062 rtime = thedate
10381063
10391064 if np .logical_and (thedate >= thestartdate ,
@@ -1174,33 +1199,39 @@ def pcol_2dxy(self, x, y):
11741199
11751200 # Get contours of Q/sla parameter
11761201 if 'first_record' not in locals ():
1202+
11771203 print '------ getting SLA contours'
1178- plt .figure (99 )
1204+ contfig = plt .figure (99 )
1205+ ax = contfig .add_subplot (111 )
1206+
1207+ if anim_figs :
1208+ animfig = plt .figure (999 )
1209+ animax = animfig .add_subplot (111 )
1210+
11791211 if 'Q' in diag_type :
1180- CS = plt .contour (sla_grd .lon (),
1212+ CS = ax .contour (sla_grd .lon (),
11811213 sla_grd .lat (), qparam , qparameter )
11821214 # Get xi contour field at zero
1183- CSxi = plt .contour (sla_grd .lon (),
1215+ CSxi = ax .contour (sla_grd .lon (),
11841216 sla_grd .lat (), xi , [0. ])
11851217
11861218 elif 'sla' in diag_type :
1187- A_CS = plt .contour (sla_grd .lon (),
1219+ A_CS = ax .contour (sla_grd .lon (),
11881220 sla_grd .lat (), A_eddy .sla , slaparameter )
11891221 # Note that CSc is for the cyclonics, slaparameter in reverse order
1190- C_CS = plt .contour (sla_grd .lon (),
1222+ C_CS = ax .contour (sla_grd .lon (),
11911223 sla_grd .lat (), C_eddy .sla , slaparameter [::- 1 ])
11921224 else : Exception
11931225
1194- if True :
1195- plt .close (99 )
1196- else :
1197- # Debug
1226+ if True : # clear the current axis
1227+ ax .cla ()
1228+ else : # draw debug figure
11981229 if 'Q' in diag_type :
1199- plt . title ('qparameter and xi' )
1200- plt .clabel (CS , np .array ([qparameter .min (), qparameter .max ()]))
1230+ ax . set_title ('qparameter and xi' )
1231+ ax .clabel (CS , np .array ([qparameter .min (), qparameter .max ()]))
12011232 elif 'sla' in diag_type :
1202- plt . title ('slaparameter' )
1203- plt .clabel (A_CS , np .array ([slaparameter .min (), slaparameter .max ()]))
1233+ ax . set_title ('slaparameter' )
1234+ ax .clabel (A_CS , np .array ([slaparameter .min (), slaparameter .max ()]))
12041235 plt .axis ('image' )
12051236 plt .show ()
12061237
@@ -1227,7 +1258,7 @@ def pcol_2dxy(self, x, y):
12271258 if 'fig250' in locals ():
12281259
12291260 plt .figure (250 )
1230- tit = 'Y' + str (yr ) + 'M' + str (mo ) + 'D' + str (da )
1261+ tit = 'Y' + str (yr ) + 'M' + str (mo ). zfill ( 2 ) + 'D' + str (da ). zfill ( 2 )
12311262
12321263 if 'Q' in diag_type :
12331264 plt .title ('Q ' + tit )
@@ -1274,7 +1305,7 @@ def pcol_2dxy(self, x, y):
12741305
12751306 if anim_figs : # Make figures for animations
12761307
1277- tit = 'Y' + str (yr ) + 'M' + str (mo ) + 'D' + str (da )
1308+ tit = 'Y' + str (yr ) + 'M' + str (mo ). zfill ( 2 ) + 'D' + str (da ). zfill ( 2 )
12781309
12791310 #if 'anim_fig' in locals():
12801311 ## Wait if there is a still-active anim_fig thread
@@ -1290,11 +1321,11 @@ def pcol_2dxy(self, x, y):
12901321 args=(33, M, pMx, pMy, slacopy, plt.cm.RdBu_r, rtime, diag_type, Mx, My,
12911322 slacopy, slacopy, slaparameter, A_eddy, C_eddy,
12921323 savedir, plt, 'SLA ' + tit))'''
1293- fignum = 31
1324+
12941325 #print 'figure saving'
12951326 #tt = time.time()
12961327 anim_figure (A_eddy , C_eddy , Mx , My , pMx , pMy , plt .cm .RdBu_r , rtime , diag_type ,
1297- savedir , 'SLA ' + tit , fignum )
1328+ savedir , 'SLA ' + tit , animax )
12981329 #print 'figure saving done in %s seconds\n' %(time.time() - tt)
12991330 #anim_fig.start()
13001331
0 commit comments