From ff4e74853d10cc54ebdf4d6c03bb76679c61e49e Mon Sep 17 00:00:00 2001
From: "(no author)" <(no author)@8a9318a1-56ba-4d59-b755-99d26321be01>
Date: Mon, 17 Aug 2009 20:20:50 +0000
Subject: [PATCH] clear figures after use; correctly check if a file has a
 missing value before attempting to get it; also pull the correct missing
 value for file b if it has a different variable name than file a

git-svn-id: https://svn.ssec.wisc.edu/repos/glance/trunk@54 8a9318a1-56ba-4d59-b755-99d26321be01
---
 pyglance/glance/compare.py | 22 ++++++++++++++--------
 pyglance/glance/io.py      | 25 +++++++++++++++++++++++--
 pyglance/glance/plot.py    |  6 +++++-
 3 files changed, 42 insertions(+), 11 deletions(-)

diff --git a/pyglance/glance/compare.py b/pyglance/glance/compare.py
index 590a84b..e3654a8 100644
--- a/pyglance/glance/compare.py
+++ b/pyglance/glance/compare.py
@@ -138,7 +138,7 @@ def _resolve_names(fileAObject, fileBObject, defaultValues,
     if (usingConfigFileFormat) :
         
         # if the user didn't ask for any, try everything
-        if (requestedNames == {}) :
+        if (len(requestedNames) is 0) :
             finalFromCommandLine = _parse_varnames(fileCommonNames, ['.*'],
                                                    defaultValues['epsilon'], defaultValues['missing_value'])
             for name, epsilon, missing in finalFromCommandLine :
@@ -163,20 +163,26 @@ def _resolve_names(fileAObject, fileBObject, defaultValues,
             # check each of the names the user asked for to see if it is either in the list of common names
             # or, if the user asked for an alternate name mapping in file B, if the two mapped names are in
             # files A and B respectively
-            for name in requestedNames :
+            for name in requestedNames : # TODO rekey on display name?
+                
+                name_b = name
+                if ('alternate_name_in_B' in requestedNames[name]) :
+                    name_b = requestedNames[name_b]['alternate_name_in_B']
+                
                 if (name in fileCommonNames) | \
                         (requestedNames[name].has_key('alternate_name_in_B') and
-                         (name in nameComparison['uniqueToAVars']) and
-                         (requestedNames[name]['alternate_name_in_B'] in nameComparison['uniqueToBVars'])) :
+                         (name   in nameComparison['uniqueToAVars']) and
+                         (name_b in nameComparison['uniqueToBVars'])) :
                     finalNames[name] = defaultValues.copy()
                     finalNames[name]['variable_name'] = name
                     finalNames[name].update(requestedNames[name])
                     
                     # load the missing value if it was not provided
                     if finalNames[name]['missing_value'] is None :
-                        finalNames[name]['missing_value'] = fileAObject.missing_value(name)
-                    if not('missing_value_alt_in_b' in finalNames[name]) or (finalNames[name]['missing_value_alt_in_b'] is None) :
-                        finalNames[name]['missing_value_alt_in_b'] = fileBObject.missing_value(name)
+                        finalNames[name]['missing_value']          = fileAObject.missing_value(name)
+                    if not('missing_value_alt_in_b' in finalNames[name]) or \
+                        (finalNames[name]['missing_value_alt_in_b'] is None) :
+                        finalNames[name]['missing_value_alt_in_b'] = fileBObject.missing_value(name_b)
     else:
         # format command line input similarly to the stuff from the config file
         print (requestedNames)
@@ -795,7 +801,7 @@ python -m glance
         # if we wouldn't generate anything, just stop now
         if (not runInfo['shouldIncludeImages']) and (not runInfo['shouldIncludeReport']) :
             LOG.warn("User selection of no image generation and no report generation will result in no " +
-                     "content being generated. Aborting report generation function.")
+                     "content being generated. Aborting generation function.")
             return
         
         # get info on who's doing the run and where
diff --git a/pyglance/glance/io.py b/pyglance/glance/io.py
index 9fd2efc..9e53096 100644
--- a/pyglance/glance/io.py
+++ b/pyglance/glance/io.py
@@ -90,7 +90,15 @@ class hdf(SD):
         return self.select(name)
     
     def missing_value(self, name):
-        return getattr(self.select(name),'_FillValue',None)
+        missing_value_attr_name = '_FillValue'
+        variable_object = self.select(name)
+        
+        to_return = None
+        if hasattr(variable_object, missing_value_attr_name) :
+            to_return = getattr(variable_object, missing_value_attr_name, None)
+        SDS.endaccess(variable_object)
+        
+        return to_return
         
 
 class nc(CDF):
@@ -142,7 +150,20 @@ class nc(CDF):
         return self.var(name)
     
     def missing_value(self, name):
-        return getattr(self.var(name),'_FillValue',getattr(self.var(name),'missing_value',None))
+        
+        missing_value_attr_name_1 = '_FillValue'
+        missing_value_attr_name_2 = 'missing_value'
+        variable_object = self.var(name)
+        
+        to_return = None
+        if hasattr(variable_object, missing_value_attr_name_1) \
+           or \
+           hasattr(variable_object, missing_value_attr_name_2) :
+            to_return = getattr(variable_object, missing_value_attr_name_1,
+                                getattr(variable_object, missing_value_attr_name_2, None))
+        
+        return to_return
+
 nc4 = nc
 cdf = nc
 
diff --git a/pyglance/glance/plot.py b/pyglance/glance/plot.py
index 14576fa..74f4f44 100644
--- a/pyglance/glance/plot.py
+++ b/pyglance/glance/plot.py
@@ -33,7 +33,7 @@ LOG = logging.getLogger(__name__)
 offsetToRange = 0.0000000000000000001
 
 # the value that will denote "bad" longitudes and latitudes
-badLonLat = 1.0E30
+badLonLat = maps.badLonLat
 
 # a constant for the larger size dpi
 fullSizeDPI = 150 # 200
@@ -401,6 +401,9 @@ def plot_and_save_spacial_trouble(longitude, latitude,
         
         spatialTroubleFig.savefig(outputPath + "/" + fileBaseName + "." + fileNameDiscriminator + ".small.png", dpi=thumbSizeDPI)
     
+    # clear the figure
+    spatialTroubleFig.clf()
+    
     return
     
 def _handle_fig_creation_task(child_figure_function, log_message,
@@ -427,6 +430,7 @@ def _handle_fig_creation_task(child_figure_function, log_message,
         figure.savefig(fullFigOutputNamePath, dpi=fullSizeDPI)
         if (shouldMakeSmall) :
             figure.savefig(smallFigOutputNamePath, dpi=thumbSizeDPI)
+        figure.clf() # clear the figure
     
     # if we've reached this point and we did fork,
     # then we're the child process and we should stop now
-- 
GitLab