In [134]:
import pandas as pd
import matplotlib
matplotlib.rcParams.update({'font.size': 12})
matplotlib.rcParams.update({'grid.color': 'white', 'grid.linewidth':1})
%pylab inline


Populating the interactive namespace from numpy and matplotlib

In [141]:
path = "../data/HVC2014_10Grenon/"
fnameobs = "BC13867-A 2014-10-23.z"
fnamepred = "HVC 2014-10-27simplified.csv"
pathobs = path+fnameobs
pathpred = path+fnamepred

# #windows
# pathforPK = "..\\data\\nt01222a.z"
# pathfordata = "..\\data\\Kimberlite-2015-07-17.xls"

temp = np.loadtxt(pathobs, skiprows=11, delimiter=",")
data = pd.read_csv(pathpred)
data_active = data.loc[np.logical_and(data["Fl"]<100., data["Fm"]<1.)]
# data_active = data.loc[np.logical_and((data['Facies'] == 'XVK')|(data['Facies'] == 'PK')|(data['Facies'] == 'HK')|(data['Facies'] == 'VK'), data.notnull()['Rinf']==True)][["Facies", "0LabID (PCG)", "Peregrine ID", "(Latitude)", "(Longitude)", "Depth (m)","Mag Susc [SI]","Resistivity [Ohm.m]","Geometric Factor [m]","Sat Geometric Dens [g/cc]","Chargeability [ms]","Rinf","Linf","Ro","Rh","Qh","Ph", "Fh","pRh", "pQh","Rm","Qm","Pm", "Fm","pRm", "pQm","Rl","Ql","Pl", "Fl", "pRl", "pQl","Re","Qe","Pe-f","Pe-i"]]

In [142]:
# data_active[data['Facies'] == 'XVK']

In [143]:
data_active


Out[143]:
file Rinf Rh Ph Fh Rm Pm Fm Rl Pl Fl Re Qe Pe-f Pe-i Linf Fhigh Flow date/time
3 BC13861-A 2014-10-23.z 17.9 66700 0.741 243000 1.000 0.500 0.100 12400 0.306 33.90 10000000000 0.000405 0.269 -2.0300 0.000002 1000000 0.0159 2014-11-03/11:05:19
11 BC13870 2014-10-23.z 513.0 683000 0.758 21200 1.000 0.500 0.100 60600 0.329 4.81 784000 0.000007 0.290 0.0555 0.000869 39800 0.0159 2015-03-09/15:32:27
12 BC13871-B 2014-10-23.z 10.2 246000 0.776 62900 1.000 0.500 0.100 64900 0.158 36.20 181000 0.000109 0.841 0.0689 0.000105 100000 0.0631 2015-03-09/15:33:27
15 BC13874 2014-10-23.z 12.0 105000 0.810 129000 1.000 0.500 0.100 40100 0.211 11.10 366000000 0.001070 1.440 0.0358 0.000003 1000000 0.0159 2014-11-03/10:10:15
18 BC13877 2014-10-28.z 70.1 66300 0.752 286000 1.000 0.500 0.100 28600 0.217 26.60 10000000000 0.000375 0.207 0.6200 0.000012 1000000 0.0159 2014-11-03/10:11:31
23 BC13882A 2014-10-28.z 69.3 176000 0.792 91400 1.000 0.500 0.100 76600 0.165 9.90 10000000000 0.000118 0.485 0.1790 0.000072 1000000 0.0159 2014-11-03/10:15:37
29 BC13888A 2014-10-23.z 697.0 32900 0.768 543000 1.000 0.500 0.100 18600 0.254 21.20 10000000000 0.002240 0.970 0.0960 0.000003 1000000 0.0159 2014-11-03/10:21:12
30 BC13889 2014-10-23.z 2910.0 157000 0.851 98200 1.000 0.500 0.100 25500 0.313 13.50 10000000000 0.000106 1.010 0.0344 0.000031 1000000 0.0159 2014-11-03/10:21:20
38 BC13911A 2014-10-29.z 570.0 68800 0.842 245000 4.450 0.516 0.114 13000 0.382 61.50 31200 0.000264 1.180 0.0578 0.000112 1000000 0.0251 2014-11-12/15:16:52
44 BC13924A 2014-10-28.z 31.5 256000 0.856 53600 1.000 0.500 0.100 54700 0.236 32.50 10000000000 0.000080 0.936 0.0815 0.000120 1000000 0.0159 2014-11-03/10:26:17
50 BC13932a 2014-10-28.z 133.0 562000 0.860 50100 1.000 0.500 0.100 20000 0.530 2.29 10000000000 0.000018 0.492 -1.9900 0.000029 1000000 0.0159 2014-11-03/10:33:36
51 BC13933a 2014-10-28.z 42.7 200000 0.712 55200 1.000 0.500 0.100 31300 0.293 15.00 10700000000 0.000335 1.330 0.0200 0.000011 1000000 0.0159 2014-11-03/10:34:01
57 BC13939A 2014-10-29.z 200.0 411000 0.763 42900 1.000 0.500 0.100 54000 0.326 91.20 10000000000 0.000097 1.150 0.0552 0.000003 1000000 0.0159 2014-11-03/10:41:34
59 BC13941B 2014-10-29.z 562.0 63800 0.704 218000 1.040 0.501 0.097 13500 0.407 65.60 174000 0.001440 0.685 0.1970 0.000010 1000000 0.0159 2014-11-12/15:18:59
60 BC13942B 2014-10-29.z 976.0 524000 0.800 40300 1.000 0.500 0.100 98100 0.339 10.10 2230000000 0.000040 1.040 0.0241 0.000059 1000000 0.0159 2014-11-03/10:44:24
65 BC13947A 2014-10-29.z 67.3 100000 0.729 96400 1.000 0.500 0.100 43800 0.241 17.70 29100000000 0.001120 0.498 0.2840 0.000017 1000000 0.0159 2014-11-03/10:46:47
67 BC13949A 2014-10-29.z 16.0 51100 0.745 267000 0.956 0.500 0.101 9090 0.564 85.10 11500000000 0.000624 0.198 0.5360 0.000004 1000000 1.0000 2014-11-12/14:27:17

