SuperDARN / pydarn

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

Option to output coastline coordinates in magnetlic longitude #366

Closed billetd closed 7 months ago

billetd commented 7 months ago

Scope

This PR adds an option for outputting coastlines in geomagnetic longitude. Previously, convert_geo_coastline_to_mag (Cartopy version) and convert_coastline_list_to_mag (non-Cartopy) could only produce mlat-MLT coordinates. Now there is an option to not do the MLT rotation and produce mlat-mlon coordinates. It is off by default to not disrupt default plotting.

As there is currently no polar projections which use magnetic longitude, this currently has no default use in pyDARN. When/if projections using mlon are set up, these can be used to get coastlines correctly.

Test

# Use case with cartopy installed
import cartopy.feature as cfeature
import datetime as dt
from pydarn.plotting.projections import convert_geo_coastline_to_mag

# Set a time, required for the magnetic conversion
time = dt.datetime(2024, 1, 18)

# Read in the geometry object of the coastlines
cc = cfeature.NaturalEarthFeature('physical', 'coastline', '110m',
                                      color='k', zorder=2.0)

# Iterate over the geometry objects (with coordinates in geographic) and send them to get converted
for geom in cc.geometries():
    coastline_mlt = convert_geo_coastline_to_mag(geom, time)
    coastline_mlon = convert_geo_coastline_to_mag(geom, time, mag_lon=True)
    mlt, mlat = coastline_mlt.coords.xy[0], coastline_mlt.coords.xy[1]
    mlon, mlat = coastline_mlon.coords.xy[0], coastline_mlon.coords.xy[1]
# Use case without cartopy installed
from pydarn import coast_outline
from pydarn.plotting.projections import convert_coastline_list_to_mag
import datetime as dt

# Set a time, required for the magnetic conversion
time = dt.datetime(2024, 1, 18)

# Iterate over the geometry objects for the saved coastlines
for geom in coast_outline:
    [mlat, mlt] = convert_coastline_list_to_mag(geom, time)
    [mlat, mlon] = convert_coastline_list_to_mag(geom, time, mag_lon=True)
carleyjmartin commented 7 months ago

Test code for MultiLineStrings: it's more on the user right now to figure out how to put data into the functions. If in the future we decide to include the 50m option of plotting for cartopy coastlines in a function we will have to add something similar into the functions, for now this is fine and when we come across that bridge this comment is here.

# Use case with cartopy installed
import cartopy.feature as cfeature
import datetime as dt
from pydarn.plotting.projections import convert_geo_coastline_to_mag
from shapely.geometry import mapping

# Set a time, required for the magnetic conversion
time = dt.datetime(2024, 1, 18, 0 ,0)

# Read in the geometry object of the coastlines
cc = cfeature.NaturalEarthFeature('physical', 'coastline', '50m',
                                      color='k', zorder=2.0)

# Iterate over the geometry objects (with coordinates in geographic) and send them to get converted
for geom in cc.geometries():
    if geom.__class__.__name__ == 'MultiLineString':
        for g in geom.geoms:
            coastline_mlt = convert_geo_coastline_to_mag(g, time)
            coastline_mlon = convert_geo_coastline_to_mag(g, time, mag_lon=True)
            mlt, mlat = coastline_mlt.coords.xy[0], coastline_mlt.coords.xy[1]
            mlon, mlat = coastline_mlon.coords.xy[0], coastline_mlon.coords.xy[1]
    else:
        coastline_mlt = convert_geo_coastline_to_mag(geom, time)
        coastline_mlon = convert_geo_coastline_to_mag(geom, time, mag_lon=True)
        mlt, mlat = coastline_mlt.coords.xy[0], coastline_mlt.coords.xy[1]
        mlon, mlat = coastline_mlon.coords.xy[0], coastline_mlon.coords.xy[1]

Happy to merge when above suggestions are resolved.