Skip to content
Snippets Groups Projects
Commit 243afdd9 authored by (no author)'s avatar (no author)
Browse files

reducing over analysis of data objects and some other cleanup

git-svn-id: https://svn.ssec.wisc.edu/repos/glance/trunk@207 8a9318a1-56ba-4d59-b755-99d26321be01
parent b06b1931
No related branches found
No related tags found
No related merge requests found
...@@ -161,38 +161,53 @@ class DataObject (object) : ...@@ -161,38 +161,53 @@ class DataObject (object) :
return DataObject(self.data.copy(), fillValue=self.fill_value, ignoreMask=self.masks.ignore_mask, return DataObject(self.data.copy(), fillValue=self.fill_value, ignoreMask=self.masks.ignore_mask,
overrideFillValue=self.override_fill_value, defaultFillValue=self.default_fill_value) overrideFillValue=self.override_fill_value, defaultFillValue=self.default_fill_value)
def self_analysis(self) : def self_analysis(self, re_do_analysis=False) :
""" """
Gather some basic information about a data set Gather some basic information about a data set
"""
# hang onto the shape for convenience
shape = self.data.shape
# if there isn't an ignore mask, make an empty one
if self.masks.ignore_mask is None :
self.masks.ignore_mask = np.zeros(shape, dtype=np.bool)
# find the non-finite values Note: If the data has already been analyzed it will not do anything
non_finite_mask = ~np.isfinite(self.data) & ~self.masks.ignore_mask unless you send in re_do_analysis=True
"""
# find and mark the missing values
missing_mask = np.zeros(shape, dtype=np.bool)
# if the data has a fill value, mark where the missing data is
tempFillValue = self.select_fill_value()
if tempFillValue is not None :
missing_mask[self.data == tempFillValue] = True
missing_mask[self.masks.ignore_mask] = False
# define the valid mask as places where the data is not missing,
# nonfinite, or ignored
valid_mask = ~ (missing_mask | non_finite_mask | self.masks.ignore_mask)
# set our masks # data objects are intended to be immutable, build a new one or override to re-analyze
self.masks = BasicMaskSetObject(self.masks.ignore_mask, valid_mask, if (not self.have_analyzed) or re_do_analysis :
non_finite_mask, missing_mask)
self.have_analyzed = True # hang onto the shape for convenience
shape = self.data.shape
# if there isn't an ignore mask, make an empty one
if self.masks.ignore_mask is None :
self.masks.ignore_mask = np.zeros(shape, dtype=np.bool)
# find the non-finite values
#non_finite_mask = ~np.isfinite(self.data) & ~self.masks.ignore_mask
#non_finite_mask = ~ (np.isfinite(self.data) | self.masks.ignore_mask)
non_finite_mask = np.zeros(shape, dtype=np.bool)
np.isfinite(self.data, non_finite_mask)
np.logical_or(non_finite_mask, self.masks.ignore_mask, non_finite_mask)
np.logical_not(non_finite_mask, non_finite_mask)
# find and mark the missing values
missing_mask = np.zeros(shape, dtype=np.bool)
# if the data has a fill value, mark where the missing data is
tempFillValue = self.select_fill_value()
if tempFillValue is not None :
missing_mask[self.data == tempFillValue] = True
missing_mask[self.masks.ignore_mask] = False
# define the valid mask as places where the data is not missing,
# nonfinite, or ignored
#valid_mask = ~ (missing_mask | non_finite_mask | self.masks.ignore_mask)
valid_mask = np.zeros(shape, dtype=np.bool)
np.logical_or(missing_mask, non_finite_mask, valid_mask)
np.logical_or(self.masks.ignore_mask, valid_mask, valid_mask)
np.logical_not(valid_mask, valid_mask)
# set our masks
self.masks = BasicMaskSetObject(self.masks.ignore_mask, valid_mask,
non_finite_mask, missing_mask)
self.have_analyzed = True
def select_fill_value (self) : def select_fill_value (self) :
""" """
...@@ -207,10 +222,7 @@ class DataObject (object) : ...@@ -207,10 +222,7 @@ class DataObject (object) :
get the minimum value in this data set get the minimum value in this data set
""" """
# TODO it would be better to put this test in the analysis function self.self_analysis()
# TODO but first I'd need to be sure that wouldn't break anything
if not self.have_analyzed :
self.self_analysis()
return delta.min_with_mask(self.data, self.masks.valid_mask) return delta.min_with_mask(self.data, self.masks.valid_mask)
def get_max (self) : def get_max (self) :
...@@ -218,10 +230,7 @@ class DataObject (object) : ...@@ -218,10 +230,7 @@ class DataObject (object) :
get the maximum value in this data set get the maximum value in this data set
""" """
# TODO it would be better to put this test in the analysis function self.self_analysis()
# TODO but first I'd need to be sure that wouldn't break anything
if not self.have_analyzed :
self.self_analysis()
return delta.max_with_mask(self.data, self.masks.valid_mask) return delta.max_with_mask(self.data, self.masks.valid_mask)
class DiffInfoObject (object) : class DiffInfoObject (object) :
......
...@@ -65,9 +65,7 @@ def min_with_mask(data, goodMask=None) : ...@@ -65,9 +65,7 @@ def min_with_mask(data, goodMask=None) :
goodData = data[goodMask] goodData = data[goodMask]
# if we have any good data, get the minimum # if we have any good data, get the minimum
toReturn = None toReturn = np.min(goodData) if goodData.size > 0 else None
if goodData.size > 0 :
toReturn = np.min(goodData)
return toReturn return toReturn
...@@ -92,9 +90,7 @@ def max_with_mask(data, goodMask=None) : ...@@ -92,9 +90,7 @@ def max_with_mask(data, goodMask=None) :
goodData = data[goodMask] goodData = data[goodMask]
# if we have any good data, get the maximum # if we have any good data, get the maximum
toReturn = None toReturn = np.max(goodData) if goodData.size > 0 else None
if goodData.size > 0 :
toReturn = np.max(goodData)
return toReturn return toReturn
......
...@@ -291,6 +291,9 @@ def create_hexbin_plot(dataX, dataY, title, xLabel, yLabel, epsilon=None, units_ ...@@ -291,6 +291,9 @@ def create_hexbin_plot(dataX, dataY, title, xLabel, yLabel, epsilon=None, units_
# the hexbin plot of the good data # the hexbin plot of the good data
plt.hexbin(dataX, dataY, bins='log', cmap=cm.jet) plt.hexbin(dataX, dataY, bins='log', cmap=cm.jet)
plt.axis([dataX.min(), dataX.max(), dataY.min(), dataY.max()]) plt.axis([dataX.min(), dataX.max(), dataY.min(), dataY.max()])
#heatmap, xedges, yedges = np.histogram2d(dataX, dataY, bins=100) #todo, testing
#heatmap = log(heatmap + 1)
#plt.imshow(heatmap, extent=[xedges[0], xedges[-1], yedges[0], yedges[-1]], cmap=cm.jet)
# create a color bar # create a color bar
cb = plt.colorbar() cb = plt.colorbar()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment