DOI: 10.25820/data.006605
title: Code and Data for Statistical Decomposition and Machine Learning to Clean In-Situ Spaceflight Magnetic Field Measurements

description: This repository contains all of the MATLAB code and data required to regenerate the major contents of the manuscript named above. Note that FOUR major subdirectories are contained at the top level of the repository:&lt;br&gt;1. _libThe *_lib* subdirectory contains all of the generic functions used throughout. * &lt;strong&gt;&lt;em&gt;calcSpectrum.m&lt;/em&gt;&lt;/strong&gt; returns the power and amplitude spectrums for a given input using one of several filter types. * &lt;strong&gt;&lt;em&gt;mssa.m&lt;/em&gt;&lt;/strong&gt; returns the sub-signals output by Multichannel Singular Spectrum Analysis for a pair of inputs with a given window length. * &lt;strong&gt;&lt;em&gt;ssa.m&lt;/em&gt;&lt;/strong&gt; returns the sub-signals outpuit by Singular Spectrum Analysis for a single input with a given window length. * &lt;strong&gt;&lt;em&gt;uniform_detrend.m&lt;/em&gt;&lt;/strong&gt; returns the output of a uniform filter with given length applied to the input.&lt;br&gt;2. _sourceThe *_source* subdirectory contains the source data used for analysis of the proposed method. Specifically, Common Data Format (.cdf) files are stored from both the Parker Solar Probe FIELDS magnetometers (MAGo and MAGi) and the CASSIOPE e-POP/Swarm-Echo Magnetic Field Instrument (MGF).Note that the Parker Solar Probe FIELDS instrument suite was designed, built, and is operated by a team lead by the Space Sciences Laboratory at the University of California, Berkeley (PI: S.D. Bale). MAGo measurements from PSP are publicly available at https://fields.ssl.berkeley.edu/data/. The MAGi data stored here was generated for this manuscript.The CASSIOPE e-POP MGF data stored here (inboard and outboard) is publicly available through https://epop.phys.ucalgary.ca/data-handbook/getting-e-pop-data/.&lt;br&gt;3. ePOP_MGFThe &lt;em&gt;ePOP_MGF&lt;/em&gt; subdirectory contains all of the analysis code required to regenerate the ePOP figures and analysis presented in the manuscript. * &lt;strong&gt;&lt;em&gt;epop_dataset_gen.m&lt;/em&gt;&lt;/strong&gt; reads in 5 days worth of ePOP magnetic field data from the *_source* folder, chops the measurements into 40-second intervals, and omits any intervals that contain NaN values. The resulting data is stored in &lt;em&gt;.mat&lt;/em&gt; format in the *_intermediates* subdirectory. * &lt;strong&gt;&lt;em&gt;component_dataset_gen.m&lt;/em&gt;&lt;/strong&gt; takes the intermediate data generated from &lt;em&gt;epop_dataset_gen&lt;/em&gt; and passes each interval (for inboard and outboard magnetometers) through the MSSA function and associated labeling scheme. The sub-signals generated by MSSA are saved in &lt;em&gt;.mat&lt;/em&gt; format in the *_intermediates* subdirectory. * &lt;strong&gt;&lt;em&gt;train_neural_net.m&lt;/em&gt;&lt;/strong&gt; reads in the output of the &lt;em&gt;component_datset_gen&lt;/em&gt; and uses the data to train the neural network detailed in the manuscript. The trained model is stored in the *_intermediates* subdirectory. * &lt;strong&gt;&lt;em&gt;'&lt;/em&gt;_data_gen.m'&lt;/strong&gt;* files read in the appropriate CDF file and convert only certain time intervals of the relevant magnetic field data to &lt;em&gt;.mat&lt;/em&gt; format for use in figure generation and analysis. * *&lt;strong&gt;'&lt;em&gt;_fig_gen.m'&lt;/em&gt;&lt;/strong&gt; files use the trained neural network and data generated by *_data_gen* to generate the appropriate figures and numerical analysis. These figures are stored in the *_outputs* subdirectory.&lt;br&gt;4. PSP_MAGThe &lt;em&gt;PSP_MAG&lt;/em&gt; subdirectory contains all of the analysis code required to regenerate the PSP figures and analysis presented in the manuscript. * &lt;strong&gt;&lt;em&gt;psp_dataset_gen.m&lt;/em&gt;&lt;/strong&gt; reads in the PSP magnetic field data from the *_source* folder. The resulting data is stored in &lt;em&gt;.mat&lt;/em&gt; format in the *_intermediates* subdirectory. Note that in order to read the PSP CDF files, the NASA SPDF CDF MATLAB patch is required. This patch is documented at: https://cdf.gsfc.nasa.gov/html/matlab_cdf_patch.html. Note that the 'addpath()' MATLAB command used here may need to be updated depending on the location that the patch is stored on your local machine. * &lt;strong&gt;&lt;em&gt;psp_data_slicing.m&lt;/em&gt;&lt;/strong&gt; reads in the PSP MAG data and slices it into 40-second intervals. The resulting data is stored in the *_intermediates* subdirectory. * &lt;strong&gt;&lt;em&gt;psp_data_labeling.m&lt;/em&gt;&lt;/strong&gt; takes the sliced PSP MAG data from the *_intermediates* subdirectory and passes it through the MSSA algorithm and associated labeling scheme. The sub-signals are saved in &lt;em&gt;.mat&lt;/em&gt; format in the *_intermediates* subdirectory. * &lt;strong&gt;&lt;em&gt;psp_train_neural_net.m&lt;/em&gt;&lt;/strong&gt; reads in the output of the sub-signal labeling from the *_intermediates* subdirectory and uses it to train the classification network described in the manuscript. * &lt;em&gt;'_interval...'&lt;/em&gt;** files are used to read in specific time intervals from the PSP MAG data and generate the appropriate figures and numerical analysis. These figures are stored in the *_outputs* subdirectory.