API: Functions

The following is a full listing of the public functions within the package.

MagNav.TL_mat2vecMethod
TL_mat2vec(TL_coef_p, TL_coef_i, TL_coef_e, terms; Bt_scale = 50000f0)

Extract the vector form of Tolles-Lawson coefficients from the matrix form.

Arguments:

  • TL_coef_p: length-3 vector of permanent field coefficients
  • TL_coef_i: 3 x 3 symmetric matrix of induced field coefficients, denormalized
  • TL_coef_e: 3 x 3 matrix of eddy current coefficients, denormalized
  • terms: Tolles-Lawson terms used {:permanent,:induced,:eddy}
  • Bt_scale: (optional) scaling factor for induced & eddy current terms [nT]

Returns:

  • TL_coef: Tolles-Lawson coefficients
source
MagNav.TL_vec2matMethod
TL_vec2mat(TL_coef::Vector, terms; Bt_scale = 50000f0)

Extract the matrix form of Tolles-Lawson coefficients from the vector form.

Arguments:

  • TL_coef: Tolles-Lawson coefficients (must include :permanent & :induced)
  • terms: Tolles-Lawson terms used {:permanent,:induced,:eddy}
  • Bt_scale: (optional) scaling factor for induced & eddy current terms [nT]

Returns:

  • TL_coef_p: length-3 vector of permanent field coefficients
  • TL_coef_i: 3 x 3 symmetric matrix of induced field coefficients, denormalized
  • TL_coef_e: 3 x 3 matrix of eddy current coefficients, denormalized
source
MagNav.bpf_data!Method
bpf_data!(x::AbstractVecOrMat; bpf=get_bpf())

Bandpass (or low-pass or high-pass) filter vector or columns of matrix.

Arguments:

  • x: data vector or matrix
  • bpf: (optional) filter object

Returns:

  • nothing: x is mutated with filtered data
source
MagNav.bpf_dataMethod
bpf_data(x::AbstractMatrix; bpf=get_bpf())

Bandpass (or low-pass or high-pass) filter columns of matrix.

Arguments:

  • x: data matrix (e.g., Tolles-Lawson A matrix)
  • bpf: (optional) filter object

Returns:

  • x_f: data matrix, filtered
source
MagNav.bpf_dataMethod
bpf_data(x::AbstractVector; bpf=get_bpf())

Bandpass (or low-pass or high-pass) filter vector.

Arguments:

  • x: data vector (e.g., magnetometer measurements)
  • bpf: (optional) filter object

Returns:

  • x_f: data vector, filtered
source
MagNav.chunk_dataMethod
chunk_data(x, y, l_window::Int)

Break data into non-overlapping sequences (vectors).

Arguments:

  • x: N x Nf data matrix (Nf is number of features)
  • y: length-N target vector
  • l_window: temporal window length

Returns:

  • x_seqs: sequence (vector) of Nf x l_window data matrices
  • y_seqs: sequence (vector) of length-l_window target vectors
source
MagNav.comp_m2bc_testMethod
comp_m2bc_test(comp_params::NNCompParams, lines,
               df_line::DataFrame, df_flight::DataFrame, df_map::DataFrame;
               silent::Bool = false)

Evaluate performance of neural network-based aeromagnetic compensation, model 2b or 2c with additional outputs for explainability.

Arguments:

  • comp_params: NNCompParams neural network-based aeromagnetic compensation parameters struct
  • lines: selected line number(s)
  • df_line: lookup table (DataFrame) of lines
FieldTypeDescription
flightSymbolflight name (e.g., :Flt1001)
lineRealline number, i.e., segments within flight
t_startRealstart time of line to use [s]
t_endRealend time of line to use [s]
map_nameSymbol(optional) name of magnetic anomaly map relevant to line
  • df_flight: lookup table (DataFrame) of flight data files
FieldTypeDescription
flightSymbolflight name (e.g., :Flt1001)
xyz_typeSymbolsubtype of XYZ to use for flight data {:XYZ0,:XYZ1,:XYZ20,:XYZ21}
xyz_setRealflight dataset number (used to prevent improper mixing of datasets, such as different magnetometer locations)
xyz_fileStringpath/name of flight data CSV, HDF5, or MAT file (.csv, .h5, or .mat extension required)
  • df_map: lookup table (DataFrame) of map data files
FieldTypeDescription
map_nameSymbolname of magnetic anomaly map
map_fileStringpath/name of map data HDF5 or MAT file (.h5 or .mat extension required)
  • silent: (optional) if true, no print outs

Returns:

  • y_nn: length-N neural network compensation portion
  • y_TL: length-N Tolles-Lawson compensation portion
  • y: length-N target vector
  • y_hat: length-N prediction vector
  • err: length-N mean-corrected (per line) compensation error
  • features: length-Nf feature vector (including components of TL A, etc.)
source
MagNav.comp_m3_testMethod
comp_m3_test(comp_params::NNCompParams, lines,
             df_line::DataFrame, df_flight::DataFrame, df_map::DataFrame;
             temp_params::TempParams = TempParams(),
             silent::Bool            = false)

Evaluate performance of neural network-based aeromagnetic compensation, model 3 with additional outputs for explainability.

Arguments:

  • comp_params: NNCompParams neural network-based aeromagnetic compensation parameters struct
  • lines: selected line number(s)
  • df_line: lookup table (DataFrame) of lines
FieldTypeDescription
flightSymbolflight name (e.g., :Flt1001)
lineRealline number, i.e., segments within flight
t_startRealstart time of line to use [s]
t_endRealend time of line to use [s]
map_nameSymbol(optional) name of magnetic anomaly map relevant to line
  • df_flight: lookup table (DataFrame) of flight data files
FieldTypeDescription
flightSymbolflight name (e.g., :Flt1001)
xyz_typeSymbolsubtype of XYZ to use for flight data {:XYZ0,:XYZ1,:XYZ20,:XYZ21}
xyz_setRealflight dataset number (used to prevent improper mixing of datasets, such as different magnetometer locations)
xyz_fileStringpath/name of flight data CSV, HDF5, or MAT file (.csv, .h5, or .mat extension required)
  • df_map: lookup table (DataFrame) of map data files
FieldTypeDescription
map_nameSymbolname of magnetic anomaly map
map_fileStringpath/name of map data HDF5 or MAT file (.h5 or .mat extension required)
  • temp_params: (optional) TempParams temporary temporal parameters struct
  • silent: (optional) if true, no print outs

Returns:

  • TL_perm: 3 x N matrix of TL permanent vector field
  • TL_induced: 3 x N matrix of TL induced vector field
  • TL_eddy: 3 x N matrix of TL eddy current vector field
  • TL_aircraft: 3 x N matrix of TL aircraft vector field
  • B_unit: 3 x N matrix of normalized vector magnetometer measurements
  • B_vec: 3 x N matrix of vector magnetometer measurements
  • y_nn: 3 x N matrix of vector neural network correction (for scalar models, in direction of Bt)
  • vec_aircraft: 3 x N matrix of predicted aircraft vector field
  • y: length-N target vector
  • y_hat: length-N prediction vector
  • err: length-N mean-corrected (per line) compensation error
  • features: length-Nf feature vector (including components of TL A, etc.)
source
MagNav.comp_testFunction
comp_test(comp_params::CompParams, xyz::XYZ, ind,
          mapS::Union{MapS,MapSd,MapS3D} = mapS_null;
          temp_params::TempParams        = TempParams(),
          silent::Bool                   = false)

Evaluate performance of an aeromagnetic compensation model.

Arguments:

  • comp_params: CompParams aeromagnetic compensation parameters struct, either:
    • NNCompParams: neural network-based aeromagnetic compensation parameters struct
    • LinCompParams: linear aeromagnetic compensation parameters struct
  • xyz: XYZ flight data struct
  • ind: selected data indices
  • mapS: (optional) MapS, MapSd, or MapS3D scalar magnetic anomaly map struct, only used for y_type = :b, :c
  • temp_params: (optional) TempParams temporary temporal parameters struct
  • silent: (optional) if true, no print outs

Returns:

  • y: length-N target vector
  • y_hat: length-N prediction vector
  • err: length-N compensation error
  • features: length-Nf feature vector (including components of TL A, etc.)
source
MagNav.comp_testMethod
comp_test(comp_params::CompParams, lines,
          df_line::DataFrame, df_flight::DataFrame, df_map::DataFrame;
          temp_params::TempParams = TempParams(),
          silent::Bool            = false)

Evaluate performance of an aeromagnetic compensation model.

Arguments:

  • comp_params: CompParams aeromagnetic compensation parameters struct, either:
    • NNCompParams: neural network-based aeromagnetic compensation parameters struct
    • LinCompParams: linear aeromagnetic compensation parameters struct
  • lines: selected line number(s)
  • df_line: lookup table (DataFrame) of lines
FieldTypeDescription
flightSymbolflight name (e.g., :Flt1001)
lineRealline number, i.e., segments within flight
t_startRealstart time of line to use [s]
t_endRealend time of line to use [s]
map_nameSymbol(optional) name of magnetic anomaly map relevant to line
  • df_flight: lookup table (DataFrame) of flight data files
FieldTypeDescription
flightSymbolflight name (e.g., :Flt1001)
xyz_typeSymbolsubtype of XYZ to use for flight data {:XYZ0,:XYZ1,:XYZ20,:XYZ21}
xyz_setRealflight dataset number (used to prevent improper mixing of datasets, such as different magnetometer locations)
xyz_fileStringpath/name of flight data CSV, HDF5, or MAT file (.csv, .h5, or .mat extension required)
  • df_map: lookup table (DataFrame) of map data files
FieldTypeDescription
map_nameSymbolname of magnetic anomaly map
map_fileStringpath/name of map data HDF5 or MAT file (.h5 or .mat extension required)
  • temp_params: (optional) TempParams temporary temporal parameters struct
  • silent: (optional) if true, no print outs

Returns:

  • y: length-N target vector
  • y_hat: length-N prediction vector
  • err: length-N mean-corrected (per line) compensation error
  • features: length-Nf feature vector (including components of TL A, etc.)
source
MagNav.comp_trainFunction
comp_train(comp_params::CompParams, xyz_vec::Vector, ind_vec::Vector,
           mapS::Union{MapS,MapSd,MapS3D} = mapS_null;
           temp_params::TempParams        = TempParams(),
           xyz_test::XYZ                  = xyz_vec[1],
           ind_test                       = BitVector(),
           silent::Bool                   = false)

Train an aeromagnetic compensation model.

Arguments:

  • comp_params: CompParams aeromagnetic compensation parameters struct, either:
    • NNCompParams: neural network-based aeromagnetic compensation parameters struct
    • LinCompParams: linear aeromagnetic compensation parameters struct
  • xyz_vec: vector of XYZ flight data structs
  • ind_vec: vector of selected data indices
  • mapS: (optional) MapS, MapSd, or MapS3D scalar magnetic anomaly map struct, only used for y_type = :b, :c
  • temp_params: (optional) TempParams temporary temporal parameters struct
  • xyz_test: (optional) XYZ held-out test data struct
  • ind_test: (optional) indices for test data struct
  • silent: (optional) if true, no print outs

Returns:

  • comp_params: CompParams aeromagnetic compensation parameters struct
  • y: length-N target vector
  • y_hat: length-N prediction vector
  • err: length-N compensation error
  • features: length-Nf feature vector (including components of TL A, etc.)
source
MagNav.comp_trainFunction
comp_train(comp_params::CompParams, xyz::XYZ, ind,
           mapS::Union{MapS,MapSd,MapS3D} = mapS_null;
           temp_params::TempParams        = TempParams(),
           xyz_test::XYZ                  = xyz,
           ind_test                       = BitVector(),
           silent::Bool                   = false)

Train an aeromagnetic compensation model.

Arguments:

  • comp_params: CompParams aeromagnetic compensation parameters struct, either:
    • NNCompParams: neural network-based aeromagnetic compensation parameters struct
    • LinCompParams: linear aeromagnetic compensation parameters struct
  • xyz: XYZ flight data struct
  • ind: selected data indices
  • mapS: (optional) MapS, MapSd, or MapS3D scalar magnetic anomaly map struct, only used for y_type = :b, :c
  • temp_params: (optional) TempParams temporary temporal parameters struct
  • xyz_test: (optional) XYZ held-out test data struct
  • ind_test: (optional) indices for test data struct
  • silent: (optional) if true, no print outs

Returns:

  • comp_params: CompParams aeromagnetic compensation parameters struct
  • y: length-N target vector
  • y_hat: length-N prediction vector
  • err: length-N compensation error
  • features: length-Nf feature vector (including components of TL A, etc.)
source
MagNav.comp_trainMethod
comp_train(comp_params::CompParams, lines,
           df_line::DataFrame, df_flight::DataFrame, df_map::DataFrame;
           temp_params::TempParams = TempParams(),
           silent::Bool            = false)

Train an aeromagnetic compensation model.

Arguments:

  • comp_params: CompParams aeromagnetic compensation parameters struct, either:
    • NNCompParams: neural network-based aeromagnetic compensation parameters struct
    • LinCompParams: linear aeromagnetic compensation parameters struct
  • lines: selected line number(s)
  • df_line: lookup table (DataFrame) of lines
FieldTypeDescription
flightSymbolflight name (e.g., :Flt1001)
lineRealline number, i.e., segments within flight
t_startRealstart time of line to use [s]
t_endRealend time of line to use [s]
map_nameSymbol(optional) name of magnetic anomaly map relevant to line
  • df_flight: lookup table (DataFrame) of flight data files
FieldTypeDescription
flightSymbolflight name (e.g., :Flt1001)
xyz_typeSymbolsubtype of XYZ to use for flight data {:XYZ0,:XYZ1,:XYZ20,:XYZ21}
xyz_setRealflight dataset number (used to prevent improper mixing of datasets, such as different magnetometer locations)
xyz_fileStringpath/name of flight data CSV, HDF5, or MAT file (.csv, .h5, or .mat extension required)
  • df_map: lookup table (DataFrame) of map data files
FieldTypeDescription
map_nameSymbolname of magnetic anomaly map
map_fileStringpath/name of map data HDF5 or MAT file (.h5 or .mat extension required)
  • temp_params: (optional) TempParams temporary temporal parameters struct
  • silent: (optional) if true, no print outs

Returns:

  • comp_params: CompParams aeromagnetic compensation parameters struct
  • y: length-N target vector
  • y_hat: length-N prediction vector
  • err: length-N mean-corrected (per line) compensation error
  • features: length-Nf feature vector (including components of TL A, etc.)
source
MagNav.comp_train_testFunction
comp_train_test(comp_params::CompParams,
                xyz_train::XYZ, xyz_test::XYZ, ind_train, ind_test,
                mapS_train::Union{MapS,MapSd,MapS3D} = mapS_null,
                mapS_test::Union{MapS,MapSd,MapS3D}  = mapS_null;
                temp_params::TempParams = TempParams(),
                silent::Bool            = false)

Train & evaluate performance of an aeromagnetic compensation model.

Arguments:

  • comp_params: CompParams aeromagnetic compensation parameters struct, either:
    • NNCompParams: neural network-based aeromagnetic compensation parameters struct
    • LinCompParams: linear aeromagnetic compensation parameters struct
  • xyz_train: XYZ flight data struct for training
  • xyz_test: XYZ flight data struct for testing
  • ind_train: selected data indices for training
  • ind_test: selected data indices for testing
  • mapS_train: (optional) MapS, MapSd, or MapS3D scalar magnetic anomaly map struct for training, only used for y_type = :b, :c
  • mapS_test: (optional) MapS, MapSd, or MapS3D scalar magnetic anomaly map struct for testing, only used for y_type = :b, :c
  • temp_params: (optional) TempParams temporary temporal parameters struct
  • silent: (optional) if true, no print outs

Returns:

  • comp_params: CompParams aeromagnetic compensation parameters struct
  • y_train: length-N_train training target vector
  • y_train_hat: length-N_train training prediction vector
  • err_train: length-N_train training compensation error
  • y_test: length-N_test testing target vector
  • y_test_hat: length-N_test testing prediction vector
  • err_test: length-N_test testing compensation error
  • features: length-Nf feature vector (including components of TL A, etc.)
source
MagNav.comp_train_testMethod
comp_train_test(comp_params::CompParams, lines_train, lines_test,
                df_line::DataFrame, df_flight::DataFrame, df_map::DataFrame;
                temp_params::TempParams = TempParams(),
                silent::Bool            = false)

Train & evaluate performance of an aeromagnetic compensation model.

Arguments:

  • comp_params: CompParams aeromagnetic compensation parameters struct, either:
    • NNCompParams: neural network-based aeromagnetic compensation parameters struct
    • LinCompParams: linear aeromagnetic compensation parameters struct
  • lines_train: selected line number(s) for training
  • lines_test: selected line number(s) for testing
  • df_line: lookup table (DataFrame) of lines
FieldTypeDescription
flightSymbolflight name (e.g., :Flt1001)
lineRealline number, i.e., segments within flight
t_startRealstart time of line to use [s]
t_endRealend time of line to use [s]
map_nameSymbol(optional) name of magnetic anomaly map relevant to line
  • df_flight: lookup table (DataFrame) of flight data files
FieldTypeDescription
flightSymbolflight name (e.g., :Flt1001)
xyz_typeSymbolsubtype of XYZ to use for flight data {:XYZ0,:XYZ1,:XYZ20,:XYZ21}
xyz_setRealflight dataset number (used to prevent improper mixing of datasets, such as different magnetometer locations)
xyz_fileStringpath/name of flight data CSV, HDF5, or MAT file (.csv, .h5, or .mat extension required)
  • df_map: lookup table (DataFrame) of map data files
FieldTypeDescription
map_nameSymbolname of magnetic anomaly map
map_fileStringpath/name of map data HDF5 or MAT file (.h5 or .mat extension required)
  • temp_params: (optional) TempParams temporary temporal parameters struct
  • silent: (optional) if true, no print outs

Returns:

  • comp_params: CompParams aeromagnetic compensation parameters struct
  • y_train: length-N_train training target vector
  • y_train_hat: length-N_train training prediction vector
  • err_train: length-N_train mean-corrected (per line) training compensation error
  • y_test: length-N_test testing target vector
  • y_test_hat: length-N_test testing prediction vector
  • err_test: length-N_test mean-corrected (per line) testing compensation error
  • features: length-Nf feature vector (including components of TL A, etc.)
source
MagNav.compare_fieldsMethod
compare_fields(s1, s2; silent::Bool = false)

Compare data for each data field in 2 structs of the same type.

Arguments:

  • s1: struct 1
  • s2: struct 2
  • silent: (optional) if true, no summary print out

Returns:

  • N_dif: if silent = false, number of different fields
source
MagNav.corrupt_magMethod
corrupt_mag(mag_c, Bx, By, Bz;
            dt           = 0.1,
            cor_sigma    = 1.0,
            cor_tau      = 600.0,
            cor_var      = 1.0^2,
            cor_drift    = 0.001,
            cor_perm_mag = 5.0,
            cor_ind_mag  = 5.0,
            cor_eddy_mag = 0.5)

Corrupt compensated (clean) magnetometer measurements with random, FOGM, drift, and Tolles-Lawson noise to create uncompensated (corrupted) scalar magnetometer measurements. FOGM is a First-order Gauss-Markov stochastic process.

Arguments:

  • mag_c: compensated (clean) scalar magnetometer measurements [nT]
  • Bx,By,Bz: vector magnetometer measurements [nT]
  • dt: (optional) measurement time step [s]
  • cor_sigma: (optional) corruption FOGM catch-all bias [nT]
  • cor_tau: (optional) corruption FOGM catch-all time constant [s]
  • cor_var: (optional) corruption measurement (white) noise variance [nT^2]
  • cor_drift: (optional) corruption measurement linear drift [nT/s]
  • cor_perm_mag: (optional) corruption permanent field TL coef std dev
  • cor_ind_mag: (optional) corruption induced field TL coef std dev
  • cor_eddy_mag: (optional) corruption eddy current TL coef std dev

Returns:

  • mag_uc: uncompensated (corrupted) scalar magnetometer measurements [nT]
  • TL_coef: Tolles-Lawson coefficients (partially) used to create mag_uc
  • cor_fogm: corruption FOGM portion [nT]
source
MagNav.corrupt_magMethod
corrupt_mag(mag_c, flux;
            dt           = 0.1,
            cor_sigma    = 1.0,
            cor_tau      = 600.0,
            cor_var      = 1.0^2,
            cor_drift    = 0.001,
            cor_perm_mag = 5.0,
            cor_ind_mag  = 5.0,
            cor_eddy_mag = 0.5)

Corrupt compensated (clean) magnetometer measurements with random, FOGM, drift, and Tolles-Lawson noise to create uncompensated (corrupted) scalar magnetometer measurements. FOGM is a First-order Gauss-Markov stochastic process.

Arguments:

  • mag_c: compensated (clean) scalar magnetometer measurements [nT]
  • flux: MagV vector magnetometer measurement struct
  • dt: (optional) measurement time step [s]
  • cor_sigma: (optional) corruption FOGM catch-all bias [nT]
  • cor_tau: (optional) corruption FOGM catch-all time constant [s]
  • cor_var: (optional) corruption measurement (white) noise variance [nT^2]
  • cor_drift: (optional) corruption measurement linear drift [nT/s]
  • cor_perm_mag: (optional) corruption permanent field TL coef std dev
  • cor_ind_mag: (optional) corruption induced field TL coef std dev
  • cor_eddy_mag: (optional) corruption eddy current TL coef std dev

Returns:

  • mag_uc: uncompensated (corrupted) scalar magnetometer measurements [nT]
  • TL_coef: Tolles-Lawson coefficients (partially) used to create mag_uc
  • cor_fogm: corruption FOGM portion [nT]
source
MagNav.create_P0Function
create_P0(lat1 = deg2rad(45);
          init_pos_sigma   = 3.0,
          init_alt_sigma   = 0.001,
          init_vel_sigma   = 0.01,
          init_att_sigma   = deg2rad(0.01),
          ha_sigma         = 0.001,
          a_hat_sigma      = 0.01,
          acc_sigma        = 0.000245,
          gyro_sigma       = 0.00000000727,
          fogm_sigma       = 3.0,
          vec_sigma        = 1000.0,
          vec_states::Bool = false,
          fogm_state::Bool = true,
          P0_TL            = [])

Create initial covariance matrix P0.

Arguments:

  • lat1: initial approximate latitude [rad]
  • init_pos_sigma: (optional) initial position uncertainty [m]
  • init_alt_sigma: (optional) initial altitude uncertainty [m]
  • init_vel_sigma: (optional) initial velocity uncertainty [m/s]
  • init_att_sigma: (optional) initial attitude uncertainty [rad]
  • ha_sigma: (optional) barometer aiding altitude bias [m]
  • a_hat_sigma: (optional) barometer aiding vertical accel bias [m/s^2]
  • acc_sigma: (optional) accelerometer bias [m/s^2]
  • gyro_sigma: (optional) gyroscope bias [rad/s]
  • fogm_sigma: (optional) FOGM catch-all bias [nT]
  • vec_sigma: (optional) vector magnetometer noise std dev
  • vec_states: (optional) if true, include vector magnetometer states
  • fogm_state: (optional) if true, include FOGM catch-all bias state
  • P0_TL: (optional) initial Tolles-Lawson covariance matrix

Returns:

  • P0: initial covariance matrix
source
MagNav.create_QdFunction
create_Qd(dt = 0.1;
          VRW_sigma        = 0.000238,
          ARW_sigma        = 0.000000581,
          baro_sigma       = 1.0,
          acc_sigma        = 0.000245,
          gyro_sigma       = 0.00000000727,
          fogm_sigma       = 3.0,
          vec_sigma        = 1000.0,
          TL_sigma         = [],
          baro_tau         = 3600.0,
          acc_tau          = 3600.0,
          gyro_tau         = 3600.0,
          fogm_tau         = 600.0,
          vec_states::Bool = false,
          fogm_state::Bool = true)

Create the discrete time process/system noise matrix Qd.

Arguments:

  • dt: measurement time step [s]
  • VRW_sigma: (optional) velocity random walk [m/s^2 /sqrt(Hz)]
  • ARW_sigma: (optional) angular random walk [rad/s /sqrt(Hz)]
  • baro_sigma: (optional) barometer bias [m]
  • acc_sigma: (optional) accelerometer bias [m/s^2]
  • gyro_sigma: (optional) gyroscope bias [rad/s]
  • fogm_sigma: (optional) FOGM catch-all bias [nT]
  • vec_sigma: (optional) vector magnetometer noise std dev
  • TL_sigma: (optional) Tolles-Lawson coefficients estimate std dev
  • baro_tau: (optional) barometer time constant [s]
  • acc_tau: (optional) accelerometer time constant [s]
  • gyro_tau: (optional) gyroscope time constant [s]
  • fogm_tau: (optional) FOGM catch-all time constant [s]
  • vec_states: (optional) if true, include vector magnetometer states
  • fogm_state: (optional) if true, include FOGM catch-all bias state

Returns:

  • Qd: discrete time process/system noise matrix
source
MagNav.create_TL_AFunction
create_TL_A(flux::MagV, ind = trues(length(flux.x));
            Bt       = sqrt.(flux.x.^2+flux.y.^2+flux.z.^2)[ind],
            terms    = [:permanent,:induced,:eddy],
            Bt_scale = 50000,
            return_B = false)

Create Tolles-Lawson A matrix using vector magnetometer measurements. Optionally returns the magnitude & derivatives of total field.

Arguments:

  • flux: MagV vector magnetometer measurement struct
  • ind: (optional) selected data indices
  • Bt: (optional) magnitude of vector magnetometer measurements or scalar magnetometer measurements for modified Tolles-Lawson [nT]
  • terms: (optional) Tolles-Lawson terms to use {:permanent,:induced,:eddy,:bias}
  • Bt_scale: (optional) scaling factor for induced & eddy current terms [nT]
  • return_B: (optional) if true, also return Bt & B_dot

Returns:

  • A: Tolles-Lawson A matrix
  • Bt: if return_B = true, magnitude of total field measurements [nT]
  • B_dot: if return_B = true, finite differences of total field vector [nT]
source
MagNav.create_TL_AMethod
create_TL_A(Bx, By, Bz;
            Bt       = sqrt.(Bx.^2+By.^2+Bz.^2),
            terms    = [:permanent,:induced,:eddy],
            Bt_scale = 50000,
            return_B = false)

Create Tolles-Lawson A matrix using vector magnetometer measurements. Optionally returns the magnitude & derivatives of total field.

Arguments:

  • Bx,By,Bz: vector magnetometer measurements [nT]
  • Bt: (optional) magnitude of vector magnetometer measurements or scalar magnetometer measurements for modified Tolles-Lawson [nT]
  • terms: (optional) Tolles-Lawson terms to use {:permanent,:induced,:eddy,:bias}
  • Bt_scale: (optional) scaling factor for induced & eddy current terms [nT]
  • return_B: (optional) if true, also return Bt & B_dot

Returns:

  • A: Tolles-Lawson A matrix
  • Bt: if return_B = true, magnitude of total field measurements [nT]
  • B_dot: if return_B = true, finite differences of total field vector [nT]
source
MagNav.create_TL_coefFunction
create_TL_coef(flux::MagV, B, ind = trues(length(flux.x));
               Bt         = sqrt.(flux.x.^2+flux.y.^2+flux.z.^2)[ind],
               λ          = 0,
               terms      = [:permanent,:induced,:eddy],
               pass1      = 0.1,
               pass2      = 0.9,
               fs         = 10.0,
               pole::Int  = 4,
               trim::Int  = 20,
               Bt_scale   = 50000,
               return_var = false)

Create Tolles-Lawson coefficients using vector & scalar magnetometer measurements with a bandpass, low-pass, or high-pass filter.

Arguments:

  • flux: MagV vector magnetometer measurement struct
  • B: scalar magnetometer measurements [nT]
  • ind: (optional) selected data indices
  • Bt: (optional) magnitude of vector magnetometer measurements or scalar magnetometer measurements for modified Tolles-Lawson [nT]
  • λ: (optional) ridge parameter
  • terms: (optional) Tolles-Lawson terms to use {:permanent,:induced,:eddy,:bias}
  • pass1: (optional) first passband frequency [Hz]
  • pass2: (optional) second passband frequency [Hz]
  • fs: (optional) sampling frequency [Hz]
  • pole: (optional) number of poles for Butterworth filter
  • trim: (optional) number of elements to trim after filtering
  • Bt_scale: (optional) scaling factor for induced & eddy current terms [nT]
  • return_var: (optional) if true, also return B_var

Returns:

  • coef: Tolles-Lawson coefficients
  • B_var: if return_var = true, fit error variance
source
MagNav.create_TL_coefMethod
create_TL_coef(Bx, By, Bz, B;
               Bt         = sqrt.(Bx.^2+By.^2+Bz.^2),
               λ          = 0,
               terms      = [:permanent,:induced,:eddy],
               pass1      = 0.1,
               pass2      = 0.9,
               fs         = 10.0,
               pole::Int  = 4,
               trim::Int  = 20,
               Bt_scale   = 50000,
               return_var = false)

Create Tolles-Lawson coefficients using vector & scalar magnetometer measurements with a bandpass, low-pass, or high-pass filter.

Arguments:

  • Bx,By,Bz: vector magnetometer measurements [nT]
  • B: scalar magnetometer measurements [nT]
  • Bt: (optional) magnitude of vector magnetometer measurements or scalar magnetometer measurements for modified Tolles-Lawson [nT]
  • λ: (optional) ridge parameter
  • terms: (optional) Tolles-Lawson terms to use {:permanent,:induced,:eddy,:bias}
  • pass1: (optional) first passband frequency [Hz]
  • pass2: (optional) second passband frequency [Hz]
  • fs: (optional) sampling frequency [Hz]
  • pole: (optional) number of poles for Butterworth filter
  • trim: (optional) number of elements to trim after filtering
  • Bt_scale: (optional) scaling factor for induced & eddy current terms [nT]
  • return_var: (optional) if true, also return B_var

