Permalink
Browse files

Moving EddyData and EddyDataVar back to ringslegacy

  • Loading branch information...
castelao committed Jun 17, 2013
1 parent 05d4674 commit 526cd2494bee045254a0297ec4d1f18ec5786f53
Showing with 0 additions and 80 deletions.
  1. +0 −80 rings/utils.py
@@ -255,86 +255,6 @@ def cfg2dict(cfg_file):
parameters['eddy_track']['force_reprocess'] = False
return parameters
# ----------------------------------------------------------------------------
class EddyDataVar(object):
""" Return each variable for each eddy
This is necessary because the reference data fields are
stored as dictionaries of 3D data:
{var1: 3D MA, var2: 3D MA}
but with this class is possible to recover the data as
EddyDataVar[var1]
"""
def __init__(self, input, ind, mask=False):
"""
"""
self.input = input
self.ind = ind
self.mask = mask
def keys(self):
return self.input.keys()
def __getitem__(self,key):
if key in ['datetime']:
# Non grided will fail here. Since it'll not be a slice
return self.input[key][self.ind[0]][0]
elif key in ['Lat', 'Lon']:
tmp = self.input[key][self.ind[-2:]]
return ma.masked_array(tmp.data, ((tmp.mask==True) | (self.mask==True)))
else:
tmp = self.input[key][self.ind][0]
return ma.masked_array(tmp.data, ((tmp.mask==True) | (self.mask==True)))
class EddyData(object):
"""
"""
def __init__(self, input):
"""
"""
#self.data = {}
self.input = input
#for id in ids:
# ind = ma.nonzero(self.input['patches']==id)
# self.data[id] = {}
# self.data[id]['ssh'] = EddyDataVar(self.input, ind)
def keys(self):
return self.input.keys()
@property
def ids(self):
return ma.unique(self.input['patches'].compressed())
def __getitem__(self, id):
"""
"""
ind = ma.nonzero(self.input['patches']==id)
gridded = True
if gridded == True:
ind = slice(ind[0].min(), ind[0].max()+1), \
slice(ind[1].min(), ind[1].max()+1), \
slice(ind[2].min(), ind[2].max()+1)
mask = ((self.input['patches'][ind].data!=id) | self.input['patches'][ind].mask)
return EddyDataVar(self.input, ind, mask)
else:
return EddyDataVar(self.input, ind)
def getaround(self, id, bl=2):
"""
"""
ind = ma.nonzero(self.input['patches']==id)
gridded = True
if gridded == True:
ind = slice(ind[0].min(), ind[0].max()+1), \
slice(max(0,ind[1].min()-bl), ind[1].max()+1+bl), \
slice(max(0,ind[2].min()-bl), ind[2].max()+1+bl)
return EddyDataVar(self.input, ind)
else:
return EddyDataVar(self.input, ind)
# ============================================================================
def neighbor_cluster(ind, verbose=False):

0 comments on commit 526cd24

Please sign in to comment.