pygimli.physics.sNMR#

Surface nuclear magnetic resonance (NMR) data inversion

Overview#

Classes

MRS([name, verbose])

Magnetic resonance sounding (MRS) manager class.

MRS1dBlockQTModelling(nlay, K, zvec, t[, ...])

MRS1dBlockQTModelling - pygimli modelling class for block-mono QT inversion

MRSprofile([filename, x, dx, x0])

manager class for several MRS data along a profile for joint inversion

Classes#

class pygimli.physics.sNMR.MRS(name=None, verbose=True, **kwargs)[source]#

Bases: object

Magnetic resonance sounding (MRS) manager class.

Variables:
  • q (t,) –

  • error (data,) –

  • z (K,) –

  • modelU (model, modelL,) –

loadMRSI - load MRSI (MRSmatlab format) data
showCube - show any data/error/misfit as data cube (over q and t)
showDataAndError - show data and error cubes
showKernel - show Kernel matrix
createFOP - create forward operator
createInv - create pygimli Inversion instance
run - run block-mono (alternatively smooth-mono) inversion (with bootstrap)
calcMCM - compute model covariance matrix and thus uncertainties
splitModel - return thickness, water content and T2* time from vector
showResult/showResultAndFit - show inversion result (with fit)
runEA - run evolutionary algorithm (GA, PSO etc.) using inspyred
plotPopulation - plot final population of an EA run
__init__(name=None, verbose=True, **kwargs)[source]#

MRS init with optional data load from mrsi file

Parameters:
  • name (string) – Filename with load data and kernel (.mrsi) or just data (.mrsd)

  • verbose (bool) – be verbose

:param kwargs - see MRS.loadMRSI().:

calcMCM()[source]#

Compute linear model covariance matrix.

calcMCMbounds()[source]#

Compute model bounds using covariance matrix diagonals.

checkData(**kwargs)[source]#

Check data and retrieve data and error vector.

static createFOP(nlay, K, z, t)[source]#

Create forward operator instance.

createInv(nlay=3, lam=100.0, verbose=True, **kwargs)[source]#

Create inversion instance (and fop if necessary with nlay).

genMod(individual)[source]#

Generate (GA) model from random vector (0-1) using model bounds.

invert(nlay=3, lam=100.0, startvec=None, verbose=True, uncertainty=False, **kwargs)[source]#

Easiest variant doing all (create fop and inv) in one call.

loadDataCube(filename='datacube.dat')[source]#

Load data cube from single ascii file (old stuff)

loadDataNPZ(filename, **kwargs)[source]#

Load data and kernel from numpy gzip packed file.

The npz file contains the fields: q, t, D, (E), z, K

loadDir(dirname)[source]#

Load several standard files from dir (old Borkum stage).

loadErrorCube(filename='errorcube.dat')[source]#

Load error cube from a single ascii file (old stuff).

loadKernel(name='')[source]#

Load kernel matrix from mrsk or two bmat files.

loadKernelNPZ(filename, **kwargs)[source]#

Load data and kernel from numpy gzip packed file.

The npz file contains the fields: q, t, D, (E), z, K

loadMRSD(filename, usereal=False, mint=0.0, maxt=2.0)[source]#

Load mrsd (MRS data) file: not really used as in MRSD.

loadMRSI(filename, **kwargs)[source]#

Load data, error and kernel from mrsi or mrsd file

Parameters:
  • usereal (bool [False]) – use real parts (after data rotation) instead of amplitudes

  • mint/maxt (float [0.0/2.0]) – minimum/maximum time to restrict time series

loadResult(filename)[source]#

Load inversion result from column file.

loadZVector(filename='zkernel.vec')[source]#

Load the kernel vertical discretisation (z) vector.

plotEAstatistics(fname=None)[source]#

Plot EA statistics (best, worst, …) over time.

plotPopulation(maxfitness=None, fitratio=1.05, savefile=True)[source]#

Plot fittest individuals (fitness<maxfitness) as 1d models

Parameters:
  • maxfitness (float) – maximum fitness value (absolute) OR

  • fitratio (float [1.05]) – maximum ratio to minimum fitness

result()[source]#

Return block model results (thk, wc and T2 vectors).

run(verbose=True, uncertainty=False, **kwargs)[source]#

Easiest variant doing all (create fop and inv) in one call.

runEA(nlay=None, eatype='GA', pop_size=100, num_gen=100, runs=1, mp_num_cpus=8, **kwargs)[source]#

Run evolutionary algorithm using the inspyred library

Parameters:
  • nlay (int [taken from classic fop if not given]) – number of layers

  • pop_size (int [100]) – population size

  • num_gen (int [100]) – number of generations

  • runs (int [pop_size*num_gen]) – number of independent runs (with random population)

  • eatype (string ['GA']) –

    algorithm, choose among:

    ’GA’ - Genetic Algorithm [default] ‘SA’ - Simulated Annealing ‘DEA’ - Discrete Evolutionary Algorithm ‘PSO’ - Particle Swarm Optimization ‘ACS’ - Ant Colony Strategy ‘ES’ - Evolutionary Strategy

