FAC: Field-aligned currents (WIP)#
import datetime as dt
import numpy as np
from swarmpal.io import create_paldata, PalDataItem
from swarmpal.toolboxes import fac
Fetching data#
data_params = dict(
collection="SW_OPER_MAGA_LR_1B",
measurements=["B_NEC"],
models=["CHAOS"],
start_time="2016-01-01T00:00:00",
end_time="2016-01-01T03:00:00",
server_url="https://vires.services/ows",
options=dict(asynchronous=False, show_progress=False),
)
data = create_paldata(PalDataItem.from_vires(**data_params))
print(data)
DataTree('paldata', parent=None)
└── DataTree('SW_OPER_MAGA_LR_1B')
Dimensions: (Timestamp: 10800, NEC: 3)
Coordinates:
* Timestamp (Timestamp) datetime64[ns] 2016-01-01 ... 2016-01-01T02:59:59
* NEC (NEC) <U1 'N' 'E' 'C'
Data variables:
Spacecraft (Timestamp) object 'A' 'A' 'A' 'A' 'A' ... 'A' 'A' 'A' 'A' 'A'
B_NEC_CHAOS (Timestamp, NEC) float64 -1.6e+03 -1.031e+04 ... -2.568e+04
Longitude (Timestamp) float64 92.79 92.82 92.85 ... 41.83 41.83 41.83
Latitude (Timestamp) float64 -72.5 -72.56 -72.63 ... -44.9 -44.97 -45.03
Radius (Timestamp) float64 6.834e+06 6.834e+06 ... 6.833e+06 6.833e+06
B_NEC (Timestamp, NEC) float64 -1.581e+03 -1.049e+04 ... -2.564e+04
Attributes:
Sources: ['CHAOS-7_static.shc', 'SW_OPER_MAGA_LR_1B_20151231T0000...
MagneticModels: ["CHAOS = 'CHAOS-Core'(max_degree=20,min_degree=1) + 'CH...
AppliedFilters: []
PAL_meta: {"analysis_window": ["2016-01-01T00:00:00", "2016-01-01T...
data.swarmpal.pal_meta
{'.': {},
'SW_OPER_MAGA_LR_1B': {'analysis_window': ['2016-01-01T00:00:00',
'2016-01-01T03:00:00'],
'magnetic_models': {'CHAOS': "'CHAOS-Core'(max_degree=20,min_degree=1) + 'CHAOS-Static'(max_degree=185,min_degree=21) + 'CHAOS-MMA-Primary'(max_degree=2,min_degree=1) + 'CHAOS-MMA-Secondary'(max_degree=2,min_degree=1)"}}}
Applying a process and viewing the results#
process = fac.processes.FAC_singlesat(
config={
"dataset": "SW_OPER_MAGA_LR_1B",
"model_varname": "B_NEC_CHAOS",
"measurement_varname": "B_NEC",
},
)
data = data.swarmpal.apply(process)
print(data)
DataTree('paldata', parent=None)
│ Dimensions: ()
│ Data variables:
│ *empty*
│ Attributes:
│ PAL_meta: {"FAC_singlesat": {"dataset": "SW_OPER_MAGA_LR_1B", "model_var...
└── DataTree('SW_OPER_MAGA_LR_1B')
│ Dimensions: (Timestamp: 10800, NEC: 3)
│ Coordinates:
│ * Timestamp (Timestamp) datetime64[ns] 2016-01-01 ... 2016-01-01T02:59:59
│ * NEC (NEC) <U1 'N' 'E' 'C'
│ Data variables:
│ Spacecraft (Timestamp) object 'A' 'A' 'A' 'A' 'A' ... 'A' 'A' 'A' 'A' 'A'
│ B_NEC_CHAOS (Timestamp, NEC) float64 -1.6e+03 -1.031e+04 ... -2.568e+04
│ Longitude (Timestamp) float64 92.79 92.82 92.85 ... 41.83 41.83 41.83
│ Latitude (Timestamp) float64 -72.5 -72.56 -72.63 ... -44.9 -44.97 -45.03
│ Radius (Timestamp) float64 6.834e+06 6.834e+06 ... 6.833e+06 6.833e+06
│ B_NEC (Timestamp, NEC) float64 -1.581e+03 -1.049e+04 ... -2.564e+04
│ Attributes:
│ Sources: ['CHAOS-7_static.shc', 'SW_OPER_MAGA_LR_1B_20151231T0000...
│ MagneticModels: ["CHAOS = 'CHAOS-Core'(max_degree=20,min_degree=1) + 'CH...
│ AppliedFilters: []
│ PAL_meta: {"analysis_window": ["2016-01-01T00:00:00", "2016-01-01T...
└── DataTree('output')
Dimensions: (Timestamp: 10799)
Coordinates:
* Timestamp (Timestamp) datetime64[ns] 2016-01-01T00:00:00.500000 ... 2016...
Data variables:
FAC (Timestamp) float64 -0.135 -0.04186 ... 0.005908 -0.007011
data.swarmpal.pal_meta
{'.': {'FAC_singlesat': {'dataset': 'SW_OPER_MAGA_LR_1B',
'model_varname': 'B_NEC_CHAOS',
'measurement_varname': 'B_NEC'}},
'SW_OPER_MAGA_LR_1B': {'analysis_window': ['2016-01-01T00:00:00',
'2016-01-01T03:00:00'],
'magnetic_models': {'CHAOS': "'CHAOS-Core'(max_degree=20,min_degree=1) + 'CHAOS-Static'(max_degree=185,min_degree=21) + 'CHAOS-MMA-Primary'(max_degree=2,min_degree=1) + 'CHAOS-MMA-Secondary'(max_degree=2,min_degree=1)"}},
'SW_OPER_MAGA_LR_1B/output': {}}
print(data["SW_OPER_MAGA_LR_1B"])
DataTree('SW_OPER_MAGA_LR_1B', parent="paldata")
│ Dimensions: (Timestamp: 10800, NEC: 3)
│ Coordinates:
│ * Timestamp (Timestamp) datetime64[ns] 2016-01-01 ... 2016-01-01T02:59:59
│ * NEC (NEC) <U1 'N' 'E' 'C'
│ Data variables:
│ Spacecraft (Timestamp) object 'A' 'A' 'A' 'A' 'A' ... 'A' 'A' 'A' 'A' 'A'
│ B_NEC_CHAOS (Timestamp, NEC) float64 -1.6e+03 -1.031e+04 ... -2.568e+04
│ Longitude (Timestamp) float64 92.79 92.82 92.85 ... 41.83 41.83 41.83
│ Latitude (Timestamp) float64 -72.5 -72.56 -72.63 ... -44.9 -44.97 -45.03
│ Radius (Timestamp) float64 6.834e+06 6.834e+06 ... 6.833e+06 6.833e+06
│ B_NEC (Timestamp, NEC) float64 -1.581e+03 -1.049e+04 ... -2.564e+04
│ Attributes:
│ Sources: ['CHAOS-7_static.shc', 'SW_OPER_MAGA_LR_1B_20151231T0000...
│ MagneticModels: ["CHAOS = 'CHAOS-Core'(max_degree=20,min_degree=1) + 'CH...
│ AppliedFilters: []
│ PAL_meta: {"analysis_window": ["2016-01-01T00:00:00", "2016-01-01T...
└── DataTree('output')
Dimensions: (Timestamp: 10799)
Coordinates:
* Timestamp (Timestamp) datetime64[ns] 2016-01-01T00:00:00.500000 ... 2016...
Data variables:
FAC (Timestamp) float64 -0.135 -0.04186 ... 0.005908 -0.007011
print(data["SW_OPER_MAGA_LR_1B"]["output"])
DataTree('output', parent="SW_OPER_MAGA_LR_1B")
Dimensions: (Timestamp: 10799)
Coordinates:
* Timestamp (Timestamp) datetime64[ns] 2016-01-01T00:00:00.500000 ... 2016...
Data variables:
FAC (Timestamp) float64 -0.135 -0.04186 ... 0.005908 -0.007011
data.swarmpal_fac.quicklook();
Retrying with data subselection#
This time we will fetch data with a filter applied to the request from VirES
See viresclient.SwarmRequest.add_filter for how these behave. swarmpal.io.PalDataItem.from_vires
accepts a list of such filters.
NB. there is currently a bug requiring that each filter string is enclosed in parentheses.
data_params = dict(
collection="SW_OPER_MAGA_LR_1B",
measurements=["B_NEC"],
models=["CHAOS"],
start_time="2016-01-01T00:00:00",
end_time="2016-01-01T03:00:00",
server_url="https://vires.services/ows",
options=dict(asynchronous=False, show_progress=False),
filters=[
"((QDLat > 50) OR (QDLat < -50))", # the algorithm is only valid at high latitude
"(Flags_B <= 9)", # Exclude particularly bad data
],
)
data = create_paldata(PalDataItem.from_vires(**data_params))
data = data.swarmpal.apply(process)
data.swarmpal_fac.quicklook();