from __future__ import print_function
%matplotlib inline
import matplotlib.pyplot as plt
#plt.style.use("bmh")
# figure size
plt.rcParams['figure.figsize'] = 15,15
# font size
SMALL_SIZE = 22
MEDIUM_SIZE = 24
BIGGER_SIZE = 32
#SMALL_SIZE = 32
#MEDIUM_SIZE = 32
#BIGGER_SIZE = 36
plt.rc('font', size=SMALL_SIZE) # controls default text sizes
plt.rc('axes', titlesize=SMALL_SIZE) # fontsize of the axes title
plt.rc('axes', labelsize=MEDIUM_SIZE) # fontsize of the x and y labels
plt.rc('xtick', labelsize=SMALL_SIZE) # fontsize of the tick labels
plt.rc('ytick', labelsize=SMALL_SIZE) # fontsize of the tick labels
plt.rc('legend', fontsize=SMALL_SIZE) # legend fontsize
plt.rc('figure', titlesize=BIGGER_SIZE) # fontsize of the figure title
from obspy import read, read_inventory
from obspy import UTCDateTime
from obspy.clients.fdsn import Client
from obspy.signal import PPSD
from obspy.imaging.cm import pqlx
# data from NCEDC
client = Client("NCEDC")
# BKS BHZ data
sta = "BKS"
com = "BHZ"
net = "BK"
start_day = "2020-03-01"
end_day = "2020-03-02"
starttime = UTCDateTime(start_day)
endtime = UTCDateTime(end_day)
# png (plot) file
png_name = net+"."+sta+"."+com+"."+start_day+"."+end_day+".png"
print(png_name)
# get response file
inv = client.get_stations(network=net, station=sta,
starttime=starttime,
endtime=endtime, level="response")
# download waveform
st = client.get_waveforms(net, sta, "*", com,
starttime, endtime)
print(st)
# check waveform
st.plot()
ppsd_length = 7200 # 2h
# first segment only. if data have gaps, only first segment is stored
tr = st[0]
# psd estimate
min_db = -200
max_db = -50
ddb = 1 # 1 db increment
ppsd = PPSD(stats=tr.stats, metadata=inv, db_bins=(min_db, max_db, ddb), ppsd_length=ppsd_length)
ppsd.add(tr)
period_low = 0.05 # 0.05 sec
period_max = 1000 # 1000 sec
# plot
ppsd.plot(cmap=pqlx, period_lim=(period_low, period_max), show_mean = True, )
# save png file
ppsd.plot(png_name, cmap=pqlx, period_lim=(period_low, period_max), show_mean = True, )