# + from obspy.signal import PPSD ppsd = PPSD.load_npz("data/PPSD_FUR_HHN.npz") # - ppsd.plot(max_percentage=10) ppsd.plot(cumulative=True) # * do different stacks of the data using the [`calculate_histogram()` (see docs!)](http://docs.obspy.org/packages/autogen/obspy.signal.spectral_estimation.PPSD.calculate_histogram.html) method of `PPSD` and visualize them # * compare differences in different frequency bands qualitatively (anthropogenic vs. "natural" noise).. # * nighttime stack, daytime stack # * advanced exercise: Use the `callback` option and use some crazy custom callback function in `calculate_histogram()`, e.g. stack together all data from birthdays in your family.. or all German holidays + Sundays in the time span.. or from dates of some bands' concerts on a tour.. etc. ppsd.calculate_histogram(time_of_weekday=[(-1, 0, 2), (-1, 22, 24)]) ppsd.plot(max_percentage=10) ppsd.calculate_histogram(time_of_weekday=[(-1, 8, 16)]) ppsd.plot(max_percentage=10) # * do different stacks of the data using the [`calculate_histogram()` (see docs!)](http://docs.obspy.org/packages/autogen/obspy.signal.spectral_estimation.PPSD.calculate_histogram.html) method of `PPSD` and visualize them # * compare differences in different frequency bands qualitatively (anthropogenic vs. "natural" noise).. # * weekdays stack, weekend stack ppsd.calculate_histogram(time_of_weekday=[ (1, 0, 24), (2, 0, 24), (3, 0, 24), (4, 0, 24), (5, 0, 24), ])
def get_ppsd(my_storage, client, inv, ppsd_restrictions, single_cha_contents, starttime, endtime, plot_trace=False): """ Calculates the ppsd object according to starttime, endtime and ppsd_restrictions parameters. It will be save in my_storage/{network}.{station}.{location}.{channel}/ppsd Parameters: ----------- my_storage: str Path to save all ppsd analyses client: Client object from obspy To use get_waveforms method inv: Inventory object from obspy To recognize the filtered stations that you want to calculate the ppsd ppsd_restrictions: PPSDRestrictions Information about the PPSD parameters single_cha_contents: 'str' network.station.location.channel starttime: UTCDateTime Start time that will be used to calculate the ppsd. endtime: UTCDateTime End time that will be used to calculate the ppsd. plot_trace: Boolean Plot the stream (It consumes a little bit time) """ network, station, location, channel = single_cha_contents.split('.') try: st = client.get_waveforms(network=network, station=station, location=location, channel=channel, starttime=starttime, endtime=endtime) except: strftime = "%Y%m%dT%H%M%SZ" st_warn = (f"{network}." f"{station}." f"{location}." f"{channel}" f"__{starttime.strftime(strftime)}" f"__{endtime.strftime(strftime)}") st = None now = dt.datetime.now().strftime("%Y/%m/%d %H:%M:%S") if st == None: print_logs(job='load_trace', content=single_cha_contents, status='no', path=st_warn) return None if plot_trace == True: plotst_path = get_path(my_storage, PLOT_TRACE_DIRNAME, single_cha_contents, starttime, endtime, extension_file='jpg') filename = os.path.basename(plotst_path) if os.path.isfile(plotst_path) == True: print_logs(job='save_trace', content=single_cha_contents, status='exist', path=filename) else: plotst_dir = os.path.dirname(plotst_path) if os.path.isdir(plotst_dir) == False: os.makedirs(plotst_dir) st.plot(outfile=plotst_path) print_logs(job='save_trace', content=single_cha_contents, status='ok', path=filename) now = dt.datetime.now().strftime("%Y/%m/%d %H:%M:%S") try: ppsd_path = get_path(my_storage, PPSD_DIRNAME, single_cha_contents, starttime, endtime, extension_file='npz') filename = os.path.basename(ppsd_path) if os.path.isfile(ppsd_path) == True: print_logs(job='save_ppsd', content=single_cha_contents, status='exist', path=filename) else: ppsd_dir = os.path.dirname(ppsd_path) if os.path.isdir(ppsd_dir) == False: os.makedirs(ppsd_dir) tr = st[0] ppsd = PPSD(tr.stats, metadata=inv, **ppsd_restrictions.__dict__) ppsd.add(st) if ppsd_restrictions.time_of_weekday != None: ppsd.calculate_histogram( time_of_weekday=ppsd_restrictions.time_of_weekday) ppsd.save_npz(ppsd_path) print_logs(job='save_ppsd', content=single_cha_contents, status='ok', path=filename) except: print_logs(job='save_ppsd', content=single_cha_contents, status='exist', path=filename)
from obspy.signal import PPSD from obspy.core.utcdatetime import UTCDateTime from obspy.clients.fdsn import Client from obspy.imaging.cm import pqlx client = Client("IRIS") st = client.get_waveforms(network="IU", station="ANMO", location="00", channel="LHZ", starttime=UTCDateTime("2010-03-25T06:00:00.000"), endtime=UTCDateTime("2010-03-29T14:00:00.000")) print(st) inv = client.get_stations(network="IU", station="ANMO", location="00", channel="LHZ", starttime=UTCDateTime("2010-03-25T06:00:00.000"), endtime=UTCDateTime("2010-03-29T14:00:00.000"), level="response") tr = st[0] ppsd = PPSD(tr.stats, inv, time_of_weekday=[(-1, 0, 2), (-1, 22, 24)]) ppsd.add(st) ppsd.calculate_histogram(time_of_weekday=[(-1, 0, 2), (-1, 22, 24)]) # print("acabe") # ppsd.plot() # print(ppsd.times_processed) ppsd.plot("prove.jpg", cmap=pqlx) # ppsd = PPSD.load_npz("/home/ecastillo/SANL_results/CM.BAR2.10.HNZ/MassPPSD/CM.BAR2.10.HNZ__20190101T000000Z__20190104T000000Z.npz") # ppsd.plot("prove.jpg",cmap=pqlx)