SolarWind package
kaipy.solarWind.OMNI module
- class kaipy.solarWind.OMNI.OMNI(filename=None, doFilter=False, sigmaVal=3.0)
Bases:
SolarWindProcesses OMNI Solar Wind data from CDAweb [http://cdaweb.gsfc.nasa.gov/]. Data stored as a kaipy.solarWind.SolarWind object in GSE coordinates.
- Parameters:
filename (str) – The path to the OMNI Solar Wind data.
doFilter (bool) – Flag indicating whether to apply coarse filtering to remove outliers. Default is set to False.
sigmaVal (float) – The number of standard deviations to use for the coarse filtering. Default is to remove data points 3 standard deviation from the mean if doFilter is True.
- filter
Flag indicating whether filtering is enabled.
- Type:
bool
- sigma
The number of standard deviations used for filtering.
- Type:
float
- bad_data
List of values considered as bad data.
- Type:
list
- data
TimeSeries object to store the solar wind data.
- Type:
- __init__(self, filename=None, doFilter=False, sigmaVal=3.0)
Initializes the OMNI object.
- __read(self, filename)
Reads the solar wind data and stores the results in self.data as TimeSeries objects.
- __readData(self, fh)
Reads the variables from the file and returns a 2D array containing the data.
- __appendMetaData(self, date, filename)
Adds standard metadata to the data dictionary.
- _removeBadData(self, data, datanames=['Time', 'Bx', 'By', 'Bz', 'Vx', 'Vy', 'Vz', 'n', 'Temp', 'AE', 'AL', 'AU', 'SYMH', 'BowShockX', 'BowShockY', 'BowShockZ'], hasBeenInterpolated=None)
Linearly interpolates over bad data in the data array.
- _coarseFilter(self, dataArray, hasBeenInterpolated)
Uses coarse noise filtering to remove outliers from the data array.
- class kaipy.solarWind.OMNI.OMNIW(fWIND=None, doFilter=False, sigmaVal=3.0, windowsize=5)
Bases:
OMNIOMNIW Solar Wind file from CDAweb [http://cdaweb.gsfc.nasa.gov/]. Data stored in GSE coordinates.
- Parameters:
fWIND (str) – Path to the WIND file.
doFilter (bool) – Flag indicating whether to apply filtering to the data.
sigmaVal (float) – Sigma value for the filtering.
windowsize (int) – Size of the window for data interpolation.
- filter
Flag indicating whether filtering is applied.
- Type:
bool
- sigma
Sigma value for the filtering.
- Type:
float
- windowsize
Size of the window for data interpolation.
- Type:
int
- bad_data
List of values considered as bad data.
- Type:
list
- good_quality
List of values considered as good quality.
- Type:
list
- data
TimeSeries object to store the solar wind data.
- Type:
- __init__(self, fWIND=None, doFilter=False, sigmaVal=3.0, windowsize=5)
Constructor method.
- __read(self, fWIND)
Read the solar wind file and store results in self.data TimeSeries object.
- __readWData(self, fWIND)
Read the WIND data from file.
- __readOData(self, t0r, t1r)
Read the OMNI data from CDAWeb.
- __appendMetaData(self, date, filename)
Add standard metadata to the data dictionary.
- __combineData(self, Wdates, WdataArray, WhasBeenInterpolated, Odates, OdataArray, OhasBeenInterpolated)
Combine the WIND and OMNI data.
- kaipy.solarWind.OMNI.main()
kaipy.solarWind.SolarWind module
- class kaipy.solarWind.SolarWind.SolarWind
Bases:
objectThis class serves as an abstract base class for Solar Wind processing.
Derived classes should implement the necessary methods to read in Solar Wind data and store the results in a standard way using the kaipy.solarWind.TimeSeries object. The derived classes should also make a call to the _appendDerivedQuantities() method to compute additional solar wind variables.
- data
The TimeSeries object that stores all the Solar Wind data.
- Type:
- __init__()
Initializes the SolarWind object. See file for variables that must be set.
- _getTiltAngle(dateTime)
Get the tilt angle with respect to season for the current Date & Time.
- _gsm2sm(dateTime, x, y, z)
Convert from GSM to SM coordinates for the current Date & Time.
- bxFit()
Compute and return coefficients for a multiple linear regression fit of Bx to By & Bz.
- _appendDerivedQuantities()
Calculate and append standard derived quantities to the data dictionary.
- bxFit()
Compute and return coefficients for a multiple linear regression fit of Bx to By & Bz.
- Parameters:
None
- Returns:
The coefficients of the linear regression fit.
- Return type:
numpy.ndarray
Notes
The linear regression fit is applied to the Bx, By, and Bz data stored in the SolarWind object.
Before performing the fit, the Bx, By, and Bz data are converted to SM coordinates.
The fit is performed using the OLS method from umpy.linalg.lstsq
kaipy.solarWind.TimeSeries module
- class kaipy.solarWind.TimeSeries.TimeSeries(indict={})
Bases:
dictTimeSeries is a standard Python Dictionary with some helper functions useful for data processing collections of time series.
- append(key, name, units, data)
Append a new time series to the TimeSeries object.
- Parameters:
key (str) – Unique identifier of the variable.
name (str) – More descriptive name of the variable.
units (str) – Units of the variable (e.g., grams).
data (list) – Time series data array.
- Raises:
KeyError – If the TimeSeries object already has the specified key.
Example
>>> ts = TimeSeries() >>> ts.append('v', 'Velocity', 'm/s', [1, 2, 3])
- getData(key)
Get the data of a variable in the TimeSeries object.
- Parameters:
key (str) – Unique identifier of the variable.
- Returns:
Time series data of the variable.
- Return type:
list
Example
>>> ts = TimeSeries({'v': {'name': 'Velocity', 'data': [1, 2, 3], 'units': 'm/s'}}) >>> ts.getData('v') [1, 2, 3]
- getName(key)
Get the name of a variable in the TimeSeries object.
- Parameters:
key (str) – Unique identifier of the variable.
- Returns:
Name of the variable.
- Return type:
str
Example
>>> ts = TimeSeries({'v': {'name': 'Velocity', 'data': [1, 2, 3], 'units': 'm/s'}}) >>> ts.getName('v') 'Velocity'
- getUnits(key)
Get the units of a variable in the TimeSeries object.
- Parameters:
key (str) – Unique identifier of the variable.
- Returns:
Units of the variable.
- Return type:
str
Example
>>> ts = TimeSeries({'v': {'name': 'Velocity', 'data': [1, 2, 3], 'units': 'm/s'}}) >>> ts.getUnits('v') 'm/s'
- setData(key, data, index=None)
Set the data of a variable in the TimeSeries object.
- Parameters:
key (str) – Unique identifier of the variable.
data (list) – Time series data of the variable.
index (int, optional) – Index of the data to set. If not provided, the entire data array will be replaced.
Example
>>> ts = TimeSeries({'v': {'name': 'Velocity', 'data': [1, 2, 3], 'units': 'm/s'}}) >>> ts.setData('v', [4, 5, 6])
- setName(key, name)
Set the name of a variable in the TimeSeries object.
- Parameters:
key (str) – Unique identifier of the variable.
name (str) – Name of the variable.
Example
>>> ts = TimeSeries({'v': {'name': 'Velocity', 'data': [1, 2, 3], 'units': 'm/s'}}) >>> ts.setName('v', 'Speed')
- setUnits(key, units)
Set the units of a variable in the TimeSeries object.
- Parameters:
key (str) – Unique identifier of the variable.
units (str) – Units of the variable.
Example
>>> ts = TimeSeries({'v': {'name': 'Velocity', 'data': [1, 2, 3], 'units': 'm/s'}}) >>> ts.setUnits('v', 'km/h')
- kaipy.solarWind.TimeSeries.main()
kaipy.solarWind.WIND module
- class kaipy.solarWind.WIND.WIND(fSWE, fMFI, t0, t1, doFilter=False, sigmaVal=3.0)
Bases:
OMNIWIND Solar Wind from file. Data stored in GSE coordinates.
- Parameters:
fSWE (str) – Filepath for the SWE data.
fMFI (str) – Filepath for the MFI data.
fOMNI (str) – Filepath for the OMNI data.
xloc (str) – Location of the data.
tOffset (int) – Time offset.
t0 (datetime.datetime) – Start time.
t1 (datetime.datetime) – End time.
- filter
Flag indicating whether filtering is enabled.
- Type:
bool
- sigma
The number of standard deviations used for filtering.
- Type:
float
- bad_data
List of values considered as bad data.
- Type:
list
- data
TimeSeries object to store the solar wind data.
- Type:
- __init__(self, filename=None, doFilter=False, sigmaVal=3.0)
Initializes the OMNI object.
- __read(self, filename)
Reads the solar wind file and stores the results in self.data TimeSeries object.
- __readData(self, fh)
Reads the variables from the file and returns a 2D array containing the data.
- __appendMetaData(self, date, filename)
Adds standard metadata to the data dictionary.
- _removeBadData(self, data, datanames=['Time', 'Bx', 'By', 'Bz', 'Vx', 'Vy', 'Vz', 'n', 'Temp', 'AE', 'AL', 'AU', 'SYMH', 'BowShockX', 'BowShockY', 'BowShockZ'], hasBeenInterpolated=None)
Linearly interpolates over bad data in the data array.
- _coarseFilter(self, dataArray, hasBeenInterpolated)
Uses coarse noise filtering to remove outliers from the data array.
- kaipy.solarWind.WIND.main()
kaipy.solarWind.swBCplots module
Generate plots of 1d time series data stored as kaipy.solarWind.TimeSeries objects. See scritps/preproc/cda2wind.py for example usage.
- kaipy.solarWind.swBCplots.BasicPlot(VarDict, Xname, Yname, Xlabel=True, color='b')
Plot a basic line graph using the given variables.
- Parameters:
VarDict (dict) – A dictionary containing the variables.
Xname (str) – The name of the variable in the dictionary to be plotted on the x-axis.
Yname (str) – The name of the variable in the dictionary to be plotted on the y-axis.
Xlabel (bool, optional) – Whether to display the x-axis label. Defaults to True.
color (str or list, optional) – The color(s) of the line(s) in the plot. Defaults to ‘b’.
- Raises:
Exception – If datetime time-axis elements are mixed with other types.
- Returns:
None
Notes
The function uses plt.plot(…) to create the line graph.
The y variable can be a time series of tuples/lists of variables to plot simultaneously, using different colors.
If Xname points to a list of datetime.datetime objects, the plot will be formatted as datetimes.
If y[‘name’] is not a scalar, the y-axis label will only display the units.
Example
>>> VarDict = {'X': {'name': 'Time', 'data': [1, 2, 3]}, 'Y': {'name': 'Value', 'data': [4, 5, 6], 'units': 'm'}} >>> BasicPlot(VarDict, 'X', 'Y')
- kaipy.solarWind.swBCplots.MultiPlot(VarDict, Xname, Items, color='b')
Plot variables stored in TimeSeries object ‘varDict’.
This function is a simple wrapper around the more generic MultiPlotN function.
- Parameters:
VarDict (TimeSeries) – The TimeSeries object containing the variables to be plotted.
Xname (str) – The name of the x-axis variable.
Items (list) – A list of variable names to be plotted.
color (str, optional) – The color of the plot. Defaults to ‘b’.
- Returns:
None
- kaipy.solarWind.swBCplots.MultiPlot2(VarDict, VarDict2, Xname, Items, color1='b', color2='r')
Plot items (stored in TimeSeries objects VarDict and VarDict2) against one another. One sub plot is created for each item.
- Parameters:
VarDict (TimeSeries) – A TimeSeries object containing the first set of data.
VarDict2 (TimeSeries) – A TimeSeries object containing the second set of data.
Xname (str) – The name of the x-axis variable.
Items (list) – A list of items to plot against each other.
color1 (str, optional) – The color of the plot for VarDict. Default is ‘b’ (blue).
color2 (str, optional) – The color of the plot for VarDict2. Default is ‘r’ (red).
- Returns:
None
- kaipy.solarWind.swBCplots.MultiPlotN(varDicts, Xname, variables, colors=[], legendLabels=[])
Creates one subplot for each variable. Each subplot renders a plot of that variable for each varDict passed.
- For example:
one varDict and 5 variables will give 5 subplots with one line each 5 varDicts and one variable will give 1 subplot with 5 lines
- Parameters:
varDicts (list) – List of TimeSeries data dictionaries.
Xname (str) – Key of horizontal axes label (must be defined in all varDicts).
variables (list) – List of keys to plot for each varDict.
colors (list, optional) – Color of each line to be drawn. Defaults to [].
legendLabels (list, optional) – Display a legend on the plot. Defaults to [].
- Returns:
None
- kaipy.solarWind.swBCplots.SummaryPlot(VarDict, Xname)
Plots every variable in VarDict.
This is a simple wrapper around the more generic MultiPlotN. This code may have problems with varDicts that store non-time series data. You’ve been warned.
- Parameters:
VarDict (dict) – A dictionary containing variables to be plotted. Each variable should be a dictionary with a ‘data’ key.
Xname (str) – The name of the x-axis variable.
- Returns:
None
- kaipy.solarWind.swBCplots.swQuickPlot(UT, D, Temp, Vx, Vy, Vz, Bx, By, Bz, SYMH, interped, fname, xBS=None, yBS=None, zBS=None, t0fmt='%Y-%m-%d %H:%M:%S', utfmt='%H:%M\n%Y-%m%d', title='Solar Wind', doTrim=True, doEps=False, returnAxs=False)
Plot solar wind parameters over a specified time period.
- Parameters:
UT (array-like) – Array of time values.
D (array-like) – Array of solar wind density values.
Temp (array-like) – Array of solar wind temperature values.
Vx (array-like) – Array of solar wind velocity values in the x-direction.
Vy (array-like) – Array of solar wind velocity values in the y-direction.
Vz (array-like) – Array of solar wind velocity values in the z-direction.
Bx (array-like) – Array of solar wind magnetic field values in the x-direction.
By (array-like) – Array of solar wind magnetic field values in the y-direction.
Bz (array-like) – Array of solar wind magnetic field values in the z-direction.
SYMH (array-like) – Array of SYM/H values.
interped (array-like) – Array indicating whether the data is interpolated or not.
fname (str) – File name to save the plot.
xBS (array-like, optional) – Array of Bow Shock position values in the x-direction.
yBS (array-like, optional) – Array of Bow Shock position values in the y-direction.
zBS (array-like, optional) – Array of Bow Shock position values in the z-direction.
t0fmt (str, optional) – Format string for the time values in UT.
utfmt (str, optional) – Format string for the x-axis labels.
title (str, optional) – Title of the plot.
doTrim (bool, optional) – Whether to trim the plot or not.
doEps (bool, optional) – Whether to save the plot in EPS format or not.
returnAxs (bool, optional) – Whether to return the axes objects or not.
- Returns:
Dictionary containing the axes objects if returnAxs is True.
- Return type:
axDict (dict)