Skip to content

Commit 729857b

Browse files
author
delepoullea
committed
peps8, pylint correction and some question, which begin with evan
slicing and logging instead of eval and print
1 parent 7662ea7 commit 729857b

6 files changed

+357
-397
lines changed

global_tracking.py

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,57 +6,54 @@
66

77
class GlobalTracking(object):
88
"""
9-
9+
1010
"""
1111
def __init__(self, eddy, ymd_str):
1212
"""
1313
"""
1414
self.tracklist = eddy.tracklist
15-
self.SIGN_TYPE = eddy.SIGN_TYPE
15+
self.sign_type = eddy.SIGN_TYPE
1616
self.ymd_str = ymd_str
1717
self.num_tracks = np.sum([i.alive for i in self.tracklist])
18-
19-
18+
2019
def create_netcdf(self):
2120
"""
2221
"""
23-
with Dataset('%s_%s.nc' % (self.SIGN_TYPE, self.ymd_str),
22+
with Dataset('%s_%s.nc' % (self.sign_type, self.ymd_str),
2423
'w', format='NETCDF4') as nc:
25-
24+
2625
# Create dimensions
2726
nc.createDimension('tracks', self.num_tracks)
2827
nc.createDimension('properties', None)
29-
3028
# Create variables
3129
t = 0
3230
for track in self.tracklist:
33-
if track.alive:
31+
# if track.alive:
3432
varname = 'track_%s' % np.str(t).zfill(4)
3533
nc.createVariable(varname, np.float64, ('properties'))
3634
t += 1
3735
nc.createVariable('track_lengths', np.int, ('tracks'))
38-
39-
36+
4037
def write_tracks(self):
4138
"""
4239
"""
4340
t = 0
4441
for track in self.tracklist:
4542
tracklen = len(track.lon)
4643
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))
44+
properties = np.hstack((
45+
track.dayzero, track.saved2nc,
46+
track.save_extras, track.lon, track.lat,
47+
track.amplitude, track.radius_s,
48+
track.radius_e, track.uavg,
49+
track.teke, track.ocean_time))
5250

53-
with Dataset('%s_%s.nc' % (self.SIGN_TYPE, self.ymd_str), 'a') as nc:
51+
with Dataset('%s_%s.nc' % (self.sign_type, self.ymd_str), 'a') as nc:
5452
varname = 'track_%s' % np.str(t).zfill(4)
5553
nc.variables[varname][:] = properties
5654
nc.variables['track_lengths'][t] = tracklen
5755
t += 1
58-
59-
56+
6057
def read_tracks(self):
6158
"""
6259
Read and sort the property data for returning to the
@@ -65,13 +62,13 @@ def read_tracks(self):
6562
with Dataset('Anticyclonic_20140312.nc') as nc:
6663
tracklens = nc.variables['track_lengths'][:]
6764
for t, tracklen in enumerate(tracklengths):
68-
65+
6966
varname = 'track_%s' % np.str(t).zfill(4)
7067
track = nc.variables[varname][:]
7168
dayzero = track[0].astype(bool)
7269
saved2nc = track[1].astype(bool)
7370
save_extras = track[2].astype(bool)
74-
71+
7572
inds = np.arange(3, 3 + (tracklen * 8), tracklen)
7673
lon = track[inds[0]:inds[1]]
7774
lat = track[inds[1]:inds[2]]
@@ -81,10 +78,5 @@ def read_tracks(self):
8178
uavg = track[inds[5]:inds[6]]
8279
teke = track[inds[6]:inds[7]]
8380
ocean_time = track[inds[7]:]
84-
85-
81+
8682
properties = nc.variables['track_0000'][:]
87-
88-
89-
90-

0 commit comments

Comments
 (0)