In [1]:
import sys
sys.path.append("../codes/")
from Readfiles import getFnames
from DCdata import readReservoirDC_all
%pylab inline


/Users/sgkang/anaconda2/lib/python2.7/site-packages/matplotlib/font_manager.py:273: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment.
  warnings.warn('Matplotlib is building the font cache using fc-list. This may take a moment.')
Populating the interactive namespace from numpy and matplotlib

In [2]:
directory = "../data/ChungCheonDC/"

In [3]:
fnames = getFnames(directory, dtype="apr", minimumsize=7000.)

In [4]:
fname_temp = fnames[0]
dat_temp,height_temp, ID = readReservoirDC_all(directory+fname_temp)

In [5]:
ntimes = len(fnames)
DATA = np.zeros((dat_temp.shape[0], ntimes))*np.nan
height = np.ones(ntimes)*np.nan

In [6]:
def vizDCtimeSeriesVariation(idatum, itime):
#     idatum = 0
    figsize(8,6)
    fig = plt.figure()
    ax1 = plt.subplot(211)
    ax2 = plt.subplot(212)    
#     ax1.plot(mid, dz, '.')
    itime_ref = 790
    DATA_ref = DATA[:,itime_ref]
    grid_rho = griddata(mid, dz, DATA[:,itime]/DATA_ref, grid_x, grid_z, interp='linear')
    grid_rho = grid_rho.reshape(grid_x.shape)
    vmin, vmax = 0.9, 1.1
    ax1.contourf(grid_x, grid_z, grid_rho, 100, vmin =vmin, vmax = vmax, clim=(vmin, vmax), cmap="jet")    
    ax1.contourf(grid_x, grid_z, grid_rho, 100, vmin =vmin, vmax = vmax, clim=(vmin, vmax), cmap="jet")        
    ax1.scatter(mid, dz, s=20, c = DATA[:,itime]/DATA_ref, edgecolor="None", vmin =vmin, vmax = vmax, clim=(vmin, vmax))
#     ax1.plot(grid_x.flatten(), grid_z.flatten(), 'k.')
    ax1.plot(mid[idatum], dz[idatum], 'ro')    
    ax2.plot(DATA[idatum,:], 'k-', lw=2)
    ax2.set_yscale('log')
    vmin, vmax = 50., 200.
    ax2.set_ylim(vmin, vmax)
    ax2_1 = ax2.twinx()
    ax2_1.plot(height)
    ax2_1.set_ylim(15, 21.)
    ax2_1.plot(np.r_[itime, itime], np.r_[15, 21.], 'k--', lw=1)
    ax1.text(0,0, fnames[itime])

In [7]:
fnamesactive = []
for i, fname in enumerate(fnames):
    dat_temp,height_temp, ID = readReservoirDC_all(directory+fname)
    if dat_temp.shape[0] == 380:        
        DATA[:,i] = dat_temp[:,-1]
        height[i] = height_temp[0]      
#         print fname        
        fnamesactive.append(fname)
    else:
        print fname


20150103180000.apr
20150106180000.apr
20150109120000.apr
20150112120000.apr
20150117120000.apr
20150120120000.apr
20150123120000.apr
20150126120000.apr
20150127000000.apr
20150129060000.apr
20150201000000.apr
20150204000000.apr
20150207000000.apr
20150209180000.apr
20150212180000.apr
20150215180000.apr
20150218120000.apr
20150221060000.apr
20150224120000.apr
20150227060000.apr
20150228000000.apr
20150302000000.apr
20150305000000.apr
20150308000000.apr
20150329000000.apr
20150401000000.apr
20150403180000.apr
20150404120000.apr
20150406180000.apr
20150409000000.apr
20150412120000.apr
20150415060000.apr
20150418000000.apr
20150421000000.apr
20150424000000.apr

In [8]:
a = ['1', '2', '3']

In [9]:
def strtofloat(input):
    temp = ""
    for i in input:
        temp += i 
    return float(temp)

In [10]:
# dat_temp,height_temp, datalist = readReservoirDC_all(fnames[79])
# print fnames[79]
# # datalist = readReservoirDC_all(fnames[79])

In [11]:
print fnames[79]


20150120120000.apr

In [12]:
locs = dat_temp[:,:4]

In [13]:
mida = locs[:,:2].sum(axis=1)
midb = locs[:,2:].sum(axis=1)
mid = (mida + midb)*0.5
dz = mida-midb

In [14]:
from ipywidgets import interact, IntSlider

In [15]:
from scipy import interpolate

In [16]:
x = np.linspace(mid.min(), mid.max(), 100)
z = np.linspace(dz.min(), dz.max(), 100)
# grid_x, grid_z = np.mgrid[np.min(mid):np.max(mid), np.min(dz):np.max(dz)]
grid_x, grid_z = np.meshgrid(x,z)

def vizDCtimeSeries(idatum, itime):
#     idatum = 0
    figsize(8,6)
    fig = plt.figure()
    ax1 = plt.subplot(211)
    ax2 = plt.subplot(212)    
