resistics.statistics.data module¶
-
class
resistics.statistics.data.
StatisticData
(statName: str, refTime: datetime.datetime, sampleFreq: float, winSize: int, winOlap: int, **kwargs)[source]¶ Bases:
resistics.common.base.ResisticsBase
Class for holding information about a statistic
- Attributes
- statNamestr
The name of the statistic
- refTimedatetime.datetime
The reference time of the project
- sampleFreqfloat
The sampling frequency of the data
- winSizeint
Window size in samples
- winOlapint
Window overlap in samples
- numWindowsint
Number of windows
- winStatsList[str]
Values calculated for the statistic
- numStatsPerWindowint
The number of statistics per window (length of winStats)
- statsnp.ndarray
The statistic data of size number of windows * number evaluation frequencies * number of window stats
- evalFreqList, np.ndarray
The evaluation frequencies for the statistic data
- freq2indexDict
Mapping from evaluation frequency to index
- globalIndicesList, np.ndarray
Array of global indices. Allows local -> global conversion
- global2localMapDict
Dictionary which maps global indices to local. Allows global -> local conversion
- commentsList[str]
Statistic comments
- dtypestr (default “float”)
The data type of the statistic values
- maxcolsint (default 4)
The number of columns in plots
- globalDatesStartList, np.ndarray
Global window start datetimes
- globalDatesStopList, np.ndarray
Global window stop datetimes
Methods
__init__(sampleFreq, numLevels, evalFreq, kwargs)
Initialise maskData
getStats(includewindows, maskwindows)
Get the statistics array and choose to either include some windows or mask some windows
getUnmaskedIndices(maskwindows)
Return the local indices to use given a set of global indices to exclude
getStatLocal(localIndex)
Get statistic values for a local window index
getStatGlobal(globalIndex)
Get statistic values for a global window index
getGlobalIndex(localIndex)
Get the global window index for a local window index
getLocalIndicesF(globalIndices)
Get local indices for an list or array of global indices
getGlobalDates()
Get the global index dates for all the windows
setStatParams(numWindows, winStats, evalFreq)
Set the statistic parameters and prepare the data arrays
addStat(localIndex, globalIndex, stat)
Add a statistic, providing the local index, the corresponding global index and the statististic values
getComments()
Get a deepcopy of the comments
addComment(comment)
Add a comment to the comments
view(eFreqI, **kwargs)
View statistic values for a evaluation frequency (time on x axis, statistic values on y axis)
histogram(eFreqI, **kwargs)
View a histogram of the statistic values for each statistic component for a single evaluation frequency
crossplot(eFreqI, **kwargs)
View a crossplot of the data
addColourbar(plot, cax, title, plotfonts)
Add a colourbar to a plot
addColourbarDates(plot, cax, title, plotfonts)
Add a coloubar the represents dates to the plot
dateTicks(gIndices, dates, timeNum)
Deal with the dateTicks of the plot
calcColourData(plotData, val, eFreqI, keywords)
Calculate colours
getRowsCols(maxcols, numStats)
Get the number of rows and columns for a plot
printList()
Class status returned as list of strings
-
addColourbar
(self, plot: matplotlib.collections.PathCollection, cax, title: str, plotfonts: Dict) → None[source]¶ Add a colourbar to a plot
- Parameters
- plotmatplotlib.collections.PathCollection
A plot e.g. a scatter graph
- cax :
Colourbar axis
- titlestr
The tital for the colourbar
- plotfontsDict
A dictionary with font types as keys and sizes as values
-
addColourbarDates
(self, plot: matplotlib.collections.PathCollection, cax, title: str, plotfonts: Dict)[source]¶ Make the colourbar show dates for identifying window times where there is not date axis
- Parameters
- plotmatplotlib.collections.PathCollection
A plot e.g. a scatter graph
- cax :
Colourbar axis
- titlestr
The tital for the colourbar
- plotfontsDict
A dictionary with font types as keys and sizes as values
-
addComment
(self, comment: str) → None[source]¶ Add a new comment
- Parameters
- commentfloat
A new comment
-
addStat
(self, localIndex: int, globalIndex: int, stat) → None[source]¶ Add statistic values for a window for all evaluation frequencies
- Parameters
- localIndexint
Local index of the window
- globalIndexint
Global index of the window
- statDict
An dictionary of dictionaries. First set of key, values are evaluationFrequencies and dictionaries, second set of key, values are statistic names in winStats and their corresponding value for the window
-
calcColourData
(self, plotData, val, eFreqI, keywords)[source]¶ Calculate the colour data
Todo
Write more complete documentation
-
crossplot
(self, eFreqI: int, **kwargs) → matplotlib.figure.Figure[source]¶ Plots crossplots of statistic components for evaluation frequency index
- Parameters
- eFreqIint
Evaluation frequency index
- maskwindowsList, np.ndarray
Global windows to exclude
- crossplotsList[List[str]], optional
The parameters to crossplot
- figmatplotlib.pyplot.figure, optional
A figure object
- plotfontsDict, optional
A dictionary of plot fonts
- labelstr, optional
Label for the plots
- climList, optional
Limits for colourbar axis
- xlimList, optional
Limits for the x axis
- ylimList, optional
Limits for the y axis
- colortitlestr, optional
Title for the colourbar
- legenedbool
Boolean flag for adding a legend
- Returns
- plt.figure
Matplotlib figure object
Notes
By default, the crossplots plotted are statistic component 1 vs statistic component 2 statistic component 3 vs statistic component 4 etc
But crossplots can be explicity set by using the crossplots keyword. They should be specified as a list of a list of strings e.g. crossplots = [[component2, component3], [component1, component4]]
-
dateTicks
(self, gIndices, dates, timeNum)[source]¶ Format dateticks
Todo
Write more complete documentation
-
densityplot
(self, eFreqI: int, **kwargs) → matplotlib.figure.Figure[source]¶ Plots density plots of statistic components for evaluation frequency index
- Parameters
- eFreqIint
Evaluation frequency index
- maskwindowsList, np.ndarray
Global windows to exclude
- crossplotsList[List[str]], optional
The parameters to crossplot
- figmatplotlib.pyplot.figure, optional
A figure object
- plotfontsDict, optional
A dictionary of plot fonts
- labelstr, optional
Label for the plots
- xlimList, optional
Limits for the x axis
- ylimList, optional
Limits for the y axis
- colortitlestr, optional
Title for the colourbar
- legenedbool
Boolean flag for adding a legend
- Returns
- plt.figure
Matplotlib figure object
Notes
By default, the density plots plotted are statistic component 1 vs statistic component 2 statistic component 3 vs statistic component 4 etc
But density plots can be explicity set by using the crossplots keyword. They should be specified as a list of a list of strings e.g. crossplots = [[component2, component3], [component1, component4]]
-
getComments
(self) → List[str][source]¶ Get a deepcopy of the comments
- Returns
- List[str]
Dataset comments as a list of strings
-
getGlobalDates
(self)[source]¶ Get the global start dates and end dates for each window
- Returns
- np.ndarray
The global window start times
-
getGlobalIndex
(self, localIndex)[source]¶ Get global index for local index
- Parameters
- localIndexint
Local index of the window
- Returns
- globalIndexint
Global index for local index
-
getLocalIndices
(self, globalIndices: Tuple[List[int], numpy.ndarray]) → List[int][source]¶ Converts a list or array of global indices to local indices
- Parameters
- globalIndicesList, np.ndarray
Global indices to convert into local indices
- Returns
- List
List of local indices
-
getRowsCols
(self, maxcols: int, numStats: int = 0) → Tuple[int, int][source]¶ Get the numbers of rows and columns for the plots
- Parameters
- maxcolsint
The maximum number of columns
- numStatsint
The number of statistics to plot (in case this is not all of the winStats)
-
getStatGlobal
(self, globalIndex: int) → numpy.ndarray[source]¶ Get statistics for a local window index
- Parameters
- globalIndexint
Global index of the window
- Returns
- outnp.ndarray
Statistics for the local window
-
getStatLocal
(self, localIndex: int) → numpy.ndarray[source]¶ Get statistics for a local window index
- Parameters
- localIndexint
Local index of the window
- Returns
- outnp.ndarray
Statistics for the local window
-
getStats
(self, includewindows: Union[numpy.ndarray, List, NoneType] = None, maskwindows: Union[numpy.ndarray, List, NoneType] = None) → numpy.ndarray[source]¶ Get statistics when either selecting a set of indices or wanting to mask a set of indices
- Parameters
- includewindowsList, np.ndarray, optional
Windows to get. This should be a list of numpy array of global indices.
- maskwindowsList, np.ndarray, optional
Windows to exclude. This is expected to be a list, set or numpy array of global indices.
- Returns
- np.ndarray
Statistics limited by the window selection options
-
getUnmaskedIndices
(self, maskWindows: Union[List, numpy.ndarray]) → Union[List, NoneType][source]¶ Given a list of global windows to mask, returns the set of indices to include in the plot
- Parameters
- maskWindowsList, np.ndarray
Global indices of windows to mask
- Returns
- List, None
List of indices to include. None if all windows should be included
-
histogram
(self, eFreqI: int, **kwargs) → matplotlib.figure.Figure[source]¶ Plot statistics for evaluation frequency index
Plots a histogram of each statistic with bins on the xaxis and count on the yaxis. Ideal for exploring the distribution of statistic values over the windows.
- Parameters
- eFreqIint
Evaluation frequency index
- maskwindowsList, np.ndarray
Global windows to exclude
- numbinsint
The number of bins for the histogram data binning
- figmatplotlib.pyplot.figure, optional
A figure object
- plotfontsDict, optional
A dictionary of plot fonts
- labelstr, optional
Label for the plots
- xlimList, optional
Limits for the x axis
- legenedbool
Boolean flag for adding a legend
- Returns
- plt.figure
Matplotlib figure object
-
printList
(self) → List[str][source]¶ Class information as a list of strings
- Returns
- outList[str]
List of strings with information
-
setStatParams
(self, numWindows: int, winStats: List[str], evalFreq, dtype: Any = None)[source]¶ Set the statistic parameters
- Parameters
- numWindowsint
Number of windows for which the statistic has been or will be calculated
- winStatsint
The parameters in the statistic
- evalFreqList
A list of evaluation frequencies
- dtypestr, optional
The datatype of the statistic values
-
view
(self, eFreqI: int, **kwargs) → matplotlib.figure.Figure[source]¶ Plot statistics for evaluation frequency index
Plots a simple scatter of each statistic with datetime on the xaxis (datetime of the window start dates). Number of subplots is equal to numStaStatPerWindow.
- Parameters
- eFreqIint
Evaluation frequency index
- maskwindowsList, np.ndarray
Global windows to exclude
- figmatplotlib.pyplot.figure, optional
A figure object
- plotfontsDict, optional
A dictionary of plot fonts
- labelstr, optional
Label for the plots
- climList, optional
Limits for colourbar axis
- xlimList, optional
Limits for the x axis
- ylimList, optional
Limits for the y axis
- colortitlestr, optional
Title for the colourbar
- legenedbool
Boolean flag for adding a legend
- Returns
- plt.figure
Matplotlib figure object