From 94e9ca4f1de8a2d19f052408218f174b30b437ee Mon Sep 17 00:00:00 2001 From: Remington Rohel Date: Thu, 10 Oct 2024 17:57:01 +0000 Subject: [PATCH] Fixed bug with terminator plotting behind background pixels --- docs/user/range_time.md | 29 +++++++++++++++-------------- pydarn/plotting/rtp.py | 18 +++++++++++++----- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/docs/user/range_time.md b/docs/user/range_time.md index c9846427..643fc487 100644 --- a/docs/user/range_time.md +++ b/docs/user/range_time.md @@ -96,20 +96,21 @@ plt.show() ### Additional options To see all the customisation options, check out all the parameters listed in 'rtp.py'. A few useful ones: -| Parameter | Action | -|------------------------------|-------------------------------------------------------------| -| start_time=(datetime object) | Control the start time of the plot | -| end_time=(datetime object) | Control the end time of the plot | -| channel=(int or string) | Choose which channel to plot. Default is 'all'. | -| groundscatter=(bool) | True or false to showing ground scatter as grey | -| date_fmt=(string) | How the x-tick labels look. Default is ('%y/%m/%d\n %H:%M') | -| zmin=(int) | Minimum data value to be plotted | -| zmax=(int) | Maximum data value to be plotted | -| range_estimation=(RangeEstimation) | Estaimtion of the distance for the radar to use for the y-axis (See [Ranges, Coords and Projs](coordinates.md)) | -| coords=(Coords) | Used in conjunction with range_estimation, converts the y-axis to a coordinate | -| lat_or_lon=(str) | In conjunction with coords, choose if you would like the latitude ('lat') or longitude ('lon') | -| colorbar=(plt.colorbar) | If you would like a different colorbar than the default | -| colorbar_label=(str) | Set the label fo the colorbar | +| Parameter | Action | +|------------------------------------|-----------------------------------------------------------------------------------------------------------------| +| start_time=(datetime object) | Control the start time of the plot | +| end_time=(datetime object) | Control the end time of the plot | +| channel=(int or string) | Choose which channel to plot. Default is 'all'. | +| groundscatter=(bool) | True or false to showing ground scatter as grey | +| date_fmt=(string) | How the x-tick labels look. Default is ('%y/%m/%d\n %H:%M') | +| zmin=(int) | Minimum data value to be plotted | +| zmax=(int) | Maximum data value to be plotted | +| range_estimation=(RangeEstimation) | Estaimtion of the distance for the radar to use for the y-axis (See [Ranges, Coords and Projs](coordinates.md)) | +| coords=(Coords) | Used in conjunction with range_estimation, converts the y-axis to a coordinate | +| lat_or_lon=(str) | In conjunction with coords, choose if you would like the latitude ('lat') or longitude ('lon') | +| colorbar=(plt.colorbar) | If you would like a different colorbar than the default | +| colorbar_label=(str) | Set the label fo the colorbar | +| terminator=(bool) | Turn on shading of the day-night terminator | For instance, code for a velocity RTP showing the same beam of Clyde river radar as above, but with ground scatter plotted in grey, date format as `hh:mm`, custom min and max values and a colour bar label could look something like: ```python diff --git a/pydarn/plotting/rtp.py b/pydarn/plotting/rtp.py index 4e2b58fc..ae859f77 100644 --- a/pydarn/plotting/rtp.py +++ b/pydarn/plotting/rtp.py @@ -80,7 +80,7 @@ def __str__(self): @classmethod def plot_range_time(cls, dmap_data: List[dict], parameter: str = 'v', beam_num: int = 0, channel: int = 'all', ax=None, - background: str = 'w', background_alpha: float = 1.0, + background: str = 'w', background_alpha: float = 0.0, groundscatter: bool = False, zmin: int = None, zmax: int = None, start_time: datetime = None, end_time: datetime = None, @@ -130,7 +130,7 @@ def plot_range_time(cls, dmap_data: List[dict], parameter: str = 'v', default: white background_alpha : float alpha (transparency) of the background in the plot - default: 1.0 (opaque) + default: 0.0 (transparent) zmin: int Minimum normalized value Default: minimum parameter value in the data set @@ -467,14 +467,18 @@ def plot_range_time(cls, dmap_data: List[dict], parameter: str = 'v', geographic_points = np.flip(geographic_points, axis=1) # [num_times, num_ranges] indicating if the cell is in darkness at that time - is_night = np.zeros((y.shape[0], len(x)), dtype=bool) + is_night = np.zeros_like(time_axis, dtype=np.int8) geodesic = cartopy.geodesic.Geodesic() for i, t in enumerate(x): anti_point, arc_ang, _ = calc_terminator(t, height) distance_to_antisolar_point = geodesic.inverse(anti_point, geographic_points)[:, 0] / 1000.0 # convert to km is_night[:, i] = distance_to_antisolar_point < arc_ang - - ax.pcolormesh(time_axis, y_axis, is_night, cmap=matplotlib.cm.get_cmap('binary'), zorder=0, alpha=0.5) + ax.pcolormesh(time_axis, y_axis, is_night, + cmap=colors.ListedColormap(['white', 'gray']), + zorder=0.5, + vmin=0, + vmax=1, + alpha=0.7) # setup some standard axis information if ymax is None: @@ -903,6 +907,7 @@ def plot_summary(cls, dmap_data: List[dict], latlon: str = None, coords: object = Coords.AACGM, vector_parameters: list = [('p_l'), ('v'), ('w_l'), ('elv')], + terminator: bool = False, **kwargs): """ Plots the summary of several SuperDARN parameters using time-series and @@ -991,6 +996,8 @@ def plot_summary(cls, dmap_data: List[dict], Required parameters for plotting in the summary plot Must be a subset of the default list below default:[('p_l'), ('v'), ('w_l'), ('elv')] + terminator: bool=False + Flag to include the terminator (day/night boundary) and shade the night-side kwargs: reflection_height for ground_scatter_mapped method background @@ -1294,6 +1301,7 @@ def plot_summary(cls, dmap_data: List[dict], yspacing=500, background=background, range_estimation=range_estimation, + terminator=terminator, **kwargs) else: rt_rtn =\