Skip to content

Commit

Permalink
ENH: enable passing kwargs to SIP load and thus enable SIP-Quad import
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Günther committed Sep 7, 2023
1 parent 60c5e7f commit 688e4d1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 30 deletions.
48 changes: 24 additions & 24 deletions pygimli/physics/SIP/importData.py
Expand Up @@ -44,8 +44,8 @@ def load(fileName, verbose=False, **kwargs):
elif 'SIP-Quad' in firstLine:
if verbose:
pg.info("Reading SIP Quad file")
f, amp, phi, header = readFuchs3File(fileName,
verbose=verbose, **kwargs)
f, amp, phi, header = readFuchs3File(fileName, nfr=9, namp=10, nphi=11,
nk=7, verbose=verbose, **kwargs)
phi *= -np.pi/180.
elif 'SIP-Fuchs' in firstLine:
if verbose:
Expand Down Expand Up @@ -77,25 +77,24 @@ def fstring(fri):
return fstr


def readTXTSpectrum(filename):
def readTXTSpectrum(filename, nfr=0, namp=1, nphi=3, sphi=-1):
"""Read spectrum from ZEL device output (txt) data file."""
fid = open(filename)
lines = fid.readlines()
fid.close()
f, amp, phi = [], [], []
for line in lines[1:]:
snums = line.replace(';', ' ').split()
if len(snums) > 3:
f.append(float(snums[0]))
amp.append(float(snums[1]))
phi.append(-float(snums[3]))
else:
break
with open(filename) as fid:
lines = fid.readlines()
for line in lines[1:]:
snums = line.replace(';', ' ').split()
if len(snums) > 3:
f.append(float(snums[nfr]))
amp.append(float(snums[namp]))
phi.append(sphi*float(snums[nphi]))
else:
break

return np.asarray(f), np.asarray(amp), np.asarray(phi)
return np.asarray(f), np.asarray(amp), np.asarray(phi)


def readFuchs3File(resfile, k=1.0, verbose=False):
def readFuchs3File(resfile, k=1.0, verbose=False, nfr=11, namp=12, nphi=13, nk=9):
"""Read Fuchs III (SIP spectrum) data file.
Parameters
Expand All @@ -108,8 +107,8 @@ def readFuchs3File(resfile, k=1.0, verbose=False):
header = {}
LINE = []
dataAct = False
with codecs.open(resfile, 'r', encoding='iso-8859-15', errors='replace') as f:
for line in f:
with codecs.open(resfile, 'r', encoding='iso-8859-15', errors='replace') as fid:
for line in fid:
line = line.replace('\r\n', '\n') # correct for carriage return
if dataAct:
LINE.append(line)
Expand All @@ -118,12 +117,12 @@ def readFuchs3File(resfile, k=1.0, verbose=False):
for li in LINE:
sline = li.split()
if len(sline) > 12:
fi = float(sline[11])
fi = float(sline[nfr])
if np.isfinite(fi):
f.append(fi)
amp.append(float(sline[12]))
phi.append(float(sline[13]))
kIn.append(float(sline[9]))
amp.append(float(sline[namp]))
phi.append(float(sline[nphi]))
kIn.append(float(sline[nk]))

if k != 1.0 and verbose is True:
pg.info("Geometric value changed to:", k)
Expand Down Expand Up @@ -380,8 +379,9 @@ def readSIP256file(resfile, verbose=False):
bpos = fd.start() + 4

# print(ss[:bpos], ss[bpos:])
sline.insert(i, ss[:bpos])
sline[i+1] = ss[bpos:]
if ss[5:8] != ".20":
sline.insert(i, ss[:bpos])
sline[i+1] = ss[bpos:]
# print(sline)
fd = re.search('NaN[0-9-]*\.', ss)
if fd:
Expand Down
9 changes: 5 additions & 4 deletions pygimli/physics/SIP/sipspectrum.py
Expand Up @@ -250,7 +250,7 @@ class SIPSpectrum(object):

def __init__(self, filename=None, unify=False, onlydown=True,
f=None, amp=None, phi=None, k=1, sort=True,
basename='new'):
basename='new', **kwargs):
"""Init SIP class with either filename to read or data vectors.
Examples
Expand All @@ -269,7 +269,7 @@ def __init__(self, filename=None, unify=False, onlydown=True,
self.epsilon0 = 8.854e-12

if filename is not None:
self.loadData(filename)
self.loadData(filename, **kwargs)
else:
if f is not None:
self.f = np.asarray(f)
Expand Down Expand Up @@ -325,7 +325,8 @@ def loadData(self, filename, **kwargs):
if verbose:
pg.info("Reading SIP Quad file")
self.f, self.amp, self.phi, self.header = readFuchs3File(
filename, verbose=verbose, **kwargs)
filename, nfr=9, namp=10, nphi=11, nk=7,
verbose=verbose, **kwargs)
self.phi *= -np.pi/180.
elif 'SIP-Fuchs' in firstLine:
if verbose:
Expand All @@ -335,7 +336,7 @@ def loadData(self, filename, **kwargs):
**kwargs)
self.phi *= -np.pi/180.
elif fnLow.endswith('.txt') or fnLow.endswith('.csv'):
self.f, self.amp, self.phi = readTXTSpectrum(filename)
self.f, self.amp, self.phi = readTXTSpectrum(filename, **kwargs)
else:
try:
out = np.genfromtxt(filename, names=True)
Expand Down
4 changes: 2 additions & 2 deletions pygimli/physics/SIP/tools.py
Expand Up @@ -116,8 +116,8 @@ def fitCCC(f, amp, phi, eRho=0.01, ePhi=0.001, lam=1000., mstart=None,
return model, response[:len(f)], response[len(f):], ICC.chi2()


def fitCCCC(f, amp, phi, error=0.01, lam=10., taupar=(1e-2, 1e-5, 100),
cpar=(0.25, 0, 1), mpar=(0, 0, 1)):
def fitCCCC(f, amp, phi, error=0.01, lam=10., taupar=[1e-2, 1e-5, 100],
cpar=[0.25, 0, 1], mpar=[0, 0, 1]):
"""Fit complex spectrum by Cole-Cole model based on sigma."""
fCC = ColeColeComplexSigma(f)
tLog = pg.trans.TransLog()
Expand Down

0 comments on commit 688e4d1

Please sign in to comment.