Skip to content

Commit 4f65466

Browse files
committed
Added EKE calculation and saving
1 parent a14f7ee commit 4f65466

File tree

5 files changed

+141
-55
lines changed

5 files changed

+141
-55
lines changed

haversine_distmat.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
!
2828
! If you have ifort on your system, change 'gfortran' to 'intelem'
2929
!
30-
! Version 1.2.1
30+
! Version 1.3.0
3131
!
3232
!===========================================================================
3333

make_eddy_track_AVISO.py

Lines changed: 56 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
2525
make_eddy_track_AVISO.py
2626
27-
Version 1.2.1
27+
Version 1.3.0
2828
2929
3030
Scroll down to line ~640 to get started
@@ -401,9 +401,30 @@ def __init__(self, AVISO_file, lonmin, lonmax, latmin, latmax, with_pad=True, us
401401
self.set_index_padding()
402402
self.make_gridmask(with_pad, use_maskoceans).uvmask()
403403
self.get_AVISO_f_pm_pn()
404+
self.set_u_v_eke()
404405

405406

406407

408+
def set_u_v_eke(self, pad=2):
409+
'''
410+
'''
411+
double_pad = pad * 2
412+
if self.zero_crossing:
413+
u1 = np.empty((self.ip0, self.jp1 - self.jp0))
414+
u0 = np.empty((self._lon.shape[0] - self.ip1, self.jp1 - self.jp0))
415+
self.u = np.ma.concatenate((u0, u1), axis=1)
416+
else:
417+
self.u = np.empty((self.jp1 - self.jp0, self.ip1 - self.ip0))
418+
self.v = np.empty_like(self.u)
419+
self.eke = np.empty((self.u.shape[0] - double_pad,
420+
self.u.shape[1] - double_pad))
421+
return self
422+
423+
424+
425+
426+
427+
407428
def get_AVISO_data(self, AVISO_file):
408429
'''
409430
Read nc data from AVISO file
@@ -492,13 +513,21 @@ def getSurfGeostrVel(self, zeta):
492513
by Evan Mason
493514
Changed to gv2, 14 May 07...
494515
'''
495-
def gv2(zeta, gof, pm, pn, umask, vmask): # Pierrick's version
496-
ugv = -gof * self.v2rho_2d(vmask * (zeta[1:] - zeta[:-1]) \
497-
* 0.5 * (pn[1:] + pn[:-1]))
498-
vgv = gof * self.u2rho_2d(umask * (zeta[:, 1:] - zeta[:, :-1]) \
499-
* 0.5 * (pm[:, 1:] + pm[:, :-1]))
500-
return ugv, vgv
501-
return gv2(zeta, self.gof(), self.pm(), self.pn(), self.umask(), self.vmask())
516+
#def gv2(zeta, gof, pm, pn, umask, vmask): # Pierrick's version
517+
self.u[:] = -self.gof() * self.v2rho_2d(self.vmask() * (zeta.data[1:] - zeta.data[:-1]) \
518+
* 0.5 * (self.pn()[1:] + self.pn()[:-1]))
519+
self.v[:] = self.gof() * self.u2rho_2d(self.umask() * (zeta.data[:, 1:] - zeta.data[:, :-1]) \
520+
* 0.5 * (self.pm()[:, 1:] + self.pm()[:, :-1]))
521+
#return ugv, vgv
522+
#return gv2(zeta, self.gof(), self.pm(), self.pn(), self.umask(), self.vmask())
523+
return self
524+
525+
def getEKE(self, u, v):
526+
'''
527+
'''
528+
np.add(u**2, v**2, out=self.eke)
529+
self.eke *= 0.5
530+
return self
502531

503532

504533
def lon(self):
@@ -782,15 +811,15 @@ def pcol_2dxy(self, x, y):
782811
subdomain = True
783812
if the_domain in 'Global':
784813

785-
#lonmin = -36. # Canary
786-
#lonmax = -7.5
787-
#latmin = 18.
788-
#latmax = 33.2
814+
lonmin = -36. # Canary
815+
lonmax = -7.5
816+
latmin = 18.
817+
latmax = 33.2
789818

790-
lonmin = -65. # Corridor
791-
lonmax = -5.5
792-
latmin = 11.5
793-
latmax = 38.5
819+
#lonmin = -65. # Corridor
820+
#lonmax = -5.5
821+
#latmin = 11.5
822+
#latmax = 38.5
794823

795824
#lonmin = -179. # SEP
796825
#lonmax = -65
@@ -1174,14 +1203,16 @@ def pcol_2dxy(self, x, y):
11741203
#else:
11751204
#umask, vmask, junk = sla_grd.uvpmask(np.zeros_like(sla))
11761205

1177-
# Multiply by 0.01 for m/s
1178-
u, v = sla_grd.getSurfGeostrVel(sla * 0.01)
1206+
# Multiply by 0.01 for m
1207+
sla_grd.getSurfGeostrVel(sla * 0.01)
11791208

11801209
# Remove padded boundary
11811210
sla = sla[sla_grd.jup0:sla_grd.jup1, sla_grd.iup0:sla_grd.iup1]
1182-
u = u[sla_grd.jup0:sla_grd.jup1, sla_grd.iup0:sla_grd.iup1]
1183-
v = v[sla_grd.jup0:sla_grd.jup1, sla_grd.iup0:sla_grd.iup1]
1184-
1211+
u = sla_grd.u[sla_grd.jup0:sla_grd.jup1, sla_grd.iup0:sla_grd.iup1]
1212+
v = sla_grd.v[sla_grd.jup0:sla_grd.jup1, sla_grd.iup0:sla_grd.iup1]
1213+
1214+
sla_grd.getEKE(u, v)
1215+
11851216
A_eddy.sla = np.ma.copy(sla)
11861217
C_eddy.sla = np.ma.copy(sla)
11871218
A_eddy.slacopy = np.ma.copy(sla)
@@ -1207,7 +1238,9 @@ def pcol_2dxy(self, x, y):
12071238
if anim_figs:
12081239
animfig = plt.figure(999)
12091240
animax = animfig.add_subplot(111)
1210-
1241+
# Colorbar axis
1242+
animax_cbar = get_cax(animax, dx=0.03, width=.05, position='b')
1243+
12111244
if 'Q' in diag_type:
12121245
CS = ax.contour(sla_grd.lon(),
12131246
sla_grd.lat(), qparam, qparameter)
@@ -1325,7 +1358,7 @@ def pcol_2dxy(self, x, y):
13251358
#print 'figure saving'
13261359
#tt = time.time()
13271360
anim_figure(A_eddy, C_eddy, Mx, My, pMx, pMy, plt.cm.RdBu_r, rtime, diag_type,
1328-
savedir, 'SLA ' + tit, animax)
1361+
savedir, 'SLA ' + tit, animax, animax_cbar)
13291362
#print 'figure saving done in %s seconds\n' %(time.time() - tt)
13301363
#anim_fig.start()
13311364

