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: Single Beam Options #298

Merged
merged 2 commits into from
Mar 24, 2023
Merged

EHN: Single Beam Options #298

merged 2 commits into from
Mar 24, 2023

Conversation

carleyjmartin
Copy link
Collaborator

Scope

This PR contains an addition to the fan.py module that allows for the option beam to be passed to the fov and fan plotting functions. This allows the user to plot more specific data, or make diagrams with beams in fov. The examples below use a file that is using camping beam, which is a good use case/option to plot single beams. Default for beam is None. Docs updated.

issue: #294

Approval

Number of approvals: 2 test and code review

Test

matplotlib version: 3.6.3
Note testers: please indicate what version of matplotlib you are using

import matplotlib.pyplot as plt
import pydarn
import datetime as dt

file = "/Users/carley/Documents/data/20150308.1400.03.cly.fitacf"
SDarn_read = pydarn.SuperDARNRead(file)
fitacf_data = SDarn_read.read_fitacf()

# FOV plot highlighting geographic and magnetic
_, _ , ax, ccrs = pydarn.Fan.plot_fov(fitacf_data[0]['stid'], dt.datetime(2015,3,8,14,10), beam=10, grid=True, fov_color='red',coords=pydarn.Coords.GEOGRAPHIC ,projs=pydarn.Projs.GEO, coastline=True, lowlat=50)
_, _, ax, ccrs = pydarn.Fan.plot_fov(fitacf_data[0]['stid'], dt.datetime(2015,3,8,14,10), ax=ax, ccrs=ccrs, beam=4, grid=True, fov_color='blue',ranges=[30,60], coords=pydarn.Coords.GEOGRAPHIC ,projs=pydarn.Projs.GEO)
_, _, ax, ccrs = pydarn.Fan.plot_fov(fitacf_data[0]['stid'], dt.datetime(2015,3,8,14,10), ax=ax, ccrs=ccrs, coords=pydarn.Coords.GEOGRAPHIC ,projs=pydarn.Projs.GEO)
plt.show()

_, _, ax, _ = pydarn.Fan.plot_fov(fitacf_data[0]['stid'], dt.datetime(2015,3,8,14,10), beam=10, grid=True, fov_color='red', coastline=True, lowlat=50)
_, _, ax, _ = pydarn.Fan.plot_fov(fitacf_data[0]['stid'], dt.datetime(2015,3,8,14,10), ax=ax, beam=4, grid=True, fov_color='blue',ranges=[30,60])
_, _, ax, _ = pydarn.Fan.plot_fov(fitacf_data[0]['stid'], dt.datetime(2015,3,8,14,10), ax=ax)
plt.show()

# Fan plot with specific data in geo and mag
_, _, ax, ccrs = pydarn.Fan.plot_fov(fitacf_data[0]['stid'], dt.datetime(2015,3,8,14,10), coastline=True, lowlat=50, coords=pydarn.Coords.GEOGRAPHIC ,projs=pydarn.Projs.GEO)
pydarn.Fan.plot_fan(fitacf_data, scan_index=dt.datetime(2015,3,8,14,10), beam=10, boundary=True,radar_label=True, groundscatter=True, ax=ax, colorbar=False, coords=pydarn.Coords.GEOGRAPHIC ,projs=pydarn.Projs.GEO)
pydarn.Fan.plot_fan(fitacf_data, scan_index=dt.datetime(2015,3,8,14,10), beam=4, ranges=[30,60], boundary=True, radar_label=True, groundscatter=True, ax=ax, coords=pydarn.Coords.GEOGRAPHIC ,projs=pydarn.Projs.GEO)
plt.show()

_, _, ax, _ = pydarn.Fan.plot_fov(fitacf_data[0]['stid'], dt.datetime(2015,3,8,14,10), coastline=True, lowlat=50)
pydarn.Fan.plot_fan(fitacf_data, scan_index=dt.datetime(2015,3,8,14,10), beam=10, boundary=True,radar_label=True, groundscatter=True, ax=ax, colorbar=False)
pydarn.Fan.plot_fan(fitacf_data, scan_index=dt.datetime(2015,3,8,14,10), beam=4, ranges=[30,60], boundary=True, radar_label=True, groundscatter=True, ax=ax)
plt.show()

The above code, produces the following plots:

Screenshot 2023-02-06 at 12 48 38 PM

Screenshot 2023-02-06 at 12 48 51 PM

