Skip to content

Commit

Permalink
sideview can use mscolab
Browse files Browse the repository at this point in the history
  • Loading branch information
ReimarBauer committed Nov 5, 2024
1 parent a2e4f5e commit 7fe8a97
Showing 1 changed file with 53 additions and 58 deletions.
111 changes: 53 additions & 58 deletions mslib/utils/mssautoplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down Expand Up @@ -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']
Expand All @@ -333,21 +337,23 @@ 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)
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
Expand Down Expand Up @@ -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,
Expand All @@ -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):
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 7fe8a97

Please sign in to comment.