Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
RJbalikian committed Oct 18, 2023
1 parent 1193c25 commit 2d8560f
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 38 deletions.
Binary file added __pycache__/file_test.cpython-310-pytest-7.4.2.pyc
Binary file not shown.
Binary file added __pycache__/run_test.cpython-310-pytest-7.4.2.pyc
Binary file not shown.
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.48
version: 0.1.49

source:
git_url: https://github.com/RJbalikian/SPRIT-HVSR
git_tag: v0.1.48
git_tag: v0.1.49

build:
number: 0
Expand Down
20 changes: 18 additions & 2 deletions docs/generate_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#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.48'
release_version= '0.1.49'
run_tests=True
lint_it=True

currentDir = pathlib.Path((__file__)).parent
docsDir = currentDir
Expand All @@ -17,7 +19,7 @@
spritGUIPath = spritDir.joinpath('sprit_gui.py')
spritUtilsPath = spritDir.joinpath('sprit_utils.py')
spritCLIPath = spritDir.joinpath('sprit_cli.py')
spritPath = spritDir.joinpath('sprit_hvsr.py')
spritHVSRPath = spritDir.joinpath('sprit_hvsr.py')
resourcesDir = spritDir.joinpath('resources')
pyinstallerGUI = currentDir.joinpath('sprit_gui_COPY.py')

Expand Down Expand Up @@ -173,3 +175,17 @@

with open(cFile.as_posix(), 'w') as f:
f.write(cFileText)

if lint_it:
print('Running linting')
fileList = [spritGUIPath, spritCLIPath, spritUtilsPath, spritHVSRPath]
for fileP in fileList:
print(f'\nLINTING {fileP}')
ignoreList = ['E501']
strIgnoreList = "--ignore="+str(str(ignoreList)[1:-1].replace(' ', '').replace("'",""))
result = subprocess.run(['flake8', strIgnoreList, fileP.as_posix(),], stdout=subprocess.PIPE)
print(result.stdout.decode('utf-8'))

if run_tests:
print('Testing sprit.run()')
subprocess.run(["pytest", repoDir.as_posix()], shell=True)
4 changes: 2 additions & 2 deletions docs/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ <h2 id="parameters">Parameters</h2>
dataIN.merge()

