solarwindpy.tools.swap_protons
- swap_protons(data, logger=None)[source]
Swap beam and core proton labels when the beam density dominates.
- Parameters:
data (pandas.DataFrame) – Data containing proton information. Proton species are stored in the
Slevel of the column index.logger (logging.Logger, optional) – Logger used to report indices of swapped protons. If
Nonea simple logger is created.
- Returns:
new_data (pandas.DataFrame) – Copy of
datawithp1andp2columns swapped where the beam density exceeds the core density.swap (pandas.Series) – Boolean mask indicating where swaps occurred.
Examples
>>> import pandas as pd >>> import numpy as np >>> columns = pd.MultiIndex.from_tuples([ ... ('n', '', 'p1'), ('n', '', 'p2') ... ], names=['M', 'C', 'S']) >>> df = pd.DataFrame([[2, 1], [1, 2]], columns=columns) # p1 < p2 in first row >>> new_df, mask = swap_protons(df) >>> mask.iloc[0] # First row should be swapped True