From b97dd70ea4ae3673e97894a6265030983b92d8d0 Mon Sep 17 00:00:00 2001 From: Daniel Cuneo Date: Sat, 28 May 2022 12:32:24 -0700 Subject: [PATCH 1/4] Catch div by zero. --- src/pythonprop/voaFile.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/pythonprop/voaFile.py b/src/pythonprop/voaFile.py index 3f8695c..f03f93e 100644 --- a/src/pythonprop/voaFile.py +++ b/src/pythonprop/voaFile.py @@ -132,6 +132,10 @@ def parse_file(self): elif line.startswith("Gridsize"): self.gridsize = int(line[11:16]) if DEBUG: print("Gridsize = ", self.gridsize) + if self.gridsize < 2: + msg = "Grid size parsed is less than 2 resulting in div by zero." + msg += "\nInput file: {}".format(self.filename) + raise Exception(msg) if int(line[19:20]) in PROJECTION: self.projection = PROJECTION[int(line[19:20])] if DEBUG: print("Projection = ", self.projection) From 9ac670b072b42390e86ab80a9d4ecca5cd803116 Mon Sep 17 00:00:00 2001 From: Daniel Cuneo Date: Sat, 28 May 2022 12:33:04 -0700 Subject: [PATCH 2/4] Use proper cross platform path join. Should be everywhere. May fix an issue with reading proper file that I had earlier. --- src/pythonprop/voacapgui.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pythonprop/voacapgui.py b/src/pythonprop/voacapgui.py index 83f0ffd..ae12b0d 100644 --- a/src/pythonprop/voacapgui.py +++ b/src/pythonprop/voacapgui.py @@ -77,6 +77,8 @@ gettext.textdomain(GETTEXT_DOMAIN) +from os import path + from .voaTextFileViewDialog import VOATextFileViewDialog from .voaDatFile import * from .voaDefaults import * @@ -101,7 +103,7 @@ class VOACAP_GUI(): itshfbc_path = 'C:\itshfbc' prefs_dir = 'C:\itshfbc\database\\' else: - itshfbc_path = os.path.expanduser("~")+os.sep+'itshfbc' + itshfbc_path = path.join(os.path.expanduser("~"), 'itshfbc') prefs_dir = os.path.expanduser("~")+os.sep+'.voacapgui'+os.sep From c310aff59e9fe0f6d0ae0f09c170315cd4858b03 Mon Sep 17 00:00:00 2001 From: Daniel Cuneo Date: Sat, 28 May 2022 12:53:12 -0700 Subject: [PATCH 3/4] If area is not selected, we get div by zero. GUI needs a fix, this is cheap insurance. --- src/pythonprop/voaAreaPlot.py | 38 +++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/pythonprop/voaAreaPlot.py b/src/pythonprop/voaAreaPlot.py index a0bd789..e58bd3a 100644 --- a/src/pythonprop/voaAreaPlot.py +++ b/src/pythonprop/voaAreaPlot.py @@ -21,6 +21,7 @@ # 02110-1301, USA. # +import ipdb import argparse import datetime import gettext @@ -129,7 +130,7 @@ def __init__(self, in_file, if len(points_of_interest) > 0: self.points_of_interest.extend(points_of_interest) """ - + imageBuf = np.zeros([img_grid_size, img_grid_size], float) area_rect = plot_parameters.get_area_rect() @@ -203,19 +204,22 @@ def __init__(self, in_file, cbar_pad=0.2, cbar_size='3%', label_mode='') - + self.main_title_label = fig.suptitle(str(self.image_defs['title']), fontsize=self.main_title_fontsize) - + #for plot_idx, vg_file in enumerate(vg_files): for plot_idx, ax, vg_file in zip(range(number_of_subplots), axgr, vg_files): - + points = np.zeros([img_grid_size,img_grid_size], float) - lons = np.arange(area_rect.get_sw_lon(), area_rect.get_ne_lon()+0.001,(area_rect.get_ne_lon()-area_rect.get_sw_lon())/float(img_grid_size-1)) + ipdb.set_trace() + area_diff = (area_rect.get_ne_lon()-area_rect.get_sw_lon()) + 0.001 + lons = np.arange(area_rect.get_sw_lon(), area_rect.get_ne_lon()+0.001, area_diff/float(img_grid_size-1)) lons[-1] = min(180.0, lons[-1]) - lats = np.arange(area_rect.get_sw_lat(), area_rect.get_ne_lat()+0.001,(area_rect.get_ne_lat()-area_rect.get_sw_lat())/float(img_grid_size-1)) + area_diff = (area_rect.get_ne_lat()-area_rect.get_sw_lat()) + 0.001 + lats = np.arange(area_rect.get_sw_lat(), area_rect.get_ne_lat()+0.001, area_diff/float(img_grid_size-1)) lats[-1] = min(90.0, lats[-1]) #ax.label_outer() @@ -238,12 +242,12 @@ def __init__(self, in_file, vgFile.close() if 'zf' in locals(): zf.close() - + ax.set_extent([area_rect.get_sw_lon(), area_rect.get_ne_lon(), area_rect.get_sw_lat(), area_rect.get_ne_lat()], projection) - + ax.coastlines() lons, lats = np.meshgrid(lons, lats) @@ -269,7 +273,7 @@ def __init__(self, in_file, vmin=self.image_defs['min'], vmax=self.image_defs['max'], transform=projection) - + if plot_nightshade: self.fill_dark_side(ax, time=plot_parameters.get_daynight_datetime(vg_files[plot_idx]-1), @@ -325,18 +329,18 @@ def __init__(self, in_file, title_str = plot_parameters.get_minimal_plot_description_string(vg_files[plot_idx]-1, self.image_defs['plot_type'], time_zone=time_zone) self.subplot_title_label = ax.set_title(title_str) - # Hide any unused subplots + # Hide any unused subplots for ax in axgr[number_of_subplots:]: ax.set_visible(False) axgr.cbar_axes[0].colorbar(im, ticks = self.image_defs['y_labels'], format = mticker.FuncFormatter(eval('self.'+self.image_defs['formatter']))) - + if save_file : - plt.savefig(save_file, - dpi=self.dpi, - facecolor=fig.get_facecolor(), + plt.savefig(save_file, + dpi=self.dpi, + facecolor=fig.get_facecolor(), edgecolor='none') #todo this ought to a command line param @@ -459,7 +463,7 @@ def main(in_file, datadir=None): parser = argparse.ArgumentParser(description="Plot voacap area data") parser.add_argument("in_file", help = _("Path to the .voa file. This should be in the same directory as the associated .vgx files.")) - + parser.add_argument("-c", "--contours", dest = "plot_contours", action = "store_true", @@ -482,7 +486,7 @@ def main(in_file, datadir=None): action="store_true", default=False, help=_("Plot meridians.")) - + parser.add_argument("-k", "--background", dest="face_colour", default='white', @@ -600,7 +604,7 @@ def main(in_file, datadir=None): except: print(_("Error reading vg files, resetting to '1'")) vg_files = [1] - + if args.timezone: time_zone = int(args.timezone) if time_zone > 12: time_zone = 0 From 743a331621221fef8a587699d33a256f3772b85c Mon Sep 17 00:00:00 2001 From: Daniel Cuneo Date: Sat, 28 May 2022 13:10:12 -0700 Subject: [PATCH 4/4] Some hints on how to start the gui from ipython terminal. --- DEVNOTES.txt | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 DEVNOTES.txt diff --git a/DEVNOTES.txt b/DEVNOTES.txt new file mode 100644 index 0000000..c7708d3 --- /dev/null +++ b/DEVNOTES.txt @@ -0,0 +1,6 @@ +cd pythonprop/src +ipython +import sys +from pythonprop import voacapgui +voacapgui.main(sys.argv, datadir='/usr/local/share/pythonprop') +