#     ax1.plot(mid, dz, '.')

    grid_rho = griddata(mid, dz, DATA[:,itime], grid_x, grid_z, interp='linear')
    grid_rho = grid_rho.reshape(grid_x.shape)
    vmin, vmax = 50, 200.
    ax1.contourf(grid_x, grid_z, grid_rho, 100, vmin =vmin, vmax = vmax, clim=(vmin, vmax), cmap="jet")    
    ax1.contourf(grid_x, grid_z, grid_rho, 100, vmin =vmin, vmax = vmax, clim=(vmin, vmax), cmap="jet")        
    ax1.scatter(mid, dz, s=20, c = DATA[:,itime], edgecolor="None", vmin =vmin, vmax = vmax, clim=(vmin, vmax))
#     ax1.plot(grid_x.flatten(), grid_z.flatten(), 'k.')
    ax1.plot(mid[idatum], dz[idatum], 'ro')    
    ax2.plot(DATA[idatum,:], 'k-', lw=2)
    ax2.set_yscale('log')
    ax2.set_ylim(vmin, vmax)
    ax2_1 = ax2.twinx()
    ax2_1.plot(height)
    ax2_1.set_ylim(15, 21.)
    ax2_1.plot(np.r_[itime, itime], np.r_[15, 21.], 'k--', lw=1)
    ax1.text(0,0, fnames[itime])

In [17]:
interact(vizDCtimeSeries, idatum=IntSlider(min=0, max=300, step=10, value=0), 
        itime=IntSlider(min=0, max=DATA.shape[1]-1, step=100, value=0))


Out[17]:
<function __main__.vizDCtimeSeries>
/Users/sgkang/anaconda2/lib/python2.7/site-packages/matplotlib/scale.py:101: RuntimeWarning: invalid value encountered in less_equal
  a[a <= 0.0] = 1e-300

In [ ]:


In [ ]:


In [18]:
interact(vizDCtimeSeriesVariation, idatum=IntSlider(min=0, max=300, step=1, value=0), 
        itime=IntSlider(min=0, max=DATA.shape[1]-1, step=20, value=0))


Out[18]:
<function __main__.vizDCtimeSeriesVariation>

In [19]:
DATA.shape


Out[19]:
(380, 1270)

In [20]:
x = np.linspace(mid.min(), mid.max(), 100)
z = np.linspace(dz.min(), dz.max(), 40)

In [21]:
print z.min(), z.max()
print x.min(), x.max()


-18.0 -4.0
5.0 105.0

In [22]:
np.diff(x)


Out[22]:
array([ 1.01010101,  1.01010101,  1.01010101,  1.01010101,  1.01010101,
        1.01010101,  1.01010101,  1.01010101,  1.01010101,  1.01010101,
        1.01010101,  1.01010101,  1.01010101,  1.01010101,  1.01010101,
        1.01010101,  1.01010101,  1.01010101,  1.01010101,  1.01010101,
        1.01010101,  1.01010101,  1.01010101,  1.01010101,  1.01010101,
        1.01010101,  1.01010101,  1.01010101,  1.01010101,  1.01010101,
        1.01010101,  1.01010101,  1.01010101,  1.01010101,  1.01010101,
        1.01010101,  1.01010101,  1.01010101,  1.01010101,  1.01010101,
        1.01010101,  1.01010101,  1.01010101,  1.01010101,  1.01010101,
        1.01010101,  1.01010101,  1.01010101,  1.01010101,  1.01010101,
        1.01010101,  1.01010101,  1.01010101,  1.01010101,  1.01010101,
        1.01010101,  1.01010101,  1.01010101,  1.01010101,  1.01010101,
        1.01010101,  1.01010101,  1.01010101,  1.01010101,  1.01010101,
        1.01010101,  1.01010101,  1.01010101,  1.01010101,  1.01010101,
        1.01010101,  1.01010101,  1.01010101,  1.01010101,  1.01010101,
        1.01010101,  1.01010101,  1.01010101,  1.01010101,  1.01010101,
        1.01010101,  1.01010101,  1.01010101,  1.01010101,  1.01010101,
        1.01010101,  1.01010101,  1.01010101,  1.01010101,  1.01010101,
        1.01010101,  1.01010101,  1.01010101,  1.01010101,  1.01010101,
        1.01010101,  1.01010101,  1.01010101,  1.01010101])

In [23]:
from SimPEG import Mesh
from scipy import interpolate

In [24]:
hx = np.ones(110)*1.
hz = np.ones(40)*0.5
mesh2D = Mesh.TensorMesh([hx,hz], x0 = '0N')

In [25]:
len(range(90,900,4))


Out[25]:
203

In [26]:
# fnamesfinal = []
# for ind in timeind:
#     fnamesfinal.append(fnamesactive[ind])

