Skip to content

Commit

Permalink
fix error with settings read, update vernum
Browse files Browse the repository at this point in the history
  • Loading branch information
RJbalikian committed Oct 31, 2023
1 parent facedb9 commit 6198f51
Show file tree
Hide file tree
Showing 8 changed files with 568 additions and 126 deletions.
4 changes: 2 additions & 2 deletions conda/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package:
name: sprit
version: 0.1.50
version: 0.1.51

source:
git_url: https://github.com/RJbalikian/SPRIT-HVSR
git_tag: v0.1.50
git_tag: v0.1.51

build:
number: 0
Expand Down
2 changes: 1 addition & 1 deletion docs/generate_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#Whether to convert_md using markdown library (True), or let github do it (False)
convert_md=True
rtd_theme=False #Not currently working
release_version= '0.1.50'
release_version= '0.1.51'
run_tests=True
lint_it=True

Expand Down
243 changes: 207 additions & 36 deletions docs/main.html

Large diffs are not rendered by default.

404 changes: 332 additions & 72 deletions docs/sprit_hvsr.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "sprit"
authors = [{name="Riley Balikian"}, {name="Hongyu Xaio"}]
dynamic = ["readme"]
license = {file = "LICENSE"}
version="0.1.50"
version="0.1.51"
description = "A package for processing and analyzing HVSR (Horizontal to Vertical Spectral Ratio) data"
keywords = ["HVSR", "seismic", "horizontal to vertical spectral ratio", "obspy", 'geology', 'geophysics', 'geotechnical']
requires-python = ">=3.9"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
name="sprit",
author= "Riley Balikian",
author_email = "balikian@illinois.edu",
version="0.1.50",
version="0.1.51",
package_data={'sprit': ['resources/*', 'resources/icon/*', 'resources/themes/*', 'resources/themes/forest-dark/*',
'resources/themes/forest-light/*', 'resources/sample_data/*','resources/settings/*']},
long_description_content_type="text/markdown",
Expand Down
Binary file modified sprit/__pycache__/sprit_hvsr.cpython-310.pyc
Binary file not shown.
37 changes: 24 additions & 13 deletions sprit/sprit_hvsr.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ def run(datapath, source='file', verbose=False, **kwargs):
RuntimeError
If the data being processed is a single file, an error will be raised if generate_ppsds() 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) .
"""

if 'hvsr_band' not in kwargs.keys():
kwargs['hvsr_band'] = inspect.signature(input_params).parameters['hvsr_band'].default
if 'peak_freq_range' not in kwargs.keys():
Expand Down Expand Up @@ -775,7 +776,7 @@ def check_peaks(hvsr_data, hvsr_band=[0.4, 40], peak_selection='max', peak_freq_
defaultVDict = dict(zip(inspect.getfullargspec(check_peaks).args[1:],
inspect.getfullargspec(check_peaks).defaults))
# Manual input to function overrides the imported parameter values
if k in orig_args.keys() and orig_args[k]==defaultVDict[k]:
if (not isinstance(v, (HVSRData, HVSRBatch))) and (k in orig_args.keys()) and (orig_args[k]==defaultVDict[k]):
orig_args[k] = v

hvsr_band = orig_args['hvsr_band']
Expand Down Expand Up @@ -1129,10 +1130,12 @@ def export_settings(hvsr_data, export_settings_path='default', export_settings_t
print(f"Processing settings exported to {procSetFPath}")
print(f"{jsonString}")
print()

#Reads in traces to obspy stream
def fetch_data(params, source='file', trim_dir=None, export_format='mseed', detrend='spline', detrend_order=2, update_metadata=True, plot_input_stream=False, verbose=False, **kwargs):
#Get intput paramaters
orig_args = locals().copy()
start_time = datetime.datetime.now()

# Update with processing parameters specified previously in input_params, if applicable
if 'processing_parameters' in params.keys():
Expand All @@ -1142,7 +1145,7 @@ def fetch_data(params, source='file', trim_dir=None, export_format='mseed', detr
defaultVDict['kwargs'] = kwargs
for k, v in params['processing_parameters']['fetch_data'].items():
# Manual input to function overrides the imported parameter values
if k in orig_args.keys() and orig_args[k]==defaultVDict[k]:
if k!='params' and k in orig_args.keys() and orig_args[k]==defaultVDict[k]:
orig_args[k] = v

#Update local variables, in case of previously-specified parameters
Expand Down Expand Up @@ -1554,7 +1557,7 @@ def fetch_data(params, source='file', trim_dir=None, export_format='mseed', detr
for line in dataINStr:
print('\t',line)

params = _check_processing_status(params)
params = _check_processing_status(params, start_time=start_time, func_name=inspect.stack()[0][3], verbose=verbose)

return params

Expand Down Expand Up @@ -1589,7 +1592,9 @@ def generate_ppsds(hvsr_data, remove_outliers=True, outlier_std=3, verbose=False
Dictionary containing entries with ppsds for each channel
"""
#First, divide up for batch or not
print(locals())
orig_args = locals().copy() #Get the initial arguments
start_time = datetime.datetime.now()

