Skip to content

Commit

Permalink
Merge branch 'master' of github.com:SuperDARN/pydarn
Browse files Browse the repository at this point in the history
  • Loading branch information
mts299 committed Feb 23, 2021
2 parents 9d4b645 + 52a7c9d commit 3fc370f
Show file tree
Hide file tree
Showing 15 changed files with 155 additions and 140 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/flake8PR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ jobs:
pip3 install flake8
pip3 install --upgrade flake8
# stop the build if there are Python syntax errors or undefined names
flake8 --exit-zero
flake8 --exit-zero --ignore=E501
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Python data visualization library for the Super Dual Auroral Radar Network (Supe
pyDARN release v2.0includes the following features:
- Integration with pyDARNio to read files
- Updates to Hardware utility
- **Fan Plots**
- **Fan Plots** with transparent fix
- **Statistical Power Plots**
- Slant range option for plotting
- getting beam/gate geographic/geomagnetic locations
Expand Down
5 changes: 5 additions & 0 deletions pydarn/exceptions/plot_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ def __init__(self, parameter: str, beam_num: int, opt_beam_num: int,
"".format(beam_num=self.beam_num,
parameter=self.parameter,
opt_beam=self.opt_beam_num,
start_time=self.start_time.strftime("%Y %m"
" %d %H"
":%M"),
end_time=self.end_time.strftime("%Y %m"
" %d %H:%M"),
parameter_value=opt_parameter_value)

super().__init__(self.message)
Expand Down
1 change: 0 additions & 1 deletion pydarn/exceptions/rtp_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright (C) SuperDARN Canada, Universtiy of Saskatchewan
# Authors: Marina Schmidt
import logging
import datetime

pydarn_log = logging.getLogger('pydarn')

Expand Down
8 changes: 4 additions & 4 deletions pydarn/exceptions/warning_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# Disclaimer: pyDARN is licensed under the GPL v 3.0 found in LICENSE
#


def standard_warning_format(message: str, category: str, filename: str,
lineno: int, file: str = None,
line: int = None) -> str:
Expand Down Expand Up @@ -61,7 +62,6 @@ def only_message_warning_format(message: str, category: str, filename: str,
-------
formatted warning message to be printed to the console
"""
return "{category}: {message}\n".format(filename=filename,
linenum=lineno,
category=category.__name__,
message=message)
return "{filename} {linenum} {category}: {message}\n"\
"".format(filename=filename, linenum=lineno,
category=category.__name__, message=message)
6 changes: 3 additions & 3 deletions pydarn/io/superdarn_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SuperDARNRead(pydarnio.SDarnRead):
Methods
-------
read_dmap : reads superDARN DMap formats
read_borealis: Reads Borealis hdf5 formats and converts
read_borealis: Reads Borealis hdf5 formats and converts
Borealis' data dictionary to SDARN data dictionary
"""
def __init__(self, filename: str = None, stream: bool = False):
Expand Down Expand Up @@ -83,8 +83,8 @@ def read_borealis(self, filename: str, slice_id: int = None):
string name of the file, make sure "rawacf" or "bfiq" is in
the name
slice_id: int
the Borealis slice id of the file, required if reading Borealis data
produced prior to when Borealis v0.5 was released
the Borealis slice id of the file, required if reading Borealis
data produced prior to when Borealis v0.5 was released
Post
----
Expand Down
14 changes: 7 additions & 7 deletions pydarn/plotting/acf.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,11 @@ def plot_acfs(cls, dmap_data: List[dict], beam_num: int = 0,
break
scan_count += 1
if record['cp'] == 503:
warnings.warn("Please note that this data is from Tauscan which has "
"different lag properties compared to other control "
"programs. The ACF plot may not be correct. "
"Please contact the PI of the radar to "
"confirm if the data looks correct.")
warnings.warn("Please note that this data is from Tauscan "
"which has different lag properties compared "
"to other control programs. The ACF plot may "
"not be correct. Please contact the PI of the "
"radar to confirm if the data looks correct.")
if re == [] or im == []:
if gate_num > 0 and gate_num < record['nrang']:
time = time2datetime(record)
Expand Down Expand Up @@ -262,6 +262,7 @@ def plot_acfs(cls, dmap_data: List[dict], beam_num: int = 0,
" https://zenodo.org/record/3978643. Citing information"
" for SuperDARN data is found at"
" https://pydarn.readthedocs.io/en/master/user/citing/")

@classmethod
def __found_scan(cls, scan_num: int, count_num: int,
start_time: datetime, time: datetime):
Expand All @@ -287,14 +288,13 @@ def __found_scan(cls, scan_num: int, count_num: int,
else False
"""
if start_time is None:
if scan_num==count_num:
if scan_num == count_num:
return True
elif start_time < time:
return True

return False


@classmethod
def __blanked_lags(cls, record: dict, lags: list, gate: int):
"""
Expand Down
82 changes: 44 additions & 38 deletions pydarn/plotting/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
# document, but changing it is not allowed.
#
# This version of the GNU Lesser General Public License incorporates the terms
# and conditions of version 3 of the GNU General Public License, supplemented by
# the additional permissions listed below.
# and conditions of version 3 of the GNU General Public License,
# supplemented by the additional permissions listed below.


"""
Expand All @@ -20,7 +20,6 @@
import datetime as dt
import matplotlib.pyplot as plt
import numpy as np
import os

from matplotlib import ticker, cm, colors
from typing import List
Expand All @@ -30,6 +29,7 @@

from pydarn import PyDARNColormaps, build_scan, radar_fov


class Fan():
"""
Fan plots for SuperDARN data
Expand All @@ -47,22 +47,25 @@ def __str__(self):

@classmethod
def plot_fan(cls, dmap_data: List[dict], ax=None, scan_index: int = 1,
ranges: List = [0,75], boundary: bool = True,
parameter: str = 'v', lowlat: int = 30, cmap: str = None,
groundscatter: bool = False,
zmin: int = None, zmax: int = None,
colorbar: bool = True,
colorbar_label: str = ''):
ranges: List = [0, 75], boundary: bool = True,
parameter: str = 'v', lowlat: int = 30,
cmap: str = None, groundscatter: bool = False,
zmin: int = None, zmax: int = None,
colorbar: bool = True,
colorbar_label: str = ''):
"""
Plots a radar's Field Of View (FOV) fan plot for the given data and scan number
Plots a radar's Field Of View (FOV)
fan plot for the given data and scan number
Parameters
-----------
dmap_data: List[dict]
Named list of dictionaries obtained from SDarn_read
ax: matplotlib.pyplot axis
Pre-defined axis object to pass in, must currently be polar projection
Default: Generates a polar projection for the user with MLT/latitude labels
Pre-defined axis object to pass in,
must currently be polar projection
Default: Generates a polar projection for
the user with MLT/latitude labels
scan_index: int
Scan number from beginning of first record in file
Default: 1
Expand Down Expand Up @@ -95,7 +98,8 @@ def plot_fan(cls, dmap_data: List[dict], ax=None, scan_index: int = 1,
Draw a colourbar if True
Default: True
colorbar_label: str
the label that appears next to the colour bar. Requires colorbar to be true
the label that appears next to the colour bar.
Requires colorbar to be true
Default: ''
Returns
-----------
Expand All @@ -104,32 +108,33 @@ def plot_fan(cls, dmap_data: List[dict], ax=None, scan_index: int = 1,
beam_corners_aacgm_lons
n_beams x n_gates numpy array of AACGMv2 longitudes
scan
n_beams x n_gates numpy array of the scan data (for the selected parameter)
n_beams x n_gates numpy array of the scan data
(for the selected parameter)
grndsct
n_beams x n_gates numpy array of the scan data (for the selected parameter)
n_beams x n_gates numpy array of the scan data
(for the selected parameter)
dtime
datetime object for the scan plotted
"""

my_path = os.path.abspath(os.path.dirname(__file__))
base_path = os.path.join(my_path, '..')

# Get scan numbers for each record
beam_scan=build_scan(dmap_data)
beam_scan = build_scan(dmap_data)

# Locate scan in loaded data
plot_beams = np.where(beam_scan == scan_index)

# Time for coordinate conversion
dtime = dt.datetime(dmap_data[plot_beams[0][0]]['time.yr'],
dmap_data[plot_beams[0][0]]['time.mo'], dmap_data[plot_beams[0][0]]['time.dy'],
dmap_data[plot_beams[0][0]]['time.hr'], dmap_data[plot_beams[0][0]]['time.mt'],
dmap_data[plot_beams[0][0]]['time.mo'],
dmap_data[plot_beams[0][0]]['time.dy'],
dmap_data[plot_beams[0][0]]['time.hr'],
dmap_data[plot_beams[0][0]]['time.mt'],
dmap_data[plot_beams[0][0]]['time.sc'])

# Get radar beam/gate locations
beam_corners_aacgm_lats, beam_corners_aacgm_lons=radar_fov(dmap_data[0]['stid'],
coords='aacgm', date=dtime)
beam_corners_aacgm_lats, beam_corners_aacgm_lons = \
radar_fov(dmap_data[0]['stid'], coords='aacgm', date=dtime)
fan_shape = beam_corners_aacgm_lons.shape

# Work out shift due in MLT
Expand All @@ -144,11 +149,13 @@ def plot_fan(cls, dmap_data: List[dict], ax=None, scan_index: int = 1,

# Get range-gate data and groundscatter array for given scan
scan = np.zeros((fan_shape[0] - 1, fan_shape[1]-1))
grndsct = np.zeros((fan_shape[0] - 1, fan_shape[1]-1)) #initialise arrays
grndsct = np.zeros((fan_shape[0] - 1, fan_shape[1]-1))
for i in np.nditer(plot_beams):
try:
slist = dmap_data[i.astype(int)]['slist'] #get a list of gates where there is data
beam = dmap_data[i.astype(int)]['bmnum'] #get the beam number for the record
# get a list of gates where there is data
slist = dmap_data[i.astype(int)]['slist']
# get the beam number for the record
beam = dmap_data[i.astype(int)]['bmnum']
scan[slist, beam] = dmap_data[i.astype(int)][parameter]
grndsct[slist, beam] = dmap_data[i.astype(int)]['gflg']
# if there is no slist field this means partial record
Expand All @@ -157,8 +164,6 @@ def plot_fan(cls, dmap_data: List[dict], ax=None, scan_index: int = 1,

# Colour table and max value selection depending on parameter plotted
# Load defaults if none given
# TODO: use cmaps as over writting cmap is bad practice...
# did I do that in my code ... hmm
if cmap is None:
cmap = {'p_l': 'plasma', 'v': PyDARNColormaps.PYDARN_VELOCITY,
'w_l': PyDARNColormaps.PYDARN_VIRIDIS,
Expand All @@ -177,7 +182,7 @@ def plot_fan(cls, dmap_data: List[dict], ax=None, scan_index: int = 1,
# This may screw up references
if ax is None:
ax = plt.axes(polar=True)
if beam_corners_aacgm_lats[0,0] > 0:
if beam_corners_aacgm_lats[0, 0] > 0:
ax.set_ylim(90, lowlat)
ax.set_yticks(np.arange(lowlat, 90, 10))
else:
Expand All @@ -187,7 +192,7 @@ def plot_fan(cls, dmap_data: List[dict], ax=None, scan_index: int = 1,
ax.set_theta_zero_location("S")

# Begin plotting by iterating over ranges and beams
for gates in range(ranges[0],ranges[1]-1):
for gates in range(ranges[0], ranges[1] - 1):
for beams in range(thetas.shape[1] - 2):
# Index colour table correctly
cmapindex = (scan[gates, beams] + abs(zmin)) /\
Expand All @@ -201,24 +206,24 @@ def plot_fan(cls, dmap_data: List[dict], ax=None, scan_index: int = 1,

# Check for zero values (white) and groundscatter (gray)
if scan[gates, beams] == 0:
colour_rgba = 'w'
colour_rgba = (1, 1, 1, 0)

if groundscatter and grndsct[gates, beams] == 1:
colour_rgba = 'gray'

#Angle for polar plotting
# Angle for polar plotting
theta = [thetas[gates, beams], thetas[gates + 1, beams],
thetas[gates + 1, beams + 1],
thetas[gates, beams + 1]]
#Radius for polar plotting
# Radius for polar plotting
r = [rs[gates, beams], rs[gates + 1, beams],
rs[gates + 1, beams + 1], rs[gates, beams + 1]]
im = ax.fill(theta, r, color=colour_rgba)
ax.fill(theta, r, color=colour_rgba)

# Plot FOV outline
if boundary is True:
plt.polar(thetas[0:ranges[1], 0], rs[0:ranges[1], 0], color='black',
linewidth=0.5)
plt.polar(thetas[0:ranges[1], 0], rs[0:ranges[1], 0],
color='black', linewidth=0.5)
plt.polar(thetas[ranges[1] - 1, 0:thetas.shape[1] - 1],
rs[ranges[1] - 1, 0:thetas.shape[1] - 1], color='black',
linewidth=0.5)
Expand All @@ -238,9 +243,10 @@ def plot_fan(cls, dmap_data: List[dict], ax=None, scan_index: int = 1,
integer=True, nbins='auto')
ticks = locator.tick_values(vmin=zmin, vmax=zmax)

cb = ax.figure.colorbar(mappable, ax=ax, extend='both', ticks=ticks)
cb = ax.figure.colorbar(mappable, ax=ax,
extend='both', ticks=ticks)

if colorbar_label != '':
cb.set_label(colorbar_label)

return beam_corners_aacgm_lats, beam_corners_aacgm_lons, scan, grndsct, dtime
return beam_corners_aacgm_lats, beam_corners_aacgm_lons,
2 changes: 0 additions & 2 deletions pydarn/plotting/power.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,6 @@ def plot_pwr0_statistic(cls, records: List[dict], beam_num: int = 0,
cls.__plot_pwr0(records_of_interest, beam_num,
statistical_method)



@staticmethod
def __plot_pwr0(records: list, beam_num: int, statistical_method: object,
title: bool = True):
Expand Down

0 comments on commit 3fc370f

Please sign in to comment.