SuperDARN / pydarn

Python library for visualizing SuperDARN Data
GNU Lesser General Public License v3.0
31 stars 11 forks source link

BUG: Corrections converting gate to geographic location #353

Closed carleyjmartin closed 9 months ago

carleyjmartin commented 1 year ago

Scope

This PR changes the calculation for geographic coordinates of the location of each range gate to include the 'offset' value of boresight from hdw files, and removes the abs() function from bmsep calculation to allow for the correct beam numbers.

As the abs() was originally a bug fix for a colouring-in issue with cartopy plots, this is now taken care of inside the fov method rather than in the position calculation using an if statement.

issue: #351

Approval

Number of approvals: 2 with a quick code review if possible

Test

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

You can plot all the FOV in geographic coordinates, this should colour in the FOv in grey, anything outside should not be shaded:

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

# North
stids = [209,208, 211,210,33,207,206,66,205,204,1,10,
         40,41,64,50,3,16,7,90,9,6,65,5,8,32]
plt.figure(figsize=(8, 8))
_,_,ax,ccrs=pydarn.Fan.plot_fov(stids[0], datetime(2021, 2, 5, 0, 5),
                        fov_color= 'grey',radar_location=True,
                        radar_label=True, coastline=True,
                        coords=pydarn.Coords.GEOGRAPHIC,
                        projs=pydarn.Projs.GEO)

for stid in stids[1:]:
    _,_,ax,ccrs=pydarn.Fan.plot_fov(stid, datetime(2021, 2, 5, 0, 5), ax=ax,
                            ccrs=ccrs, fov_color= 'grey',
                            radar_location=True, radar_label=True,
                            coastline=True,
                            coords=pydarn.Coords.GEOGRAPHIC,
                            projs=pydarn.Projs.GEO)
plt.show()

# South
stids = [24,96,97,21,4,15,20,11,22,13,12,14,18,19]
plt.figure(figsize=(8, 8))
_,_,ax,ccrs=pydarn.Fan.plot_fov(stids[0], datetime(2021, 2, 5, 0, 5),
                        fov_color= 'grey',radar_location=True,
                        radar_label=True, coastline=True,
                        coords=pydarn.Coords.GEOGRAPHIC,
                        projs=pydarn.Projs.GEO)

for stid in stids[1:]:
    _,_,ax,ccrs=pydarn.Fan.plot_fov(stid, datetime(2021, 2, 5, 0, 5), ax=ax,
                            ccrs=ccrs, fov_color= 'grey',
                            radar_location=True, radar_label=True,
                            coords=pydarn.Coords.GEOGRAPHIC,
                            projs=pydarn.Projs.GEO)
plt.show()
Screenshot 2023-08-16 at 4 07 20 PM Screenshot 2023-08-16 at 4 07 05 PM

To check on the direction of beams, you can use the following code:

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

plt.figure(figsize=(8, 8))
stids = [20]
_,_,ax,ccrs=pydarn.Fan.plot_fov(stids[0], datetime(2021, 2, 5, 0, 5),
                        fov_color= 'grey',radar_location=True,
                        radar_label=True, coastline=True,
                        coords=pydarn.Coords.GEOGRAPHIC,
                        projs=pydarn.Projs.GEO)
_,_,ax,ccrs=pydarn.Fan.plot_fov(stids[0], datetime(2021, 2, 5, 0, 5), ax=ax,
                        fov_color= 'red', beam=0, ccrs=ccrs,
                        coords=pydarn.Coords.GEOGRAPHIC,
                        projs=pydarn.Projs.GEO)
_,_,ax,ccrs=pydarn.Fan.plot_fov(stids[0], datetime(2021, 2, 5, 0, 5), ax=ax,
                        fov_color= 'blue', beam=15, ccrs=ccrs,
                        coords=pydarn.Coords.GEOGRAPHIC,
                        projs=pydarn.Projs.GEO)
plt.show()

plt.figure(figsize=(8, 8))
stids = [24]
_,_,ax,ccrs=pydarn.Fan.plot_fov(stids[0], datetime(2021, 2, 5, 0, 5),
                        fov_color= 'grey',radar_location=True,
                        radar_label=True, coastline=True,
                        coords=pydarn.Coords.GEOGRAPHIC,
                        projs=pydarn.Projs.GEO)
_,_,ax,ccrs=pydarn.Fan.plot_fov(stids[0], datetime(2021, 2, 5, 0, 5), ax=ax,
                        fov_color= 'red', beam=0, ccrs=ccrs,
                        coords=pydarn.Coords.GEOGRAPHIC,
                        projs=pydarn.Projs.GEO)
_,_,ax,ccrs=pydarn.Fan.plot_fov(stids[0], datetime(2021, 2, 5, 0, 5), ax=ax,
                        fov_color= 'blue', beam=15, ccrs=ccrs,
                        coords=pydarn.Coords.GEOGRAPHIC,
                        projs=pydarn.Projs.GEO)
plt.show()

This code checks the first and 15th beam (red and blue) for a -ve and +ve bmsep value:

Screenshot 2023-08-16 at 4 16 34 PM Screenshot 2023-08-16 at 4 16 45 PM

These all require Cartopy to be installed - you can remove the projs, coords and coastline keywords to test in magnetic coordinates without cartopy.

Please check out the associated issue for further discussion!

egthomas commented 1 year ago

@carleyjmartin thanks for making those changes - hopefully @Prof-CW agrees / can confirm!

carleyjmartin commented 1 year ago

Looks like @Prof-CW agrees with the changes over on the issue #351 , anyone feel free to merge if you like, or let me know if it needs any more changes! :)