Returns:

  • coef: Tolles-Lawson coefficients
  • B_var: if return_var = true, fit error variance
source
MagNav.create_XYZ0Function
create_XYZ0(mapS::Union{MapS,MapSd,MapS3D} = get_map(namad);
            alt            = 1000,
            dt             = 0.1,
            t              = 300,
            v              = 68,
            ll1::Tuple     = (),
            ll2::Tuple     = (),
            N_waves::Int   = 1,
            attempts::Int  = 10,
            info::String   = "Simulated data",
            flight         = 1,
            line           = 1,
            year           = 2023,
            doy            = 154,
            mapV::MapV     = get_map(emm720),
            cor_sigma      = 1.0,
            cor_tau        = 600.0,
            cor_var        = 1.0^2,
            cor_drift      = 0.001,
            cor_perm_mag   = 5.0,
            cor_ind_mag    = 5.0,
            cor_eddy_mag   = 0.5,
            init_pos_sigma = 3.0,
            init_alt_sigma = 0.001,
            init_vel_sigma = 0.01,
            init_att_sigma = deg2rad(0.01),
            VRW_sigma      = 0.000238,
            ARW_sigma      = 0.000000581,
            baro_sigma     = 1.0,
            ha_sigma       = 0.001,
            a_hat_sigma    = 0.01,
            acc_sigma      = 0.000245,
            gyro_sigma     = 0.00000000727,
            fogm_sigma     = 1.0,
            baro_tau       = 3600.0,
            acc_tau        = 3600.0,
            gyro_tau       = 3600.0,
            fogm_tau       = 600.0,
            save_h5::Bool  = false,
            xyz_h5::String = "xyz_data.h5",
            silent::Bool   = false)

Create basic flight data. Assumes constant altitude (2D flight). No required arguments, though many are available to create custom data.

Trajectory Arguments:

  • mapS: (optional) MapS, MapSd, or MapS3D scalar magnetic anomaly map struct
  • alt: (optional) altitude [m]
  • dt: (optional) measurement time step [s]
  • t: (optional) total flight time, ignored if ll2 is set [s]
  • v: (optional) approximate aircraft velocity [m/s]
  • ll1: (optional) initial (lat,lon) point [deg]
  • ll2: (optional) final (lat,lon) point [deg]
  • N_waves: (optional) number of sine waves along path
  • attempts: (optional) maximum attempts at creating flight path on mapS
  • info: (optional) flight data information
  • flight: (optional) flight number
  • line: (optional) line number, i.e., segment within flight
  • year: (optional) year
  • doy: (optional) day of year
  • mapV: (optional) MapV vector magnetic anomaly map struct
  • save_h5: (optional) if true, save xyz to xyz_h5
  • xyz_h5: (optional) path/name of flight data HDF5 file to save (.h5 extension optional)

Compensated Measurement Corruption Arguments:

  • cor_var: (optional) corruption measurement (white) noise variance [nT^2]
  • fogm_sigma: (optional) FOGM catch-all bias [nT]
  • fogm_tau: (optional) FOGM catch-all time constant [s]

Uncompensated Measurement Corruption Arguments:

  • cor_sigma: (optional) corruption FOGM catch-all bias [nT]
  • cor_tau: (optional) corruption FOGM catch-all time constant [s]
  • cor_var: (optional) corruption measurement (white) noise variance [nT^2]
  • cor_drift: (optional) corruption measurement linear drift [nT/s]
  • cor_perm_mag: (optional) corruption permanent field TL coef std dev
  • cor_ind_mag: (optional) corruption induced field TL coef std dev
  • cor_eddy_mag: (optional) corruption eddy current TL coef std dev

INS Arguments:

  • init_pos_sigma: (optional) initial position uncertainty [m]
  • init_alt_sigma: (optional) initial altitude uncertainty [m]
  • init_vel_sigma: (optional) initial velocity uncertainty [m/s]
  • init_att_sigma: (optional) initial attitude uncertainty [rad]
  • VRW_sigma: (optional) velocity random walk [m/s^2 /sqrt(Hz)]
  • ARW_sigma: (optional) angular random walk [rad/s /sqrt(Hz)]
  • baro_sigma: (optional) barometer bias [m]
  • ha_sigma: (optional) barometer aiding altitude bias [m]
  • a_hat_sigma: (optional) barometer aiding vertical accel bias [m/s^2]
  • acc_sigma: (optional) accelerometer bias [m/s^2]
  • gyro_sigma: (optional) gyroscope bias [rad/s]
  • baro_tau: (optional) barometer time constant [s]
  • acc_tau: (optional) accelerometer time constant [s]
  • gyro_tau: (optional) gyroscope time constant [s]

General Arguments:

  • silent: (optional) if true, no print outs

Returns:

  • xyz: XYZ0 flight data struct
source
MagNav.create_fluxFunction
create_flux(path::Path, mapV::MapV = get_map(emm720);
            meas_var     = 1.0^2,
            fogm_sigma   = 1.0,
            fogm_tau     = 600.0,
            silent::Bool = false)

Create compensated (clean) vector magnetometer measurements from a vector magnetic anomaly map.

Arguments:

  • path: Path struct, i.e., Traj trajectory struct, INS inertial navigation system struct, or FILTout filter extracted output struct
  • mapV: (optional) MapV vector magnetic anomaly map struct
  • meas_var: (optional) measurement (white) noise variance [nT^2]
  • fogm_sigma: (optional) FOGM catch-all bias [nT]
  • fogm_tau: (optional) FOGM catch-all time constant [s]
  • silent: (optional) if true, no print outs

Returns:

  • flux: MagV vector magnetometer measurement struct
source
MagNav.create_fluxFunction
create_flux(lat, lon, mapV::MapV = get_map(emm720);
            Cnb          = repeat(I(3),1,1,length(lat)),
            alt          = 1000,
            dt           = 0.1,
            meas_var     = 1.0^2,
            fogm_sigma   = 1.0,
            fogm_tau     = 600.0,
            silent::Bool = false)

Create compensated (clean) vector magnetometer measurements from a vector magnetic anomaly map.

Arguments:

  • lat: latitude [rad]
  • lon: longitude [rad]
  • mapV: (optional) MapV vector magnetic anomaly map struct
  • Cnb: (optional) direction cosine matrix (body to navigation) [-]
  • alt: (optional) altitude [m]
  • dt: (optional) measurement time step [s]
  • meas_var: (optional) measurement (white) noise variance [nT^2]
  • fogm_sigma: (optional) FOGM catch-all bias [nT]
  • fogm_tau: (optional) FOGM catch-all time constant [s]
  • silent: (optional) if true, no print outs

Returns:

  • flux: MagV vector magnetometer measurement struct
source
MagNav.create_informed_xyzMethod
create_informed_xyz(xyz::XYZ, ind, mapS::Union{MapS,MapSd,MapS3D},
                    use_mag::Symbol, use_vec::Symbol, TL_coef::Vector;
                    terms::Vector{Symbol} = [:permanent,:induced,:eddy],
                    disp_min = 100,
                    disp_max = 500,
                    Bt_disp  = 50,
                    Bt_scale = 50000)

Create knowledge-informed data from existing data. Given map information, an XYZ structure with magnetometer readings, and a fitted Tolles-Lawson model, this function creates a consistent, displaced XYZ structure representing what the use_mag and mag_1_c would have collected had the entire flight been laterally shifted by (disp_min,disp_max), assuming that the linear aircraft model is reasonably accurate. It makes use of a Taylor expansion of the map information to update the expected changes due to the alternative map location and due to the imputed aircraft field. The aircraft "noise" is then carried over into use_mag in the new XYZ data.

Arguments:

  • xyz: XYZ flight data struct
  • ind: selected data indices
  • mapS: MapS, MapSd, or MapS3D scalar magnetic anomaly map struct
  • use_mag: uncompensated scalar magnetometer to use for y target vector {:mag_1_uc, etc.}
  • use_vec: vector magnetometer (fluxgate) to use for Tolles-Lawson A matrix {:flux_a, etc.}
  • TL_coef: Tolles-Lawson coefficients
  • terms: (optional) Tolles-Lawson terms to use {:permanent,:induced,:eddy}
  • disp_min: (optional) minimum trajectory displacement [m]
  • disp_max: (optional) maximum trajectory displacement [m]
  • Bt_disp: (optional) target total magnetic field magnitude displacement offset [nT]
  • Bt_scale: (optional) scaling factor for induced & eddy current terms [nT]

Returns:

  • xyz_disp: XYZ flight data struct with displaced trajectory & modified magnetometer readings
source
MagNav.create_insMethod
create_ins(traj::Traj;
           init_pos_sigma = 3.0,
           init_alt_sigma = 0.001,
           init_vel_sigma = 0.01,
           init_att_sigma = deg2rad(0.01),
           VRW_sigma      = 0.000238,
           ARW_sigma      = 0.000000581,
           baro_sigma     = 1.0,
           ha_sigma       = 0.001,
           a_hat_sigma    = 0.01,
           acc_sigma      = 0.000245,
           gyro_sigma     = 0.00000000727,
           baro_tau       = 3600.0,
           acc_tau        = 3600.0,
           gyro_tau       = 3600.0,
           save_h5::Bool  = false,
           ins_h5::String = "ins_data.h5")

Creates an INS trajectory about a true trajectory. Propagates a 17-state Pinson error model to create INS errors.

Arguments:

  • traj: Traj trajectory struct
  • init_pos_sigma: (optional) initial position uncertainty [m]
  • init_alt_sigma: (optional) initial altitude uncertainty [m]
  • init_vel_sigma: (optional) initial velocity uncertainty [m/s]
  • init_att_sigma: (optional) initial attitude uncertainty [rad]
  • VRW_sigma: (optional) velocity random walk [m/s^2 /sqrt(Hz)]
  • ARW_sigma: (optional) angular random walk [rad/s /sqrt(Hz)]
  • baro_sigma: (optional) barometer bias [m]
  • ha_sigma: (optional) barometer aiding altitude bias [m]
  • a_hat_sigma: (optional) barometer aiding vertical accel bias [m/s^2]
  • acc_sigma: (optional) accelerometer bias [m/s^2]
  • gyro_sigma: (optional) gyroscope bias [rad/s]
  • baro_tau: (optional) barometer time constant [s]
  • acc_tau: (optional) accelerometer time constant [s]
  • gyro_tau: (optional) gyroscope time constant [s]
  • save_h5: (optional) if true, save ins to ins_h5
  • ins_h5: (optional) path/name of INS data HDF5 file to save (.h5 extension optional)

Returns:

  • ins: INS inertial navigation system struct
source
MagNav.create_mag_cFunction
create_mag_c(path::Path, mapS::Union{MapS,MapSd,MapS3D} = get_map(namad);
             meas_var     = 1.0^2,
             fogm_sigma   = 1.0,
             fogm_tau     = 600.0,
             silent::Bool = false)

Create compensated (clean) scalar magnetometer measurements from a scalar magnetic anomaly map.

Arguments:

  • path: Path struct, i.e., Traj trajectory struct, INS inertial navigation system struct, or FILTout filter extracted output struct
  • mapS: (optional) MapS, MapSd, or MapS3D scalar magnetic anomaly map struct
  • meas_var: (optional) measurement (white) noise variance [nT^2]
  • fogm_sigma: (optional) FOGM catch-all bias [nT]
  • fogm_tau: (optional) FOGM catch-all time constant [s]
  • silent: (optional) if true, no print outs

Returns:

  • mag_c: compensated (clean) scalar magnetometer measurements [nT]
source
MagNav.create_mag_cFunction
create_mag_c(lat, lon, mapS::Union{MapS,MapSd,MapS3D} = get_map(namad);
             alt          = 1000,
             dt           = 0.1,
             meas_var     = 1.0^2,
             fogm_sigma   = 1.0,
             fogm_tau     = 600.0,
             silent::Bool = false)

Create compensated (clean) scalar magnetometer measurements from a scalar magnetic anomaly map.

Arguments:

  • lat: latitude [rad]
  • lon: longitude [rad]
  • mapS: (optional) MapS, MapSd, or MapS3D scalar magnetic anomaly map struct
  • alt: (optional) altitude [m]
  • dt: (optional) measurement time step [s]
  • meas_var: (optional) measurement (white) noise variance [nT^2]
  • fogm_sigma: (optional) FOGM catch-all bias [nT]
  • fogm_tau: (optional) FOGM catch-all time constant [s]
  • silent: (optional) if true, no print outs

Returns:

  • mag_c: compensated (clean) scalar magnetometer measurements [nT]
source
MagNav.create_modelFunction
create_model(dt = 0.1, lat1 = deg2rad(45);
             init_pos_sigma   = 3.0,
             init_alt_sigma   = 0.001,
             init_vel_sigma   = 0.01,
             init_att_sigma   = deg2rad(0.01),
             meas_var         = 3.0^2,
             VRW_sigma        = 0.000238,
             ARW_sigma        = 0.000000581,
             baro_sigma       = 1.0,
             ha_sigma         = 0.001,
             a_hat_sigma      = 0.01,
             acc_sigma        = 0.000245,
             gyro_sigma       = 0.00000000727,
             fogm_sigma       = 3.0,
             vec_sigma        = 1000.0,
             TL_sigma         = [],
             baro_tau         = 3600.0,
             acc_tau          = 3600.0,
             gyro_tau         = 3600.0,
             fogm_tau         = 600.0,
             vec_states::Bool = false,
             fogm_state::Bool = true,
             P0_TL            = [])

Create a magnetic navigation filter model for use in an EKF or a MPF.

Arguments:

  • dt: measurement time step [s]
  • lat1: initial approximate latitude [rad]
  • init_pos_sigma: (optional) initial position uncertainty [m]
  • init_alt_sigma: (optional) initial altitude uncertainty [m]
  • init_vel_sigma: (optional) initial velocity uncertainty [m/s]
  • init_att_sigma: (optional) initial attitude uncertainty [rad]
  • meas_var: (optional) measurement (white) noise variance [nT^2]
  • VRW_sigma: (optional) velocity random walk [m/s^2 /sqrt(Hz)]
  • ARW_sigma: (optional) angular random walk [rad/s /sqrt(Hz)]
  • baro_sigma: (optional) barometer bias [m]
  • ha_sigma: (optional) barometer aiding altitude bias [m]
  • a_hat_sigma: (optional) barometer aiding vertical accel bias [m/s^2]
  • acc_sigma: (optional) accelerometer bias [m/s^2]
  • gyro_sigma: (optional) gyroscope bias [rad/s]
  • fogm_sigma: (optional) FOGM catch-all bias [nT]
  • vec_sigma: (optional) vector magnetometer noise std dev
  • TL_sigma: (optional) Tolles-Lawson coefficients estimate std dev
  • baro_tau: (optional) barometer time constant [s]
  • acc_tau: (optional) accelerometer time constant [s]
  • gyro_tau: (optional) gyroscope time constant [s]
  • fogm_tau: (optional) FOGM catch-all time constant [s]
  • vec_states: (optional) if true, include vector magnetometer states
  • fogm_state: (optional) if true, include FOGM catch-all bias state
  • P0_TL: (optional) initial Tolles-Lawson covariance matrix

Returns:

  • P0: initial covariance matrix
  • Qd: discrete time process/system noise matrix
  • R: measurement (white) noise variance
source
MagNav.create_trajFunction
create_traj(mapS::Union{MapS,MapSd,MapS3D} = get_map(namad);
            alt             = 1000,
            dt              = 0.1,
            t               = 300,
            v               = 68,
            ll1::Tuple      = (),
            ll2::Tuple      = (),
            N_waves::Int    = 1,
            attempts::Int   = 10,
            save_h5::Bool   = false,
            traj_h5::String = "traj_data.h5")

Create Traj trajectory struct with a straight or sinusoidal flight path at constant altitude (2D flight).

Arguments:

  • mapS: (optional) MapS, MapSd, or MapS3D scalar magnetic anomaly map struct
  • alt: (optional) altitude [m]
  • dt: (optional) measurement time step [s]
  • t: (optional) total flight time, ignored if ll2 is set [s]
  • v: (optional) approximate aircraft velocity [m/s]
  • ll1: (optional) initial (lat,lon) point [deg]
  • ll2: (optional) final (lat,lon) point [deg]
  • N_waves: (optional) number of sine waves along path
  • attempts: (optional) maximum attempts at creating flight path on mapS
  • save_h5: (optional) if true, save traj to traj_h5
  • traj_h5: (optional) path/name of trajectory data HDF5 file to save (.h5 extension optional)

Returns:

  • traj: Traj trajectory struct
source
MagNav.crlbMethod
crlb(lat, lon, alt, vn, ve, vd, fn, fe, fd, Cnb, dt, itp_mapS;
     P0         = create_P0(),
     Qd         = create_Qd(),
     R          = 1.0,
     baro_tau   = 3600.0,
     acc_tau    = 3600.0,
     gyro_tau   = 3600.0,
     fogm_tau   = 600.0,
     date       = get_years(2020,185),
     core::Bool = false)

Cramér–Rao lower bound (CRLB) computed with classic Kalman Filter. Equations evaluated about true trajectory.

Arguments:

  • lat: latitude [rad]
  • lon: longitude [rad]
  • alt: altitude [m]
  • vn: north velocity [m/s]
  • ve: east velocity [m/s]
  • vd: down velocity [m/s]
  • fn: north specific force [m/s^2]
  • fe: east specific force [m/s^2]
  • fd: down specific force [m/s^2]
  • Cnb: direction cosine matrix (body to navigation) [-]
  • dt: measurement time step [s]
  • itp_mapS: scalar map interpolation function (f(lat,lon) or f(lat,lon,alt))
  • P0: (optional) initial covariance matrix
  • Qd: (optional) discrete time process/system noise matrix
  • R: (optional) measurement (white) noise variance
  • baro_tau: (optional) barometer time constant [s]
  • acc_tau: (optional) accelerometer time constant [s]
  • gyro_tau: (optional) gyroscope time constant [s]
  • fogm_tau: (optional) FOGM catch-all time constant [s]
  • date: (optional) measurement date (decimal year) for IGRF [yr]
  • core: (optional) if true, include core magnetic field in measurement

Returns:

  • P: non-linear covariance matrix
source
MagNav.crlbMethod
crlb(traj::Traj, itp_mapS;
     P0         = create_P0(),
     Qd         = create_Qd(),
     R          = 1.0,
     baro_tau   = 3600.0,
     acc_tau    = 3600.0,
     gyro_tau   = 3600.0,
     fogm_tau   = 600.0,
     date       = get_years(2020,185),
     core::Bool = false)

Cramér–Rao lower bound (CRLB) computed with classic Kalman Filter. Equations evaluated about true trajectory.

Arguments:

  • traj: Traj trajectory struct
  • itp_mapS: scalar map interpolation function (f(lat,lon) or f(lat,lon,alt))
  • P0: (optional) initial covariance matrix
  • Qd: (optional) discrete time process/system noise matrix
  • R: (optional) measurement (white) noise variance
  • baro_tau: (optional) barometer time constant [s]
  • acc_tau: (optional) accelerometer time constant [s]
  • gyro_tau: (optional) gyroscope time constant [s]
  • fogm_tau: (optional) FOGM catch-all time constant [s]
  • date: (optional) measurement date (decimal year) for IGRF [yr]
  • core: (optional) if true, include core magnetic field in measurement

Returns:

  • P: non-linear covariance matrix
source
MagNav.dcm2eulerFunction
dcm2euler(dcm, order::Symbol = :body2nav)

Converts a DCM (direction cosine matrix) to yaw, pitch, and roll Euler angles. Yaw is synonymous with azimuth and heading here. There are 2 use cases:

  1. With order = :body2nav, the provided DCM is assumed to rotate from the

body frame in the standard -roll, -pitch, -yaw sequence to the navigation frame. For example, if v1 is a 3x1 vector in the body frame [nose, right wing, down], then that vector rotated into the navigation frame [north, east, down] would be v2 = dcm * v1.

  1. With order = :nav2body, the provided DCM is assumed to rotate from the

navigation frame in the standard yaw, pitch, roll sequence to the body frame. For example, if v1 is a 3x1 vector in the navigation frame [north, east, down], then that vector rotated into the body frame [nose, right wing, down] would be v2 = dcm * v1.

Reference: Titterton & Weston, Strapdown Inertial Navigation Technology, 2004, Section 3.6 (pg. 36-41 & 537).

Arguments:

  • dcm: 3 x 3 x N direction cosine matrix [-]
  • order: (optional) rotation order {:body2nav,:nav2body}

Returns:

  • roll: length-N roll angle [rad], right-handed rotation about x-axis
  • pitch: length-N pitch angle [rad], right-handed rotation about y-axis
  • yaw: length-N yaw angle [rad], right-handed rotation about z-axis
source
MagNav.de2dlonMethod
de2dlon(de, lat)

Convert east-west position (easting) difference to longitude difference.

Arguments:

  • de: east-west position (easting) difference [m]
  • lat: nominal latitude [rad]

Returns:

  • dlon: longitude difference [rad]
source
MagNav.denorm_setsMethod
denorm_sets(train_bias, train_scale, train, test)

Denormalize (or destandardize) features (columns) of training & testing data.

Arguments:

  • train_bias: 1 x Nf training data biases (means, mins, or zeros)
  • train_scale: 1 x Nf training data scaling factors (std devs, maxs-mins, or ones)
  • train: N_train x Nf training data, normalized
  • test: N_test x Nf testing data, normalized

Returns:

  • train: N_train x Nf training data, denormalized
  • test: N_test x Nf testing data, denormalized
source
MagNav.denorm_setsMethod
denorm_sets(train_bias, train_scale, train, val, test)

Denormalize (or destandardize) features (columns) of training, validation, & testing data.

Arguments:

  • train_bias: 1 x Nf training data biases (means, mins, or zeros)
  • train_scale: 1 x Nf training data scaling factors (std devs, maxs-mins, or ones)
  • train: N_train x Nf training data, normalized
  • val: N_val x Nf validation data, normalized
  • test: N_test x Nf testing data, normalized

Returns:

  • train: N_train x Nf training data, denormalized
  • val: N_val x Nf validation data, denormalized
  • test: N_test x Nf testing data, denormalized
source
MagNav.denorm_setsMethod
denorm_sets(train_bias, train_scale, train)

Denormalize (or destandardize) features (columns) of training data.

Arguments:

  • train_bias: 1 x Nf training data biases (means, mins, or zeros)
  • train_scale: 1 x Nf training data scaling factors (std devs, maxs-mins, or ones)
  • train: N_train x Nf training data, normalized

Returns:

  • train: N_train x Nf training data, denormalized
source
MagNav.detrendFunction
detrend(y, x = [eachindex(y);]; λ = 0, mean_only::Bool = false)

Detrend signal (remove mean and optionally slope).

Arguments:

  • y: length-N observed data vector
  • x: (optional) N x Nf input data matrix (Nf is number of features)
  • λ: (optional) ridge parameter
  • mean_only: (optional) if true, only remove mean (not slope)

Returns:

  • y: length-N observed data vector, detrended
source
MagNav.dlat2dnMethod
dlat2dn(dlat, lat)

Convert latitude difference to north-south position (northing) difference.

Arguments:

  • dlat: latitude difference [rad]
  • lat: nominal latitude [rad]

Returns:

  • dn: north-south position (northing) difference [m]
source
MagNav.dlon2deMethod
dlon2de(dlon, lat)

Convert longitude difference to east-west position (easting) difference.

Arguments:

  • dlon: longitude difference [rad]
  • lat: nominal latitude [rad]

Returns:

  • de: east-west position (easting) difference [m]
source
MagNav.dn2dlatMethod
dn2dlat(dn, lat)

Convert north-south position (northing) difference to latitude difference.

Arguments:

  • dn: north-south position (northing) difference [m]
  • lat: nominal latitude [rad]

Returns:

  • dlat: latitude difference [rad]
source
MagNav.downward_LMethod
downward_L(map_map::Matrix, dx, dy, dz, α::Vector;
           map_mask::BitMatrix = map_params(map_map)[2],
           expand::Bool        = true)

Downward continuation using a sequence of regularization parameters to create a characteristic L-curve. The optimal regularization parameter is at a local minimum on the L-curve, which is a local maximum of curvature. The global maximum of curvature may or may not be the optimal regularization parameter.

Arguments:

  • map_map: ny x nx 2D gridded map data
  • dx: x-direction map step size [m]
  • dy: y-direction map step size [m]
  • dz: z-direction upward/downward continuation distance [m]
  • α: (geometric) sequence of regularization parameters
  • map_mask: (optional) ny x nx mask for valid (not filled-in) map data
  • expand: (optional) if true, expand map temporarily to reduce edge effects

Returns:

  • norms: L-infinity norm of difference between sequential D.C. solutions
source
MagNav.downward_LMethod
downward_L(mapS::Union{MapS,MapSd,MapS3D}, alt, α::Vector;
           expand::Bool = true)

Downward continuation using a sequence of regularization parameters to create a characteristic L-curve. The optimal regularization parameter is at a local minimum on the L-curve, which is a local maximum of curvature. The global maximum of curvature may or may not be the optimal regularization parameter.

Arguments:

  • mapS: MapS, MapSd, or MapS3D scalar magnetic anomaly map struct
  • alt: target downward continuation altitude [m]
  • α: (geometric) sequence of regularization parameters
  • expand: (optional) if true, expand map temporarily to reduce edge effects

Returns:

  • norms: L-infinity norm of difference between sequential D.C. solutions
source
MagNav.ekfMethod
ekf(lat, lon, alt, vn, ve, vd, fn, fe, fd, Cnb, meas, dt, itp_mapS;
    P0         = create_P0(),
    Qd         = create_Qd(),
    R          = 1.0,
    baro_tau   = 3600.0,
    acc_tau    = 3600.0,
    gyro_tau   = 3600.0,
    fogm_tau   = 600.0,
    date       = get_years(2020,185),
    core::Bool = false,
    der_mapS   = nothing,
    map_alt    = 0)

Extended Kalman filter (EKF) for airborne magnetic anomaly navigation.