saveFigs(basename=None, extension='pdf')[source]#

Save all figures to (pdf) files.

saveResult(filename)[source]#

Save inversion result to column text file for later use.

setBoundaries()[source]#

Set parameter boundaries for inversion.

showCube(ax=None, vec=None, islog=None, clim=None, clab=None)[source]#

Plot any data (or response, error, misfit) cube nicely.

showDataAndError(figsize=(10, 8), show=False)[source]#

Show data cube along with error cube.

showKernel(ax=None)[source]#

Show the kernel as matrix (Q over z).

showResult(figsize=(10, 8), save='', fig=None, ax=None)[source]#

Show theta(z) and T2*(z) (+uncertainties if there).

showResultAndFit(figsize=(12, 10), save='', plotmisfit=False, maxdep=0, clim=None)[source]#

Show ec(z), T2*(z), data and model response.

static simulate(model, K, z, t)[source]#

Do synthetic modelling.

splitModel(model=None)[source]#

Split model vector into d, theta and T2*.

class pygimli.physics.sNMR.MRS1dBlockQTModelling(nlay, K, zvec, t, verbose=False)[source]#

Bases: ModellingBaseMT__

MRS1dBlockQTModelling - pygimli modelling class for block-mono QT inversion

f=MRS1dBlockQTModelling(lay, KR, KI, zvec, t, verbose = False )

__init__(nlay, K, zvec, t, verbose=False)[source]#

Constructor with number of layers, kernel, z and t vectors.

response(par)[source]#

Yield model response cube as vector.

class pygimli.physics.sNMR.MRSprofile(filename=None, x=None, dx=1, x0=0, **kwargs)[source]#

Bases: object

manager class for several MRS data along a profile for joint inversion

Variables:
  • mrs (list of MRS objects (single soundings)) –

  • x (list of positions for the soundings) –

load - load mrs files from a directory
set X - set x vector
showData - show MRS data
independentBlock1dInversion - perform independent 1D block inversion
block1dInversion - 1D block inversion of all data sets together
blockLCInversion - 1D block laterally constrained inversion of all data
printFits - print total misfit (chi^2, rms) and individual values
showModel - show LCI model
__init__(filename=None, x=None, dx=1, x0=0, **kwargs)[source]#

Initialize profile object by mrs objects and optional positions.

Parameters:
  • filename (list of str | str) – list of files OR filenames(with *) OR directory to load

  • x (iterable) – position vector of individual soundings

  • x0 (float [0]) – starting position

  • dx (position [1]) – position increment

block1dInversion(nlay=2, lam=100.0, show=False, verbose=True, uncertainty=False)[source]#

Invert all data together by a 1D model (more general solution).

block1dInversionOld(nlay=2, startModel=None, verbose=True, uncertainty=False, **kwargs)[source]#

Invert all data together by one 1D model (variant 1 - all equal).

blockLCInversion(nlay=2, startModel=None, **kwargs)[source]#

Laterally constrained (piece-wise 1D) block inversion.

independentBlock1dInversion(nlay=2, lam=100, startModel=None)[source]#

Independent inversion of all soundings.

Parameters:
  • nlay (int [2]) – number of layers

  • lam (float) – regularization parameter

  • startModel (array/vector) – starting model (see MRS.run parameters)

load(filenames, **kwargs)[source]#

load mrs files in a list of (single) MRS handlers filename can be a list of mrsi files or a directory to search Additional parameters: usereal, mint, maxt (see MRS.load)

loadKernel(kernelfile)[source]#

load one kernel file for all soundings

printFits()[source]#

Show single fits and total fit.

saveFigs(basename='out', extension='pdf')[source]#

Save all figures to (pdf) files.

setX(x=None, x0=0, dx=1)[source]#

define positions for soundings and sort accordingly

show1dModel()[source]#

Show 1D model (e.g. of joint block inversion).

showData(figsize=(15, 10), nc=0, nr=0, clim=None)[source]#

show all data cubes in subplots

showFits(ax=None)[source]#

Show chi-square and rms fits of individual soundings.

showInitialValues()[source]#

show initial values of whole profile

showModel(showFit=0, cmap='Spectral', figsize=(13, 12), wlim=(0, 0.5), tlim=(0.05, 0.5))[source]#

Show 2d model as stitched 1d models along with fit.

showT2(tlim=(0.05, 0.5), ax=None, cmap='Spectral', title='$T_2^*$ (s)')[source]#

Show relaxation time distribution as stitched model section.

showWC(wlim=(0, 0.5), ax=None, cmap='Spectral', title='$\\theta$ (-)')[source]#

Show water content distribution as stitched model section.