params[&#39;batch&#39;] = False #Set False by default, will get corrected later in batch mode
params[&#39;input_stream&#39;]
params[&#39;input_stream&#39;] = dataIN.copy()
params[&#39;stream&#39;] = dataIN.copy()
params[&#39;ProcessingStatus&#39;][&#39;FetchDataStatus&#39;] = True
if verbose and not isinstance(params, HVSRBatch):
Expand Down Expand Up @@ -2365,7 +2365,7 @@ <h2 id="returns">Returns</h2>
</details>
</dd>
<dt id="sprit.input_params"><code class="name flex">
<span>def <span class="ident">input_params</span></span>(<span>datapath, site='HVSR Site', network='AM', station='RAC84', loc='00', channels=['EHZ', 'EHN', 'EHE'], acq_date='2023-10-17', starttime='00:00:00.00', endtime='23:59:59.999999', tzone='UTC', xcoord=-88.2290526, ycoord=40.1012122, elevation=755, input_crs='EPSG:4326', output_crs='EPSG:4326', elev_unit='feet', depth=0, instrument='Raspberry Shake', metapath='', hvsr_band=[0.4, 40], peak_freq_range=[0.4, 40], verbose=False)</span>
<span>def <span class="ident">input_params</span></span>(<span>datapath, site='HVSR Site', network='AM', station='RAC84', loc='00', channels=['EHZ', 'EHN', 'EHE'], acq_date='2023-10-18', starttime='00:00:00.00', endtime='23:59:59.999999', tzone='UTC', xcoord=-88.2290526, ycoord=40.1012122, elevation=755, input_crs='EPSG:4326', output_crs='EPSG:4326', elev_unit='feet', depth=0, instrument='Raspberry Shake', metapath='', hvsr_band=[0.4, 40], peak_freq_range=[0.4, 40], verbose=False)</span>
</code></dt>
<dd>
<div class="desc"><p>Function for designating input parameters for reading in and processing data</p>
Expand Down
18 changes: 10 additions & 8 deletions docs/sprit_hvsr.html
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,7 @@ <h1 class="title">Module <code>sprit.sprit_hvsr</code></h1>
dataIN.merge()

params[&#39;batch&#39;] = False #Set False by default, will get corrected later in batch mode
params[&#39;input_stream&#39;]
params[&#39;input_stream&#39;] = dataIN.copy()
params[&#39;stream&#39;] = dataIN.copy()
params[&#39;ProcessingStatus&#39;][&#39;FetchDataStatus&#39;] = True
if verbose and not isinstance(params, HVSRBatch):
Expand Down Expand Up @@ -6047,6 +6047,7 @@ <h1 class="title">Module <code>sprit.sprit_hvsr</code></h1>

return _peak


#Check stability
def __check_stability(_stdf, _peak, _hvsr_log_std, rank):
&#34;&#34;&#34;Test peaks for satisfying stability conditions as outlined by SESAME 2004
Expand Down Expand Up @@ -6189,6 +6190,7 @@ <h1 class="title">Module <code>sprit.sprit_hvsr</code></h1>

return _peak


#Get frequency standard deviation
def __get_stdf(x_values, indexList, hvsrPeaks):
&#34;&#34;&#34;Private function to get frequency standard deviation, from multiple time-step HVSR curves&#34;&#34;&#34;
Expand All @@ -6201,17 +6203,17 @@ <h1 class="title">Module <code>sprit.sprit_hvsr</code></h1>
if p is None:
p = hvsrPeaks.iloc[j][k]
else:
#Find closest peak in current time to (current) main hvsr peak
# Find closest peak in current time to (current) hvsr peak
if abs(index - hvsrPeaks.iloc[j][k]) &lt; abs(index - p):
p = hvsrPeaks.iloc[j][k]
#p = hvsrPeaks[j][k]
#print(p=p1, p, p1)
# p = hvsrPeaks[j][k]
# print(p=p1, p, p1)
if p is not None:
point.append(p)
point.append(index)
v = list()
for l in range(len(point)):
v.append(x_values[point[l]])
for pl in range(len(point)):
v.append(x_values[point[pl]])
stdf.append(np.std(v))
return stdf</code></pre>
</details>
Expand Down Expand Up @@ -7096,7 +7098,7 @@ <h2 id="parameters">Parameters</h2>
dataIN.merge()

params[&#39;batch&#39;] = False #Set False by default, will get corrected later in batch mode
params[&#39;input_stream&#39;]
params[&#39;input_stream&#39;] = dataIN.copy()
params[&#39;stream&#39;] = dataIN.copy()
params[&#39;ProcessingStatus&#39;][&#39;FetchDataStatus&#39;] = True
if verbose and not isinstance(params, HVSRBatch):
Expand Down Expand Up @@ -7963,7 +7965,7 @@ <h2 id="returns">Returns</h2>
</details>
</dd>
<dt id="sprit.sprit_hvsr.input_params"><code class="name flex">
<span>def <span class="ident">input_params</span></span>(<span>datapath, site='HVSR Site', network='AM', station='RAC84', loc='00', channels=['EHZ', 'EHN', 'EHE'], acq_date='2023-10-17', starttime='00:00:00.00', endtime='23:59:59.999999', tzone='UTC', xcoord=-88.2290526, ycoord=40.1012122, elevation=755, input_crs='EPSG:4326', output_crs='EPSG:4326', elev_unit='feet', depth=0, instrument='Raspberry Shake', metapath='', hvsr_band=[0.4, 40], peak_freq_range=[0.4, 40], verbose=False)</span>
<span>def <span class="ident">input_params</span></span>(<span>datapath, site='HVSR Site', network='AM', station='RAC84', loc='00', channels=['EHZ', 'EHN', 'EHE'], acq_date='2023-10-18', starttime='00:00:00.00', endtime='23:59:59.999999', tzone='UTC', xcoord=-88.2290526, ycoord=40.1012122, elevation=755, input_crs='EPSG:4326', output_crs='EPSG:4326', elev_unit='feet', depth=0, instrument='Raspberry Shake', metapath='', hvsr_band=[0.4, 40], peak_freq_range=[0.4, 40], verbose=False)</span>
</code></dt>
<dd>
<div class="desc"><p>Function for designating input parameters for reading in and processing data</p>
Expand Down
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.48"
version="0.1.49"
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
10 changes: 10 additions & 0 deletions run_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import sprit

def test_run():
try:
sprit.run("sample")
test_passed = True
except:
test_passed = False

assert test_passed
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 = "[email protected]",
version="0.1.48",
version="0.1.49",
package_data={'sprit': ['resources/*', 'resources/icon/*', 'resources/themes/*', 'resources/themes/forest-dark/*', 'resources/themes/forest-light/*', 'resources/sample_data/*',]},
long_description_content_type="text/markdown",
long_description=long_description,
Expand Down
Binary file modified sprit/__pycache__/sprit_hvsr.cpython-310.pyc
Binary file not shown.
44 changes: 22 additions & 22 deletions sprit/sprit_hvsr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,7 @@ def fetch_data(params, source='file', trim_dir=None, export_format='mseed', detr
dataIN.merge()

params['batch'] = False #Set False by default, will get corrected later in batch mode
params['input_stream']
params['input_stream'] = dataIN.copy()
params['stream'] = dataIN.copy()
params['ProcessingStatus']['FetchDataStatus'] = True
if verbose and not isinstance(params, HVSRBatch):
Expand Down Expand Up @@ -5720,8 +5720,8 @@ def _plot_specgram_stream(stream, params=None, component='Z', stack_type='linear

return

##Helper functions for checking peaks
#Initialize peaks
# HELPER functions for checking peaks
# Initialize peaks
def __init_peaks(_x, _y, _index_list, _hvsr_band, peak_freq_range=[0.4, 40], _min_peak_amp=1):
""" Initialize peaks.
Expand Down Expand Up @@ -5759,7 +5759,7 @@ def __init_peaks(_x, _y, _index_list, _hvsr_band, peak_freq_range=[0.4, 40], _mi
'PeakPasses':False})
return _peak

#Check reliability of HVSR of curve
# Check reliability of HVSR of curve
def __check_curve_reliability(hvsr_data, _peak):
"""Tests to check for reliable H/V curve
Expand Down Expand Up @@ -5938,7 +5938,7 @@ def __check_clarity(_x, _y, _peak, do_rank=True):

return _peak

#Check the stability of the frequency peak
# Check the stability of the frequency peak
def __check_freq_stability(_peak, _peakm, _peakp):
"""Test peaks for satisfying stability conditions
Expand All @@ -5962,12 +5962,10 @@ def __check_freq_stability(_peak, _peakm, _peakp):
"""
global max_rank

#
# check σf and σA
#
max_rank += 1

#First check below
# First check below
_found_m = list()
for _i in range(len(_peak)):
_dx = 1000000.
Expand All @@ -5986,12 +5984,12 @@ def __check_freq_stability(_peak, _peakm, _peakp):
_peak[_i]['Report']['P-'] = '%0.3f within ±5%s of %0.3f %1s' % (_peakm[_j]['f0'], '%', ##changed i to j
_peak[_i]['f0'], '✘')

#Then Check above
# Then Check above
_found_p = list()
for _i in range(len(_peak)):
_dx = 1000000.
_found_p.append(False)
_peak[_i]['Report']['P+'] = '✘'
_peak[_i]['Report']['P+'] = sprit_utils.x_mark()
for _j in range(len(_peakp)):
if abs(_peakp[_j]['f0'] - _peak[_i]['f0']) < _dx:
_index = _j
Expand All @@ -6010,13 +6008,14 @@ def __check_freq_stability(_peak, _peakm, _peakp):
else:
_peak[_i]['Report']['P+'] = '%0.3f within ±5%s of %0.3f %1s' % (_peakp[_j]['f0'], '%', _peak[_i]['f0'], '✘')
_peak[_i]['PassList']['FreqStability'] = False
if _peak[_i]['Report']['P+'] == '✘' and len(_peakp) > 0:
if _peak[_i]['Report']['P+'] == sprit_utils.x_mark() and len(_peakp) > 0:
_peak[_i]['Report']['P+'] = '%0.3f within ±5%s of %0.3f %1s' % (
_peakp[_j]['f0'], '%', _peak[_i]['f0'], '✘')###changed i to j
_peakp[_j]['f0'], '%', _peak[_i]['f0'], sprit_utils.x_mark()) #changed i to j

return _peak

#Check stability

# Check stability
def __check_stability(_stdf, _peak, _hvsr_log_std, rank):
"""Test peaks for satisfying stability conditions as outlined by SESAME 2004
This includes:
Expand All @@ -6033,12 +6032,12 @@ def __check_stability(_stdf, _peak, _hvsr_log_std, rank):
_hvsr_log_std : list
List of dictionaries containing log standard deviation along curve
rank : int
Integer value, higher value is "higher-ranked" peak, helps determine which peak is actual hvsr peak
Integer value, higher value is "higher-ranked" peak, helps determine which peak is actual hvsr peak
Returns
-------
_peak : list
List of dictionaries containing output information about peak test
List of dictionaries containing output information about peak test
"""

global max_rank
Expand Down Expand Up @@ -6158,7 +6157,8 @@ def __check_stability(_stdf, _peak, _hvsr_log_std, rank):

return _peak

#Get frequency standard deviation

# Get frequency standard deviation
def __get_stdf(x_values, indexList, hvsrPeaks):
"""Private function to get frequency standard deviation, from multiple time-step HVSR curves"""
stdf = list()
Expand All @@ -6170,16 +6170,16 @@ def __get_stdf(x_values, indexList, hvsrPeaks):
if p is None:
p = hvsrPeaks.iloc[j][k]
else:
#Find closest peak in current time to (current) main hvsr peak
# Find closest peak in current time to (current) hvsr peak
if abs(index - hvsrPeaks.iloc[j][k]) < abs(index - p):
p = hvsrPeaks.iloc[j][k]
#p = hvsrPeaks[j][k]
#print(p=p1, p, p1)
# p = hvsrPeaks[j][k]
# print(p=p1, p, p1)
if p is not None:
point.append(p)
point.append(index)
v = list()
for l in range(len(point)):
v.append(x_values[point[l]])
for pl in range(len(point)):
v.append(x_values[point[pl]])
stdf.append(np.std(v))
return stdf
return stdf

0 comments on commit 2d8560f

Please sign in to comment.