Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
RJbalikian committed Oct 30, 2023
2 parents 5cf5af2 + 7ea0d12 commit facedb9
Show file tree
Hide file tree
Showing 20 changed files with 3,531 additions and 1,231 deletions.
803 changes: 640 additions & 163 deletions docs/main.html

Large diffs are not rendered by default.

183 changes: 149 additions & 34 deletions docs/sprit_gui.html

Large diffs are not rendered by default.

2,162 changes: 1,565 additions & 597 deletions docs/sprit_hvsr.html

Large diffs are not rendered by default.

28 changes: 24 additions & 4 deletions docs/sprit_utils.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ <h1 class="title">Module <code>sprit.sprit_utils</code></h1>
channel_order = {&#39;Z&#39;: 0, &#39;1&#39;: 1, &#39;N&#39;: 1, &#39;2&#39;: 2, &#39;E&#39;: 2}

def check_gui_requirements():
print(&#34;Checking requirements for gui&#34;)
#First, check requirements
# Define a command that tries to open a window
command = &#34;python -c \&#34;import tkinter; tkinter.Tk()\&#34;&#34;

Expand All @@ -60,7 +60,7 @@ <h1 class="title">Module <code>sprit.sprit_utils</code></h1>
oktoproceed=True
else:
oktoproceed=False
print(&#34;GUI window could not be created.&#34;)
print(&#34;GUI window cannot be created.&#34;)

return oktoproceed

Expand Down Expand Up @@ -339,6 +339,16 @@ <h1 class="title">Module <code>sprit.sprit_utils</code></h1>
#Make input data (dict) into sprit_hvsr class
def make_it_classy(input_data, verbose=False):
if isinstance(input_data, (sprit_hvsr.HVSRData, sprit_hvsr.HVSRBatch)):
for k, v in input_data.items():
if k==&#39;input_params&#39;:
for kin in input_data[&#39;input_params&#39;].keys():
if kin not in input_data.keys():
input_data[kin] = input_data[&#39;input_params&#39;][kin]
if k==&#39;params&#39;:
for kin in input_data[&#39;params&#39;].keys():
print(kin)
if kin not in input_data.keys():
input_data[kin] = input_data[&#39;params&#39;][kin]
output_class = input_data
else:
output_class = sprit_hvsr.HVSRData(input_data)
Expand Down Expand Up @@ -464,7 +474,7 @@ <h2 class="section-title" id="header-functions">Functions</h2>
<span>Expand source code</span>
</summary>
<pre><code class="python">def check_gui_requirements():
print(&#34;Checking requirements for gui&#34;)
#First, check requirements
# Define a command that tries to open a window
command = &#34;python -c \&#34;import tkinter; tkinter.Tk()\&#34;&#34;

Expand All @@ -477,7 +487,7 @@ <h2 class="section-title" id="header-functions">Functions</h2>
oktoproceed=True
else:
oktoproceed=False
print(&#34;GUI window could not be created.&#34;)
print(&#34;GUI window cannot be created.&#34;)

return oktoproceed

Expand Down Expand Up @@ -855,6 +865,16 @@ <h2 id="returns">Returns</h2>
</summary>
<pre><code class="python">def make_it_classy(input_data, verbose=False):
if isinstance(input_data, (sprit_hvsr.HVSRData, sprit_hvsr.HVSRBatch)):
for k, v in input_data.items():
if k==&#39;input_params&#39;:
for kin in input_data[&#39;input_params&#39;].keys():
if kin not in input_data.keys():
input_data[kin] = input_data[&#39;input_params&#39;][kin]
if k==&#39;params&#39;:
for kin in input_data[&#39;params&#39;].keys():
print(kin)
if kin not in input_data.keys():
input_data[kin] = input_data[&#39;params&#39;][kin]
output_class = input_data
else:
output_class = sprit_hvsr.HVSRData(input_data)
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
author= "Riley Balikian",
author_email = "balikian@illinois.edu",
version="0.1.50",
package_data={'sprit': ['resources/*', 'resources/icon/*', 'resources/themes/*', 'resources/themes/forest-dark/*', 'resources/themes/forest-light/*', 'resources/sample_data/*',]},
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",
long_description=long_description,
packages=find_packages(),
Expand Down
6 changes: 5 additions & 1 deletion sprit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
from sprit.sprit_hvsr import(
run,
export_data,
export_settings,
import_data,
import_settings,
input_params,
gui,
get_metadata,
Expand Down Expand Up @@ -51,8 +53,10 @@
'get_char',
'time_it',
'checkifpath',
'export_data',
'export_data',
'export_settings',
'import_data',
'import_settings',
'input_params',
'gui',
'get_metadata',
Expand Down
Binary file modified sprit/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file modified sprit/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file modified sprit/__pycache__/sprit_gui.cpython-310.pyc
Binary file not shown.
Binary file modified sprit/__pycache__/sprit_gui.cpython-311.pyc
Binary file not shown.
Binary file modified sprit/__pycache__/sprit_hvsr.cpython-310.pyc
Binary file not shown.
Binary file modified sprit/__pycache__/sprit_hvsr.cpython-311.pyc
Binary file not shown.
Binary file modified sprit/__pycache__/sprit_utils.cpython-310.pyc
Binary file not shown.
Binary file modified sprit/__pycache__/sprit_utils.cpython-311.pyc
Binary file not shown.
1 change: 1 addition & 0 deletions sprit/resources/settings/gui_theme.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"theme_name": "alt"}
10 changes: 10 additions & 0 deletions sprit/resources/settings/instrument_settings.inst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"instrument": "Raspberry Shake",
"net": "AM",
"sta": "RAC84",
"loc": "00",
"cha": ["EHZ", "EHN", "EHE"],
"depth": 0,
"metapath": "c:/Users/balikian/LocalData/CodesScripts/Github/SPRIT-HVSR/sprit/resources/rs3dv5plus_metadata.inv",
"hvsr_band": [0.4, 40]
}
69 changes: 69 additions & 0 deletions sprit/resources/settings/processing_settings.proc
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"fetch_data":
{
"source": "file",
"trim_dir": null,
"export_format": "mseed",
"detrend": "spline",
"detrend_order": 2,
"update_metadata": true,
"plot_input_stream": false,
"verbose": false,
"kwargs":
{}
},

"remove_noise":
{
"remove_method": "auto",
"sat_percent": 0.995,
"noise_percent": 0.8,
"sta": 2,
"lta": 30,
"stalta_thresh": [ 0.5, 5 ],
"warmup_time": 0,
"cooldown_time": 0,
"min_win_size": 1,
"remove_raw_noise": false,
"verbose": false
},

"generate_ppsds":
{
"remove_outliers": true,
"outlier_std": 3,
"verbose": false,
"ppsd_kwargs":
{ "skip_on_gaps": true, "db_bins": [ -200, -50, 1.0 ], "ppsd_length": 30.0, "overlap": 0.5, "special_handling": null, "period_smoothing_width_octaves": 1.0, "period_step_octaves": 0.03125, "period_limits": [ 0.025, 2.5 ] }
},

"process_hvsr":
{
"method": 3,
"smooth": true,
"freq_smooth": "konno ohmachi",
"f_smooth_width": 40,
"resample": true,
"outlier_curve_std": 1.75,
"verbose": false
},

"check_peaks":
{
"hvsr_band": [ 0.4, 40 ],
"peak_selection": "max",
"peak_freq_range": [ 0.4, 40 ],
"verbose": false
},

"get_report":
{
"report_format": "print",
"plot_type": "HVSR p ann C+ p ann Spec",
"export_path": null,
"return_results": false,
"csv_overwrite_opt": "append",
"no_output": false,
"verbose": false
}
}
69 changes: 57 additions & 12 deletions sprit/sprit_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import datetime
import functools
import linecache
import json
import os
import pathlib
import pkg_resources
Expand Down Expand Up @@ -34,6 +35,14 @@
pass

global spritApp
global current_theme_name

resource_dir = pathlib.Path(pkg_resources.resource_filename(__name__, 'resources/'))
settings_dir = resource_dir.joinpath('settings')
gui_theme_file = settings_dir.joinpath('gui_theme.json')
with open(gui_theme_file, 'r') as f:
curr_gui_dict = json.load(f)
current_theme_name = curr_gui_dict['theme_name']

#Decorator that catches errors and warnings (to be modified later for gui)
def catch_errors(func):
Expand Down Expand Up @@ -151,10 +160,11 @@ def __init__(self, master):
self.darkthemepath = pathlib.Path(pkg_resources.resource_filename(__name__, "resources/themes/forest-dark.tcl"))
self.lightthemepath = pathlib.Path(pkg_resources.resource_filename(__name__, "resources/themes/forest-light.tcl"))



# Create the style object
self.style = ttk.Style(master)
self.master.tk.call('source', self.lightthemepath)
#self.style.theme_use('default')
#
#self.style.theme_use('forest-light')

self.create_menubar()
Expand All @@ -164,6 +174,13 @@ def __init__(self, master):
self.master.columnconfigure(0, weight=1)


if 'forest' in current_theme_name:
if 'light' in current_theme_name:
self.master.tk.call('source', self.lightthemepath)
else:
self.master.tk.call('source', self.darkthemepath)
else:
self.style.theme_use(current_theme_name)
# Create the dark theme
#self.style.theme_create("dark", parent="alt", settings={
# "TLabel": {"configure": {"background": "black", "foreground": "white"}},
Expand Down Expand Up @@ -211,7 +228,33 @@ def create_menubar(self):
def on_theme_select():
# Set the theme based on the selected value
self.style = ttk.Style()


#Update the theme file so the new theme opens on reboot
prev_theme = curr_gui_dict['theme_name']
curr_gui_dict['theme_name'] = self.theme_var.get()
with open(gui_theme_file, 'w') as f:
json.dump(curr_gui_dict, f)

def apply_theme():
if 'forest' in self.theme_var.get():
if self.theme_var.get()=='forest-dark' and 'forest-dark' not in self.style.theme_names():
self.master.tk.call('source', self.darkthemepath)
elif self.theme_var.get()=='forest-light' and 'forest-light' not in self.style.theme_names():
self.master.tk.call('source', self.lightthemepath)
self.master.tk.call("ttk::style", "theme", "use", self.theme_var.get())

if curr_gui_dict['theme_name']=='forest-light' or curr_gui_dict['theme_name'] == 'forest-dark':
do_reboot = messagebox.askyesno('App Restart Required',
f"It is recommended to restart the SpRIT GUI at this time to apply this theme. If not, you may continue but theme errors may occur. Click No to retain current theme ({prev_theme}) \nReboot now?",
)
print(do_reboot)
if do_reboot:
reboot_app()
else:
self.theme_var.set(prev_theme)
else:
apply_theme()

"""An attempt to get the backgrounds right
def apply_to_all_children(widget, func):
Recursively apply a function to all child widgets of a given widget
Expand All @@ -229,12 +272,7 @@ def change_background_color(widget):
apply_to_all_children(self.master, change_background_color)
"""
if 'forest' in self.theme_var.get():
if self.theme_var.get()=='forest-dark' and 'forest-dark' not in self.style.theme_names():
self.master.tk.call('source', self.darkthemepath)
elif self.theme_var.get()=='forest-light' and 'forest-light' not in self.style.theme_names():
self.master.tk.call('source', self.lightthemepath)
self.master.tk.call("ttk::style", "theme", "use", self.theme_var.get())

#self.master.tk.call("ttk::setTheme", self.theme_var.get())

#self.style.theme_use(self.theme_var.get())
Expand All @@ -250,7 +288,7 @@ def export_parameters(self):
filepath = filedialog.asksaveasfilename()

self.theme_menu = tk.Menu(self.menubar, tearoff=0)
self.theme_var = tk.StringVar(value="Default")
self.theme_var = tk.StringVar(value=current_theme_name)
self.theme_menu.add_radiobutton(label="Default", variable=self.theme_var, value="default", command=on_theme_select)
self.theme_menu.add_radiobutton(label="Clam", variable=self.theme_var, value="clam", command=on_theme_select)
self.theme_menu.add_radiobutton(label="Alt", variable=self.theme_var, value="alt", command=on_theme_select)
Expand Down Expand Up @@ -495,8 +533,8 @@ def report_results(hvsr_results):
self.peakTest6ResultText.configure(text=hvsr_results['BestPeak']['Report']['Sa'][:-1])
self.peakTest6Result.configure(text=hvsr_results['BestPeak']['Report']['Sa'][-1])

peakPass = (hvsr_results['BestPeak']['PassList']['PeakFreqClarityBelow'] +
hvsr_results['BestPeak']['PassList']['PeakFreqClarityAbove']+
peakPass = (hvsr_results['BestPeak']['PassList']['PeakProminenceBelow'] +
hvsr_results['BestPeak']['PassList']['PeakProminenceAbove']+
hvsr_results['BestPeak']['PassList']['PeakAmpClarity']+
hvsr_results['BestPeak']['PassList']['FreqStability']+
hvsr_results['BestPeak']['PassList']['PeakStability_FreqStD']+
Expand Down Expand Up @@ -3036,6 +3074,13 @@ def on_closing():
root.destroy()
exit()

def reboot_app():
"""Restarts the current program.
Note: this function does not return. Any cleanup action (like
saving data) must be done before calling this function."""
python = sys.executable
os.execl(python, python, * sys.argv)

if __name__ == "__main__":
can_gui = sprit_utils.check_gui_requirements()

Expand Down
Loading

0 comments on commit facedb9

Please sign in to comment.