Skip to content

Commit

Permalink
Merge pull request #602 from spedas/master
Browse files Browse the repository at this point in the history
Merge master into psp branch, should get everything synced up properly
  • Loading branch information
jameswilburlewis authored Oct 13, 2023
2 parents 004e59d + ec2160a commit da1a522
Show file tree
Hide file tree
Showing 48 changed files with 3,181 additions and 33 deletions.
Binary file added docs/source/_static/elfin_epd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions pyspedas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
from . import akebono
from . import soho
from . import barrel
from . import elfin

# set up logging/console output
import logging
Expand Down
115 changes: 115 additions & 0 deletions pyspedas/analysis/neutral_sheet.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import numpy as np
import math
from geopack.geopack import recalc as geopack_recalc
from pyspedas import cotrans, time_double

Expand Down Expand Up @@ -464,6 +465,120 @@ def rthph2xyz(r,th,ph):
return x,y,z



"""
C========================================================================================
C
SUBROUTINE TAG14_EQUAT_SHEET (XGSM,YGSM,ZGSM,PSI,PDYN,ByIMF,BzIMF,
* XGSM_S,YGSM_S,ZGSM_S)
C
C INPUT: XGSM,YGSM,ZGSM: position of a point inside the magnetosphere
C PSI: geodipole tilt angle in radians
C PDYN: solar wind ram pressure in nanoPascals
c ByIMF, BzIMF: Y- and Z- GSM components of the IMF in nT
c (averaged over previous 30 minutes)
C
c OUTPUT: XGSM_S,YGSM_S,ZGSM_S: GSM coordinates of a point of the TAG14 equatorial sheet,
c located at the same geocentric distance R=sqrt(XGSM^2+YGSM^2+ZGSM^2)
c and lying in the same GSM meridian plane as the original point {XGSM,YGSM,ZGSM}
c
c Author: N. A. Tsyganenko, Dec.18, 2014
c Reference: Tsyganenko, N. A., V. A. Andreeva, and E. I. Gordeev, Internally and externally induced deformations
c of the magnetospheric equatorial current as inferred from spacecraft data,
c Ann.Geophys., v.33, pp.1-11, doi:10.5194/angeo-33-1-2015, 2015.
c
Translated from FORTRAN via Chat-GPT4.
Original FORTRAN source: https://geo.phys.spbu.ru/~tsyganenko/models/cs/TAG14.for
"""


def tag14_equat_sheet(xgsm, ygsm, zgsm, psi, pdyn, byimf, bzimf):
PI = 3.1415926539
ERR = 1e-8

# Constants
RH0, RH1, RH2, RH3, RH4, RH5, T0, T1, A00, A01, A02, A10, A11, A12, ALPHA0, DALPHA1, DALPHA2, DALPHA3, XAPPA, BETA0, BETA1 = (
11.01595255, 6.054799445, 0.8376136340, -2.283371357, -0.2505011095, -0.9648465280, 0.2865647076, 0.1847283161,
2.909423481, -0.1585372900, 0.5648121327, 1.889466989, 0.06086006001, 0.4853873874, 7.128509839, 4.867577218,
-0.2248219212, -0.1441988549, -0.2868279445, 2.179888855, 0.4035940369
)

xgsm1 = xgsm
ygsm1 = ygsm
zgsm1 = zgsm
r = math.sqrt(xgsm1 ** 2 + ygsm1 ** 2 + zgsm1 ** 2)
theta = math.acos(zgsm1 / r)

if xgsm1 == 0 and ygsm1 == 0:
phi = 0
else:
phi = math.atan2(ygsm1, xgsm1)

byfact = byimf / 5.0
bzfact = bzimf / 5.0

pdyn_0 = 2.0
pfact = (pdyn / pdyn_0) ** XAPPA - 1.0

cps = math.cos(psi)
sps = math.sin(psi)
cp = math.cos(phi)
sp = math.sin(phi)
th1 = 0.0
th2 = PI

while abs(th1 - th2) > ERR:
th = 0.5 * (th1 + th2)

xgsm1 = r * math.sin(th) * cp
ygsm1 = r * math.sin(th) * sp
zgsm1 = r * math.cos(th)
xsm = xgsm1 * cps - zgsm1 * sps
ysm = ygsm1
zsm = xgsm1 * sps + zgsm1 * cps

rho = math.sqrt(xsm ** 2 + ysm ** 2)

if abs(rho) < 1e-6:
cosphi = 1.0
sinphi = 0.0
else:
cosphi = xsm / rho
sinphi = ysm / rho

alpha = ALPHA0 + DALPHA1 * cosphi + DALPHA2 * pfact + DALPHA3 * bzfact
beta = BETA0 + BETA1 * bzfact

rh = RH0 + RH1 * pfact + RH2 * bzfact + (RH3 + RH4 * pfact + RH5 * bzfact) * cosphi
t = T0 + T1 * pfact
a0 = A00 + A01 * pfact + A02 * bzfact
a1 = A10 + A11 * pfact + A12 * bzfact

f = 1.0 - (1.0 + (rho / rh) ** alpha) ** (1.0 / alpha)
g = a0 + a1 * cosphi
f1 = t * byfact * (rho / 10.0) ** beta * sinphi

zsm_sheet = rh * math.tan(psi) * f * g + f1

ff = zsm - zsm_sheet

if ff > 0:
th1 = th
else:
th2 = th

theta_s_gsm = 0.5 * (th1 + th2)

xgsm_s = r * math.sin(theta_s_gsm) * cp
ygsm_s = r * math.sin(theta_s_gsm) * sp
zgsm_s = r * math.cos(theta_s_gsm)

return xgsm_s, ygsm_s, zgsm_s



def neutral_sheet(time, pos, kp=None, model='themis', mlt=None, in_coord='gsm', sc2NS=False):
"""
Calculate the distance to the neutral sheet for a given time and position.
Expand Down
15 changes: 11 additions & 4 deletions pyspedas/barrel/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def load(trange=None,
"""


if not isinstance(probe, list):
probe = [probe]

Expand All @@ -55,10 +54,18 @@ def load(trange=None,

if downloadonly:
return out_files

tvars = cdf_to_tplot(out_files, get_support_data=get_support_data, notplot=notplot)

if tvars is None:
#Convert the cdf files to tvars.
# Make sure each of the variables is prefixed with the flight ID
tvars=[]
for file in out_files:
p_start = file.find("bar_")
p_end = file.find("_", p_start + len("bar_"))
flight = str.upper(file[p_start+len("bar_"):p_end + 1])
prefix = "brl"+flight
tvars = tvars + cdf_to_tplot(out_files, prefix=prefix, get_support_data=get_support_data, notplot=notplot)

if len(tvars) == 0:
return

if time_clip:
Expand Down
1 change: 0 additions & 1 deletion pyspedas/cdagui/cdagui.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ def get_data():
local_dir = default_dir
dir_entry.insert(0, default_dir)


# Get the files, and/or the tplot variables
# sesults is a list [remote filename, local filename, status]
result = cda.cda_download(sel_f_val, local_dir, download_only)
Expand Down
4 changes: 0 additions & 4 deletions pyspedas/cotrans/tvector_rotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ def tvector_rotate(mat_var_in, vec_var_in, newname=None):
if is_left_mat:
m_d_y = ctv_swap_hands(m_d_y)

if not np.array_equal(vec_data.times, mat_data.times) and len(mat_data.times) != 1:
print('Interpolating the matrix timestamps to the vector time stamps')
tinterpol(mat_var_in, vec_var)
mat_data = get_data(mat_var_in + '-itrp')

vec_fac = np.zeros((len(vec_data.times), len(vec_data.y[0, :])))

Expand Down
75 changes: 75 additions & 0 deletions pyspedas/elfin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@

## Electron Losses and Fields Investigation (ELFIN)
The routines in this module can be used to load data from the Electron Losses and Fields Investigation (ELFIN) mission.

### Instruments
- Fluxgate Magnetometer (FGM)
- Energetic Particle Detector (EPD)
- Magneto Resistive Magnetometer-a (MRMa)
- Magneto Resistive Magnetometer-i (MRMi)
- State data (state)
- Engineering data (ENG)

### Examples
Get started by importing pyspedas and tplot; these are required to load and plot the data:

```python
import pyspedas
from pytplot import tplot
```

#### Fluxgate Magnetometer (FGM)

```python
fgm_vars = pyspedas.elfin.fgm(trange=['2020-10-01', '2020-10-02'])

tplot('ela_fgs')
```


#### Energetic Particle Detector (EPD)

```python
epd_vars = pyspedas.elfin.epd(trange=['2020-11-01', '2020-11-02'])

tplot('ela_pef')
```


#### Magneto Resistive Magnetometer (MRMa)

```python
mrma_vars = pyspedas.elfin.mrma(trange=['2020-11-5', '2020-11-6'])

tplot('ela_mrma')
```


#### Magneto Resistive Magnetometer (MRMi)

```python
mrmi_vars = pyspedas.elfin.mrmi(trange=['2020-11-5', '2020-11-6'])

tplot('ela_mrmi')
```


#### State data (state)

```python
state_vars = pyspedas.elfin.state(trange=['2020-11-5/10:00', '2020-11-5/12:00'])

tplot('ela_pos_gei')
```


#### Engineering (ENG)

```python
eng_vars = pyspedas.elfin.eng(trange=['2020-11-5', '2020-11-6'])

tplot('ela_fc_idpu_temp')
```



Loading

0 comments on commit da1a522

Please sign in to comment.