In [27]:
timeind = range(0,1200,4)
hy = np.ones(len(timeind))
mesh = Mesh.TensorMesh([hx,hy,hz], x0 = '00N')
itime_ref = 790
DATA_ref = DATA[:,itime_ref]
print "reference data", fnamesactive[itime_ref]
# model = np.zeros((mesh2D.nC,len(timeind)))
# model_ratio = model.copy()
MODEL = np.zeros((mesh.nCx, mesh.nCy, mesh.nCz))
MODEL_ratio = np.zeros((mesh.nCx, mesh.nCy, mesh.nCz))
for i, itime in enumerate(timeind) :
    print itime
    F = interpolate.LinearNDInterpolator(np.c_[mid, dz], DATA[:,itime])
    F_ratio = interpolate.LinearNDInterpolator(np.c_[mid, dz], (DATA[:,itime]-DATA_ref)/abs(DATA_ref))
    MODEL[:,i,:] = F(mesh2D.gridCC).reshape((mesh.nCx, mesh.nCz), order="F")
    MODEL_ratio[:,i,:] = F_ratio(mesh2D.gridCC).reshape((mesh.nCx, mesh.nCz), order="F")


reference data 20150819180000.apr
0
4
8
12
16
20
24
28
32
36
40
44
48
52
56
60
64
68
72
76
80
84
88
92
96
100
104
108
112
116
120
124
128
132
136
140
144
148
152
156
160
164
168
172
176
180
184
188
192
196
200
204
208
212
216
220
224
228
232
236
240
244
248
252
256
260
264
268
272
276
280
284
288
292
296
300
304
308
312
316
320
324
328
332
336
340
344
348
352
356
360
364
368
372
376
380
384
388
392
396
400
404
408
412
416
420
424
428
432
436
440
444
448
452
456
460
464
468
472
476
480
484
488
492
496
500
504
508
512
516
520
524
528
532
536
540
544
548
552
556
560
564
568
572
576
580
584
588
592
596
600
604
608
612
616
620
624
628
632
636
640
644
648
652
656
660
664
668
672
676
680
684
688
692
696
700
704
708
712
716
720
724
728
732
736
740
744
748
752
756
760
764
768
772
776
780
784
788
792
796
800
804
808
812
816
820
824
828
832
836
840
844
848
852
856
860
864
868
872
876
880
884
888
892
896
900
904
908
912
916
920
924
928
932
936
940
944
948
952
956
960
964
968
972
976
980
984
988
992
996
1000
1004
1008
1012
1016
1020
1024
1028
1032
1036
1040
1044
1048
1052
1056
1060
1064
1068
1072
1076
1080
1084
1088
1092
1096
1100
1104
1108
1112
1116
1120
1124
1128
1132
1136
1140
1144
1148
1152
1156
1160
1164
1168
1172
1176
1180
1184
1188
1192
1196

In [28]:
MODEL.shape


Out[28]:
(110, 300, 40)

In [29]:
from SimPEG import Utils

In [30]:
Model = Utils.mkvc(MODEL[:,:,:])
Model_ratio = Utils.mkvc(MODEL_ratio[:,:,:])

In [31]:
Model[np.isnan(Model)] = -100
Model_ratio[np.isnan(Model_ratio)] = -100

In [36]:
Model


Out[36]:
array([-100., -100., -100., ..., -100., -100., -100.])

In [32]:
# mesh.writeModelUBC("/Users/sgkang/Dropbox/dammodel.txt", Model)
# mesh.writeModelUBC("/Users/sgkang/Dropbox/dammodel_ratio.txt", Model_ratio)
# mesh.writeUBC("/Users/sgkang/Dropbox/dammodel_mesh.txt")
# # mesh.writeModelUBC("dammodel.txt", Model)
# # mesh.writeModelUBC("dammodel_ratio.txt", Model_ratio)
# # mesh.writeUBC("dammodel_mesh.txt")

In [33]:
mesh.writeVTK("dammodel", models={"data":Model, "data_ratio":Model_ratio})

In [35]:
# iloc = 0
# fnamesfinal[iloc]

In [ ]:
plot(Model)

In [ ]:


In [ ]:
mesh.plotSlice(Model, clim=(50., 200.))

In [ ]:


In [ ]:
dzu = np.unique(dz)

In [ ]:
def profile_time(i_n, color):
    figsize(6,3)
    ind = np.argwhere(dz == dzu[::-1][i_n])
    nskip = 5
    for i in range(0,ind.size,nskip):
        plt.semilogy(DATA[ind.flatten()[i],:], color)
        plt.tight_layout()
    plt.ylim(50, 200)

In [ ]:
colors = ['k', 'b', 'r', 'g']
inds = [0, 2, 4, 6]
for i, ind in enumerate(inds):
    profile_time(ind,colors[i])

In [ ]:
profile_time(0, 'k')

In [ ]:
profile_time(2, 'k')

In [ ]:
profile_time(3, 'k')

In [ ]:
profile_time(4, 'k')

In [ ]:
profile_time(5, 'k')

In [ ]:
profile_time(6, 'k')

In [ ]:
profile_time(7, 'k')

In [ ]:


In [ ]: