Skip to content

Commit

Permalink
calculate_lshell prototype is added.
Browse files Browse the repository at this point in the history
  • Loading branch information
xandrd committed Oct 23, 2023
1 parent 7bbea9e commit 9fd3072
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions pyspedas/geopack/calculate_lshell.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
def calculate_lshell(sc_pos):
"""
Calculate the L-shell value for spacecraft position data.
Parameters:
sc_pos (numpy.ndarray): Spacecraft position data array with columns [time, x, y, z]
where time is in Unix timestamp, and x, y, z are in GSM coordinates.
Returns:
numpy.ndarray: L-shell values corresponding to the input spacecraft positions.
"""
import numpy as np
import geopack.geopack as geopack

# Extracting the columns from the spacecraft position data
times, x, y, z = sc_pos[:, 0], sc_pos[:, 1], sc_pos[:, 2], sc_pos[:, 3]

lshell_values = [] # List to store the calculated L-shell values

for time, xi, yi, zi in zip(times, x, y, z):
# Recalculating geomagnetic dipole parameters
geopack.recalc(time)

# Tracing the magnetic field line from the position to the equator
xf, yf, zf, xx, yy, zz = geopack.trace(xi, yi, zi, dir=-1, rlim=60., r0=1.,
parmod=2, exname='t89', inname='igrf')

# Calculating the L-shell value as the radial distance at the equator
lshell = np.sqrt(xf ** 2 + yf ** 2 + zf ** 2)

lshell_values.append(lshell)

return np.array(lshell_values)

0 comments on commit 9fd3072

Please sign in to comment.