From 84eb21a5dd305b704ccf1de428870fad0bf06e87 Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@8a9318a1-56ba-4d59-b755-99d26321be01> Date: Tue, 25 Aug 2009 18:00:40 +0000 Subject: [PATCH] fixed bug when scaling data which includes missing values; changed thumbnail creation to resize existing image instead of resaving figure git-svn-id: https://svn.ssec.wisc.edu/repos/glance/trunk@62 8a9318a1-56ba-4d59-b755-99d26321be01 --- pyglance/glance/compare.py | 2 +- pyglance/glance/io.py | 18 +++++++++++++++--- pyglance/glance/plot.py | 12 ++++++++++-- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/pyglance/glance/compare.py b/pyglance/glance/compare.py index ae8efbd..cb8d240 100644 --- a/pyglance/glance/compare.py +++ b/pyglance/glance/compare.py @@ -179,7 +179,7 @@ def _resolve_names(fileAObject, fileBObject, defaultValues, if ('alternate_name_in_B' in currNameInfo) : name_b = currNameInfo['alternate_name_in_B'] - if (name in fileCommonNames) | \ + if (name in fileCommonNames) or \ (currNameInfo.has_key('alternate_name_in_B') and (name in nameComparison['uniqueToAVars']) and (name_b in nameComparison['uniqueToBVars'])) : diff --git a/pyglance/glance/io.py b/pyglance/glance/io.py index 9e53096..b9319ee 100644 --- a/pyglance/glance/io.py +++ b/pyglance/glance/io.py @@ -80,9 +80,13 @@ class hdf(SD): LOG.warn ('Scaling method of \"' + str(scaling_method) + '\" will be ignored in favor of hdf standard method. ' + 'This may cause problems with data consistency') + # get information about where the data is the missing value + missing_val = self.missing_value(name) + missing_mask = (raw_data_copy == missing_value) + # create the scaled version of the data scaled_data_copy = np.array(raw_data_copy, dtype=data_type) - scaled_data_copy = (scaled_data_copy - add_offset) * scale_factor #TODO, type truncation issues? + scaled_data_copy[~missing_mask] = (scaled_data_copy[~missing_mask] - add_offset) * scale_factor #TODO, type truncation issues? return scaled_data_copy @@ -140,9 +144,13 @@ class nc(CDF): if (scale_factor == 1.0) and (add_offset == 0.0) : return raw_data_copy + # get information about where the data is the missing value + missing_val = self.missing_value(name) + missing_mask = (raw_data_copy == missing_value) + # create the scaled version of the data scaled_data_copy = np.array(raw_data_copy, dtype=data_type) - scaled_data_copy = (scaled_data_copy - add_offset) * scale_factor #TODO, type truncation issues? + scaled_data_copy[~missing_mask] = (scaled_data_copy[~missing_mask] - add_offset) * scale_factor #TODO, type truncation issues? return scaled_data_copy @@ -212,9 +220,13 @@ class h5(object): if (scale_factor == 1.0) and (add_offset == 0.0) : return raw_data_copy + # get information about where the data is the missing value + missing_val = self.missing_value(name) + missing_mask = (raw_data_copy == missing_value) + # create the scaled version of the data scaled_data_copy = np.array(raw_data_copy, dtype=data_type) - scaled_data_copy = (scaled_data_copy - add_offset) * scale_factor #TODO, type truncation issues? + scaled_data_copy[~missing_mask] = (scaled_data_copy[~missing_mask] - add_offset) * scale_factor #TODO, type truncation issues? return scaled_data_copy diff --git a/pyglance/glance/plot.py b/pyglance/glance/plot.py index ae2ec2b..49f929c 100644 --- a/pyglance/glance/plot.py +++ b/pyglance/glance/plot.py @@ -18,6 +18,8 @@ from matplotlib import cm import matplotlib.colors as colors from matplotlib.ticker import FormatStrFormatter +from PIL import Image + import os, sys, logging import numpy as np @@ -439,8 +441,14 @@ def _handle_fig_creation_task(child_figure_function, log_message, LOG.info(log_message) figure.savefig(fullFigOutputNamePath, dpi=fullSizeDPI) if (shouldMakeSmall) : - figure.savefig(smallFigOutputNamePath, dpi=thumbSizeDPI) - + + tempImage = Image.open(fullFigOutputNamePath) + scaleFactor = float(thumbSizeDPI) / float(fullSizeDPI) + originalSize = tempImage.size + newSize = (int(originalSize[0] * scaleFactor), int(originalSize[1] * scaleFactor)) + tempImage = tempImage.resize(newSize, Image.ANTIALIAS) + tempImage.save(smallFigOutputNamePath) + # get rid of the figure plt.close(figure) del(figure) -- GitLab