def debye_decomposition_one_spectrum(self, abmn, spectrum, gen_plots_in_dir=None): """Conduct a Debye Decomposition on each spectrum. Save certain parameters in sEIT.data columns and/or return fit data """ opt_import('lib_dd') import lib_dd.decomposition.ccd_single as ccd_single import lib_dd.config.cfg_single as cfg_single print(abmn) # set options using this dict-like object config = cfg_single.cfg_single() config['frequency_file'] = spectrum['frequency'].values rmag_rpha = np.hstack(( spectrum['r'], spectrum['rpha'], )) # print('rmag_rpha') # print(rmag_rpha) config['data_file'] = rmag_rpha ccd_obj = ccd_single.ccd_single(config) ccd_obj.fit_data() last_it = ccd_obj.results[0].iterations[-1] if gen_plots_in_dir is not None: pwd = os.getcwd() os.makedirs(gen_plots_in_dir, exist_ok=True) os.chdir(gen_plots_in_dir) filename = 'plot_{}.jpg'.format(abmn.values[0, :]) print('FILENAME', filename) last_it.plot(filename=filename) os.chdir(pwd) return last_it
""" Compute geometric factors (also referred to as K) using CRMod/CRTomo """ import os import tempfile import shutil import subprocess import numpy as np import pandas as pd from reda.utils import opt_import CRbinaries = opt_import("crtomo.binaries") CRcfg = opt_import("crtomo.cfg") import reda.utils.mpl plt, mpl = reda.utils.mpl.setup() def _write_config_file(filename, dataframe): if isinstance(dataframe, pd.DataFrame): AB = dataframe['a'].values * 1e4 + dataframe['b'].values MN = dataframe['m'].values * 1e4 + dataframe['n'].values else: AB = dataframe[:, 0] * 1e4 + dataframe[:, 1] MN = dataframe[:, 2] * 1e4 + dataframe[:, 3] with open(filename, 'wb') as fid: fid.write('{0}\n'.format(AB.shape[0]).encode('utf-8'))
def to_pg_scheme(self, container=None, positions=None): """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) """ if container is None and positions is None: raise Exception('electrode positions are required for BERT export') if container is not None and container.electrodes is None: raise Exception('container does not contain electrode positions') if container is not None and positions is not None: raise Exception( 'only one of container OR positions must be provided') if container is not None: elec_positions = container.electrodes.values elif positions is not None: elec_positions = positions opt_import("pybert", requiredFor="") import pybert # Initialize BERT DataContainer data = pybert.DataContainerERT() # Define electrodes (48 electrodes spaced by 0.5 m) for nr, (x, y, z) in enumerate(elec_positions): data.createSensor((x, y, z)) # Define number of measurements data.resize(self.configs.shape[0]) for index, token in enumerate("abmn"): data.set(token, self.configs[:, index].tolist()) # account for zero indexing for token in "abmn": data.set(token, data(token) - 1) # np.vstack([data.get(x).array() for x in ("abmn")]).T return data
# *-* coding: utf-8 *-* import re import itertools import pandas as pd import numpy as np # from StringIO import StringIO from io import StringIO import os import logging from reda.utils import opt_import IPython = opt_import("IPython", "interactive debugging") def _get_nr_of_electrodes(header_group): groups = itertools.groupby( header_group, lambda line: (line.startswith('[Number of Remote Units]'))) for switch, group in groups: if switch: nr_of_electrodes = int(next(group)[24:].strip()) + 1 return nr_of_electrodes def parse_readic_header(header_group, dipole_mode="all"): """ Parameters ---------- dipole_mode: Which dipoles should be extracted "all" "before"