sprit.sprit_hvsr module¶
This module is the main SpRIT module that contains all the functions needed to run HVSR analysis.
The functions defined here are read both by the SpRIT graphical user interface and by the command-line interface to run HVSR analysis on input data.
See documentation for individual functions for more information.
- class sprit.sprit_hvsr.HVSRBatch(*args, **kwargs)[source]¶
Bases:
object
HVSRBatch is the data container used for batch processing. It contains several HVSRData objects (one for each site). These can be accessed using their site name, either square brackets (HVSRBatchVariable[“SiteName”]) or the dot (HVSRBatchVariable.SiteName) accessor.
The dot accessor may not work if there is a space in the site name.
All of the functions in the sprit package are designed to perform the bulk of their operations iteratively on the individual HVSRData objects contained in the HVSRBatch object, and do little with the HVSRBatch object itself, besides using it determine which sites are contained within it.
Methods
copy
([type])Make a copy of the HVSRBatch object.
export
([hvsr_export_path, ext])Method to export HVSRData objects in HVSRBatch container to indivdual .hvsr pickle files.
export_settings
([site_name, ...])Method to export settings from HVSRData object in HVSRBatch object.
get_report
(**kwargs)Method to get report from processed data, in print, graphical, or tabular format.
items
()Method to return both the site names and the HVSRData object as a set of dict_items tuples.
keys
()Method to return the "keys" of the HVSRBatch object.
plot
(**kwargs)Method to plot data, based on the sprit.plot_hvsr() function.
report
(**kwargs)Wrapper of get_report()
- copy(type='shallow')[source]¶
Make a copy of the HVSRBatch object. Uses python copy module.
- Parameters:
- typestr {‘shallow’, ‘deep’}
Based on input, creates either a shallow or deep copy of the HVSRBatch object. Shallow is equivalent of copy.copy(). Input of ‘deep’ is equivalent of copy.deepcopy() (still experimental). Defaults to shallow.
- export(hvsr_export_path=True, ext='hvsr')[source]¶
Method to export HVSRData objects in HVSRBatch container to indivdual .hvsr pickle files.
- Parameters:
- hvsr_export_pathfilepath, default=True
Filepath to save file. Can be either directory (which will assign a filename based on the HVSRData attributes). By default True. If True, it will first try to save each file to the same directory as input_data, then if that does not work, to the current working directory, then to the user’s home directory, by default True
- extstr, optional
The extension to use for the output, by default ‘hvsr’. This is still a pickle file that can be read with pickle.load(), but will have .hvsr extension.
- export_settings(site_name=None, export_settings_path='default', export_settings_type='all', include_location=False, verbose=True)[source]¶
Method to export settings from HVSRData object in HVSRBatch object.
Simply calls sprit.export_settings() from specified HVSRData object in the HVSRBatch object. See sprit.export_settings() for more details.
- Parameters:
- site_namestr, default=None
The name of the site whose settings should be exported. If None, will default to the first site, by default None.
- export_settings_pathstr, optional
Filepath to output file. If left as ‘default’, will save as the default value in the resources directory. If that is not possible, will save to home directory, by default ‘default’
- export_settings_typestr, {‘all’, ‘instrument’, ‘processing’}, optional
They type of settings to save, by default ‘all’
- include_locationbool, optional
Whether to include the location information in the instrument settings, if that settings type is selected, by default False
- verbosebool, optional
Whether to print output (filepath and settings) to terminal, by default True
See also
- get_report(**kwargs)[source]¶
Method to get report from processed data, in print, graphical, or tabular format.
- Returns:
- Variable
May return nothing, pandas.Dataframe, or pyplot Figure, depending on input.
See also
- items()[source]¶
Method to return both the site names and the HVSRData object as a set of dict_items tuples. Functions similar to dict.items().
- Returns:
- _type_
_description_
- keys()[source]¶
Method to return the “keys” of the HVSRBatch object. For HVSRBatch objects, these are the site names. Functions similar to dict.keys().
- Returns:
- dict_keys
A dict_keys object listing the site names of each of the HVSRData objects contained in the HVSRBatch object
- plot(**kwargs)[source]¶
Method to plot data, based on the sprit.plot_hvsr() function.
All the same kwargs and default values apply as plot_hvsr(). For return_fig, returns it to the ‘Plot_Report’ attribute of each HVSRData object
- Returns:
- _type_
_description_
See also
- class sprit.sprit_hvsr.HVSRData(*args, **kwargs)[source]¶
Bases:
object
HVSRData is the basic data class of the sprit package. It contains all the processed data, input parameters, and reports.
These attributes and objects can be accessed using square brackets or the dot accessor. For example, to access the site name, HVSRData[‘site’] and HVSRData.site will both return the site name.
Some of the methods that work on the HVSRData object (e.g., .plot() and .get_report()) are essentially wrappers for some of the main sprit package functions (sprit.plot_hvsr() and sprit.get_report(), respectively)
- Attributes:
batch
Whether this HVSRData object is part of an HVSRBatch object.
datastream
A copy of the original obspy datastream read in.
params
Dictionary containing the parameters used to process the data
ppsds
Dictionary copy of the class object obspy.signal.spectral_estimation.PPSD().
ppsds_obspy
The original ppsd information from the obspy.signal.spectral_estimation.PPSD(), so as to keep original if copy is manipulated/changed.
Methods
copy
([type])Make a copy of the HVSRData object.
export
([hvsr_export_path, ext])Method to export HVSRData objects to .hvsr pickle files.
export_settings
([export_settings_path, ...])Method to export settings from HVSRData object.
get_report
(**kwargs)Method to get report from processed data, in print, graphical, or tabular format.
items
()Method to return the "items" of the HVSRData object.
keys
()Method to return the "keys" of the HVSRData object.
plot
(**kwargs)Method to plot data, wrapper of sprit.plot_hvsr()
report
(**kwargs)Wrapper of get_report()
- property batch¶
Whether this HVSRData object is part of an HVSRBatch object. This is used throughout the code to help direct the object into the proper processing pipeline.
- Returns:
- bool
True if HVSRData object is part of HVSRBatch object, otherwise, False
- copy(type='shallow')[source]¶
Make a copy of the HVSRData object. Uses python copy module.
- Parameters:
- typestr {‘shallow’, ‘deep’}
Based on input, creates either a shallow or deep copy of the HVSRData object. Shallow is equivalent of copy.copy(). Input of type=’deep’ is equivalent of copy.deepcopy() (still experimental). Defaults to shallow.
- property datastream¶
A copy of the original obspy datastream read in. This helps to retain the original data even after processing is carried out.
- Returns:
- obspy.core.Stream.stream
Obspy stream
- export(hvsr_export_path=None, ext='hvsr')[source]¶
Method to export HVSRData objects to .hvsr pickle files.
- Parameters:
- hvsr_export_pathfilepath, default=True
Filepath to save file. Can be either directory (which will assign a filename based on the HVSRData attributes). By default True. If True, it will first try to save each file to the same directory as input_data, then if that does not work, to the current working directory, then to the user’s home directory, by default True
- extstr, optional
The extension to use for the output, by default ‘hvsr’. This is still a pickle file that can be read with pickle.load(), but will have .hvsr extension.
- export_settings(export_settings_path='default', export_settings_type='all', include_location=False, verbose=True)[source]¶
Method to export settings from HVSRData object. Simply calls sprit.export_settings() from the HVSRData object. See sprit.export_settings() for more details.
- Parameters:
- export_settings_pathstr, optional
Filepath to output file. If left as ‘default’, will save as the default value in the resources directory. If that is not possible, will save to home directory, by default ‘default’
- export_settings_typestr, {‘all’, ‘instrument’, ‘processing’}, optional
They type of settings to save, by default ‘all’
- include_locationbool, optional
Whether to include the location information in the instrument settings, if that settings type is selected, by default False
- verbosebool, optional
Whether to print output (filepath and settings) to terminal, by default True
- get_report(**kwargs)[source]¶
Method to get report from processed data, in print, graphical, or tabular format.
- Returns:
- Variable
May return nothing, pandas.Dataframe, or pyplot Figure, depending on input.
See also
- items()[source]¶
Method to return the “items” of the HVSRData object. For HVSRData objects, this is a dict_items object with the keys and values in tuples. Functions similar to dict.items().
- Returns:
- dict_items
A dict_items object of the HVSRData objects attributes, parameters, etc.
- keys()[source]¶
Method to return the “keys” of the HVSRData object. For HVSRData objects, these are the attributes and parameters of the object. Functions similar to dict.keys().
- Returns:
- dict_keys
A dict_keys object of the HVSRData objects attributes, parameters, etc.
- property params¶
Dictionary containing the parameters used to process the data
- Returns:
- dict
Dictionary containing the process parameters
- plot(**kwargs)[source]¶
Method to plot data, wrapper of sprit.plot_hvsr()
- Returns:
- matplotlib.Figure, matplotlib.Axis (if return_fig=True)
See also
- property ppsds¶
Dictionary copy of the class object obspy.signal.spectral_estimation.PPSD(). The dictionary copy allows manipulation of the data in PPSD, whereas that data cannot be easily manipulated in the original Obspy object.
- Returns:
- dict
Dictionary copy of the PPSD information from generate_psds()
- property ppsds_obspy¶
The original ppsd information from the obspy.signal.spectral_estimation.PPSD(), so as to keep original if copy is manipulated/changed.
- sprit.sprit_hvsr.batch_data_read(batch_data, batch_type='table', param_col=None, batch_params=None, verbose=False, **readcsv_getMeta_fetch_kwargs)[source]¶
Function to read data in data as a batch of multiple data files. This is best used through sprit.fetch_data(*args, source=’batch’, **other_kwargs).
- Parameters:
- batch_datafilepath or list
Input data information for how to read in data as batch. Can be filepath or list of filepaths/stream objects. If filepath, should point to .csv (or similar that can be read by pandas.read_csv()) with batch data information.
- batch_typestr, optional
Type of batch read, only ‘table’ and ‘filelist’ accepted. If ‘table’, will read data from a file read in using pandas.read_csv(), by default ‘table’
- param_colNone or str, optional
Name of parameter column from batch information file. Only used if a batch_type=’table’ and single parameter column is used, rather than one column per parameter (for single parameter column, parameters are formatted with = between keys/values and , between item pairs), by default None
- batch_paramslist, dict, or None, default = None
Parameters to be used if batch_type=’filelist’. If it is a list, needs to be the same length as batch_data. If it is a dict, will be applied to all files in batch_data and will combined with extra keyword arguments caught by **readcsv_getMeta_fetch_kwargs.
- verbosebool, optional
Whether to print information to terminal during batch read, by default False
- **readcsv_getMeta_fetch_kwargs
Keyword arguments that will be read into pandas.read_csv(), sprit.input_params, sprit.get_metadata(), and/or sprit.fetch_data()
- Returns:
- hvsrBatch
HVSRBatch object with each item representing a different HVSRData object
- Raises:
- IndexError
_description_
- sprit.sprit_hvsr.calculate_azimuth(hvsr_data, azimuth_angle=30, azimuth_type='multiple', azimuth_unit='degrees', show_az_plot=False, verbose=False, **plot_azimuth_kwargs)[source]¶
Function to calculate azimuthal horizontal component at specified angle(s). Adds each new horizontal component as a radial component to obspy.Stream object at hvsr_data[‘stream’]
- Parameters:
- hvsr_dataHVSRData
Input HVSR data
- azimuth_angleint, default=10
If azimuth_type=’multiple’, this is the angular step (in unit azimuth_unit) of each of the azimuthal measurements. If azimuth_type=’single’ this is the angle (in unit azimuth_unit) of the single calculated azimuthal measruement. By default 10.
- azimuth_typestr, default=’multiple’
What type of azimuthal measurement to make, by default ‘multiple’. If ‘multiple’ (or {‘multi’, ‘mult’, ‘m’}), will take a measurement at each angular step of azimuth_angle of unit azimuth_unit. If ‘single’ (or {‘sing’, ‘s’}), will take a single azimuthal measurement at angle specified in azimuth_angle.
- azimuth_unitstr, default=’degrees’
Angular unit used to specify azimuth_angle parameter. By default ‘degrees’. If ‘degrees’ (or {‘deg’, ‘d’}), will use degrees. If ‘radians’ (or {‘rad’, ‘r’}), will use radians.
- show_az_plotbool, default=False
Whether to show azimuthal plot, by default False.
- verbosebool, default=False
Whether to print terminal output, by default False
- Returns:
- HVSRData
Updated HVSRData object specified in hvsr_data with hvsr_data[‘stream’] attribute containing additional components (EHR-*), with * being zero-padded (3 digits) azimuth angle in degrees.
- sprit.sprit_hvsr.check_peaks(hvsr_data, hvsr_band=[0.4, 40], peak_selection='max', peak_freq_range=[0.4, 40], azimuth='HV', verbose=False)[source]¶
Function to run tests on HVSR peaks to find best one and see if it passes quality checks
- Parameters:
- hvsr_datadict
Dictionary containing all the calculated information about the HVSR data (i.e., hvsr_out returned from process_hvsr)
- hvsr_bandtuple or list, default=[0.4, 40]
2-item tuple or list with lower and upper limit of frequencies to analyze
- peak_selectionstr or numeric, default=’max’
How to select the “best” peak used in the analysis. For peak_selection=”max” (default value), the highest peak within peak_freq_range is used. For peak_selection=’scored’, an algorithm is used to select the peak based in part on which peak passes the most SESAME criteria. If a numeric value is used (e.g., int or float), this should be a frequency value to manually select as the peak of interest.
- peak_freq_rangetuple or list, default=[0.4, 40];
The frequency range within which to check for peaks. If there is an HVSR curve with multiple peaks, this allows the full range of data to be processed while limiting peak picks to likely range.
- verbosebool, default=False
Whether to print results and inputs to terminal.
- Returns:
- hvsr_dataHVSRData or HVSRBatch object
Object containing previous input data, plus information about peak tests
- sprit.sprit_hvsr.export_data(hvsr_data, hvsr_export_path=None, ext='hvsr', verbose=False)[source]¶
Export data into pickle format that can be read back in using import_data() so data does not need to be processed each time. Default extension is .hvsr but it is still a pickled file that can be read in using pickle.load().
- Parameters:
- hvsr_dataHVSRData or HVSRBatch
Data to be exported
- hvsr_export_pathstr or filepath object, default = None
String or filepath object to be read by pathlib.Path() and/or a with open(hvsr_export_path, ‘wb’) statement. If None, defaults to input input_data directory, by default None
- extstr, default = ‘hvsr’
Filepath extension to use for data file, by default ‘hvsr’
- sprit.sprit_hvsr.export_report(hvsr_results, report_export_path=None, report_export_format=['pdf'], azimuth='HV', csv_handling='rename', show_report=True, verbose=False)[source]¶
Function to export reports to disk. Exportable formats include: * ‘table’: saves a pandas DataFrame as a csv) * ‘plot’: saves the matplotlib or plotly plot figure (depending on what is designated via plot_engine) as an image (png by default) * ‘print’: saves the print report as a .txt file * ‘html’: saves the html report as a .html file * ‘pdf’: saves the pdf report as a .pdf file
- Parameters:
- hvsr_resultsHVSRData object
HVSRData object containing the HVSR data
- report_export_pathpath-like object, optional
The path to where the report should be exported. If this is None (default), this is written to the home directory. If this is a True, uses the same directory as the input data, but generates a filename. If this is a directory, generates a filename. If filename is specified and the extension does not match the report type, the extension is adjusted. Otherwise, this is the output file or , by default None
- csv_handling{‘rename’, ‘append’, ‘overwrite’, ‘keep’}, optional
If table is the report type, this can prevent overwriting data, by default ‘rename’. * “rename” (or “keep”): renames the new file to prevent overwrite, appends a digit to the end of filename * “append”: appends the new data to the existing file * “overwrite”: overwrites the existing file
- report_export_formatstr or list, optional
The format (or a list of formats) to export the report, by default [‘pdf’].
- show_reportbool, optional
Whether to show the designated reports that were chosen for export, by default True
- verbosebool, optional
Whether to print progress and other information to terminal, by default False
- Returns:
- HVSRData
An HVSRData object that is the same as hvsr_results, but with any additionally generated reports.
- sprit.sprit_hvsr.export_settings(hvsr_data, export_settings_path='default', export_settings_type='all', include_location=False, verbose=True)[source]¶
Save settings to json file
- Parameters:
- export_settings_pathstr, default=”default”
Where to save the json file(s) containing the settings, by default ‘default’. If “default,” will save to sprit package resources. Otherwise, set a filepath location you would like for it to be saved to. If ‘all’ is selected, a directory should be supplied. Otherwise, it will save in the directory of the provided file, if it exists. Otherwise, defaults to the home directory.
- export_settings_typestr, {‘all’, ‘instrument’, ‘processing’}
What kind of settings to save. If ‘all’, saves all possible types in their respective json files. If ‘instrument’, save the instrument settings to their respective file. If ‘processing’, saves the processing settings to their respective file. By default ‘all’
- include_locationbool, default=False, input CRS
Whether to include the location parametersin the exported settings document.This includes xcoord, ycoord, elevation, elev_unit, and input_crs
- verbosebool, default=True
Whether to print outputs and information to the terminal
- sprit.sprit_hvsr.fetch_data(params, source='file', data_export_path=None, data_export_format='mseed', detrend='spline', detrend_options=2, filter_type=None, filter_options={}, update_metadata=True, plot_input_stream=False, plot_engine='matplotlib', show_plot=True, verbose=False, **kwargs)[source]¶
Fetch ambient seismic data from a source to read into obspy stream
- Parameters:
- paramsdict
- Dictionary containing all the necessary params to get data.
Parameters defined using input_params() function.
- sourcestr, {‘raw’, ‘dir’, ‘file’, ‘batch’}
- String indicating where/how data file was created. For example, if raw data, will need to find correct channels.
‘raw’ finds raspberry shake data, from raw output copied using scp directly from Raspberry Shake, either in folder or subfolders; ‘dir’ is used if the day’s 3 component files (currently Raspberry Shake supported only) are all 3 contained in a directory by themselves. ‘file’ is used if the params[‘input_data’] specified in input_params() is the direct filepath to a single file to be read directly into an obspy stream. ‘batch’ is used to read a list or specified set of seismic files.
Most commonly, a csv file can be read in with all the parameters. Each row in the csv is a separate file. Columns can be arranged by parameter.
- data_export_pathNone or str or pathlib obj, default=None
If None (or False), data is not trimmed in this function. Otherwise, this is the directory to save trimmed and exported data.
- data_export_format: str=’mseed’
If data_export_path is not None, this is the format in which to save the data
- detrendstr or bool, default=’spline’
If False, data is not detrended. Otherwise, this should be a string accepted by the type parameter of the obspy.core.trace.Trace.detrend method: https://docs.obspy.org/packages/autogen/obspy.core.trace.Trace.detrend.html
- detrend_optionsint, default=2
If detrend parameter is ‘spline’ or ‘polynomial’, this is passed directly to the order parameter of obspy.core.trace.Trace.detrend method.
- filter_typeNone, str
Type of filter to use on raw data. This should either be None or any of {‘bandpass’, ‘bandstop’, ‘lowpass’, ‘highpass’, ‘lowpass_cheby_2’, ‘lowpass_fir’, ‘remez_fir’}. This passes filter_type to the type parameter and **filter_options to the **options parameter of the obspy.Stream filter() method. See here for more information: https://docs.obspy.org/packages/autogen/obspy.core.stream.Stream.filter.html If None, no filtering is done on the input seismic data.
- filter_optionsdict
Dictionary that will be unpacked into the **options parameter of the filter() method of the obspy.Stream class. This should fit the parameters of whichever filter type is specifed by filter_type. Example options for the ‘bandpass’ filter_type might be: filter_options={‘freqmin’: 0.4, ‘freqmax’:40, ‘df’:100, ‘corners’:4, ‘zerophase’:True}. See here for more information: https://docs.obspy.org/packages/autogen/obspy.core.stream.Stream.filter.html
- update_metadatabool, default=True
Whether to update the metadata file, used primarily with Raspberry Shake data which uses a generic inventory file.
- plot_input_streambool, default=False
Whether to plot the raw input stream. This plot includes a spectrogram (Z component) and the raw (with decimation for speed) plots of each component signal.
- plot_enginestr, default=’matplotlib’
Which plotting library/engine to use for plotting the Input stream. Options are ‘matplotlib’, ‘plotly’, or ‘obspy’ (not case sensitive).
- verbosebool, default=False
Whether to print outputs and inputs to the terminal
- **kwargs
Keywords arguments, primarily for ‘batch’ and ‘dir’ sources
- Returns:
- paramsHVSRData or HVSRBatch object
Same as params parameter, but with an additional “stream” attribute with an obspy data stream with 3 traces: Z (vertical), N (North-south), and E (East-west)
- sprit.sprit_hvsr.generate_ppsds(hvsr_data, **gen_psds_kwargs)[source]¶
This function is to maintain backwards compatibility with previous version
- sprit.sprit_hvsr.generate_psds(hvsr_data, window_length=30.0, overlap_pct=0.5, window_type='hann', window_length_method='length', skip_on_gaps=True, num_freq_bins=500, obspy_ppsds=False, azimuthal_ppsds=False, verbose=False, plot_psds=False, **obspy_ppsd_kwargs)[source]¶
Generates PPSDs for each channel
Channels need to be in Z, N, E order Info on PPSD creation here: https://docs.obspy.org/packages/autogen/obspy.signal.spectral_estimation.PPSD.html
- Parameters:
- hvsr_datadict, HVSRData object, or HVSRBatch object
Data object containing all the parameters and other data of interest (stream and paz, for example)
- azimuthal_ppsdsbool, default=False
Whether to generate PPSDs for azimuthal data
- verbosebool, default=True
Whether to print inputs and results to terminal
- **obspy_ppsd_kwargsdict
Dictionary with keyword arguments that are passed directly to obspy.signal.PPSD. If the following keywords are not specified, their defaults are amended in this function from the obspy defaults for its PPSD function. Specifically:
ppsd_length defaults to 30 (seconds) here instead of 3600
skip_on_gaps defaults to True instead of False
period_step_octaves defaults to 0.03125 instead of 0.125
- Returns:
- ppsdsHVSRData object
Dictionary containing entries with ppsds for each channel
- sprit.sprit_hvsr.get_metadata(params, write_path='', update_metadata=True, source=None, **read_inventory_kwargs)[source]¶
Get metadata and calculate or get paz parameter needed for PPSD
- Parameters:
- paramsdict
- Dictionary containing all the input and other parameters needed for processing
Ouput from input_params() function
- write_pathstr
- String with output filepath of where to write updated inventory or metadata file
If not specified, does not write file
- update_metadatabool
Whether to update the metadata file itself, or just read as-is. If using provided raspberry shake metadata file, select True.
- sourcestr, default=None
This passes the source variable value to _read_RS_metadata. It is expected that this is passed directly from the source parameter of sprit.fetch_data()
- Returns:
- paramsdict
Modified input dictionary with additional key:value pair containing paz dictionary (key = “paz”)
- sprit.sprit_hvsr.get_report(hvsr_results, report_formats=['print', 'table', 'plot', 'html', 'pdf'], azimuth='HV', plot_type='HVSR p ann COMP+ p ann SPEC p ann', plot_engine='matplotlib', show_print_report=True, show_table_report=False, show_plot_report=True, show_html_report=False, show_pdf_report=True, suppress_report_outputs=False, show_report_outputs=False, csv_handling='append', report_export_format=None, report_export_path=None, verbose=False, **kwargs)[source]¶
Generate and/or print and/or export a report of the HVSR analysis in a variety of formats.
Formats include: * ‘print’: A (monospace) text summary of the HVSR results * ‘table’: A pandas.DataFrame summary of the HVSR Results.
This is useful for copy/pasting directly into a larger worksheet.
‘plot’: A plot summary of the HVSR results, generated using the plot_hvsr() function.
‘html’: An HTML document/text of the HVSR results. This includes the table, print, and plot reports in one document.
- ‘pdf’: A PDF document showing the summary of the HVSR Results.
The PDF report is simply the HTML report saved to an A4-sized PDF document.
- Parameters:
- hvsr_resultsdict
Dictionary containing all the information about the processed hvsr data
- report_formats{‘table’, ‘print’, plot}
Format in which to print or export the report. The following report_formats return the following items in the following attributes:
‘plot’: hvsr_results[‘Print_Report’] as a str
‘print’: hvsr_results[‘HV_Plot’] - matplotlib.Figure object
- ‘table’: hvsr_results[‘Table_Report’]- pandas.DataFrame object
list/tuple - a list or tuple of the above objects, in the same order they are in the report_formats list
‘html’: hvsr_results[‘HTML_Report’] - a string containing the text for an HTML document
‘pdf’: currently does not save to the HVSRData object itself, can only be saved to the disk directly
- plot_typestr, default = ‘HVSR p ann C+ p ann Spec p ann’
What type of plot to plot, if ‘plot’ part of report_formats input
- azimuthstr, default = ‘HV’
Which azimuth to plot, by default “HV” which is the main “azimuth” combining the E and N components
- csv_handlingstr, {‘append’, ‘overwrite’, ‘keep/rename’}
How to handle table report outputs if the designated csv output file already exists. By default, appends the new information to the end of the existing file.
- suppress_report_outputsbool, default=False
If True, only reads output to appropriate attribute of data class (ie, print does not print, only reads text into variable). If False, performs as normal.
- report_export_formatlist or str, default=[‘pdf’]
A string or list of strings indicating which report formats should be exported to disk.
- report_export_pathNone, bool, or filepath, default = None
If None or False, does not export; if True, will export to same directory as the input_data parameter in the input_params() function. Otherwise, it should be a string or path object indicating where to export results. May be a file or directory. If a directory is specified, the filename will be “<site_name>_<acq_date>_<UTC start time>-<UTC end time>”. The extension/suffix defaults to png for report_formats=”plot”, csv for ‘table’, txt for ‘print’, html for ‘html’, and pdf for ‘pdf.’
- verbosebool, default=True
Whether to print the results to terminal. This is the same output as report_formats=’print’, and will not repeat if that is already selected
- Returns:
- sprit.HVSRData
- sprit.sprit_hvsr.gui(kind='browser')[source]¶
Function to open a graphical user interface (gui)
- Parameters:
- kindstr, optional
What type of gui to open: * “browser” or “default” opens browser interface (using streamlit) * “widget” opens jupyter widget (using ipywidgets) * “window” opens windowed gui (using tkinter)
- sprit.sprit_hvsr.import_data(import_filepath, data_format='pickle')[source]¶
Function to import .hvsr (or other extension) data exported using export_data() function
- Parameters:
- import_filepathstr or path object
Filepath of file created using export_data() function. This is usually a pickle file with a .hvsr extension
- data_formatstr, default=’pickle’
Type of format data is in. Currently, only ‘pickle’ supported. Eventually, json or other type may be supported, by default ‘pickle’.
- Returns:
- HVSRData or HVSRBatch object
- sprit.sprit_hvsr.import_settings(settings_import_path, settings_import_type='instrument', verbose=False)[source]¶
- sprit.sprit_hvsr.input_params(input_data, site='HVSR Site', project=None, network='AM', station='RAC84', loc='00', channels=['EHZ', 'EHN', 'EHE'], acq_date='2024-11-09', starttime=UTCDateTime(2024, 11, 9, 0, 0), endtime=UTCDateTime(2024, 11, 9, 23, 59, 59, 999999), tzone='UTC', xcoord=-88.2290526, ycoord=40.1012122, elevation=755, input_crs=None, output_crs=None, elev_unit='meters', depth=0, instrument='Raspberry Shake', metapath=None, hvsr_band=[0.4, 40], peak_freq_range=[0.4, 40], processing_parameters={}, verbose=False)[source]¶
Function for designating input parameters for reading in and processing data
- Parameters:
- input_datastr or pathlib.Path object
Filepath of data. This can be a directory or file, but will need to match with what is chosen later as the source parameter in fetch_data()
- sitestr, default=”HVSR Site”
Site name as designated by user for ease of reference. Used for plotting titles, filenames, etc.
- projectstr, default=None
A prefix that may be used to create unique identifiers for each site. The identifier created is saved as the [‘HVSR_ID’] attribute of the HVSRData object, and is equivalent to the following formatted string: f”{project}-{acq_date.strftime(“%Y%m%d”)}-{starttime.strftime(“%H%M”)}-{station}”.
- networkstr, default=’AM’
The network designation of the seismometer. This is necessary for data from Raspberry Shakes. ‘AM’ is for Amateur network, which fits Raspberry Shakes.
- stationstr, default=’RAC84’
The station name of the seismometer. This is necessary for data from Raspberry Shakes.
- locstr, default=’00’
Location information of the seismometer.
- channelslist, default=[‘EHZ’, ‘EHN’, ‘EHE’]
The three channels used in this analysis, as a list of strings. Preferred that Z component is first, but not necessary
- acq_datestr, int, date object, or datetime object
If string, preferred format is ‘YYYY-MM-DD’. If int, this will be interpreted as the time_int of year of current year (e.g., 33 would be Feb 2 of current year) If date or datetime object, this will be the date. Make sure to account for time change when converting to UTC (if UTC is the following time_int, use the UTC time_int).
- starttimestr, time object, or datetime object, default=’00:00:00.00’
Start time of data stream. This is necessary for Raspberry Shake data in ‘raw’ form, or for trimming data. Format can be either ‘HH:MM:SS.micros’ or ‘HH:MM’ at minimum.
- endtimestr, time obejct, or datetime object, default=’23:59:99.99’
End time of data stream. This is necessary for Raspberry Shake data in ‘raw’ form, or for trimming data. Same format as starttime.
- tzonestr or int, default = ‘UTC’
Timezone of input data. If string, ‘UTC’ will use the time as input directly. Any other string value needs to be a TZ identifier in the IANA database, a wikipedia page of these is available here: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones. If int, should be the int value of the UTC offset (e.g., for American Eastern Standard Time: -5). This is necessary for Raspberry Shake data in ‘raw’ format.
- xcoordfloat, default=-88.2290526
Longitude (or easting, or, generally, X coordinate) of data point, in Coordinate Reference System (CRS) designated by input_crs. Currently only used in table output, but will likely be used in future for mapping/profile purposes.
- ycoordfloat, default=40.1012122
Latitute (or northing, or, generally, X coordinate) of data point, in Coordinate Reference System (CRS) designated by input_crs. Currently only used in table output, but will likely be used in future for mapping/profile purposes.
- input_crsstr or other format read by pyproj, default=’EPSG:4326’
Coordinate reference system of input data, as used by pyproj.CRS.from_user_input()
- output_crsstr or other format read by pyproj, default=’EPSG:4326’
Coordinate reference system to which input data will be transformed, as used by pyproj.CRS.from_user_input()
- elevationfloat, default=755
Surface elevation of data point. Not currently used (except in table output), but will likely be used in the future.
- depthfloat, default=0
Depth of seismometer. Not currently used, but will likely be used in the future.
- instrumentstr {‘Raspberry Shake’, “Tromino”}
Instrument from which the data was acquired.
- metapathstr or pathlib.Path object, default=None
Filepath of metadata, in format supported by obspy.read_inventory. If default value of None, will read from resources folder of repository (only supported for Raspberry Shake).
- hvsr_bandlist, default=[0.4, 40]
Two-element list containing low and high “corner” frequencies (in Hz) for processing. This can specified again later.
- peak_freq_rangelist or tuple, default=[0.4, 40]
Two-element list or tuple containing low and high frequencies (in Hz) that are used to check for HVSR Peaks. This can be a tigher range than hvsr_band, but if larger, it will still only use the hvsr_band range.
- processing_parameters={}dict or filepath, default={}
If filepath, should point to a .proc json file with processing parameters (i.e, an output from sprit.export_settings()). Note that this only applies to parameters for the functions: ‘fetch_data’, ‘remove_noise’, ‘generate_psds’, ‘process_hvsr’, ‘check_peaks’, and ‘get_report.’ If dictionary, dictionary containing nested dictionaries of function names as they key, and the parameter names/values as key/value pairs for each key. If a function name is not present, or if a parameter name is not present, default values will be used. For example:
{ ‘fetch_data’ : {‘source’:’batch’, ‘data_export_path’:”/path/to/trimmed/data”, ‘data_export_format’:’mseed’, ‘detrend’:’spline’, ‘plot_input_stream’:True, ‘verbose’:False, kwargs:{‘kwargskey’:’kwargsvalue’}} }
- verbosebool, default=False
Whether to print output and results to terminal
- Returns:
- paramssprit.HVSRData
sprit.HVSRData class containing input parameters, including data file path and metadata path. This will be used as an input to other functions. If batch processing, params will be converted to batch type in fetch_data() step.
- sprit.sprit_hvsr.plot_azimuth(hvsr_data, fig=None, ax=None, show_azimuth_peaks=False, interpolate_azimuths=True, show_azimuth_grid=False, show_plot=True, **plot_azimuth_kwargs)[source]¶
Function to plot azimuths when azimuths are calculated
- Parameters:
- hvsr_dataHVSRData or HVSRBatch
HVSRData that has gone through at least the sprit.fetch_data() step, and before sprit.generate_psds()
- show_azimuth_peaksbool, optional
Whether to display the peak value at each azimuth calculated on the chart, by default False
- interpolate_azimuthsbool, optional
Whether to interpolate the azimuth data to get a smoother plot. This is just for visualization, does not change underlying data. It takes a lot of time to process the data, but interpolation for vizualization can happen fairly fast. By default True.
- show_azimuth_gridbool, optional
Whether to display the grid on the chart, by default False
- Returns:
- matplotlib.Figure, matplotlib.Axis
Figure and axis of resulting azimuth plot
- sprit.sprit_hvsr.plot_hvsr(hvsr_data, plot_type='HVSR p ann COMP+ p ann SPEC p ann', azimuth='HV', use_subplots=True, fig=None, ax=None, return_fig=False, plot_engine='matplotlib', save_dir=None, save_suffix='', show_legend=False, show_plot=True, close_figs=False, clear_fig=True, **kwargs)[source]¶
Function to plot HVSR data
- Parameters:
- hvsr_datadict
Dictionary containing output from process_hvsr function
- plot_typestr or list, default = ‘HVSR ann p C+ ann p SPEC ann p’
The plot_type of plot(s) to plot. If list, will plot all plots listed - ‘HVSR’ - Standard HVSR plot, including standard deviation. Options are included below:
‘p’ shows a vertical dotted line at frequency of the “best” peak
‘ann’ annotates the frequency value of of the “best” peak
‘all’ shows all the peaks identified in check_peaks() (by default, only the max is identified)
‘t’ shows the H/V curve for all time windows
‘tp’ shows all the peaks from the H/V curves of all the time windows
‘fr’ shows the window within which SpRIT will search for peak frequencies, as set by peak_freq_range
- ‘test’ shows a visualization of the results of the peak validity test(s). Examples:
‘tests’ visualizes the results of all the peak tests (not the curve tests)
- ‘test12’ shows the results of tests 1 and 2.
Append any number 1-6 after ‘test’ to show a specific test result visualized
- ‘COMP’ - plot of the PPSD curves for each individual component (“C” also works)
‘+’ (as a suffix in ‘C+’ or ‘COMP+’) plots C on a plot separate from HVSR (C+ is default, but without + will plot on the same plot as HVSR)
‘p’ shows a vertical dotted line at frequency of the “best” peak
‘ann’ annotates the frequency value of of the “best” peak
‘all’ shows all the peaks identified in check_peaks() (by default, only the max is identified)
‘t’ shows the H/V curve for all time windows
- ‘SPEC’ - spectrogram style plot of the H/V curve over time
‘p’ shows a horizontal dotted line at the frequency of the “best” peak
‘ann’ annotates the frequency value of the “best” peak
‘all’ shows all the peaks identified in check_peaks()
‘tp’ shows all the peaks of the H/V curve at all time windows
- ‘AZ’ - circular plot of calculated azimuthal HV curves, similar in style to SPEC plot.
‘p’ shows a point at each calculated (not interpolated) azimuth peak
‘g’ shows grid lines at various angles
- ‘i’ interpolates so that there is an interpolated azimuth at each degree interval (1 degree step)
This is the default, so usually ‘i’ is not needed.
‘-i’ prohibits interpolation (only shows the calculated azimuths, as determined by azimuth_angle (default = 30))
- azimuthstr, default = ‘HV’
What ‘azimuth’ to plot, default being standard N E components combined
- use_subplotsbool, default = True
Whether to output the plots as subplots (True) or as separate plots (False)
- figmatplotlib.Figure, default = None
If not None, matplotlib figure on which plot is plotted
- axmatplotlib.Axis, default = None
If not None, matplotlib axis on which plot is plotted
- return_figbool
Whether to return figure and axis objects
- plot_enginestr, default=’Matplotlib’
Which engine to use for plotting. Both “matplotlib” and “plotly” are acceptable. For shorthand, ‘mpl’, ‘m’ also work for matplotlib; ‘plty’ or ‘p’ also work for plotly. Not case sensitive.
- save_dirstr or None
Directory in which to save figures
- save_suffixstr
Suffix to add to end of figure filename(s), if save_dir is used
- show_legendbool, default=False
Whether to show legend in plot
- show_plotbool
Whether to show plot
- close_figsbool, default=False
Whether to close figures before plotting
- clear_figbool, default=True
Whether to clear figures before plotting
- **kwargskeyword arguments
Keyword arguments for matplotlib.pyplot
- Returns:
- fig, axmatplotlib figure and axis objects
Returns figure and axis matplotlib.pyplot objects if return_fig=True, otherwise, simply plots the figures
- sprit.sprit_hvsr.plot_stream(stream, params, fig=None, axes=None, show_plot=False, ylim_std=0.75, return_fig=True)[source]¶
Function to plot a stream of data with Z, E, N components using matplotlib. Similar to obspy.Stream.Plot(), but will be formatted differently and eventually more customizable. This is also used in various functions throughout the package.
- Parameters:
- streamobspy.core.Stream.stream
Obpsy stream of data with Z, E, N componenents
- paramsHVSRData or HVSRBatch
Data object with parameters relevant for creating plot
- figmatplotlib.Figure, default=None
Optional: if not None, matplotlib.Figure in which to plot the resulting figure (i.e., can be plotted in existing figure)
- axesmatplotlib.Axis, default=None
Optional: if not None, matplotlib.Axis in which to plot the resulting figure (i.e., can be plotted in existing axis)
- show_plotbool, default=False
Whether to do matplotlib.pylot.show(), by default False
- ylim_stdfloat, default = 0.75
Optional: the standard deviation of the data at which to clip the chart, by default 0.75
- return_figbool, default=True
Optional: whether to return the figure, by default True
- Returns:
- (matplotlib.Figure, matplotlib.Axes)
Tuple containing the figure and axes of the resulting plot, only returned if return_fig = True
- sprit.sprit_hvsr.process_hvsr(hvsr_data, horizontal_method=None, smooth=True, freq_smooth='konno ohmachi', f_smooth_width=40, resample=True, outlier_curve_rmse_percentile=False, azimuth=None, verbose=False)[source]¶
Process the input data and get HVSR data
This is the main function that uses other (private) functions to do the bulk of processing of the HVSR data and the data quality checks.
- Parameters:
- hvsr_dataHVSRData or HVSRBatch
Data object containing all the parameters input and generated by the user (usually, during sprit.input_params(), sprit.fetch_data(), sprit.generate_psds() and/or sprit.remove_noise()).
- horizontal_methodint or str, default=3
- Method to use for combining the horizontal components. Default is 3) Geometric Mean
(not used)
‘Diffuse field assumption’ H = √( (eie_E + eie_N) / eie_Z), eie = equal interval energy
‘Arithmetic Mean’ H ≡ (HN + HE)/2
‘Geometric Mean’ H ≡ √(HN · HE), recommended by the SESAME project (2004)
‘Vector Summation’ H ≡ √(HN^2 + HE^2)
‘Quadratic Mean’ H ≡ √(HN^2 + HE^2)/2
‘Maximum Horizontal Value’ H ≡ max {HN, HE}
‘Minimum Horizontal Valey’ H ≡ min {HN, HE}
‘Single Azimuth’ H = H2·cos(az) + H1·sin(az)
- smoothbool, default=True
- bool or int may be used.
If True, default to smooth H/V curve to using savgoy filter with window length of 51 (works well with default resample of 1000 pts) If int, the length of the window in the savgoy filter.
- freq_smoothstr {‘konno ohmachi’, ‘constant’, ‘proportional’}
- Which frequency smoothing method to use. By default, uses the ‘konno ohmachi’ method.
The Konno & Ohmachi method uses the obspy.signal.konnoohmachismoothing.konno_ohmachi_smoothing() function: https://docs.obspy.org/packages/autogen/obspy.signal.konnoohmachismoothing.konno_ohmachi_smoothing.html
The constant method uses a window of constant length f_smooth_width
The proportional method uses a window the percentage length of the frequncy steps/range (f_smooth_width now refers to percentage)
See here for more information: https://www.geopsy.org/documentation/geopsy/hv-processing.html
- f_smooth_widthint, default = 40
For ‘konno ohmachi’: passed directly to the bandwidth parameter of the konno_ohmachi_smoothing() function, determines the width of the smoothing peak, with lower values resulting in broader peak. Must be > 0.
For ‘constant’: the size of a triangular smoothing window in the number of frequency steps
For ‘proportional’: the size of a triangular smoothing window in percentage of the number of frequency steps (e.g., if 1000 frequency steps/bins and f_smooth_width=40, window would be 400 steps wide)
- resamplebool, default = True
- bool or int.
If True, default to resample H/V data to include 1000 frequency values for the rest of the analysis If int, the number of data points to interpolate/resample/smooth the component psd/HV curve data to.
- outlier_curve_rmse_percentilebool, float, default = False
If False, outlier curve removal is not carried out here. If True, defaults to 98 (98th percentile). Otherwise, float of percentile used as rmse_thresh of remove_outlier_curve().
- azimuthfloat, default = None
The azimuth angle to use when method is single azimuth.
- verbosebool, defualt=False
Whether to print output to terminal
- Returns:
- hvsr_outdict
Dictionary containing all the information about the data, including input parameters
- sprit.sprit_hvsr.read_tromino_files(input_data, params, struct_format='H', sampling_rate=128, start_byte=24576, verbose=False, **kwargs)[source]¶
Function to read data from tromino. Specifically, this has been lightly tested on Tromino 3G+ machines
- Parameters:
- input_datastr, pathlib.Path()
The input parameter _datapath_ from sprit.input_params()
- paramsHVSRData or HVSRBatch
The parameters as read in from input_params() and and fetch_data()
- verbosebool, optional
Whether to print results to terminal, by default False
- Returns:
- obspy.Stream
An obspy.Stream object containing the trace data from the Tromino instrument
- sprit.sprit_hvsr.remove_noise(hvsr_data, remove_method=None, processing_window=None, sat_percent=0.995, noise_percent=0.8, sta=2, lta=30, stalta_thresh=[8, 16], std_ratio_thresh=2.0, std_window_size=20.0, min_std_win=5.0, warmup_time=0, cooldown_time=0, min_win_size=1, remove_raw_noise=False, show_stalta_plot=False, verbose=False)[source]¶
Function to remove noisy windows from data, using various methods.
Methods include - Manual window selection (by clicking on a chart with spectrogram and stream data), - Auto window selection, which does the following two in sequence (these can also be done indepently):
A sta/lta “antitrigger” method (using stalta values to automatically remove triggered windows where there appears to be too much noise)
A noise threshold method, that cuts off all times where the noise threshold equals more than (by default) 80% of the highest amplitude noise sample for the length specified by lta (in seconds)
A saturation threshold method, that cuts off all times where the noise threshold equals more than (by default) 99.5% of the highest amplitude noise sample.
- Parameters:
- hvsr_datadict, obspy.Stream, or obspy.Trace
Dictionary containing all the data and parameters for the HVSR analysis
- remove_methodstr, {‘auto’, ‘manual’, ‘stalta’/’antitrigger’, ‘saturation threshold’, ‘noise threshold’, ‘warmup’/’cooldown’/’buffer’/’warm_cool’}
The different methods for removing noise from the dataset. A list of strings will also work, in which case, it should be a list of the above strings. See descriptions above for what how each method works. By default ‘auto.’ If remove_method=’auto’, this is the equivalent of remove_method=[‘noise threshold’, ‘antitrigger’, ‘saturation threshold’, ‘warm_cool’]
- processing_windowlist, tuple, or None
A list/tuple of two items [s, e] or a list/tuple of two-item lists/tuples [[s0, e0], [s1,e1],…[sn, en]] with start and end time(s) for windows to keep for processing. Data outside of these times will be excluded from processing. Times should be obspy.UTCDateTime objects to ensure precision, but time strings (“13:05”) will also work in most cases (excpetions may be when the data stream starts/ends on different UTC days)
- sat_percentfloat, default=0.995
Percentage (between 0 and 1), to use as the threshold at which to remove data. This is used in the saturation method. By default 0.995. If a value is passed that is greater than 1, it will be divided by 100 to obtain the percentage.
- noise_percentfloat, default = 0.8
Percentage (between 0 and 1), to use as the threshold at which to remove data, if it persists for longer than time (in seconds (specified by min_win_size)). This is used in the noise threshold method. By default 0.8. If a value is passed that is greater than 1, it will be divided by 100 to obtain the percentage.
- staint, optional
Short term average (STA) window (in seconds), by default 2. For use with sta/lta antitrigger method.
- ltaint, optional
Long term average (STA) window (in seconds), by default 30. For use with sta/lta antitrigger method.
- stalta_threshlist, default=[0.5,5]
Two-item list or tuple with the thresholds for the stalta antitrigger. The first value (index [0]) is the lower threshold, the second value (index [1] is the upper threshold), by default [0.5,5]
- std_ratio_threshfloat, optional
The ratio to use as a threshold for removal of noise. The ratio represents the standard deviation value for a rolling window (the size of which is determined by the std_window_size parameter) divided by the standard deviation calculated for the entire trace. This rolling window standard deviation method is similar to the default noise removal method used by the Grilla HVSR software.
- std_window_sizefloat, optional
The length of the window (in seconds) to use for calculating the rolling/moving standard deviation of a trace for the rolling standard deviation method.
- min_std_winfloat, optional
The minimum size of “window” that will be remove using the rolling standard deviation method.
- warmup_timeint, default=0
Time in seconds to allow for warmup of the instrument (or while operator is still near instrument). This will renove any data before this time, by default 0.
- cooldown_timeint, default=0
Time in seconds to allow for cooldown of the instrument (or for when operator is nearing instrument). This will renove any data before this time, by default 0.
- min_win_sizefloat, default=1
The minumum size a window must be over specified threshold (in seconds) for it to be removed
- remove_raw_noisebool, default=False
If remove_raw_noise=True, will perform operation on raw data (‘input_stream’), rather than potentially already-modified data (‘stream’).
- verbosebool, default=False
Whether to print status of remove_noise
- Returns:
- outputdict
Dictionary similar to hvsr_data, but containing modified data with ‘noise’ removed
- sprit.sprit_hvsr.remove_outlier_curves(hvsr_data, rmse_thresh=98, use_percentile=True, use_hv_curve=False, plot_engine='matplotlib', show_plot=False, verbose=False)[source]¶
Function used to remove outliers curves using Root Mean Square Error to calculate the error of each windowed Probabilistic Power Spectral Density (PPSD) curve against the median PPSD value at each frequency step for all times. It calculates the RMSE for the PPSD curves of each component individually. All curves are removed from analysis.
Some abberant curves often occur due to the remove_noise() function, so this should be run some time after remove_noise(). In general, the recommended workflow is to run this immediately following the generate_psds() function.
- Parameters:
- hvsr_datadict
Input dictionary containing all the values and parameters of interest
- rmse_threshfloat or int, default=98
The Root Mean Square Error value to use as a threshold for determining whether a curve is an outlier. This averages over each individual entire curve so that curves with very abberant data (often occurs when using the remove_noise() method), can be identified. Otherwise, specify a float or integer to use as the cutoff RMSE value (all curves with RMSE above will be removed)
- use_percentilefloat, default=True
Whether rmse_thresh should be interepreted as a raw RMSE value or as a percentile of the RMSE values.
- use_hv_curvebool, default=False
Whether to use the calculated HV Curve or the individual components. This can only be True after process_hvsr() has been run.
- show_plotbool, default=False
Whether to show a plot of the removed data
- verbosebool, default=False
Whether to print output of function to terminal
- Returns:
- hvsr_datadict
Input dictionary with values modified based on work of function.
- sprit.sprit_hvsr.run(input_data, source='file', azimuth_calculation=False, noise_removal=False, outlier_curves_removal=False, verbose=False, **kwargs)[source]¶
The sprit.run() is the main function that allows you to do all your HVSR processing in one simple step (sprit.run() is how you would call it in your code, but it may also be called using sprit.sprit_hvsr.run())
The input_data parameter of sprit.run() is the only required parameter. This can be either a single file, a list of files (one for each component, for example), a directory (in which case, all obspy-readable files will be added to an HVSRBatch instance), a Rasp. Shake raw data directory, or sample data.
- Parameters:
- input_datastr or filepath object that can be read by obspy
Filepath to data to be processed. This may be a file or directory, depending on what kind of data is being processed (this can be specified with the source parameter). For sample data, The following can be specified as the input_data parameter:
Any integer 1-6 (inclusive), or the string (e.g., input_data=”1” or input_data=1 will work)
The word “sample” before any integer (e.g., input_data=”sample1”)
The word “sample” will default to “sample1” if source=’file’.
If source=’batch’, input_data should be input_data=’sample’ or input_data=’batch’. In this case, it will read and process all the sample files using the HVSRBatch class. Set verbose=True to see all the information in the sample batch csv file.
- sourcestr, optional
_description_, by default ‘file’
- azimuth_calculationbool, optional
Whether to perform azimuthal analysis, by default False.
- noise_removalbool, default=False
Whether to remove noise (before processing PPSDs)
- outlier_curves_removalbool, default=False
Whether to remove outlier curves from HVSR time windows
- show_plotbool, default=True
Whether to show plots. This does not affect whether the plots are created (and then inserted as an attribute of HVSRData), only whether they are shown.
- verbosebool, optional
_description_, by default False
- **kwargs
Keyword arguments for the functions listed above. The keyword arguments are unique, so they will get parsed out and passed into the appropriate function.
- input_paramsfunction name (not an actual parameter)
Function for designating input parameters for reading in and processing data See API documentation: [input_params()](https://sprit.readthedocs.io/en/latest/sprit.html#sprit.input_params)
- input_data: any, default = ‘<no default>’
See API documentation at link above or at help(sprit.input_params) for specifics.
- site: any, default = ‘HVSR Site’
See API documentation at link above or at help(sprit.input_params) for specifics.
- project: any, default = None
See API documentation at link above or at help(input_params) for specifics.
- network: any, default = ‘AM’
See API documentation at link above or at help(sprit.input_params) for specifics.
- station: any, default = ‘RAC84’
See API documentation at link above or at help(sprit.input_params) for specifics.
- loc: any, default = ‘00’
See API documentation at link above or at help(sprit.input_params) for specifics.
- channels: any, default = [‘EHZ’, ‘EHN’, ‘EHE’]
See API documentation at link above or at help(input_params) for specifics.
- acq_date: any, default = ‘2024-11-09’
See API documentation at link above or at help(sprit.input_params) for specifics.
- starttime: any, default = 2024-11-09T00:00:00.000000Z
See API documentation at link above or at help(input_params) for specifics.
- endtime: any, default = 2024-11-09T23:59:59.999999Z
See API documentation at link above or at help(input_params) for specifics.
- tzone: any, default = ‘UTC’
See API documentation at link above or at help(sprit.input_params) for specifics.
- xcoord: any, default = -88.2290526
See API documentation at link above or at help(input_params) for specifics.
- ycoord: any, default = 40.1012122
See API documentation at link above or at help(input_params) for specifics.
- elevation: any, default = 755
See API documentation at link above or at help(input_params) for specifics.
- input_crs: any, default = None
See API documentation at link above or at help(input_params) for specifics.
- output_crs: any, default = None
See API documentation at link above or at help(input_params) for specifics.
- elev_unit: any, default = ‘meters’
See API documentation at link above or at help(sprit.input_params) for specifics.
- depth: any, default = 0
See API documentation at link above or at help(input_params) for specifics.
- instrument: any, default = ‘Raspberry Shake’
See API documentation at link above or at help(sprit.input_params) for specifics.
- metapath: any, default = None
See API documentation at link above or at help(input_params) for specifics.
- hvsr_band: any, default = [0.4, 40]
See API documentation at link above or at help(input_params) for specifics.
- peak_freq_range: any, default = [0.4, 40]
See API documentation at link above or at help(input_params) for specifics.
- processing_parameters: any, default = {}
See API documentation at link above or at help(input_params) for specifics.
- verbose: any, default = False
See API documentation at link above or at help(input_params) for specifics.
- fetch_datafunction name (not an actual parameter)
Fetch ambient seismic data from a source to read into obspy stream See API documentation: [fetch_data()](https://sprit.readthedocs.io/en/latest/sprit.html#sprit.fetch_data)
- params: any, default = ‘<output of previous function>’
See API documentation at link above or at help(sprit.fetch_data) for specifics.
- source: any, default = ‘file’
See API documentation at link above or at help(sprit.fetch_data) for specifics.
- data_export_path: any, default = None
See API documentation at link above or at help(fetch_data) for specifics.
- data_export_format: any, default = ‘mseed’
See API documentation at link above or at help(sprit.fetch_data) for specifics.
- detrend: any, default = ‘spline’
See API documentation at link above or at help(sprit.fetch_data) for specifics.
- detrend_options: any, default = 2
See API documentation at link above or at help(fetch_data) for specifics.
- filter_type: any, default = None
See API documentation at link above or at help(fetch_data) for specifics.
- filter_options: any, default = {}
See API documentation at link above or at help(fetch_data) for specifics.
- update_metadata: any, default = True
See API documentation at link above or at help(fetch_data) for specifics.
- plot_input_stream: any, default = False
See API documentation at link above or at help(fetch_data) for specifics.
- plot_engine: any, default = ‘matplotlib’
See API documentation at link above or at help(sprit.fetch_data) for specifics.
- show_plot: any, default = True
See API documentation at link above or at help(fetch_data) for specifics.
- verbose: any, default = False
See API documentation at link above or at help(fetch_data) for specifics.
- kwargs: any, default = {}
See API documentation at link above or at help(fetch_data) for specifics.
- calculate_azimuthfunction name (not an actual parameter)
Function to calculate azimuthal horizontal component at specified angle(s). Adds each new horizontal See API documentation: [calculate_azimuth()](https://sprit.readthedocs.io/en/latest/sprit.html#sprit.calculate_azimuth)
- hvsr_data: any, default = ‘<output of previous function>’
See API documentation at link above or at help(sprit.calculate_azimuth) for specifics.
- azimuth_angle: any, default = 30
See API documentation at link above or at help(calculate_azimuth) for specifics.
- azimuth_type: any, default = ‘multiple’
See API documentation at link above or at help(sprit.calculate_azimuth) for specifics.
- azimuth_unit: any, default = ‘degrees’
See API documentation at link above or at help(sprit.calculate_azimuth) for specifics.
- show_az_plot: any, default = False
See API documentation at link above or at help(calculate_azimuth) for specifics.
- verbose: any, default = False
See API documentation at link above or at help(calculate_azimuth) for specifics.
- plot_azimuth_kwargs: any, default = {}
See API documentation at link above or at help(calculate_azimuth) for specifics.
- remove_noisefunction name (not an actual parameter)
Function to remove noisy windows from data, using various methods. See API documentation: [remove_noise()](https://sprit.readthedocs.io/en/latest/sprit.html#sprit.remove_noise)
- hvsr_data: any, default = ‘<output of previous function>’
See API documentation at link above or at help(sprit.remove_noise) for specifics.
- remove_method: any, default = None
See API documentation at link above or at help(remove_noise) for specifics.
- processing_window: any, default = None
See API documentation at link above or at help(remove_noise) for specifics.
- sat_percent: any, default = 0.995
See API documentation at link above or at help(remove_noise) for specifics.
- noise_percent: any, default = 0.8
See API documentation at link above or at help(remove_noise) for specifics.
- sta: any, default = 2
See API documentation at link above or at help(remove_noise) for specifics.
- lta: any, default = 30
See API documentation at link above or at help(remove_noise) for specifics.
- stalta_thresh: any, default = [8, 16]
See API documentation at link above or at help(remove_noise) for specifics.
- std_ratio_thresh: any, default = 2.0
See API documentation at link above or at help(remove_noise) for specifics.
- std_window_size: any, default = 20.0
See API documentation at link above or at help(remove_noise) for specifics.
- min_std_win: any, default = 5.0
See API documentation at link above or at help(remove_noise) for specifics.
- warmup_time: any, default = 0
See API documentation at link above or at help(remove_noise) for specifics.
- cooldown_time: any, default = 0
See API documentation at link above or at help(remove_noise) for specifics.
- min_win_size: any, default = 1
See API documentation at link above or at help(remove_noise) for specifics.
- remove_raw_noise: any, default = False
See API documentation at link above or at help(remove_noise) for specifics.
- show_stalta_plot: any, default = False
See API documentation at link above or at help(remove_noise) for specifics.
- verbose: any, default = False
See API documentation at link above or at help(remove_noise) for specifics.
- generate_psdsfunction name (not an actual parameter)
Generates PPSDs for each channel See API documentation: [generate_psds()](https://sprit.readthedocs.io/en/latest/sprit.html#sprit.generate_psds)
- hvsr_data: any, default = ‘<output of previous function>’
See API documentation at link above or at help(sprit.generate_psds) for specifics.
- window_length: any, default = 30.0
See API documentation at link above or at help(generate_psds) for specifics.
- overlap_pct: any, default = 0.5
See API documentation at link above or at help(generate_psds) for specifics.
- window_type: any, default = ‘hann’
See API documentation at link above or at help(sprit.generate_psds) for specifics.
- window_length_method: any, default = ‘length’
See API documentation at link above or at help(sprit.generate_psds) for specifics.
- skip_on_gaps: any, default = True
See API documentation at link above or at help(generate_psds) for specifics.
- num_freq_bins: any, default = 500
See API documentation at link above or at help(generate_psds) for specifics.
- obspy_ppsds: any, default = False
See API documentation at link above or at help(generate_psds) for specifics.
- azimuthal_ppsds: any, default = False
See API documentation at link above or at help(generate_psds) for specifics.
- verbose: any, default = False
See API documentation at link above or at help(generate_psds) for specifics.
- plot_psds: any, default = False
See API documentation at link above or at help(generate_psds) for specifics.
- obspy_ppsd_kwargs: any, default = {}
See API documentation at link above or at help(generate_psds) for specifics.
- process_hvsrfunction name (not an actual parameter)
Process the input data and get HVSR data See API documentation: [process_hvsr()](https://sprit.readthedocs.io/en/latest/sprit.html#sprit.process_hvsr)
- hvsr_data: any, default = ‘<output of previous function>’
See API documentation at link above or at help(sprit.process_hvsr) for specifics.
- horizontal_method: any, default = None
See API documentation at link above or at help(process_hvsr) for specifics.
- smooth: any, default = True
See API documentation at link above or at help(process_hvsr) for specifics.
- freq_smooth: any, default = ‘konno ohmachi’
See API documentation at link above or at help(sprit.process_hvsr) for specifics.
- f_smooth_width: any, default = 40
See API documentation at link above or at help(process_hvsr) for specifics.
- resample: any, default = True
See API documentation at link above or at help(process_hvsr) for specifics.
- outlier_curve_rmse_percentile: any, default = False
See API documentation at link above or at help(process_hvsr) for specifics.
- azimuth: any, default = None
See API documentation at link above or at help(process_hvsr) for specifics.
- verbose: any, default = False
See API documentation at link above or at help(process_hvsr) for specifics.
- remove_outlier_curvesfunction name (not an actual parameter)
Function used to remove outliers curves using Root Mean Square Error to calculate the error of each See API documentation: [remove_outlier_curves()](https://sprit.readthedocs.io/en/latest/sprit.html#sprit.remove_outlier_curves)
- hvsr_data: any, default = ‘<output of previous function>’
See API documentation at link above or at help(sprit.remove_outlier_curves) for specifics.
- rmse_thresh: any, default = 98
See API documentation at link above or at help(remove_outlier_curves) for specifics.
- use_percentile: any, default = True
See API documentation at link above or at help(remove_outlier_curves) for specifics.
- use_hv_curve: any, default = False
See API documentation at link above or at help(remove_outlier_curves) for specifics.
- plot_engine: any, default = ‘matplotlib’
See API documentation at link above or at help(sprit.remove_outlier_curves) for specifics.
- show_plot: any, default = False
See API documentation at link above or at help(remove_outlier_curves) for specifics.
- verbose: any, default = False
See API documentation at link above or at help(remove_outlier_curves) for specifics.
- check_peaksfunction name (not an actual parameter)
Function to run tests on HVSR peaks to find best one and see if it passes quality checks See API documentation: [check_peaks()](https://sprit.readthedocs.io/en/latest/sprit.html#sprit.check_peaks)
- hvsr_data: any, default = ‘<output of previous function>’
See API documentation at link above or at help(sprit.check_peaks) for specifics.
- hvsr_band: any, default = [0.4, 40]
See API documentation at link above or at help(check_peaks) for specifics.
- peak_selection: any, default = ‘max’
See API documentation at link above or at help(sprit.check_peaks) for specifics.
- peak_freq_range: any, default = [0.4, 40]
See API documentation at link above or at help(check_peaks) for specifics.
- azimuth: any, default = ‘HV’
See API documentation at link above or at help(sprit.check_peaks) for specifics.
- verbose: any, default = False
See API documentation at link above or at help(check_peaks) for specifics.
- get_reportfunction name (not an actual parameter)
Generate and/or print and/or export a report of the HVSR analysis in a variety of formats. See API documentation: [get_report()](https://sprit.readthedocs.io/en/latest/sprit.html#sprit.get_report)
- hvsr_results: any, default = ‘<output of previous function>’
See API documentation at link above or at help(sprit.get_report) for specifics.
- report_formats: any, default = [‘print’, ‘table’, ‘plot’, ‘html’, ‘pdf’]
See API documentation at link above or at help(get_report) for specifics.
- azimuth: any, default = ‘HV’
See API documentation at link above or at help(sprit.get_report) for specifics.
- plot_type: any, default = ‘HVSR p ann COMP+ p ann SPEC p ann’
See API documentation at link above or at help(sprit.get_report) for specifics.
- plot_engine: any, default = ‘matplotlib’
See API documentation at link above or at help(sprit.get_report) for specifics.
- show_print_report: any, default = True
See API documentation at link above or at help(get_report) for specifics.
- show_table_report: any, default = False
See API documentation at link above or at help(get_report) for specifics.
- show_plot_report: any, default = True
See API documentation at link above or at help(get_report) for specifics.
- show_html_report: any, default = False
See API documentation at link above or at help(get_report) for specifics.
- show_pdf_report: any, default = True
See API documentation at link above or at help(get_report) for specifics.
- suppress_report_outputs: any, default = False
See API documentation at link above or at help(get_report) for specifics.
- show_report_outputs: any, default = False
See API documentation at link above or at help(get_report) for specifics.
- csv_handling: any, default = ‘append’
See API documentation at link above or at help(sprit.get_report) for specifics.
- report_export_format: any, default = None
See API documentation at link above or at help(get_report) for specifics.
- report_export_path: any, default = None
See API documentation at link above or at help(get_report) for specifics.
- verbose: any, default = False
See API documentation at link above or at help(get_report) for specifics.
- kwargs: any, default = {}
See API documentation at link above or at help(get_report) for specifics.
- export_datafunction name (not an actual parameter)
Export data into pickle format that can be read back in using import_data() so data does not need to See API documentation: [export_data()](https://sprit.readthedocs.io/en/latest/sprit.html#sprit.export_data)
- hvsr_data: any, default = ‘<output of previous function>’
See API documentation at link above or at help(sprit.export_data) for specifics.
- hvsr_export_path: any, default = None
See API documentation at link above or at help(export_data) for specifics.
- ext: any, default = ‘hvsr’
See API documentation at link above or at help(sprit.export_data) for specifics.
- verbose: any, default = False
See API documentation at link above or at help(export_data) for specifics.
- Returns:
- hvsr_resultssprit.HVSRData or sprit.HVSRBatch object
If a single file/data point is being processed, a HVSRData object will be returned. Otherwise, it will be a HVSRBatch object. See their documention for more information.
- Raises:
- RuntimeError
If the input parameter may not be read correctly. This is raised if the input_params() function fails. This raises an error since no other data processing or reading steps will be able to carried out correctly.
- RuntimeError
If the data is not read/fetched correctly using fetch_data(), an error will be raised. This is raised if the fetch_data() function fails. This raises an error since no other data processing steps will be able to carried out correctly.
- RuntimeError
If the data being processed is a single file, an error will be raised if generate_psds() does not work correctly. No errors are raised for remove_noise() errors (since that is an optional step) and the process_hvsr() step (since that is the last processing step) .
Notes
The sprit.run() function calls the following functions. This is the recommended order/set of functions to run to process HVSR using SpRIT. See the API documentation for these functions for more information: - input_params(): The input_data parameter of input_params() is the only required variable, though others may also need to be called for your data to process correctly. - fetch_data(): the source parameter of fetch_data() is the only explicit variable in the sprit.run() function aside from input_data and verbose. Everything else gets delivered to the correct function via the kwargs dictionary - remove_noise(): by default, the kind of noise removal is remove_method=’auto’. See the remove_noise() documentation for more information. If remove_method is set to anything other than one of the explicit options in remove_noise, noise removal will not be carried out. - generate_psds(): generates ppsds for each component, which will be combined/used later. Any parameter of obspy.signal.spectral_estimation.PPSD() may also be read into this function. - remove_outlier_curves(): removes any outlier ppsd curves so that the data quality for when curves are combined will be enhanced. See the remove_outlier_curves() documentation for more information. - process_hvsr(): this is the main function processing the hvsr curve and statistics. See process_hvsr() documentation for more details. The hvsr_band parameter sets the frequency spectrum over which these calculations occur. - check_peaks(): this is the main function that will find and ‘score’ peaks to get a best peak. The parameter peak_freq_range can be set to limit the frequencies within which peaks are checked and scored. - get_report(): this is the main function that will print, plot, and/or save the results of the data. See the get_report() API documentation for more information. - export_data(): this function exports the final data output as a pickle file (by default, this pickle object has a .hvsr extension). This can be used to read data back into SpRIT without having to reprocess data.