diff --git a/pyglance/glance/collocation.py b/pyglance/glance/collocation.py index 4c5ad9475a57bd130a7bfa23ec0dc26d71c639ae..ea34629987570d0b01783fc68ab8e10d391c8cd3 100644 --- a/pyglance/glance/collocation.py +++ b/pyglance/glance/collocation.py @@ -303,7 +303,7 @@ def create_colocated_lonlat_with_lon_lat_colocation(listOfColocatedALonLat, list def create_colocated_data_with_lon_lat_colocation(listOfColocatedALonLat, listOfColocatedBLonLat, colocatedLongitude, colocatedLatitude, aData, bData, - missingData=None, altMissingDataInB=None, + missingData, altMissingDataInB=None, invalidAMask=None, invalidBMask=None) : """ given a pre colocated list of A and B lon/lat info from create_colocation_mapping_within_epsilon, @@ -311,6 +311,9 @@ def create_colocated_data_with_lon_lat_colocation(listOfColocatedALonLat, listOf values so that it will match the original longitude and latitude """ + # Todo other asserts needed? + assert(missingData is not None) + if altMissingDataInB is None : altMissingDataInB = missingData diff --git a/pyglance/glance/compare.py b/pyglance/glance/compare.py index e787907d65435a6513cfdd9c9e95e793e5f4e6eb..04c93ccdfc82e0239a741365d11fcc8a0ee4892e 100644 --- a/pyglance/glance/compare.py +++ b/pyglance/glance/compare.py @@ -295,7 +295,7 @@ def _load_config_or_options(aPath, bPath, optionsSet, requestedVars = [ ]) : requestedConfigFile = optionsSet['configFile'] usedConfigFile = False - if (not (requestedConfigFile is None)) and os.path.exists(requestedConfigFile): + if (requestedConfigFile is not None) and os.path.exists(requestedConfigFile): LOG.info ("Using Config File Settings") @@ -467,7 +467,7 @@ def _check_lon_lat_equality(longitudeA, latitudeA, bDataObject = dataobj.DataObject(longitudeB, ignoreMask=ignoreMaskB) diffInfo = dataobj.DiffInfoObject(aDataObject, bDataObject, epsilonValue=llepsilon) #TODO, needs epsilon percent #TODO, for the moment, unpack these values into local variables - longitudeDiff = diffInfo.diff_data_object.data + longitudeDiff = diffInfo.diff_data_object.data finiteLongitudeMask = diffInfo.diff_data_object.masks.valid_mask lon_not_equal_mask = diffInfo.diff_data_object.masks.trouble_mask @@ -475,7 +475,7 @@ def _check_lon_lat_equality(longitudeA, latitudeA, bDataObject = dataobj.DataObject(latitudeB, ignoreMask=ignoreMaskB) diffInfo = dataobj.DiffInfoObject(aDataObject, bDataObject, epsilonValue=llepsilon) #TODO, needs epsilon percent #TODO, for the moment, unpack these values into local variables - latitudeDiff = diffInfo.diff_data_object.data + latitudeDiff = diffInfo.diff_data_object.data finiteLatitudeMask = diffInfo.diff_data_object.masks.valid_mask lat_not_equal_mask = diffInfo.diff_data_object.masks.trouble_mask @@ -749,10 +749,12 @@ def _check_pass_or_fail(varRunInfo, variableStats, defaultValues) : # figure out the overall pass/fail result didPass = None for passValue in passValues : - if (passValue is None) or (didPass is None) : - didPass = didPass or passValue - else : - didPass = didPass and passValue + # if passValue isn't none, we need to update didPass + if passValue is not None : + if didPass is not None : + didPass = passValue and didPass + else : + didPass = passValue return didPass, failed_fraction, non_finite_diff_fraction, r_squared_value diff --git a/pyglance/glance/data.py b/pyglance/glance/data.py index b138e74006775b9428143fed4adda3e651146065..5d4c25315878a461f9923b801669f72aad44872e 100644 --- a/pyglance/glance/data.py +++ b/pyglance/glance/data.py @@ -98,9 +98,6 @@ class DataObject (object) : If the fill value is provided it is expected to be of the same data type as the data array. """ - - # TODO, add some assertions for our expectations - self.data = dataArray self.fill_value = fillValue self.masks = BasicMaskSetObject(ignoreMask) @@ -254,10 +251,8 @@ class DiffInfoObject (object) : outside_epsilon_mask = outside_epsilon_mask | \ (abs(raw_diff) > epsilonValue) & valid_in_both if (epsilonPercent is not None) : - # TODO, test this part of the formula outside_epsilon_mask = outside_epsilon_mask | \ ((abs(raw_diff) > (aDataObject.data * (float(epsilonPercent) / 100.0))) & valid_in_both) - #outside_epsilon_mask = (abs(raw_diff) > epsilonValue) & valid_in_both # TODO also use epsilon percent # trouble points = mismatched nans, mismatched missing-values, differences that are too large trouble_pt_mask = ( (aDataObject.masks.non_finite_mask ^ bDataObject.masks.non_finite_mask) | diff --git a/pyglance/glance/delta.py b/pyglance/glance/delta.py index f7053266043628bb10c37dd2031ff1358ad1a2c3..687b0fb71b6cf3165b6c957a8e5272e366676f40 100644 --- a/pyglance/glance/delta.py +++ b/pyglance/glance/delta.py @@ -199,7 +199,7 @@ class BinTupleMapping (object) : self.bin_dimension_index = binIndexNumber self.tuple_dimension_index = tupleIndexNumber - # get the new index ordering for the data # TODO, bring call into class + # get the new index ordering for the data self.new_index_order = BinTupleMapping._make_new_index_list(numberOfDimensions, self.bin_dimension_index, self.tuple_dimension_index) diff --git a/pyglance/glance/plotcreatefns.py b/pyglance/glance/plotcreatefns.py index 38ae2342008c600d7c918cc96e76b7b87c40a573..bc8b238b3438b5d063296ac2a32e7bc82e6a874c 100644 --- a/pyglance/glance/plotcreatefns.py +++ b/pyglance/glance/plotcreatefns.py @@ -100,13 +100,25 @@ def select_projection(boundingAxes) : return projToUse -def _make_axis_and_basemap(lonLatDataDict, goodInAMask, goodInBMask, shouldUseSharedRangeForOriginal=False, variableDisplayName=None) : +def _make_shared_range(aData, goodInAMask, bData, goodInBMask, shouldUseSharedRangeForOriginal=False) : """ - Determine the appropriate axes for the given data (in longitude and latitude) and create the appropriate basemap and shared - range information. + If a shared range is desired, figure out what the shared range including all the data in + both sets is and return it. If it is not desired, return None. + """ + + # figure out the shared range for A and B's data, by default don't share a range + sharedRange = None + if (shouldUseSharedRangeForOriginal) : + sharedRange = figures._make_range(aData, ~goodInAMask, 50, offset_to_range=figures.offsetToRange, + data_b=bData, invalid_b_mask=~goodInBMask) + + return sharedRange + +def _make_axis_and_basemap(lonLatDataDict, goodInAMask, goodInBMask, variableDisplayName=None) : + """ + Determine the appropriate axes for the given data (in longitude and latitude) and create the appropriate basemap. - fullAxis, baseMapInstance, sharedRange = _make_axis_and_basemap(lonLatDataDict, goodInAMask, goodInBMask, - shouldUseSharedRangeForOriginal=False) + fullAxis, baseMapInstance, sharedRange = _make_axis_and_basemap(lonLatDataDict, goodInAMask, goodInBMask) """ nameMessage = '' @@ -133,58 +145,7 @@ def _make_axis_and_basemap(lonLatDataDict, goodInAMask, goodInBMask, shouldUseSh baseMapInstance, fullAxis = maps.create_basemap(lonLatDataDict['common']['lon'], lonLatDataDict['common']['lat'], fullAxis, select_projection(fullAxis)) - """ TODO, this doesn't work, but we will need something eventually - if (projection is 'lcc') : - # TODO this is a hack to make sure all my data is visible in a lcc projection - # otherwise the conic projection may cause part of the data to curve - # out of the field of view - # at some point in the future this should be integrated in a more elegant way - - # preprocess a copy of our lon/lat data - lonACopy = lonLatDataDict['a']['lon'].copy() - lonACopy[~goodInAMask] = maps.badLonLat - latACopy = lonLatDataDict['a']['lat'].copy() - latACopy[~goodInAMask] = maps.badLonLat - lonBCopy = lonLatDataDict['b']['lon'].copy() - lonBCopy[~goodInBMask] = maps.badLonLat - latBCopy = lonLatDataDict['b']['lat'].copy() - latBCopy[~goodInBMask] = maps.badLonLat - - # find out where the longitude and latitude data would be in x and y - xTempA, yTempA = baseMapInstance(lonACopy, latACopy) - xTempB, yTempB = baseMapInstance(lonBCopy, latBCopy) - maxX = max(max(xTempA[goodInAMask]), max(xTempB[goodInBMask])) - minX = min(min(xTempA[goodInAMask]), min(xTempB[goodInBMask])) - maxY = max(max(yTempA[goodInAMask]), max(yTempB[goodInBMask])) - minY = min(min(yTempA[goodInAMask]), min(yTempB[goodInBMask])) - - # the corners of a bounding box (starting at the upper right going clockwise) - cornerX = [maxX, maxX, minX, minX] - cornerY = [maxY, minY, minY, maxY] - - # now where is this in the lon / lat space? - newLon, newLat = baseMapInstance(cornerX, cornerY, inverse=True) - newLon = np.array(newLon) - newLat = np.array(newLat) - # use this to make a new axis that will include all the data - borderAxis = get_visible_axes(newLon, newLat, ones(newLon.shape, dtype=bool)) - fullAxis = borderAxis - #fullAxis = [min(borderAxis[0], fullAxis[0]), max(borderAxis[1], fullAxis[1]), - # min(borderAxis[2], fullAxis[2]), max(borderAxis[3], fullAxis[3])] - - # make our new and improved basemap - baseMapInstance, fullAxis = maps.create_basemap(lonLatDataDict['common']['lon'], - lonLatDataDict['common']['lat'], - fullAxis, projection) - """ - - # figure out the shared range for A and B's data, by default don't share a range - sharedRange = None - if (shouldUseSharedRangeForOriginal) : - sharedRange = figures._make_range(aData, ~goodInAMask, 50, offset_to_range=figures.offsetToRange, - data_b=bData, invalid_b_mask=~goodInBMask) - - return fullAxis, baseMapInstance, sharedRange + return fullAxis, baseMapInstance # ********************* Section of public classes *********************** @@ -367,10 +328,12 @@ class MappedContourPlotFunctionFactory (PlottingFunctionFactory) : assert(goodInBMask is not None) # TODO, do I also need to encorporate the lon/lat invalid masks with the good masks? - fullAxis, baseMapInstance, sharedRange = _make_axis_and_basemap(lonLatDataDict, - goodInAMask, goodInBMask, - shouldUseSharedRangeForOriginal, - variableDisplayName) + fullAxis, baseMapInstance = _make_axis_and_basemap(lonLatDataDict, + goodInAMask, goodInBMask, + variableDisplayName) + sharedRange = _make_shared_range(aData, goodInAMask, + bData, goodInBMask, + shouldUseSharedRangeForOriginal) # make the plotting functions @@ -542,8 +505,8 @@ class MappedQuiverPlotFunctionFactory (PlottingFunctionFactory) : assert(goodInBMask is not None) # TODO, do I also need to encorporate the lon/lat invalid masks with the good masks? - fullAxis, baseMapInstance, _ = _make_axis_and_basemap(lonLatDataDict, goodInAMask, goodInBMask, - variableDisplayName=variableDisplayName) + fullAxis, baseMapInstance = _make_axis_and_basemap(lonLatDataDict, goodInAMask, goodInBMask, + variableDisplayName=variableDisplayName) # make the plotting functions