From 9fd3072ff264cf3169f5d7e17fc1378f1e5e62b6 Mon Sep 17 00:00:00 2001 From: "Alexander Drozdov (Sasha)" Date: Mon, 23 Oct 2023 13:04:34 -0700 Subject: [PATCH] calculate_lshell prototype is added. --- pyspedas/geopack/calculate_lshell.py | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 pyspedas/geopack/calculate_lshell.py diff --git a/pyspedas/geopack/calculate_lshell.py b/pyspedas/geopack/calculate_lshell.py new file mode 100644 index 00000000..57e4199f --- /dev/null +++ b/pyspedas/geopack/calculate_lshell.py @@ -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) \ No newline at end of file