reda.configs package

Submodules

reda.configs.configManager module

Manage measurement configurations measurements.

class reda.configs.configManager.ConfigManager(nr_of_electrodes=None)[source]

Bases: object

The class`ConfigManager` manages four-point measurement configurations.

Attributes:
nr_of_configs

Return number of configurations

unique_injections

Methods

abmn_to_dataframe()

Return a pandas.DataFrame containing the measurement configurations

add_to_configs(configs)

Add one or more measurement configurations to the stored configurations

clear_configs()

Remove all configs.

gen_all_current_dipoles()

Generate all possible current dipoles for the given number of electrodes (self.nr_electrodes).

gen_all_voltages_for_injections(injections_raw)

For a given set of current injections AB, generate all possible unique potential measurements.

gen_configs_permutate(injections_raw[, ...])

Create measurement configurations out of a pool of current injections.

gen_dipole_dipole(skipc[, skipv, stepc, ...])

Generate dipole-dipole configurations

gen_gradient([skip, step, vskip, vstep])

Generate gradient measurements

gen_inner_gradients(injections[, skips])

Given a set of current injections, generate voltage dipoles between the current electrodes

gen_reciprocals([append])

Generate reciprocal configurations, sort by AB, and optionally append to configurations.

gen_schlumberger(M, N[, a])

generate one Schlumberger sounding configuration, that is, one set of configurations for one potential dipole MN.

gen_wenner(a)

Generate Wenner measurement configurations.

get_unique_current_injections()

Return all unique current injection electrode pairs

load_configs(filename)

Load configurations from a file with four columns: a b m n

load_crmod_config(filename)

Load a CRMod configuration file

load_crmod_or_4c_configs(filename)

Load configurations either from a CRMod measurement file, or from a four-column file.

load_injections_from_mcf(filename)

Load injections from a mcf-file used by the sEIT-systems from FZJ; Injections in the file must be formatted like the following: SE 001 002 SE 002 001 .

remove_duplicates([configs])

remove duplicate entries from 4-point configurations.

remove_max_dipole_sep([maxsep])

Remove configurations with dipole separations higher than maxsep.

split_into_normal_and_reciprocal([pad, ...])

Split the stored configurations into normal and reciprocal measurements

to_iris_syscal(filename[, spacing])

Export to IRIS Instrument configuration file

to_pg_scheme([container, positions])

Convert the configuration to a pygimli measurement scheme

write_configs(filename)

Write configs to file in four columns

write_crmod_config(filename)

Write the configurations to a configuration file in the CRMod format All configurations are merged into one previor to writing to file

write_crmod_volt(filename, mid)

Write the measurements to the output file in the volt.dat file format that can be read by CRTomo.

write_crmod_volt_with_individual_errors(...)

Write the measurements and individual errors to the output file in the volt.dat file format that can be read by CRTomo.

remove_reciprocals

abmn_to_dataframe()[source]

Return a pandas.DataFrame containing the measurement configurations

Returns:
abmn_dfpandas.DataFrame

Configurations in a DataFrame (columns: a,b,m,n)

add_to_configs(configs)[source]

Add one or more measurement configurations to the stored configurations

Parameters:
configslist or numpy.ndarray

list or array of configurations

Returns:
configsKx4 numpy.ndarray

array holding all configurations of this instance

clear_configs()[source]

Remove all configs. This implies deleting all measurements.

gen_all_current_dipoles()[source]

Generate all possible current dipoles for the given number of electrodes (self.nr_electrodes). Duplicates are removed in the process.

After Noel and Xu, 1991, for N electrodes, the number of possible unique configurations is \(N \cdot (N - 1) / 2\). This excludes duplicates in the form of switches current/voltages electrodes, as well as reciprocal measurements.

Returns:
configsNx2 numpy.ndarray

all possible current dipoles A-B

gen_all_voltages_for_injections(injections_raw)[source]

For a given set of current injections AB, generate all possible unique potential measurements.

After Noel and Xu, 1991, for N electrodes, the number of possible voltage dipoles for a given current dipole is \((N - 2)(N - 3) / 2\). This includes normal and reciprocal measurements.

