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/cartopy fan plots #219

Merged
merged 42 commits into from Feb 17, 2022
Merged

Ehn/cartopy fan plots #219

merged 42 commits into from Feb 17, 2022

Conversation

mts299
Copy link
Contributor

@mts299 mts299 commented Feb 2, 2022

Scope

This PR focuses on using cartopy in pyDARN's plot_fan plots and plot_fov by passing in Projs.GEO_COASTALINE and Coords.GEOGRAPHIC. There is a lot missing nice features but this is the base PR.

Things still to do that are not included in this PR:

  • COASTALINE with POLAR coordinates system
  • GRID plots
  • Convection map plots
  • centering based on the radar location
  • changing the centering
  • plotting on a globe
  • etc....

issue: #206

Approval

Number of approvals: 3 approvals if possible

Test

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

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

pydarn.Fan.plot_fov(stid=65, date=dt.datetime(2022, 1, 8, 14, 5), grid=True, fov_color='blue')#, coords=pydarn.Coords.GEOGRAPHIC ,projs=pydarn.Projs.GEO_COASTALINE)

plot_fov

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

data_file = "/home/marina/superdarn/data/fitacf/20220108.0801.00.dcn.fitacf.bz2" 

with bz2.open(data_file) as fp: 
    fitacf_stream = fp.read()

data = pydarn.SuperDARNRead(fitacf_stream, True).read_fitacf()

pydarn.Fan.plot_fan(data, grid=True, scan_index=5, fov_color='blue', radar_label=True, groundscatter=True, coords=pydarn.Coords.GEOGRAPHIC, projs=pydarn.Projs.GEO_COASTALINE)
plt.show()

plot_fan

Also test without the coordinate and projection changes and if possible if cartopy is not installed.
You should get the same results in as before without new coordinates and projects and if you don't have cartopy installed and request for a coastaline then it should throw an exception.

mts299 and others added 30 commits November 17, 2021 12:58
@mts299
Copy link
Contributor Author

mts299 commented Feb 8, 2022

@Shirling-VT updated the error message though it will point to the current main page which does not have the install guidelines. I did this so I don't have remember to update it come to release :p

instead are the current ones: https://pydarn.readthedocs.io/en/ehn-cartopy_fan_plots/user/install/

@Shirling-VT
Copy link
Collaborator

MacOS 10.15.7
matplotlib 3.4.2
python 3.8.0

Installed cartopy through conda: conda install -c conda-forge cartopy. Other related dependencies (e.g., geos, proj, pyshp, and shapely) are installed automatically with cartopy in conda.

When I ran the plot_fov test code using projs=pydarn.Projs.GEO_COASTALINE, the following error appears:
Traceback (most recent call last):
File "", line 3, in
File "/Users/xueling/opt/anaconda3/envs/pydarn_test/lib/python3.8/enum.py", line 341, in getattr
raise AttributeError(name) from None
AttributeError: GEO_COASTALINE

