resistics.time.writer module¶
-
class
resistics.time.writer.
TimeWriter
[source]¶ Bases:
resistics.common.base.ResisticsBase
Base class for data writers
All input readers provide headers in a common format
- Attributes
- outPathstr
The path to write to
- extension: str
The extension to give to the data files
- dtypedata type
Data format to write out, default is np.int32
- headers :
Header information to write out
- chansList[str]
Channels to write out
- chanMapDict
Map between channel and index in channel headers
- chanHeadersList
Channel specific headers
Methods
__init__()
Initialise writer
getOutPath()
Get the path to write out to
setOutPath(path)
Set the path to write out to
setExtension()
For subclasses to set their extension
setGlobalHeadersFromKeywords(headers, keywords)
Set the global headers
setChanHeadersFromKeywords(chanHeaders, keywords)
Set channel headers
calcStopDateTime(sampleFreq, numSamples, datetimeStart)
Calculate time series stop time
globalHeaderwords()
Get a list of the global headers of interest
chanHeaderwords()
Get a list of the channel headers of interest
writeTemplateHeaderFiles(chans, chanFileMap, sampleFreq, numSamples, startDate)
Write out a set of template header files for a case in which ASCII data without headers is to be loaded in
writeDataset(reader, **kwargs)
Write an existing dataset as a different format
writeData(headers, chanHeaders, timeData, **kwargs)
Write data based on headers, channel headers and time series data
write(headers, chanHeaders, chanMap, timeData, **kwargs)
Write out a dataset
writeHeaders(headers, chans, chanMap, chanHeaders)
Write out headers
writeComments(comments)
Write out comments
writeDataFiles(chans, timeData)
Write out time series data - not implemented in base class
printList()
Class status returned as list of strings
-
calcStopDateTime
(self, sampleFreq: float, numSamples: int, datetimeStart: datetime.datetime) → datetime.datetime[source]¶ Calculate time of last sample
- Parameters
- sampleFreqfloat
Sampling frequency in Hz of the time series data
- numSamplesint
The number of samples in the time series data
- datetimeStartdatetime
The time of the first sample
-
chanHeaderwords
(self) → List[str][source]¶ Get a list of channel headerwords to write out
- Returns
- List[str]
A list of the global header words of interest for writing out
-
getOutPath
(self) → str[source]¶ Get the out path
- Parameters
- str
The outpath defining where data is written
-
globalHeaderwords
(self) → List[str][source]¶ Get a list of global headerwords to write out
- Returns
- List[str]
A list of the global header words of interest for writing out
-
printList
(self) → List[str][source]¶ Class information as a list of strings
- Returns
- outList[str]
List of strings with information
-
setChanHeadersFromKeywords
(self, chanHeaders: List, keywords: Dict) → List[source]¶ Set the channel headers
Before writing out data, channel headers are set. The priority order is:
keywords[headername] if headername exists in keywords
headers[headername] if headername exists in headers
“” where the channel header is not defined in either keywords or headers
The reason keywords takes top priority is there may be instances where the headers defined in a reader may need to be altered due to processing of time data.
- Parameters
- chanHeadersList
List of channel headers
- keywordsDict
A dictionary of header values to overwrite those in channel headers
-
setGlobalHeadersFromKeywords
(self, headers: Dict, keywords: Dict) → Dict[source]¶ Set the global headers
Before writing out data, global headers are set. The priority order is:
keywords[headername] if headername exists in keywords
headers[headername] if headername exists in headers
“” where the header is not defined in either keywords or headers
The reason keywords takes top priority is there may be instances where the headers defined in a reader may need to be altered due to processing of time data.
- Parameters
- headersDict
Dictionary of header values
- keywordsDict
A dictionary of header values to overwrite those in headers
-
setOutPath
(self, path: str) → None[source]¶ Set the out path
- Parameters
- pathstr
The new outpath defining where data is written
-
write
(self, headers: Dict, chanHeaders: List, chanMap: Dict, timeData: resistics.time.data.TimeData, **kwargs)[source]¶ Write out the header file
- Parameters
- headersDict
Dictionary of headers
- chanHeadersList
List of channel headers
- chanMapDict
Maps channel to index for chanHeaders
- timeDataTimeData
Time series data as TimeData object
-
writeComments
(self, comments: List[str]) → None[source]¶ Write out a comments file
- Parameters
- commentsList[str]
List of strings with data comments
-
writeData
(self, headers, chanHeaders, timeData, physical: bool = True, **kwargs)[source]¶ Write out time data
This method requires the user to pass global headers and chan headers explicitly.
- Parameters
- headersDict
Dictionary of headers
- chanHeadersList
List of channel headers
- timeDataTimeData
Time series data to write out
- physicalbool, optional
An optional flag designating whether the data is in field units (i.e. all scalings have been applied). This will result in the scaling_applied header being set to True. Default value for physical is True (i.e. data is assumed to be in field units).
-
writeDataset
(self, reader: resistics.time.reader.TimeReader, physical: bool = True, **kwargs) → None[source]¶ Write out a dataset by passing a data reader
This method is intended to transform an existing dataset into internal format
- Parameters
- readerDataReader
A list of the global header words of interest for writing out
- physicalbool, optional
An optional flag designating whether to use physical samples or not. Default is true
-
writeHeaders
(self, headers: Dict[str, Any], chans: List[str], chanMap: Dict[str, int], chanHeaders: List[Dict], rename: bool = True, ext: str = 'hdr') → bool[source]¶ Write out the header file
- Parameters
- headersDict
Dictionary of headers
- chansList[str]
Channels as a list of strings
- chanMapDict
Maps channel to index for chanHeaders
- chanHeadersList
List of channel headers
- renamebool, optional
Rename the output ats_data_files. Default is True and this is the case when writing out data which has been read in from a different source with pre-existing headers. However, if creating template header files, then set this to False.
- extstr, optional
The extension for the headers. Default is hdr
-
writeTemplateHeaderFiles
(self, chans: List[str], chanFileMap: Dict, sampleFreq: float, numSamples: int, startDate: str)[source]¶ Write a set of blank headers
Blank headers might be useful for reading in ascii files where no headers are existing. By giving a few header words, many options can be set
- Parameters
- chansList[str]
List of chans (e.g. Ex, Ey, Hx, Hy, Hz)
- chanFileMapDict[str, str]
Map from channel to file
- numsamplesint
Number of samples of data
- startdatestr
The start date of the recording in format %Y-%m-%d %H:%M:%S