If current dipoles are generated with ConfigManager.gen_all_current_dipoles(), then \(N \cdot (N - 1) / 2\) current dipoles are generated. Thus, this function will produce \((N - 1)(N - 2)(N - 3) / 4\) four-point configurations ABMN, half of which are reciprocals (Noel and Xu, 1991).

All generated measurements are added to the instance.

Use ConfigManager.split_into_normal_and_reciprocal() to split the configurations into normal and reciprocal measurements.

Parameters:
injectionsnumpy.ndarray

Kx2 array holding K current injection dipoles A-B

Returns:
configsnumpy.ndarray

Nax4 array holding all possible measurement configurations

gen_configs_permutate(injections_raw, only_same_dipole_length=False, ignore_crossed_dipoles=False, silent=False)[source]

Create measurement configurations out of a pool of current injections. Use only the provided dipoles for potential dipole selection. This means that we have always reciprocal measurements.

Remove quadpoles where electrodes are used both as current and voltage dipoles.

Parameters:
injections_rawNx2 array

current injections

only_same_dipole_lengthbool, optional

if True, only generate permutations for the same dipole length

ignore_crossed_dipolesbool, optional

If True, potential dipoles will be ignored that lie between current dipoles, e.g. 1-4 3-5. In this case it is possible to not have full normal-reciprocal coverage.

silent: bool, optional

if True, do not print information on ignored configs (default: False)

Returns:
configsNx4 array

quadrupoles generated out of the current injections

gen_dipole_dipole(skipc, skipv=None, stepc=1, stepv=1, nr_voltage_dipoles=10, before_current=False, allow_crossings=False, start_skip=0, N=None)[source]

Generate dipole-dipole configurations

Parameters:
skipc: int

number of electrode positions that are skipped between electrodes of a given dipole

skipv: int

steplength between subsequent voltage dipoles. A steplength of 0 will produce increments by one, i.e., 3-4, 4-5, 5-6 …

stepc: int

steplength between subsequent current dipoles. A steplength of 0 will produce increments by one, i.e., 3-4, 4-5, 5-6 …

stepv: int

steplength between subsequent voltage dipoles. A steplength of 0 will produce increments by one, i.e., 3-4, 4-5, 5-6 …

nr_voltage_dipoles: int

the number of voltage dipoles to generate for each current injection dipole

before_current: bool, optional

if set to True, also generate voltage dipoles in front of current dipoles.

allow_crossingsbool, optional

Allow potential dipoles to cross current injection dipoles. Note that any quadpole generated by crossing the current electrodes is NOT counted into nr_voltage_dipoles.

start_skip: int, optional

how many electrode to skip before/after the first/second current electrode.

N: int, optional

number of electrodes, must be given if not already known by the config instance

Examples

>>> from reda.configs.configManager import ConfigManager
>>> config = ConfigManager(nr_of_electrodes=10)
>>> config.gen_dipole_dipole(skipc=2)
array([[ 1,  4,  5,  8],
       [ 1,  4,  6,  9],
       [ 1,  4,  7, 10],
       [ 2,  5,  6,  9],
       [ 2,  5,  7, 10],
       [ 3,  6,  7, 10]])
>>> from reda.configs.configManager import ConfigManager
>>> config = ConfigManager(nr_of_electrodes=10)
>>> config.gen_dipole_dipole(
...     skipc=2, before_current=True, allow_crossings=True)
array([[ 1,  4,  2,  5],
       [ 1,  4,  3,  6],
       [ 1,  4,  5,  8],
       [ 1,  4,  6,  9],
       [ 1,  4,  7, 10],
       [ 2,  5,  1,  4],
       [ 2,  5,  3,  6],
       [ 2,  5,  4,  7],
       [ 2,  5,  6,  9],
       [ 2,  5,  7, 10],
       [ 3,  6,  1,  4],
       [ 3,  6,  2,  5],
       [ 3,  6,  4,  7],
       [ 3,  6,  5,  8],
       [ 3,  6,  7, 10]])
>>> from reda.configs.configManager import ConfigManager
>>> config = ConfigManager(nr_of_electrodes=10)
>>> config.gen_dipole_dipole(skipc=1, before_current=True)
array([[ 1,  3,  4,  6],
       [ 1,  3,  5,  7],
       [ 1,  3,  6,  8],
       [ 1,  3,  7,  9],
       [ 1,  3,  8, 10],
       [ 2,  4,  5,  7],
       [ 2,  4,  6,  8],
       [ 2,  4,  7,  9],
       [ 2,  4,  8, 10],
       [ 3,  5,  6,  8],
       [ 3,  5,  7,  9],
       [ 3,  5,  8, 10],
       [ 4,  6,  1,  3],
       [ 4,  6,  7,  9],
       [ 4,  6,  8, 10],
       [ 5,  7,  2,  4],
       [ 5,  7,  1,  3],
       [ 5,  7,  8, 10]])
gen_gradient(skip=0, step=1, vskip=0, vstep=1)[source]

Generate gradient measurements

Parameters:
skip: int

distance between current electrodes

step: int

steplength between subsequent current dipoles

vskip: int

distance between voltage electrodes

vstep: int

steplength between subsequent voltage dipoles

gen_inner_gradients(injections, skips=None)[source]

Given a set of current injections, generate voltage dipoles between the current electrodes

Parameters:
injectionsNx2 numpy.ndarray

Current injections

skipsNone or iterable

The skips to generate. None will generate all possible skips

Returns:
configsNx4 numpy.ndarray

The generated configurations

Examples

>>> import reda
>>> cfg = reda.ConfigManager(nr_of_electrodes=10)
>>> cfg.gen_inner_gradients([1, 10], skips=[2, ])
array([[ 1, 10,  2,  5],
       [ 1, 10,  3,  6],
       [ 1, 10,  4,  7],
       [ 1, 10,  5,  8],
       [ 1, 10,  6,  9]])
gen_reciprocals(append=False)[source]

Generate reciprocal configurations, sort by AB, and optionally append to configurations.

Parameters:
appendbool

Append reciprocals to configs (the default is False).

Examples

>>> cfgs = ConfigManager(nr_of_electrodes=5)
>>> nor = cfgs.gen_dipole_dipole(skipc=0)
>>> rec = cfgs.gen_reciprocals(append=True)
>>> print(cfgs.configs)
[[1 2 3 4]
 [1 2 4 5]
 [2 3 4 5]
 [3 4 1 2]
 [4 5 1 2]
 [4 5 2 3]]
gen_schlumberger(M, N, a=None)[source]

generate one Schlumberger sounding configuration, that is, one set of configurations for one potential dipole MN.

Parameters:
M: int

electrode number for the first potential electrode

N: int

electrode number for the second potential electrode

a: int, optional

stepping between subsequent voltage electrodes. If not set, determine it as a = abs(M - N)

Returns:
configs: Kx4 numpy.ndarray

array holding the configurations

Examples

import reda.configs.configManager as CRconfig config = CRconfig.ConfigManager(nr_of_electrodes=40) config.gen_schlumberger(M=20, N=21)

gen_wenner(a)[source]

Generate Wenner measurement configurations.

Parameters:
a: int

distance (in electrodes) between subsequent electrodes of each four-point configuration.

Returns:
configs: Kx4 numpy.ndarray

array holding the configurations

get_unique_current_injections()[source]

Return all unique current injection electrode pairs

Returns:
unique_injectionsNx2 numpy.ndarray

Current injections

Examples

>>> from reda.configs.configManager import ConfigManager
>>> cfg = ConfigManager()
>>> cfg.nr_electrodes
>>> cfg.nr_electrodes = 10
>>> cfg.add_to_configs((
...     (1, 2, 3, 4),
...     (1, 2, 5, 6),
...     (7, 8, 9, 10)
... ))
array([[ 1,  2,  3,  4],
       [ 1,  2,  5,  6],
       [ 7,  8,  9, 10]])
>>> cfg.get_unique_current_injections()
array([[1, 2],
       [7, 8]])

cfg = ConfigManager() cfg.get_unique_current_injections()

load_configs(filename)[source]

Load configurations from a file with four columns: a b m n

load_crmod_config(filename)[source]

Load a CRMod configuration file

Parameters:
filename: string|io.BytesIO

absolute or relative path to a crmod config.dat file. Can also be a BytesIO object

load_crmod_or_4c_configs(filename)[source]

Load configurations either from a CRMod measurement file, or from a four-column file. Assume 1-indexed data (start with electrode 1).