In [144]:
labid = fnameobs

In [145]:
def readfun(i):
    Linf = data_active.iloc[i]['Linf']
    Rinf = data_active.iloc[i]['Rinf']
    Rh = data_active.iloc[i]['Rh']
    Ph = data_active.iloc[i]['Ph']
    Fh = data_active.iloc[i]['Fh']

    Rm = data_active.iloc[i]['Rm']
    Pm = data_active.iloc[i]['Pm']
    Fm = data_active.iloc[i]['Fm']

    Rl = data_active.iloc[i]['Rl']
    Pl = data_active.iloc[i]['Pl']
    Fl = data_active.iloc[i]['Fl']

    Re = data_active.iloc[i]['Re']
    Qe = data_active.iloc[i]['Qe']

    Pef = data_active.iloc[i]['Pe-f']
    Pei = data_active.iloc[i]['Pe-i']
    fname = data_active.iloc[i]['file']
    return Linf, Rinf, Rh, Fh, Ph, Rl, Fl, Pl, Rm, Fm, Pm, Re, Qe, Pef, Pei, fname

In [146]:
# Linf = data_active[data['file'] == labid]['Linf'].values[0]

# Rinf = data_active[data['file'] == labid]['Rinf'].values[0]
# Rh = data_active[data['file'] == labid]['Rh'].values[0]
# Ph = data_active[data['file'] == labid]['Ph'].values[0]
# Fh = data_active[data['file'] == labid]['Fh'].values[0]

# Rm = data_active[data['file'] == labid]['Rm'].values[0]
# Pm = data_active[data['file'] == labid]['Pm'].values[0]
# Fm = data_active[data['file'] == labid]['Fm'].values[0]

# Rl = data_active[data['file'] == labid]['Rl'].values[0]
# Pl = data_active[data['file'] == labid]['Pl'].values[0]
# Fl = data_active[data['file'] == labid]['Fl'].values[0]

# Re = data_active[data['file'] == labid]['Re'].values[0]
# Qe = data_active[data['file'] == labid]['Qe'].values[0]

# Pef = data_active[data['file'] == labid]['Pe-f'].values[0]
# Pei = data_active[data['file'] == labid]['Pe-i'].values[0]

