In [1]:
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 [2]:
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"]<20., 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 [3]:
# data_active[data['Facies'] == 'XVK']

In [4]:
data_active


Out[4]:
file Rinf Rh Ph Fh Rm Pm Fm Rl Pl Fl Re Qe Pe-f Pe-i Linf Fhigh Flow date/time
8 BC13867-A 2014-10-23.z 4300.000 91700 0.846 176000 2720 0.654 430 5140 0.393 1.2300 1.070000e+10 0.000188 0.934 0.02260 7.100000e-07 159000 0.0631 2015-03-09/15:29:24
9 BC13868 2014-10-23.z 35.200 33100 0.753 546000 6810 0.453 235 5160 0.399 0.6020 1.000000e+10 0.000864 0.280 0.35700 1.440000e-05 1000000 0.0159 2015-03-09/15:29:55
10 BC13869 2014-10-23.z 36.100 34300 0.734 354000 8090 0.462 435 8690 0.421 0.4790 1.000000e+10 0.000213 0.325 0.30000 1.070000e-06 1000000 0.0251 2015-03-09/15:31:36
14 BC13873A 2014-10-23.z 11.200 42700 0.803 383000 1160 0.854 106 16000 0.193 5.6700 3.660000e+08 0.002500 0.962 0.11500 1.410000e-06 398000 0.0251 2015-03-09/15:34:14
17 BC13876B 2014-10-28.z 32.000 14300 0.710 838000 4590 0.521 167 1840 0.667 0.5930 1.000000e+10 0.003060 0.433 -2.00000 1.450000e-06 1000000 0.0159 2014-11-03/10:11:15
20 BC13879A 2014-10-28.z 0.692 254 1.000 852000 1310 0.617 3610 2150 0.391 4.5300 1.000000e+10 0.000218 0.300 -1.90000 2.520000e-08 1000000 3.9800 2015-03-09/15:45:20
21 BC13880B 2014-10-28.z 236.000 119000 0.770 120000 21000 0.556 171 16100 0.500 0.2000 1.380000e+10 0.000537 0.920 0.10800 7.750000e-05 159000 0.0251 2015-03-09/15:45:51
22 BC13881 2014-10-28.z 50.500 7960 0.813 2180000 14500 0.408 1350 4210 0.569 0.4150 1.120000e+06 0.000193 0.294 0.51500 1.540000e-06 1000000 0.0398 2015-03-09/15:47:21
25 BC13884A 2014-10-23.z 73.400 38800 0.689 373000 4580 0.556 285 4000 0.572 0.6740 2.190000e+10 0.000827 0.715 0.07770 6.690000e-06 1000000 0.0251 2014-11-12/10:40:44
31 BC13890A 2014-10-23.z 527.000 25200 0.770 568000 8970 0.526 490 12000 0.374 0.2020 1.000000e+10 0.011000 0.262 0.12100 5.700000e-08 1000000 0.0100 2015-10-14/11:44:35
33 BC13892A 2014-10-23.z 17.900 16200 0.737 1230000 4000 0.511 192 845 0.758 0.8190 2.590000e+11 0.001230 0.238 0.46800 1.160000e-06 1000000 0.0251 2014-11-12/13:51:46
34 BC13893A 2014-10-23.z 2880.000 72200 0.882 235000 6970 0.412 600 8460 0.429 0.1780 1.000000e+10 0.000175 0.593 0.05880 5.140000e-06 398000 0.0398 2015-03-09/15:49:15
35 BC13894 2014-10-23.z 73.600 40800 0.784 408000 3410 0.507 285 9670 0.271 0.0508 5.660000e+03 0.001630 0.927 -0.01700 2.620000e-06 1000000 0.0251 2015-10-14/12:19:23
37 BC13896A 2014-10-28.z 22.900 60000 0.814 190000 8600 0.391 473 6840 0.468 0.1030 1.200000e+10 0.000735 0.648 -0.00324 2.240000e-05 1000000 0.0251 2014-11-03/10:24:43
39 BC13914A 2014-10-29.z 85.100 77300 0.794 216000 10500 0.460 231 9290 0.343 1.4100 8.050000e+10 0.000884 0.552 0.39800 7.050000e-05 1000000 0.0159 2015-03-09/15:49:56
41 BC13919B 2014-10-29.z 14.500 27700 0.752 405000 8020 0.465 373 2610 0.894 0.7150 5.770000e+09 0.003170 0.562 0.44000 2.230000e-06 1000000 0.0251 2014-11-03/10:25:33
43 BC13921A 2014-10-29.z 8.670 22800 0.777 544000 4640 0.584 264 1900 0.748 0.5530 1.000000e+10 0.002900 0.183 0.58700 1.170000e-06 1000000 0.0159 2014-11-12/14:01:51
45 BC13925 2014-10-28.z 252.000 32200 0.887 808000 12000 0.428 564 804 0.909 0.4240 3.140000e+09 0.001300 0.203 0.72500 2.100000e-06 1000000 0.1590 2014-11-03/10:27:18
47 BC13928b 2014-10-28.z 257.000 5890 0.638 2460000 3120 0.681 325 847 0.706 3.9300 5.300000e+09 0.000582 0.152 -2.05000 1.760000e-06 1000000 0.0159 2015-03-09/15:51:46
52 BC13934 2014-10-28.z 145.000 5540 0.882 2020000 5540 0.474 1330 1850 0.963 1.5000 2.390000e+09 0.000537 0.394 -2.01000 4.840000e-06 1000000 0.0631 2015-03-09/15:52:32
53 BC13935a 2014-10-28.z 1800.000 52500 0.748 185000 3670 0.546 289 9590 0.374 0.0687 1.050000e+10 0.000389 0.793 -0.00173 5.190000e-06 1000000 0.0631 2014-11-03/10:38:02
55 BC13937A 2014-10-29.z 49.200 14500 0.711 1490000 3950 0.512 198 1350 0.870 0.4540 2.140000e+09 0.001850 0.345 -2.20000 1.480000e-06 1000000 0.0159 2014-11-12/14:10:52
56 BC13938A 2014-10-29.z 76.000 18900 0.655 1140000 11800 0.350 347 4480 0.593 0.2620 1.240000e+10 0.145000 0.390 0.07030 1.280000e-06 1000000 0.0159 2014-11-12/14:13:11
58 BC13940 2014-10-29.z 92.000 63300 0.767 245000 26700 0.284 1430 2660 0.518 0.0807 9.880000e+09 0.000148 1.130 0.01670 4.420000e-05 1000000 0.0159 2014-11-03/10:42:28
62 BC13944B 2014-10-29.z 15.000 55500 0.734 244000 10800 0.436 135 6520 0.424 0.0960 2.680000e+10 0.000374 0.319 -1.89000 2.370000e-06 1000000 0.1000 2014-11-03/10:46:10

In [5]:
labid = fnameobs

In [6]:
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 [7]:
# 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 [8]:
import sys 
#windows
# sys.path.append("..\\codes\\")
sys.path.append("../codes/")
from Zarcfit import *

In [9]:
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 [10]:
from IPython.html import widgets


/Users/sgkang/anaconda/lib/python2.7/site-packages/IPython/html.py:14: ShimWarning: The `IPython.html` package has been deprecated. You should import from `notebook` instead. `IPython.html.widgets` has moved to `ipywidgets`.
  "`IPython.html.widgets` has moved to `ipywidgets`.", ShimWarning)

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

In [20]:
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 [21]:
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 [22]:
widgets.interact(filehandler, i=widgets.IntSlider(min=0, max=ndata, step=1, value=0), 
                 viewtype=widgets.ToggleButtons(options=['ampphase','zarc']))


BC13890A 2014-10-23.z
(46697.0, 34697.0, 0.25697582285799947, 0.78789575788067023, 0.374)

In [14]:
# 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 [15]:


In [ ]:


In [ ]: