diff --git a/pyglance/glance/compare.py b/pyglance/glance/compare.py index 4b80bf6f27d1abe4e0c1a0ccfdc06d8cdd131e74..0ff335cd13506359f04652dd506be2a22cf3cfa0 100644 --- a/pyglance/glance/compare.py +++ b/pyglance/glance/compare.py @@ -1610,7 +1610,8 @@ def inspect_library_call (a_path, var_list=[ ], fullDPI= runInfo['detail_DPI'], thumbDPI= runInfo['thumb_DPI'], units_a= varRunInfo['units_a'] if 'units_a' in varRunInfo else None, - useBData=False) + useBData=False, + histRange=varRunInfo['histogram_range'] if 'histogram_range' in varRunInfo else None) LOG.info("\tfinished creating figures for: " + explanationName) @@ -1935,7 +1936,8 @@ def reportGen_library_call (a_path, b_path, var_list=[ ], fullDPI= runInfo['detail_DPI'], thumbDPI= runInfo['thumb_DPI'], units_a= varRunInfo['units_a'] if 'units_a' in varRunInfo else None, - units_b= varRunInfo['units_b'] if 'units_b' in varRunInfo else None) + units_b= varRunInfo['units_b'] if 'units_b' in varRunInfo else None, + )#histRange= varRunInfo['histogram_range'] if 'histogram_range' in varRunInfo else None) LOG.info("\tfinished creating figures for: " + explanationName) diff --git a/pyglance/glance/figures.py b/pyglance/glance/figures.py index 8777caf8b55cf0afd903f2ab7b25c557d0cee1c9..faa4c1176e4700fe2abb84536acbfc2151958258 100644 --- a/pyglance/glance/figures.py +++ b/pyglance/glance/figures.py @@ -351,7 +351,7 @@ def _draw_x_equals_y_line(axes, color='k', style='--', epsilon=None, epsilonColo axes.set_ybound(ybounds) # build a histogram figure of the given data with the given title and number of bins -def create_histogram(data, bins, title, xLabel, yLabel, displayStats=False, units=None) : +def create_histogram(data, bins, title, xLabel, yLabel, displayStats=False, units=None, rangeList=None) : # make the figure figure = plt.figure() @@ -360,8 +360,12 @@ def create_histogram(data, bins, title, xLabel, yLabel, displayStats=False, unit if (data is None) or (len(data) <= 0) : return figure + if rangeList is not None : + assert len(rangeList) == 2 + assert rangeList[0] < rangeList[1] + # the histogram of the data - n, outBins, patches = plt.hist(data, bins) + n, outBins, patches = plt.hist(data, bins, range=rangeList) # if rangeList is None the range won't be restricted # format our axes so they display gracefully yFormatter = FormatStrFormatter("%3.3g") @@ -412,6 +416,11 @@ def create_histogram(data, bins, title, xLabel, yLabel, displayStats=False, unit xValToUse = 0.17 figtext(xValToUse, 0.60, statText) + # make sure we didn't mess up the range if it's being restricted + # (this may be unnessicary, but it's a good extra precaution) + if rangeList is not None: + plt.xlim(rangeList) + return figure # create a figure including our data mapped onto a map at the lon/lat given diff --git a/pyglance/glance/filters.py b/pyglance/glance/filters.py index 2efcbee6b066189e43ed02ecb9a488ad3eda0727..cb2c2e250c1cb9190188e4bc12aaa65f4c755c0c 100644 --- a/pyglance/glance/filters.py +++ b/pyglance/glance/filters.py @@ -178,11 +178,19 @@ def rotate_indexes_right (data) : return data_new +# TODO, this method is only here for backwards compatibility def set_to_value_between_bounds(data, value_to_set_to, bottom_bound_exclusive, top_bound_exclusive) : """ Wherever the data is non-finite or outside the given bounds, set it to the given value. """ + return set_to_value_outside_bounds (data, value_to_set_to, bottom_bound_exclusive, top_bound_exclusive) + +def set_to_value_outside_bounds(data, value_to_set_to, bottom_bound_exclusive, top_bound_exclusive) : + """ + Wherever the data is non-finite or outside the given bounds, set it to the given value. + """ + mask = (data < bottom_bound_exclusive) | (data > top_bound_exclusive) | (~ np.isfinite(data)) data[mask] = value_to_set_to diff --git a/pyglance/glance/gui_figuremanager.py b/pyglance/glance/gui_figuremanager.py index e42f3d88886ff222b7a8f441f14990d45a79399a..a02f6fce2ee992e2e34eadaa24ed010063b6a7e0 100644 --- a/pyglance/glance/gui_figuremanager.py +++ b/pyglance/glance/gui_figuremanager.py @@ -343,6 +343,7 @@ class GlanceGUIFigures (object) : # Note: histograms don't care about data format requested, they are histogram formatted rawDiffDataClean = diffData.diff_data_object.data[diffData.diff_data_object.masks.valid_mask] + # TODO, should the range option be added here? tempFigure = figures.create_histogram(rawDiffDataClean, DEFAULT_NUM_BINS, "Difference in\n" + aVarName, "Value of (B - A) at each data point", "Number of points with a given difference", units=aUnitsText) diff --git a/pyglance/glance/plot.py b/pyglance/glance/plot.py index c3be9a23f24aa297196edfdbc8d178662bfc8d99..62c1e3a73b4fb89496fa170518d54d608581bff8 100644 --- a/pyglance/glance/plot.py +++ b/pyglance/glance/plot.py @@ -170,7 +170,8 @@ def plot_and_save_comparison_figures (aData, bData, epsilonPercent=None, fullDPI=None, thumbDPI=None, units_a=None, units_b=None, - useBData=True) : + useBData=True, + histRange=None) : """ Plot images for a set of figures based on the data sets and settings passed in. The images will be saved to disk according to the settings. @@ -229,6 +230,7 @@ def plot_and_save_comparison_figures (aData, bData, useBData - should the b data be expected or not? when this is false, b data will not be used and no lon/lat data for b will be expected either + histRange - the range that should be used for the histogram, or None ** May fail due to a known bug on MacOSX systems. """ @@ -302,7 +304,10 @@ def plot_and_save_comparison_figures (aData, bData, epsilonPercent=epsilonPercent, # used for display in several types of plots - units_a=units_a, units_b=units_b + units_a=units_a, units_b=units_b, + + # range for a histogram + histRange=histRange ) plottingFunctions.update(moreFunctions) diff --git a/pyglance/glance/plotcreatefns.py b/pyglance/glance/plotcreatefns.py index 14904c7643c9984dadff98f2ed067ddfe1026def..efb52aee7a96a09270c1201b9916d610a73679e2 100644 --- a/pyglance/glance/plotcreatefns.py +++ b/pyglance/glance/plotcreatefns.py @@ -183,7 +183,10 @@ class PlottingFunctionFactory : # the optional epsilon for comparison of a percent of A epsilonPercent=None, # the optional units for display - units_a=None, units_b=None + units_a=None, units_b=None, + + # an optional range for a histogram + histRange=None ) : _abstract @@ -226,7 +229,10 @@ class BasicComparisonPlotsFunctionFactory (PlottingFunctionFactory) : # the optional epsilon for comparison of a percent of A epsilonPercent=None, # the optional units for display - units_a=None, units_b=None + units_a=None, units_b=None, + + # an optional range for a histogram + histRange=None ) : @@ -255,7 +261,7 @@ class BasicComparisonPlotsFunctionFactory (PlottingFunctionFactory) : ("Difference in\n" + variableDisplayName), ('Value of (Data File B - Data File A) at a Data Point'), ('Number of Data Points with a Given Difference'), - True, units=units_a)), + True, units=units_a, rangeList=histRange)), "histogram of the amount of difference in " + variableDisplayName, "Hist.png", compared_fig_list) # make the scatter plot @@ -327,7 +333,10 @@ class MappedContourPlotFunctionFactory (PlottingFunctionFactory) : # the optional epsilon for comparison of a percent of A epsilonPercent=None, # the optional units for display - units_a=None, units_b=None + units_a=None, units_b=None, + + # an optional range for a histogram + histRange=None ) : @@ -514,7 +523,10 @@ class MappedQuiverPlotFunctionFactory (PlottingFunctionFactory) : # the optional epsilon for comparison of a percent of A epsilonPercent=None, # the optional units for display - units_a=None, units_b=None + units_a=None, units_b=None, + + # an optional range for a histogram + histRange=None ) : @@ -707,7 +719,10 @@ class LinePlotsFunctionFactory (PlottingFunctionFactory) : # the optional epsilon for comparison of a percent of A epsilonPercent=None, # the optional units for display - units_a=None, units_b=None + units_a=None, units_b=None, + + # an optional range for a histogram + histRange=None ) : """ @@ -821,7 +836,10 @@ class BinTupleAnalysisFunctionFactory (PlottingFunctionFactory) : # the optional epsilon for comparison of a percent of A epsilonPercent=None, # the optional units for display - units_a=None, units_b=None + units_a=None, units_b=None, + + # an optional range for a histogram + histRange=None ) : """ @@ -916,7 +934,7 @@ class BinTupleAnalysisFunctionFactory (PlottingFunctionFactory) : "\nfor " + binName + " # " + str(binNumber + 1)), ('RMS Difference across ' + tupleName + ' dimension'), ('Number of Cases with a Given RMS Diff.'), - True, units=units_a) + True, units=units_a, rangeList=histRange) functionsToReturn[str(binNumber + 1) + 'histogram'] = (make_histogram, "histogram of rms differences in " + variableDisplayName, str(binNumber + 1) + "Hist.png", new_list) @@ -1021,7 +1039,10 @@ class IMShowPlotFunctionFactory (PlottingFunctionFactory) : # the optional epsilon for comparison of a percent of A epsilonPercent=None, # the optional units for display - units_a=None, units_b=None + units_a=None, units_b=None, + + # an optional range for a histogram + histRange=None ) : """ @@ -1163,7 +1184,10 @@ class DataHistogramPlotFunctionFactory (PlottingFunctionFactory) : # the optional epsilon for comparison of a percent of A epsilonPercent=None, # the optional units for display - units_a=None, units_b=None + units_a=None, units_b=None, + + # an optional range for a histogram + histRange=None ) : @@ -1186,7 +1210,7 @@ class DataHistogramPlotFunctionFactory (PlottingFunctionFactory) : ("Values of\n" + variableDisplayName), ('Value of Data Point'), ('Number of Data Points with a Given Value'), - True, units=units_a)), + True, units=units_a, rangeList=histRange)), "histogram of the values in " + variableDisplayName, "HistA.png", original_fig_list) @@ -1229,7 +1253,10 @@ class InspectIMShowPlotFunctionFactory (PlottingFunctionFactory) : # the optional epsilon for comparison of a percent of A epsilonPercent=None, # the optional units for display - units_a=None, units_b=None + units_a=None, units_b=None, + + # an optional range for a histogram + histRange=None ) : """ @@ -1300,7 +1327,10 @@ class InspectLinePlotsFunctionFactory (PlottingFunctionFactory) : # the optional epsilon for comparison of a percent of A epsilonPercent=None, # the optional units for display - units_a=None, units_b=None + units_a=None, units_b=None, + + # an optional range for a histogram + histRange=None ) : """ @@ -1373,7 +1403,10 @@ class InspectMappedContourPlotFunctionFactory (PlottingFunctionFactory) : # the optional epsilon for comparison of a percent of A epsilonPercent=None, # the optional units for display - units_a=None, units_b=None + units_a=None, units_b=None, + + # an optional range for a histogram + histRange=None ) :