obspy.signal.spectral_estimation.PPSD

class PPSD(stats, metadata, skip_on_gaps=False, db_bins=(-200, -50, 1.0), ppsd_length=3600.0, overlap=0.5, special_handling=None, period_smoothing_width_octaves=1.0, period_step_octaves=0.125, period_limits=None, **kwargs)[source]

Bases: object

Class to compile probabilistic power spectral densities for one combination of network/station/location/channel/sampling_rate.

Calculations are based on the routine used by [McNamara2004]. For information on New High/Low Noise Model see [Peterson1993].

Basic Usage

>>> from obspy import read
>>> from obspy.signal import PPSD
>>> st = read()
>>> tr = st.select(channel="EHZ")[0]
>>> paz = {'gain': 60077000.0,
...        'poles': [-0.037004+0.037016j, -0.037004-0.037016j,
...                  -251.33+0j, -131.04-467.29j, -131.04+467.29j],
...        'sensitivity': 2516778400.0,
...        'zeros': [0j, 0j]}
>>> ppsd = PPSD(tr.stats, paz)
>>> print(ppsd.id)
BW.RJOB..EHZ
>>> print(ppsd.times_processed)
[]

Now we could add data to the probabilistic psd (all processing like demeaning, tapering and so on is done internally) and plot it like …

>>> ppsd.add(st) # doctest: +SKIP
>>> print(ppsd.times) # doctest: +SKIP
>>> ppsd.plot() # doctest: +SKIP

… but the example stream is too short and does not contain enough data.

Note

For a real world example see the ObsPy Tutorial.

Saving and Loading

The PPSD object supports saving to a numpy npz compressed binary file:

>>> ppsd.save_npz("myfile.npz") # doctest: +SKIP

The saved PPSD can then be loaded again using the static method load_npz(), e.g. to plot the results again. If additional data is to be processed (note that another option is to combine multiple npz files using add_npz()), metadata must be provided again, since they are not stored in the numpy npz file:

>>> ppsd = PPSD.load_npz("myfile.npz")  # doctest: +SKIP

Note

When using metadata from an Inventory, a Parser instance or from a RESP file, information on metadata will be correctly picked for the respective starttime of the data trace. This means that instrument changes are correctly taken into account during response removal. This is obviously not the case for a static PAZ dictionary!

Attributes

NPZ_STORE_KEYS

NPZ_STORE_KEYS_ARRAY_TYPES

NPZ_STORE_KEYS_LIST_TYPES

NPZ_STORE_KEYS_SIMPLE_TYPES

NPZ_STORE_KEYS_VERSION_NUMBERS

__dict__

__doc__

__module__

__weakref__

list of weak references to the object (if defined)

channel

current_histogram

current_histogram_count

current_histogram_cumulative

current_times_used

db_bin_centers

db_bin_edges

delta

len

Trace length for one psd segment.

location

merge_method

network

nfft

nlap

period_bin_centers

Return centers of period bins (geometric mean of left and right edge of period smoothing ranges).

period_bin_left_edges

Returns left edges of period bins (same length as number of bins).

period_bin_right_edges

Returns right edges of period bins (same length as number of bins).

period_xedges

Returns edges of period histogram bins (one element longer than number of bins).

psd_frequencies

psd_periods

psd_values

Returns all individual smoothed psd arrays as a list.

station

step

Time step between start times of adjacent psd segments in seconds (assuming gap-less data).

times_data

times_gaps

times_processed

Public Methods

add

Process all traces with compatible information and add their spectral estimates to the histogram containing the probabilistic psd.

add_npz

Add previously computed PPSD results to current PPSD instance.

calculate_histogram

Calculate and set current 2D histogram stack, optionally with start- and endtime and time of day restrictions.

extract_psd_values

Extract PSD values for given period in seconds.

get_mean

Returns periods and mean psd values (i.e.

get_mode

Returns periods and mode psd values (i.e.

get_percentile

Returns periods and approximate psd values for given percentile value.

load_npz

Load previously computed PPSD results.

plot

Plot the 2D histogram of the current PPSD.

plot_coverage

Plot the data coverage of the histogram of the current PPSD.

plot_spectrogram

Plot the temporal evolution of the PSD in a spectrogram-like plot.

plot_temporal

Plot the evolution of PSD value of one (or more) period bins over time.

save_npz

Saves the PPSD as a compressed numpy binary (npz format).

Private Methods

Warning

Private methods are mainly for internal/developer use and their API might change without notice.

_PPSD__check_histogram

_PPSD__check_time_present

Checks if the given UTCDateTime is already part of the current PPSD instance.

_PPSD__insert_data_times

Gets gap information of stream and adds the encountered gaps to the gap list of the PPSD instance.

_PPSD__insert_gap_times

Gets gap information of stream and adds the encountered gaps to the gap list of the PPSD instance.

_PPSD__insert_processed_data

Inserts the given UTCDateTime and processed/octave-binned spectrum at the right position in the lists, keeping the order intact.

_PPSD__invalidate_histogram

_PPSD__plot_coverage

Helper function to plot coverage into given axes.

_PPSD__process

Processes a segment of data and save the psd information.

_PPSD__sanity_check

Checks if trace is compatible for use in the current PPSD instance.

_add_npz

See PPSD.add_npz().

_get_gapless_psd

Helper routine to get a list of 2-tuples with gapless portions of processed PPSD time ranges.

_get_plot_title

_get_response

_get_response_from_inventory

_get_response_from_parser

_get_response_from_paz_dict

_get_response_from_resp

_get_times_all_details

_plot_histogram

Reuse a previously created figure returned by plot(show=False)() and plot the current histogram stack (pre-computed using calculate_histogram()) into the figure.

_setup_period_binning

Set up period binning.

_split_lists

_stack_selection

For details on restrictions see calculate_histogram().

Special Methods

__dir__

Default dir() implementation.

__format__

Default object formatter.

__init__

Initialize the PPSD object setting all fixed information on the station that should not change afterwards to guarantee consistent spectral estimates.

__init_subclass__

This method is called when a class is subclassed.

__new__

Create and return a new object.

__reduce__

Helper for pickle.

__reduce_ex__

Helper for pickle.

__sizeof__

Size of object in memory, in bytes.

__subclasshook__

Abstract classes can override this to customize issubclass().