In [1]:
%matplotlib inline
In [2]:
import pandas as pd
from math import pi

from bokeh.models import ColumnDataSource
from bokeh.models import HoverTool
from bokeh.plotting import figure,  output_file, show

from bokeh.models import LinearAxis, Range1d
from bokeh.layouts import gridplot

from scipy.signal import detrend
In [3]:
print("# pandas version = ",pd.__version__)
# pandas version =  0.24.2
In [4]:
import bokeh as bk
print("# bokeh version = ",bk.__version__)
# bokeh version =  1.4.0
In [5]:
import scipy as sp
print("# scipy version = ",sp.__version__)
# scipy version =  1.3.0
In [6]:
# ftp directory
donet_dir = "http://ncedc.org/ftp/outgoing/taira/DONET"
In [7]:
# sts1v data
kis_sts1v_fi = donet_dir + "/kis_sts1v_0.00001-0.01hz.300sps.acc.ts.wh.out"
In [8]:
print(kis_sts1v_fi)
http://ncedc.org/ftp/outgoing/taira/DONET/kis_sts1v_0.00001-0.01hz.300sps.acc.ts.wh.out
In [9]:
# pfo volumetric strain data. assuming poisson's ratio = 0.25
kis_evolume_fi = donet_dir + "/ez_volume_nu0.25_.ts.wh.out"
In [10]:
print(kis_evolume_fi)
http://ncedc.org/ftp/outgoing/taira/DONET/ez_volume_nu0.25_.ts.wh.out
In [11]:
# pfo gravitatity data
kis_grav_fi = donet_dir + "/KIS.grav.out.ts.wh.out"
In [ ]:
 
In [12]:
# read file
# format
# time           acc (nano m/s*2)          
#2009-7-14T0:0:00 -53298
kis_sts1v =pd.read_csv(kis_sts1v_fi,
                          sep=" ",names=["time", "acc_nano"],
                          header=None, skiprows=1)
#print(hhz_psd_ts)
In [13]:
# convert "time" to datetime. need for plot
kis_sts1v['time'] = pd.to_datetime(kis_sts1v['time'])
In [14]:
len(kis_sts1v)
Out[14]:
105408
In [15]:
# check
kis_sts1v.head()
Out[15]:
time acc_nano
0 2016-01-01 00:00:00 -2549
1 2016-01-01 00:05:00 -2512
2 2016-01-01 00:10:00 -2475
3 2016-01-01 00:15:00 -2439
4 2016-01-01 00:20:00 -2402
In [16]:
# check
kis_sts1v.tail()
Out[16]:
time acc_nano
105403 2016-12-31 23:35:00 -2814
105404 2016-12-31 23:40:00 -3143
105405 2016-12-31 23:45:00 -3484
105406 2016-12-31 23:50:00 -3837
105407 2016-12-31 23:55:00 -4204
In [17]:
# PFO strain data
# time vol ez0 (az=0deg) ez90 (az=90deg)
kis_evolume =pd.read_csv(kis_evolume_fi,
                          sep=",",names=["time", "vol","ez0","ez90"],
                          header=None, skiprows=1)
In [18]:
len(kis_evolume)
Out[18]:
105408
In [19]:
kis_evolume.head()
Out[19]:
time vol ez0 ez90
0 2016-01-01T00:00:00.0000 -9.939358 -8.64875 -6.26028
1 2016-01-01T00:05:00.0000 -10.260012 -8.93439 -6.45562
2 2016-01-01T00:10:00.0000 -10.565132 -9.20508 -6.64261
3 2016-01-01T00:15:00.0000 -10.856425 -9.46217 -6.82246
4 2016-01-01T00:20:00.0000 -11.133279 -9.70481 -6.99510
In [20]:
# time format conversion
kis_evolume['time'] = pd.to_datetime(kis_evolume['time'])
In [21]:
# PFO gravity data
# time                    gravity microgal, positive for decreasing    
# microgal = microgal2. same data
kis_grav =pd.read_csv(kis_grav_fi,
                          sep=" ",names=["time", "microgal", "microgal2"],
                          header=None, skiprows=1)
