From ec0cc1417e25f2867569e4e2b85707b9a3f8daf7 Mon Sep 17 00:00:00 2001
From: "(no author)" <(no author)@8a9318a1-56ba-4d59-b755-99d26321be01>
Date: Tue, 25 Aug 2009 19:27:50 +0000
Subject: [PATCH] changing how the stats that are out of the number of finite
 pts are calculated

git-svn-id: https://svn.ssec.wisc.edu/repos/glance/trunk@69 8a9318a1-56ba-4d59-b755-99d26321be01
---
 pyglance/glance/compare.py |  2 +-
 pyglance/glance/delta.py   | 11 +++++++++--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/pyglance/glance/compare.py b/pyglance/glance/compare.py
index cb8d240..2e21b39 100644
--- a/pyglance/glance/compare.py
+++ b/pyglance/glance/compare.py
@@ -550,7 +550,7 @@ def _check_pass_or_fail(varRunInfo, variableStats, defaultValues) :
     # check to see if it failed on nonfinite data
     if not (nonfiniteTolerance is None) :
         non_finite_pts = variableStats['Finite Data Statistics']['finite_in_only_one_count']
-        non_finite_pts = non_finite_pts + variableStats['Missing Value Statistics']['common_missing_count']
+        non_finite_pts = non_finite_pts + variableStats['Missing Value Statistics']['common_missing_count'] # TODO, should this line be removed?
         non_finite_pts = non_finite_pts + variableStats['NaN Statistics']['common_nan_count']
         non_finite_fraction = float(non_finite_pts) / float(variableStats['General Statistics']['num_data_points'])
         passedNonFinite = non_finite_fraction <= nonfiniteTolerance
diff --git a/pyglance/glance/delta.py b/pyglance/glance/delta.py
index 5139873..0debd97 100644
--- a/pyglance/glance/delta.py
+++ b/pyglance/glance/delta.py
@@ -275,10 +275,17 @@ def _get_numerical_data_stats(a, b, diff_data, data_is_finite_mask, outside_epsi
     # we actually want the total number of _finite_ values rather than all the data
     total_num_finite_values = sum(data_is_finite_mask)
     
+    # no dividing by 0!
+    fraction_too_different = 1.0
+    fraction_perfect = 0.0
+    if total_num_finite_values > 0 :
+        fraction_too_different = num_finite_values_too_different / float(total_num_finite_values)
+        fraction_perfect = num_perfect / float(total_num_finite_values)
+    
     comparison = {  'diff_outside_epsilon_count': num_finite_values_too_different,
-                    'diff_outside_epsilon_fraction': num_finite_values_too_different / float(total_num_finite_values),
+                    'diff_outside_epsilon_fraction': fraction_too_different,
                     'perfect_match_count': num_perfect,
-                    'perfect_match_fraction': num_perfect / float(total_num_finite_values),
+                    'perfect_match_fraction': fraction_perfect,
                     'correlation': r_corr
                     }
     comparison.update(additional_statistics)
-- 
GitLab