resistics.window.selector module¶
-
class
resistics.window.selector.
WindowSelector
(projData: resistics.project.data.ProjectData, sampleFreq: float, decParams: resistics.decimate.parameters.DecimationParameters, winParams: resistics.window.parameters.WindowParameters, **kwargs)[source]¶ Bases:
resistics.common.base.ResisticsBase
Select windows for further processing
Finds windows for further processing. Given more than one site, WindowSelector will find the shared windows. For example, when processing with a remote reference, WindowSelector will find the shared global windows (i.e. referenced to the project reference time) of the local site and the remote site.
Shared windows will accept maskData when constraints are to be used. Further, datetime constraints can be added to the selection process, in the case where, for example, only night time data is to be processed.
For datetime constraints, the order of priorities are: 1. datetime constraints 2. date constraints 3. time constraints
- Attributes
- projDataProjectData
A ProjectData instance
- sampleFreqfloat
Sampling frequency of the data
- decParamsDecimationParameters
A DecimationParameters instance detailing the decimation schemes
- winParamsWindowParameters
A WindowParameters instance detailing the windowing information
- sitesList[str]
List of sites for which to calculate shared windows
- sharedWindowsDict
Dictionary to store shared window information between sites. The keys of the dictionary are the decimation levels.
- siteMasksDict
Masks to use for each site
- siteSpecFoldersDict
Spectra folders for each site at sampleFreq
- siteSpecReadersDict
SpectraReaders for each site at sampleFreq
- siteSpecRangesDict
Global window ranges for all the spectra files for the sites at sampleFreq
- siteGlobalIndicesDict
Global window sets for all the spectra files for the sites at sampleFreq
- specdirstr
The spectra data to use for calculating shared windows and the subsequent processing
- prependstr
The string prepending the spectra data files. This is usually “spectra” and not expected to change
- datetimesDict
User supplied datetime constraints. These are the highest priority in the time constraints. This is a list of constraints for each decimation level.
- datesDict
User supplied date constraints. These are the second highest priority in the time constraints. This is a list of constraints for each decimation level.
- timesDict
User supplied time constraints. These are the last priority in the time constraints. This is a list of constraints for each decimation level.
- datetimeConstraintsDict
Final combined date and time constraints. This is a list of constraints for each decimation level
Methods
__init__(decParams)
Initialise window selector with information about the decimation parameters
getSharedWindowsLevel(declevel)
Get the shared windows for a decimation level as a python set
getNumSharedWindows(declevel)
Get the number of shared windows for a decimation level
getWindowsForFreq(declevel, eIdx)
Get the number of shared windows for a decimation level and evaluation frequency
getUnmaskedWindowsLevel(declevel)
Get unmasked windows for a decimation level
getDatetimeConstraints()
Get the datetime constraints
getLevelDatetimeConstraints(declevel)
Get the datetime constraints for a decimation level
getMasks()
Get a dictionary with masks to use for each site in the window selector
getSpecReaderForWindow(site, declevel, iWin)
Get the spectrum reader for a window
getDataSize(declevel)
Get the spectrum reader for a window
setSites(sites)
Set the sites for which to find the shared windows
addDatetimeConstraint(start, stop)
Add a datetime constraint
addDateConstraint(dateC)
Add a date constraint
addTimeConstraint(start, stop)
Add a time constraint. This will recur on every day of recording
addWindowMask(site, maskName)
Add a window mask
resetDatetimeConstraints()
Clear and reset all datetime constraints
resetMasks()
Clear and reset site masks
calcSharedWindows()
Calculate shared windows between sites
calcGlobalIndices()
Find all the global indices for the sites
calcDatetimeConstraints()
Calculate overall datetime constraints
calcSiteDates()
Calculate a list of days that all the sites were operating
printList()
Class information as a list of strings
printSiteInfo()
Print out information about the sites included in the window selection
printSiteInfoList(site)
Return site window information as a list of strings
printSharedWindows()
Print out the shared windows
printSharedWindowsList()
Shared window information as a list of strings
printDatetimeConstraints()
Print out the datetime constraints
printDatetimeConstraintsList()
Datetime constraint information as a list of strings
printWindowMasks()
Print information about masks being used in the window selection
printWindowMasksList()
Window mask information as a list of strings
printWindowsForFrequency(listwindows=False):
Print information about the windows for each evaluation frequency
printWindowsForFrequencyList(listwindows=False)
Information about windows for each evaluation frequency as a list of strings
-
addDateConstraint
(self, dateC: str, declevel: Union[List[int], int, NoneType] = None)[source]¶ Add a date constraint
- Parameters
- dateCstr
Datetime constraint in format %Y-%m-%d
- declevelList[int], int, optional
The decimation level. If left as default, will be applied to all decimation levels.
-
addDatetimeConstraint
(self, start: str, stop: str, declevel: Union[List[int], int, NoneType] = None)[source]¶ Add datetime constraints
- Parameters
- startstr
Datetime constraint start in format %Y-%m-%d %H:%M:%S
- stopstr
Datetime constraint end in format %Y-%m-%d %H:%M:%S
- declevelList[int], int, optional
The decimation level. If left as default, will be applied to all decimation levels.
-
addTimeConstraint
(self, start: str, stop: str, declevel: Union[List[int], int, NoneType] = None)[source]¶ Add a time constraint. This will recur on every day of recording.
- Parameters
- startstr
Time constraint start in format %H:%M:%S
- stopstr
Time constraint end in format %H:%M:%S
- declevelList[int], int, optional
The decimation level. If left as default, will be applied to all decimation levels.
-
addWindowMask
(self, site: str, maskName: str) → None[source]¶ Add a window mask
This is a mask with values for each evaluation frequency.
- Parameters
- sitestr
The site for which to search for a mask
- maskNamestr
The name of the mask
-
calcDatetimeConstraints
(self) → None[source]¶ Calculate overall datetime constraints
Priority order for datetime constraints is: 1. datetime constraints 2. date constraints 3. time constraints
Calculate shared windows between sites
Calculates the shared windows between sites. Datetime constraints are applied. No masks are applied in this method. Masks are only applied when getting the windows for a particular evaluation frequency.
-
calcSiteDates
(self) → List[datetime.datetime][source]¶ Calculate a list of days that all the sites were operating
This uses the siteStart and siteEnd datetimes, so does not take into account the start and end of actual time series measurements, which is taken into account later.
- Returns
- List[datetime]
A list of dates all the sites were operating
-
getDataSize
(self, declevel: int) → int[source]¶ Get the spectrum reader for a window
- Parameters
- declevelstr
The decimation level
- Returns
- int
The data size (number of points in the spectrum) at the decimation level
-
getDatetimeConstraints
(self) → Dict[source]¶ Get the datetime constraints
- Returns
- Dict
Dictionary of datetime constraints at all decimation levels
-
getLevelDatetimeConstraints
(self, declevel: int) → List[List[datetime.datetime]][source]¶ Get the datetime constraints for a decimation level
- Returns
- List[List[datetime]]
Returns a list of datetime constraints, where each is a 2 element list with a start and stop
-
getMasks
(self) → Dict[source]¶ Get a dictionary with masks to use for each site in the window selector
- Returns
- Dict
Dictionary with masks to use for each site in the window selector
Get the number of shared windows for a decimation level
- Parameters
- declevelint
The decimation level (0 is the first level)
- Returns
- int
The number of shared windows for the decimation level
Get the shared windows for a decimation level
- Parameters
- declevelint
The decimation level (0 is the first level)
- Returns
- set
The shared windows for the decimation level
-
getSpecReaderBatches
(self, declevel: int) → Tuple[List, List][source]¶ Batch the readers into wndow groups that can be read as required in a more efficient way
First sorts all the site spectra files by global window range, putting them in ascending order. Loops over all the sites and constructs spectra batches to read in.
- Parameters
- declevelint
The decimation level
- Returns
- batchesList[Dict[str, All]]
The list of batches
-
getSpecReaderForWindow
(self, site: str, declevel: int, iWin: int)[source]¶ Get the spectrum reader for a window
- Parameters
- sitestr
The name of the site to get the spectrum reader for
- declevelint
The decimation level
- iWinint
The window index
- Returns
- specFilestr, bool
The name of the spectra file or False if the window is not found in any spectra file
- specReaderSpectrumReader, bool
The spectrum reader or False if the window is not found in any spectra file
-
getUnmaskedWindowsLevel
(self, declevel: int) → Set[source]¶ Get unmasked windows for a decimation level
Calculate the number of non masked windows for the decimation level. This should speed up processing when constraints are applied.
- Parameters
- declevelint
The decimation level
- Returns
- set
Unmasked windows for the decimation level
-
getWindowsForFreq
(self, declevel: int, eIdx: int) → Set[source]¶ Get the number of shared windows for a decimation level and evaluation frequency
- Parameters
- declevelint
The decimation level (0 is the first level)
- eIdxint
The evaluation frequency index
- Returns
- set
The shared windows for evaluation frequency eIdx at decimation level declevel
-
printDatetimeConstraintsList
(self) → List[str][source]¶ Datetime constraint information as a list of strings
- Returns
- List[str]
Datetime constraint information as a list of strings
-
printList
(self) → List[str][source]¶ Class information as a list of strings
- Returns
- outlist
List of strings with information
Print out the shared windows
Shared window information as a list of strings
- Returns
- List[str]
Shared window information as a list of strings
-
printSiteInfoList
(self, site: str) → List[str][source]¶ Return site window information as a list of strings
- Parameters
- sitestr
The site name
- Returns
- List[str]
Site window information as a list of strings
-
printWindowMasksList
(self) → List[str][source]¶ Window mask information as a list of strings
- Returns
- List[str]
Window mask information as a list of strings
-
printWindowsForFrequency
(self, listwindows=False)[source]¶ Print information about the windows for each evaluation frequency
- Parameters
- listwindowsbool
Boolean flag to actually write out all the windows. Default is False as this takes up a lot of space in the terminal
-
printWindowsForFrequencyList
(self, listwindows=False) → List[str][source]¶ Information about windows for each evaluation frequency as a list of strings
- Parameters
- listwindowsbool
Boolean flag to actually write out all the windows. Default is False as this takes up a lot of space in the terminal
- Returns
- List[str]
Windows for evaluation frequency information as a list of strings