Screenshot 2023-02-06 at 12 49 06 PM

Screenshot 2023-02-06 at 12 49 23 PM

@carleyjmartin carleyjmartin self-assigned this Feb 6, 2023
@carleyjmartin carleyjmartin added the enhancement New feature or request label Feb 6, 2023
@carleyjmartin carleyjmartin linked an issue Feb 6, 2023 that may be closed by this pull request
5 tasks
@KhanalKrishna
Copy link
Contributor

Hi,
I am receiving a value error:

Matplotlib version: 3.6.3

import matplotlib.pyplot as plt
import pydarn
import datetime as dt

file = "20150308.1400.03.cly.fitacf"
SDarn_read = pydarn.SuperDARNRead(file)
fitacf_data = SDarn_read.read_fitacf()

FOV plot highlighting geographic and magnetic

_, _ , ax, ccrs = pydarn.Fan.plot_fov(fitacf_data[0]['stid'], dt.datetime(2015,3,8,14,10), beam=10, grid=True, fov_color='red',coords=pydarn.Coords.GEOGRAPHIC ,projs=pydarn.Projs.GEO, coastline=True, lowlat=50)
_, _, ax, ccrs = pydarn.Fan.plot_fov(fitacf_data[0]['stid'], dt.datetime(2015,3,8,14,10), ax=ax, ccrs=ccrs, beam=4, grid=True, fov_color='blue',ranges=[30,60], coords=pydarn.Coords.GEOGRAPHIC ,projs=pydarn.Projs.GEO)
_, _, ax, ccrs = pydarn.Fan.plot_fov(fitacf_data[0]['stid'], dt.datetime(2015,3,8,14,10), ax=ax, ccrs=ccrs, coords=pydarn.Coords.GEOGRAPHIC ,projs=pydarn.Projs.GEO)
plt.show()

_, _, ax, _ = pydarn.Fan.plot_fov(fitacf_data[0]['stid'], dt.datetime(2015,3,8,14,10), beam=10, grid=True, fov_color='red', coastline=True, lowlat=50)
_, _, ax, _ = pydarn.Fan.plot_fov(fitacf_data[0]['stid'], dt.datetime(2015,3,8,14,10), ax=ax, beam=4, grid=True, fov_color='blue',ranges=[30,60])
_, _, ax, _ = pydarn.Fan.plot_fov(fitacf_data[0]['stid'], dt.datetime(2015,3,8,14,10), ax=ax)
plt.show()

Fan plot with specific data in geo and mag

_, _, ax, ccrs = pydarn.Fan.plot_fov(fitacf_data[0]['stid'], dt.datetime(2015,3,8,14,10), coastline=True, lowlat=50, coords=pydarn.Coords.GEOGRAPHIC ,projs=pydarn.Projs.GEO)
pydarn.Fan.plot_fan(fitacf_data, scan_index=dt.datetime(2015,3,8,14,10), beam=10, boundary=True,radar_label=True, groundscatter=True, ax=ax, colorbar=False, coords=pydarn.Coords.GEOGRAPHIC ,projs=pydarn.Projs.GEO)
pydarn.Fan.plot_fan(fitacf_data, scan_index=dt.datetime(2015,3,8,14,10), beam=4, ranges=[30,60], boundary=True, radar_label=True, groundscatter=True, ax=ax, coords=pydarn.Coords.GEOGRAPHIC ,projs=pydarn.Projs.GEO)
plt.show()

_, _, ax, _ = pydarn.Fan.plot_fov(fitacf_data[0]['stid'], dt.datetime(2015,3,8,14,10), coastline=True, lowlat=50)
pydarn.Fan.plot_fan(fitacf_data, scan_index=dt.datetime(2015,3,8,14,10), beam=10, boundary=True,radar_label=True, groundscatter=True, ax=ax, colorbar=False)
pydarn.Fan.plot_fan(fitacf_data, scan_index=dt.datetime(2015,3,8,14,10), beam=4, ranges=[30,60], boundary=True, radar_label=True, groundscatter=True, ax=ax)
plt.show()