In [ ]:


In [147]:
import sys 
#windows
# sys.path.append("..\\codes\\")
sys.path.append("../codes/")
from Zarcfit import *

In [193]:
def filehandler(i, viewtype):
    Linf, Rinf, Rh, Fh, Ph, Rl, Fl, Pl, Rm, Fm, Pm, Re, Qe, Pef, Pei,predname =readfun(i)
    pathobs = path+predname
    temp = np.loadtxt(pathobs, skiprows=11, delimiter=",")

    # observed impedance
    obs = temp[:,4]+1j*temp[:,5]
    # frequency
    frequency = temp[:,0].copy()
    # Initiate Zarfit
    zarc = Zarcfit(obs, frequency)
    zarc.SetParametersSeries(Linf, Rinf, Rh, Fh, Ph, Rl, Fl, Pl, Rm, Fm, Pm, Re, Qe, Pef, Pei)
    predS = zarc.Zseries(frequency)
    predP = zarc.Zparallel(frequency)
    Ro = zarc.R0
    pRinf = 1./(1./Ro+1./zarc.pRl)
    m = (Ro-pRinf) / Ro
    tau = (Ro*zarc.pQl/m)**(1./zarc.Pl)
    if viewtype =="ampphase":
        plotAmpPhase(obs, predS, predP, frequency)
    elif viewtype =="zarc":
        plotZarcdlogZdlogF(obs, predS, predP, frequency)
    print (predname)
    print (Ro, pRinf, m, tau, Pl)    
    return

In [194]:
from IPython.html import widgets

In [195]:
ndata = len(data_active.index)

In [196]:
widgets.interact(filehandler, i=widgets.IntSlider(min=0, max=ndata, step=1, value=0), 
                 viewtype=widgets.ToggleButtons(options=['ampphase','zarc']))


BC13924A 2014-10-28.z
310732.5 256032.5 0.17603565768 0.00489707517206 0.236

In [154]:




In [133]:
plotZarcdlogZdlogF(obs, predS, predP, frequency)



In [186]:
def plotAmpPhase(obs, predS, predP, frequency):
    matplotlib.rcParams.update({'font.size': 12})
    fig = plt.figure(figsize = (12, 5))
    amp = np.sqrt(obs.real**2+obs.imag**2)
    amp_predS = np.sqrt(predS.real**2+predS.imag**2)
    amp_predP = np.sqrt(predP.real**2+predP.imag**2)
    phase = np.angle(obs, deg=True)
    phase_predS = np.angle(predS, deg=True)
    phase_predP = np.angle(predP, deg=True)    
    ax = plt.subplot(121)
    ax1 = plt.subplot(122)
    ax.patch.set_facecolor('black')
    ax1.patch.set_facecolor('black')
    ax.plot(frequency, amp, 'lime', lw=3, marker=".", ms=8)
    ax.plot(frequency, amp_predS, 'deepskyblue', lw=2)
    ax.plot(frequency, amp_predP, 'b.')
    ax.set_xscale('log')
    ax.set_yscale('linear')        
    ax1.plot(frequency, -phase, 'lime', lw=3, marker=".", ms=8)
    ax1.plot(frequency, -phase_predS, 'deepskyblue', lw=2)
    ax1.plot(frequency, -phase_predP, 'b.')
    ax1.set_xscale('log')
    ax1.set_yscale('log')        
#     ax.set_ylim(amp.min(), amp.max())
    ax.set_xlabel("Frequency (Hz)")
    ax.set_ylabel("|Z| (Ohm)")
    ax1.set_xlabel("Frequency")
    ax1.set_ylabel("Phase (degree)")
    ax.grid(True)
    ax.yaxis.grid(True, which='minor')
    plt.tick_params(axis='y', which='minor')
    ax1.grid(True)
    ax1.yaxis.grid(True, which='minor')
    plt.tick_params(axis='y', which='minor')
    leg = ax1.legend(("Observed", "Predicted Series", "Predicted Parallel"), fontsize = 12, bbox_to_anchor = (1.6, 1))
    plt.show()
    return

In [ ]:


