Skip to content

Commit 8a865d5

Browse files
committed
Added new file global_tracking.py
Usage will be saving data to nc file rather than pickle file !! Under development still !!
1 parent beed0c0 commit 8a865d5

File tree

3 files changed

+100
-2
lines changed

3 files changed

+100
-2
lines changed

global_tracking.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# %run global_tracking.py
2+
3+
from netCDF4 import Dataset
4+
import numpy as np
5+
6+
7+
class GlobalTracking(object):
8+
"""
9+
10+
"""
11+
def __init__(self, eddy, ymd_str):
12+
"""
13+
"""
14+
self.tracklist = eddy.tracklist
15+
self.SIGN_TYPE = eddy.SIGN_TYPE
16+
self.ymd_str = ymd_str
17+
self.num_tracks = np.sum([i.alive for i in self.tracklist])
18+
19+
20+
def create_netcdf(self):
21+
"""
22+
"""
23+
with Dataset('%s_%s.nc' % (self.SIGN_TYPE, self.ymd_str),
24+
'w', format='NETCDF4') as nc:
25+
26+
# Create dimensions
27+
nc.createDimension('tracks', self.num_tracks)
28+
nc.createDimension('properties', None)
29+
30+
# Create variables
31+
t = 0
32+
for track in self.tracklist:
33+
if track.alive:
34+
varname = 'track_%s' % np.str(t).zfill(4)
35+
nc.createVariable(varname, np.float64, ('properties'))
36+
t += 1
37+
nc.createVariable('track_lengths', np.int, ('tracks'))
38+
39+
40+
def write_tracks(self):
41+
"""
42+
"""
43+
t = 0
44+
for track in self.tracklist:
45+
tracklen = len(track.lon)
46+
if track.alive:
47+
properties = np.hstack((track.dayzero, track.saved2nc,
48+
track.save_extras, track.lon, track.lat,
49+
track.amplitude, track.radius_s,
50+
track.radius_e, track.uavg,
51+
track.teke, track.ocean_time))
52+
53+
with Dataset('%s_%s.nc' % (self.SIGN_TYPE, self.ymd_str), 'a') as nc:
54+
varname = 'track_%s' % np.str(t).zfill(4)
55+
nc.variables[varname][:] = properties
56+
nc.variables['track_lengths'][t] = tracklen
57+
t += 1
58+
59+
60+
def read_tracks(self):
61+
"""
62+
Read and sort the property data for returning to the
63+
Eddy object
64+
"""
65+
with Dataset('Anticyclonic_20140312.nc') as nc:
66+
tracklens = nc.variables['track_lengths'][:]
67+
for t, tracklen in enumerate(tracklengths):
68+
69+
varname = 'track_%s' % np.str(t).zfill(4)
70+
track = nc.variables[varname][:]
71+
dayzero = track[0].astype(bool)
72+
saved2nc = track[1].astype(bool)
73+
save_extras = track[2].astype(bool)
74+
75+
inds = np.arange(3, 3 + (tracklen * 8), tracklen)
76+
lon = track[inds[0]:inds[1]]
77+
lat = track[inds[1]:inds[2]]
78+
amplitude = track[inds[2]:inds[3]]
79+
radius_s = track[inds[3]:inds[4]]
80+
radius_e = track[inds[4]:inds[5]]
81+
uavg = track[inds[5]:inds[6]]
82+
teke = track[inds[6]:inds[7]]
83+
ocean_time = track[inds[7]:]
84+
85+
86+
properties = nc.variables['track_0000'][:]
87+
88+
89+
90+

make_eddy_track_AVISO.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
from datetime import datetime
5050
import cPickle as pickle
5151

52+
import global_tracking as gbtk
53+
5254

5355
def timeit(method):
5456
"""
@@ -1197,7 +1199,13 @@ def brypath(self, imin=0, imax=-1, jmin=0, jmax=-1):
11971199
pickle.dump(C_eddy, save_pickle, 2)
11981200

11991201
print 'EXIT here'
1200-
exit()
1202+
1203+
print ''
1204+
save2nc = gbtk.save_netcdf(A_eddy, ymd_str)
1205+
save2nc.create_netcdf()
1206+
save2nc.write_tracks()
1207+
1208+
#exit()
12011209
## Unpickle
12021210
#with open('C_eddy.pkl', 'rb') as load_pickle:
12031211
#C_eddy = pickle.load(load_pickle)

make_eddy_tracker_list_obj.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ def __getstate__(self):
367367
"""pops = ('uspd', 'uspd_coeffs', 'sla_coeffs', 'points',
368368
'circlon', 'circlat', 'sla', 'slacopy', 'swirl',
369369
'mask_eff', 'mask_eff_sum', 'mask_eff_1d')"""
370-
pops = ('uspd', 'uspd_coeffs', 'sla_coeffs', 'points',
370+
pops = ('uspd', 'uspd_coeffs', 'sla_coeffs', 'points',
371371
'sla', 'slacopy', 'swirl',
372372
'mask_eff', 'mask_eff_sum', 'mask_eff_1d')
373373
result = self.__dict__.copy()

0 commit comments

Comments
 (0)