Example #1
0
    def _get_tdm(self, m):
        """For a given model of resistivity magnitudes and phases, return a
        tdMan instance

        Parameters
        ----------
        m : Nx1|Nx2 ndarray
            N Model parameters, first column linear magnitudes [ohm m], second
            column phase values [mrad]

        Returns
        -------
        tdm : crtomo.tdMan
            td manager
        """
        if len(m.shape) == 1:
            m = m[:, np.newaxis]
        assert len(m.shape) == 2
        # print('gettm')
        # import IPython
        # IPython.embed()
        tdm = crtomo.tdMan(grid=self.grid, tempdir=self.tempdir)
        tdm.configs.add_to_configs(self.configs)

        pid_mag = tdm.parman.add_data(m[:, 0])
        tdm.register_magnitude_model(pid_mag)
        if m.shape[1] == 2:
            pid_pha = tdm.parman.add_data(m[:, 1])
        else:
            pid_pha = tdm.parman.add_data(np.zeros(m.shape[0]))
        tdm.register_phase_model(pid_pha)
        return tdm
Example #2
0
    def export_to_crtomo_td_manager(self, grid, norrec='norrec'):
        """Return a ready-initialized tdman object from the CRTomo tools.

        WARNING: Not timestep aware!

        Parameters
        ----------
        grid : crtomo.crt_grid
            A CRTomo grid instance
        norrec : str (nor|rec|norrec)
            Which data to export. Default: norrec (all)
        """
        subdata = self.data.query('norrec == "{}"'.format(norrec))
        import crtomo
        data = subdata[['a', 'b', 'm', 'n', 'r', 'rpha']]
        tdman = crtomo.tdMan(grid=grid, volt_data=data)
        return tdman
Example #3
0
noise level. As such it **may** be possible/useful to sometimes reduce a given
noise estimate below the actual noise level added to synthetic data.

For further reading, see:

https://en.wikipedia.org/wiki/Pseudorandom_number_generator
"""
###############################################################################
# Imports
import numpy as np
import crtomo

###############################################################################
# Setup: Generate some synthetic data
mesh = crtomo.crt_grid.create_surface_grid(nr_electrodes=10, spacing=1)
tdm = crtomo.tdMan(grid=mesh)

tdm.add_homogeneous_model(100, 0)
tdm.configs.gen_dipole_dipole(skipc=0)
rmag = tdm.measurements()[:, 0]
rpha = tdm.measurements()[:, 1]

###############################################################################
# Generate data noise
# -------------------
# For synthetic studies a good starting point is that the structure of the
# actual noise should be the same as used in the inversion error model. As such
# we use a linear model for the magnitude noise components, and an absolute
# standard deviation for the phase values.

# Important: ALWAYS initialize the random number generator using a seed!
#!/usr/bin/env python3
# *-* coding: utf-8 *-*
"""
Plot inversion results from a tomodir
=====================================

"""
import crtomo
import numpy as np
tdm = crtomo.tdMan(tomodir='tomodir')

###############################################################################
# Plot the last magnitude and phase iteration the quick and dirty way.
# Note that all iterations are stored in the tdm.a['inversion'][KEY] list
tdm.show_parset(tdm.a['inversion']['rmag'][-1])
tdm.show_parset(tdm.a['inversion']['rpha'][-1])
###############################################################################
# Let's do this the nice way: We want to plot the magnitude, real and imaginary
# part of the complex conductivity as well as the phase into one plot result.

import matplotlib.pylab as plt
# extract parameter set ids
pid_rmag = tdm.a['inversion']['rmag'][-1]
pid_rpha = tdm.a['inversion']['rpha'][-1]
pid_cre = tdm.a['inversion']['cre'][-1]
pid_cim = tdm.a['inversion']['cim'][-1]

# Note that we can switch out the resistivity magnitude with the conductivity
# magnitude by accessing the parset and taking the inverse values.
rmag = tdm.parman.parsets[pid_rmag]
cmag = 1 / rmag
Example #5
0
###############################################################################
# Datenfile in CRTomo Format ausgeben (volt.dat)
# ----------------------------------------------

crto.write_files_to_directory(ert.data, '.')

###############################################################################
# Arbeiten im Tomodir
# -------------------

###############################################################################
# Gitter und Daten einlesen
# -------------------------

td_obj = crtomo.tdMan(elem_file='elem.dat', elec_file='elec.dat')
td_obj.read_voltages('volt.dat')

###############################################################################
# Inversionseinstellungen
# -----------------------

td_obj.crtomo_cfg['robust_inv'] = 'F'
td_obj.crtomo_cfg['dc_inv'] = 'F'
td_obj.crtomo_cfg['cells_z'] = '-1'
td_obj.crtomo_cfg['mag_rel'] = '10'
td_obj.crtomo_cfg['mag_abs'] = '0.5'
td_obj.crtomo_cfg['fpi_inv'] = 'F'
# td_obj.crtomo_cfg['pha_a1'] = '10'
# td_obj.crtomo_cfg['pha_b'] = '-1.5'
# td_obj.crtomo_cfg['pha_rel'] = '10'
Example #6
0
#!/usr/bin/env python3
# *-* coding: utf-8 *-*
"""
Plot a potential distribution, computed with CRMod
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


"""
###############################################################################
# create a tomodir object
import crtomo
grid = crtomo.crt_grid('grid_surface/elem.dat', 'grid_surface/elec.dat')
td = crtomo.tdMan(grid=grid)

###############################################################################
# define configurations
import numpy as np
td.configs.add_to_configs(np.array((
    (1, 10, 5, 7),
    (1, 3, 10, 7),
)))

###############################################################################
# add a homogeneous forward model
td.add_homogeneous_model(100, 0)

###############################################################################
# compute FEM solution using CRMod
td.model(potentials=True)

###############################################################################
###############################################################################
# compute correction factors using data from this frequency
target_frequency = 70
###############################################################################
# dataset 1
seit1 = reda.sEIT()
seit1.import_eit_fzj(
    'data/CalibrationData/bnk_water_blubber_20130428_1810_34_einzel.mat',
    'data/configs.dat')
configurations = seit1.data.query(
    'frequency == {}'.format(target_frequency))[['a', 'b', 'm', 'n']].values
# extract configurations for one frequency
###############################################################################
# synthetic forward modeling
grid = crtomo.crt_grid('data/elem.dat', 'data/elec.dat')
tdman = crtomo.tdMan(grid=grid)

# add configuration added from the measurement data
tdman.configs.add_to_configs(configurations)

# true water conductivity 37.5 mS/m
tdman.add_homogeneous_model(1 / (37.5 / 1000), 0)

tdman.crmod_cfg['2D'] = '0'
tdman.crmod_cfg['fictitious_sink'] = 'T'
tdman.crmod_cfg['sink_node'] = '6467'
R_mod = tdman.measurements()

df_mod = pd.concat(
    (pd.DataFrame(tdman.configs.configs), pd.DataFrame(R_mod[:, 0])),
    axis=1,