In [187]:
# fig = plt.figure(figsize = (11, 5))
# amp = np.sqrt(obs.real**2+obs.imag**2)
# amp_predS = np.sqrt(predS.real**2+predS.imag**2)
# amp_predP = np.sqrt(predP.real**2+predP.imag**2)

# ax = plt.subplot(121)
# ax1 = plt.subplot(122)

# ax.patch.set_facecolor('black')
# ax1.patch.set_facecolor('black')
# ax.plot(obs.real, -obs.imag, 'lime', lw=3, marker=".", ms=8)
# ax.plot(predS.real, -predS.imag, 'deepskyblue', lw=2)
# ax.plot(predS.real, -predP.imag, 'b.')
# ax1.semilogx(frequency[1:]*0.5+frequency[0:-1]*0.5, diff(np.log10(amp))/diff(np.log10(frequency)), 'lime', lw=3, marker=".", ms=8)
# ax1.semilogx(frequency[1:]*0.5+frequency[0:-1]*0.5, diff(np.log10(amp_predS))/diff(np.log10(frequency)), 'deepskyblue', lw=2)
# ax1.semilogx(frequency[1:]*0.5+frequency[0:-1]*0.5, diff(np.log10(amp_predP))/diff(np.log10(frequency)), 'b.', lw=2)
# ax.set_xlim(obs.real.min(), obs.real.max())
# ax.set_ylim((-obs.imag).min(), (-obs.imag).max())
# ax.set_xlabel("Real (Ohm)")
# ax.set_ylabel("- Imaginary (Ohm)")
# ax1.set_xlabel("Frequency")
# ax1.set_ylabel("dlog(Amp)/dlog(Freq)")
# ax.grid(True)
# ax.yaxis.grid(True, which='minor')
# plt.tick_params(axis='y', which='minor')
# ax1.grid(True)
# ax1.yaxis.grid(True, which='minor')
# plt.tick_params(axis='y', which='minor')
# leg = ax1.legend(("Observed", "Predicted Series", "Predicted Parallel"), fontsize = 12, bbox_to_anchor = (1.6, 1))

In [188]:
def plotZarcdlogZdlogF(obs, predS, predP, frequency):
    fig = plt.figure(figsize = (12, 5))
    amp = np.sqrt(obs.real**2+obs.imag**2)
    amp_predS = np.sqrt(predS.real**2+predS.imag**2)
    amp_predP = np.sqrt(predP.real**2+predP.imag**2)
    ax = plt.subplot(121)
    ax1 = plt.subplot(122)
    ax.patch.set_facecolor('black')
    ax1.patch.set_facecolor('black')
    ax.plot(obs.real, -obs.imag, 'lime', lw=3, marker=".", ms=8)
    ax.plot(predS.real, -predS.imag, 'deepskyblue', lw=2)
    ax.plot(predS.real, -predP.imag, 'b.')
    ax1.semilogx(frequency[1:]*0.5+frequency[0:-1]*0.5, diff(np.log10(amp))/diff(np.log10(frequency)), 'lime', lw=3, marker=".", ms=8)
    ax1.semilogx(frequency[1:]*0.5+frequency[0:-1]*0.5, diff(np.log10(amp_predS))/diff(np.log10(frequency)), 'deepskyblue', lw=2)
    ax1.semilogx(frequency[1:]*0.5+frequency[0:-1]*0.5, diff(np.log10(amp_predP))/diff(np.log10(frequency)), 'b.', lw=2)
    ax.set_xlim(obs.real.min(), obs.real.max())
    ax.set_ylim((-obs.imag).min(), (-obs.imag).max())
    ax.set_xlabel("Real (Ohm)")
    ax.set_ylabel("Frequency (Hz)")
    ax1.set_xlabel("Frequency (Hz)")
    ax1.set_ylabel("dlog(Amp)/dlog(Freq)")
    ax.grid(True)
    ax.yaxis.grid(True, which='minor')
    plt.tick_params(axis='y', which='minor')
    ax1.grid(True)
    ax1.yaxis.grid(True, which='minor')
    plt.tick_params(axis='y', which='minor')
    leg = ax1.legend(("Observed", "Predicted Series", "Predicted Parallel"), fontsize = 12, bbox_to_anchor = (1.6, 1))
    plt.show()
    return

In [ ]: