The Plotter class#
What it does#
The Plotter class intends to provide easy and hands-on methods to plot results from simulation produced by Watlab. For example we provide a simple way to plot a result extracted from a so-called watlab pic file or to create a video from a folder containing results files. These methods should be modified by the users in order to meet their expectations.
Documentation#
- class watlab.watlab.Plotter(mesh: Mesh)#
The Plotter class provides basic tools to the user. Methods that allow to plot the data accross a line, or to generate a video are available. The class is intended to be used combined with the MatPlotLib library.
- create_video(pic_path_template, video_filename, time_step, variable_name: str, opacity=1, colorbar_values=None, csr=31370, fps=5, on_map=False)#
Creates a video from a sequence of image files, with options to overlay data on a map.
- Parameters:
pic_path_template (str) – The template for the file paths of the images. Example: “PathToFiles/pic_{:d}_{:02d}.txt”
video_filename (str) – The name of the output video file.
time_step (int) – The time interval between consecutive images.
variable_name (str, optional) – The name of the variable to plot. Select the desired variable in the output file.
opacity (float, optional) – A value between 0 and 1 to set the opacity of the plot. Defaults to 1.
colorbar_values (list, optional) – The boundary valeus for the colorbar. Defaults to None, which automatically scales based on data range.
csr (int, optional) – The coordinate reference system for the map. Defaults to 31370, which is used in Belgium.
fps (int, optional) – Frames per second for the video. Defaults to 5.
on_map (bool, optional) – If True, the images will be plotted on a map. Defaults to False.
- plot(picture_file_path, variable_name: str, opacity=1, colorbar_values=None)#
Plots the specified variable from the provided picture file with various customization options.
Interaction: - Press ‘m’ to display the mesh overlay on the plot. - Press ‘d’ and left-click on two different locations to draw a line between them, which will trigger a pop-up displaying a profile cut along the selected line.
- Parameters:
picture_file_path (str) – The path to the image file to be plotted.
variable_name (str (as stated in the head of the pic file)) – The name of the variable to plot. Select the desired variable in the output file.
opacity (float, optional) – A value between 0 and 1 to set the opacity of the plot. Defaults to 1.
colorbar_values (list, optional) – The boundary valeus for the colorbar. Defaults to None, which automatically scales based on data range.
- Raises:
ValueError – If the contour lines are not in increasing order, a ValueError will be caught and handled internally.
- plot_on_map(pic_path, variable_name: str, opacity=0.5, colorbar_values=None, csr=31370)#
Plots the specified variable on a map using a specified coordinate reference system.
- Parameters:
pic_path (str) – The path to the image file containing the data to plot.
variable_name (str, optional) – The name of the variable to plot. Select the desired variable in the output file.
opacity (float, optional) – A value between 0 and 1 to set the opacity of the plot. Defaults to 0.5.
colorbar_values (list, optional) – The boundary valeus for the colorbar. Defaults to None, which automatically scales based on data range.
csr (int, optional) – The coordinate reference system for the map. Defaults to 31370, which is used in Belgium.
- plot_profile_along_line(picture_file_path: str, variable_name: str, x_coordinate=None, y_coordinate=None, new_fig=False, n_points=50, label='') None #
Plots the profile of the selected variable along a line defined by given coordinate points.
- Parameters:
picture_file_path (str) – The path to the image file containing the data to plot.
x_coordinate (list or np.ndarray) – A list or array of x-coordinates defining the line segment. Example: [x_P1, x_P2]
y_coordinate (list or np.ndarray) – A list or array of y-coordinates defining the line segment. Example: [y_P1, y_P2]
new_fig (bool, optional) – If True, creates a new figure for the plot. If False, plots on the current figure. Defaults to False.
variable_name (str) – The name of the variable to plot.
n_points (int, optional) – The number of interpolation points along the line. Defaults to 50.
label (str, optional) – The label for the plot. Defaults to an empty string “”.
- show_velocities(picture_file_path, velocities_tags=['qx', 'qy'], relative_depth_tag='h', velocity_ds=1, scale=1)#
Plots the velocity field on a 2D plane using quiver arrows
- Parameters:
picture_file_path (str) – The path to the file containing the velocity data.
velocities_tags (list of str, optional) – A list of keys representing the velocity components in the output file. The default is [“qx”, “qy”] where “qx” is the x-component and “qy” is the y-component.
relative_depth_tag (str, optional) – The key representing the relative depth (e.g., water height) in the data file. Defaults to “h”.
velocity_ds (float, optional) – Downsampling factor for the velocity vectors. A value between 0 and 1 that determines the percentage of arrows displayed. Defaults to 1 (no downsampling).
scale (float, optional) – Scale factor to adjust the length of the velocity arrows. Defaults to 1.