Skip to content

plotmpl

Bo Chen edited this page Jul 9, 2023 · 4 revisions

plotmpl

This code consists of functions for lidar data analysis and visualization. It includes functionalities for reading lidar data, calculating derived products, and plotting 2D timeseries.

Functions

plot_mpl_2d_timeseries(mpl_datetime, mpl_range_edges, mpl_2d_data, fig=None, ax=None, range_max=20, vmin=0, vmax=1, colorbar_bool=True, tick_number=None)

Plots a 2D timeseries of lidar data.

Parameters:

  • mpl_datetime: Array of np.datetime64 objects representing the timestamps.
  • mpl_range_edges: Array of lidar range values. Height of the bottom and top of each bin instead of the average height of the bin.
  • mpl_2d_data: 2D array of lidar data.
  • fig (optional): Existing figure object for plotting.
  • ax (optional): Existing axes object for plotting.
  • range_max (optional): Maximum range in km to plot on the y-axis.
  • vmin (optional): Minimum value for the colormap normalization.
  • vmax (optional): Maximum value for the colormap normalization.
  • colorbar_bool (optional): Boolean value to enable/disable the colorbar.
  • tick_number (optional): Number of ticks and labels to use on the x-axis.

Returns:

  • None (The function directly modifies the provided fig and ax objects for plotting.)

_get_fig_and_ax(fig, ax)

Utility function to handle the creation of a figure and axes for plotting.

Parameters:

  • fig (optional): Existing figure object.
  • ax (optional): Existing axes object.

Returns:

  • fig: Updated figure object.
  • ax: Updated axes object.

_format_datetime(datetime_arr)

Helper function to format an array of datetime objects.

Parameters:

  • datetime_arr: Array of datetime objects representing timestamps.

Returns:

  • formatted_arr: Array of formatted strings representing the formatted dates and times.

Example Usage

Here's an example usage of the plot_mpl_2d_timeseries function:

from pympl import PyMPL
import plotmpl
import matplotlib.pyplot as plt
import numpy as np

mpl_file_path = '/Users/bochen/TAMU/mpl-py/test'
ap_file_path = '/Users/bochen/TAMU/tamu_tracer/tracer_data/MPL_config_files/MMPL5051_Afterpulse_202302161704_15m_energy_fixed.bin'
ov_file_path = '/Users/bochen/TAMU/tamu_tracer/tracer_data/MPL_config_files/MMPL5051_Overlap_202302211516_15m_energy_fixed.bin'
dt_file_path = '/Users/bochen/TAMU/tamu_tracer/tracer_data/MPL_config_files/MMPL5051_SPCM34394_Deadtime11.bin'

mpl_object = PyMPL(mpl_file_path, ap_file_path, ov_file_path, dt_file_path)
mpl_object.interpolate_data(np.datetime64('YYYY-MM-DDThh:mm'),np.datetime64('YYYY-MM-DDThh:mm'),60)

fig0, ax0 = plt.subplots(nrows=1, ncols=1, figsize=(10,4))
plotmpl.plot_mpl_2d_timeseries(mpl_object.datetime, mpl_object.range_edges, mpl_object.nrb_copol, fig=fig0, ax=ax0, range_max = 5, vmin=0, vmax=1)
ax0.set_title('copol nrb')

fig1, ax1 = plt.subplots(nrows=1, ncols=1, figsize=(10,4))
plotmpl.plot_mpl_2d_timeseries(mpl_object.interpolated_datetime, mpl_object.range_edges, mpl_object.interpolated_nrb_copol, fig=fig1, ax=ax1, range_max = 5, vmin=0, vmax=1, color_map = plotmpl.lidar_gist)
ax1.set_title('interpolated copol nrb')

plt.show()

Clone this wiki locally