I checked the pydarn projs.py and found only COASTALINE and POLAR are available. I then changed projs=pydarn.Projs.GEO_COASTALINE to projs=pydarn.Projs.COASTALINE, this error shows up:
Traceback (most recent call last):
File "", line 1, in
File "/Users/xueling/opt/anaconda3/envs/pydarn_test/lib/python3.8/site-packages/pydarn-2.2.1-py3.8.egg/pydarn/plotting/fan.py", line 452, in plot_fov
cls.plot_radar_position(stid, date=date, line_color=line_color,
File "/Users/xueling/opt/anaconda3/envs/pydarn_test/lib/python3.8/site-packages/pydarn-2.2.1-py3.8.egg/pydarn/plotting/fan.py", line 537, in plot_radar_position
plt.scatter(lon, lat, c=line_color, s=5, transform=transform)
File "/Users/xueling/opt/anaconda3/envs/pydarn_test/lib/python3.8/site-packages/matplotlib/pyplot.py", line 3068, in scatter
__ret = gca().scatter(
File "/Users/xueling/opt/anaconda3/envs/pydarn_test/lib/python3.8/site-packages/cartopy/mpl/geoaxes.py", line 305, in wrapper
raise ValueError('Invalid transform: Spherical {} '
ValueError: Invalid transform: Spherical scatter is not supported - consider using PlateCarree/RotatedPole.

When I changed projs=pydarn.Projs.GEO_COASTALINE to projs=pydarn.Projs.POLAR, now I get a figure, which does not look right as well:
image

Not sure if it's on my side that I didn't install cartopy correctly or needs more dependencies, or if there's something wrong with the test codes. @mts299 Would you mind double checking the test codes?

@mts299
Copy link
Contributor Author

mts299 commented Feb 9, 2022

Thanks @Shirling-VT I may have made minor change that affected everything :(

@mts299
Copy link
Contributor Author

mts299 commented Feb 9, 2022

@Shirling-VT try now, sorry I seem to keep pushing to the wrong cartopy branch

@mts299
Copy link
Contributor Author

mts299 commented Feb 9, 2022

@Shirling-VT nvm looks like there is some other bugs ... @carleyjmartin keeps breaking it

@mts299
Copy link
Contributor Author

mts299 commented Feb 11, 2022

@Shirling-VT Okay now everything should be working:

Figure_1
Figure_2

@mts299
Copy link
Contributor Author

mts299 commented Feb 11, 2022

Please ignore the layering of the grid line and fov_color this has been a known issue just need time to think about it more and will make another PR.

@Shirling-VT
Copy link
Collaborator

MacOS 10.15.7
matplotlib 3.4.2
python 3.8.0
conda install -c conda-forge cartopy

Here are my test codes:
import bz2
import pydarn
import datetime as dt
import matplotlib.pyplot as plt

data = pydarn.Fan.plot_fov(stid=65, date=dt.datetime(2022, 1, 8, 14, 5), grid=True,
fov_color='blue', coords=pydarn.Coords.GEOGRAPHIC,
projs=pydarn.Projs.GEO_COASTALINE)
plt.show()

data = pydarn.Fan.plot_fan(fitacf_data, grid=True, scan_index=5, fov_color='blue',
radar_label=True, groundscatter=True,
coords=pydarn.Coords.GEOGRAPHIC, projs=pydarn.Projs.GEO_COASTALINE)
plt.show()

Both plot_fov and plot_fan give me the same error:
Traceback (most recent call last):
File "", line 1, in
File "/Users/xueling/opt/anaconda3/envs/pydarn_test/lib/python3.8/site-packages/pydarn-3.0-py3.8.egg/pydarn/plotting/fan.py", line 471, in plot_fov
cls.plot_radar_position(stid, date=date, line_color=line_color,
File "/Users/xueling/opt/anaconda3/envs/pydarn_test/lib/python3.8/site-packages/pydarn-3.0-py3.8.egg/pydarn/plotting/fan.py", line 556, in plot_radar_position
plt.scatter(lon, lat, c=line_color, s=5, transform=transform)
File "/Users/xueling/opt/anaconda3/envs/pydarn_test/lib/python3.8/site-packages/matplotlib/pyplot.py", line 3068, in scatter
__ret = gca().scatter(
File "/Users/xueling/opt/anaconda3/envs/pydarn_test/lib/python3.8/site-packages/cartopy/mpl/geoaxes.py", line 305, in wrapper
raise ValueError('Invalid transform: Spherical {} '
ValueError: Invalid transform: Spherical scatter is not supported - consider using PlateCarree/RotatedPole.

@mts299
Copy link
Contributor Author

mts299 commented Feb 14, 2022

what is your fitacf data just so I can test it?

@mts299
Copy link
Contributor Author

mts299 commented Feb 14, 2022

Unless you picked some weird data again or not pulling the newest changes... I get no errors :(

The only thing I can think of once again is 3.5.1
That and my cartopy version had be downgraded due to ubuntu being slow on geo packas requirements.
'0.19.0.post1'

@carleyjmartin what are your specs on those two libraries since you use a Mac as well and report no issues with my code?

@carleyjmartin
Copy link
Collaborator

macos: 10.15.5
mpl: 3.5.1
python3: 3.9.9
I also installed mpl v3.4.2 and didn't get the above error.
I don't install cartopy with anaconda though, that could be the difference. I install the dependencies in brew and then just pip3 it.
My cartopy is at version 0.20.2

@mts299 mts299 mentioned this pull request Feb 14, 2022
5 tasks
@Shirling-VT
Copy link
Collaborator

@mts299 @carleyjmartin Thanks for checking this. I did pull all the newest changes. My cartopy version is 0.18.0. It's very likely that I need to upgrade my cartopy. I remember I saw some posts online mentioning the same issue when using an old version of cartopy. I'll see how I can upgrade it in conda and if I can make it work this time.

@Shirling-VT
Copy link
Collaborator

Looks like it's a cartopy issue. I'm able to install version 0.20.2 (conda install -c conda-forge cartopy=0.20.2) and reproduce the plots without any issues:
image
image
image

For some reason, the default installation in conda (maybe my conda is a bit old (4.10.3)?) of cartopy is 0.18.0. I would suggest adding the cartopy verstion requirements (>=0.19.0?) as an installation instruction.

@mts299
Copy link
Contributor Author

mts299 commented Feb 15, 2022

Thank you @Shirling-VT for figuring it out :)

Since its not an actual install in the setup.py where we would force it ... I can make some documentation on it and see if we cna make an exception to also check the version number before a user gets to using it :) I will get this done today!

@mts299
Copy link
Contributor Author

mts299 commented Feb 15, 2022

@Shirling-VT added in the documentation and an exception that is raised if the version is incorrect:

pydarn.exceptions.plot_exceptions.CartopyVersionError: cartopy is independent library that the user mustinstall to use. Please insure the version number is >= 0.19. Your current version is: 0.18.0

@Shirling-VT Shirling-VT merged commit 87fb29d into develop Feb 17, 2022
Field of View automation moved this from In progress to Done Feb 17, 2022
@mts299 mts299 mentioned this pull request Mar 10, 2022
8 tasks
@carleyjmartin carleyjmartin deleted the ehn/cartopy_fan_plots branch May 3, 2022 15:15
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
Development

Successfully merging this pull request may close these issues.

None yet

3 participants