Arguments:

  • lat: latitude [rad]
  • lon: longitude [rad]
  • alt: altitude [m]
  • vn: north velocity [m/s]
  • ve: east velocity [m/s]
  • vd: down velocity [m/s]
  • fn: north specific force [m/s^2]
  • fe: east specific force [m/s^2]
  • fd: down specific force [m/s^2]
  • Cnb: direction cosine matrix (body to navigation) [-]
  • meas: scalar magnetometer measurement [nT]
  • dt: measurement time step [s]
  • itp_mapS: scalar map interpolation function (f(lat,lon) or f(lat,lon,alt))
  • P0: (optional) initial covariance matrix
  • Qd: (optional) discrete time process/system noise matrix
  • R: (optional) measurement (white) noise variance
  • baro_tau: (optional) barometer time constant [s]
  • acc_tau: (optional) accelerometer time constant [s]
  • gyro_tau: (optional) gyroscope time constant [s]
  • fogm_tau: (optional) FOGM catch-all time constant [s]
  • date: (optional) measurement date (decimal year) for IGRF [yr]
  • core: (optional) if true, include core magnetic field in measurement
  • der_mapS: (optional) scalar map vertical derivative map interpolation function (f(lat,lon) or (f(lat,lon,alt))
  • map_alt: (optional) map altitude [m]

Returns:

  • filt_res: FILTres filter results struct
source
MagNav.ekfMethod
ekf(ins::INS, meas, itp_mapS;
    P0         = create_P0(),
    Qd         = create_Qd(),
    R          = 1.0,
    baro_tau   = 3600.0,
    acc_tau    = 3600.0,
    gyro_tau   = 3600.0,
    fogm_tau   = 600.0,
    date       = get_years(2020,185),
    core::Bool = false,
    der_mapS   = map_itp(zeros(2,2),[-pi,pi],[-pi/2,pi/2]),
    map_alt    = 0)

Extended Kalman filter (EKF) for airborne magnetic anomaly navigation.

Arguments:

  • ins: INS inertial navigation system struct
  • meas: scalar magnetometer measurement [nT]
  • itp_mapS: scalar map interpolation function (f(lat,lon) or f(lat,lon,alt))
  • P0: (optional) initial covariance matrix
  • Qd: (optional) discrete time process/system noise matrix
  • R: (optional) measurement (white) noise variance
  • baro_tau: (optional) barometer time constant [s]
  • acc_tau: (optional) accelerometer time constant [s]
  • gyro_tau: (optional) gyroscope time constant [s]
  • fogm_tau: (optional) FOGM catch-all time constant [s]
  • date: (optional) measurement date (decimal year) for IGRF [yr]
  • core: (optional) if true, include core magnetic field in measurement
  • der_mapS: (optional) scalar map vertical derivative map interpolation function (f(lat,lon) or (f(lat,lon,alt))
  • map_alt: (optional) map altitude [m]

Returns:

  • filt_res: FILTres filter results struct
source
MagNav.ekf_onlineMethod
ekf_online(lat, lon, alt, vn, ve, vd, fn, fe, fd, Cnb, meas,
           Bx, By, Bz, dt, itp_mapS, x0_TL, P0, Qd, R;
           baro_tau   = 3600.0,
           acc_tau    = 3600.0,
           gyro_tau   = 3600.0,
           fogm_tau   = 600.0,
           date       = get_years(2020,185),
           core::Bool = false,
           terms      = [:permanent,:induced,:eddy,:bias],
           Bt_scale   = 50000)

Extended Kalman filter (EKF) with online learning of Tolles-Lawson coefficients.

Arguments:

  • lat: latitude [rad]
  • lon: longitude [rad]
  • alt: altitude [m]
  • vn: north velocity [m/s]
  • ve: east velocity [m/s]
  • vd: down velocity [m/s]
  • fn: north specific force [m/s^2]
  • fe: east specific force [m/s^2]
  • fd: down specific force [m/s^2]
  • Cnb: direction cosine matrix (body to navigation) [-]
  • meas: scalar magnetometer measurement [nT]
  • Bx,By,Bz: vector magnetometer measurements [nT]
  • dt: measurement time step [s]
  • itp_mapS: scalar map interpolation function (f(lat,lon) or f(lat,lon,alt))
  • x0_TL: initial Tolles-Lawson coefficient states
  • P0: initial covariance matrix
  • Qd: discrete time process/system noise matrix
  • R: measurement (white) noise variance
  • baro_tau: (optional) barometer time constant [s]
  • acc_tau: (optional) accelerometer time constant [s]
  • gyro_tau: (optional) gyroscope time constant [s]
  • fogm_tau: (optional) FOGM catch-all time constant [s]
  • date: (optional) measurement date (decimal year) for IGRF [yr]
  • core: (optional) if true, include core magnetic field in measurement
  • terms: (optional) Tolles-Lawson terms to use {:permanent,:induced,:eddy,:bias}
  • Bt_scale: (optional) scaling factor for induced & eddy current terms [nT]

Returns:

  • filt_res: FILTres filter results struct
source
MagNav.ekf_onlineMethod
ekf_online(ins::INS, meas, flux::MagV, itp_mapS, x0_TL, P0, Qd, R;
           baro_tau   = 3600.0,
           acc_tau    = 3600.0,
           gyro_tau   = 3600.0,
           fogm_tau   = 600.0,
           date       = get_years(2020,185),
           core::Bool = false,
           terms      = [:permanent,:induced,:eddy,:bias],
           Bt_scale   = 50000)

Extended Kalman filter (EKF) with online learning of Tolles-Lawson coefficients.

Arguments:

  • ins: INS inertial navigation system struct
  • meas: scalar magnetometer measurement [nT]
  • flux: MagV vector magnetometer measurement struct
  • itp_mapS: scalar map interpolation function (f(lat,lon) or f(lat,lon,alt))
  • x0_TL: initial Tolles-Lawson coefficient states
  • P0: initial covariance matrix
  • Qd: discrete time process/system noise matrix
  • R: measurement (white) noise variance
  • baro_tau: (optional) barometer time constant [s]
  • acc_tau: (optional) accelerometer time constant [s]
  • gyro_tau: (optional) gyroscope time constant [s]
  • fogm_tau: (optional) FOGM catch-all time constant [s]
  • date: (optional) measurement date (decimal year) for IGRF [yr]
  • core: (optional) if true, include core magnetic field in measurement
  • terms: (optional) Tolles-Lawson terms to use {:permanent,:induced,:eddy,:bias}
  • Bt_scale: (optional) scaling factor for induced & eddy current terms [nT]

Returns:

  • filt_res: FILTres filter results struct
source
MagNav.ekf_online_nnMethod
ekf_online_nn(lat, lon, alt, vn, ve, vd, fn, fe, fd, Cnb, meas,
              dt, itp_mapS, x_nn, m, y_norms, P0, Qd, R;
              baro_tau   = 3600.0,
              acc_tau    = 3600.0,
              gyro_tau   = 3600.0,
              fogm_tau   = 600.0,
              date       = get_years(2020,185),
              core::Bool = false,
              terms      = [:permanent,:induced,:eddy])

Extended Kalman filter (EKF) with online learning of neural network weights.

Arguments:

  • lat: latitude [rad]
  • lon: longitude [rad]
  • alt: altitude [m]
  • vn: north velocity [m/s]
  • ve: east velocity [m/s]
  • vd: down velocity [m/s]
  • fn: north specific force [m/s^2]
  • fe: east specific force [m/s^2]
  • fd: down specific force [m/s^2]
  • Cnb: direction cosine matrix (body to navigation) [-]
  • meas: scalar magnetometer measurement [nT]
  • dt: measurement time step [s]
  • itp_mapS: scalar map interpolation function (f(lat,lon) or f(lat,lon,alt))
  • x_nn: N x Nf data matrix for neural network (Nf is number of features)
  • m: neural network model, does not work with skip connections
  • y_norms: length-2 tuple of y normalizations, (y_bias,y_scale)
  • P0: initial covariance matrix
  • Qd: discrete time process/system noise matrix
  • R: measurement (white) noise variance
  • baro_tau: (optional) barometer time constant [s]
  • acc_tau: (optional) accelerometer time constant [s]
  • gyro_tau: (optional) gyroscope time constant [s]
  • fogm_tau: (optional) FOGM catch-all time constant [s]
  • date: (optional) measurement date (decimal year) for IGRF [yr]
  • core: (optional) if true, include core magnetic field in measurement
  • terms: (optional) Tolles-Lawson terms to use {:permanent,:induced,:eddy,:bias}

Returns:

  • filt_res: FILTres filter results struct
source
MagNav.ekf_online_nnMethod
ekf_online_nn(ins::INS, meas, itp_mapS, x_nn, m, y_norms, P0, Qd, R;
              baro_tau   = 3600.0,
              acc_tau    = 3600.0,
              gyro_tau   = 3600.0,
              fogm_tau   = 600.0,
              date       = get_years(2020,185),
              core::Bool = false)

Extended Kalman filter (EKF) with online learning of neural network weights.

Arguments:

  • ins: INS inertial navigation system struct
  • meas: scalar magnetometer measurement [nT]
  • itp_mapS: scalar map interpolation function (f(lat,lon) or f(lat,lon,alt))
  • x_nn: N x Nf data matrix for neural network (Nf is number of features)
  • m: neural network model, does not work with skip connections
  • y_norms: length-2 tuple of y normalizations, (y_bias,y_scale)
  • P0: initial covariance matrix
  • Qd: discrete time process/system noise matrix
  • R: measurement (white) noise variance
  • baro_tau: (optional) barometer time constant [s]
  • acc_tau: (optional) accelerometer time constant [s]
  • gyro_tau: (optional) gyroscope time constant [s]
  • fogm_tau: (optional) FOGM catch-all time constant [s]
  • date: (optional) measurement date (decimal year) for IGRF [yr]
  • core: (optional) if true, include core magnetic field in measurement

Returns:

  • filt_res: FILTres filter results struct
source
MagNav.ekf_online_nn_setupMethod
ekf_online_nn_setup(x, y, m, y_norms; N_sigma::Int = 1000)

Setup for extended Kalman filter (EKF) with online learning of neural network weights.

Arguments:

  • x: N x Nf data matrix (Nf is number of features)
  • y: length-N target vector
  • m: neural network model, does not work with skip connections
  • y_norms: tuple of y normalizations, i.e., (y_bias,y_scale)
  • N_sigma: (optional) number of neural network weights sets to use to create nn_sigma

Returns:

  • P0_nn: initial neural network weights covariance matrix
  • nn_sigma: initial neural network weights estimate std dev
source
MagNav.ekf_online_setupFunction
ekf_online_setup(flux::MagV, meas, ind = trues(length(meas));
                 Bt           = sqrt.(flux.x.^2+flux.y.^2+flux.z.^2)[ind],
                 λ            = 0.025,
                 terms        = [:permanent,:induced,:eddy,:bias],
                 pass1        = 0.1,
                 pass2        = 0.9,
                 fs           = 10.0,
                 pole::Int    = 4,
                 trim::Int    = 20,
                 N_sigma::Int = 100,
                 Bt_scale     = 50000)

Setup for extended Kalman filter (EKF) with online learning of Tolles-Lawson coefficients.

Arguments:

  • flux: MagV vector magnetometer measurement struct
  • meas: scalar magnetometer measurement [nT]
  • ind: selected data indices
  • Bt: (optional) magnitude of vector magnetometer measurements or scalar magnetometer measurements for modified Tolles-Lawson [nT]
  • λ: (optional) ridge parameter
  • terms: (optional) Tolles-Lawson terms to use {:permanent,:induced,:eddy,:bias}
  • pass1: (optional) first passband frequency [Hz]
  • pass2: (optional) second passband frequency [Hz]
  • fs: (optional) sampling frequency [Hz]
  • pole: (optional) number of poles for Butterworth filter
  • trim: (optional) number of elements to trim after filtering
  • N_sigma: (optional) number of Tolles-Lawson coefficient sets to use to create TL_sigma
  • Bt_scale: (optional) scaling factor for induced & eddy current terms [nT]

Returns:

  • x0_TL: initial Tolles-Lawson coefficient states
  • P0_TL: initial Tolles-Lawson covariance matrix
  • TL_sigma: Tolles-Lawson coefficients estimate std dev
source
MagNav.elasticnet_fitFunction
elasticnet_fit(x, y, α::Real = 0.99, no_norm = falses(size(x,2));
               λ::Real           = -1,
               data_norms::Tuple = (zeros(1,1),zeros(1,1),[0.0],[0.0]),
               l_segs::Vector    = [length(y)],
               silent::Bool      = false)

Fit an elastic net (ridge regression and/or Lasso) model to data.

Arguments:

  • x: N x Nf data matrix (Nf is number of features)
  • y: length-N target vector
  • α: (optional) ridge regression (α=0) vs Lasso (α=1) balancing parameter {0:1}
  • no_norm: (optional) length-Nf Boolean indices of features to not be normalized
  • λ: (optional) elastic net parameter, -1 to ignore & determine with cross-validation
  • data_norms: (optional) length-4 tuple of data normalizations, (x_bias,x_scale,y_bias,y_scale)
  • l_segs: (optional) length-N_lines vector of lengths of lines, sum(l_segs) = N
  • silent: (optional) if true, no print outs

Returns:

  • model: length-2 tuple of elastic net-based model, (length-Nf coefficients, bias)
  • data_norms: length-4 tuple of data normalizations, (x_bias,x_scale,y_bias,y_scale)
  • y_hat: length-N prediction vector
  • err: length-N mean-corrected (per line) error
source
MagNav.err_segsMethod
err_segs(y_hat, y, l_segs; silent::Bool = true)

Remove mean error from multiple individual flight lines within larger dataset.

Arguments:

  • y_hat: length-N prediction vector
  • y: length-N target vector
  • l_segs: length-N_lines vector of lengths of lines, sum(l_segs) = N
  • silent: (optional) if true, no print outs

Returns:

  • err: length-N mean-corrected (per line) error
source
MagNav.euler2dcmFunction
euler2dcm(roll, pitch, yaw, order::Symbol = :body2nav)

Converts a (Euler) roll-pitch-yaw (X-Y-Z) right-handed body to navigation frame rotation (or the opposite rotation), to a DCM (direction cosine matrix). Yaw is synonymous with azimuth and heading here. If frame 1 is rotated to frame 2, then the returned DCM, when pre-multiplied, rotates a vector in frame 1 into frame 2. There are 2 use cases:

  1. With order = :body2nav, the body frame is rotated in the standard

-roll, -pitch, -yaw sequence to the navigation frame. For example, if v1 is a 3x1 vector in the body frame [nose, right wing, down], then that vector rotated into the navigation frame [north, east, down] would be v2 = dcm * v1.

  1. With order = :nav2body, the navigation frame is rotated in the standard

yaw, pitch, roll sequence to the body frame. For example, if v1 is a 3x1 vector in the navigation frame [north, east, down], then that vector rotated into the body frame [nose, right wing, down] would be v2 = dcm * v1.

Reference: Titterton & Weston, Strapdown Inertial Navigation Technology, 2004, Section 3.6 (pg. 36-41 & 537).

Arguments:

  • roll: length-N roll angle [rad], right-handed rotation about x-axis
  • pitch: length-N pitch angle [rad], right-handed rotation about y-axis
  • yaw: length-N yaw angle [rad], right-handed rotation about z-axis
  • order: (optional) rotation order {:body2nav,:nav2body}

Returns:

  • dcm: 3 x 3 x N direction cosine matrix [-]
source
MagNav.eval_crlbMethod
eval_crlb(traj::Traj, crlb_P::Array)

Extract Cramér–Rao lower bound (CRLB) results.

Arguments:

  • traj: Traj trajectory struct
  • crlb_P: Cramér–Rao lower bound non-linear covariance matrix

Returns:

  • crlb_out: CRLBout Cramér–Rao lower bound extracted output struct
source
MagNav.eval_filtMethod
eval_filt(traj::Traj, ins::INS, filt_res::FILTres)

Extract filter results.

Arguments:

  • traj: Traj trajectory struct
  • ins: INS inertial navigation system struct
  • filt_res: FILTres filter results struct

Returns:

  • filt_out: FILTout filter extracted output struct
source
MagNav.eval_gsaFunction
eval_gsa(m::Chain, x, n::Int = min(10000,size(x,1)))

Global sensitivity analysis (GSA) with the Morris Method.

Reference: https://book.sciml.ai/notes/17-GlobalSensitivityAnalysis/

Reference: https://docs.sciml.ai/GlobalSensitivity/stable/methods/morris/

Arguments:

  • m: neural network model
  • x: N x Nf data matrix (Nf is number of features)
  • n: (optional) number of samples (instances) to use for explanation

Returns:

  • means: means of elementary effects
source
MagNav.eval_insMethod
eval_ins(traj::Traj, ins::INS)

Extract INS results.

Arguments:

  • traj: Traj trajectory struct
  • ins: INS inertial navigation system struct

Returns:

  • ins_out: INSout inertial navigation system extracted output struct
source
MagNav.eval_resultsMethod
eval_results(traj::Traj, ins::INS, filt_res::FILTres, crlb_P::Array)

Extract CRLB, INS, & filter results.

Arguments:

  • traj: Traj trajectory struct
  • ins: INS inertial navigation system struct
  • filt_res: FILTres filter results struct
  • crlb_P: Cramér–Rao lower bound non-linear covariance matrix

Returns:

  • crlb_out: CRLBout Cramér–Rao lower bound extracted output struct
  • ins_out: INSout inertial navigation system extracted output struct
  • filt_out: FILTout filter extracted output struct
source
MagNav.eval_shapleyFunction
eval_shapley(m::Chain, x, features::Vector{Symbol},
             N::Int      = min(10000,size(x,1)),
             num_mc::Int = 10)

Compute stochastic Shapley effects for global feature importance.

Reference: https://nredell.github.io/ShapML.jl/dev/#Examples-1

Arguments:

  • m: neural network model
  • x: N x Nf data matrix (Nf is number of features)
  • features: length-Nf feature vector (including components of TL A, etc.)
  • N: (optional) number of samples (instances) to use for explanation
  • num_mc: (optional) number of Monte Carlo simulations

Returns:

  • df_shap: DataFrame of Shapley effects
  • baseline_shap: intercept of Shapley effects
source
MagNav.fdmMethod
fdm(x::Vector; scheme::Symbol = :central)

Finite difference method (FDM) applied to x.

Arguments:

  • x: data vector
  • scheme: (optional) finite difference method scheme used
    • backward: 1st derivative 1st-order backward difference
    • forward: 1st derivative 1st-order forward difference
    • central: 1st derivative 2nd-order central difference
    • backward2: 1st derivative 2nd-order backward difference
    • forward2: 1st derivative 2nd-order forward difference
    • fourth: 4th derivative central difference

Returns:

  • dif: vector of finite differences (length of x)
source
MagNav.filter_events!Method
filter_events!(flight::Symbol, df_event::DataFrame;
               keyword::String = "",
               tt_lim::Tuple   = ())

Filter a DataFrame of in-flight events to only contain relevant events.

Arguments:

  • flight: flight name (e.g., :Flt1001)
  • df_event: lookup table (DataFrame) of in-flight events
FieldTypeDescription
flightSymbolflight name (e.g., :Flt1001)
ttRealtime of event [s]
eventStringevent description
  • keyword: (optional) keyword to search within events, case insensitive
  • tt_lim: (optional) length-2 start & end time limits (inclusive) [s]

Returns:

  • nothing: df_event is filtered
source
MagNav.filter_eventsMethod
filter_events(flight::Symbol, df_event::DataFrame;
              keyword::String = "",
              tt_lim::Tuple   = ())

Filter a DataFrame of in-flight events to only contain relevant events.

Arguments:

  • flight: flight name (e.g., :Flt1001)
  • df_event: lookup table (DataFrame) of in-flight events
FieldTypeDescription
flightSymbolflight name (e.g., :Flt1001)
ttRealtime of event [s]
eventStringevent description
  • keyword: (optional) keyword to search within events, case insensitive
  • tt_lim: (optional) length-2 start & end time limits (inclusive) [s]

Returns:

  • df_event: lookup table (DataFrame) of in-flight events, filtered
source
MagNav.fogmMethod
fogm(sigma, tau, dt, N)

First-order Gauss-Markov stochastic process. Represents unmeasureable time-correlated errors.

Arguments:

  • sigma: FOGM catch-all bias
  • tau: FOGM catch-all time constant [s]
  • dt: measurement time step [s]
  • N: number of samples (instances)

Returns:

  • x: FOGM data
source
MagNav.get_AxyFunction
get_Axy(lines, df_line::DataFrame,
        df_flight::DataFrame, df_map::DataFrame,
        features_setup::Vector{Symbol}   = [:mag_1_uc,:TL_A_flux_a];
        features_no_norm::Vector{Symbol} = Symbol[],
        y_type::Symbol     = :d,
        use_mag::Symbol    = :mag_1_uc,
        use_mag_c::Symbol  = :mag_1_c,
        use_vec::Symbol    = :flux_a,
        terms              = [:permanent,:induced,:eddy],
        terms_A            = [:permanent,:induced,:eddy,:bias],
        sub_diurnal::Bool  = false,
        sub_igrf::Bool     = false,
        bpf_mag::Bool      = false,
        reorient_vec::Bool = false,
        l_window::Int      = -1,
        mod_TL::Bool       = false,
        map_TL::Bool       = false,
        return_B::Bool     = false,
        silent::Bool       = true)

Get "external" Tolles-Lawson A matrix, x data matrix, & y target vector from multiple flight lines, possibly multiple flights. Optionally return Bt & B_dot used to create the "external" Tolles-Lawson A matrix.

Arguments:

  • lines: selected line number(s)
  • df_line: lookup table (DataFrame) of lines
FieldTypeDescription
flightSymbolflight name (e.g., :Flt1001)
lineRealline number, i.e., segments within flight
t_startRealstart time of line to use [s]
t_endRealend time of line to use [s]
map_nameSymbol(optional) name of magnetic anomaly map relevant to line, only used for y_type = :b, :c
  • df_flight: lookup table (DataFrame) of flight data files
FieldTypeDescription
flightSymbolflight name (e.g., :Flt1001)
xyz_typeSymbolsubtype of XYZ to use for flight data {:XYZ0,:XYZ1,:XYZ20,:XYZ21}
xyz_setRealflight dataset number (used to prevent improper mixing of datasets, such as different magnetometer locations)
xyz_fileStringpath/name of flight data CSV, HDF5, or MAT file (.csv, .h5, or .mat extension required)
  • df_map: lookup table (DataFrame) of map data files
FieldTypeDescription
map_nameSymbolname of magnetic anomaly map
map_fileStringpath/name of map data HDF5 or MAT file (.h5 or .mat extension required)
  • features_setup: vector of features to include
  • features_no_norm: (optional) vector of features to not normalize
  • y_type: (optional) y target type
    • :a = anomaly field #1, compensated tail stinger total field scalar magnetometer measurements
    • :b = anomaly field #2, interpolated magnetic anomaly map values
    • :c = aircraft field #1, difference between uncompensated cabin total field scalar magnetometer measurements and interpolated magnetic anomaly map values
    • :d = aircraft field #2, difference between uncompensated cabin and compensated tail stinger total field scalar magnetometer measurements
    • :e = BPF'd total field, bandpass filtered uncompensated cabin total field scalar magnetometer measurements
  • use_mag: (optional) uncompensated scalar magnetometer to use for y target vector {:mag_1_uc, etc.}, only used for y_type = :c, :d, :e
  • use_mag_c: (optional) compensated scalar magnetometer to use for y target vector {:mag_1_c, etc.}, only used for y_type = :a, :d
  • use_vec: (optional) vector magnetometer (fluxgate) to use for "external" Tolles-Lawson A matrix {:flux_a, etc.}
  • terms: (optional) Tolles-Lawson terms to use for A within x data matrix {:permanent,:induced,:eddy,:bias}
  • terms_A: (optional) Tolles-Lawson terms to use for "external" Tolles-Lawson A matrix {:permanent,:induced,:eddy,:bias}
  • sub_diurnal: (optional) if true, subtract diurnal from scalar magnetometer measurements
  • sub_igrf: (optional) if true, subtract IGRF from scalar magnetometer measurements
  • bpf_mag: (optional) if true, bpf scalar magnetometer measurements in x data matrix
  • reorient_vec: (optional) if true, align vector magnetometer measurements with body frame
  • l_window: (optional) trim data by N % l_window, -1 to ignore
  • mod_TL: (optional) if true, create modified "external" Tolles-Lawson A matrix with use_mag
  • map_TL: (optional) if true, create map-based "external" Tolles-Lawson A matrix
  • return_B: (optional) if true, also return Bt & B_dot
  • silent: (optional) if true, no print outs

Returns:

  • A: N x N_TL "external" Tolles-Lawson A matrix (N_TL is number of Tolles-Lawson coefficients)
  • x: N x Nf data matrix (Nf is number of features)
  • y: length-N target vector
  • no_norm: length-Nf Boolean indices of features to not be normalized
  • features: length-Nf feature vector (including components of TL A, etc.)
  • l_segs: length-N_lines vector of lengths of lines, sum(l_segs) = N
  • Bt: if return_B = true, length-N magnitude of total field measurements used to create A [nT]
  • B_dot: if return_B = true, N x 3 finite differences of total field vector used to create A [nT]
source
MagNav.get_XYZMethod
get_XYZ(flight::Symbol, df_flight::DataFrame;
        tt_sort::Bool      = true,
        reorient_vec::Bool = false,
        silent::Bool       = false)

Get XYZ flight data from saved HDF5 file via DataFrame lookup.

Arguments:

  • flight: flight name (e.g., :Flt1001)
  • df_flight: lookup table (DataFrame) of flight data files
FieldTypeDescription
flightSymbolflight name (e.g., :Flt1001)
xyz_typeSymbolsubtype of XYZ to use for flight data {:XYZ0,:XYZ1,:XYZ20,:XYZ21}
xyz_setRealflight dataset number (used to prevent improper mixing of datasets, such as different magnetometer locations)
xyz_fileStringpath/name of flight data CSV, HDF5, or MAT file (.csv, .h5, or .mat extension required)
  • tt_sort: (optional) if true, sort data by time (instead of line)
  • reorient_vec: (optional) if true, align vector magnetometer measurements with body frame
  • silent: (optional) if true, no print outs

Returns:

  • xyz: XYZ flight data struct
source
MagNav.get_XYZ0Function
get_XYZ0(xyz_file::String,
         traj_field::Symbol = :traj,
         ins_field::Symbol  = :ins_data;
         info::String       = splitpath(xyz_file)[end],
         flight             = 1,
         line               = 1,
         year               = 2023,
         doy                = 154,
         dt                 = 0.1,
         tt_sort::Bool      = true,
         silent::Bool       = false)

Get the minimum dataset required for MagNav from saved CSV, HDF5, or MAT file. Not all fields within the XYZ0 flight data struct are required. The minimum data required in the CSV, HDF5, or MAT file includes:

  • lat, lon, alt (position)
  • mag_1_c OR mag_1_uc (scalar magnetometer measurements)

All other fields can be computed/simulated.

If a CSV or HDF5 file is provided, the possible columns/fields in the file are:

FieldTypeDescription
dtscalarmeasurement time step [s]
ttvectortime [s]
latvectorlatitude [deg]
lonvectorlongitude [deg]
altvectoraltitude [m]
vnvectornorth velocity [m/s]
vevectoreast velocity [m/s]
vdvectordown velocity [m/s]
fnvectornorth specific force [m/s]
fevectoreast specific force [m/s]
fdvectordown specific force [m/s]
Cnb3x3xNdirection cosine matrix (body to navigation) [-], not valid for CSV file (use roll, pitch, & yaw instead)
rollvectorroll [deg]
pitchvectorpitch [deg]
yawvectoryaw [deg]
ins_dtscalarINS measurement time step [s]
ins_ttvectorINS time [s]
ins_latvectorINS latitude [deg]
ins_lonvectorINS longitude [deg]
ins_altvectorINS altitude [m]
ins_vnvectorINS north velocity [m/s]
ins_vevectorINS east velocity [m/s]
ins_vdvectorINS down velocity [m/s]
ins_fnvectorINS north specific force [m/s]
ins_fevectorINS east specific force [m/s]
ins_fdvectorINS down specific force [m/s]
ins_Cnb3x3xNINS direction cosine matrix (body to navigation) [-], not valid for CSV file (use ins_roll, ins_pitch, & ins_yaw instead)
ins_rollvectorINS roll [deg]
ins_pitchvectorINS pitch [deg]
ins_yawvectorINS yaw [deg]
ins_P17x17xNINS covariance matrix, only relevant for simulated data, otherwise zeros [-], not valid for CSV file
flux_a_xvectorFlux A x-direction magnetic field [nT]
flux_a_yvectorFlux A y-direction magnetic field [nT]
flux_a_zvectorFlux A z-direction magnetic field [nT]
flux_a_tvectorFlux A total magnetic field [nT]
flightvectorflight number(s)
linevectorline number(s), i.e., segments within flight
yearvectoryear
doyvectorday of year
diurnalvectormeasured diurnal, i.e., temporal variations or space weather effects [nT]
igrfvectorInternational Geomagnetic Reference Field (IGRF), i.e., core field [nT]
mag_1_cvectorMag 1 compensated (clean) scalar magnetometer measurements [nT]
mag_1_ucvectorMag 1 uncompensated (corrupted) scalar magnetometer measurements [nT]

If a MAT file is provided, the above fields may also be provided, but the non-INS fields should be within the specified traj_field MAT struct and the INS fields should be within the specified ins_field MAT struct and without ins_ prefixes. This is the standard way the MATLAB-companion outputs data.

Arguments:

  • xyz_file: path/name of flight data CSV, HDF5, or MAT file (.csv, .h5, or .mat extension required)
  • traj_field: (optional) trajectory struct field within MAT file to use, not relevant for CSV or HDF5 file
  • ins_field: (optional) INS struct field within MAT file to use, :none if unavailable, not relevant for CSV or HDF5 file
  • tt_sort: (optional) if true, sort data by time (instead of line)
  • silent: (optional) if true, no print outs

If not provided in xyz_file:

  • info: (optional) flight data information
  • flight: (optional) flight number
  • line: (optional) line number, i.e., segment within flight
  • year: (optional) year
  • doy: (optional) day of year
  • dt: (optional) measurement time step [s]

Returns:

  • xyz: XYZ0 flight data struct
source
MagNav.get_XYZ1Function
get_XYZ1(xyz_file::String,
         traj_field::Symbol = :traj,
         ins_field::Symbol  = :ins_data;
         info::String       = splitpath(xyz_file)[end],
         flight             = 1,
         line               = 1,
         year               = 2023,
         doy                = 154,
         dt                 = 0.1,
         tt_sort::Bool      = true,
         silent::Bool       = false)

Get the minimum dataset required for MagNav from saved CSV, HDF5, or MAT file. Not all fields within the XYZ1 flight data struct are required. The minimum data required in the CSV, HDF5, or MAT file includes:

  • lat, lon, alt (position)
  • mag_1_c OR mag_1_uc (scalar magnetometer measurements)

All other fields can be computed/simulated, except flux_b, mag_2_c, mag_3_c, mag_2_uc, mag_3_uc, aux_1, aux_2, and aux_3.

If a CSV or HDF5 file is provided, the possible columns/fields in the file are:

FieldTypeDescription
dtscalarmeasurement time step [s]
ttvectortime [s]
latvectorlatitude [deg]
lonvectorlongitude [deg]
altvectoraltitude [m]
vnvectornorth velocity [m/s]
vevectoreast velocity [m/s]
vdvectordown velocity [m/s]
fnvectornorth specific force [m/s]
fevectoreast specific force [m/s]
fdvectordown specific force [m/s]
Cnb3x3xNdirection cosine matrix (body to navigation) [-], not valid for CSV file (use roll, pitch, & yaw instead)
rollvectorroll [deg]
pitchvectorpitch [deg]
yawvectoryaw [deg]
ins_dtscalarINS measurement time step [s]
ins_ttvectorINS time [s]
ins_latvectorINS latitude [deg]
ins_lonvectorINS longitude [deg]
ins_altvectorINS altitude [m]
ins_vnvectorINS north velocity [m/s]
ins_vevectorINS east velocity [m/s]
ins_vdvectorINS down velocity [m/s]
ins_fnvectorINS north specific force [m/s]
ins_fevectorINS east specific force [m/s]
ins_fdvectorINS down specific force [m/s]
ins_Cnb3x3xNINS direction cosine matrix (body to navigation) [-], not valid for CSV file (use ins_roll, ins_pitch, & ins_yaw instead)
ins_rollvectorINS roll [deg]
ins_pitchvectorINS pitch [deg]
ins_yawvectorINS yaw [deg]
ins_P17x17xNINS covariance matrix, only relevant for simulated data, otherwise zeros [-], not valid for CSV file
flux_a_xvectorFlux A x-direction magnetic field [nT]
flux_a_yvectorFlux A y-direction magnetic field [nT]
flux_a_zvectorFlux A z-direction magnetic field [nT]
flux_a_tvectorFlux A total magnetic field [nT]
flux_b_xvectorFlux B x-direction magnetic field [nT]
flux_b_yvectorFlux B y-direction magnetic field [nT]
flux_b_zvectorFlux B z-direction magnetic field [nT]
flux_b_tvectorFlux B total magnetic field [nT]
flightvectorflight number(s)
linevectorline number(s), i.e., segments within flight
yearvectoryear
doyvectorday of year
diurnalvectormeasured diurnal, i.e., temporal variations or space weather effects [nT]
igrfvectorInternational Geomagnetic Reference Field (IGRF), i.e., core field [nT]
mag_1_cvectorMag 1 compensated (clean) scalar magnetometer measurements [nT]
mag_2_cvectorMag 2 compensated (clean) scalar magnetometer measurements [nT]
mag_3_cvectorMag 3 compensated (clean) scalar magnetometer measurements [nT]
mag_1_ucvectorMag 1 uncompensated (corrupted) scalar magnetometer measurements [nT]
mag_2_ucvectorMag 2 uncompensated (corrupted) scalar magnetometer measurements [nT]
mag_3_ucvectorMag 3 uncompensated (corrupted) scalar magnetometer measurements [nT]
aux_1vectorflexible-use auxiliary data 1
aux_2vectorflexible-use auxiliary data 2
aux_3vectorflexible-use auxiliary data 3

If a MAT file is provided, the above fields may also be provided, but the non-INS fields should be within the specified traj_field MAT struct and the INS fields should be within the specified ins_field MAT struct and without ins_ prefixes. This is the standard way the MATLAB-companion outputs data.

Arguments:

  • xyz_file: path/name of flight data CSV, HDF5, or MAT file (.csv, .h5, or .mat extension required)
  • traj_field: (optional) trajectory struct field within MAT file to use, not relevant for CSV or HDF5 file
  • ins_field: (optional) INS struct field within MAT file to use, :none if unavailable, not relevant for CSV or HDF5 file
  • tt_sort: (optional) if true, sort data by time (instead of line)
  • silent: (optional) if true, no print outs

If not provided in xyz_file:

  • info: (optional) flight data information
  • flight: (optional) flight number
  • line: (optional) line number, i.e., segment within flight
  • year: (optional) year
  • doy: (optional) day of year
  • dt: (optional) measurement time step [s]

Returns:

  • xyz: XYZ1 flight data struct
source
MagNav.get_XYZ20Method
get_XYZ20(xyz_160_h5::String, xyz_h5::String;
          info::String = splitpath(xyz_160_h5)[end] * " & " * splitpath(xyz_h5)[end],
          silent::Bool = false)

Get 160 Hz (partial) XYZ20 flight data from saved HDF5 file and combine with 10 Hz XYZ20 flight data from another saved HDF5 file. Data is time sorted to ensure data is aligned.

Arguments:

  • xyz_160_h5: path/name of 160 Hz flight data HDF5 file (.h5 extension optional)
  • xyz_h5: path/name of 10 Hz flight data HDF5 file (.h5 extension optional)
  • info: (optional) flight data information
  • silent: (optional) if true, no print outs

Returns:

  • xyz: XYZ20 flight data struct
source
MagNav.get_XYZ20Method
get_XYZ20(xyz_h5::String;
          info::String  = splitpath(xyz_h5)[end],
          tt_sort::Bool = true,
          silent::Bool  = false)

Get XYZ20 flight data from saved HDF5 file. Based on 2020 SGL data fields.

Arguments:

  • xyz_h5: path/name of flight data HDF5 file (.h5 extension optional)
  • info: (optional) flight data information
  • tt_sort: (optional) if true, sort data by time (instead of line)
  • silent: (optional) if true, no print outs

Returns:

  • xyz: XYZ20 flight data struct
source
MagNav.get_XYZ21Method
get_XYZ21(xyz_h5::String;
          info::String  = splitpath(xyz_h5)[end],
          tt_sort::Bool = true,
          silent::Bool  = false)

Get XYZ21 flight data from saved HDF5 file. Based on 2021 SGL data fields.

Arguments:

  • xyz_h5: path/name of flight data HDF5 file (.h5 extension optional)
  • info: (optional) flight data information
  • tt_sort: (optional) if true, sort data by time (instead of line)
  • silent: (optional) if true, no print outs

Returns:

  • xyz: XYZ21 flight data struct
source
MagNav.get_autocorFunction
get_autocor(x::Vector, dt = 0.1, dt_max = 300.0)

Get autocorrelation of data (e.g., actual - expected measurements).

Arguments:

  • x: data vector
  • dt: (optional) measurement time step [s]
  • dt_max: (optional) maximum time step to evaluate [s]

Returns:

  • sigma: standard deviation
  • tau: autocorrelation decay to e^-1 of x [s]
source
MagNav.get_bpfMethod
get_bpf(; pass1 = 0.1, pass2 = 0.9, fs = 10.0, pole::Int = 4)

Create a Butterworth bandpass (or low-pass or high-pass) filter object. Set pass1 = -1 for low-pass filter or pass2 = -1 for high-pass filter.

Arguments:

  • pass1: (optional) first passband frequency [Hz]
  • pass2: (optional) second passband frequency [Hz]
  • fs: (optional) sampling frequency [Hz]
  • pole: (optional) number of poles for Butterworth filter

Returns:

  • bpf: filter object
source
MagNav.get_cached_mapMethod
get_cached_map(map_cache::Map_Cache, lat::Real, lon::Real, alt::Real;
               silent::Bool = false)

Get cached map at specific location.

Arguments:

  • map_cache: Map_Cache map cache struct
  • lat: latitude [rad]
  • lon: longitude [rad]
  • alt: altitude [m]
  • silent: (optional) if true, no print outs

Returns:

  • itp_mapS: scalar map interpolation function (f(lat,lon) at alt)
source
MagNav.get_comp_paramsFunction
get_comp_params(comp_params_bson::String, silent::Bool = false)

Get aeromagnetic compensation parameters from saved BSON file.

Arguments:

  • comp_params_bson: path/name of aeromagnetic compensation parameters BSON file (.bson extension optional)
  • silent: (optional) if true, no print outs

Returns:

  • comp_params: CompParams aeromagnetic compensation parameters struct, either:
    • NNCompParams: neural network-based aeromagnetic compensation parameters struct
    • LinCompParams: linear aeromagnetic compensation parameters struct
source
MagNav.get_fluxFunction
get_flux(flux_file::String,
         use_vec::Symbol = :flux_a,
         field::Symbol   = :traj)

Get vector magnetometer data from saved CSV, HDF5, or MAT file.

If a CSV or HDF5 file is provided, the possible columns/fields in the file are:

FieldTypeDescription
use_vec*_xvectorx-direction magnetic field [nT]
use_vec*_yvectory-direction magnetic field [nT]
use_vec*_zvectorz-direction magnetic field [nT]
use_vec*_tvectortotal magnetic field [nT], optional

If a MAT file is provided, the above fields may also be provided, but they should be within the specified field MAT struct. This is the standard way the MATLAB-companion outputs data.

Arguments:

  • flux_file: path/name of vector magnetometer data CSV, HDF5, or MAT file (.csv, .h5, or .mat extension required)
  • use_vec: (optional) vector magnetometer (fluxgate) to use
  • field: (optional) struct field within MAT file to use, not relevant for CSV or HDF5 file

Returns:

  • flux: MagV vector magnetometer measurement struct
source
MagNav.get_igrfFunction
get_igrf(xyz::XYZ, ind = trues(xyz.traj.N);
         frame::Symbol   = :body,
         norm_igrf::Bool = false,
         check_xyz::Bool = true)

Get the IGRF Earth vector in the body or navigation frame given an XYZ flight data struct containing trajectory information, valid indices, a start date in IGRF time (years since 0 CE), and reference frame.

Arguments:

  • xyz: XYZ flight data struct
  • ind: (optional) selected data indices
  • frame: (optional) desired reference frame {:body,:nav}
  • norm_igrf: (optional) if true, normalize igrf_vec
  • check_xyz: (optional) if true, cross-check with igrf field in xyz

Returns:

  • igrf_vec: length-N stacked vector of 3 IGRF coordinates in frame
source
MagNav.get_indMethod
get_ind(xyz::XYZ, lines, df_line::DataFrame;
        splits        = (1),
        l_window::Int = -1)

Get BitVector of selected data indices for further analysis via DataFrame lookup.

Arguments:

  • xyz: XYZ flight data struct
  • lines: selected line number(s)
  • df_line: lookup table (DataFrame) of lines
FieldTypeDescription
flightSymbolflight name (e.g., :Flt1001)
lineRealline number, i.e., segments within flight
t_startRealstart time of line to use [s]
t_endRealend time of line to use [s]
map_nameSymbol(optional) name of magnetic anomaly map relevant to line
  • splits: (optional) data splits, must sum to 1
  • l_window: (optional) trim data by N % l_window, -1 to ignore

Returns:

  • ind: BitVector (or tuple of BitVector) of selected data indices
source
MagNav.get_indMethod
get_ind(xyz::XYZ, line::Real, df_line::DataFrame;
        splits        = (1),
        l_window::Int = -1)

Get BitVector of indices for further analysis via DataFrame lookup.

Arguments:

  • xyz: XYZ flight data struct
  • line: line number
  • df_line: lookup table (DataFrame) of lines
FieldTypeDescription
flightSymbolflight name (e.g., :Flt1001)
lineRealline number, i.e., segments within flight
t_startRealstart time of line to use [s]
t_endRealend time of line to use [s]
map_nameSymbol(optional) name of magnetic anomaly map relevant to line
  • splits: (optional) data splits, must sum to 1
  • l_window: (optional) trim data by N % l_window, -1 to ignore

Returns:

  • ind: BitVector (or tuple of BitVector) of selected data indices
source
MagNav.get_indMethod
get_ind(xyz::XYZ;
        ind    = trues(xyz.traj.N),
        lines  = (),
        tt_lim = (),
        splits = (1))

Get BitVector of indices for further analysis from specified indices (subset), lines, and/or time range. Any or all of these may be used. Defaults to use all indices, lines, and times.

Arguments:

  • xyz: XYZ flight data struct
  • ind: (optional) selected data indices
  • lines: (optional) selected line number(s)
  • tt_lim: (optional) end time limit or length-2 start & end time limits (inclusive) [s]
  • splits: (optional) data splits, must sum to 1

Returns:

  • ind: BitVector (or tuple of BitVector) of selected data indices
source
MagNav.get_indMethod
get_ind(tt::Vector, line::Vector;
        ind    = trues(length(tt)),
        lines  = (),
        tt_lim = (),
        splits = (1))

Get BitVector of indices for further analysis from specified indices (subset), lines, and/or time range. Any or all of these may be used. Defaults to use all indices, lines, and times.

Arguments:

  • tt: time [s]
  • line: line number(s)
  • ind: (optional) selected data indices
  • lines: (optional) selected line number(s)
  • tt_lim: (optional) end time limit or length-2 start & end time limits (inclusive) [s]
  • splits: (optional) data splits, must sum to 1

Returns:

  • ind: BitVector (or tuple of BitVector) of selected data indices
source
MagNav.get_insFunction
get_ins(xyz::XYZ, ind = trues(xyz.traj.N);
        N_zero_ll::Int  = 0,
        t_zero_ll::Real = 0,
        err::Real       = 0.0)

Get inertial navigation system data at specific indices, possibly zeroed.

Arguments:

  • xyz: XYZ flight data struct
  • ind: (optional) selected data indices
  • N_zero_ll: (optional) number of samples (instances) to zero INS lat/lon to truth (xyz.traj)
  • t_zero_ll: (optional) length of time to zero INS lat/lon to truth (xyz.traj), overwrites N_zero_ll
  • err: (optional) additional position error [m]

Returns:

  • ins: INS inertial navigation system struct at ind
source
MagNav.get_insFunction
get_ins(ins_file::String, field::Symbol = :ins_data;
        dt            = 0.1,
        tt_sort::Bool = true,
        silent::Bool  = false)

Get inertial navigation system data from saved CSV, HDF5, or MAT file. The only required fields are ins_lat, ins_lon, and ins_alt (position).

If a CSV or HDF5 file is provided, the possible columns/fields in the file are:

FieldTypeDescription
ins_dtscalarINS measurement time step [s]
ins_ttvectorINS time [s]
ins_latvectorINS latitude [deg]
ins_lonvectorINS longitude [deg]
ins_altvectorINS altitude [m]
ins_vnvectorINS north velocity [m/s]
ins_vevectorINS east velocity [m/s]
ins_vdvectorINS down velocity [m/s]
ins_fnvectorINS north specific force [m/s]
ins_fevectorINS east specific force [m/s]
ins_fdvectorINS down specific force [m/s]
ins_Cnb3x3xNINS direction cosine matrix (body to navigation) [-], not valid for CSV file (use ins_roll, ins_pitch, & ins_yaw instead)
ins_rollvectorINS roll [deg]
ins_pitchvectorINS pitch [deg]
ins_yawvectorINS yaw [deg]
ins_P17x17xNINS covariance matrix, only relevant for simulated data, otherwise zeros [-], not valid for CSV file

If a MAT file is provided, the above fields may also be provided, but they should be within the specified field MAT struct and without ins_ prefixes. This is the standard way the MATLAB-companion outputs data.

Arguments:

  • ins_file: path/name of INS data CSV, HDF5, or MAT file (.csv, .h5, or .mat extension required)
  • field: (optional) struct field within MAT file to use, not relevant for CSV or HDF5 file
  • dt: (optional) measurement time step [s], only used if not in ins_file
  • silent: (optional) if true, no print outs

Returns:

  • ins: INS inertial navigation system struct
source
MagNav.get_mapFunction
get_map(map_file::String   = namad,
        map_field::Symbol  = :map_data;
        map_info::String   = splitpath(map_file)[end],
        map_units::Symbol  = :rad,
        file_units::Symbol = :deg,
        flip_map::Bool     = false)

Get map data from saved HDF5 or MAT file or folder containing CSV files. Maps are typically saved in :deg units, while :rad is used internally.

Arguments:

  • map_file: path/name of map data HDF5 or MAT file (.h5 or .mat extension required) or folder containing CSV files
  • map_field: (optional) struct field within MAT file to use, not relevant for CSV or HDF5 file
  • map_info: (optional) map information, only used if not in map_file
  • map_units: (optional) map xx/yy units to use in map_map {:rad,:deg}
  • file_units: (optional) map xx/yy units used in map_file {:rad,:deg}
  • flip_map: (optional) if true, vertically flip data from map file (possibly useful for CSV map)

Returns:

  • map_map: Map magnetic anomaly map struct
source
MagNav.get_mapFunction
get_map(map_name::Symbol, df_map::DataFrame,
        map_field::Symbol  = :map_data;
        map_info::String   = "$map_name",
        map_units::Symbol  = :rad,
        file_units::Symbol = :deg,
        flip_map::Bool     = false)

Get map data from saved HDF5 or MAT file or folder containing CSV files via DataFrame lookup. Maps are typically saved in :deg units, while :rad is used internally.

Arguments:

  • map_name: name of magnetic anomaly map
  • df_map: lookup table (DataFrame) of map data HDF5 and/or MAT files and/or folder containing CSV files
FieldTypeDescription
map_nameSymbolname of magnetic anomaly map
map_fileStringpath/name of map data HDF5 or MAT file (.h5 or .mat extension required) or folder containing CSV files
  • map_info: (optional) map information, only used if not in map_file
  • map_field: (optional) struct field within MAT file to use, not relevant for CSV or HDF5 file
  • map_units: (optional) map xx/yy units to use in map_map {:rad,:deg}
  • file_units: (optional) map xx/yy units used in files within df_map {:rad,:deg}
  • flip_map: (optional) if true, vertically flip data from map file (possibly useful for CSV map)

Returns:

  • map_map: Map magnetic anomaly map struct
source
MagNav.get_map_valFunction
get_map_val(map_map_vec::Vector, path::Path, ind = trues(path.N); α = 200)

Get scalar magnetic anomaly map values from multiple maps along a flight path. Each map in map_map_vec is upward and/or downward continued to alt as necessary.

Arguments:

  • map_map_vec: vector of Map magnetic anomaly map structs
  • path: Path struct, i.e., Traj trajectory struct, INS inertial navigation system struct, or FILTout filter extracted output struct
  • ind: (optional) selected data indices
  • α: (optional) regularization parameter for downward continuation

Returns:

  • map_vals: vector of scalar magnetic anomaly map values
source
MagNav.get_map_valFunction
get_map_val(map_map::Map, path::Path, ind = trues(path.N);
            α=200, return_itp::Bool = false)

Get scalar magnetic anomaly map values along a flight path. map_map is upward and/or downward continued to alt as necessary.

Arguments:

  • map_map: Map magnetic anomaly map struct
  • path: Path struct, i.e., Traj trajectory struct, INS inertial navigation system struct, or FILTout filter extracted output struct
  • ind: (optional) selected data indices
  • α: (optional) regularization parameter for downward continuation
  • return_itp: (optional) if true, also return map_itp

Returns:

  • map_val: scalar magnetic anomaly map values
  • map_itp: if return_itp = true, map interpolation function (f(lat,lon) or f(lat,lon,alt))
source
MagNav.get_map_valMethod
get_map_val(map_map::Map, lat, lon, alt; α = 200, return_itp::Bool = false)

Get scalar magnetic anomaly map values along a flight path. map_map is upward and/or downward continued to alt as necessary (except if drape map).

Arguments:

  • map_map: Map magnetic anomaly map struct
  • lat: latitude [rad]
  • lon: longitude [rad]
  • alt: altitude [m]
  • α: (optional) regularization parameter for downward continuation
  • return_itp: (optional) if true, also return itp_map

Returns:

  • map_val: scalar magnetic anomaly map values
  • itp_map: if return_itp = true, map interpolation function (f(lat,lon) or f(lat,lon,alt))
source
MagNav.get_nn_mFunction
get_nn_m(Nf::Int, Ny::Int = 1;
         hidden                = [8],
         activation::Function  = swish,
         final_bias::Bool      = true,
         skip_con::Bool        = false,
         model_type::Symbol    = :m1
         l_window::Int         = 5,
         tf_layer_type::Symbol = :postlayer,
         tf_norm_type::Symbol  = :batch,
         dropout_prob::Real    = 0.2,
         N_tf_head::Int        = 8,
         tf_gain::Real         = 1.0)

Get neural network model. Valid for 0-3 hidden layers, except for model_type = :m3w, :m3tf, which are only valid for 1 or 2 hidden layers.

Arguments:

  • Nf: length of input (feature) layer
  • Ny: (optional) length of output layer
  • hidden: (optional) hidden layers & nodes (e.g., [8,8] for 2 hidden layers, 8 nodes each)
  • activation: (optional) activation function
    • relu = rectified linear unit
    • σ = sigmoid (logistic function)
    • swish = self-gated
    • tanh = hyperbolic tan
    • run plot_activation() for a visual
  • final_bias: (optional) if true, include final layer bias
  • skip_con: (optional) if true, use skip connections, must have length(hidden) == 1
  • model_type: (optional) aeromagnetic compensation model type
  • l_window: (optional) temporal window length, only used for model_type = :m3w, :m3tf
  • tf_layer_type: (optional) transformer normalization layer before or after skip connection {:prelayer,:postlayer}, only used for model_type = :m3tf
  • tf_norm_type: (optional) normalization for transformer encoder {:batch,:layer,:none}, only used for model_type = :m3tf
  • dropout_prob: (optional) dropout rate, only used for model_type = :m3w, :m3tf
  • N_tf_head: (optional) number of attention heads, only used for model_type = :m3tf
  • tf_gain: (optional) weight initialization parameter, only used for model_type = :m3tf

Returns:

  • m: neural network model
source
MagNav.get_optimal_rotation_matrixMethod
get_optimal_rotation_matrix(v1s, v2s)

Get the 3 x 3 rotation matrix rotating the directions of v1s into v2s. Uses the Kabsch algorithm.

Reference: https://en.wikipedia.org/wiki/Kabsch_algorithm

Arguments:

  • v1s: N x 3 matrix for first set of 3D points
  • v2s: N x 3 matrix for second set of 3D points

Returns:

  • R: 3D matrix rotatating v1s into v2s' directions
source
MagNav.get_pinsonMethod
get_pinson(nx::Int, lat, vn, ve, vd, fn, fe, fd, Cnb;
           baro_tau         = 3600.0,
           acc_tau          = 3600.0,
           gyro_tau         = 3600.0,
           fogm_tau         = 600.0,
           vec_states::Bool = false,
           fogm_state::Bool = true,
           k1=3e-2, k2=3e-4, k3=1e-6)

Get the nx x nx Pinson dynamics matrix. States (errors) are:

NumStateUnitsDescription
1latradlatitude
2lonradlongitude
3altmaltitude
4vnm/snorth velocity
5vem/seast velocity
6vdm/sdown velocity
7tnradnorth tilt (attitude)
8teradeast tilt (attitude)
9tdraddown tilt (attitude)
10hambarometer aiding altitude
11a_hatm/s^2barometer aiding vertical acceleration
12axm/s^2x accelerometer
13aym/s^2y accelerometer
14azm/s^2z accelerometer
15gxrad/sx gyroscope
16gyrad/sy gyroscope
17gzrad/sz gyroscope
endSnTFOGM catch-all

Arguments:

  • nx: total state dimension
  • lat: latitude [rad]
  • vn: north velocity [m/s]
  • ve: east velocity [m/s]
  • vd: down velocity [m/s]
  • fn: north specific force [m/s^2]
  • fe: east specific force [m/s^2]
  • fd: down specific force [m/s^2]
  • Cnb: direction cosine matrix (body to navigation) [-]
  • baro_tau: (optional) barometer time constant [s]
  • acc_tau: (optional) accelerometer time constant [s]
  • gyro_tau: (optional) gyroscope time constant [s]
  • fogm_tau: (optional) FOGM catch-all time constant [s]
  • vec_states: (optional) if true, include vector magnetometer states
  • fogm_state: (optional) if true, include FOGM catch-all bias state
  • k1: (optional) barometer aiding constant [1/s]
  • k2: (optional) barometer aiding constant [1/s^2]
  • k3: (optional) barometer aiding constant [1/s^3]

Returns:

  • F: nx x nx Pinson matrix
source
MagNav.get_trajFunction
get_traj(xyz::XYZ, ind = trues(xyz.traj.N))

Get trajectory data at specific indices.

Arguments:

  • xyz: XYZ flight data struct
  • ind: (optional) selected data indices

Returns:

  • traj: Traj trajectory struct at ind
source
MagNav.get_trajFunction
get_traj(traj_file::String, field::Symbol = :traj;
         dt            = 0.1,
         tt_sort::Bool = true,
         silent::Bool  = false)

Get trajectory data from saved CSV, HDF5, or MAT file. The only required fields are lat, lon, and alt (position).

If a CSV or HDF5 file is provided, the possible columns/fields in the file are:

FieldTypeDescription
dtscalarmeasurement time step [s]
ttvectortime [s]
latvectorlatitude [deg]
lonvectorlongitude [deg]
altvectoraltitude [m]
vnvectornorth velocity [m/s]
vevectoreast velocity [m/s]
vdvectordown velocity [m/s]
fnvectornorth specific force [m/s]
fevectoreast specific force [m/s]
fdvectordown specific force [m/s]
Cnb3x3xNdirection cosine matrix (body to navigation) [-], not valid for CSV file (use roll, pitch, & yaw instead)
rollvectorroll [deg]
pitchvectorpitch [deg]
yawvectoryaw [deg]

If a MAT file is provided, the above fields may also be provided, but they should be within the specified field MAT struct. This is the standard way the MATLAB-companion outputs data.

Arguments:

  • traj_file: path/name of trajectory data CSV, HDF5, or MAT file (.csv, .h5, or .mat extension required)
  • field: (optional) struct field within MAT file to use, not relevant for CSV or HDF5 file
  • dt: (optional) measurement time step [s], only used if not in traj_file
  • silent: (optional) if true, no print outs

Returns:

  • traj: Traj trajectory struct
source
MagNav.get_xFunction
get_x(xyz::XYZ, ind = trues(xyz.traj.N),
      features_setup::Vector{Symbol}   = [:mag_1_uc,:TL_A_flux_a];
      features_no_norm::Vector{Symbol} = Symbol[],
      terms             = [:permanent,:induced,:eddy],
      sub_diurnal::Bool = false,
      sub_igrf::Bool    = false,
      bpf_mag::Bool     = false)

Get x data matrix.

Arguments:

  • xyz: XYZ flight data struct
  • ind: selected data indices
  • features_setup: vector of features to include
  • features_no_norm: (optional) vector of features to not normalize
  • terms: (optional) Tolles-Lawson terms to use {:permanent,:induced,:eddy,:bias}
  • sub_diurnal: (optional) if true, subtract diurnal from scalar magnetometer measurements
  • sub_igrf: (optional) if true, subtract IGRF from scalar magnetometer measurements
  • bpf_mag: (optional) if true, bpf scalar magnetometer measurements

Returns:

  • x: N x Nf data matrix (Nf is number of features)
  • no_norm: length-Nf Boolean indices of features to not be normalized
  • features: length-Nf feature vector (including components of TL A, etc.)
  • l_segs: length-N_lines vector of lengths of lines, sum(l_segs) = N
source
MagNav.get_xFunction
get_x(lines, df_line::DataFrame, df_flight::DataFrame,
      features_setup::Vector{Symbol}   = [:mag_1_uc,:TL_A_flux_a];
      features_no_norm::Vector{Symbol} = Symbol[],
      terms              = [:permanent,:induced,:eddy],
      sub_diurnal::Bool  = false,
      sub_igrf::Bool     = false,
      bpf_mag::Bool      = false,
      reorient_vec::Bool = false,
      l_window::Int      = -1,
      silent::Bool       = true)

Get x data matrix from multiple flight lines, possibly multiple flights.

Arguments:

  • lines: selected line number(s)
  • df_line: lookup table (DataFrame) of lines
FieldTypeDescription
flightSymbolflight name (e.g., :Flt1001)
lineRealline number, i.e., segments within flight
t_startRealstart time of line to use [s]
t_endRealend time of line to use [s]
map_nameSymbol(optional) name of magnetic anomaly map relevant to line
  • df_flight: lookup table (DataFrame) of flight data files
FieldTypeDescription
flightSymbolflight name (e.g., :Flt1001)
xyz_typeSymbolsubtype of XYZ to use for flight data {:XYZ0,:XYZ1,:XYZ20,:XYZ21}
xyz_setRealflight dataset number (used to prevent improper mixing of datasets, such as different magnetometer locations)
xyz_fileStringpath/name of flight data CSV, HDF5, or MAT file (.csv, .h5, or .mat extension required)
  • features_setup: vector of features to include
  • features_no_norm: (optional) vector of features to not normalize
  • terms: (optional) Tolles-Lawson terms to use {:permanent,:induced,:eddy,:bias}
  • sub_diurnal: (optional) if true, subtract diurnal from scalar magnetometer measurements
  • sub_igrf: (optional) if true, subtract IGRF from scalar magnetometer measurements
  • bpf_mag: (optional) if true, bpf scalar magnetometer measurements
  • reorient_vec: (optional) if true, align vector magnetometer measurements with body frame
  • l_window: (optional) trim data by N % l_window, -1 to ignore
  • silent: (optional) if true, no print outs

Returns:

  • x: N x Nf data matrix (Nf is number of features)
  • no_norm: length-Nf Boolean indices of features to not be normalized
  • features: length-Nf feature vector (including components of TL A, etc.)
  • l_segs: length-N_lines vector of lengths of lines, sum(l_segs) = N
source
MagNav.get_xFunction
get_x(xyz_vec::Vector{XYZ}, ind_vec,
      features_setup::Vector{Symbol}   = [:mag_1_uc,:TL_A_flux_a];
      features_no_norm::Vector{Symbol} = Symbol[],
      terms             = [:permanent,:induced,:eddy],
      sub_diurnal::Bool = false,
      sub_igrf::Bool    = false,
      bpf_mag::Bool     = false)

Get x data matrix from multiple XYZ flight data structs.

Arguments:

  • xyz_vec: vector of XYZ flight data structs
  • ind_vec: vector of selected data indices
  • features_setup: vector of features to include
  • features_no_norm: (optional) vector of features to not normalize
  • terms: (optional) Tolles-Lawson terms to use {:permanent,:induced,:eddy,:bias}
  • sub_diurnal: (optional) if true, subtract diurnal from scalar magnetometer measurements
  • sub_igrf: (optional) if true, subtract IGRF from scalar magnetometer measurements
  • bpf_mag: (optional) if true, bpf scalar magnetometer measurements

Returns:

  • x: N x Nf data matrix (Nf is number of features)
  • no_norm: length-Nf Boolean indices of features to not be normalized
  • features: length-Nf feature vector (including components of TL A, etc.)
  • l_segs: length-N_lines vector of lengths of lines, sum(l_segs) = N
source
MagNav.get_yFunction
get_y(xyz::XYZ, ind = trues(xyz.traj.N),
      map_val           = -1);
      y_type::Symbol    = :d,
      use_mag::Symbol   = :mag_1_uc,
      use_mag_c::Symbol = :mag_1_c,
      sub_diurnal::Bool = false,
      sub_igrf::Bool    = false)

Get y target vector.

Arguments:

  • xyz: XYZ flight data struct
  • ind: selected data indices
  • map_val: (optional) scalar magnetic anomaly map values, only used for y_type = :b
  • y_type: (optional) y target type
    • :a = anomaly field #1, compensated tail stinger total field scalar magnetometer measurements
    • :b = anomaly field #2, interpolated magnetic anomaly map values
    • :c = aircraft field #1, difference between uncompensated cabin total field scalar magnetometer measurements and interpolated magnetic anomaly map values
    • :d = aircraft field #2, difference between uncompensated cabin and compensated tail stinger total field scalar magnetometer measurements
    • :e = BPF'd total field, bandpass filtered uncompensated cabin total field scalar magnetometer measurements
  • use_mag: (optional) uncompensated scalar magnetometer to use for y target vector {:mag_1_uc, etc.}, only used for y_type = :c, :d, :e
  • use_mag_c: (optional) compensated scalar magnetometer to use for y target vector {:mag_1_c, etc.}, only used for y_type = :a, :d
  • sub_diurnal: (optional) if true, subtract diurnal from scalar magnetometer measurements
  • sub_igrf: (optional) if true, subtract IGRF from scalar magnetometer measurements

Returns:

  • y: length-N target vector
source
MagNav.get_yMethod
get_y(lines, df_line::DataFrame, df_flight::DataFrame,
      df_map::DataFrame;
      y_type::Symbol    = :d,
      use_mag::Symbol   = :mag_1_uc,
      use_mag_c::Symbol = :mag_1_c,
      sub_diurnal::Bool = false,
      sub_igrf::Bool    = false,
      l_window::Int     = -1,
      silent::Bool      = true)

Get y target vector from multiple flight lines, possibly multiple flights.

Arguments:

  • lines: selected line number(s)
  • df_line: lookup table (DataFrame) of lines
FieldTypeDescription
flightSymbolflight name (e.g., :Flt1001)
lineRealline number, i.e., segments within flight
t_startRealstart time of line to use [s]
t_endRealend time of line to use [s]
map_nameSymbol(optional) name of magnetic anomaly map relevant to line, only used for y_type = :b, :c
  • df_flight: lookup table (DataFrame) of flight data files
FieldTypeDescription
flightSymbolflight name (e.g., :Flt1001)
xyz_typeSymbolsubtype of XYZ to use for flight data {:XYZ0,:XYZ1,:XYZ20,:XYZ21}
xyz_setRealflight dataset number (used to prevent improper mixing of datasets, such as different magnetometer locations)
xyz_fileStringpath/name of flight data CSV, HDF5, or MAT file (.csv, .h5, or .mat extension required)
  • df_map: lookup table (DataFrame) of map data files
FieldTypeDescription
map_nameSymbolname of magnetic anomaly map
map_fileStringpath/name of map data HDF5 or MAT file (.h5 or .mat extension required)
  • y_type: (optional) y target type
    • :a = anomaly field #1, compensated tail stinger total field scalar magnetometer measurements
    • :b = anomaly field #2, interpolated magnetic anomaly map values
    • :c = aircraft field #1, difference between uncompensated cabin total field scalar magnetometer measurements and interpolated magnetic anomaly map values
    • :d = aircraft field #2, difference between uncompensated cabin and compensated tail stinger total field scalar magnetometer measurements
    • :e = BPF'd total field, bandpass filtered uncompensated cabin total field scalar magnetometer measurements
  • use_mag: (optional) uncompensated scalar magnetometer to use for y target vector {:mag_1_uc, etc.}, only used for y_type = :c, :d, :e
  • use_mag_c: (optional) compensated scalar magnetometer to use for y target vector {:mag_1_c, etc.}, only used for y_type = :a, :d
  • sub_diurnal: (optional) if true, subtract diurnal from scalar magnetometer measurements
  • sub_igrf: (optional) if true, subtract IGRF from scalar magnetometer measurements
  • l_window: (optional) trim data by N % l_window, -1 to ignore
  • silent: (optional) if true, no print outs

Returns:

  • y: length-N target vector
source
MagNav.get_yearsMethod
get_years(year, doy=0)

Get decimal (fractional) year from year and doy (day of year).

Arguments:

  • year: year
  • doy: day of year

Returns:

  • years: decimal (fractional) year
source
MagNav.gif_animation_m3Function
gif_animation_m3(TL_perm::AbstractMatrix, TL_induced::AbstractMatrix, TL_eddy::AbstractMatrix,
                 TL_aircraft::AbstractMatrix, B_unit::AbstractMatrix, y_nn::AbstractMatrix,
                 y::Vector, y_hat::Vector, xyz::XYZ,
                 filt_lat::Vector = [],
                 filt_lon::Vector = [];
                 ind              = trues(xyz.traj.N),
                 tt_lim::Tuple    = (0, (xyz.traj(ind).N-1)*xyz.traj.dt/60),
                 skip_every::Int  = 5,
                 save_plot::Bool  = false,
                 mag_gif::String  = "comp_xai.gif")

Create a GIF animation of the model 3 components and the true and predicted scalar magnetic field. First run comp_m3_test() to generate the individual model components 3.

Arguments

  • TL_perm: 3 x N matrix of TL permanent vector field
  • TL_induced: 3 x N matrix of TL induced vector field
  • TL_eddy: 3 x N matrix of TL eddy current vector field
  • TL_aircraft: 3 x N matrix of TL aircraft vector field
  • B_unit: 3 x N matrix of normalized vector magnetometer measurements
  • y_nn: 3 x N matrix of vector neural network correction (for scalar models, in direction of Bt)
  • y: length-N target vector
  • y_hat: length-N prediction vector
  • xyz: XYZ flight data struct
  • filt_lat: (optional) length-N filter output latitude [rad]
  • filt_lon: (optional) length-N filter output longitude [rad]
  • ind: (optional) selected data indices
  • tt_lim: (optional) length-2 start & end time limits (inclusive) [min]
  • skip_every: (optional) number of time steps to skip between frames
  • save_plot: (optional) if true, save g1 as mag_gif
  • mag_gif: (optional) path/name of magnetic field GIF file to save (.gif extension optional)

Returns

  • g1: magnetic field GIF animation

Example

gif_animation_m3(TL_perm, TL_induced, TL_eddy, TL_aircraft, B_unit,
                 y_nn, y, y_hat, xyz, filt_lat, filt_lon; ind=ind, tt_lim=(0.0,10.0),
                 skip_every=5, save_plot=false, mag_gif="comp_xai.gif")
source
MagNav.gif_ellipseFunction
gif_ellipse(P, lat1 = deg2rad(45);
            dt                   = 0.1,
            di::Int              = 10,
            speedup::Int         = 60,
            conf_units::Symbol   = :m,
            μ                    = zeros(eltype(P),2),
            conf                 = 0.95,
            clip                 = Inf,
            n::Int               = 61,
            lim                  = 500,
            margin::Int          = 2,
            axis::Bool           = true,
            plot_eigax::Bool     = false,
            bg_color::Symbol     = :white,
            ce_color::Symbol     = :black,
            b_e::AbstractBackend = gr(),
            save_plot::Bool      = false,
            ellipse_gif::String  = "conf_ellipse.gif")

Create a (position) confidence ellipse GIF animation for a 2 x 2 (x N) covariance matrix.

Arguments:

  • P: 2 x 2 (x N) covariance matrix
  • lat1: (optional) nominal latitude [rad], only used if conf_units = :m or :ft
  • dt: (optional) measurement time step [s]
  • di: (optional) GIF measurement interval (e.g., di = 10 uses every 10th measurement)
  • speedup: (optional) GIF speedup (e.g., speedup = 60 is 60x speed)
  • conf_units: (optional) confidence ellipse units {:m,:ft,:deg,:rad}
  • μ: (optional) confidence ellipse center [conf_units]
  • conf: (optional) percentile {0:1}
  • clip: (optional) clipping radius [conf_units]
  • n: (optional) number of confidence ellipse points
  • lim: (optional) plot x & y limits (-lim,lim) [conf_units]
  • margin: (optional) margin around plot [mm]
  • axis: (optional) if true, show axes
  • plot_eigax: (optional) if true, show major & minor axes
  • bg_color: (optional) background color
  • ce_color: (optional) confidence ellipse color
  • b_e: (optional) plotting backend
  • save_plot: (optional) if true, save g1 as ellipse_gif
  • ellipse_gif: (optional) path/name of confidence ellipse GIF file to save (.gif extension optional)

Returns:

  • g1: confidence ellipse GIF animation
source
MagNav.gif_ellipseFunction
gif_ellipse(filt_res::FILTres,
            filt_out::FILTout,
            map_map::Map         = mapS_null;
            dt                   = 0.1,
            di::Int              = 10,
            speedup::Int         = 60,
            conf_units::Symbol   = :m,
            μ                    = zeros(eltype(filt_res.P),2),
            conf                 = 0.95,
            clip                 = Inf,
            n::Int               = 61,
            lim                  = 500,
            dpi::Int             = 200,
            margin::Int          = 2,
            axis::Bool           = true,
            plot_eigax::Bool     = false,
            bg_color::Symbol     = :white,
            ce_color::Symbol     = :black,
            map_color::Symbol    = :usgs,
            clims::Tuple         = (),
            b_e::AbstractBackend = gr(),
            save_plot::Bool      = false,
            ellipse_gif::String  = "conf_ellipse.gif")

Create a (position) confidence ellipse GIF animation for a 2 x 2 (x N) covariance matrix.

Arguments:

  • filt_res: FILTres filter results struct
  • filt_out: FILTout filter extracted output struct
  • map_map: (optional) Map magnetic anomaly map struct
  • dt: (optional) measurement time step [s]
  • di: (optional) GIF measurement interval (e.g., di = 10 uses every 10th measurement)
  • speedup: (optional) GIF speedup (e.g., speedup = 60 is 60x speed)
  • conf_units: (optional) confidence ellipse units {:m,:ft,:deg,:rad}
  • μ: (optional) confidence ellipse center [conf_units]
  • conf: (optional) percentile {0:1}
  • clip: (optional) clipping radius [conf_units]
  • n: (optional) number of confidence ellipse points
  • lim: (optional) plot x & y limits (-lim,lim) [conf_units]
  • dpi: (optional) dots per inch (image resolution)
  • margin: (optional) margin around plot [mm]
  • axis: (optional) if true, show axes
  • plot_eigax: (optional) if true, show major & minor axes
  • bg_color: (optional) background color
  • ce_color: (optional) confidence ellipse color
  • map_color: (optional) filled contour color scheme {:usgs,:gray,:gray1,:gray2,:plasma,:magma}
  • clims: (optional) length-2 map colorbar limits (cmin,cmax)
  • b_e: (optional) plotting backend
  • save_plot: (optional) if true, save g1 as ellipse_gif
  • ellipse_gif: (optional) path/name of confidence ellipse GIF file to save (.gif extension optional)

Returns:

  • g1: confidence ellipse GIF animation
source
MagNav.krr_fitFunction
krr_fit(x, y, no_norm = falses(size(x,2));
        k::Kernel           = PolynomialKernel(;degree=1),
        λ::Real             = 0.5,
        norm_type_x::Symbol = :standardize,
        norm_type_y::Symbol = :standardize,
        data_norms::Tuple   = (zeros(1,1),zeros(1,1),[0.0],[0.0]),
        l_segs::Vector      = [length(y)],
        silent::Bool        = false)

Fit a kernel ridge regression (KRR) model to data.

Arguments:

  • x: N x Nf data matrix (Nf is number of features)
  • y: length-N target vector
  • no_norm: (optional) length-Nf Boolean indices of features to not be normalized
  • k: (optional) kernel
  • λ: (optional) ridge parameter
  • norm_type_x: (optional) normalization for x data matrix
  • norm_type_y: (optional) normalization for y target vector
  • data_norms: (optional) length-4 tuple of data normalizations, (x_bias,x_scale,y_bias,y_scale)
  • l_segs: (optional) length-N_lines vector of lengths of lines, sum(l_segs) = N
  • silent: (optional) if true, no print outs

Returns:

  • model: length-3 tuple of KRR-based model, (k, length-N coefficients, N x Nf data matrix, normalized)
  • data_norms: length-4 tuple of data normalizations, (x_bias,x_scale,y_bias,y_scale)
  • y_hat: length-N prediction vector
  • err: length-N mean-corrected (per line) error
source
MagNav.krr_testMethod
krr_test(x, y, data_norms::Tuple, model::Tuple;
         l_segs::Vector = [length(y)],
         silent::Bool   = false)

Evaluate performance of a kernel ridge regression (KRR) model.

Arguments:

  • x: N x Nf data matrix (Nf is number of features)
  • y: length-N target vector
  • data_norms: length-4 tuple of data normalizations, (x_bias,x_scale,y_bias,y_scale)
  • model: length-3 tuple of KRR-based model, (k, length-N_train coefficients, N_train x Nf training data matrix, normalized)
  • l_segs: (optional) length-N_lines vector of lengths of lines, sum(l_segs) = N
  • silent: (optional) if true, no print outs

Returns:

  • y_hat: length-N prediction vector
  • err: length-N mean-corrected (per line) error
source
MagNav.linear_fitFunction
linear_fit(x, y, no_norm = falses(size(x,2));
           trim::Int           = 0,
           λ::Real             = 0,
           norm_type_x::Symbol = :none,
           norm_type_y::Symbol = :none,
           data_norms::Tuple   = (zeros(1,1),zeros(1,1),[0.0],[0.0]),
           l_segs::Vector      = [length(y)],
           silent::Bool        = false)

Fit a linear regression model to data.

Arguments:

  • x: N x Nf data matrix (Nf is number of features)
  • y: length-N target vector
  • no_norm: (optional) length-Nf Boolean indices of features to not be normalized
  • trim: (optional) number of elements to trim (e.g., due to bpf)
  • λ: (optional) ridge parameter
  • norm_type_x: (optional) normalization for x data matrix
  • norm_type_y: (optional) normalization for y target vector
  • data_norms: (optional) length-4 tuple of data normalizations, (x_bias,x_scale,y_bias,y_scale)
  • l_segs: (optional) length-N_lines vector of lengths of lines, sum(l_segs) = N
  • silent: (optional) if true, no print outs

Returns:

  • model: length-2 tuple of linear regression model, (length-Nf coefficients, bias=0)
  • data_norms: length-4 tuple of data normalizations, (x_bias,x_scale,y_bias,y_scale)
  • y_hat: length-N prediction vector
  • err: length-N mean-corrected (per line) error
source
MagNav.linear_testMethod
linear_test(x_norm, y, y_bias, y_scale, model::Tuple;
            l_segs::Vector = [length(y)],
            silent::Bool   = false)

Evaluate performance of a linear model.

Arguments:

  • x_norm: N x Nf normalized data matrix (Nf is number of features)
  • y: length-N target vector
  • y_bias: y target vector bias bias (mean, min, or zero)
  • y_scale: y target vector bias scaling factor (std dev, max-min, or one)
  • model: length-2 tuple of model, (length-Nf coefficients, bias)
  • l_segs: (optional) length-N_lines vector of lengths of lines, sum(l_segs) = N
  • silent: (optional) if true, no print outs

Returns:

  • y_hat: length-N prediction vector
  • err: length-N mean-corrected (per line) error
source
MagNav.linear_testMethod
linear_test(x, y, data_norms::Tuple, model::Tuple;
            l_segs::Vector = [length(y)],
            silent::Bool   = false)

Evaluate performance of a linear model.

Arguments:

  • x: N x Nf data matrix (Nf is number of features)
  • y: length-N target vector
  • data_norms: length-4 tuple of data normalizations, (x_bias,x_scale,y_bias,y_scale)
  • model: length-2 tuple of model, (length-Nf coefficients, bias)
  • l_segs: (optional) length-N_lines vector of lengths of lines, sum(l_segs) = N
  • silent: (optional) if true, no print outs

Returns:

  • y_hat: length-N prediction vector
  • err: length-N mean-corrected (per line) error
source
MagNav.linregMethod
linreg(y, x; λ=0)

Linear regression with data matrix.

Arguments:

  • y: length-N observed data vector
  • x: N x Nf input data matrix (Nf is number of features)
  • λ: (optional) ridge parameter

Returns:

  • coef: linear regression coefficients
source
MagNav.linregMethod
linreg(y; λ=0)

Linear regression to determine best fit line for x = eachindex(y).

Arguments:

  • y: length-N observed data vector
  • λ: (optional) ridge parameter

Returns:

  • coef: length-2 vector of linear regression coefficients
source
MagNav.map2kmzFunction
map2kmz(map_map::Matrix, map_xx::Vector, map_yy::Vector,
        map_kmz::String   = "map.kmz";
        map_units::Symbol = :rad,
        plot_alt::Real    = 0,
        opacity::Real     = 0.75,
        clims::Tuple      = ())

Create KMZ file of map for use with Google Earth. Generates an "icon" overlay, thus not suitable for large maps (e.g., > 5 deg x 5 deg).

Arguments:

  • map_map: ny x nx 2D gridded map data
  • map_xx: nx map x-direction (longitude) coordinates [rad] or [deg]
  • map_yy: ny map y-direction (latitude) coordinates [rad] or [deg]
  • map_kmz: (optional) path/name of map KMZ file to save (.kmz extension optional)
  • map_units: (optional) map xx/yy units {:rad,:deg}
  • plot_alt: (optional) map altitude in Google Earth [m]
  • opacity: (optional) map opacity {0:1}
  • clims: (optional) length-2 map colorbar limits (cmin,cmax)

Returns:

  • nothing: map_kmz is created
source
MagNav.map2kmzFunction
map2kmz(mapS::Union{MapS,MapSd,MapS3D},
        map_kmz::String = "map.kmz";
        use_mask::Bool  = true,
        plot_alt::Real  = 0,
        opacity::Real   = 0.75,
        clims::Tuple    = ())

Create KMZ file of map for use with Google Earth. Generates an "icon" overlay, thus not suitable for large maps (e.g., > 5 deg x 5 deg).

Arguments:

  • mapS: MapS, MapSd, or MapS3D scalar magnetic anomaly map struct
  • map_kmz: (optional) path/name of map KMZ file to save (.kmz extension optional)
  • use_mask: (optional) if true, apply mapS mask to map
  • plot_alt: (optional) map altitude in Google Earth [m]
  • opacity: (optional) map opacity {0:1}
  • clims: (optional) length-2 map colorbar limits (cmin,cmax)

Returns:

  • nothing: map_kmz is created
source
MagNav.map_borderMethod
map_border(map_map::Matrix, map_xx::Vector, map_yy::Vector;
           inner::Bool       = true,
           sort_border::Bool = false,
           return_ind::Bool  = false)

Get map border from an unfilled map.

Arguments:

  • map_map: ny x nx 2D gridded map data
  • map_xx: nx map x-direction (longitude) coordinates
  • map_yy: ny map y-direction (latitude) coordinates
  • inner: (optional) if true, get inner border, otherwise outer border
  • sort_border: (optional) if true, sort border data points sequentially
  • return_ind: (optional) if true, return ind

Returns:

  • yy: border y-direction (latitude) coordinates
  • xx: border x-direction (longitude) coordinates
  • ind: if return_ind = true, BitMatrix of border indices within map_map
source
MagNav.map_borderMethod
map_border(mapS::Union{MapS,MapSd,MapS3D};
           inner::Bool       = true,
           sort_border::Bool = false,
           return_ind::Bool  = false)

Get map border from an unfilled map.

Arguments:

  • mapS: MapS, MapSd, or MapS3D scalar magnetic anomaly map struct
  • inner: (optional) if true, get inner border, otherwise outer border
  • sort_border: (optional) if true, sort border data points sequentially
  • return_ind: (optional) if true, return ind

Returns:

  • yy: border y-direction (latitude) coordinates
  • xx: border x-direction (longitude) coordinates
  • ind: if return_ind = true, BitMatrix of border indices within map_map
source
MagNav.map_checkFunction
map_check(map_map_vec::Vector, path::Path, ind = trues(path.N))

Check if latitude and longitude points are on given maps.

Arguments:

  • map_map_vec: vector of Map magnetic anomaly map structs
  • path: Path struct, i.e., Traj trajectory struct, INS inertial navigation system struct, or FILTout filter extracted output struct
  • ind: (optional) selected data indices

Returns:

  • bools: if true, all path[ind] points are on map_map_vec[i]
source
MagNav.map_checkFunction
map_check(map_map::Map, path::Path, ind = trues(path.N))

Check if latitude and longitude points are on given map.

Arguments:

  • map_map: Map magnetic anomaly map struct
  • path: Path struct, i.e., Traj trajectory struct, INS inertial navigation system struct, or FILTout filter extracted output struct
  • ind: (optional) selected data indices

Returns:

  • bool: if true, all path[ind] points are on map_map
source
MagNav.map_checkFunction
map_check(map_map::Map, lat, lon, alt = fill(median(map_map.alt),size(lat)))

Check if latitude and longitude points are on given map.

Arguments:

  • map_map: Map magnetic anomaly map struct
  • lat: latitude [rad]
  • lon: longitude [rad]
  • alt: (optional) altitude [m], only used for MapS3D

Returns:

  • bool: if true, all lat & lon (& alt) points are on map_map
source
MagNav.map_chessboard!Method
map_chessboard!(map_map::Matrix, map_alt::Matrix, map_xx::Vector,
                map_yy::Vector, alt::Real;
                down_cont::Bool = true,
                dz              = 5,
                down_max        = 150,
                α               = 200)

Perform the chessboard method, which upward (and possibly downward) continues a map to multiple altitudes to create a 3D map, then vertically interpolates at each horizontal grid point.

Reference: Cordell, Phillips, & Godson, U.S. Geological Survey Potential-Field Software Version 2.0, 1992.

Arguments:

  • map_map: ny x nx 2D gridded target (e.g., magnetic) map data on [m] grid
  • map_alt: ny x nx 2D gridded altitude map data [m] on [m] grid
  • map_xx: nx map x-direction (longitude) coordinates [m]
  • map_yy: ny map y-direction (latitude) coordinates [m]
  • alt: final map altitude after upward continuation [m]
  • down_cont: (optional) if true, downward continue if needed, only used if up_cont = true
  • dz: (optional) upward continuation step size [m]
  • down_max: (optional) maximum downward continuation distance [m]
  • α: (optional) regularization parameter for downward continuation

Returns:

  • nothing: map_map is mutated with upward continued map data
source
MagNav.map_chessboardMethod
map_chessboard(mapSd::MapSd, alt::Real;
               down_cont::Bool = true,
               dz              = 5,
               down_max        = 150,
               α               = 200)

Perform the chessboard method, which upward (and possibly downward) continues a map to multiple altitudes to create a 3D map, then vertically interpolates at each horizontal grid point.

Reference: Cordell, Phillips, & Godson, U.S. Geological Survey Potential-Field Software Version 2.0, 1992.

Arguments:

  • mapSd: MapSd scalar magnetic anomaly map struct
  • alt: final map altitude after upward continuation [m]
  • down_cont: (optional) if true, downward continue if needed
  • dz: (optional) upward continuation step size [m]
  • down_max: (optional) maximum downward continuation distance [m]
  • α: (optional) regularization parameter for downward continuation

Returns:

  • mapS: MapS scalar magnetic anomaly map struct
source
MagNav.map_combineFunction
map_combine(mapS_vec::Vector, mapS_fallback::MapS = get_map(namad);
            map_info::String   = "Combined map",
            N_levels::Int      = 3,
            dx                 = get_step(mapS_vec[1].xx),
            dy                 = get_step(mapS_vec[1].yy),
            xx_lim::Tuple      = get_lim(mapS_vec[1].xx,0.5),
            yy_lim::Tuple      = get_lim(mapS_vec[1].yy,0.5),
            α                  = 200,
            use_fallback::Bool = true)

Combine maps at different altitudes. Lowest and highest maps are directly used (with resampling & resizing), with intermediate maps determined by N_levels.

Arguments:

  • mapS_vec: vector of MapS scalar magnetic anomaly map structs
  • mapS_fallback: (optional) fallback MapS scalar magnetic anomaly map struct
  • map_info: (optional) map information
  • N_levels: (optional) number of map altitude levels
  • dx: (optional) desired x-direction map step size
  • dy: (optional) desired y-direction map step size
  • xx_lim: (optional) length-2x-direction map limits (xx_min,xx_max)
  • yy_lim: (optional) length-2 y-direction map limits (yy_min,yy_max)
  • α: (optional) regularization parameter for downward continuation
  • use_fallback: (optional) if true, use mapS_fallback for missing map data

Returns:

  • mapS3D: MapS3D 3D (multi-level) scalar magnetic anomaly map struct
source
MagNav.map_combineFunction
map_combine(mapS::MapS, mapS_fallback::MapS = get_map(namad);
            map_info::String = mapS.info,
            xx_lim::Tuple    = get_lim(mapS.xx,0.1),
            yy_lim::Tuple    = get_lim(mapS.yy,0.1),
            α                = 200)

Combine two maps at same altitude.

Arguments:

  • mapS: MapS scalar magnetic anomaly map struct
  • mapS_fallback: (optional) fallback MapS scalar magnetic anomaly map struct
  • map_info: (optional) map information
  • xx_lim: (optional) length-2 x-direction map limits (xx_min,xx_max)
  • yy_lim: (optional) length-2 y-direction map limits (yy_min,yy_max)
  • α: (optional) regularization parameter for downward continuation

Returns:

  • mapS: MapS scalar magnetic anomaly map struct, combined
source
MagNav.map_correct_igrf!Method
map_correct_igrf!(map_map::Matrix, map_alt,
                  map_xx::Vector, map_yy::Vector;
                  sub_igrf_date::Real = get_years(2013,293), # 20-Oct-2013
                  add_igrf_date::Real = -1,
                  zone_utm::Int       = 18,
                  is_north::Bool      = true,
                  map_units::Symbol   = :rad)

Correct the International Geomagnetic Reference Field (IGRF), i.e., core field, of a map by subtracting and/or adding the IGRF on specified date(s).

Arguments:

  • map_map: ny x nx 2D gridded map data
  • map_alt: ny x nx 2D gridded altitude map data, single altitude value may be provided [m]
  • map_xx: nx map x-direction (longitude) coordinates [rad] or [deg] or [m]
  • map_yy: ny map y-direction (latitude) coordinates [rad] or [deg] or [m]
  • sub_igrf_date: (optional) date of IGRF core field to subtract [yr], -1 to ignore
  • add_igrf_date: (optional) date of IGRF core field to add [yr], -1 to ignore
  • zone_utm: (optional) UTM zone, only used if map_units = :utm
  • is_north: (optional) if true, map is in northern hemisphere, only used if map_units = :utm
  • map_units: (optional) map xx/yy units {:rad,:deg,:utm}

Returns:

  • nothing: map_map is mutated with IGRF corrected map data
source
MagNav.map_correct_igrf!Method
map_correct_igrf!(mapS::Union{MapS,MapSd,MapS3D};
                  sub_igrf_date::Real = get_years(2013,293), # 20-Oct-2013
                  add_igrf_date::Real = -1,
                  zone_utm::Int       = 18,
                  is_north::Bool      = true,
                  map_units::Symbol   = :rad)

Correct the International Geomagnetic Reference Field (IGRF), i.e., core field, of a map by subtracting and/or adding the IGRF on specified date(s).

Arguments:

  • mapS: MapS, MapSd, or MapS3D scalar magnetic anomaly map struct
  • sub_igrf_date: (optional) date of IGRF core field to subtract [yr], -1 to ignore
  • add_igrf_date: (optional) date of IGRF core field to add [yr], -1 to ignore
  • zone_utm: (optional) UTM zone, only used if map_units = :utm
  • is_north: (optional) if true, map is in northern hemisphere, only used if map_units = :utm
  • map_units: (optional) map xx/yy units {:rad,:deg,:utm}

Returns:

  • nothing: map field within mapS is mutated with IGRF corrected map data
source
MagNav.map_correct_igrfMethod
map_correct_igrf(map_map::Matrix, map_alt,
                 map_xx::Vector, map_yy::Vector;
                 sub_igrf_date::Real = get_years(2013,293), # 20-Oct-2013
                 add_igrf_date::Real = -1,
                 zone_utm::Int       = 18,
                 is_north::Bool      = true,
                 map_units::Symbol   = :rad)

Correct the International Geomagnetic Reference Field (IGRF), i.e., core field, of a map by subtracting and/or adding the IGRF on specified date(s).

Arguments:

  • map_map: ny x nx 2D gridded map data
  • map_alt: ny x nx 2D gridded altitude map data [m]
  • map_xx: nx map x-direction (longitude) coordinates [rad] or [deg] or [m]
  • map_yy: ny map y-direction (latitude) coordinates [rad] or [deg] or [m]
  • sub_igrf_date: (optional) date of IGRF core field to subtract [yr], -1 to ignore
  • add_igrf_date: (optional) date of IGRF core field to add [yr], -1 to ignore
  • zone_utm: (optional) UTM zone, only used if map_units = :utm
  • is_north: (optional) if true, map is in northern hemisphere, only used if map_units = :utm
  • map_units: (optional) map xx/yy units {:rad,:deg,:utm}

Returns:

  • map_map: ny x nx 2D gridded map data, IGRF corrected
source
MagNav.map_correct_igrfMethod
map_correct_igrf(mapS::Union{MapS,MapSd,MapS3D};
                 sub_igrf_date::Real = get_years(2013,293), # 20-Oct-2013
                 add_igrf_date::Real = -1,
                 zone_utm::Int       = 18,
                 is_north::Bool      = true,
                 map_units::Symbol   = :rad)

Correct the International Geomagnetic Reference Field (IGRF), i.e., core field, of a map by subtracting and/or adding the IGRF on specified date(s).

Arguments:

  • mapS: MapS, MapSd, or MapS3D scalar magnetic anomaly map struct
  • sub_igrf_date: (optional) date of IGRF core field to subtract [yr], -1 to ignore
  • add_igrf_date: (optional) date of IGRF core field to add [yr], -1 to ignore
  • zone_utm: (optional) UTM zone, only used if map_units = :utm
  • is_north: (optional) if true, map is in northern hemisphere, only used if map_units = :utm
  • map_units: (optional) map xx/yy units {:rad,:deg,:utm}

Returns:

  • mapS: MapS, MapSd, or MapS3D scalar magnetic anomaly map struct, IGRF corrected
source
MagNav.map_expandFunction
map_expand(map_map::Matrix, pad::Int = 1)

Expand a map with padding on each edge to eliminate discontinuities in the discrete Fourier transform. The map is “wrapped around” to make it periodic. Padding expands the map to 7-smooth dimensions, allowing for a faster Fast Fourier Transform algorithm to be used during upward/downward continuation.

Arguments:

  • map_map: ny x nx 2D gridded map data
  • pad: minimum padding (grid cells) along map edges

Returns:

  • map_map: ny x nx 2D gridded map data, expanded (padded)
  • padx: x-direction padding (grid cells) applied on first edge
  • pady: y-direction padding (grid cells) applied on first edge
source
MagNav.map_fill!Method
map_fill!(map_map::Matrix, map_xx::Vector, map_yy::Vector; k::Int = 3)

Fill areas that are missing map data.

Arguments:

  • map_map: ny x nx 2D gridded map data
  • map_xx: nx map x-direction (longitude) coordinates
  • map_yy: ny map y-direction (latitude) coordinates
  • k: (optional) number of nearest neighbors for knn

Returns:

  • nothing: map_map is mutated with filled map data
source
MagNav.map_fill!Method
map_fill!(mapS::Union{MapS,MapSd,MapS3D}; k::Int = 3)

Fill areas that are missing map data.

Arguments:

  • mapS: MapS, MapSd, or MapS3D scalar magnetic anomaly map struct
  • k: (optional) number of nearest neighbors for knn

Returns:

  • nothing: map field within mapS is mutated with filled map data
source
MagNav.map_fillMethod
map_fill(map_map::Matrix, map_xx::Vector, map_yy::Vector; k::Int = 3)

Fill areas that are missing map data.

Arguments:

  • map_map: ny x nx 2D gridded map data
  • map_xx: nx map x-direction (longitude) coordinates
  • map_yy: ny map y-direction (latitude) coordinates
  • k: (optional) number of nearest neighbors for knn

Returns:

  • map_map: ny x nx 2D gridded map data, filled
source
MagNav.map_fillMethod
map_fill(mapS::Union{MapS,MapSd,MapS3D}; k::Int = 3)

Fill areas that are missing map data.

Arguments:

  • mapS: MapS, MapSd, or MapS3D scalar magnetic anomaly map struct
  • k: (optional) number of nearest neighbors for knn

Returns:

  • mapS: MapS, MapSd, or MapS3D scalar magnetic anomaly map struct, filled
source
MagNav.map_get_gxfMethod
map_get_gxf(map_gxf::String)

Use ArchGDAL to read in map data from GXF file.

Arguments:

  • map_gxf: path/name of map GXF file (.gxf extension optional)

Returns:

  • map_map: ny x nx 2D gridded map data
  • map_xx: nx map x-direction (longitude) coordinates
  • map_yy: ny map y-direction (latitude) coordinates
source
MagNav.map_gxf2h5Method
map_gxf2h5(map_gxf::String, alt::Real;
           map_info::String = splitpath(map_gxf)[end],
           fill_map::Bool   = true,
           get_lla::Bool    = true,
           zone_utm::Int    = 18,
           is_north::Bool   = true,
           save_h5::Bool    = false,
           map_h5::String   = "map_data.h5")

Convert map data file (with assumed UTM grid) from GXF to HDF5. The order of operations is:

  • original map from map_gxf =>
  • trim away large areas that are missing map data =>
  • fill remaining areas that are missing map data =>
  • convert map grid from UTM to LLA

Specifically meant for SMALL and LEVEL maps ONLY.

Arguments:

  • map_gxf: path/name of target (e.g., magnetic) map GXF file (.gxf extension optional)
  • alt: map altitude [m]
  • map_info: (optional) map information
  • fill_map: (optional) if true, fill areas that are missing map data
  • get_lla: (optional) if true, convert map grid from UTM to LLA
  • zone_utm: (optional) UTM zone
  • is_north: (optional) if true, map is in northern hemisphere
  • save_h5: (optional) if true, save mapS to map_h5
  • map_h5: (optional) path/name of map data HDF5 file to save (.h5 extension optional)

Returns:

  • mapS: MapS scalar magnetic anomaly map struct
source
MagNav.map_gxf2h5Method
map_gxf2h5(map_gxf::String, alt_gxf::String, alt::Real;
           map_info::String    = splitpath(map_gxf)[end],
           pad::Int            = 0,
           sub_igrf_date::Real = get_years(2013,293),
           add_igrf_date::Real = -1,
           zone_utm::Int       = 18,
           is_north::Bool      = true,
           fill_map::Bool      = true,
           up_cont::Bool       = true,
           down_cont::Bool     = true,
           get_lla::Bool       = true,
           dz::Real            = 5,
           down_max::Real      = 150,
           α::Real             = 200,
           save_h5::Bool       = false,
           map_h5::String      = "map_data.h5")

Convert map data file (with assumed UTM grid) from GXF to HDF5. The order of operations is:

  • original map from map_gxf =>
  • trim away large areas that are missing map data =>
  • subtract and/or add IGRF to map data =>
  • fill remaining areas that are missing map data =>
  • upward/downward continue to alt =>
  • convert map grid from UTM to LLA

This can be memory intensive, largely depending on the map size and dz. If up_cont = true, a MapS struct is returned. If up_cont = false, a MapSd struct is returned, which has an included altitude map.

Arguments:

  • map_gxf: path/name of target (e.g., magnetic) map GXF file (.gxf extension optional)
  • alt_gxf: path/name of altitude map GXF file (.gxf extension optional)
  • alt: final map altitude after upward continuation [m], not used for drape map
  • map_info: (optional) map information
  • pad: (optional) minimum padding (grid cells) along map edges
  • sub_igrf_date: (optional) date of IGRF core field to subtract [yr], -1 to ignore
  • add_igrf_date: (optional) date of IGRF core field to add [yr], -1 to ignore
  • zone_utm: (optional) UTM zone
  • is_north: (optional) if true, map is in northern hemisphere
  • fill_map: (optional) if true, fill areas that are missing map data
  • up_cont: (optional) if true, upward/downward continue to alt
  • down_cont: (optional) if true, downward continue if needed, only used if up_cont = true
  • get_lla: (optional) if true, convert map grid from UTM to LLA
  • dz: (optional) upward continuation step size [m]
  • down_max: (optional) maximum downward continuation distance [m]
  • α: (optional) regularization parameter for downward continuation
  • save_h5: (optional) if true, save mapS to map_h5
  • map_h5: (optional) path/name of map data HDF5 file to save (.h5 extension optional)

Returns:

  • mapS: MapS or MapSd scalar magnetic anomaly map struct
source
MagNav.map_interpolateFunction
map_interpolate(mapV::MapV, dim::Symbol = :X, type::Symbol = :cubic)

Create map interpolation function, equivalent of griddedInterpolant in MATLAB.

Arguments:

  • mapV: MapV vector magnetic anomaly map struct
  • dim: map dimension to interpolate {:X,:Y,:Z}
  • type: (optional) type of interpolation {:linear,:quad,:cubic}

Returns:

  • itp_map: map interpolation function (f(yy,xx))
source
MagNav.map_interpolateFunction
map_interpolate(mapS::Union{MapS,MapSd,MapS3D}, type::Symbol = :cubic;
                return_vert_deriv::Bool = false)

Create map interpolation function, equivalent of griddedInterpolant in MATLAB. Optionally return vertical derivative map interpolation function, which is calculated using finite differences between map and 1 m upward continued map.

Arguments:

  • mapS: MapS, MapSd, or MapS3D scalar magnetic anomaly map struct
  • type: (optional) type of interpolation {:linear,:quad,:cubic}
  • return_vert_deriv: (optional) if true, also return der_map

Returns:

  • itp_map: map interpolation function (f(yy,xx) or (f(yy,xx,alt))
  • der_map: if return_vert_deriv = true, vertical derivative map interpolation function (f(yy,xx) or (f(yy,xx,alt))
source
MagNav.map_interpolateMethod
map_interpolate(map_map::AbstractArray{T},
                map_xx::AbstractVector{T},
                map_yy::AbstractVector{T},
                type::Symbol = :cubic,
                map_alt::AbstractVector{T} = T[0]) where T

Create map interpolation function, equivalent of griddedInterpolant in MATLAB.

Arguments:

  • map_map: ny x nx (x nz) 2D or 3D gridded map data
  • map_xx: nx map x-direction (longitude) coordinates
  • map_yy: ny map y-direction (latitude) coordinates
  • type: (optional) type of interpolation {:linear,:quad,:cubic}
  • map_alt: (optional) map altitude levels

Returns:

  • itp_map: map interpolation function (f(yy,xx) or (f(yy,xx,alt))
source
MagNav.map_resampleMethod
map_resample(mapS::MapS, mapS_new::MapS)

Resample map with new grid.

Arguments:

  • mapS: MapS scalar magnetic anomaly map struct
  • mapS_new: MapS scalar magnetic anomaly map struct to use for resampling

Returns:

  • mapS: MapS scalar magnetic anomaly map struct, resampled
source
MagNav.map_resampleMethod
map_resample(mapS::MapS, map_xx_new::Vector, map_yy_new::Vector)

Resample map with new grid.

Arguments:

  • mapS: MapS scalar magnetic anomaly map struct
  • map_xx_new: nx_new map x-direction (longitude) coordinates to use for resampling
  • map_yy_new: ny_new map y-direction (latitude) coordinates to use for resampling

Returns:

  • mapS: MapS scalar magnetic anomaly map struct, resampled
source
MagNav.map_resampleMethod
map_resample(map_map::Matrix, map_xx::Vector, map_yy::Vector,
             map_mask::BitMatrix, map_xx_new::Vector, map_yy_new::Vector)

Resample map with new grid.

Arguments:

  • map_map: ny x nx 2D gridded map data
  • map_xx: nx map x-direction (longitude) coordinates
  • map_yy: ny map y-direction (latitude) coordinates
  • map_mask ny x nx mask for valid (not filled-in) map data
  • map_xx_new: nx_new map x-direction (longitude) coordinates to use for resampling
  • map_yy_new: ny_new map y-direction (latitude) coordinates to use for resampling

Returns:

  • map_map: ny_new x nx_new 2D gridded map data, resampled
  • map_mask: ny_new x nx_new mask for valid (not filled-in) map data, resampled
source
MagNav.map_trimFunction
map_trim(map_map::Matrix,
         map_xx::Vector    = collect(axes(map_map,2)),
         map_yy::Vector    = collect(axes(map_map,1)),
         pad::Int          = 0,
         xx_lim::Tuple     = (-Inf,Inf),
         yy_lim::Tuple     = (-Inf,Inf),
         zone_utm::Int     = 18,
         is_north::Bool    = true,
         map_units::Symbol = :rad,
         silent::Bool      = true)

Trim map by removing large areas that are missing map data. Returns indices for the original map that produces the appropriate trimmed map.

Arguments:

  • map_map: ny x nx 2D gridded map data
  • map_xx: (optional) nx map x-direction (longitude) coordinates [rad] or [deg] or [m]
  • map_yy: (optional) ny map y-direction (latitude) coordinates [rad] or [deg] or [m]
  • pad: (optional) minimum padding (grid cells) along map edges
  • xx_lim: (optional) x-direction map limits (xx_min,xx_max) [rad] or [deg] or [m]
  • yy_lim: (optional) y-direction map limits (yy_min,yy_max) [rad] or [deg] or [m]
  • zone_utm: (optional) UTM zone, only used if map_units = :utm
  • is_north: (optional) if true, map is in northern hemisphere, only used if map_units = :utm
  • map_units: (optional) map xx/yy units {:rad,:deg,:utm}
  • silent: (optional) if true, no print outs

Returns:

  • ind_xx: nx trimmed x-direction map indices
  • ind_yy: ny trimmed y-direction map indices
source
MagNav.map_trimMethod
map_trim(map_map::Map, path::Path;
         pad::Int          = 0,
         zone_utm::Int     = 18,
         is_north::Bool    = true,
         map_units::Symbol = :rad,
         silent::Bool      = true)

Trim map by removing large areas far away from path. Do not use prior to upward continuation, as this causes in edge effect errors. Returns trimmed magnetic anomaly map struct.

Arguments:

  • map_map: Map magnetic anomaly map struct
  • path: Path struct, i.e., Traj trajectory struct, INS inertial navigation system struct, or FILTout filter extracted output struct
  • pad: (optional) minimum padding (grid cells) along map edges
  • zone_utm: (optional) UTM zone, only used if map_units = :utm
  • is_north: (optional) if true, map is in northern hemisphere, only used if map_units = :utm
  • map_units: (optional) map xx/yy units {:rad,:deg,:utm}
  • silent: (optional) if true, no print outs

Returns:

  • map_map: Map magnetic anomaly map struct, trimmed
source
MagNav.map_trimMethod
map_trim(map_map::Map;
         pad::Int          = 0,
         xx_lim::Tuple     = (-Inf,Inf),
         yy_lim::Tuple     = (-Inf,Inf),
         zone_utm::Int     = 18,
         is_north::Bool    = true,
         map_units::Symbol = :rad,
         silent::Bool      = true)

Trim map by removing large areas that are missing map data. Returns trimmed magnetic anomaly map struct.

Arguments:

  • map_map: Map magnetic anomaly map struct
  • pad: (optional) minimum padding (grid cells) along map edges
  • xx_lim: (optional) x-direction map limits (xx_min,xx_max) [rad] or [deg] or [m]
  • yy_lim: (optional) y-direction map limits (yy_min,yy_max) [rad] or [deg] or [m]
  • zone_utm: (optional) UTM zone, only used if map_units = :utm
  • is_north: (optional) if true, map is in northern hemisphere, only used if map_units = :utm
  • map_units: (optional) map xx/yy units {:rad,:deg,:utm}
  • silent: (optional) if true, no print outs

Returns:

  • map_map: Map magnetic anomaly map struct, trimmed
source
MagNav.map_utm2lla!Method
map_utm2lla!(map_map::Matrix, map_xx::Vector, map_yy::Vector,
             alt, map_mask::BitMatrix;
             map_info::String = "Map",
             zone_utm::Int    = 18,
             is_north::Bool   = true,
             save_h5::Bool    = false,
             map_h5::String   = "map_data.h5")

Convert map grid from UTM to LLA.

Arguments:

  • map_map: ny x nx 2D gridded map data on UTM grid
  • map_xx: nx map x-direction (longitude) coordinates [m]
  • map_yy: ny map y-direction (latitude) coordinates [m]
  • alt: map altitude(s) or altitude map [m]
  • map_mask: ny x nx mask for valid (not filled-in) map data
  • map_info: (optional) map information
  • zone_utm: (optional) UTM zone
  • is_north: (optional) if true, map is in northern hemisphere
  • save_h5: (optional) if true, save map data to map_h5
  • map_h5: (optional) path/name of map data HDF5 file to save (.h5 extension optional)

Returns:

  • nothing: map_map, map_xx, map_yy, & map_mask (& alt) are mutated with LLA gridded map data
source
MagNav.map_utm2lla!Method
map_utm2lla!(mapS::Union{MapS,MapSd,MapS3D};
             zone_utm::Int  = 18,
             is_north::Bool = true,
             save_h5::Bool  = false
             map_h5::String = "map_data.h5")

Convert map grid from UTM to LLA.

Arguments:

  • mapS: MapS, MapSd, or MapS3D scalar magnetic anomaly map struct on UTM grid
  • zone_utm: (optional) UTM zone
  • is_north: (optional) if true, map is in northern hemisphere
  • save_h5: (optional) if true, save mapS to map_h5
  • map_h5: (optional) path/name of map data HDF5 file to save (.h5 extension optional)

Returns:

  • nothing: map, xx, yy, & mask (& alt) fields within mapS are mutated with LLA gridded map data
source
MagNav.map_utm2llaMethod
map_utm2lla(map_map::Matrix, map_xx::Vector, map_yy::Vector,
            alt, map_mask::BitMatrix;
            map_info::String = "Map",
            zone_utm::Int    = 18,
            is_north::Bool   = true,
            save_h5::Bool    = false,
            map_h5::String   = "map_data.h5")

Convert map grid from UTM to LLA.

Arguments:

  • map_map: ny x nx 2D gridded map data on UTM grid
  • map_xx: nx map x-direction (longitude) coordinates [m]
  • map_yy: ny map y-direction (latitude) coordinates [m]
  • alt: map altitude(s) or altitude map [m]
  • map_mask: ny x nx mask for valid (not filled-in) map data
  • map_info: (optional) map information
  • zone_utm: (optional) UTM zone
  • is_north: (optional) if true, map is in northern hemisphere
  • save_h5: (optional) if true, save map data to map_h5
  • map_h5: (optional) path/name of map data HDF5 file to save (.h5 extension optional)

Returns:

  • map_map: ny x nx 2D gridded map data on LLA grid
  • map_xx: nx map x-direction (longitude) coordinates [rad]
  • map_yy: ny map y-direction (latitude) coordinates [rad]
  • map_mask: ny x nx mask for valid (not filled-in) map data on LLA grid
source
MagNav.map_utm2llaMethod
map_utm2lla(mapS::Union{MapS,MapSd,MapS3D};
            zone_utm::Int  = 18,
            is_north::Bool = true,
            save_h5::Bool  = false
            map_h5::String = "map_data.h5")

Convert map grid from UTM to LLA.

Arguments:

  • mapS: MapS, MapSd, or MapS3D scalar magnetic anomaly map struct on UTM grid
  • zone_utm: (optional) UTM zone
  • is_north: (optional) if true, map is in northern hemisphere
  • save_h5: (optional) if true, save mapS to map_h5
  • map_h5: (optional) path/name of map data HDF5 file to save (.h5 extension optional)

Returns:

  • mapS: MapS, MapSd, or MapS3D scalar magnetic anomaly map struct on LLA grid
source
MagNav.mpfMethod
mpf(lat, lon, alt, vn, ve, vd, fn, fe, fd, Cnb, meas, dt, itp_mapS;
    P0         = create_P0(),
    Qd         = create_Qd(),
    R          = 1.0,
    num_part   = 1000,
    thresh     = 0.8,
    baro_tau   = 3600.0,
    acc_tau    = 3600.0,
    gyro_tau   = 3600.0,
    fogm_tau   = 600.0,
    date       = get_years(2020,185),
    core::Bool = false)

Rao-Blackwellized (marginalized) particle filter (MPF) for airborne magnetic anomaly navigation. This simplified MPF works only with LINEAR dynamics. This allows the same Kalman filter covariance matrices to be used with each particle, simplifying the filter and reducing the computational load. It is especially suited for map-matching navigation in which there is a highly non-linear, non-Gaussian MEASUREMENT, but NOT non-linear dynamics. The filter also assumes NON-correlated measurements to speed up computation.

Arguments:

  • lat: latitude [rad]
  • lon: longitude [rad]
  • alt: altitude [m]
  • vn: north velocity [m/s]
  • ve: east velocity [m/s]
  • vd: down velocity [m/s]
  • fn: north specific force [m/s^2]
  • fe: east specific force [m/s^2]
  • fd: down specific force [m/s^2]
  • Cnb: direction cosine matrix (body to navigation) [-]
  • meas: scalar magnetometer measurement [nT]
  • dt: measurement time step [s]
  • itp_mapS: scalar map interpolation function (f(lat,lon) or f(lat,lon,alt))
  • P0: (optional) initial covariance matrix
  • Qd: (optional) discrete time process/system noise matrix
  • R: (optional) measurement (white) noise variance
  • num_part: (optional) number of particles
  • thresh: (optional) resampling threshold fraction {0:1}
  • baro_tau: (optional) barometer time constant [s]
  • acc_tau: (optional) accelerometer time constant [s]
  • gyro_tau: (optional) gyroscope time constant [s]
  • fogm_tau: (optional) FOGM catch-all time constant [s]
  • date: (optional) measurement date (decimal year) for IGRF [yr]
  • core: (optional) if true, include core magnetic field in measurement

Returns:

  • filt_res: FILTres filter results struct
source
MagNav.mpfMethod
mpf(ins::INS, meas, itp_mapS;
    P0         = create_P0(),
    Qd         = create_Qd(),
    R          = 1.0,
    num_part   = 1000,
    thresh     = 0.8,
    baro_tau   = 3600.0,
    acc_tau    = 3600.0,
    gyro_tau   = 3600.0,
    fogm_tau   = 600.0,
    date       = get_years(2020,185),
    core::Bool = false)

Rao-Blackwellized (marginalized) particle filter (MPF) for airborne magnetic anomaly navigation. This simplified MPF works only with LINEAR dynamics. This allows the same Kalman filter covariance matrices to be used with each particle, simplifying the filter and reducing the computational load. It is especially suited for map-matching navigation in which there is a highly non-linear, non-Gaussian MEASUREMENT, but NOT non-linear dynamics. The filter also assumes NON-correlated measurements to speed up computation.

Arguments:

  • ins: INS inertial navigation system struct
  • meas: scalar magnetometer measurement [nT]
  • itp_mapS: scalar map interpolation function (f(lat,lon) or f(lat,lon,alt))
  • P0: (optional) initial covariance matrix
  • Qd: (optional) discrete time process/system noise matrix
  • R: (optional) measurement (white) noise variance
  • num_part: (optional) number of particles
  • thresh: (optional) resampling threshold fraction {0:1}
  • baro_tau: (optional) barometer time constant [s]
  • acc_tau: (optional) accelerometer time constant [s]
  • gyro_tau: (optional) gyroscope time constant [s]
  • fogm_tau: (optional) FOGM catch-all time constant [s]
  • date: (optional) measurement date (decimal year) for IGRF [yr]
  • core: (optional) if true, include core magnetic field in measurement

Returns:

  • filt_res: FILTres filter results struct
source
MagNav.nekfFunction
nekf(lat, lon, alt, vn, ve, vd, fn, fe, fd, Cnb, meas, dt, itp_mapS,
     x_nn::Matrix = meas[:,:],
     m            = Dense(1 => 1);
     P0           = create_P0(),
     Qd           = create_Qd(),
     R            = 1.0,
     baro_tau     = 3600.0,
     acc_tau      = 3600.0,
     gyro_tau     = 3600.0,
     fogm_tau     = 600.0,
     date         = get_years(2020,185),
     core::Bool   = false)

Measurement noise covariance-adaptive neural extended Kalman filter (nEKF) for airborne magnetic anomaly navigation.

Arguments:

  • lat: latitude [rad]
  • lon: longitude [rad]
  • alt: altitude [m]
  • vn: north velocity [m/s]
  • ve: east velocity [m/s]
  • vd: down velocity [m/s]
  • fn: north specific force [m/s^2]
  • fe: east specific force [m/s^2]
  • fd: down specific force [m/s^2]
  • Cnb: direction cosine matrix (body to navigation) [-]
  • meas: scalar magnetometer measurement [nT]
  • dt: measurement time step [s]
  • itp_mapS: scalar map interpolation function (f(lat,lon) or f(lat,lon,alt))
  • x_nn: N x Nf data matrix for neural network (Nf is number of features)
  • m: neural network model
  • P0: (optional) initial covariance matrix
  • Qd: (optional) discrete time process/system noise matrix
  • R: (optional) measurement (white) noise variance
  • baro_tau: (optional) barometer time constant [s]
  • acc_tau: (optional) accelerometer time constant [s]
  • gyro_tau: (optional) gyroscope time constant [s]
  • fogm_tau: (optional) FOGM catch-all time constant [s]
  • date: (optional) measurement date (decimal year) for IGRF [yr]
  • core: (optional) if true, include core magnetic field in measurement

Returns:

  • filt_res: FILTres filter results struct
source
MagNav.nekfFunction
nekf(ins::INS, meas, itp_mapS,
     x_nn::Matrix = meas[:,:],
     m            = Dense(1 => 1);
     P0           = create_P0(),
     Qd           = create_Qd(),
     R            = 1.0,
     baro_tau     = 3600.0,
     acc_tau      = 3600.0,
     gyro_tau     = 3600.0,
     fogm_tau     = 600.0,
     date         = get_years(2020,185),
     core::Bool   = false)

Measurement noise covariance-adaptive neural extended Kalman filter (nEKF) for airborne magnetic anomaly navigation.

Arguments:

  • ins: INS inertial navigation system struct
  • meas: scalar magnetometer measurement [nT]
  • itp_mapS: scalar map interpolation function (f(lat,lon) or f(lat,lon,alt))
  • x_nn: N x Nf data matrix for neural network (Nf is number of features)
  • m: neural network model
  • P0: (optional) initial covariance matrix
  • Qd: (optional) discrete time process/system noise matrix
  • R: (optional) measurement (white) noise variance
  • baro_tau: (optional) barometer time constant [s]
  • acc_tau: (optional) accelerometer time constant [s]
  • gyro_tau: (optional) gyroscope time constant [s]
  • fogm_tau: (optional) FOGM catch-all time constant [s]
  • date: (optional) measurement date (decimal year) for IGRF [yr]
  • core: (optional) if true, include core magnetic field in measurement

Returns:

  • filt_res: FILTres filter results struct
source
MagNav.nekf_trainMethod
nekf_train(lat, lon, alt, vn, ve, vd, fn, fe, fd, Cnb, meas, dt,
           itp_mapS, x_nn::Matrix, y_nn::Matrix;
           P0                   = create_P0(),
           Qd                   = create_Qd(),
           R                    = 1.0,
           baro_tau             = 3600.0,
           acc_tau              = 3600.0,
           gyro_tau             = 3600.0,
           fogm_tau             = 600.0,
           η_adam               = 0.1,
           epoch_adam::Int      = 10,
           hidden::Int          = 1,
           activation::Function = swish,
           l_window::Int        = 50,
           date                 = get_years(2020,185),
           core::Bool           = false)

Train a measurement noise covariance-adaptive neural extended Kalman filter (nEKF) model for airborne magnetic anomaly navigation.

Arguments:

  • lat: latitude [rad]
  • lon: longitude [rad]
  • alt: altitude [m]
  • vn: north velocity [m/s]
  • ve: east velocity [m/s]
  • vd: down velocity [m/s]
  • fn: north specific force [m/s^2]
  • fe: east specific force [m/s^2]
  • fd: down specific force [m/s^2]
  • Cnb: direction cosine matrix (body to navigation) [-]
  • meas: scalar magnetometer measurement [nT]
  • dt: measurement time step [s]
  • itp_mapS: scalar map interpolation function (f(lat,lon) or f(lat,lon,alt))
  • x_nn: N x Nf data matrix for neural network (Nf is number of features)
  • y_nn: y target matrix for neural network ([latitude longitude])
  • P0: (optional) initial covariance matrix
  • Qd: (optional) discrete time process/system noise matrix
  • R: (optional) measurement (white) noise variance
  • baro_tau: (optional) barometer time constant [s]
  • acc_tau: (optional) accelerometer time constant [s]
  • gyro_tau: (optional) gyroscope time constant [s]
  • fogm_tau: (optional) FOGM catch-all time constant [s]
  • η_adam: (optional) learning rate for Adam optimizer
  • epoch_adam: (optional) number of epochs for Adam optimizer
  • hidden: (optional) hidden layers & nodes (e.g., [8,8] for 2 hidden layers, 8 nodes each)
  • activation: (optional) activation function
    • relu = rectified linear unit
    • σ = sigmoid (logistic function)
    • swish = self-gated
    • tanh = hyperbolic tan
    • run plot_activation() for a visual
  • l_window: (optional) temporal window length
  • date: (optional) measurement date (decimal year) for IGRF [yr]
  • core: (optional) if true, include core magnetic field in measurement

Returns:

  • m: neural network model
source
MagNav.nekf_trainMethod
nekf_train(ins::INS, meas, itp_mapS, x_nn::Matrix, y_nn::Matrix;
           P0                   = create_P0(),
           Qd                   = create_Qd(),
           R                    = 1.0,
           baro_tau             = 3600.0,
           acc_tau              = 3600.0,
           gyro_tau             = 3600.0,
           fogm_tau             = 600.0,
           η_adam               = 0.1,
           epoch_adam::Int      = 10,
           hidden::Int          = 1,
           activation::Function = swish,
           l_window::Int        = 50,
           date                 = get_years(2020,185),
           core::Bool           = false)

Train a measurement noise covariance-adaptive neural extended Kalman filter (nEKF) model for airborne magnetic anomaly navigation.

Arguments:

  • ins: INS inertial navigation system struct
  • meas: scalar magnetometer measurement [nT]
  • itp_mapS: scalar map interpolation function (f(lat,lon) or f(lat,lon,alt))
  • x_nn: N x Nf data matrix for neural network (Nf is number of features)
  • y_nn: y target matrix for neural network ([latitude longitude])
  • P0: (optional) initial covariance matrix
  • Qd: (optional) discrete time process/system noise matrix
  • R: (optional) measurement (white) noise variance
  • baro_tau: (optional) barometer time constant [s]
  • acc_tau: (optional) accelerometer time constant [s]
  • gyro_tau: (optional) gyroscope time constant [s]
  • fogm_tau: (optional) FOGM catch-all time constant [s]
  • η_adam: (optional) learning rate for Adam optimizer
  • epoch_adam: (optional) number of epochs for Adam optimizer
  • hidden: (optional) hidden layers & nodes (e.g., [8,8] for 2 hidden layers, 8 nodes each)
  • activation: (optional) activation function
    • relu = rectified linear unit
    • σ = sigmoid (logistic function)
    • swish = self-gated
    • tanh = hyperbolic tan
    • run plot_activation() for a visual
  • l_window: (optional) temporal window length
  • date: (optional) measurement date (decimal year) for IGRF [yr]
  • core: (optional) if true, include core magnetic field in measurement

Returns:

  • m: neural network model
source
MagNav.nekf_trainMethod
nekf_train(xyz::XYZ, ind, meas, itp_mapS, x::Matrix;
           P0                   = create_P0(),
           Qd                   = create_Qd(),
           R                    = 1.0,
           baro_tau             = 3600.0,
           acc_tau              = 3600.0,
           gyro_tau             = 3600.0,
           fogm_tau             = 600.0,
           η_adam               = 0.1,
           epoch_adam::Int      = 10,
           hidden::Int          = 1,
           activation::Function = swish,
           l_window::Int        = 50,
           date                 = get_years(2020,185),
           core::Bool           = false)

Train a measurement noise covariance-adaptive neural extended Kalman filter (nEKF) model for airborne magnetic anomaly navigation.

Arguments:

  • xyz: XYZ flight data struct
  • ind: selected data indices
  • meas: scalar magnetometer measurement [nT]
  • itp_mapS: scalar map interpolation function (f(lat,lon) or f(lat,lon,alt))
  • x: N x Nf data matrix (Nf is number of features)
  • P0: (optional) initial covariance matrix
  • Qd: (optional) discrete time process/system noise matrix
  • R: (optional) measurement (white) noise variance
  • baro_tau: (optional) barometer time constant [s]
  • acc_tau: (optional) accelerometer time constant [s]
  • gyro_tau: (optional) gyroscope time constant [s]
  • fogm_tau: (optional) FOGM catch-all time constant [s]
  • η_adam: (optional) learning rate for Adam optimizer
  • epoch_adam: (optional) number of epochs for Adam optimizer
  • hidden: (optional) hidden layers & nodes (e.g., [8,8] for 2 hidden layers, 8 nodes each)
  • activation: (optional) activation function
    • relu = rectified linear unit
    • σ = sigmoid (logistic function)
    • swish = self-gated
    • tanh = hyperbolic tan
    • run plot_activation() for a visual
  • l_window: (optional) temporal window length
  • date: (optional) measurement date (decimal year) for IGRF [yr]
  • core: (optional) if true, include core magnetic field in measurement

Returns:

  • m: neural network model
  • data_norms: length-3 tuple of data normalizations, (v_scale,x_bias,x_scale)
source
MagNav.norm_setsMethod
norm_sets(train, val, test;
          norm_type::Symbol = :standardize,
          no_norm           = falses(size(train,2)))

Normalize (or standardize) features (columns) of training, validation, & testing data.

Arguments:

  • train: N_train x Nf training data
  • val: N_val x Nf validation data
  • test: N_test x Nf testing data
  • norm_type: (optional) normalization type:
    • :standardize = Z-score normalization
    • :normalize = min-max normalization
    • :scale = scale by maximum absolute value, bias = 0
    • :none = scale by 1, bias = 0
  • no_norm: (optional) length-Nf Boolean indices of features to not be normalized

Returns:

  • train_bias: 1 x Nf training data biases (means, mins, or zeros)
  • train_scale: 1 x Nf training data scaling factors (std devs, maxs-mins, or ones)
  • train: N_train x Nf training data, normalized
  • val: N_val x Nf validation data, normalized
  • test: N_test x Nf testing data, normalized
source
MagNav.norm_setsMethod
norm_sets(train, test;
          norm_type::Symbol = :standardize,
          no_norm           = falses(size(train,2)))

Normalize (or standardize) features (columns) of training & testing data.

Arguments:

  • train: N_train x Nf training data
  • test: N_test x Nf testing data
  • norm_type: (optional) normalization type:
    • :standardize = Z-score normalization
    • :normalize = min-max normalization
    • :scale = scale by maximum absolute value, bias = 0
    • :none = scale by 1, bias = 0
  • no_norm: (optional) length-Nf Boolean indices of features to not be normalized

Returns:

  • train_bias: 1 x Nf training data biases (means, mins, or zeros)
  • train_scale: 1 x Nf training data scaling factors (std devs, maxs-mins, or ones)
  • train: N_train x Nf training data, normalized
  • test: N_test x Nf testing data, normalized
source
MagNav.norm_setsMethod
norm_sets(train;
          norm_type::Symbol = :standardize,
          no_norm           = falses(size(train,2)))

Normalize (or standardize) features (columns) of training data.

Arguments:

  • train: N_train x Nf training data
  • norm_type: (optional) normalization type:
    • :standardize = Z-score normalization
    • :normalize = min-max normalization
    • :scale = scale by maximum absolute value, bias = 0
    • :none = scale by 1, bias = 0
  • no_norm: (optional) length-Nf Boolean indices of features to not be normalized

Returns:

  • train_bias: 1 x Nf training data biases (means, mins, or zeros)
  • train_scale: 1 x Nf training data scaling factors (std devs, maxs-mins, or ones)
  • train: N_train x Nf training data, normalized
source
MagNav.ottawa_area_mapsFunction
ottawa_area_maps(f::Union{String,Symbol} = "")

Magnetic anomaly maps near Ottawa, Ontario, Canada, contains:

  • Eastern_395.h5: Eastern Ontario at 395 m HAE
  • Eastern_drape.h5: Eastern Ontario on drape
  • Renfrew_395.h5: Renfrew at 395 m HAE
  • Renfrew_555.h5: Renfrew at 555 m HAE
  • Renfrew_drape.h5: Renfrew on drape
  • HighAlt_5181.h5: High Altitude mini-survey (within Renfrew) at 5181 m HAE
  • Perth_800.h5: Perth mini-survey (within Eastern Ontario) at 800 m HAE

NOTE: Missing map data within each map has been filled in (using k-nearest neighbors) so that the maps are fully filled. Care must be taken to not navigate in the filled-in areas, as this is not real data and only done for more accurate and consistent upward continuation of the maps. Use the map_check function with the desired map and flight path data to check if the map may be used without navigating into filled-in (artificial) areas.

Arguments:

  • f: (optional) name of data file (.h5 extension optional)

Returns:

  • p: path of folder or f data file
source
MagNav.ottawa_area_maps_gxfFunction
ottawa_area_maps_gxf(f::Union{String,Symbol} = "")

GXF versions of small magnetic anomaly maps near Ottawa, Ontario, Canada, contains:

  • HighAlt_Mag.gxf: High Altitude mini-survey (within Renfrew) at 5181 m HAE
  • Perth_Mag.gxf: Perth mini-survey (within Eastern Ontario) at 800 m HAE

Arguments:

  • f: (optional) name of data file (_Mag & .gxf extension optional)

Returns:

  • p: path of folder or f data file
source
MagNav.path2kmlFunction
path2kml(path::Path,
         path_kml::String = "path.kml";
         width::Int       = 3,
         color1::String   = "",
         color2::String   = "00ffffff",
         points::Bool     = false)

Create KML file of flight path for use with Google Earth.

Arguments:

  • path: Path struct, i.e., Traj trajectory struct, INS inertial navigation system struct, or FILTout filter extracted output struct
  • path_kml: (optional) path/name of flight path KML file to save (.kml extension optional)
  • width: (optional) line width
  • color1: (optional) path color
  • color2: (optional) below-path color
  • points: (optional) if true, create points instead of line

Returns:

  • nothing: path_kml is created
source
MagNav.path2kmlFunction
path2kml(lat::Vector, lon::Vector, alt::Vector,
         path_kml::String   = "path.kml";
         path_units::Symbol = :rad,
         width::Int         = 3,
         color1::String     = "ff000000",
         color2::String     = "80000000",
         points::Bool       = false)

Create KML file of flight path for use with Google Earth.

Arguments:

  • lat: latitude [rad] or [deg]
  • lon: longitude [rad] or [deg]
  • alt: altitude [m]
  • path_kml: (optional) path/name of flight path KML file to save (.kml extension optional)
  • path_units: (optional) lat/lon units {:rad,:deg}
  • width: (optional) line width
  • color1: (optional) path color
  • color2: (optional) below-path color
  • points: (optional) if true, create points instead of line

Returns:

  • nothing: path_kml is created
source
MagNav.plot_activationFunction
plot_activation(activation = [:relu,:σ,:swish,:tanh];
                plot_deriv::Bool  = false,
                show_plot::Bool   = true,
                save_plot::Bool   = false,
                plot_png::String  = "act_func.png")

Plot activation function(s) or their derivative(s).

Arguments:

  • activation: activation function(s) to plot
    • relu = rectified linear unit
    • σ = sigmoid (logistic function)
    • swish = self-gated
    • tanh = hyperbolic tan
  • plot_deriv: (optional) if true, plot activation function(s) derivative(s)
  • show_plot: (optional) if true, show p1
  • save_plot: (optional) if true, save p1 as plot_png
  • plot_png: (optional) plot file name to save (.png extension optional)

Returns:

  • p1: plot of activation function(s) or their derivative(s)
source
MagNav.plot_autocorFunction
plot_autocor(x::Vector, dt = 0.1, dt_max = 300.0;
             show_plot::Bool  = true,
             save_plot::Bool  = false,
             plot_png::String = "autocor.png")

Plot autocorrelation of data (e.g., actual - expected measurements). Prints out σ = standard deviation & τ = autocorrelation decay to e^-1 of x.

Arguments:

  • x: data vector
  • dt: (optional) measurement time step [s]
  • dt_max: (optional) maximum time step to evaluate [s]
  • show_plot: (optional) if true, show p1
  • save_plot: (optional) if true, save p1 as plot_png
  • plot_png: (optional) plot file name to save (.png extension optional)

Returns:

  • p1: plot of autocorrelation of x
source
MagNav.plot_basicFunction
plot_basic(tt::Vector, y::Vector, ind = trues(length(tt));
           lab::String      = "",
           xlab::String     = "time [min]",
           ylab::String     = "",
           show_plot::Bool  = true,
           save_plot::Bool  = false,
           plot_png::String = "data_vs_time.png")

Plot data vs time.

Arguments:

  • tt: length-N time vector [s]
  • y: length-N data vector
  • ind: (optional) selected data indices
  • lab: (optional) data (legend) label
  • xlab: (optional) x-axis label
  • ylab: (optional) y-axis label
  • show_plot: (optional) if true, show p1
  • save_plot: (optional) if true, save p1 as plot_png
  • plot_png: (optional) plot file name to save (.png extension optional)

Returns:

  • p1: plot of y vs tt
source
MagNav.plot_correlationFunction
plot_correlation(x::Vector, y::Vector,
                 xfeature::Symbol = :feature_1,
                 yfeature::Symbol = :feature_2;
                 lim::Real        = 0,
                 dpi::Int         = 200,
                 show_plot::Bool  = true,
                 save_plot::Bool  = false,
                 plot_png::String = "$xfeature-$yfeature.png",
                 silent::Bool     = true)

Plot the correlation between 2 features.

Arguments:

  • x: x-axis data
  • y: y-axis data
  • xfeature: x-axis feature name
  • yfeature: y-axis feature name
  • lim: (optional) only plot if Pearson correlation coefficient > lim
  • dpi: (optional) dots per inch (image resolution)
  • show_plot: (optional) if true, show p1
  • save_plot: (optional) if true, save p1 as plot_png
  • plot_png: (optional) plot file name to save (.png extension optional)
  • silent: (optional) if true, no print outs

Returns:

  • p1: plot of yfeature vs xfeature correlation
source
MagNav.plot_correlationFunction
plot_correlation(xyz::XYZ,
                 xfeature::Symbol = :mag_1_c,
                 yfeature::Symbol = :mag_1_uc,
                 ind              = trues(xyz.traj.N);
                 lim::Real        = 0,
                 dpi::Int         = 200,
                 show_plot::Bool  = true,
                 save_plot::Bool  = false,
                 plot_png::String = "$xfeature-$yfeature.png",
                 silent::Bool     = true)

Plot the correlation between 2 features.

Arguments:

  • xyz: XYZ flight data struct
  • xfeature: x-axis feature name
  • yfeature: y-axis feature name
  • ind: (optional) selected data indices
  • lim: (optional) only plot if Pearson correlation coefficient > lim
  • dpi: (optional) dots per inch (image resolution)
  • show_plot: (optional) if true, show p1
  • save_plot: (optional) if true, save p1 as plot_png
  • plot_png: (optional) plot file name to save (.png extension optional)
  • silent: (optional) if true, no print outs

Returns:

  • p1: plot of yfeature vs xfeature correlation
source
MagNav.plot_correlation_matrixFunction
plot_correlation_matrix(xyz::XYZ, ind = trues(xyz.traj.N),
                        features_setup::Vector{Symbol} = [:mag_1_uc,:TL_A_flux_a];
                        terms             = [:permanent],
                        sub_diurnal::Bool = false,
                        sub_igrf::Bool    = false,
                        bpf_mag::Bool     = false,
                        dpi::Int          = 200,
                        Nmax::Int         = 1000,
                        show_plot::Bool   = true,
                        save_plot::Bool   = false,
                        plot_png::String  = "correlation_matrix.png")

Plot the correlation matrix for 2-5 features.

Arguments:

  • xyz: XYZ flight data struct
  • ind: selected data indices
  • features_setup: vector of features to include
  • terms: (optional) Tolles-Lawson terms to use {:permanent,:induced,:eddy,:bias}
  • sub_diurnal: (optional) if true, subtract diurnal from scalar magnetometer measurements
  • sub_igrf: (optional) if true, subtract IGRF from scalar magnetometer measurements
  • bpf_mag: (optional) if true, bpf scalar magnetometer measurements
  • dpi: (optional) dots per inch (image resolution)
  • Nmax: (optional) maximum number of data points plotted
  • show_plot: (optional) if true, show p1
  • save_plot: (optional) if true, save p1 as plot_png
  • plot_png: (optional) plot file name to save (.png extension optional)

Returns:

  • p1: plot of correlation matrix between features (created from features_setup)
source
MagNav.plot_correlation_matrixMethod
plot_correlation_matrix(x::AbstractMatrix, features::Vector{Symbol};
                        dpi::Int         = 200,
                        Nmax::Int        = 1000,
                        show_plot::Bool  = true,
                        save_plot::Bool  = false,
                        plot_png::String = "correlation_matrix.png")

Plot the correlation matrix for 2-5 features.

Arguments:

  • x: N x Nf data matrix (Nf is number of features)
  • features: length-Nf feature vector (including components of TL A, etc.)
  • dpi: (optional) dots per inch (image resolution)
  • Nmax: (optional) maximum number of data points plotted
  • show_plot: (optional) if true, show p1
  • save_plot: (optional) if true, save p1 as plot_png
  • plot_png: (optional) plot file name to save (.png extension optional)

Returns:

  • p1: plot of correlation matrix between features
source
MagNav.plot_events!Function
plot_events!(p1::Plot, t::Real, lab::String = "";
             legend::Symbol = :outertopright)

Plot in-flight event on an existing plot.

Arguments:

  • p1: plot (i.e., time series of data)
  • t: time of in-flight event
  • lab: (optional) in-flight event (legend) label
  • legend: (optional) legend position (e.g., :topleft,:outertopright)

Returns:

  • nothing: in-flight event is plotted on p1
source
MagNav.plot_events!Method
plot_events!(p1::Plot, flight::Symbol,  df_event::DataFrame;
             keyword::String = "",
             show_lab::Bool  = true,
             t0::Real        = 0,
             t_units::Symbol = :sec,
             legend::Symbol  = :outertopright)

Plot in-flight event(s) on an existing plot.

Arguments:

  • p1: plot (i.e., time series of data)
  • flight: flight name (e.g., :Flt1001)
  • df_event: lookup table (DataFrame) of in-flight events
FieldTypeDescription
flightSymbolflight name (e.g., :Flt1001)
ttRealtime of event [s]
eventStringevent description
  • keyword: (optional) keyword to search within events, case insensitive
  • show_lab: (optional) if true, show in-flight event (legend) label(s)
  • t0: (optional) time offset [t_units]
  • t_units: (optional) time units {:sec,:min}
  • legend: (optional) legend position (e.g., :topleft,:outertopright)

Returns:

  • nothing: in-flight events are plotted on p1
source
MagNav.plot_eventsMethod
plot_events(p1::Plot, flight::Symbol,  df_event::DataFrame;
            keyword::String = "",
            show_lab::Bool  = true,
            t0::Real        = 0,
            t_units::Symbol = :sec,
            legend::Symbol  = :outertopright)

Plot in-flight event(s) on an existing plot.

Arguments:

  • p1: plot (i.e., time series of data)
  • flight: flight name (e.g., :Flt1001)
  • df_event: lookup table (DataFrame) of in-flight events
FieldTypeDescription
flightSymbolflight name (e.g., :Flt1001)
ttRealtime of event [s]
eventStringevent description
  • keyword: (optional) keyword to search within events, case insensitive
  • show_lab: (optional) if true, show in-flight event (legend) label(s)
  • t0: (optional) time offset [t_units]
  • t_units: (optional) time units {:sec,:min}
  • legend: (optional) legend position (e.g., :topleft,:outertopright)

Returns:

  • p2: p1 with in-flight events
source
MagNav.plot_filt!Method
plot_filt!(p1::Plot, traj::Traj, ins::INS, filt_out::FILTout;
           dpi::Int        = 200,
           Nmax::Int       = 5000,
           show_plot::Bool = true,
           save_plot::Bool = false)

Plot flights paths on an existing plot.

Arguments:

  • p1: plot (i.e., map)
  • traj: Traj trajectory struct
  • ins: INS inertial navigation system struct
  • filt_out: FILTout filter extracted output struct
  • dpi: (optional) dots per inch (image resolution)
  • Nmax: (optional) maximum number of data points plotted
  • show_plot: (optional) if true, show plots
  • save_plot: (optional) if true, save plots with default file names

Returns:

  • nothing: flight paths are plotted on p1
source
MagNav.plot_filtMethod
plot_filt(traj::Traj, ins::INS, filt_out::FILTout;
          dpi::Int        = 200,
          Nmax::Int       = 5000,
          plot_vel::Bool  = false,
          show_plot::Bool = true,
          save_plot::Bool = false)

Plot flights paths and latitudes & longitudes vs time.

Arguments:

  • traj: Traj trajectory struct
  • ins: INS inertial navigation system struct
  • filt_out: FILTout filter extracted output struct
  • dpi: (optional) dots per inch (image resolution)
  • Nmax: (optional) maximum number of data points plotted
  • plot_vel: (optional) if true, plot velocities
  • show_plot: (optional) if true, show plots
  • save_plot: (optional) if true, save plots with default file names

Returns:

  • p1: flight paths
  • p2: latitudes vs time
  • p3: longitudes vs time
  • p4: if plot_vel = true, north velocities vs time
  • p5: if plot_vel = true, east velocities vs time
source
MagNav.plot_filtMethod
plot_filt(p1::Plot, traj::Traj, ins::INS, filt_out::FILTout;
          dpi::Int        = 200,
          Nmax::Int       = 5000,
          plot_vel::Bool  = false,
          show_plot::Bool = true,
          save_plot::Bool = false)

Plot flights paths on an existing plot and latitudes & longitudes vs time.

Arguments:

  • p1: plot (i.e., map)
  • traj: Traj trajectory struct
  • ins: INS inertial navigation system struct
  • filt_out: FILTout filter extracted output struct
  • dpi: (optional) dots per inch (image resolution)
  • Nmax: (optional) maximum number of data points plotted
  • plot_vel: (optional) if true, plot velocities
  • show_plot: (optional) if true, show plots
  • save_plot: (optional) if true, save plots with default file names

Returns:

  • p2: p1 with flight paths
  • p3: latitudes vs time
  • p4: longitudes vs time
  • p5: if plot_vel = true, north velocities vs time
  • p6: if plot_vel = true, east velocities vs time
source
MagNav.plot_filt_errMethod
plot_filt_err(traj::Traj, filt_out::FILTout, crlb_out::CRLBout;
              dpi::Int        = 200,
              Nmax::Int       = 5000,
              plot_vel::Bool  = false,
              show_plot::Bool = true,
              save_plot::Bool = false)

Plot northing & easting errors vs time.

Arguments:

  • traj: Traj trajectory struct
  • filt_out: FILTout filter extracted output struct
  • crlb_out: CRLBout Cramér–Rao lower bound extracted output struct
  • dpi: (optional) dots per inch (image resolution)
  • Nmax: (optional) maximum number of data points plotted
  • plot_vel: (optional) if true, plot velocity errors
  • show_plot: (optional) if true, show plots
  • save_plot: (optional) if true, save plots with default file names

Returns:

  • p1: northing errors vs time
  • p2: easting errors vs time
  • p3: if plot_vel = true, north velocity errors vs time
  • p4: if plot_vel = true, east velocity errors vs time
source
MagNav.plot_frequencyMethod
plot_frequency(xyz::XYZ;
               ind                = trues(xyz.traj.N),
               field::Symbol      = :mag_1_uc,
               freq_type::Symbol  = :PSD,
               detrend_data::Bool = true,
               window::Function   = hamming,
               dpi::Int           = 200,
               show_plot::Bool    = true,
               save_plot::Bool    = false,
               plot_png::String   = "PSD.png")

Plot frequency data, either Welch power spectral density (PSD) or spectrogram.

Arguments:

  • xyz: XYZ flight data struct
  • ind: (optional) selected data indices
  • field: (optional) data field in xyz to plot
  • freq_type: (optional) frequency plot type {:PSD,:psd,:spectrogram,:spec}
  • detrend_data: (optional) if true, detrend plot data
  • window: (optional) type of window used
  • dpi: (optional) dots per inch (image resolution)
  • show_plot: (optional) if true, show p1
  • save_plot: (optional) if true, save p1 as plot_png
  • plot_png: (optional) plot file name to save (.png extension optional)

Returns:

  • p1: plot of Welch power spectral density (PSD) or spectrogram
source
MagNav.plot_magMethod
plot_mag(xyz::XYZ;
         ind                       = trues(xyz.traj.N),
         detrend_data::Bool        = false,
         use_mags::Vector{Symbol}  = [:all_mags],
         vec_terms::Vector{Symbol} = [:all],
         ylim::Tuple               = (),
         dpi::Int                  = 200,
         show_plot::Bool           = true,
         save_plot::Bool           = false,
         plot_png::String          = "scalar_mags.png")

Plot scalar or vector (fluxgate) magnetometer data from a given flight test.

Arguments:

  • xyz: XYZ flight data struct
  • ind: (optional) selected data indices
  • detrend_data: (optional) if true, detrend plot data
  • use_mags: (optional) scalar or vector (fluxgate) magnetometers to plot {:all_mags, :comp_mags or :mag_1_c, :mag_1_uc, :flux_a, etc.}
    • :all_mags = all provided scalar magnetometer fields (e.g., :mag_1_c, :mag_1_uc, etc.)
    • :comp_mags = provided compensation(s) between :mag_1_uc & :mag_1_c, etc.
  • vec_terms: (optional) vector magnetometer (fluxgate) terms to plot {:all or :x,:y,:z,:t}
  • ylim: (optional) length-2 plot y limits (ymin,ymax) [nT]
  • dpi: (optional) dots per inch (image resolution)
  • show_plot: (optional) if true, show p1
  • save_plot: (optional) if true, save p1 as plot_png
  • plot_png: (optional) plot file name to save (.png extension optional)

Returns:

  • p1: plot of scalar or vector (fluxgate) magnetometer data
source
MagNav.plot_mag_cMethod
plot_mag_c(xyz::XYZ,xyz_comp::XYZ;
           ind                      = trues(xyz.traj.N),
           ind_comp                 = trues(xyz_comp.traj.N),
           detrend_data::Bool       = true,
           λ                        = 0.025,
           terms                    = [:permanent,:induced,:eddy],
           pass1                    = 0.1,
           pass2                    = 0.9,
           fs                       = 10.0,
           use_mags::Vector{Symbol} = [:all_mags],
           use_vec::Symbol          = :flux_a,
           plot_diff::Bool          = false,
           plot_mag_1_uc::Bool      = true,
           plot_mag_1_c::Bool       = true,
           ylim                     = (),
           dpi::Int                 = 200,
           show_plot::Bool          = true,
           save_plot::Bool          = false,
           plot_png::String         = "scalar_mags_comp.png")

Plot compensated magnetometer(s) data from a given flight test. Assumes Mag 1 (i.e., :mag_1_uc & :mag_1_c) is the best magnetometer (i.e., stinger).

Arguments:

  • xyz: XYZ flight data struct
  • xyz_comp: XYZ flight data struct to use for compensation
  • ind: (optional) selected data indices
  • ind_comp: (optional) selected data indices to use for compensation
  • detrend_data: (optional) if true, detrend plot data
  • λ: (optional) ridge parameter
  • terms: (optional) Tolles-Lawson terms to use {:permanent,:induced,:eddy,:bias}
  • pass1: (optional) filter first passband frequency [Hz]
  • pass2: (optional) filter second passband frequency [Hz]
  • fs: (optional) filter sampling frequency [Hz]
  • use_mags: (optional) scalar or vector (fluxgate) magnetometers to plot {:all_mags, or :mag_1_uc, etc.}
    • :all_mags = all uncompensated scalar magnetometer fields (e.g., :mag_1_uc, etc.)
  • use_vec: (optional) vector magnetometer (fluxgate) to use for Tolles-Lawson A matrix {:flux_a, etc.}
  • plot_diff: (optional) if true, plot difference between provided compensated data & compensated mags as performed here
  • plot_mag_1_uc: (optional) if true, plot mag1uc (uncompensated mag_1)
  • plot_mag_1_c: (optional) if true, plot mag1c (compensated mag_1)
  • ylim: (optional) length-2 plot y limits (ymin,ymax) [nT]
  • dpi: (optional) dots per inch (image resolution)
  • show_plot: (optional) if true, show p1
  • save_plot: (optional) if true, save p1 as plot_png
  • plot_png: (optional) plot file name to save (.png extension optional)

Returns:

  • p1: plot of compensated magnetometer data
source
MagNav.plot_mag_mapMethod
plot_mag_map(path::Path, mag, itp_mapS;
             lab::String        = "magnetometer",
             order::Symbol      = :magmap,
             dpi::Int           = 200,
             Nmax::Int          = 5000,
             detrend_data::Bool = true,
             show_plot::Bool    = true,
             save_plot::Bool    = false,
             plot_png::String   = "mag_vs_map.png")

Plot scalar magnetometer measurements vs map values.

Arguments:

  • path: Path struct, i.e., Traj trajectory struct, INS inertial navigation system struct, or FILTout filter extracted output struct
  • mag: scalar magnetometer measurements [nT]
  • itp_mapS: scalar map interpolation function (f(lat,lon) or f(lat,lon,alt))
  • lab: (optional) magnetometer data (legend) label
  • order: (optional) plotting order {:magmap,:mapmag}
  • dpi: (optional) dots per inch (image resolution)
  • Nmax: (optional) maximum number of data points plotted
  • detrend_data: (optional) if true, detrend plot data
  • show_plot: (optional) if true, show p1
  • save_plot: (optional) if true, save p1 as plot_png
  • plot_png: (optional) plot file name to save (.png extension optional)

Returns:

  • p1: scalar magnetometer measurements vs map values
source
MagNav.plot_mag_map_errMethod
plot_mag_map_err(path::Path, mag, itp_mapS;
                 lab::String        = "",
                 dpi::Int           = 200,
                 Nmax::Int          = 5000,
                 detrend_data::Bool = true,
                 show_plot::Bool    = true,
                 save_plot::Bool    = false,
                 plot_png::String   = "mag_map_err.png")

Plot scalar magnetometer measurement vs map value errors.

Arguments:

  • path: Path struct, i.e., Traj trajectory struct, INS inertial navigation system struct, or FILTout filter extracted output struct
  • mag: scalar magnetometer measurements [nT]
  • itp_mapS: scalar map interpolation function (f(lat,lon) or f(lat,lon,alt))
  • lab: (optional) data (legend) label
  • dpi: (optional) dots per inch (image resolution)
  • Nmax: (optional) maximum number of data points plotted
  • detrend_data: (optional) if true, detrend plot data
  • show_plot: (optional) if true, show p1
  • save_plot: (optional) if true, save p1 as plot_png
  • plot_png: (optional) plot file name to save (.png extension optional)

Returns:

  • p1: scalar magnetometer measurement vs map value errors
source
MagNav.plot_mapFunction
plot_map(map_map::Matrix,
         map_xx::Vector       = [],
         map_yy::Vector       = [];
         clims::Tuple         = (),
         dpi::Int             = 200,
         margin::Int          = 2,
         Nmax::Int            = 6*dpi,
         legend::Bool         = true,
         axis::Bool           = true,
         map_color::Symbol    = :usgs,
         bg_color::Symbol     = :white,
         map_units::Symbol    = :rad,
         plot_units::Symbol   = :deg,
         b_e::AbstractBackend = gr())

Plot map.

Arguments:

  • map_map: ny x nx 2D gridded map data
  • map_xx: nx map x-direction (longitude) coordinates [rad] or [deg]
  • map_yy: ny map y-direction (latitude) coordinates [rad] or [deg]
  • clims: (optional) length-2 colorbar limits (cmin,cmax)
  • dpi: (optional) dots per inch (image resolution)
  • margin: (optional) margin around plot [mm]
  • Nmax: (optional) maximum number of data points plotted (per axis)
  • legend: (optional) if true, show legend
  • axis: (optional) if true, show axes
  • map_color: (optional) filled contour color scheme {:usgs,:gray,:gray1,:gray2,:plasma,:magma}
  • bg_color: (optional) background color
  • map_units: (optional) map xx/yy units {:rad,:deg}
  • plot_units: (optional) plot xx/yy units {:rad,:deg,:m}
  • b_e: (optional) plotting backend

Returns:

  • p1: plot of map
source
MagNav.plot_map!Function
plot_map!(p1::Plot, map_map::Matrix,
          map_xx::Vector       = [],
          map_yy::Vector       = [];
          clims::Tuple         = (),
          dpi::Int             = 200,
          margin::Int          = 2,
          Nmax::Int            = 6*dpi,
          legend::Bool         = true,
          axis::Bool           = true,
          map_color::Symbol    = :usgs,
          bg_color::Symbol     = :white,
          map_units::Symbol    = :rad,
          plot_units::Symbol   = :deg,
          b_e::AbstractBackend = gr())

Plot map on an existing plot.

Arguments:

  • p1: plot
  • map_map: ny x nx 2D gridded map data
  • map_xx: nx map x-direction (longitude) coordinates [rad] or [deg]
  • map_yy: ny map y-direction (latitude) coordinates [rad] or [deg]
  • clims: (optional) length-2 colorbar limits (cmin,cmax)
  • dpi: (optional) dots per inch (image resolution)
  • margin: (optional) margin around plot [mm]
  • Nmax: (optional) maximum number of data points plotted (per axis)
  • legend: (optional) if true, show legend
  • axis: (optional) if true, show axes
  • map_color: (optional) filled contour color scheme {:usgs,:gray,:gray1,:gray2,:plasma,:magma}
  • bg_color: (optional) background color
  • map_units: (optional) map xx/yy units {:rad,:deg}
  • plot_units: (optional) plot xx/yy units {:rad,:deg,:m}
  • b_e: (optional) plotting backend

Returns:

  • nothing: map is plotted on p1
source
MagNav.plot_map!Method
plot_map!(p1::Plot, p2::Plot, p3::Plot, mapV::MapV;
          use_mask::Bool       = true,
          clims::Tuple         = (),
          dpi::Int             = 200,
          margin::Int          = 2,
          Nmax::Int            = 6*dpi,
          legend::Bool         = true,
          axis::Bool           = true,
          map_color::Symbol    = :usgs,
          bg_color::Symbol     = :white,
          map_units::Symbol    = :rad,
          plot_units::Symbol   = :deg
          b_e::AbstractBackend = gr())

Plot map on an existing plot.

Arguments:

  • p1: plot
  • p2: plot
  • p3: plot
  • mapV: MapV vector magnetic anomaly map struct
  • use_mask: (optional) if true, apply mapV mask to map
  • clims: (optional) length-2 colorbar limits (cmin,cmax)
  • dpi: (optional) dots per inch (image resolution)
  • margin: (optional) margin around plot [mm]
  • Nmax: (optional) maximum number of data points plotted (per axis)
  • legend: (optional) if true, show legend
  • axis: (optional) if true, show axes
  • map_color: (optional) filled contour color scheme {:usgs,:gray,:gray1,:gray2,:plasma,:magma}
  • bg_color: (optional) background color
  • map_units: (optional) map xx/yy units {:rad,:deg}
  • plot_units: (optional) plot xx/yy units {:rad,:deg,:m}
  • b_e: (optional) plotting backend

Returns:

  • nothing: mapX is plotted on p1
  • nothing: mapY is plotted on p2
  • nothing: mapZ is plotted on p3
source
MagNav.plot_map!Method
plot_map!(p1::Plot, mapS::Union{MapS,MapSd,MapS3D};
          use_mask::Bool       = true,
          clims::Tuple         = (),
          dpi::Int             = 200,
          margin::Int          = 2,
          Nmax::Int            = 6*dpi,
          legend::Bool         = true,
          axis::Bool           = true,
          map_color::Symbol    = :usgs,
          bg_color::Symbol     = :white,
          map_units::Symbol    = :rad,
          plot_units::Symbol   = :deg
          b_e::AbstractBackend = gr())

Plot map on an existing plot.

Arguments:

  • p1: plot
  • mapS: MapS, MapSd, or MapS3D scalar magnetic anomaly map struct
  • use_mask: (optional) if true, apply mapS mask to map
  • clims: (optional) length-2 colorbar limits (cmin,cmax)
  • dpi: (optional) dots per inch (image resolution)
  • margin: (optional) margin around plot [mm]
  • Nmax: (optional) maximum number of data points plotted (per axis)
  • legend: (optional) if true, show legend
  • axis: (optional) if true, show axes
  • map_color: (optional) filled contour color scheme {:usgs,:gray,:gray1,:gray2,:plasma,:magma}
  • bg_color: (optional) background color
  • map_units: (optional) map xx/yy units {:rad,:deg}
  • plot_units: (optional) plot xx/yy units {:rad,:deg,:m}
  • b_e: (optional) plotting backend

Returns:

  • nothing: map is plotted on p1
source
MagNav.plot_mapMethod
plot_map(map_map::Map;
         use_mask::Bool       = true,
         clims::Tuple         = (),
         dpi::Int             = 200,
         margin::Int          = 2,
         Nmax::Int            = 6*dpi,
         legend::Bool         = true,
         axis::Bool           = true,
         map_color::Symbol    = :usgs,
         bg_color::Symbol     = :white,
         map_units::Symbol    = :rad,
         plot_units::Symbol   = :deg,
         b_e::AbstractBackend = gr())

Plot map.

Arguments:

  • map_map: Map magnetic anomaly map struct
  • use_mask: (optional) if true, apply map_map mask to map
  • clims: (optional) length-2 colorbar limits (cmin,cmax)
  • dpi: (optional) dots per inch (image resolution)
  • margin: (optional) margin around plot [mm]
  • Nmax: (optional) maximum number of data points plotted (per axis)
  • legend: (optional) if true, show legend
  • axis: (optional) if true, show axes
  • map_color: (optional) filled contour color scheme {:usgs,:gray,:gray1,:gray2,:plasma,:magma}
  • bg_color: (optional) background color
  • map_units: (optional) map xx/yy units {:rad,:deg}
  • plot_units: (optional) plot xx/yy units {:rad,:deg,:m}
  • b_e: (optional) plotting backend

Returns:

  • p1: plot of map (if map_map isa MapV, mapX)
  • p2: if map_map isa MapV, mapY
  • p3: if map_map isa MapV, mapZ
source
MagNav.plot_pathFunction
plot_path(p1::Plot, path::Path, ind = trues(path.N);
          lab::String        = "",
          Nmax::Int          = 5000,
          show_plot::Bool    = true,
          zoom_plot::Bool    = false,
          path_color::Symbol = :ignore)

Plot flight path on an existing plot.

Arguments:

  • p1: plot (i.e., map)
  • path: Path struct, i.e., Traj trajectory struct, INS inertial navigation system struct, or FILTout filter extracted output struct
  • ind: (optional) selected data indices
  • lab: (optional) data (legend) label
  • Nmax: (optional) maximum number of data points plotted
  • show_plot: (optional) if true, show plot
  • zoom_plot: (optional) if true, zoom plot onto flight path
  • path_color: (optional) path color {:ignore,:black,:gray,:red,:orange,:yellow,:green,:cyan,:blue,:purple}

Returns:

  • p2: p1 with flight path
source
MagNav.plot_pathFunction
plot_path(path::Path, ind = trues(path.N);
          lab::String        = "",
          dpi::Int           = 200,
          margin::Int        = 2,
          Nmax::Int          = 5000,
          show_plot::Bool    = true,
          zoom_plot::Bool    = true,
          path_color::Symbol = :ignore)

Plot flight path.

Arguments:

  • path: Path struct, i.e., Traj trajectory struct, INS inertial navigation system struct, or FILTout filter extracted output struct
  • ind: (optional) selected data indices
  • lab: (optional) data (legend) label
  • dpi: (optional) dots per inch (image resolution)
  • margin: (optional) margin around plot [mm]
  • Nmax: (optional) maximum number of data points plotted
  • show_plot: (optional) if true, show plot
  • zoom_plot: (optional) if true, zoom plot onto flight path
  • path_color: (optional) path color {:ignore,:black,:gray,:red,:orange,:yellow,:green,:cyan,:blue,:purple}

Returns:

  • p1: plot of flight path
source
MagNav.plot_path!Function
plot_path!(p1::Plot, path::Path, ind = trues(path.N);
           lab::String        = "",
           Nmax::Int          = 5000,
           show_plot::Bool    = true,
           zoom_plot::Bool    = false,
           path_color::Symbol = :ignore)

Plot flight path on an existing plot.

Arguments:

  • p1: plot (i.e., map)
  • path: Path struct, i.e., Traj trajectory struct, INS inertial navigation system struct, or FILTout filter extracted output struct
  • ind: (optional) selected data indices
  • lab: (optional) data (legend) label
  • Nmax: (optional) maximum number of data points plotted
  • show_plot: (optional) if true, show plot
  • zoom_plot: (optional) if true, zoom plot onto flight path
  • path_color: (optional) path color {:ignore,:black,:gray,:red,:orange,:yellow,:green,:cyan,:blue,:purple}

Returns:

  • nothing: flight path is plotted on p1
source
MagNav.plot_path!Method
plot_path!(p1::Plot, lat, lon;
           lab::String        = "",
           Nmax::Int          = 5000,
           show_plot::Bool    = true,
           zoom_plot::Bool    = false,
           path_color::Symbol = :ignore)

Plot flight path on an existing plot.

Arguments:

  • p1: plot (i.e., map)
  • lat: latitude [rad]
  • lon: longitude [rad]
  • lab: (optional) data (legend) label
  • Nmax: (optional) maximum number of data points plotted
  • show_plot: (optional) if true, show plot
  • zoom_plot: (optional) if true, zoom plot onto flight path
  • path_color: (optional) path color {:ignore,:black,:gray,:red,:orange,:yellow,:green,:cyan,:blue,:purple}

Returns:

  • nothing: flight path is plotted on p1
source
MagNav.plot_pathMethod
plot_path(lat, lon;
          lab::String        = "",
          dpi::Int           = 200,
          margin::Int        = 2,
          Nmax::Int          = 5000,
          show_plot::Bool    = true,
          zoom_plot::Bool    = true,
          path_color::Symbol = :ignore)

Plot flight path.

Arguments:

  • lat: latitude [rad]
  • lon: longitude [rad]
  • lab: (optional) data (legend) label
  • dpi: (optional) dots per inch (image resolution)
  • margin: (optional) margin around plot [mm]
  • Nmax: (optional) maximum number of data points plotted
  • show_plot: (optional) if true, show plot
  • zoom_plot: (optional) if true, zoom plot onto flight path
  • path_color: (optional) path color {:ignore,:black,:gray,:red,:orange,:yellow,:green,:cyan,:blue,:purple}

Returns:

  • p1: plot of flight path
source
MagNav.plot_pathMethod
plot_path(p1::Plot, lat, lon;
          lab::String        = "",
          Nmax::Int          = 5000,
          show_plot::Bool    = true,
          zoom_plot::Bool    = false,
          path_color::Symbol = :ignore)

Plot flight path on an existing plot.

Arguments:

  • p1: plot (i.e., map)
  • lat: latitude [rad]
  • lon: longitude [rad]
  • lab: (optional) data (legend) label
  • Nmax: (optional) maximum number of data points plotted
  • show_plot: (optional) if true, show plot
  • zoom_plot: (optional) if true, zoom plot onto flight path
  • path_color: (optional) path color {:ignore,:black,:gray,:red,:orange,:yellow,:green,:cyan,:blue,:purple}

Returns:

  • p2: p1 with flight path
source
MagNav.plot_shapleyFunction
plot_shapley(df_shap, baseline_shap,
             range_shap::UnitRange = UnitRange(axes(df_shap,1));
             title::String         = "features $range_shap",
             dpi::Int              = 200)

Plot horizontal bar graph of feature importance (Shapley effects).

Arguments:

  • df_shap: DataFrame of Shapley effects
FieldTypeDescription
feature_nameSymbolfeature name
mean_effectRealmean Shapley effect
  • baseline_shap: intercept of Shapley effects
  • range_shap: (optional) range of Shapley effects to plot (limit to length ~20)
  • dpi: (optional) dots per inch (image resolution)
  • title: (optional) plot title

Returns:

  • p1: plot of Shapley effects
source
MagNav.plsr_fitFunction
plsr_fit(x, y, k::Int = size(x,2), no_norm = falses(size(x,2));
         data_norms::Tuple = (zeros(1,1),zeros(1,1),[0.0],[0.0]),
         l_segs::Vector    = [length(y)],
         return_set::Bool  = false,
         silent::Bool      = false)

Fit a multi-input, multi-output (MIMO) partial least squares regression (PLSR) model to data with a specified output dimension. PLSR is a type of regularized linear regression where the number of components controls the strength of the regularization.

Arguments:

  • x: N x Nf data matrix (Nf is number of features)
  • y: length-N target vector
  • k: (optional) number of components
  • no_norm: (optional) length-Nf Boolean indices of features to not be normalized
  • data_norms: (optional) length-4 tuple of data normalizations, (x_bias,x_scale,y_bias,y_scale)
  • l_segs: (optional) length-N_lines vector of lengths of lines, sum(l_segs) = N
  • return_set: (optional) if true, return coef_set instead of other outputs
  • silent: (optional) if true, no print outs

Returns:

  • model: length-2 tuple of PLSR-based model, (length-Nf coefficients, bias=0)
  • data_norms: length-4 tuple of data normalizations, (x_bias,x_scale,y_bias,y_scale)
  • y_hat: length-N prediction vector
  • err: length-N mean-corrected (per line) error
  • coef_set: if return_set = true, set of coefficients (size Nf x Ny x k)
source
MagNav.predict_rnn_fullMethod
predict_rnn_full(m, x)

Apply model m to data matrix x.

Arguments:

  • m: recurrent neural network model
  • x: N x Nf data matrix (Nf is number of features)

Returns:

  • y_hat: length-N prediction vector
source
MagNav.predict_rnn_windowedMethod
predict_rnn_windowed(m, x, l_window::Int)

Apply model m to data matrix x with sliding window of length-l_window.

Arguments:

  • m: recurrent neural network model
  • x: N x Nf data matrix (Nf is number of features)
  • l_window: temporal window length

Returns:

  • y_hat: length-N prediction vector
source
MagNav.project_body_field_to_2d_igrfMethod
project_body_field_to_2d_igrf(vec_body, igrf_nav, Cnb)

Project a body frame vector onto a 2D plane defined by the direction of the IGRF and a tangent vector to the Earth ellipsoid, which is computed by taking the cross product of the IGRF with the upward direction. Returns a 2D vector whose components describe the amount of the body field that is in alignment with the Earth field and an orthogonal direction to the Earth field (roughly to the east).

Arguments:

  • vec_body: vector in body frame (e.g., aircraft induced field)
  • igrf_nav: IGRF unit vector in navigation frame
  • Cnb: 3 x 3 x N direction cosine matrix (body to navigation) [-]

Returns:

  • v_out: 2D vector whose components illustrate projection onto the Earth field and an orthogonal component
source
MagNav.psdMethod
psd(map_map::Matrix, dx, dy)

Power spectral density of a potential field (i.e., magnetic anomaly field) map. Uses the Fast Fourier Transform to determine the spectral energy distribution across the radial wavenumbers (spatial frequencies) in the Fourier transform.

Arguments:

  • map_map: ny x nx 2D gridded map data
  • dx: x-direction map step size [m]
  • dy: y-direction map step size [m]

Returns:

  • map_psd: ny x nx power spectral density of 2D gridded map data
  • kx: ny x nx x-direction radial wavenumber
  • ky: ny x nx y-direction radial wavenumber
source
MagNav.psdMethod
psd(mapS::Union{MapS,MapSd,MapS3D})

Power spectral density of a potential field (i.e., magnetic anomaly field) map. Uses the Fast Fourier Transform to determine the spectral energy distribution across the radial wavenumbers (spatial frequencies) in the Fourier transform.

Arguments:

  • mapS: MapS, MapSd, or MapS3D scalar magnetic anomaly map struct

Returns:

  • map_psd: ny x nx power spectral density of 2D gridded map data
  • kx: ny x nx x-direction radial wavenumber
  • ky: ny x nx y-direction radial wavenumber
source
MagNav.run_filtFunction
run_filt(traj::Traj, ins::INS, meas, itp_mapS, filt_type::Symbol = :ekf;
         P0             = create_P0(),
         Qd             = create_Qd(),
         R              = 1.0,
         num_part       = 1000,
         thresh         = 0.8,
         baro_tau       = 3600.0,
         acc_tau        = 3600.0,
         gyro_tau       = 3600.0,
         fogm_tau       = 600.0,
         date           = get_years(2020,185),
         core::Bool     = false,
         map_alt        = 0,
         x_nn           = nothing,
         m              = nothing,
         y_norms        = nothing,
         terms          = [:permanent,:induced,:eddy,:bias],
         flux::MagV     = MagV([0.0],[0.0],[0.0],[0.0]),
         x0_TL          = ones(eltype(P0),19),
         extract::Bool  = true,
         run_crlb::Bool = true)

Run navigation filter and optionally compute Cramér–Rao lower bound (CRLB).

Arguments:

  • traj: Traj trajectory struct
  • ins: INS inertial navigation system struct
  • meas: scalar magnetometer measurement [nT]
  • itp_mapS: scalar map interpolation function (f(lat,lon) or f(lat,lon,alt))
  • filt_type: (optional) filter type {:ekf,:mpf}
  • P0: (optional) initial covariance matrix
  • Qd: (optional) discrete time process/system noise matrix
  • R: (optional) measurement (white) noise variance
  • num_part: (optional) number of particles, only used for filt_type = :mpf
  • thresh: (optional) resampling threshold fraction {0:1}, only used for filt_type = :mpf
  • baro_tau: (optional) barometer time constant [s]
  • acc_tau: (optional) accelerometer time constant [s]
  • gyro_tau: (optional) gyroscope time constant [s]
  • fogm_tau: (optional) FOGM catch-all time constant [s]
  • date: (optional) measurement date (decimal year) for IGRF [yr]
  • core: (optional) if true, include core magnetic field in measurement
  • map_alt: (optional) map altitude [m]
  • x_nn: (optional) N x Nf data matrix for neural network (Nf is number of features)
  • m: (optional) neural network model
  • y_norms: (optional) tuple of y normalizations, i.e., (y_bias,y_scale)
  • terms: (optional) Tolles-Lawson terms to use {:permanent,:induced,:eddy,:bias}
  • flux: (optional) MagV vector magnetometer measurement struct
  • x0_TL: (optional) initial Tolles-Lawson coefficient states
  • extract: (optional) if true, extract output structs
  • run_crlb: (optional) if true, compute the Cramér–Rao lower bound (CRLB)

Returns:

  • if extract = true & run_crlb = true
    • crlb_out: CRLBout Cramér–Rao lower bound extracted output struct
    • ins_out: INSout inertial navigation system extracted output struct
    • filt_out: FILTout filter extracted output struct
  • if extract = true & run_crlb = false
    • filt_out: FILTout filter extracted output struct
  • if extract = false & run_crlb = true
    • filt_res: FILTres filter results struct
    • crlb_P: Cramér–Rao lower bound non-linear covariance matrix
  • if extract = false & run_crlb = false
    • filt_res: FILTres filter results struct
source
MagNav.run_filtMethod
run_filt(traj::Traj, ins::INS, meas, itp_mapS,
         filt_type::Vector{Symbol}; ...)

Run multiple filter models and print results (nothing returned).

Arguments:

  • filt_type: multiple filter types, e.g., [:ekf,:ekf_online_nn]
source
MagNav.save_comp_paramsFunction
save_comp_params(comp_params::CompParams,
                 comp_params_bson::String = "comp_params.bson")

Save aeromagnetic compensation parameters to BSON file.

Arguments:

  • comp_params: CompParams aeromagnetic compensation parameters struct, either:
    • NNCompParams: neural network-based aeromagnetic compensation parameters struct
    • LinCompParams: linear aeromagnetic compensation parameters struct
  • comp_params_bson: (optional) path/name of aeromagnetic compensation parameters BSON file to save (.bson extension optional)

Returns:

  • nothing: comp_params_bson is created
source
MagNav.save_mapFunction
save_map(map_map, map_xx, map_yy, map_alt, map_h5::String = "map_data.h5";
         map_info::String   = "Map",
         map_mask::BitArray = falses(1,1),
         map_border::Matrix = zeros(eltype(map_alt),1,1),
         map_units::Symbol  = :rad,
         file_units::Symbol = :deg)

Save map data to HDF5 file. Maps are typically saved in :deg units, while :rad is used internally.

Arguments:

  • map_map: ny x nx (x nz) 2D or 3D gridded map data
  • map_xx: nx map x-direction (longitude) coordinates [rad] or [deg]
  • map_yy: ny map y-direction (latitude) coordinates [rad] or [deg]
  • map_alt: map altitude(s) or ny x nx 2D gridded altitude map data [m]
  • map_h5: (optional) path/name of map data HDF5 file to save (.h5 extension optional)
  • map_info: (optional) map information
  • map_mask: (optional) ny x nx (x nz) mask for valid (not filled-in) map data
  • map_border: (optional) [xx yy] border for valid (not filled-in) map data [rad] or [deg]
  • map_units: (optional) map xx/yy units used in map_xx & map_yy {:rad,:deg}
  • file_units: (optional) map xx/yy units to use in map_h5 {:rad,:deg}

Returns:

  • nothing: map_h5 is created
source
MagNav.save_mapFunction
save_map(map_map::Map, map_h5::String = "map_data.h5";
         map_border::Matrix = zeros(eltype(map_map.alt),1,1),
         map_units::Symbol  = :rad,
         file_units::Symbol = :deg)

Save map data to HDF5 file. Maps are typically saved in :deg units, while :rad is used internally.

Arguments:

  • map_map: Map magnetic anomaly map struct
  • map_h5: (optional) path/name of map data HDF5 file to save (.h5 extension optional)
  • map_border: (optional) [xx yy] border for valid (not filled-in) map data [rad] or [deg]
  • map_units: (optional) map xx/yy units used in map_map {:rad,:deg}
  • file_units: (optional) map xx/yy units to use in map_h5 {:rad,:deg}

Returns:

  • nothing: map_h5 is created
source
MagNav.sgl_2020_trainFunction
sgl_2020_train(f::Union{String,Symbol} = "")

Flight data from the 2020 SGL flight data collection - training portion. Collected from 20-Jun-2020 to 07-Jul-2020 near Ottawa, Ontario, Canada by Sander Geophysics Ltd. (SGL) using a Cessna Grand Caravan. Contains:

  • Flt1002_train.h5
  • Flt1003_train.h5
  • Flt1004_train.h5
  • Flt1005_train.h5
  • Flt1006_train.h5
  • Flt1007_train.h5

Arguments:

  • f: (optional) name of data file (_train & .h5 extension optional)

Returns:

  • p: path of folder or f data file
source
MagNav.sgl_2021_trainFunction
sgl_2021_train(f::Union{String,Symbol} = "")

Flight data from the 2021 SGL flight data collection - training portion. Collected from 13-Dec-2021 to 05-Jan-2022 near Ottawa, Ontario, Canada by Sander Geophysics Ltd. (SGL) using a Cessna Grand Caravan. Contains:

  • Flt2001_train.h5
  • Flt2002_train.h5
  • Flt2004_train.h5
  • Flt2005_train.h5
  • Flt2006_train.h5
  • Flt2007_train.h5
  • Flt2008_train.h5
  • Flt2015_train.h5
  • Flt2016_train.h5
  • Flt2017_train.h5

Arguments:

  • f: (optional) name of data file (_train & .h5 extension optional)

Returns:

  • p: path of folder or f data file
source
MagNav.sparse_group_lassoFunction
sparse_group_lasso(m::Chain, α=1)

Get the sparse group Lasso term for sparse-input regularization, which is the combined L1 & L2 norm of the first-layer neural network weights corresponding to each input feature.

Reference: Feng & Simon, Sparse-Input Neural Networks for High-dimensional Nonparametric Regression and Classification, 2017 (pg. 4).

Arguments:

  • m: neural network model
  • α: (optional) Lasso (α=0) vs group Lasso (α=1) balancing parameter {0:1}

Returns:

  • w_norm: sparse group Lasso term
source
MagNav.sparse_group_lassoFunction
sparse_group_lasso(weights::Params, α=1)

Get the sparse group Lasso term for sparse-input regularization, which is the combined L1 & L2 norm of the first-layer neural network weights corresponding to each input feature.

Reference: Feng & Simon, Sparse-Input Neural Networks for High-dimensional Nonparametric Regression and Classification, 2017 (pg. 4).

Arguments:

  • weights: neural network model weights
  • α: (optional) Lasso (α=0) vs group Lasso (α=1) balancing parameter {0:1}

Returns:

  • w_norm: sparse group Lasso term
source
MagNav.upward_fftMethod
upward_fft(map_map::Map, alt; expand::Bool = true, α = 0)

Upward continuation of a potential field (i.e., magnetic anomaly field) map. Uses the Fast Fourier Transform (FFT) to convert the map to the frequency domain, applies an upward continuation filter, and uses the inverse FFT to convert the map back to the spatial domain. Optionally expands the map temporarily with periodic padding. Downward continuation may be performed to a limited degree as well, but be careful, as this is generally unstable and amplifies high frequencies (i.e., noise).

Reference: Blakely, Potential Theory in Gravity and Magnetic Applications, 2009, Chapter 12 & Appendix B (pg. 315-317 & 402).

Arguments:

  • map_map: Map magnetic anomaly map struct
  • alt: target upward continuation altitude(s) [m]
  • expand: (optional) if true, expand map temporarily to reduce edge effects
  • α: (optional) regularization parameter for downward continuation

Returns:

  • map_map: Map magnetic anomaly map struct, upward/downward continued (MapS with alt vector => MapS3D)
source
MagNav.upward_fftMethod
upward_fft(map_map::Matrix, dx, dy, dz; expand::Bool = true, α = 0)

Upward continuation of a potential field (i.e., magnetic anomaly field) map. Uses the Fast Fourier Transform (FFT) to convert the map to the frequency domain, applies an upward continuation filter, and uses the inverse FFT to convert the map back to the spatial domain. Optionally expands the map temporarily with periodic padding. Downward continuation may be performed to a limited degree as well, but be careful, as this is generally unstable and amplifies high frequencies (i.e., noise).

Reference: Blakely, Potential Theory in Gravity and Magnetic Applications, 2009, Chapter 12 & Appendix B (pg. 315-317 & 402).

Arguments:

  • map_map: ny x nx 2D gridded map data
  • dx: x-direction map step size [m]
  • dy: y-direction map step size [m]
  • dz: nz z-direction upward/downward continuation distance(s) [m]
  • expand: (optional) if true, expand map temporarily to reduce edge effects
  • α: (optional) regularization parameter for downward continuation

Returns:

  • map_map: ny x nx (x nz) 2D or 3D gridded map data, upward/downward continued
source
MagNav.vector_fftMethod
vector_fft(map_map::Matrix, dx, dy, D, I)

Get potential field (i.e., magnetic anomaly field) map vector components using declination and inclination.

Arguments:

  • map_map: ny x nx 2D gridded map data
  • dx: x-direction map step size [m]
  • dy: y-direction map step size [m]
  • D: map declination (Earth core field) [rad]
  • I: map inclination (Earth core field) [rad]

Returns:

  • Bx, By, Bz: map vector components
source
MagNav.xyz2h5Method
xyz2h5(data::Array, xyz_h5::String, flight::Symbol;
       tt_sort::Bool      = true,
       lines::Vector      = [()],
       lines_type::Symbol = :exclude)
source
MagNav.xyz2h5Method
xyz2h5(xyz_xyz::String, xyz_h5::String, flight::Symbol;
       lines::Vector        = [()],
       lines_type::Symbol   = :exclude,
       tt_sort::Bool        = true,
       downsample_160::Bool = true,
       return_data::Bool    = false)

Convert SGL flight data file from .xyz to HDF5.

  • Valid for SGL flights:
    • :Flt1001
    • :Flt1002
    • :Flt1003
    • :Flt1004_1005
    • :Flt1004
    • :Flt1005
    • :Flt1006
    • :Flt1007
    • :Flt1008
    • :Flt1009
    • :Flt1001_160Hz
    • :Flt1002_160Hz
    • :Flt2001_2017

May take 1+ hr for 1+ GB files. For reference, a 1.23 GB file took 46.8 min to process using a 64 GB MacBook Pro.

Arguments:

  • xyz_xyz: path/name of flight data .xyz file (.xyz extension optional)
  • xyz_h5: path/name of flight data HDF5 file to save (.h5 extension optional)
  • flight: flight name (e.g., :Flt1001)
  • lines: (optional) selected line number(s) to ONLY include or exclude, must be a vector of 3-element (line,start_time,end_time) tuple(s)
  • lines_type: (optional) whether to ONLY :include (i.e., to generate testing data) or :exclude (i.e., to generate training data) lines
  • tt_sort: (optional) if true, sort data by time (instead of line)
  • downsample_160: (optional) if true, downsample 160 Hz data to 10 Hz (only for 160 Hz data files)
  • return_data: (optional) if true, return data instead of creating xyz_h5

Returns:

  • data: if return_data = true, internal data matrix
source