alpss 1.3.0.dev2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
alpss/__init__.py ADDED
File without changes
@@ -0,0 +1,102 @@
1
+ """
2
+ Credit to Michael Cho
3
+ https://michaelcho.me/article/using-pythons-watchdog-to-monitor-changes-to-a-directory
4
+ """
5
+
6
+ import time
7
+ from watchdog.observers import Observer
8
+ from watchdog.events import FileSystemEventHandler
9
+ from alpss_main import *
10
+ import os
11
+
12
+
13
+ class Watcher:
14
+
15
+ # this is the directory where you will add the files to
16
+ DIRECTORY_TO_WATCH = (os.getcwd() + '/input_data')
17
+
18
+ def __init__(self):
19
+ self.observer = Observer()
20
+
21
+ def run(self):
22
+ event_handler = Handler()
23
+ self.observer.schedule(event_handler, self.DIRECTORY_TO_WATCH, recursive=True)
24
+ self.observer.start()
25
+ try:
26
+ while True:
27
+ time.sleep(5)
28
+ except:
29
+ self.observer.stop()
30
+ print("Error")
31
+
32
+ self.observer.join()
33
+
34
+
35
+ class Handler(FileSystemEventHandler):
36
+
37
+ @staticmethod
38
+ def on_any_event(event):
39
+ if event.is_directory:
40
+ return None
41
+
42
+ elif event.event_type == 'created':
43
+
44
+ # Take any action here when a file is first created.
45
+ print("Received created event - %s." % event.src_path)
46
+
47
+ fname = os.path.split(event.src_path)[1]
48
+ print(f"File Created: {fname}")
49
+
50
+ # use these function inputs the same as for the non-automated function alpss_run.py
51
+ alpss_main(filename=fname,
52
+ save_data='yes',
53
+ start_time_user='none',
54
+ header_lines=1,
55
+ time_to_skip=2e-6,
56
+ time_to_take=2e-6,
57
+ t_before=10e-9,
58
+ t_after=100e-9,
59
+ start_time_correction=0e-9,
60
+ freq_min=1.5e9,
61
+ freq_max=4e9,
62
+ smoothing_window=401,
63
+ smoothing_wid=3,
64
+ smoothing_amp=1,
65
+ smoothing_sigma=1,
66
+ smoothing_mu=0,
67
+ pb_neighbors=400,
68
+ pb_idx_correction=0,
69
+ rc_neighbors=400,
70
+ rc_idx_correction=0,
71
+ sample_rate=80e9,
72
+ nperseg=512,
73
+ noverlap=435,
74
+ nfft=5120,
75
+ window='hann',
76
+ blur_kernel=(5, 5),
77
+ blur_sigx=0,
78
+ blur_sigy=0,
79
+ carrier_band_time=250e-9,
80
+ cmap='viridis',
81
+ uncert_mult=100,
82
+ order=6,
83
+ wid=5e7,
84
+ lam=1547.461e-9,
85
+ C0=4540,
86
+ density=1730,
87
+ delta_rho=9,
88
+ delta_C0=23,
89
+ delta_lam=8e-18,
90
+ theta=0,
91
+ delta_theta=5,
92
+ exp_data_dir=(os.getcwd() + '/input_data'),
93
+ out_files_dir=(os.getcwd() + '/output_data'),
94
+ display_plots='yes',
95
+ spall_calculation='yes',
96
+ plot_figsize=(30, 10),
97
+ plot_dpi=300)
98
+
99
+
100
+ if __name__ == '__main__':
101
+ w = Watcher()
102
+ w.run()
alpss/alpss_main.py ADDED
@@ -0,0 +1,121 @@
1
+ import os
2
+ from alpss.spall_doi_finder import spall_doi_finder
3
+ from alpss.plotting import plot_results, plot_voltage
4
+ from alpss.carrier_frequency import carrier_frequency
5
+ from alpss.carrier_filter import carrier_filter
6
+ from alpss.velocity_calculation import velocity_calculation
7
+ from alpss.spall_analysis import spall_analysis
8
+ from alpss.full_uncertainty_analysis import full_uncertainty_analysis
9
+ from alpss.instantaneous_uncertainty_analysis import instantaneous_uncertainty_analysis
10
+ from alpss.saving import save
11
+ from datetime import datetime
12
+ import traceback
13
+ import logging
14
+
15
+ logging.basicConfig(
16
+ level=logging.ERROR, # Minimum level of messages to log (can be DEBUG, INFO, WARNING, ERROR, CRITICAL)
17
+ format="%(asctime)s - %(levelname)s - %(message)s", # Log format (include timestamp, level, message)
18
+ handlers=[
19
+ logging.FileHandler("error_log.txt"), # Log to a file
20
+ logging.StreamHandler(), # Also log to console
21
+ ],
22
+ )
23
+
24
+
25
+ def validate_inputs(inputs):
26
+ if inputs["t_after"] > inputs["time_to_take"]:
27
+ raise ValueError("'t_after' must be less than 'time_to_take'. ")
28
+
29
+
30
+ # main function to link together all the sub-functions
31
+ def alpss_main(**inputs):
32
+ # validate the inputs for the run
33
+ validate_inputs(inputs)
34
+
35
+ # attempt to run the program in full
36
+ try:
37
+ # begin the program timer
38
+
39
+ start_time = datetime.now()
40
+
41
+ # function to find the spall signal domain of interest
42
+ sdf_out = spall_doi_finder(**inputs)
43
+
44
+ # function to find the carrier frequency
45
+ cen = carrier_frequency(sdf_out, **inputs)
46
+
47
+ # function to filter out the carrier frequency after the signal has started
48
+ cf_out = carrier_filter(sdf_out, cen, **inputs)
49
+
50
+ # function to calculate the velocity from the filtered voltage signal
51
+ vc_out = velocity_calculation(sdf_out, cen, cf_out, **inputs)
52
+
53
+ # function to estimate the instantaneous uncertainty for all points in time
54
+ iua_out = instantaneous_uncertainty_analysis(sdf_out, vc_out, cen, **inputs)
55
+
56
+ # function to find points of interest on the velocity trace
57
+ sa_out = spall_analysis(vc_out, iua_out, **inputs)
58
+
59
+ # function to calculate uncertainties in the spall strength and strain rate due to external uncertainties
60
+ fua_out = full_uncertainty_analysis(cen, sa_out, iua_out, **inputs)
61
+
62
+ # end the program timer
63
+ end_time = datetime.now()
64
+
65
+ # function to generate the final figure
66
+ fig = plot_results(
67
+ sdf_out,
68
+ cen,
69
+ cf_out,
70
+ vc_out,
71
+ sa_out,
72
+ iua_out,
73
+ fua_out,
74
+ start_time,
75
+ end_time,
76
+ **inputs,
77
+ )
78
+
79
+ # function to save the output files if desired
80
+ # MOVED to plotting
81
+ # end final timer and display full runtime
82
+ end_time2 = datetime.now()
83
+ logging.info(
84
+ f"\nFull program runtime (including plotting and saving):\n{end_time2 - start_time}\n"
85
+ )
86
+
87
+ # return the figure so it can be saved if desired
88
+ # function to save the output files if desired
89
+ if inputs["save_data"] == "yes":
90
+ df = save(
91
+ sdf_out,
92
+ cen,
93
+ vc_out,
94
+ sa_out,
95
+ iua_out,
96
+ fua_out,
97
+ start_time,
98
+ end_time,
99
+ fig,
100
+ **inputs,
101
+ )
102
+ return fig, df
103
+
104
+ return (fig,)
105
+
106
+ # in case the program throws an error
107
+ except Exception as e:
108
+ logging.error("Error in the execution of the main program:: %s", str(e))
109
+ logging.error("Traceback: %s", traceback.format_exc())
110
+
111
+ # attempt to plot the voltage signal from the imported data
112
+ try:
113
+ logging.info("Attempting a fallback visualization of the voltage signal...")
114
+ plot_voltage(**inputs)
115
+
116
+ # if that also fails then log the traceback and stop running the program
117
+ except Exception as e:
118
+ logging.error(
119
+ "Error in the fallback visualization of the voltage signal: %s", str(e)
120
+ )
121
+ logging.error("Traceback: %s", traceback.format_exc())