ppsd_kwargs_sprit_defaults = ppsd_kwargs.copy()
#Set defaults here that are different than obspy defaults
Expand Down Expand Up @@ -1623,9 +1628,8 @@ def get_default_args(func):
inspect.getfullargspec(generate_ppsds).defaults))
defaultVDict['ppsd_kwargs'] = ppsd_kwargs
for k, v in hvsr_data['processing_parameters']['generate_ppsds'].items():

# Manual input to function overrides the imported parameter values
if k in orig_args.keys() and orig_args[k]==defaultVDict[k]:
if not isinstance(v, (HVSRData, HVSRBatch)) and (k in orig_args.keys()) and (orig_args[k]==defaultVDict[k]):
orig_args[k] = v

remove_outliers = orig_args['remove_outliers']
Expand Down Expand Up @@ -1833,7 +1837,7 @@ def convert_to_mpl_dates(obspyUTCDateTime):
hvsr_data['processing_parameters']['generate_ppsds'][key] = value

hvsr_data['ProcessingStatus']['PPSDStatus'] = True
hvsr_data = _check_processing_status(hvsr_data)
hvsr_data = _check_processing_status(hvsr_data, start_time=start_time, func_name=inspect.stack()[0][3], verbose=verbose)
return hvsr_data

#Gets the metadata for Raspberry Shake, specifically for 3D v.7
Expand Down Expand Up @@ -1974,7 +1978,7 @@ def get_report(hvsr_results, report_format='print', plot_type='HVSR p ann C+ p a
defaultVDict = dict(zip(inspect.getfullargspec(get_report).args[1:],
inspect.getfullargspec(get_report).defaults))
# Manual input to function overrides the imported parameter values
if k in orig_args.keys() and orig_args[k]==defaultVDict[k]:
if (not isinstance(v, (HVSRData, HVSRBatch))) and (k in orig_args.keys()) and (orig_args[k]==defaultVDict[k]):
orig_args[k] = v

report_format = orig_args['report_format']
Expand Down Expand Up @@ -2438,6 +2442,7 @@ def input_params(datapath,
"""
orig_args = locals().copy() #Get the initial arguments
start_time = datetime.datetime.now()

#Reformat times
if type(acq_date) is datetime.datetime:
Expand Down Expand Up @@ -2580,7 +2585,7 @@ def input_params(datapath,
#Format everything nicely
params = sprit_utils.make_it_classy(inputParamDict)
params['ProcessingStatus']['InputParams'] = True
params = _check_processing_status(params)
params = _check_processing_status(params, start_time=start_time, func_name=inspect.stack()[0][3], verbose=verbose)
return params

#Main function for plotting results
Expand Down Expand Up @@ -2934,6 +2939,7 @@ def process_hvsr(hvsr_data, method=3, smooth=True, freq_smooth='konno ohmachi',
"""
orig_args = locals().copy() #Get the initial arguments
start_time = datetime.datetime.now()

# Update with processing parameters specified previously in input_params, if applicable
if 'processing_parameters' in hvsr_data.keys():
Expand All @@ -2942,7 +2948,7 @@ def process_hvsr(hvsr_data, method=3, smooth=True, freq_smooth='konno ohmachi',
defaultVDict = dict(zip(inspect.getfullargspec(process_hvsr).args[1:],
inspect.getfullargspec(process_hvsr).defaults))
# Manual input to function overrides the imported parameter values
if k in orig_args.keys() and orig_args[k]==defaultVDict[k]:
if (not isinstance(v, (HVSRData, HVSRBatch))) and (k in orig_args.keys()) and (orig_args[k]==defaultVDict[k]):
orig_args[k] = v

method = orig_args['method']
Expand Down Expand Up @@ -3213,7 +3219,7 @@ def process_hvsr(hvsr_data, method=3, smooth=True, freq_smooth='konno ohmachi',
hvsr_out['input_stream'] = hvsr_dataUpdate['input_params']['input_stream'] #input_stream
hvsr_out = sprit_utils.make_it_classy(hvsr_out)
hvsr_out['ProcessingStatus']['HVStatus'] = True
hvsr_out = _check_processing_status(hvsr_out)
hvsr_out = _check_processing_status(hvsr_out, start_time=start_time, func_name=inspect.stack()[0][3], verbose=verbose)

hvsr_data['processing_parameters']['process_hvsr'] = {}
for key, value in orig_args.items():
Expand Down Expand Up @@ -3269,6 +3275,7 @@ def remove_noise(hvsr_data, remove_method='auto', sat_percent=0.995, noise_perce
"""
#Get intput paramaters
orig_args = locals().copy()
start_time = datetime.datetime.now()

# Update with processing parameters specified previously in input_params, if applicable
if 'processing_parameters' in hvsr_data.keys():
Expand Down Expand Up @@ -3420,7 +3427,7 @@ def remove_noise(hvsr_data, remove_method='auto', sat_percent=0.995, noise_perce
output['processing_parameters']['remove_noise'][key] = value

output['ProcessingStatus']['RemoveNoiseStatus'] = True
output = _check_processing_status(output)
output = _check_processing_status(output, start_time=start_time, func_name=inspect.stack()[0][3], verbose=verbose)

if 'hvsr_df' in output.keys() or ('params' in output.keys() and 'hvsr_df' in output['params'].keys())or ('input_params' in output.keys() and 'hvsr_df' in output['input_params'].keys()):
hvsrDF = output['hvsr_df']
Expand Down Expand Up @@ -3856,7 +3863,7 @@ def _process_hvsr_batch(**process_hvsr_kwargs):
return hvsr_data

#Special helper function that checks the processing status at each stage of processing to help determine if any processing steps were skipped
def _check_processing_status(hvsr_data):
def _check_processing_status(hvsr_data, start_time=datetime.datetime.now(), func_name='', verbose=False):
"""Internal function to check processing status, used primarily in the sprit.run() function to allow processing to continue if one site is bad.
Parameters
Expand Down Expand Up @@ -3889,7 +3896,11 @@ def _check_processing_status(hvsr_data):

if isinstance(hvsr_data, HVSRData):
hvsr_data = hvsr_interim[siteName]
return hvsr_data

if verbose:
elapsed = (datetime.datetime.now()-start_time)
print(f"\t\t{func_name} completed in {str(elapsed)[:-3]}")
return hvsr_data

#HELPER functions for fetch_data() and get_metadata()
#Read in metadata .inv file, specifically for RaspShake
Expand Down

0 comments on commit 6198f51

Please sign in to comment.