From fd439f55e3448b03db89fb44f9cff4dabce3f11a Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@8a9318a1-56ba-4d59-b755-99d26321be01> Date: Fri, 15 Oct 2010 22:39:31 +0000 Subject: [PATCH] fixed config file link on main report page; added units display to reports if units attribute is present in files git-svn-id: https://svn.ssec.wisc.edu/repos/glance/trunk@137 8a9318a1-56ba-4d59-b755-99d26321be01 --- pyglance/glance/compare.py | 14 ++++++ pyglance/glance/io.py | 79 ++++++++++++++++++++++++++++-- pyglance/glance/mainreport.txt | 2 +- pyglance/glance/variablereport.txt | 8 +++ 4 files changed, 97 insertions(+), 6 deletions(-) diff --git a/pyglance/glance/compare.py b/pyglance/glance/compare.py index a93f00f..807c8b7 100644 --- a/pyglance/glance/compare.py +++ b/pyglance/glance/compare.py @@ -57,6 +57,8 @@ glance_analysis_defaults = {'epsilon': 0.0, 'minimum_acceptable_squared_correlation_coefficient': None } +UNITS_CONSTANT = "units" + def _clean_path(string_path) : """ Return a clean form of the path without any '.', '..', or '~' @@ -144,6 +146,10 @@ def _resolve_names(fileAObject, fileBObject, defaultValues, finalNames[name]['missing_value'] = missing finalNames[name]['missing_value_alt_in_b'] = missing_b + # get any information about the units listed in the files + finalNames[name]['units_a'] = fileAObject.get_attribute(name, UNITS_CONSTANT) + finalNames[name]['units_b'] = fileBObject.get_attribute(name, UNITS_CONSTANT) + # otherwise just do the ones the user asked for else : # check each of the names the user asked for to see if it is either in the list of common names @@ -180,6 +186,10 @@ def _resolve_names(fileAObject, fileBObject, defaultValues, _get_missing_values_if_needed((fileAObject, fileBObject), name, name_b, missing, missing_b) + # get any information about the units listed in the files + finalNames[dispName]['units_a'] = fileAObject.get_attribute(name, UNITS_CONSTANT) + finalNames[dispName]['units_b'] = fileBObject.get_attribute(name_b, UNITS_CONSTANT) + else : LOG.warn('No technical variable name was given for the entry described as "' + dispName + '". ' + 'Skipping this variable.') @@ -202,6 +212,10 @@ def _resolve_names(fileAObject, fileBObject, defaultValues, missing_value_A=missing, missing_value_B=missing) finalNames[name]['missing_value'] = missing finalNames[name]['missing_value_alt_in_b'] = missing_b + + # get any information about the units listed in the files + finalNames[name]['units_a'] = fileAObject.get_attribute(name, UNITS_CONSTANT) + finalNames[name]['units_b'] = fileBObject.get_attribute(name, UNITS_CONSTANT) LOG.debug("Final selected set of variables to analyze:") LOG.debug(str(finalNames)) diff --git a/pyglance/glance/io.py b/pyglance/glance/io.py index 73601aa..ed3e77d 100644 --- a/pyglance/glance/io.py +++ b/pyglance/glance/io.py @@ -32,6 +32,17 @@ except ImportError: fillValConst1 = '_FillValue' fillValConst2 = 'missing_value' +class IOUnimplimentedError(Exception): + """ + The exception raised when a requested io operation is not yet available. + + msg -- explanation of the problem + """ + def __init__(self, msg): + self.msg = msg + def __str__(self): + return self.msg + class hdf(SD): """wrapper for HDF4 dataset for comparison __call__ yields sequence of variable names @@ -134,7 +145,7 @@ class hdf(SD): be created """ - # TODO + raise IOUnimplimentedError('Unable to create variable in hdf file, this functionality is not yet available.') return None @@ -143,9 +154,24 @@ class hdf(SD): if the attribute exists for the given variable, set it to the new value if the attribute does not exist for the given variable, create it and set it to the new value """ - # TODO + + raise IOUnimplimentedError('Unable add attribute to hdf file, this functionality is not yet available.') return + + def get_attribute(self, variableName, attributeName) : + """ + returns the value of the attribute if it is available for this variable, or None + """ + toReturn = None + + variable_object = self.get_variable_object(variableName) + temp_attributes = variable_object.attributes() + + if attributeName in temp_attributes : + toReturn = temp_attributes[attributeName] + + return toReturn class nc(CDF): """wrapper for NetCDF3/4/opendap dataset for comparison @@ -300,6 +326,20 @@ class nc(CDF): self.enddef() return + + def get_attribute(self, variableName, attributeName) : + """ + returns the value of the attribute if it is available for this variable, or None + """ + toReturn = None + + variable_object = self.get_variable_object(variableName) + temp_attributes = variable_object.attributes() + + if attributeName in temp_attributes : + toReturn = temp_attributes[attributeName] + + return toReturn nc4 = nc @@ -417,7 +457,7 @@ class h5(object): be created """ - # TODO + raise IOUnimplimentedError('Unable to create variable in hdf 5 file, this functionality is not yet available.') return None @@ -426,9 +466,22 @@ class h5(object): if the attribute exists for the given variable, set it to the new value if the attribute does not exist for the given variable, create it and set it to the new value """ - # TODO + + raise IOUnimplimentedError('Unable to add attribute to hdf 5 file, this functionality is not yet available.') return + + def get_attribute(self, variableName, attributeName) : + """ + returns the value of the attribute if it is available for this variable, or None + """ + toReturn = None + + variable_object = self.get_variable_object(variableName) + if (attributeName in variable_object.attrs) : + toReturn = variable_object.attrs[attributeName] + + return toReturn @@ -502,7 +555,10 @@ class aeri(object): the created variable will be returned, or None if a variable could not be created - """ + """ + + raise IOUnimplimentedError('Unable to create variable in aeri file, this functionality is not yet available.') + return None def add_attribute_data_to_variable(self, variableName, newAttributeName, newAttributeValue) : @@ -511,7 +567,20 @@ class aeri(object): if the attribute does not exist for the given variable, create it and set it to the new value """ + raise IOUnimplimentedError('Unable to add attribute to aeri file, this functionality is not yet available.') + return + + def get_attribute(self, variableName, attributeName) : + """ + returns the value of the attribute if it is available for this variable, or None + """ + toReturn = None + + # TODO + LOG.warn('Glance does not yet support attribute retrieval in AERI files. None will be used.') + + return toReturn # handle the variety of file suffixes by building aliases to aeri class cxs = rnc = cxv = csv = spc = sum = uvs = aeri diff --git a/pyglance/glance/mainreport.txt b/pyglance/glance/mainreport.txt index e18dbeb..0354923 100644 --- a/pyglance/glance/mainreport.txt +++ b/pyglance/glance/mainreport.txt @@ -42,7 +42,7 @@ Copyright (c) 2009 University of Wisconsin SSEC. All rights reserved. % if ('config_file_path' in runInfo) and (runInfo['config_file_path'] is not None) : <p> A configuration file was used to control the production report.<br> - Please see <a href="${runInfo['config_file_path']}">this copy of the configuration file</a> + Please see <a href="./${runInfo['config_file_name']}">this copy of the configuration file</a> for details. </p> diff --git a/pyglance/glance/variablereport.txt b/pyglance/glance/variablereport.txt index 3c84004..1819695 100644 --- a/pyglance/glance/variablereport.txt +++ b/pyglance/glance/variablereport.txt @@ -179,6 +179,14 @@ Copyright (c) 2009 University of Wisconsin SSEC. All rights reserved. % else : "missing" data value: ${str(runInfo['missing_value'])}<br> % endif + + ## if there are units available, display those + % if ('units_a' in runInfo) and (runInfo['units_a'] is not None) : + units in A: ${str(runInfo['units_a'])}<br> + % endif + % if ('units_b' in runInfo) and (runInfo['units_b'] is not None) : + units in B: ${str(runInfo['units_b'])}<br> + % endif </p> <h3>Statistical Summary</h3> -- GitLab