From 7fe8a97a8ddab5f7cd5a3579f78869a83feba950 Mon Sep 17 00:00:00 2001 From: ReimarBauer Date: Tue, 5 Nov 2024 18:16:44 +0100 Subject: [PATCH 1/3] sideview can use mscolab --- mslib/utils/mssautoplot.py | 111 ++++++++++++++++++------------------- 1 file changed, 53 insertions(+), 58 deletions(-) diff --git a/mslib/utils/mssautoplot.py b/mslib/utils/mssautoplot.py index 3ac186411..e45f12a05 100644 --- a/mslib/utils/mssautoplot.py +++ b/mslib/utils/mssautoplot.py @@ -238,6 +238,32 @@ def __init__(self, cpath, msc_url=None, msc_auth_password=None, username=None, p raise SystemExit("Filename {} doesn't exist".format(filename)) self.read_ftml(filename) + def update_path(self, filename=None): + """ + Update the path by reading the FTML data from the given filename + and redrawing the path based on the updated waypoints model data. + + Parameters: + :filename: The name of the file to read FTML data from. + + Returns: + None + """ + # plot path and label + if filename != "": + self.read_ftml(filename) + self.fig.canvas.draw() + self.plotter.update_from_waypoints(self.wp_model_data) + self.plotter.redraw_path(waypoints_model_data=self.wp_model_data) + + def update_path_ops(self, filename=None): + # plot path and label + if filename != "": + self.read_operation(filename, self.url, self.msc_auth, self.username, self.password) + self.fig.canvas.draw() + self.plotter.update_from_waypoints(self.wp_model_data) + self.plotter.redraw_path(waypoints_model_data=self.wp_model_data) + def read_ftml(self, filename): self.wps, self.wp_model_data = load_from_ftml(filename) self.wp_lats, self.wp_lons, self.wp_locs = [[x[i] for x in self.wps] for i in [0, 1, 3]] @@ -278,37 +304,15 @@ def __init__(self, cpath, msc_url, msc_auth_password, msc_username, msc_password self.msc_auth = msc_auth_password self.url = msc_url - def update_path(self, filename=None): - """ - Update the path by reading the FTML data from the given filename - and redrawing the path based on the updated waypoints model data. - - Parameters: - :filename: The name of the file to read FTML data from. - - Returns: - None - """ - # plot path and label - if filename != "": - self.read_ftml(filename) - self.fig.canvas.draw() - self.plotter.update_from_waypoints(self.wp_model_data) - self.plotter.redraw_path(waypoints_model_data=self.wp_model_data) - - def update_path_ops(self, filename=None): - # plot path and label - if filename != "": - self.read_operation(filename, self.url, self.msc_auth, self.username, self.password) - self.fig.canvas.draw() - self.plotter.update_from_waypoints(self.wp_model_data) - self.plotter.redraw_path(waypoints_model_data=self.wp_model_data) - def draw(self, flight, section, vertical, filename, init_time, time, url, layer, style, elevation, no_of_plots): if filename != "" and filename == flight: self.update_path_ops(filename) elif filename != "": - self.update_path(filename) + try: + self.update_path(filename) + except AttributeError as e: + logging.debug(e) + raise SystemExit("No FLIGHT Selected") width, height = self.myfig.get_plot_size_in_px() self.bbox = self.params['basemap'] @@ -333,7 +337,7 @@ def draw(self, flight, section, vertical, filename, init_time, time, url, layer, wms = MSUIWebMapService(url, username=auth_username, password=auth_password, - version='1.3.0') + version='1.1.1') img = wms.getmap(**kwargs) image_io = io.BytesIO(img.read()) @@ -341,13 +345,15 @@ def draw(self, flight, section, vertical, filename, init_time, time, url, layer, self.myfig.draw_image(img) t = str(time) date_time = re.sub(r'\W+', '', t) - self.myfig.fig.savefig(f"{flight}_{layer}_{section}_{date_time}_{no_of_plots}_{elevation}.png") + filename = f"{flight}_{layer}_{section}_{date_time}_{no_of_plots}_{elevation}.png" + self.myfig.fig.savefig(filename) + print(f"The image is saved at: {os.getcwd()}/{filename}") class SideViewPlotting(Plotting): def __init__(self, cpath, msc_url, msc_auth_password, msc_username, msc_password, pdlg): # ToDo Implement access to MSColab - super(SideViewPlotting, self).__init__(cpath, msc_url, msc_auth_password, msc_username, msc_password) + super(SideViewPlotting, self).__init__(cpath, msc_url, msc_auth_password, msc_username, msc_password, pdlg) self.pdlg = pdlg self.myfig = qt.SideViewPlotter() self.ax = self.myfig.ax @@ -375,32 +381,15 @@ def setup(self): times_visible = False self.myfig.redraw_xaxis(self.lats, self.lons, times, times_visible) - def update_path(self, filename=None): - self.setup() - if filename is not None: - self.read_ftml(filename) - self.fig.canvas.draw() - self.plotter.update_from_waypoints(self.wp_model_data) - indices = list(zip(self.intermediate_indexes, self.wp_press)) - self.plotter.redraw_path(vertices=indices, - waypoints_model_data=self.wp_model_data) - highlight = [[wp[0], wp[1]] for wp in self.wps] - self.myfig.draw_vertical_lines(highlight, self.lats, self.lons) - - def update_path_ops(self, filename=None): - # plot path and label - if filename != "": - self.read_operation(filename, self.url, self.msc_auth, self.username, self.password) - self.fig.canvas.draw() - self.plotter.update_from_waypoints(self.wp_model_data) - self.plotter.redraw_path(waypoints_model_data=self.wp_model_data) - def draw(self, flight, section, vertical, filename, init_time, time, url, layer, style, elevation, no_of_plots): - try: - self.update_path(filename) - except AttributeError as e: - logging.debug(e) - raise SystemExit("No FLIGHT Selected") + if filename != "" and filename == flight: + self.update_path_ops(filename) + elif filename != "": + try: + self.update_path(filename) + except AttributeError as e: + logging.debug(e) + raise SystemExit("No FLIGHT Selected") width, height = self.myfig.get_plot_size_in_px() p_bot, p_top = [float(x) * 100 for x in vertical.split(",")] self.bbox = tuple([x for x in (self.num_interpolation_points, @@ -425,14 +414,15 @@ def draw(self, flight, section, vertical, filename, init_time, time, url, layer, wms = MSUIWebMapService(url, username=auth_username, password=auth_password, - version='1.3.0') + version='1.1.1') img = wms.getmap(**kwargs) - image_io = io.BytesIO(img.read()) img = PIL.Image.open(image_io) + filename = f"{flight}_{layer}_{no_of_plots}.png" self.myfig.draw_image(img) - self.myfig.fig.savefig(f"{flight}_{layer}_{no_of_plots}.png", bbox_inches='tight') + self.myfig.fig.savefig(filename, bbox_inches='tight') + print(f"The image is saved at: {os.getcwd()}/{filename}") class LinearViewPlotting(Plotting): @@ -524,6 +514,8 @@ def draw(self): @click.option('--etime', default="", help='Ending time for downloading multiple plots with a fixed interval.') @click.pass_context def main(ctx, cpath, view, ftrack, itime, vtime, intv, stime, etime): + pdlg = None + def close_process_dialog(pdlg): pdlg.close() @@ -575,6 +567,9 @@ def draw(no_of_plots): elif view == "side": side_view.draw(flight, section, vertical, filename, init_time, time, url, layer, style, elevation, no_of_plots=no_of_plots) + else: + print("View is not available, Plot not created!") + return False except Exception as e: if "times" in str(e): print("Invalid times and/or levels requested") From 7977280b84084672abd27d6181e3fafd21f1b0ea Mon Sep 17 00:00:00 2001 From: ReimarBauer Date: Fri, 8 Nov 2024 14:02:41 +0100 Subject: [PATCH 2/3] added mscolab for sideview --- mslib/utils/mssautoplot.py | 54 +++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/mslib/utils/mssautoplot.py b/mslib/utils/mssautoplot.py index e45f12a05..adc22f781 100644 --- a/mslib/utils/mssautoplot.py +++ b/mslib/utils/mssautoplot.py @@ -238,6 +238,9 @@ def __init__(self, cpath, msc_url=None, msc_auth_password=None, username=None, p raise SystemExit("Filename {} doesn't exist".format(filename)) self.read_ftml(filename) + def setup(self): + pass + def update_path(self, filename=None): """ Update the path by reading the FTML data from the given filename @@ -257,6 +260,7 @@ def update_path(self, filename=None): self.plotter.redraw_path(waypoints_model_data=self.wp_model_data) def update_path_ops(self, filename=None): + self.setup() # plot path and label if filename != "": self.read_operation(filename, self.url, self.msc_auth, self.username, self.password) @@ -304,6 +308,9 @@ def __init__(self, cpath, msc_url, msc_auth_password, msc_username, msc_password self.msc_auth = msc_auth_password self.url = msc_url + def setup(self): + pass + def draw(self, flight, section, vertical, filename, init_time, time, url, layer, style, elevation, no_of_plots): if filename != "" and filename == flight: self.update_path_ops(filename) @@ -334,6 +341,7 @@ def draw(self, flight, section, vertical, filename, init_time, time, url, layer, } auth_username, auth_password = get_auth_from_url_and_name(url, self.config["MSS_auth"]) + # bbox for 1.3.0 needs a fix, swapped order wms = MSUIWebMapService(url, username=auth_username, password=auth_password, @@ -352,7 +360,6 @@ def draw(self, flight, section, vertical, filename, init_time, time, url, layer, class SideViewPlotting(Plotting): def __init__(self, cpath, msc_url, msc_auth_password, msc_username, msc_password, pdlg): - # ToDo Implement access to MSColab super(SideViewPlotting, self).__init__(cpath, msc_url, msc_auth_password, msc_username, msc_password, pdlg) self.pdlg = pdlg self.myfig = qt.SideViewPlotter() @@ -381,6 +388,41 @@ def setup(self): times_visible = False self.myfig.redraw_xaxis(self.lats, self.lons, times, times_visible) + def update_path(self, filename=None): + """ + Update the path by reading the FTML data from the given filename + and redrawing the path based on the updated waypoints model data. + + Parameters: + :filename: The name of the file to read FTML data from. + + Returns: + None + """ + # plot path and label + if filename != "": + self.read_ftml(filename) + self.fig.canvas.draw() + self.plotter.update_from_waypoints(self.wp_model_data) + indices = list(zip(self.intermediate_indexes, self.wp_press)) + self.plotter.redraw_path(vertices=indices, + waypoints_model_data=self.wp_model_data) + highlight = [[wp[0], wp[1]] for wp in self.wps] + self.myfig.draw_vertical_lines(highlight, self.lats, self.lons) + + def update_path_ops(self, filename=None): + self.setup() + # plot path and label + if filename != "": + self.read_operation(filename, self.url, self.msc_auth, self.username, self.password) + self.fig.canvas.draw() + self.plotter.update_from_waypoints(self.wp_model_data) + indices = list(zip(self.intermediate_indexes, self.wp_press)) + self.plotter.redraw_path(vertices=indices, + waypoints_model_data=self.wp_model_data) + highlight = [[wp[0], wp[1]] for wp in self.wps] + self.myfig.draw_vertical_lines(highlight, self.lats, self.lons) + def draw(self, flight, section, vertical, filename, init_time, time, url, layer, style, elevation, no_of_plots): if filename != "" and filename == flight: self.update_path_ops(filename) @@ -410,16 +452,22 @@ def draw(self, flight, section, vertical, filename, init_time, time, url, layer, "format": "image/png", "size": (width, height) } + auth_username, auth_password = get_auth_from_url_and_name(url, self.config["MSS_auth"]) + # bbox for sideview is correct wms = MSUIWebMapService(url, username=auth_username, password=auth_password, - version='1.1.1') + version='1.3.0') img = wms.getmap(**kwargs) image_io = io.BytesIO(img.read()) img = PIL.Image.open(image_io) - filename = f"{flight}_{layer}_{no_of_plots}.png" + filename = f"{flight}_{layer}_{time}_{no_of_plots}.png" + self.myfig.setup_side_view() + self.myfig.draw_image(img) + self.ax.set_title(f"{flight}: {layer} \n{time} {no_of_plots}", horizontalalignment="left", x=0) + self.myfig.redraw_xaxis(self.lats, self.lons, None, False) self.myfig.draw_image(img) self.myfig.fig.savefig(filename, bbox_inches='tight') print(f"The image is saved at: {os.getcwd()}/{filename}") From b8cf060620a084361d7eb11f8c986f94f6fc15c6 Mon Sep 17 00:00:00 2001 From: ReimarBauer Date: Fri, 8 Nov 2024 16:50:38 +0100 Subject: [PATCH 3/3] slugify added --- mslib/utils/mssautoplot.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mslib/utils/mssautoplot.py b/mslib/utils/mssautoplot.py index adc22f781..933e2f61a 100644 --- a/mslib/utils/mssautoplot.py +++ b/mslib/utils/mssautoplot.py @@ -40,6 +40,7 @@ import defusedxml.ElementTree as etree import PIL.Image import matplotlib +from slugify import slugify from fs import open_fs import mslib @@ -353,9 +354,9 @@ def draw(self, flight, section, vertical, filename, init_time, time, url, layer, self.myfig.draw_image(img) t = str(time) date_time = re.sub(r'\W+', '', t) - filename = f"{flight}_{layer}_{section}_{date_time}_{no_of_plots}_{elevation}.png" - self.myfig.fig.savefig(filename) - print(f"The image is saved at: {os.getcwd()}/{filename}") + plot_filename = slugify(f"{flight}_{layer}_{section}_{date_time}_{no_of_plots}_{elevation}") + ".png" + self.myfig.fig.savefig(plot_filename) + print(f"The image is saved at: {os.getcwd()}/{plot_filename}") class SideViewPlotting(Plotting): @@ -463,14 +464,14 @@ def draw(self, flight, section, vertical, filename, init_time, time, url, layer, img = wms.getmap(**kwargs) image_io = io.BytesIO(img.read()) img = PIL.Image.open(image_io) - filename = f"{flight}_{layer}_{time}_{no_of_plots}.png" + plot_filename = slugify(f"{flight}_{layer}_{time}_{no_of_plots}") + ".png" self.myfig.setup_side_view() self.myfig.draw_image(img) self.ax.set_title(f"{flight}: {layer} \n{time} {no_of_plots}", horizontalalignment="left", x=0) self.myfig.redraw_xaxis(self.lats, self.lons, None, False) self.myfig.draw_image(img) - self.myfig.fig.savefig(filename, bbox_inches='tight') - print(f"The image is saved at: {os.getcwd()}/{filename}") + self.myfig.fig.savefig(plot_filename, bbox_inches='tight') + print(f"The image is saved at: {os.getcwd()}/{plot_filename}") class LinearViewPlotting(Plotting):