diff --git a/pyglance/glance/compare.py b/pyglance/glance/compare.py index 807c8b766e1cb4bf99538d22c24be473d4868375..9f534a17133cd92b977d67f7367fa9beb6e96b92 100644 --- a/pyglance/glance/compare.py +++ b/pyglance/glance/compare.py @@ -35,7 +35,9 @@ glance_setting_defaults = {'shouldIncludeReport': True, 'doFork': False, 'useThreadsToControlMemory': False, 'useSharedRangeForOriginal': False, - 'noLonLatVars': False} + 'noLonLatVars': False, + 'detail_DPI': 150, + 'thumb_DPI': 50} # these are the built in longitude/latitude defaults glance_lon_lat_defaults = {'longitude': 'pixel_longitude', @@ -453,7 +455,8 @@ def _get_percentage_from_mask(dataMask) : # TODO, this comparison needs to encorporate epsilon percent as well def _check_lon_lat_equality(longitudeADataObject, latitudeADataObject, longitudeBDataObject, latitudeBDataObject, - llepsilon, doMakeImages, outputPath) : + llepsilon, doMakeImages, outputPath, + fullDPI=None, thumbDPI=None) : """ check to make sure the longitude and latitude are equal everywhere that's not in the ignore masks if they are not and doMakeImages was passed as True, generate appropriate figures to show where @@ -486,21 +489,25 @@ def _check_lon_lat_equality(longitudeADataObject, latitudeADataObject, # if we are making images, make two showing the invalid lons/lats if (doMakeImages) : - if (len(longitudeA[~ignoreMaskA]) > 0) and (len(latitudeA[~ignoreMaskA]) > 0) : + if ((len(longitudeADataObject.data[~longitudeADataObject.masks.ignore_mask]) > 0) and + (len( latitudeADataObject.data[~ latitudeADataObject.masks.ignore_mask]) > 0)) : plot.plot_and_save_spacial_trouble(longitudeADataObject, latitudeADataObject, lon_lat_not_equal_mask, "A", "Lon./Lat. Points Mismatched between A and B\n" + "(Shown in A)", "LonLatMismatch", - outputPath, True) + outputPath, True, + fullDPI=fullDPI, thumbDPI=thumbDPI) - if (len(longitudeB[~ignoreMaskB]) > 0) and (len(latitudeB[~ignoreMaskB]) > 0) : + if ((len(longitudeBDataObject.data[~longitudeBDataObject.masks.ignore_mask]) > 0) and + (len( latitudeBDataObject.data[~ latitudeBDataObject.masks.ignore_mask]) > 0)) : plot.plot_and_save_spacial_trouble(longitudeBDataObject, latitudeBDataObject, lon_lat_not_equal_mask, "B", "Lon./Lat. Points Mismatched between A and B\n" + "(Shown in B)", "LonLatMismatch", - outputPath, True) + outputPath, True, + fullDPI=fullDPI, thumbDPI=thumbDPI) # setup our return data returnInfo = {} @@ -511,7 +518,8 @@ def _check_lon_lat_equality(longitudeADataObject, latitudeADataObject, def _compare_spatial_invalidity(longitude_a_object, longitude_b_object, latitude_a_object, latitude_b_object, - spatial_info, do_include_images, output_path) : + spatial_info, do_include_images, output_path, + fullDPI=None, thumbDPI=None) : """ Given information about where the two files are spatially invalid, figure out what invalidity they share and save information or plots for later use @@ -552,20 +560,22 @@ def _compare_spatial_invalidity(longitude_a_object, longitude_b_object, if ((spatial_info['file A']['numInvPts'] > 0) and (do_include_images) and (len(longitude_a_object.data[~invalid_in_a_mask]) > 0) and (len( latitude_a_object.data[~invalid_in_a_mask]) > 0)) : - plot.plot_and_save_spacial_trouble(longitude_a_object.data, latitude_a_object.data, + plot.plot_and_save_spacial_trouble(longitude_a_object, latitude_a_object, valid_only_in_mask_a, "A", "Points only valid in\nFile A\'s longitude & latitude", "SpatialMismatch", - output_path, True) + output_path, True, + fullDPI=fullDPI, thumbDPI=thumbDPI) if ((spatial_info['file B']['numInvPts'] > 0) and (do_include_images) and (len(longitude_b_object.data[~invalid_in_b_mask]) > 0) and (len( latitude_b_object.data[~invalid_in_b_mask]) > 0) ) : - plot.plot_and_save_spacial_trouble(longitude_b_object.data, latitude_b_object.data, + plot.plot_and_save_spacial_trouble(longitude_b_object, latitude_b_object, valid_only_in_mask_b, "B", "Points only valid in\nFile B\'s longitude & latitude", "SpatialMismatch", - output_path, True) + output_path, True, + fullDPI=fullDPI, thumbDPI=thumbDPI) return invalid_in_common_mask, spatial_info, longitude_common, latitude_common @@ -581,7 +591,8 @@ class VariableComparisonError(Exception): return self.msg def _handle_lon_lat_info (lon_lat_settings, a_file_object, b_file_object, output_path, - should_make_images=False, should_check_equality=True) : + should_make_images=False, should_check_equality=True, + fullDPI=None, thumbDPI=None) : """ Manage loading and comparing longitude and latitude information for two files @@ -640,7 +651,8 @@ def _handle_lon_lat_info (lon_lat_settings, a_file_object, b_file_object, output moreSpatialInfo = _check_lon_lat_equality(longitude_a_object, latitude_a_object, longitude_b_object, latitude_b_object, lon_lat_settings['lon_lat_epsilon'], - should_make_images, output_path) + should_make_images, output_path, + fullDPI=fullDPI, thumbDPI=thumbDPI) # update our existing spatial information spatialInfo.update(moreSpatialInfo) @@ -648,7 +660,8 @@ def _handle_lon_lat_info (lon_lat_settings, a_file_object, b_file_object, output spaciallyInvalidMask, spatialInfo, longitude_common, latitude_common = \ _compare_spatial_invalidity(longitude_a_object, longitude_b_object, latitude_a_object, latitude_b_object, - spatialInfo, should_make_images, output_path) + spatialInfo, should_make_images, output_path, + fullDPI=fullDPI, thumbDPI=thumbDPI) else: spaciallyInvalidMask = None longitude_common = None @@ -947,7 +960,8 @@ def colocateToFile_library_call(a_path, b_path, var_list=[ ], # or { } if there is no lon/lat info lon_lat_data = { } try : - lon_lat_data, _ = _handle_lon_lat_info (runInfo, aFile, bFile, pathsTemp['out'], should_check_equality=False) + lon_lat_data, _ = _handle_lon_lat_info (runInfo, aFile, bFile, pathsTemp['out'], should_check_equality=False, + fullDPI=runInfo['detail_DPI'], thumbDPI=runInfo['thumb_DPI']) except VariableLoadError, vle : LOG.warn("Error while loading longitude or latitude: ") LOG.warn(vle.msg) @@ -1268,7 +1282,8 @@ def reportGen_library_call (a_path, b_path, var_list=[ ], spatialInfo = { } try : lon_lat_data, spatialInfo = _handle_lon_lat_info (runInfo, aFile, bFile, pathsTemp['out'], - should_make_images = runInfo["shouldIncludeImages"]) + should_make_images = runInfo["shouldIncludeImages"], + fullDPI=runInfo['detail_DPI'], thumbDPI=runInfo['thumb_DPI']) except VariableLoadError, vle : LOG.warn("Error while loading longitude or latitude: ") LOG.warn(vle.msg) @@ -1454,7 +1469,9 @@ def reportGen_library_call (a_path, b_path, var_list=[ ], tupleIndex= varRunInfo['tupleIndex'] if 'tupleIndex' in varRunInfo else None, binName= varRunInfo['binName'] if 'binName' in varRunInfo else 'bin', tupleName= varRunInfo['tupleName'] if 'tupleName' in varRunInfo else 'tuple', - epsilonPercent=varRunInfo['epsilon_percent'] if 'epsilon_percent' in varRunInfo else None) + epsilonPercent=varRunInfo['epsilon_percent'] if 'epsilon_percent' in varRunInfo else None, + fullDPI= runInfo['detail_DPI'], + thumbDPI= runInfo['thumb_DPI']) print("\tfinished creating figures for: " + explanationName) diff --git a/pyglance/glance/filters.py b/pyglance/glance/filters.py index c7ee4aef8de9aa060a9b2ff81d82c2e419a16bbd..55f7973ad81577d2c61fe52514a1ab508ad0fb9a 100644 --- a/pyglance/glance/filters.py +++ b/pyglance/glance/filters.py @@ -259,5 +259,16 @@ def organize_ipopp_data_into_image(original_ipopp_data, wave_number=None, missin return new_data_image +def get_sounding_profile_at_index(profile_data_3d, index_desired) : + """ + Select a level of the sounding profile data at the index given. + For example, if you wanted to select 300 hPa in the pressure profile, you would + enter an index of 64. + """ + + assert(len(profile_data_3d.shape) > 1) + + return profile_data_3d[index_desired].copy() + if __name__=='__main__': sys.exit(main()) \ No newline at end of file diff --git a/pyglance/glance/plot.py b/pyglance/glance/plot.py index b72e5361d072fc62e5ff725fcd2cc6f0f14435dc..8248a2764c9b722cf6bf48ea02aa6c21ae39c259 100644 --- a/pyglance/glance/plot.py +++ b/pyglance/glance/plot.py @@ -35,7 +35,8 @@ thumbSizeDPI = 50 def _handle_fig_creation_task(child_figure_function, log_message, outputPath, fullFigName, - shouldMakeSmall, doFork) : + shouldMakeSmall, doFork, + fullDPI=fullSizeDPI, thumbDPI=thumbSizeDPI) : """ fork to do something. the parent will return the child pid @@ -54,11 +55,11 @@ def _handle_fig_creation_task(child_figure_function, log_message, else : figure = child_figure_function() LOG.info(log_message) - figure.savefig(os.path.join(outputPath, fullFigName), dpi=fullSizeDPI) + figure.savefig(os.path.join(outputPath, fullFigName), dpi=fullDPI) if (shouldMakeSmall) : tempImage = Image.open(os.path.join(outputPath, fullFigName)) - scaleFactor = float(thumbSizeDPI) / float(fullSizeDPI) + scaleFactor = float(thumbDPI) / float(fullDPI) originalSize = tempImage.size newSize = (int(originalSize[0] * scaleFactor), int(originalSize[1] * scaleFactor)) tempImage = tempImage.resize(newSize, Image.ANTIALIAS) @@ -78,7 +79,8 @@ def _handle_fig_creation_task(child_figure_function, log_message, def _log_spawn_and_wait_if_needed (imageDescription, childPids, taskFunction, taskOutputPath, taskFigName, - doMakeThumb=True, doFork=False, shouldClearMemoryWithThreads=False) : + doMakeThumb=True, doFork=False, shouldClearMemoryWithThreads=False, + fullDPI=fullSizeDPI, thumbDPI=thumbSizeDPI) : """ create a figure generation task, spawning a process as needed save the childPid to the list of pids if the process will remain outstanding after this method ends @@ -90,7 +92,8 @@ def _log_spawn_and_wait_if_needed (imageDescription, childPids, pid = _handle_fig_creation_task(taskFunction, "saving image of " + imageDescription, taskOutputPath, taskFigName, - doMakeThumb, doFork or shouldClearMemoryWithThreads) + doMakeThumb, doFork or shouldClearMemoryWithThreads, + fullDPI=fullDPI, thumbDPI=thumbDPI) # wait based on the state of the pid we received and why we would have forked childPid = None @@ -104,7 +107,8 @@ def _log_spawn_and_wait_if_needed (imageDescription, childPids, return def plot_and_save_spacial_trouble(longitudeObject, latitudeObject, spacialTroubleMask, - fileNameDiscriminator, title, fileBaseName, outputPath, makeSmall=False) : + fileNameDiscriminator, title, fileBaseName, outputPath, makeSmall=False, + fullDPI=fullSizeDPI, thumbDPI=thumbSizeDPI) : """ given information on spatially placed trouble points in A and B, plot only those points in a very obvious way on top of a background plot of a's data shown in grayscale, save this plot to the output path given @@ -124,12 +128,12 @@ def plot_and_save_spacial_trouble(longitudeObject, latitudeObject, spacialTroubl title, invalidMask=spaciallyInvalidMask, tagData=spacialTroubleMask) # save the figure LOG.info("Saving spatial trouble image") - spatialTroubleFig.savefig(outputPath + "/" + fileBaseName + "." + fileNameDiscriminator + ".png", dpi=fullSizeDPI) + spatialTroubleFig.savefig(outputPath + "/" + fileBaseName + "." + fileNameDiscriminator + ".png", dpi=fullDPI) # we may also save a smaller versions of the figure if (makeSmall) : - spatialTroubleFig.savefig(outputPath + "/" + fileBaseName + "." + fileNameDiscriminator + ".small.png", dpi=thumbSizeDPI) + spatialTroubleFig.savefig(outputPath + "/" + fileBaseName + "." + fileNameDiscriminator + ".small.png", dpi=thumbDPI) # get rid of the figure spatialTroubleFig.clf() @@ -159,7 +163,8 @@ def plot_and_save_comparison_figures (aData, bData, bUData=None, bVData=None, binIndex=None, tupleIndex=None, binName='bin', tupleName='tuple', - epsilonPercent=None) : + epsilonPercent=None, + fullDPI=None, thumbDPI=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. @@ -312,7 +317,7 @@ def plot_and_save_comparison_figures (aData, bData, # only plot the compared images if we aren't short circuiting them if (outputInfoList is not compared_images) or (not shortCircuitComparisons) : _log_spawn_and_wait_if_needed(figLongDesc, childPids, figFunction, outputPath, figFileName, - makeSmall, doFork, shouldClearMemoryWithThreads) + makeSmall, doFork, shouldClearMemoryWithThreads, fullDPI=fullDPI, thumbDPI=thumbDPI) # if we made an attempt to make the file, hang onto the name outputInfoList.append(figFileName)