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: builtins.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) >>> print(ppsd.times_processed) [UTCDateTime(...), UTCDateTime(...), ..., UTCDateTime(...)] >>> ppsd.plot()
... 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")
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")
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_SIMPLE_TYPE_MAP dict() -> new empty dictionary NPZ_SIMPLE_TYPE_MAP_R dict() -> new empty dictionary NPZ_STORE_KEYS list() -> new empty list NPZ_STORE_KEYS_ARRAY_TYPES list() -> new empty list NPZ_STORE_KEYS_LIST_TYPES list() -> new empty list NPZ_STORE_KEYS_SIMPLE_TYPES list() -> new empty list NPZ_STORE_KEYS_VERSION_NUMBERS list() -> new empty list __dict__ __doc__ str(object=’‘) -> str __module__ str(object=’‘) -> str __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_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 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- 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 _PPSD__insert_data_times Gets gap information of stream and adds the encountered gaps to the gap _PPSD__insert_gap_times Gets gap information of stream and adds the encountered gaps to the gap _PPSD__insert_processed_data Inserts the given UTCDateTime and processed/octave-binned spectrum at _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 _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)() _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 __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().