Message:
IMPORTANT: Please make sure to cite pyDARN in publications that use plots created by pyDARN using DOI: https://zenodo.org/record/3727269. Citing information for SuperDARN data is found at https://pydarn.readthedocs.io/en/master/user/citing/
Traceback (most recent call last):
File "/Users/krishna/Desktop/pydarn_testing/pr298.py", line 10, in
_, _ , ax, ccrs = pydarn.Fan.plot_fov(fitacf_data[0]['stid'], dt.datetime(2015,3,8,14,10), beam=10, grid=True, fov_color='red',coords=pydarn.Coords.GEOGRAPHIC ,projs=pydarn.Projs.GEO, coastline=True, lowlat=50)
File "/Users/krishna/.local/lib/python3.9/site-packages/pydarn/plotting/fan.py", line 472, in plot_fov
ax, ccrs = projs(date=date, **kwargs)
File "/Users/krishna/.local/lib/python3.9/site-packages/pydarn/plotting/projections.py", line 217, in call
return self.value[0](*args, **kwargs)
File "/Users/krishna/.local/lib/python3.9/site-packages/pydarn/plotting/projections.py", line 191, in axis_geological
ax = plt.subplot(111, projection=proj, aspect='auto')
File "/Users/krishna/opt/anaconda3/lib/python3.9/site-packages/matplotlib/pyplot.py", line 1287, in subplot
ax = fig.add_subplot(*args, **kwargs)
File "/Users/krishna/opt/anaconda3/lib/python3.9/site-packages/matplotlib/figure.py", line 746, in add_subplot
ax = subplot_class_factory(projection_class)(self, *args, **pkw)
File "/Users/krishna/opt/anaconda3/lib/python3.9/site-packages/matplotlib/axes/_subplots.py", line 34, in init
self._axes_class.init(self, fig, [0, 0, 1, 1], **kwargs)
File "/Users/krishna/opt/anaconda3/lib/python3.9/site-packages/cartopy/mpl/geoaxes.py", line 413, in init
super().init(*args, **kwargs)
File "/Users/krishna/opt/anaconda3/lib/python3.9/site-packages/matplotlib/axes/_base.py", line 653, in init
self.clear()
File "/Users/krishna/opt/anaconda3/lib/python3.9/site-packages/matplotlib/axes/_base.py", line 1339, in clear
self.cla()
File "/Users/krishna/opt/anaconda3/lib/python3.9/site-packages/cartopy/mpl/geoaxes.py", line 607, in cla
self._boundary()
File "/Users/krishna/opt/anaconda3/lib/python3.9/site-packages/cartopy/mpl/geoaxes.py", line 1602, in _boundary
trans_path = proj_to_data.transform_path(path)
File "/Users/krishna/opt/anaconda3/lib/python3.9/site-packages/matplotlib/transforms.py", line 1595, in transform_path
return self.transform_path_affine(self.transform_path_non_affine(path))
File "/Users/krishna/opt/anaconda3/lib/python3.9/site-packages/cartopy/mpl/geoaxes.py", line 170, in transform_path_non_affine
new_vertices = self.target_projection.quick_vertices_transform(
File "/Users/krishna/opt/anaconda3/lib/python3.9/site-packages/cartopy/crs.py", line 1247, in quick_vertices_transform
if (x.min() >= x_limits[0] and x.max() <= x_limits[1] and
File "/Users/krishna/opt/anaconda3/lib/python3.9/site-packages/numpy/core/_methods.py", line 44, in _amin
return umr_minimum(a, axis, None, out, keepdims, initial, where)
ValueError: zero-size array to reduction operation minimum which has no identity

@carleyjmartin
Copy link
Collaborator Author

carleyjmartin commented Feb 6, 2023

Hi @KhanalKrishna I can't recreate the error, does the code still work if you try to plot without the beam options? Also what are your numpy and cartopy versions? (I'm on 1.23.1 and 0.21.1 respectively, I am getting a different but similar error when I downgrade cartopy)

EDIT: Hmm, actually I think this might be mismatching matplotlob/cartopy+shapely/numpy versions. Recently, cartopy changed the install instructions regarding shapely, and if I play with the recent different versions of all these I get various errors with cartopy. If you update all these packages to their most recent versions (except numpy, 1.23.1 will avoid the pydarnio bug) and I can work backwards and figure out if we need to update the dependencies. Thanks for testing!

@KhanalKrishna
Copy link
Contributor

Hi @carleyjmartin,
Sorry for the late response.
Yes, I think it is due to cartopy. However, I am now getting trouble re-installing shapely and cartopy. I will get back to it later and try with updated packages.

@Shirling-VT
Copy link
Collaborator

Tested in
MacOS Monterey 12.5.1
matplotlib 3.4.2
python 3.8.0
It's working fine for me using the codes Carley provided.
image
image
image
image

@KhanalKrishna
Copy link
Contributor

matplotlib version: 3.5.3

Hi @carleyjmartin, for some data files, the beams in last two plots extend beyond the radar FOV. I changed only filename and date_time.

import matplotlib.pyplot as plt
import pydarn
import datetime as dt

#file= "20150308.1400.03.cly.fitacf"
#file = "20180225.1801.00.inv.fitacf"
file= "20130202.2001.00.inv.fitacf"
SDarn_read = pydarn.SuperDARNRead(file)
fitacf_data = SDarn_read.read_fitacf()

#date_time= dt.datetime(2015,3,8,14,10)
#date_time= dt.datetime(2018,2,25,18,10)
date_time= dt.datetime(2013, 2, 2, 20, 30)

FOV plot highlighting geographic and magnetic

_, _ , ax, ccrs = pydarn.Fan.plot_fov(fitacf_data[0]['stid'], date_time, beam=10, grid=True, fov_color='red',coords=pydarn.Coords.GEOGRAPHIC ,projs=pydarn.Projs.GEO, coastline=True, lowlat=50)
_, _, ax, ccrs = pydarn.Fan.plot_fov(fitacf_data[0]['stid'], date_time, ax=ax, ccrs=ccrs, beam=4, grid=True, fov_color='blue',ranges=[30,60], coords=pydarn.Coords.GEOGRAPHIC ,projs=pydarn.Projs.GEO)
_, _, ax, ccrs = pydarn.Fan.plot_fov(fitacf_data[0]['stid'], date_time, ax=ax, ccrs=ccrs, coords=pydarn.Coords.GEOGRAPHIC ,projs=pydarn.Projs.GEO)
plt.show()

_, _, ax, _ = pydarn.Fan.plot_fov(fitacf_data[0]['stid'], date_time, beam=10, grid=True, fov_color='red', coastline=True, lowlat=50)
_, _, ax, _ = pydarn.Fan.plot_fov(fitacf_data[0]['stid'], date_time, ax=ax, beam=4, grid=True, fov_color='blue',ranges=[30,60])
_, _, ax, _ = pydarn.Fan.plot_fov(fitacf_data[0]['stid'], date_time, ax=ax)
plt.show()

Fan plot with specific data in geo and mag

_, _, ax, ccrs = pydarn.Fan.plot_fov(fitacf_data[0]['stid'], date_time, coastline=True, lowlat=50, coords=pydarn.Coords.GEOGRAPHIC ,projs=pydarn.Projs.GEO)
pydarn.Fan.plot_fan(fitacf_data, scan_index=date_time, beam=10, boundary=True,radar_label=True, groundscatter=True, ax=ax, colorbar=False, coords=pydarn.Coords.GEOGRAPHIC ,projs=pydarn.Projs.GEO)
pydarn.Fan.plot_fan(fitacf_data, scan_index=date_time, beam=4, ranges=[30,60], boundary=True, radar_label=True, groundscatter=True, ax=ax, coords=pydarn.Coords.GEOGRAPHIC ,projs=pydarn.Projs.GEO)
plt.show()

_, _, ax, _ = pydarn.Fan.plot_fov(fitacf_data[0]['stid'], date_time, coastline=True, lowlat=50)
pydarn.Fan.plot_fan(fitacf_data, scan_index=date_time, beam=10, boundary=True,radar_label=True, groundscatter=True, ax=ax, colorbar=False)
pydarn.Fan.plot_fan(fitacf_data, scan_index=date_time, beam=4, ranges=[30,60], boundary=True, radar_label=True, groundscatter=True, ax=ax)
plt.show()

image

image

image

image

@carleyjmartin
Copy link
Collaborator Author

Thanks for testing @KhanalKrishna ! I'll look into it, although I think it might be an issue with the FOV using 'defaults' we put in and then the fan plot using the real data from a file! Might be adjustable using ranges=[0,110] or something similar in the FOV plot.

@carleyjmartin carleyjmartin merged commit 437557e into develop Mar 24, 2023
@carleyjmartin carleyjmartin deleted the ehn/single-beam branch March 24, 2023 15:57
@carleyjmartin carleyjmartin mentioned this pull request Nov 15, 2023
27 tasks
@hiyadutuje
Copy link
Collaborator

Figure_7
Figure_8
Figure_9
Figure_10
These are the plots I am getting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NewFeature: Single Beam Fan Plot
4 participants