Parameters:
filenamestr

Path to file that shall be imported

Returns:
None
load_injections_from_mcf(filename)[source]

Load injections from a mcf-file used by the sEIT-systems from FZJ; Injections in the file must be formatted like the following: SE 001 002 SE 002 001 . . .

Parameters:
filename: string

absolute or relative path to a mcf-file

Returns:
Nx2 numpy array with current injections
property nr_of_configs

Return number of configurations

Returns:
nr_of_configs: int

number of configurations stored in this instance

remove_duplicates(configs=None)[source]

remove duplicate entries from 4-point configurations. If no configurations are provided, then use self.configs. Unique configurations are only returned if configs is not None.

Parameters:
configs: Nx4 numpy.ndarray, optional

remove duplicates from these configurations instead from self.configs.

Returns:
configs_unique: Kx4 numpy.ndarray

unique configurations. Only returned if configs is not None

remove_max_dipole_sep(maxsep=10)[source]

Remove configurations with dipole separations higher than maxsep.

Parameters:
maxsepint

Maximum separation between both dipoles (the default is 10).

remove_reciprocals(configs=None)[source]
split_into_normal_and_reciprocal(pad=False, return_indices=False)[source]

Split the stored configurations into normal and reciprocal measurements

** Rule 1: the normal configuration contains the smallest electrode number of the four involved electrodes in the current dipole **

Parameters:
pad: bool, optional

if True, add numpy.nan values to the reciprocals for non-existent measuremnts

return_indices: bool, optional

if True, also return the indices of normal and reciprocal measurments. This can be used to extract corresponding measurements.

Returns:
normal: numpy.ndarray

Nnx4 array. If pad is True, then Nn == N (total number of unique measurements). Otherwise Nn is the number of normal measurements.

reciprocal: numpy.ndarray

Nrx4 array. If pad is True, then Nr == N (total number of unique measurements). Otherwise Nr is the number of reciprocal measurements.

nor_indices: numpy.ndarray, optional

Nnx1 array containing the indices of normal measurements. Only returned if return_indices is True.

rec_indices: numpy.ndarray, optional

Nrx1 array containing the indices of normal measurements. Only returned if return_indices is True.

to_iris_syscal(filename, spacing=1)[source]

Export to IRIS Instrument configuration file

Parameters:
filenamestring

Path to output filename

to_pg_scheme(container=None, positions=None)[source]

Convert the configuration to a pygimli measurement scheme

Parameters:
container: reda.containers.ERT.ERT

an ERT data container (we take the electrode positions from here)

positions = None
Returns:
data: pybert.DataContainerERT

Examples

import numpy as np from reda.configs.configManager import ConfigManager configs = ConfigManager(nr_of_electrodes=48) new_configs = configs.gen_dipole_dipole(skipc=2) x = np.arange(0, 48, 1) z = np.ones(48) * -1 y = np.zeros(48) xyz = np.vstack((x, y, z)).T scheme = configs.to_pg_scheme(positions=xyz) print(scheme)

property unique_injections
write_configs(filename)[source]

Write configs to file in four columns

write_crmod_config(filename)[source]

Write the configurations to a configuration file in the CRMod format All configurations are merged into one previor to writing to file

Parameters:
filename: string

absolute or relative path to output filename (usually config.dat)

write_crmod_volt(filename, mid)[source]

Write the measurements to the output file in the volt.dat file format that can be read by CRTomo.

Data is written in utf-8 encoding.

Parameters:
filename: string|io.BytesIO

output filename

mid: int or [int, int]

measurement ids of magnitude and phase measurements. If only one ID is given, then the phase column is filled with zeros

write_crmod_volt_with_individual_errors(filename, data_mids, error_mids, norm_mag=1, norm_pha=1)[source]

Write the measurements and individual errors to the output file in the volt.dat file format that can be read by CRTomo.

Data is written in utf-8 encoding.

Parameters:
filename: string|io.BytesIO

output filename

data_mids: [int, int]

measurement ids of magnitude and phase measurements

error_mids: [int, int]

ids of magnitude and phase error estimates

norm_mag: float

Normalization factor for magnitude errors

norm_pha: float

Normalization factor for magnitude errors