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.record_example1() Record[source]#

Get an example Record

resistics.testing.record_example2() Record[source]#

Get an example Record

resistics.testing.history_example() History[source]#

Get a History example

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:
  • fs (float, optional) – The sampling frequency, by default 10

  • first_time (str, optional) – The first time, by default “2021-01-01 00:00:00”

  • n_samples (int, optional) – The number of samples, by default 11

Returns:

TimeMetadata

Return type:

TimeMetadata

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:
  • fs (float, optional) – The sampling frequency, by default 10

  • first_time (str, optional) – The first time, by default “2021-01-01 00:00:00”

  • n_samples (int, optional) – The number of samples, by default 11

Returns:

TimeMetadata

Return type:

TimeMetadata

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:
  • chans (List[str]) – The channels in the time data

  • fs (float, optional) – The sampling frequency, by default 10

  • first_time (_type_, optional) – The time of the first sample, by default “2020-01-01 00:00:00”

  • n_samples (int, optional) – The number of samples, by default 11

Returns:

An instance of TimeMetadata with the approripate properties

Return type:

TimeMetadata

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:
  • fs (float, optional) – The sampling frequency, by default 10

  • 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 11

Returns:

TimeMetadata

Return type:

TimeMetadata

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:
  • fs (float, optional) – The sampling frequency, by default 10

  • first_time (str, optional) – The time of the first sample, by default “2020-01-01 00:00:00”

  • n_samples (int, optional) – The number of samples, by default 10

  • dtype (Optional[Type], optional) – The data type for the values, by default None

Returns:

The TimeData

Return type:

TimeData

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

Parameters:
  • fs (float, optional) – The sampling frequency, by default 10

  • first_time (str, optional) – The time of the first sample, by default “2020-01-01 00:00:00”

  • dtype (Optional[Type], optional) – The data type for the values, by default None

Returns:

The TimeData

Return type:

TimeData

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

Parameters:
  • fs (float, optional) – Sampling frequency, by default 10

  • first_time (str, optional) – The time of the first sample, by default “2020-01-01 00:00:00”

  • dtype (Optional[Type], optional) – The data type for the values, by default None

Returns:

The TimeData

Return type:

TimeData

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:
  • fs (float, optional) – The sampling frequency, by default 10

  • first_time (str, optional) – Time of first sample, by default “2020-01-01 00:00:00”

  • n_samples (int, optional) – The number of samples, by default 10

  • dtype (Optional[Type], optional) – The data type for the values, by default None

Returns:

TimeData with linear values

Return type:

TimeData

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:
  • fs (float, optional) – The sampling frequency, by default 10

  • first_time (str, optional) – Time of first sample, by default “2020-01-01 00:00:00”

  • n_samples (int, optional) – The number of samples, by default 10

  • dtype (Optional[Type], optional) – The data type for the values, by default None

Returns:

The TimeData

Return type:

TimeData

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:

TimeData

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:

TimeData

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:

DecimatedMetadata

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:

DecimatedData

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:

DecimatedData

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:

DecimatedData

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:

SpectraMetadata

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:

SpectraData

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

Parameters:
  • chans (List[str]) – The channels in the data

  • soln (Solution) – The Solution that needs to be satisfied

  • n_wins (int) – The number of windows to generate

Returns:

The evaluation frequency data array

Return type:

np.ndarray

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:

SpectraData

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:
  • n_in (int) – Number of input channels

  • n_out (int) – Number of output channels

Returns:

A randomly generated transfer function

Return type:

TransferFunction

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:

RegressionInputMetadata

resistics.testing.components_mt() Dict[str, Component][source]#

Get example components for the Impedance Tensor

Returns:

Dictionary of component values (ExHx, ExHy, EyHx, EyHy)

Return type:

Dict[str, Component]

resistics.testing.solution_mt() Solution[source]#

Get an example impedance tensor solution

Returns:

The solution for an MT dataset

Return type:

Solution

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:

Solution

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:

Solution

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:

Solution

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

resistics.testing.assert_time_data_equal(time_data1: TimeData, time_data2: TimeData, history_times: bool = True)[source]#

Assert that two time data instances are equal

Parameters:
  • time_data1 (TimeData) – Time data 1

  • time_data2 (TimeData) – Time data 2

  • history_times (bool, optional) – Flag to include history timestamps in the comparison, by default True. Including timestamps will cause a failure if processes were not run at exactly the same time.

resistics.testing.assert_soln_equal(soln1: Solution, soln2: Solution)[source]#

Check that two solutions are nearly the same

Parameters:
  • soln1 (Solution) – The first solution

  • soln2 (Solution) – The second solution