In [22]:
len(kis_grav)
Out[22]:
105408
In [23]:
# microgal2 is Nan.... Not sure why but microgal2 is not used
kis_grav.head()
Out[23]:
time microgal microgal2
0 2016-01-01T00:00:00.0000 -47.47725 -47.47725
1 2016-01-01T00:05:00.0000 -48.98182 -48.98182
2 2016-01-01T00:10:00.0000 -50.41110 -50.41110
3 2016-01-01T00:15:00.0000 -51.77316 -51.77316
4 2016-01-01T00:20:00.0000 -53.06521 -53.06521
In [24]:
# time format conversion
kis_grav['time'] = pd.to_datetime(kis_grav['time'])
In [25]:
# check
kis_grav['time'].head()
Out[25]:
0   2016-01-01 00:00:00
1   2016-01-01 00:05:00
2   2016-01-01 00:10:00
3   2016-01-01 00:15:00
4   2016-01-01 00:20:00
Name: time, dtype: datetime64[ns]
In [26]:
# trim data
#kis_grav_select = kis_grav[("2016-01-01 00:00:00" <= kis_grav['time'])  &   (kis_grav['time'] <= "2016-04-01 00:00:00")]
kis_grav_select = kis_grav
In [27]:
# check
kis_grav_select.head()
Out[27]:
time microgal microgal2
0 2016-01-01 00:00:00 -47.47725 -47.47725
1 2016-01-01 00:05:00 -48.98182 -48.98182
2 2016-01-01 00:10:00 -50.41110 -50.41110
3 2016-01-01 00:15:00 -51.77316 -51.77316
4 2016-01-01 00:20:00 -53.06521 -53.06521
In [28]:
# trim daat
#kis_evolume_select = kis_evolume[   ("2016-01-01 00:00:00" <= kis_evolume['time'])  &   
#                                 (kis_evolume['time'] <= "2016-04-01 00:00:00")   ]
kis_evolume_select=kis_evolume
In [29]:
# check
kis_evolume_select.head()
Out[29]:
time vol ez0 ez90
0 2016-01-01 00:00:00 -9.939358 -8.64875 -6.26028
1 2016-01-01 00:05:00 -10.260012 -8.93439 -6.45562
2 2016-01-01 00:10:00 -10.565132 -9.20508 -6.64261
3 2016-01-01 00:15:00 -10.856425 -9.46217 -6.82246
4 2016-01-01 00:20:00 -11.133279 -9.70481 -6.99510
In [30]:
# dataframe to numpy matrix
evolume_matrix = kis_evolume_select.as_matrix()
/anaconda3/envs/netops/lib/python3.7/site-packages/ipykernel_launcher.py:2: FutureWarning: Method .as_matrix will be removed in a future version. Use .values instead.
  
In [31]:
# check to see evol
evolume_matrix[:,1] # 0 time, 1 evol # 2 ez0 #3 ez90
Out[31]:
array([-9.939358, -10.260012, -10.565132, ..., -18.260982000000002,
       -18.134729, -17.982049], dtype=object)
In [32]:
len(evolume_matrix)
Out[32]:
105408
In [33]:
len(kis_sts1v)
Out[33]:
105408
In [34]:
len(kis_evolume_select)
Out[34]:
105408
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [35]:
# now add evol data as pfo_sts1v['vol']
kis_sts1v['vol'] =evolume_matrix[:,1] 
In [36]:
# check
kis_sts1v['vol'].head()
Out[36]:
0   -9.93936
1     -10.26
2   -10.5651
3   -10.8564
4   -11.1333
Name: vol, dtype: object
In [37]:
# check
kis_sts1v['time'].head()
Out[37]:
0   2016-01-01 00:00:00
1   2016-01-01 00:05:00
2   2016-01-01 00:10:00
3   2016-01-01 00:15:00
4   2016-01-01 00:20:00
Name: time, dtype: datetime64[ns]
In [38]:
# dataframe to numpy matrix
grav_matrix = kis_grav_select.as_matrix()
/anaconda3/envs/netops/lib/python3.7/site-packages/ipykernel_launcher.py:2: FutureWarning: Method .as_matrix will be removed in a future version. Use .values instead.
  