make_eddy_track_ROMS.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
2525
make_eddy_track_ROMS.py
2626
27-
Version 1.1.0
27+
Version 1.3.0
2828
2929
3030

make_eddy_tracker_list_obj.py

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
2626
make_eddy_tracker_list_obj.py
2727
28-
Version 1.2.1
28+
Version 1.3.0
2929
3030
3131
===========================================================================
@@ -123,7 +123,7 @@ class track (object):
123123
saved2nc - Becomes True once saved to netcdf file
124124
dayzero - True at first appearance of eddy
125125
'''
126-
def __init__(self, eddy_index, datatype, lon, lat, time, Uavg,
126+
def __init__(self, eddy_index, datatype, lon, lat, time, Uavg, teke,
127127
radius_s, radius_e, amplitude, bounds,
128128
temp=None,
129129
salt=None):
@@ -134,6 +134,7 @@ def __init__(self, eddy_index, datatype, lon, lat, time, Uavg,
134134
self.lat = np.atleast_1d(lat)
135135
self.ocean_time = np.atleast_1d(time)
136136
self.Uavg = np.atleast_1d(Uavg)
137+
self.teke = np.atleast_1d(teke)
137138
self.radius_s = np.atleast_1d(radius_s) # speed-based eddy radius
138139
self.radius_e = np.atleast_1d(radius_e) # effective eddy radius
139140
self.amplitude = np.atleast_1d(amplitude)
@@ -146,7 +147,7 @@ def __init__(self, eddy_index, datatype, lon, lat, time, Uavg,
146147
self.saved2nc = False
147148

148149

149-
def append_pos(self, lon, lat, time, Uavg,
150+
def append_pos(self, lon, lat, time, Uavg, teke,
150151
radius_s, radius_e, amplitude, bounds, temp, salt):
151152
'''
152153
Append track updates
@@ -155,6 +156,7 @@ def append_pos(self, lon, lat, time, Uavg,
155156
self.lat = np.r_[self.lat, lat]
156157
self.ocean_time = np.r_[self.ocean_time, time]
157158
self.Uavg = np.r_[self.Uavg, Uavg]
159+
self.teke = np.r_[self.teke, teke]
158160
self.radius_s = np.r_[self.radius_s, radius_s]
159161
self.radius_e = np.r_[self.radius_e, radius_e]
160162
self.amplitude = np.r_[self.amplitude, amplitude]
@@ -210,6 +212,7 @@ def __init__(self, datatype, track_duration_min):
210212
self.new_radii_e = np.array([])
211213
self.new_amp = np.array([])
212214
self.new_Uavg = np.array([])
215+
self.new_teke = np.array([])
213216
if 'ROMS' in self.datatype:
214217
self.new_temp = np.array([])
215218
self.new_salt = np.array([])
@@ -221,6 +224,7 @@ def __init__(self, datatype, track_duration_min):
221224
self.old_radii_e = np.array([])
222225
self.old_amp = np.array([])
223226
self.old_Uavg = np.array([])
227+
self.old_teke = np.array([])
224228
if 'ROMS' in self.datatype:
225229
self.old_temp = np.array([])
226230
self.old_salt = np.array([])
@@ -235,24 +239,24 @@ def __init__(self, datatype, track_duration_min):
235239
assert datatype in ('ROMS', 'AVISO'), "Unknown string in 'datatype' parameter"
236240

237241

238-
def append_list(self, lon, lat, time, Uavg,
242+
def append_list(self, lon, lat, time, Uavg, teke,
239243
radius_s, radius_e, amplitude, bounds, temp=None, salt=None):
240244
'''
241245
Append a new 'track' object to the list
242246
'''
243247
self.tracklist.append(track(self.index, self.datatype,
244-
lon, lat, time, Uavg,
248+
lon, lat, time, Uavg, teke,
245249
radius_s, radius_e,
246250
amplitude, bounds,
247251
temp, salt))
248252

249253

250-
def update_track(self, index, lon, lat, time, Uavg,
254+
def update_track(self, index, lon, lat, time, Uavg, teke,
251255
radius_s, radius_e, amplitude, bounds, temp=None, salt=None):
252256
'''
253257
Update a track at index
254258
'''
255-
self.tracklist[index].append_pos(lon, lat, time, Uavg,
259+
self.tracklist[index].append_pos(lon, lat, time, Uavg, teke,
256260
radius_s, radius_e,
257261
amplitude, bounds,
258262
temp, salt)
@@ -268,6 +272,7 @@ def reset_holding_variables(self):
268272
self.new_radii_tmp_e = np.array([])
269273
self.new_amp_tmp = np.array([])
270274
self.new_Uavg_tmp = np.array([])
275+
self.new_teke_tmp = np.array([])
271276
self.new_time_tmp = np.array([])
272277
self.new_temp_tmp = np.array([])
273278
self.new_salt_tmp = np.array([])
@@ -285,6 +290,7 @@ def set_old_variables(self):
285290
self.old_radii_e = np.copy(self.new_radii_tmp_e)
286291
self.old_amp = np.copy(self.new_amp_tmp)
287292
self.old_Uavg = np.copy(self.new_Uavg_tmp)
293+
self.old_teke = np.copy(self.new_teke_tmp)
288294
self.old_temp = np.copy(self.new_temp_tmp)
289295
self.old_salt = np.copy(self.new_salt_tmp)
290296

@@ -391,6 +397,7 @@ def create_netcdf(self, directory, savedir, title,
391397
nc.createVariable('A', 'f8', ('Nobs'), fill_value=self.fillval)
392398
nc.createVariable('L', 'f8', ('Nobs'), fill_value=self.fillval)
393399
nc.createVariable('U', 'f8', ('Nobs'), fill_value=self.fillval)
400+
nc.createVariable('Teke', 'f8', ('Nobs'), fill_value=self.fillval)
394401
nc.createVariable('radius_e', 'f8', ('Nobs'), fill_value=self.fillval)
395402
if 'Q' in self.diag_type:
396403
nc.createVariable('qparameter', 'f8', ('Nobs'), fill_value=self.fillval)
@@ -446,10 +453,11 @@ def create_netcdf(self, directory, savedir, title,
446453
'between the extremum of SSH within ' + \
447454
'the eddy and the SSH around the contour ' + \
448455
'defining the eddy perimeter'
456+
449457
nc.variables['L'].units = 'km'
450458
nc.variables['L'].min_val = self.radmin / 1000.
451459
nc.variables['L'].max_val = self.radmax / 1000.
452-
nc.variables['L'].long_name = 'radius scale'
460+
nc.variables['L'].long_name = 'speed radius scale'
453461
nc.variables['L'].description = 'radius of a circle whose area is equal ' + \
454462
'to that enclosed by the contour of ' + \
455463
'maximum circum-average speed'
@@ -460,6 +468,13 @@ def create_netcdf(self, directory, savedir, title,
460468
nc.variables['U'].long_name = 'maximum circum-averaged speed'
461469
nc.variables['U'].description = 'average speed of the contour defining ' + \
462470
'the radius scale L'
471+
nc.variables['Teke'].units = 'm^2/sec^2'
472+
#nc.variables['Teke'].min = 0.
473+
#nc.variables['Teke'].max = 376.6
474+
nc.variables['Teke'].long_name = 'sum EKE within contour Ceff'
475+
nc.variables['Teke'].description = 'sum of eddy kinetic energy within contour defining ' + \
476+
'the effective radius'
477+
463478
nc.variables['radius_e'].units = 'km'
464479
nc.variables['radius_e'].min_val = self.radmin / 1000.
465480
nc.variables['radius_e'].max_val = self.radmax / 1000.
@@ -495,6 +510,7 @@ def _reduce_inactive_tracks(self):
495510
track.qparameter = False
496511
track.amplitude = False
497512
track.Uavg = False
513+
track.teke = False
498514
track.radius_s = False
499515
track.radius_e = False
500516
track.bounds = False
@@ -549,6 +565,7 @@ def write2chelton_nc(self, savedir, rtime):
549565
nc.variables['lat'][self.ncind:tend] = np.array([self.tracklist[i].lat])
550566
nc.variables['A'][self.ncind:tend] = np.array([self.tracklist[i].amplitude])
551567
nc.variables['U'][self.ncind:tend] = np.array([self.tracklist[i].Uavg]) * 100. # to cm/s
568+
nc.variables['Teke'][self.ncind:tend] = np.array([self.tracklist[i].teke])
552569
nc.variables['L'][self.ncind:tend] = np.array([self.tracklist[i].radius_s]) * np.array(1e-3)
553570
nc.variables['radius_e'][self.ncind:tend] = np.array([self.tracklist[i].radius_e]) * np.array(1e-3)
554571
if 'ROMS' in self.datatype:
@@ -594,6 +611,7 @@ def write2chelton_nc(self, savedir, rtime):
594611
self.old_radii_e = self.new_radii_e[lasti:]
595612
self.old_amp = self.new_amp[lasti:]
596613
self.old_Uavg = self.new_Uavg[lasti:]
614+
self.old_teke = self.new_teke[lasti:]
597615
if 'ROMS' in self.datatype:
598616
self.old_temp = self.new_temp[lasti:]
599617
self.old_salt = self.new_salt[lasti:]
@@ -604,6 +622,7 @@ def write2chelton_nc(self, savedir, rtime):
604622
self.new_radii_e = np.array([])
605623
self.new_amp = np.array([])
606624
self.new_Uavg = np.array([])
625+
self.new_teke = np.array([])
607626
self.new_time = np.array([])
608627
if 'ROMS' in self.datatype:
609628
self.new_temp = np.array([])
@@ -669,6 +688,14 @@ def insert_at_index(self, xarr, ind, x):
669688
self.new_amp = np.zeros((newsize))
670689
self.new_amp[:tmp.size] = tmp
671690
self.new_amp[ind] = x
691+
elif 'new_Uavg' in xarr:
692+
self.new_Uavg = np.zeros((newsize))
693+
self.new_Uavg[:tmp.size] = tmp
694+
self.new_Uavg[ind] = x
695+
elif 'new_teke' in xarr:
696+
self.new_teke = np.zeros((newsize))
697+
self.new_teke[:tmp.size] = tmp
698+
self.new_teke[ind] = x
672699
elif 'new_temp' in xarr:
673700
self.new_temp = np.zeros((newsize))
674701
self.new_temp[:tmp.size] = tmp
@@ -683,7 +710,7 @@ def insert_at_index(self, xarr, ind, x):
683710

684711

685712
def update_eddy_properties(self, centlon, centlat, eddy_radius_s, eddy_radius_e,
686-
amplitude, Uavg, rtime, bounds, cent_temp=None, cent_salt=None):
713+
amplitude, Uavg, teke, rtime, bounds, cent_temp=None, cent_salt=None):
687714
'''
688715
Append new variable values to track arrays
689716
'''
@@ -693,6 +720,7 @@ def update_eddy_properties(self, centlon, centlat, eddy_radius_s, eddy_radius_e,
693720
self.new_radii_tmp_e = np.r_[self.new_radii_tmp_e, eddy_radius_e]
694721
self.new_amp_tmp = np.r_[self.new_amp_tmp, amplitude]
695722
self.new_Uavg_tmp = np.r_[self.new_Uavg_tmp, Uavg]
723+
self.new_teke_tmp = np.r_[self.new_teke_tmp, teke]
696724
self.new_time_tmp = np.r_[self.new_time_tmp, rtime]
697725
if 'ROMS' in self.datatype:
698726
self.new_temp_tmp = np.r_[self.new_temp_tmp, cent_temp]

0 commit comments

Comments
 (0)