solarwindpy.tools
Utility functions for manipulating solar wind data.
This module contains helper functions that are not yet organized into their own submodules. The functions are primarily used for handling proton data and for converting log-normal parameters to their normal form.
Functions
- swap_protons
Swap beam and core proton labels when the beam density exceeds the core density.
- normal_parameters
Convert log-normal distribution parameters to normal parameters.
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([[1, 0.1], [2, 0.2]], columns=columns)
>>> new_df, mask = swap_protons(df)
>>> 'swapped_protons' in new_df.columns.get_level_values('M')
True
Functions
|
Convert log-normal parameters to normal distribution parameters. |
|
Swap beam and core proton labels when the beam density dominates. |
- 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
- normal_parameters(m, s)[source]
Convert log-normal parameters to normal distribution parameters.
- Parameters:
m (pandas.Series or numpy.ndarray) – Mean of the log-normal distribution.
s (pandas.Series or numpy.ndarray) – Standard deviation of the log-normal distribution.
- Returns:
Data frame with columns
muandsigma.- Return type:
Notes
The conversion uses
\[\mu = \exp[m + s^2/2]\]\[\sigma = \sqrt{\exp[s^2 + 2m]\,(\exp[s^2] - 1)}\]These expressions apply to both natural logarithms and base-10 logarithms.
Examples
>>> import numpy as np >>> m, s = 1.0, 0.5 # log-normal parameters >>> mu, sigma = normal_parameters(m, s) >>> mu > 1.0 # Normal mean should be > 1 True