In [39]:
# check 
grav_matrix[:,1] # microgal
Out[39]:
array([-47.47725, -48.98182, -50.4111, ..., -85.86583, -85.31617,
       -84.64220999999999], dtype=object)
In [40]:
# now add microgal data as pfo_sts1v['microgal']
kis_sts1v['microgal'] = grav_matrix[:,1]
In [41]:
# check
kis_sts1v['microgal'].head()
Out[41]:
0   -47.4772
1   -48.9818
2   -50.4111
3   -51.7732
4   -53.0652
Name: microgal, dtype: object
In [ ]:
 
In [ ]:
 
In [42]:
#TOOLS = "pan,wheel_zoom,box_zoom,undo,reset,save"
TOOLS = "pan,box_zoom,undo,reset,save"

#data = {'x_values': [1, 2, 3, 4, 5],
#        'y_values': [6, 7, 2, 3, 6]}
 
# make "data". all parameters need to be added
 
data =  {
                'time': kis_sts1v['time'], 
               'acc_mili': kis_sts1v['acc_nano']/1000/1000, 
               'microgal': kis_sts1v['microgal'], 
                'vol': kis_sts1v['vol'], 

          #'time': kis_evolume['time'], 
}

# make source. needed
source = ColumnDataSource(data=data)


# x_axis is datetime. add tools. define size and add title
#p = figure(x_axis_type="datetime", tools=TOOLS, plot_width=600, height=600, title = "kis")
p = figure(x_axis_type="datetime", tools=TOOLS, plot_width=1200, height=600, title = "KIS")

# labels
p.xaxis.axis_label = 'Time (UTC)'
p.yaxis.axis_label = 'Acceleration (mm/s*2) '

# label orientation
p.xaxis.major_label_orientation = pi/4
# grid line
p.grid.grid_line_alpha=1.0

# define Y-range 
bottom, top = -5, 5
p.y_range=Range1d(bottom, top)

# plot STS1-v data
p.line(x='time', y='acc_mili', source=source,legend="STS1v")

# another Y-axis (right side)
p.extra_y_ranges = {"y2": Range1d(start=-160, end=60)}
# another Y-axis label
p.add_layout(LinearAxis(y_range_name="y2", axis_label='Nanostrain (positive extension)'), 'right')
# plot volumetric strain data with y2 axis
p.line(x='time', y='vol', y_range_name="y2", source=source,legend="Volumetric strain",line_color="black")


# font and etc
p.title.text_font="calibri"
p.title.text_font_size="20pt"
p.title.align="center"

p.xaxis.axis_label_text_font_size = "16pt"
p.xaxis.axis_label_text_font="calibri"
p.xaxis.major_label_text_font_size = "14pt"
p.xaxis.major_label_text_font="calibri"

p.yaxis.axis_label_text_font_size = "16pt"
p.yaxis.axis_label_text_font="calibri"
p.yaxis.major_label_text_font_size = "14pt"
p.yaxis.major_label_text_font="calibri"

p.xaxis.axis_label_text_font_style = 'normal'
p.yaxis.axis_label_text_font_style = 'normal'

p.xaxis[0].formatter.days = '%m/%d/%Y'


# save .html file
output_file("kis_ts.html", title="KIS")
# if you want to plot only "p"
#show(p)  # open a browser

# two figure with "vertical"
#grid = gridplot([[p], [p2]])
# two figure with "horizontal"
#grid = gridplot([[p,p2]])
grid = gridplot([[p]])

# will open a browser
show(grid)
BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead
BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]: