Compute magnetic field variables
This function serves as a wrapper to calculate a suite of magnetic field and related invariants (like L-star, MLT, B_local, B_eq, invariant Mu, and invariant K) based on provided time and geocentric coordinates. It leverages the IRBEM library for the underlying computations.
var_names_to_compute must be a list of strings containing the requested variable names followed by the magnetic field identifier string.
Supported variable names:
- B_local
- B_fofl
- B_mirr
- MLT
- R_eq
- MLT_eq
- xGEO_eq
- B_eq
- Lstar
- PA_eq
- invMu
- invK
- XJ
Supported magnetic field strings:
- OP77Q
- T89
- T96
- T01
- T01s
- TS04|TS05|T04s
Examples of valid entries: B_local_T89, Lstar_TS04
el_paso.processing.compute_magnetic_field_variables
Attributes
el_paso.processing.compute_magnetic_field_variables.VariableRequest
module-attribute
VariableRequest = Sequence[
tuple[
MagFieldVarTypes,
MagneticFieldLiteral | MagneticField,
]
]
Type alias for a request to compute magnetic field variables, consisting of a sequence of tuples where each tuple specifies the variable type and the magnetic field model to use for its computation.
Classes
el_paso.processing.compute_magnetic_field_variables.MagFieldVar
Bases: NamedTuple
A named tuple to represent a request for a magnetic field variable.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
MagFieldVarTypes
|
The type of magnetic field variable to compute (e.g., "B_local", "Lstar"). |
mag_field |
str | MagneticField
|
The magnetic field model to use for the computation . |
Source code in el_paso/processing/compute_magnetic_field_variables.py
31 32 33 34 35 36 37 38 39 40 | |
Functions:
el_paso.processing.compute_magnetic_field_variables.compute_magnetic_field_variables
compute_magnetic_field_variables
Computes various magnetic field-related variables using the IRBEM library.
This function serves as a wrapper to calculate a suite of magnetic field and related invariants (like L-star, MLT, B_local, B_eq, invariant Mu, and invariant K) based on provided time and geocentric coordinates. It leverages the IRBEM library for the underlying computations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time_var
|
Variable
|
A Variable object containing time data. The data should be a 1D array of timestamps. |
required |
xgeo_var
|
Variable
|
A Variable object containing geocentric (XGEO) coordinates. Expected to be a 2D array (time, 3) where the last dimension represents X, Y, Z coordinates. |
required |
variables_to_compute
|
Sequence[tuple[MagFieldVarTypes, str | MagneticField]]
|
A sequence of tuples, where each tuple specifies a variable to compute. The first element is the variable type (e.g., "Lstar"), and the second is the magnetic field model to use (e.g., "IGRF"). |
required |
irbem_options
|
list[int]
|
A list of 5 integer options for the IRBEM library calls, controlling aspects like model selection, bounce tracing, etc. |
required |
num_cores
|
int
|
The number of CPU cores to use for parallel processing within IRBEM calls. |
required |
indices_solar_wind
|
dict[str, Variable] | None
|
Optional. A dictionary
containing solar wind indices (e.g., "Kp", "Dst") as |
None
|
pa_local_var
|
Variable | None
|
Optional. A Variable object containing local pitch angle data in degrees. Required if any pitch-angle dependent variables (e.g., "PA_eq", "Lstar", "invMu", "invK") are requested. Defaults to None. |
None
|
energy_var
|
Variable | None
|
Optional. A Variable object containing particle energy data in MeV. Required if "invMu" is requested. Defaults to None. |
None
|
particle_species
|
Literal['electron', 'proton'] | None
|
Optional. The species of particle (e.g., "electron", "proton"). Required if "invMu" is requested. Defaults to None. |
None
|
irbem_lib_path
|
str | Path
|
Optional. The file path to the IRBEM library (e.g., "libirbem.so"). Defaults to a path relative to the el_paso package. |
parent / 'libirbem.so'
|
Returns:
| Type | Description |
|---|---|
dict[str, Variable]
|
dict[str, Variable]: A dictionary where keys are the computed variable |
dict[str, Variable]
|
names and values are their corresponding |
dict[str, Variable]
|
the calculated data and metadata. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If no IRBEM library object is found at the provided |
ValueError
|
|
NotImplementedError
|
If a requested variable name in |
Notes
- The function internally constructs an
IrbemInputobject for each unique magnetic field model encountered invariables_to_compute. - Intermediate computed variables (e.g.,
B_eq,B_local) are cached within the function to avoid redundant IRBEM calls when multiple dependent variables are requested.
Source code in el_paso/processing/compute_magnetic_field_variables.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |