GeoCotrans.jl
GeoCotrans — Module
Coordinate systems, transformations, geomagnetic field models, and field line tracing.
Reference frames
GEO: Geocentric Geographic (GEO) reference frame.GSM: Geocentric Solar Magnetospheric (GSM) reference frame.GSE: Geocentric Solar Ecliptic (GSE) reference frame.GEI: Geocentric Equatorial Inertial (GEI) reference frame.MAG: Geomagnetic (MAG) reference frame.SM: Solar Magnetic (SM) reference frame.
Utility functions for specifying coordinate representaion in GEO reference frames.
GDZ: Geodetic (GDZ) coordinate system(latitude [deg], longitude [deg], altitude [km]).
Coordinate transformations
Direct transformations
geo2gei,gei2geo: Transform between GEO and GEI reference frames.geo2gsm,gsm2geo: Transform between GEO and GSM reference frames.gei2gsm,gsm2gei: Transform between GEI and GSM reference frames.gse2gsm,gsm2gse: Transform between GSE and GSM reference frames.geo2mag,mag2geo: Transform between GEO and MAG reference frames.gsm2sm,sm2gsm: Transform between GSM and SM reference frames.
Chain transformations
gei2sm,sm2gei: Transform between GEI and SM reference frames.geo2sm,sm2geo: Transform between GEO and SM reference frames.gei2mag,mag2gei: Transform between GEI and MAG reference frames.sph2car,car2sph: Transform between spherical and cartesian coordinate representations.
References
International Geomagnetic Reference Field (IGRF)
The International Geomagnetic Reference Field (IGRF) is a standard mathematical description of the Earth's main magnetic field. It is used widely in studies of the Earth's deep interior, crust, ionosphere, and magnetosphere.
API
Examples
using GeoCotrans, Dates
r, θ, φ = 1.0, deg2rad(45), deg2rad(45)
t = Date(2015)
Br, Bθ, Bφ = igrf(r, θ, φ, t) # ≈ [-45469, -21942, 2933]
# Input position in geodetic coordinates, output magnetic field in East-North-Up (ENU) coordinates
lat, lon = 60, 5
Be, Bn, Bu = igrf(GDZ(lat, lon), t) # [430, 15184, -48864]
# Input position as a matrix in GSM Cartesian coordinates, output magnetic field as a matrix
pos = rand(3, 6)
times = Date.(2015:2020)
Bgsm = igrf(pos, times; in = GSM())References
GeoCotrans.FieldLineTracing — Module
GeoCotrans.jl provides functionality to trace magnetic field lines.
This feature is provided via a package extension and requires an ODE solver package to be loaded in the active environment. For example, load OrdinaryDiffEqTsit5 (or another SciML ODE solver) before calling trace.
API
Installation
using Pkg
Pkg.add("GeoCotrans")Usage
Magnetic Local Time (MLT) calculation
julia> using GeoCotrans, Datesjulia> xGEO = [1., 2., 3.];julia> time = Date(2020);julia> get_mlt(xGEO, time)4.383170558164894
Coordinate Systems
GeoCotrans.GEI — Type
Geocentric Equatorial Inertial (GEI) reference frame.
To Construct a CoordinateVector in GEI reference frame with cartesian representation.
GEI(x, y, z, t = nothing)
GEI(𝐫, t = nothing)GeoCotrans.GEO — Type
Geocentric Geographic (GEO) reference frame.
To Construct a CoordinateVector in GEO reference frame with cartesian representation.
GEO(x, y, z, t = nothing)
GEO(𝐫, t = nothing)GeoCotrans.GSM — Type
Geocentric Solar Magnetospheric (GSM) reference frame.
X points sunward from Earth's center. The X-Z plane is defined to contain Earth's dipole axis (positive North).
To Construct a CoordinateVector in GSM reference frame with cartesian representation.
GSM(x, y, z, t = nothing)
GSM(𝐫, t = nothing)GeoCotrans.GSE — Type
Geocentric Solar Ecliptic (GSE) reference frame.
To Construct a CoordinateVector in GSE reference frame with cartesian representation.
GSE(x, y, z, t = nothing)
GSE(𝐫, t = nothing)GeoCotrans.MAG — Type
Geomagnetic (MAG) reference frame.
Z-axis is parallel to Earth's magnetic dipole axis (positive northward). Y-axis is perpendicular to the plane containing the dipole and Earth's rotation axis.
To Construct a CoordinateVector in MAG reference frame with cartesian representation.
MAG(x, y, z, t = nothing)
MAG(𝐫, t = nothing)GeoCotrans.SM — Type
Solar Magnetic (SM) reference frame.
To Construct a CoordinateVector in SM reference frame with cartesian representation.
SM(x, y, z, t = nothing)
SM(𝐫, t = nothing)GeoCotrans.GDZ — Function
Geodetic (GDZ) coordinate system (latitude [deg], longitude [deg], altitude [km]).
Defined using a reference ellipsoid. Both the altitude and latitude depend on the ellipsoid used. GeoCotrans uses the WGS84 reference ellipsoid.
API Reference
Public
GeoCotrans.GeoCotrans — Module
Coordinate systems, transformations, geomagnetic field models, and field line tracing.
Reference frames
GEO: Geocentric Geographic (GEO) reference frame.GSM: Geocentric Solar Magnetospheric (GSM) reference frame.GSE: Geocentric Solar Ecliptic (GSE) reference frame.GEI: Geocentric Equatorial Inertial (GEI) reference frame.MAG: Geomagnetic (MAG) reference frame.SM: Solar Magnetic (SM) reference frame.
Utility functions for specifying coordinate representaion in GEO reference frames.
GDZ: Geodetic (GDZ) coordinate system(latitude [deg], longitude [deg], altitude [km]).
Coordinate transformations
Direct transformations
geo2gei,gei2geo: Transform between GEO and GEI reference frames.geo2gsm,gsm2geo: Transform between GEO and GSM reference frames.gei2gsm,gsm2gei: Transform between GEI and GSM reference frames.gse2gsm,gsm2gse: Transform between GSE and GSM reference frames.geo2mag,mag2geo: Transform between GEO and MAG reference frames.gsm2sm,sm2gsm: Transform between GSM and SM reference frames.
Chain transformations
gei2sm,sm2gei: Transform between GEI and SM reference frames.geo2sm,sm2geo: Transform between GEO and SM reference frames.gei2mag,mag2gei: Transform between GEI and MAG reference frames.sph2car,car2sph: Transform between spherical and cartesian coordinate representations.
References
International Geomagnetic Reference Field (IGRF)
The International Geomagnetic Reference Field (IGRF) is a standard mathematical description of the Earth's main magnetic field. It is used widely in studies of the Earth's deep interior, crust, ionosphere, and magnetosphere.
API
Examples
using GeoCotrans, Dates
r, θ, φ = 1.0, deg2rad(45), deg2rad(45)
t = Date(2015)
Br, Bθ, Bφ = igrf(r, θ, φ, t) # ≈ [-45469, -21942, 2933]
# Input position in geodetic coordinates, output magnetic field in East-North-Up (ENU) coordinates
lat, lon = 60, 5
Be, Bn, Bu = igrf(GDZ(lat, lon), t) # [430, 15184, -48864]
# Input position as a matrix in GSM Cartesian coordinates, output magnetic field as a matrix
pos = rand(3, 6)
times = Date.(2015:2020)
Bgsm = igrf(pos, times; in = GSM())References
GeoCotrans.CoordinateVector — Type
CoordinateVector{F, T}3-element FieldVector in a specific coordinate frame F using representation R.
GeoCotrans.GEI — Type
Geocentric Equatorial Inertial (GEI) reference frame.
To Construct a CoordinateVector in GEI reference frame with cartesian representation.
GEI(x, y, z, t = nothing)
GEI(𝐫, t = nothing)GeoCotrans.GEO — Type
Geocentric Geographic (GEO) reference frame.
To Construct a CoordinateVector in GEO reference frame with cartesian representation.
GEO(x, y, z, t = nothing)
GEO(𝐫, t = nothing)GeoCotrans.GSE — Type
Geocentric Solar Ecliptic (GSE) reference frame.
To Construct a CoordinateVector in GSE reference frame with cartesian representation.
GSE(x, y, z, t = nothing)
GSE(𝐫, t = nothing)GeoCotrans.GSM — Type
Geocentric Solar Magnetospheric (GSM) reference frame.
X points sunward from Earth's center. The X-Z plane is defined to contain Earth's dipole axis (positive North).
To Construct a CoordinateVector in GSM reference frame with cartesian representation.
GSM(x, y, z, t = nothing)
GSM(𝐫, t = nothing)GeoCotrans.IGRF — Type
IGRF(;)Load the International Geomagnetic Reference Field (IGRF) model.
IGRF is a time-varying model of Earth's main magnetic field with coefficients at 5-year epochs from 1965 to 2030, linearly interpolated between epochs.
By default the input coordinate system in is (GEO(), Spherical()).
Examples
m = IGRF()
r, θ, φ = 1.0, deg2rad(45), deg2rad(45)
t = DateTime("2021-03-28")
m(r, θ, φ, t)
# When input is in different coordinate system, specify `in` or decorate the input
# By default, the output for GDZ input is (Be, Bn, Bu) in East-North-Up (ENU) frame
lat, lon = 60.39299, 5.32415
m2 = IGRF(; in = GDZ())
m2(lat, lon, 0, t)
m(GDZ(lat, lon, 0), t)GeoCotrans.MAG — Type
Geomagnetic (MAG) reference frame.
Z-axis is parallel to Earth's magnetic dipole axis (positive northward). Y-axis is perpendicular to the plane containing the dipole and Earth's rotation axis.
To Construct a CoordinateVector in MAG reference frame with cartesian representation.
MAG(x, y, z, t = nothing)
MAG(𝐫, t = nothing)GeoCotrans.SM — Type
Solar Magnetic (SM) reference frame.
To Construct a CoordinateVector in SM reference frame with cartesian representation.
SM(x, y, z, t = nothing)
SM(𝐫, t = nothing)GeoCotrans.GDZ — Function
GDZ(ϕ, λ, h)Geodetic coordinate system with:
- ϕ: latitude (north/south)
- λ: longitude (east/west)
- h: ellipsoidal height [km]
https://www.wikipedia.org/wiki/Geodetic_coordinates
GeoCotrans.GDZ — Function
Geodetic (GDZ) coordinate system (latitude [deg], longitude [deg], altitude [km]).
Defined using a reference ellipsoid. Both the altitude and latitude depend on the ellipsoid used. GeoCotrans uses the WGS84 reference ellipsoid.
GeoCotrans.car2sph — Method
car2sph(x, y, z) -> (r, θ, φ)Convert Cartesian coordinates to spherical coordinates with angles in radians.
GeoCotrans.car2sphd — Method
car2sphd(x, y, z) -> (r, θ, φ)Convert Cartesian coordinate to spherical coordinate with angles in degrees.
GeoCotrans.gdz2sph — Method
gdz2sph(lat, lon, alt)Convert (lat [deg], lon [deg], alt [km]) in Geodetic coordinate to Spherical geocentric coordinate (r [Re], θ [rad], ϕ [rad]).
GeoCotrans.gei2geo — Function
gei2geo(x, t)
Transforms coordinate(s) x from Geocentric Equatorial Inertial (GEI) to Geographic (GEO) reference frame at time(s) t.
GeoCotrans.gei2gsm — Function
gei2gsm(x, t)
Transforms coordinate(s) x from Geocentric Equatorial Inertial (GEI) to Geocentric Solar Magnetospheric (GSM) reference frame at time(s) t.
GeoCotrans.gei2mag — Function
gei2mag(x, t)
Transforms coordinate(s) x from Geocentric Equatorial Inertial (GEI) to Geomagnetic (MAG) reference frame at time(s) t.
GeoCotrans.gei2sm — Function
gei2sm(x, t)
Transforms coordinate(s) x from Geocentric Equatorial Inertial (GEI) to Solar Magnetic (SM) reference frame at time(s) t.
GeoCotrans.geo2gei — Function
geo2gei(x, t)
Transforms coordinate(s) x from Geographic (GEO) to Geocentric Equatorial Inertial (GEI) reference frame at time(s) t.
GeoCotrans.geo2gsm — Function
geo2gsm(x, t)
Transforms coordinate(s) x from Geographic (GEO) to Geocentric Solar Magnetospheric (GSM) reference frame at time(s) t.
GeoCotrans.geo2mag — Function
geo2mag(x, t)
Transforms coordinate(s) x from Geographic (GEO) to Geomagnetic (MAG) reference frame at time(s) t.
GeoCotrans.geo2sm — Function
geo2sm(x, t)
Transforms coordinate(s) x from Geographic (GEO) to Solar Magnetic (SM) reference frame at time(s) t.
GeoCotrans.get_igrf_coeffs — Method
get_igrf_coeffs(time)Get IGRF-14 coefficients for a given time.
Similar to IRBEM implementation, but with higher precision (IRBEM uses year as the time unit).
GeoCotrans.get_mlt — Method
get_mlt(xGEO, time)Compute magnetic local time (MLT) in hours in the range [0, 24).
MLT is computed from the difference between the magnetic longitudes of the position and the subsolar direction in MAG coordinates.
GeoCotrans.gse2gsm — Function
gse2gsm(x, t)
Transforms coordinate(s) x from Geocentric Solar Ecliptic (GSE) to Geocentric Solar Magnetospheric (GSM) reference frame at time(s) t.
GeoCotrans.gsm2gei — Function
gsm2gei(x, t)
Transforms coordinate(s) x from Geocentric Solar Magnetospheric (GSM) to Geocentric Equatorial Inertial (GEI) reference frame at time(s) t.
GeoCotrans.gsm2geo — Function
gsm2geo(x, t)
Transforms coordinate(s) x from Geocentric Solar Magnetospheric (GSM) to Geographic (GEO) reference frame at time(s) t.
GeoCotrans.gsm2gse — Function
gsm2gse(x, t)
Transforms coordinate(s) x from Geocentric Solar Magnetospheric (GSM) to Geocentric Solar Ecliptic (GSE) reference frame at time(s) t.
GeoCotrans.gsm2sm — Function
gsm2sm(x, t)
Transforms coordinate(s) x from Geocentric Solar Magnetospheric (GSM) to Solar Magnetic (SM) reference frame at time(s) t.
GeoCotrans.igrf — Method
igrf(𝐫, t; kw...) = IGRF()(𝐫, t; kw...)A convenience function for IGRF().
Calculate IGRF model given coordinate(s) 𝐫 at time(s) t.
GeoCotrans.igrf_B — Method
igrf_B(r, θ, φ, t; max_degree=IGRF_degree) -> (Br, Bθ, Bφ)Calculate IGRF model components in geocentric coordinates (r [Re], θ [rad], φ [rad]) at time t.
r is the radius in Earth radii (Re), θ is the colatitude in degrees, and φ is the longitude in degrees.
GeoCotrans.mag2gei — Function
mag2gei(x, t)
Transforms coordinate(s) x from Geomagnetic (MAG) to Geocentric Equatorial Inertial (GEI) reference frame at time(s) t.
GeoCotrans.mag2geo — Function
mag2geo(x, t)
Transforms coordinate(s) x from Geomagnetic (MAG) to Geographic (GEO) reference frame at time(s) t.
GeoCotrans.mag2sm — Function
mag2sm(x, t)
Transforms coordinate(s) x from Geomagnetic (MAG) to Solar Magnetic (SM) reference frame at time(s) t.
GeoCotrans.sm2gei — Function
sm2gei(x, t)
Transforms coordinate(s) x from Solar Magnetic (SM) to Geocentric Equatorial Inertial (GEI) reference frame at time(s) t.
GeoCotrans.sm2geo — Function
sm2geo(x, t)
Transforms coordinate(s) x from Solar Magnetic (SM) to Geographic (GEO) reference frame at time(s) t.
GeoCotrans.sm2gsm — Function
sm2gsm(x, t)
Transforms coordinate(s) x from Solar Magnetic (SM) to Geocentric Solar Magnetospheric (GSM) reference frame at time(s) t.
GeoCotrans.sm2mag — Function
sm2mag(x, t)
Transforms coordinate(s) x from Solar Magnetic (SM) to Geomagnetic (MAG) reference frame at time(s) t.
GeoCotrans.sph2car — Method
Calculates cartesian field components from spherical ones
theta and phi are spherical angles of the point in radians
GeoCotrans.sph2car — Method
sph2car(r, θ, φ) -> (x, y, z)Convert spherical coordinates to Cartesian coordinates.
Arguments
r: radial distanceθ: colatitude in radians [0, π]φ: east longitude in radians [0, 2π]
GeoCotrans.sphd2car — Method
sphd2car(r, θ, φ) -> (x, y, z)Convert spherical coordinates to Cartesian coordinates, with angles in degrees.
GeoCotrans.FieldLineTracing — Module
GeoCotrans.jl provides functionality to trace magnetic field lines.
This feature is provided via a package extension and requires an ODE solver package to be loaded in the active environment. For example, load OrdinaryDiffEqTsit5 (or another SciML ODE solver) before calling trace.
API
GeoCotrans.FieldLineTracing.FieldLineCallback — Function
FieldLineCallback(; r0=1.0, rlim=10.0)Create a callback for terminating field line integration at boundaries.
Keyword Arguments
r0 = 1.0: Inner radial boundary (Earth radii)rlim = 10.0: Outer radial boundary (Earth radii)
GeoCotrans.FieldLineTracing.FieldLineProblem — Function
FieldLineProblem(pos, tspan, t; model=IGRF(), dir=1)Create an ODEProblem for tracing a magnetic field line in model at time t.
dir::Int = 1: Tracing direction (+1 for parallel to B, -1 for anti-parallel)
Example
using GeoCotrans, OrdinaryDiffEqTsit5, Dates
t = DateTime(2020, 1, 1)
pos = [3.0, 0.0, 0.0]
prob = FieldLineProblem(pos, (0.0, 50.0), t)
sol = solve(prob, Tsit5())GeoCotrans.FieldLineTracing.trace — Function
trace(pos, t, solver; kwargs...) :: ODESolutionTrace a magnetic field line using the specified SciML solver.
Keyword Arguments
model = IGRF(): Magnetic field model to usedir = 1: Tracing direction (+1 for parallel to B, -1 for anti-parallel)r0 = 1.0: Inner radial boundary (Earth radii)rlim = 10.0: Outer radial boundary (Earth radii)maxs = 100.0: Maximum arc length for integrationin = getcsys(pos): Input coordinate system (Reference frame and coordinate representation)- Additional keyword arguments are passed to
solve()
Example
using GeoCotrans, OrdinaryDiffEqTsit5
sol = trace([3.0, 0.0, 0.0], t, Tsit5())Private
GeoCotrans.calc_dipole_angle — Method
calc_dipole_angle(g10, g11, h11)Calculate dipole angle (θ, φ) and dipole strength (b0) from spherical harmonic coefficients g10, g11, h11.
θ: dipole tilt angle (radians) φ: dipole longitude/phase (radians) b0: dipole strength (nT)
GeoCotrans.calc_dipole_geo — Method
calc_dipole_geo(time)Compute dipole direction in GEO coordinates.
GeoCotrans.calc_sun_gei — Method
calc_sun_gei(ra, dec)Calculate sun direction vector in GEI given right ascension ra and declination dec.
GeoCotrans.calculate_gst_alt — Method
calculate_gst_alt(time)Alternative implementation of Greenwich sidereal time calculation based on the reference algorithm from pyspedas.cotrans_tools.csundir_vect.
GeoCotrans.car2gdz — Method
car2gdz(x, y, z; scale=R🜨)Convert Cartesian GEO coordinates (x, y, z) to Geodetic coordinates (φ [deg], λ [deg], h [km]).
Uses Bowring's formula (1976). The input coordinates are assumed to be in units of scale (default: Earth radii).
Reference:
- https://en.wikipedia.org/wiki/Geodetic_coordinates
- https://github.com/JuliaEarth/CoordRefSystems.jl/blob/main/src/crs/geographic/geodetic.jl#L197
GeoCotrans.csundir — Method
csundir(time) -> (gst, ra, dec, elong, obliq)Calculate the direction of the sun, returns a tuple of (gst, ra, dec, elong, obliq) in radians.
gst: Greenwich mean sidereal timera: Right ascensiondec: Declination of the sunelong: ecliptic longitudeobliq: Inclination of Earth's axis
See also AstroLib.sunpos.
GeoCotrans.dipole_tilt — Method
dipole_tilt(time)Compute the dipole tilt angle μ (in radians).
The dipole tilt is the angle between the dipole axis and the GSM Z-axis, positive when the north magnetic pole is tilted toward the Sun.
GeoCotrans.evalsph — Function
evalsph(coeffs, r, θ, φ)Evaluate the magnetic field at a point in spherical coordinates.
Arguments
coeffs: The magnetic field coefficientsr: Radial distance in planetary radii (dimensionless)θ: Colatitude in radians [0, π]φ: East longitude in radians [0, 2π]
Returns
SVector{3,Float64}: Magnetic field vector [Br, Bθ, B_φ] in nanoTesla
Coordinate System
- Spherical coordinates (r, θ, φ) where:
- r: radial distance from planet center
- θ: colatitude (0 at north pole, π at south pole)
- φ: east longitude (0 at prime meridian, increases eastward)
Mathematical Formulation
The magnetic field is derived from the scalar potential:
\[B_r = -\frac{∂V}{∂r}, \quad B_θ = -\frac{1}{r}\frac{∂V}{∂θ}, \quad B_φ = -\frac{1}{r\sin θ}\frac{∂V}{∂φ}\]
GeoCotrans.gdz2car — Method
gdz2car(φ, λ, h; scale=R🜨)Convert (φ [deg], λ [deg], h [km]) in Geodetic coordinate to Cartesian GEO coordinate (x [Re], y [Re], z [Re]).
Uses the standard conversion formula from Wikipedia:
- X = (N + h) * cos(φ) * cos(λ)
- Y = (N + h) * cos(φ) * sin(λ)
- Z = (N * (b²/a²) + h) * sin(φ)
where N is the prime vertical radius of curvature: N = a² / √(a² cos²(φ) + b² sin²(φ))
GeoCotrans.gei2gsm_mat — Method
gei2gsm_mat(time)Compute the GEI to GSM transformation matrix.
First axis: sun direction (xS, yS, zS) Second axis: y-axis (cross product of dipole and sun, normalized) Third axis: z-axis (cross product of sun and y-axis, normalized)
GeoCotrans.geo2mag_mat — Method
geo2mag_mat(time)Compute the GEO to MAG transformation matrix.
This follows Hapgood (1992) / UCL geo_tran convention:
T5 = <lat-90, Y> * <long, Z>
where lat/long are the dipole pole coordinates from the IGRF dipole terms. With dipole colatitude θ = π/2 - lat and dipole longitude φ = long, this can be written as R_y(θ) * R_z(-φ).
GeoCotrans.get_dipole_terms — Method
get_dipole_terms(g, h)Compute dipole parameters (θ, φ, x0, y0, z0, b0) from IGRF coefficients.
Returns a named tuple: (θ, φ, x0, y0, z0, b0)
GeoCotrans.gse2gsm_mat — Method
gse2gsm_mat(time)Compute the GSE to GSM transformation matrix T3 = <- psi,X>, where the rotation angle psi is the GSE-GSM angle.
This transformation is a rotation in the GSE YZ plane from the GSE Z axis to the GSM Z axis.
GeoCotrans.gsm2sm_mat — Method
gsm2sm_mat(time)Compute the GSM to SM transformation matrix.
The transformation is a simple rotation around the Y-axis by the dipole tilt angle μ. GSM and SM share the same Y-axis (perpendicular to the dipole-sun plane).