Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EHN: Add embargo watermark and message to FITACF plotting methods #355

Merged
merged 5 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 35 additions & 4 deletions pydarn/plotting/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
# 2022-03-23: MTS - added the NotImplementedError for AACGM and GEO projection
# as this has yet to be figured out
# 2023-02-06: CJM - Added option to plot single beams in a scan or FOV diagram
# 2023-03-01: CJM - Added ball and stick plotting options
# 2023-03-01: CJM - Added ball and stick plotting options (merged later in year)
# 2023-08-16: CJM - Corrected for winding order in geo plots
# 2023-06-28: CJM - Refactored return values
# 2023-10-14: CJM - Add embargoed data method
#
# Disclaimer:
# pyDARN is under the LGPL v3 license found in the root directory LICENSE.md
Expand All @@ -42,6 +44,7 @@
import datetime as dt
import matplotlib.pyplot as plt
import numpy as np
import warnings

from matplotlib import ticker, cm, colors, axes
from typing import List, Union
Expand Down Expand Up @@ -194,7 +197,6 @@ def plot_fan(dmap_data: List[dict], ax=None, ranges=None,
# If no records exist, advise user that the channel is not used
if not dmap_data:
raise plot_exceptions.NoChannelError(channel, opt_channel)

# Get the records which match scan_index
if isinstance(scan_index, dt.datetime):
matching_records = find_records_by_datetime(dmap_data, scan_index, tolerance)
Expand Down Expand Up @@ -454,11 +456,14 @@ def plot_fan(dmap_data: List[dict], ax=None, ranges=None,
cb.set_label(colorbar_label)
else:
cb = None

if title:
start_time = time2datetime(matching_records[0])
end_time = time2datetime(matching_records[-1])
title = Fan.__add_title__(start_time, end_time)
ax.set_title(title)
# Determine embargo status
cls.__determine_embargo(time2datetime(dmap_data[plot_beams[-1][-1]])
return {'ax': ax,
'ccrs': ccrs,
'cm': cmap,
Expand All @@ -470,7 +475,7 @@ def plot_fan(dmap_data: List[dict], ax=None, ranges=None,
'ground_scatter': grndsct}
}


@staticmethod
def plot_fov(stid: int, date: dt.datetime,
ax=None, ccrs=None, ranges: List = None, boundary: bool = True,
Expand Down Expand Up @@ -814,7 +819,7 @@ def plot_radar_label(stid: int, ax: axes.Axes,
lat, lon = SuperDARNRadars.radars[stid].mag_label
else:
lat, lon = SuperDARNRadars.radars[stid].geo_label

# Label text
label_str = ' ' + SuperDARNRadars.radars[stid]\
.hardware_info.abbrev.upper()
Expand All @@ -829,7 +834,7 @@ def plot_radar_label(stid: int, ax: axes.Axes,

theta_text = lon
r_text = lat

ax.text(theta_text, r_text, label_str, ha='center',
transform=transform, c=line_color)
return
Expand All @@ -851,3 +856,29 @@ def __add_title__(first_timestamp: dt.datetime,
zfill(2),
end_second=str(end_timestamp.second).zfill(2))
return title

@classmethod
def __determine_embargo(cls, end_time: dt.datetime):
"""
Determines if the data is under the embargo period and
has negative CPID

Parameter
---------
end_time: datetime
"""
year_ago = dt.datetime.now() - dt.timedelta(days=365)
if end_time > year_ago and cls.dmap_data[-1]['cp'] < 0:
fig = plt.gcf()
vals = []
for t in range(0, len(fig.texts)):
vals.append(fig.texts[t].get_text())
if not any(item == 'EMBARGOED' for item in vals):
fig.text(0.5, 0.5, "EMBARGOED", fontsize=70,
color='grey', ha='center', va='center',
rotation=-20, alpha=0.3)
warnings.warn('The data you are using is under embargo. '
'Please contact the principal investigator '
'of the {} radar for authorization to use the '
'data'.format(SuperDARNRadars.radars[
cls.dmap_data[0]['stid']].name))
31 changes: 30 additions & 1 deletion pydarn/plotting/rtp.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# 2022-08-04 Carley Martin added elifs for HALF_SLANT options
# 2023-06-12 Carley Martin added coordinate plotting method
# 2023-06-28 Carley Martin refactored return values
# 2023-10-14 Carley Martin added embargoed data method
#
# Disclaimer:
# pyDARN is under the LGPL v3 license found in the root directory LICENSE.md
Expand Down Expand Up @@ -542,6 +543,7 @@ def plot_range_time(cls, dmap_data: List[dict], parameter: str = 'v',
cb = colorbar
if colorbar_label != '':
cb.set_label(colorbar_label)
cls.__determine_embargo(end_time)
return {'ax': ax,
'ccrs': None,
'cm': cmap,
Expand All @@ -553,7 +555,6 @@ def plot_range_time(cls, dmap_data: List[dict], parameter: str = 'v',
'z': z_data}
}


@classmethod
def plot_time_series(cls, dmap_data: List[dict],
parameter: str = 'tfreq', beam_num: int = 0,
Expand Down Expand Up @@ -840,6 +841,7 @@ def plot_time_series(cls, dmap_data: List[dict],

ax.margins(x=0)
ax.tick_params(axis='y', which='minor')
cls.__determine_embargo(end_time)

return {'ax': ax,
'ccrs': None,
Expand Down Expand Up @@ -1938,3 +1940,30 @@ def __determine_start_end_time(cls, start_time: datetime,
if not end_time:
end_time = time2datetime(cls.dmap_data[-1])
return start_time, end_time

@classmethod
def __determine_embargo(cls, end_time: datetime):
"""
Determines if the data is under the embargo period and
has negative CPID

Parameter
---------
end_time: datetime
"""
year_ago = datetime.now() - timedelta(days=365)
if end_time > year_ago and cls.dmap_data[-1]['cp'] < 0:
fig = plt.gcf()
vals = []
for t in range(0, len(fig.texts)):
vals.append(fig.texts[t].get_text())
if not any(item == 'EMBARGOED' for item in vals):
fig.text(0.5, 0.5, "EMBARGOED", fontsize=70,
color='k', ha='center', va='center',
rotation=-20, alpha=0.5)
warnings.warn('The data you are using is under embargo. '
'Please contact the principal investigator '
'of the {} radar for authorization to use '
'the data.'
.format(SuperDARNRadars.radars[
cls.dmap_data[0]['stid']].name))