resistics.testing module#
Module for producing testing data for resistics and helper functions to compare instances of the same object.
This includes testing data for:
Record
History
TimeMetadata
TimeData
DecimatedData
SpectraData
Evaluation frequency SpectraData
RegressionInputMetadata
Solution
- resistics.testing.time_metadata_1chan(fs: float = 10, first_time: str = '2021-01-01 00:00:00', n_samples: int = 11) TimeMetadata [source]#
Get TimeMetadata for a single channel, “chan1”
- Parameters:
- Returns:
TimeMetadata
- Return type:
- resistics.testing.time_metadata_2chan(fs: float = 10, first_time: str = '2021-01-01 00:00:00', n_samples: int = 11) TimeMetadata [source]#
Get a TimeMetadata instance with two channels, “chan1” and “chan2”
- Parameters:
- Returns:
TimeMetadata
- Return type:
- resistics.testing.time_metadata_general(chans: List[str], fs: float = 10, first_time: str = '2020-01-01 00:00:00', n_samples: int = 11) TimeMetadata [source]#
Get general time metadata
- Parameters:
- Returns:
An instance of TimeMetadata with the approripate properties
- Return type:
- resistics.testing.time_metadata_mt(fs: float = 10, first_time: str = '2020-01-01 00:00:00', n_samples: int = 11) TimeMetadata [source]#
Get a magnetotelluric time metadata with four channels “Ex”, “Ey”, “Hx”, “Hy”
- Parameters:
- Returns:
TimeMetadata
- Return type:
- resistics.testing.time_data_ones(fs: float = 10, first_time: str = '2020-01-01 00:00:00', n_samples: int = 10, dtype: Type | None = None) TimeData [source]#
TimeData with all ones
- Parameters:
- Returns:
The TimeData
- Return type:
- resistics.testing.time_data_simple(fs: float = 10, first_time: str = '2020-01-01 00:00:00', dtype: Type | None = None) TimeData [source]#
Time data with 16 samples
- resistics.testing.time_data_with_nans(fs: float = 10, first_time: str = '2020-01-01 00:00:00', dtype: Type | None = None) TimeData [source]#
TimeData with 16 samples and some nan values
- resistics.testing.time_data_linear(fs: float = 10, first_time: str = '2020-01-01 00:00:00', n_samples: int = 10, dtype: Type | None = None) TimeData [source]#
Get TimeData with linear data
- Parameters:
- Returns:
TimeData with linear values
- Return type:
- resistics.testing.time_data_random(fs: float = 10, first_time: str = '2020-01-01 00:00:00', n_samples: int = 10, dtype: Type | None = None) TimeData [source]#
TimeData with random values and specifiable number of samples
- Parameters:
- Returns:
The TimeData
- Return type:
- resistics.testing.time_data_periodic(frequencies: List[float], fs: float = 50, first_time: str = '2020-01-01 00:00:00', n_samples: int = 100, dtype: Type | None = None) TimeData [source]#
Get period TimeData
- Parameters:
frequencies (List[float]) – Frequencies to include
fs (float, optional) – Sampling frequency, by default 50
first_time (str, optional) – The first time, by default “2020-01-01 00:00:00”
n_samples (int, optional) – The number of samples, by default 100
dtype (Optional[Type], optional) – The data type for the values, by default None
- Returns:
Periodic TimeData
- Return type:
- resistics.testing.time_data_with_offset(offset=0.05, fs: float = 10, first_time: str = '2020-01-01 00:00:00', n_samples: int = 11, dtype: Type | None = None) TimeData [source]#
Get TimeData with an offset on the sampling
- Parameters:
offset (float, optional) – The offset on the sampling in seconds, by default 0.05
fs (float, optional) – The sampling frequency, by default 10
first_time (str, optional) – The first time of the TimeData, by default “2020-01-01 00:00:00”
n_samples (int, optional) – The number of samples, by default 11
dtype (Optional[Type], optional) – The data type for the values, by default None
- Returns:
The TimeData
- Return type:
- resistics.testing.decimated_metadata(fs: float = 0.25, first_time: str = '2021-01-01 00:00:00', n_samples: int = 1024, n_levels: int = 3, factor: int = 4) DecimatedMetadata [source]#
Get example decimated metadata
The final level has n_samples. The number of samples for all other levels is calculated using a decimation factor of 4.
Similarly for the sampling frequencies, the final level is assumed to have a sample frequency of fs and all other levels sampling frequencies are calculated from there.
- Parameters:
fs (float, optional) – The sampling frequency of the last level, by default 0.25
first_time (str, optional) – The time of the first sample, by default “2021-01-01 00:00:00”
n_samples (int, optional) – The number of samples, by default 1024
n_levels (int, optional) – The number of decimation levels, by default 3
factor (int, optional) – The decimation factor for each level, by default 4
- Returns:
DecimatedMetadata
- Return type:
- resistics.testing.decimated_data_random(fs: float = 0.25, first_time: str = '2021-01-01 00:00:00', n_samples: int = 1024, n_levels: int = 3, factor: int = 4) DecimatedData [source]#
Get random decimated data
- Parameters:
fs (float, optional) – Sampling frequency, by default 10
first_time (str, optional) – The time of the first sample, by default “2021-01-01 00:00:00”
n_samples (int, optional) – The number of samples, by default 1024
n_levels (int, optional) – The number of levels, by default 3
factor (int, optional) – The decimation factor for each level, by default 4
- Returns:
The decimated data
- Return type:
- resistics.testing.decimated_data_linear(fs: float = 0.25, first_time: str = '2021-01-01 00:00:00', n_samples: int = 1024, n_levels: int = 3, factor: int = 4)[source]#
Get linear decimated data
- Parameters:
fs (float, optional) – Sampling frequency, by default 10
first_time (str, optional) – The time of the first sample, by default “2021-01-01 00:00:00”
n_samples (int, optional) – The number of samples, by default 1024
n_levels (int, optional) – The number of levels, by default 3
factor (int, optional) – The decimation factor for each level, by default 4
- Returns:
The decimated data
- Return type:
- resistics.testing.decimated_data_periodic(frequencies: Dict[str, List[float]], fs: float = 0.25, first_time: str = '2021-01-01 00:00:00', n_samples: int = 1024, n_levels: int = 3, factor: int = 4)[source]#
Get periodic decimated data
- Parameters:
frequencies (Dict[str, List[float]]) – Mapping from channel to list of frequencies to add
fs (float, optional) – Sampling frequency, by default 10
first_time (str, optional) – The time of the first sample, by default “2021-01-01 00:00:00”
n_samples (int, optional) – The number of samples, by default 1024
n_levels (int, optional) – The number of levels, by default 3
factor (int, optional) – The decimation factor for each level, by default 4
- Returns:
The decimated data
- Return type:
- resistics.testing.spectra_metadata_multilevel(fs: float = 128, n_levels: int = 3, n_wins: List[int] | int = 2, index_offset: List[int] | int = 0, chans: List[str] | None = None) SpectraMetadata [source]#
Get spectra metadata with multiple levels and two channels
- Parameters:
fs (float, optional) – The original sampling frequency, by default 128
n_levels (int, optional) – The number of levels, by default 3
n_wins (Union[List[int], int]) – The number of windows for each level
index_offset (Union[List[int], int], optional) – The index offset vs. the reference time, by default 0
chans (Optional[List[str]]) – The channels in the data, by default None. If None, the channels will be chan1 and chan2
- Returns:
SpectraMetadata with n_levels
- Return type:
- Raises:
ValueError – If the number of user input channels does not equal two
- resistics.testing.spectra_data_basic() SpectraData [source]#
Spectra data with a single decimation level
- Returns:
Spectra data with a single level, a single channel and two windows
- Return type:
- resistics.testing.generate_evaluation_data(chans: List[str], soln: Solution, n_wins: int) ndarray [source]#
Generate evaluation frequency data that satisfies a provided solution
The returned array has the shape: n_wins x n_chans x n_evals Which is close to the shape required for spectra data
There is an extra check provided to check if a channel appears in both the input and output channels, which could be a tricky scenario.
The data is produced randomly using np.random.randn, meaning that it is sampled from a standard normal distribution
- resistics.testing.evaluation_data(fs: float, dec_params: DecimationParameters, n_wins: int, soln: Solution) SpectraData [source]#
Generate evaluation frequency data that will satisfy a given solution. This will generate random data between the low and high values
- Parameters:
fs (float) – The sampling frequency of the original data
dec_params (DecimationParameters) – The data decimation information
n_wins (int) – The number of windows to generate
soln (Solution) – The solution that the generated data should satisfy
- Returns:
The evaluation frequency data
- Return type:
- Raises:
ValueError – If the number of evaluation frequencies is not exactly divisible by the number of levels
- resistics.testing.transfer_function_random(n_in: int, n_out: int) TransferFunction [source]#
Generate a random transfer function
n_in and n_out must be less than or equal to 26 as the random samples are taken from the alphabet
- Parameters:
- Returns:
A randomly generated transfer function
- Return type:
- Raises:
ValueError – If any of the channel names is duplicated
- resistics.testing.regression_input_metadata_single_site(fs: float, freqs: List[float], tf: TransferFunction) RegressionInputMetadata [source]#
Given a transfer function, get example regression input metadata assuming a single site
- Parameters:
fs (float) – The sampling frequency
freqs (List[float]) – The evaluation frequencies
tf (TransferFunction) – The transfer function for which to create RegressionInputMetadata
- Returns:
Example regression input metadata with fs=128 and 5 evaluation frequencies
- Return type:
- resistics.testing.components_mt() Dict[str, Component] [source]#
Get example components for the Impedance Tensor
- resistics.testing.solution_mt() Solution [source]#
Get an example impedance tensor solution
- Returns:
The solution for an MT dataset
- Return type:
- resistics.testing.solution_general(fs: float, tf: TransferFunction, n_evals: int, components: Dict[str, Component]) Solution [source]#
Create a Solution instance from the specified components
- Parameters:
fs (float) – The sampling frequency of the original data
tf (TransferFunction) – The transfer function to be solved
n_evals (int) – The number of evaluation frequencies
components (Dict[str, Component]) – The components of the solution
- Returns:
The Solution instance
- Return type:
- resistics.testing.solution_random_int(fs: float, tf: TransferFunction, n_evals=10, low: int = -10, high: int = 10) Solution [source]#
Generate a set of random integer components for a solution
- Parameters:
fs (float) – The original sampling frequency of the data
tf (TransferFunction) – The transfer function
n_evals (int, optional) – The number of evaluation frequencies, by default 10
low (int, optional) – A low value for the integers, by default -10
high (int, optional) – A high value for the integers, by default 10
- Returns:
A randomly generated solution for the transfer function
- Return type:
- resistics.testing.solution_random_float(fs: float, tf: TransferFunction, n_evals=10) Solution [source]#
Generate a set of random float components for a solution
This uses the numpy np.random.randn which generates numbers on a standard distribution and then multiplies that with a random integer between 0 and 10.
- Parameters:
fs (float) – The original sampling frequency of the data
tf (TransferFunction) – The transfer function
n_evals (int, optional) – The number of evaluation frequencies, by default 10
- Returns:
A randomly generated solution for the transfer function
- Return type:
- resistics.testing.remove_record_times(records: Dict) Dict [source]#
Remove timestamps from records
Timestamps can make comparision of two data objects harder as processes need to have been run at exactly the same time for equality, which is unlikely to be the case in tests
- Parameters:
records (Dict) – The history records
- Returns:
The history records with timestamps removed
- Return type:
Dict