Skip to content
Open
27 changes: 14 additions & 13 deletions packs/ana/ana.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,22 @@ def ana(config_file : str) -> (np.ndarray):

window_overlap_check(window_args)

if isinstance(conf_args["files"], list):
print("Averaging waveform....")

avgwf = average_waveforms(**conf_args)

checked_save_path = check_save_path(
save_path,
overwrite
if not isinstance(conf_args["files"], list):
raise TypeError(
f"'files' must be a list of file paths, got {type(conf_args['files']).__name__}"
)
print("Averaging waveform....")

checked_save_path = check_save_path(
save_path,
overwrite
)

avgwf = average_waveforms(**conf_args)

with h5py.File(checked_save_path, 'w') as f: # Save as a h5
f.create_dataset('Average_waveform', data=avgwf)
with h5py.File(checked_save_path, 'w') as f: # Save as a h5
f.create_dataset('Average_waveform', data=avgwf)

print(f"Saved to: {checked_save_path}")
print(f"Saved to: {checked_save_path}")

else:
print("Please input files as a list.")
return
10 changes: 5 additions & 5 deletions packs/ana/analysis_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,11 @@ def window_overlap_check(window_args: dict):
# Define intervals
w_start, w_end = WINDOW_START, WINDOW_END

b1_start = BASELINE_POINT_1 - BASELINE_RANGE_1 / 2
b1_end = BASELINE_POINT_1 + BASELINE_RANGE_1 / 2
b1_start = BASELINE_POINT_1 - BASELINE_RANGE_1
b1_end = BASELINE_POINT_1 + BASELINE_RANGE_1

b2_start = BASELINE_POINT_2 - BASELINE_RANGE_2 / 2
b2_end = BASELINE_POINT_2 + BASELINE_RANGE_2 / 2
b2_start = BASELINE_POINT_2 - BASELINE_RANGE_2
b2_end = BASELINE_POINT_2 + BASELINE_RANGE_2

# Check for negative values
if (w_start < 0 or w_end < 0 or
Expand Down Expand Up @@ -290,7 +290,7 @@ def window_wf_check(wf : np.ndarray,
BASELINE_POINT_2 = window_args['BASELINE_POINT_2']
BASELINE_RANGE_1 = window_args['BASELINE_RANGE_1']
BASELINE_RANGE_2 = window_args['BASELINE_RANGE_2']
if WINDOW_START>length or WINDOW_END>length or BASELINE_POINT_1+BASELINE_RANGE_1/2>length or BASELINE_POINT_2+BASELINE_RANGE_2>length:
if WINDOW_START>length or WINDOW_END>length or BASELINE_POINT_1+BASELINE_RANGE_1>length or BASELINE_POINT_2+BASELINE_RANGE_2>length:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was there a factor 1/2 here?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be worth including something in the commit description to explain why this happened, considering you're the creator that included them initially ;)

return False
else:
return True
5 changes: 3 additions & 2 deletions packs/proc/processing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,9 @@ def check_save_path(save_path: str,
------
FileNotFoundError : If the directory of save_path does not exist
'''
if not os.path.exists(os.path.dirname(save_path)):
raise FileNotFoundError(2, 'Save path not found', os.path.dirname(save_path))
dirname = os.path.dirname(os.path.abspath(save_path))
if not os.path.exists(dirname):
raise FileNotFoundError(2, 'Save path not found', dirname)

if overwrite:
return save_path
Expand Down
21 changes: 21 additions & 0 deletions packs/tests/data/configs/ana_bad_baseline_mode.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[required]

files = ['run19.h5']

window_args = {'WINDOW_START' : 100,
'WINDOW_END' : 3e4,
'BASELINE_POINT_1' : 1e6,
'BASELINE_POINT_2' : 1.5e6,
'BASELINE_RANGE_1' : 40e3,
'BASELINE_RANGE_2' : 40e3}

bin_size = 4
chunk_size = 5
negative = True
baseline_mode = 'three hundred baselines please'
verbose = 1
peak_threshold = 1000
suppression_threshold = 10

overwrite = True
save_path = 'test.h5'
21 changes: 21 additions & 0 deletions packs/tests/data/configs/ana_baseline_overlaps_window.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[required]

files = ['run19.h5']

window_args = {'WINDOW_START' : 4e2,
'WINDOW_END' : 2e6,
'BASELINE_POINT_1' : 1e6,
'BASELINE_POINT_2' : 1.5e6,
'BASELINE_RANGE_1' : 40e3,
'BASELINE_RANGE_2' : 40e3}

bin_size = 4
chunk_size = 5
negative = True
baseline_mode = 'median'
verbose = 1
peak_threshold = 1000
suppression_threshold = 10

overwrite = True
save_path = 'test.h5'
21 changes: 21 additions & 0 deletions packs/tests/data/configs/ana_baselines_overlap.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[required]

files = ['run19.h5']

window_args = {'WINDOW_START' : 100,
'WINDOW_END' : 3e4,
'BASELINE_POINT_1' : 1e6,
'BASELINE_POINT_2' : 1.01e6,
'BASELINE_RANGE_1' : 40e3,
'BASELINE_RANGE_2' : 40e3}

bin_size = 4
chunk_size = 5
negative = True
baseline_mode = 'median'
verbose = 1
peak_threshold = 1000
suppression_threshold = 10

overwrite = True
save_path = 'test.h5'
21 changes: 21 additions & 0 deletions packs/tests/data/configs/ana_empty_files.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[required]

files = ['']

window_args = {'WINDOW_START' : 100,
'WINDOW_END' : 3e4,
'BASELINE_POINT_1' : 1e6,
'BASELINE_POINT_2' : 1.5e6,
'BASELINE_RANGE_1' : 40e3,
'BASELINE_RANGE_2' : 40e3}

bin_size = 4
chunk_size = 5
negative = True
baseline_mode = 'median'
verbose = 1
peak_threshold = 1000
suppression_threshold = 10

overwrite = True
save_path = 'test.h5'
21 changes: 21 additions & 0 deletions packs/tests/data/configs/ana_files_not_list.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[required]

files = 'run19.h5'

window_args = {'WINDOW_START' : 100,
'WINDOW_END' : 3e4,
'BASELINE_POINT_1' : 1e6,
'BASELINE_POINT_2' : 1.5e6,
'BASELINE_RANGE_1' : 40e3,
'BASELINE_RANGE_2' : 40e3}

bin_size = 4
chunk_size = 5
negative = True
baseline_mode = 'median'
verbose = 1
peak_threshold = 1000
suppression_threshold = 10

overwrite = True
save_path = 'test.h5'
21 changes: 21 additions & 0 deletions packs/tests/data/configs/ana_inverted_window.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[required]

files = ['run19.h5']

window_args = {'WINDOW_START' : 3e4,
'WINDOW_END' : 4e2,
'BASELINE_POINT_1' : 1e6,
'BASELINE_POINT_2' : 1.5e6,
'BASELINE_RANGE_1' : 40e3,
'BASELINE_RANGE_2' : 40e3}

bin_size = 4
chunk_size = 5
negative = True
baseline_mode = 'median'
verbose = 1
peak_threshold = 1000
suppression_threshold = 10

overwrite = True
save_path = 'test.h5'
21 changes: 21 additions & 0 deletions packs/tests/data/configs/ana_missing_bin_size.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[required]

files = ['run19.h5']

window_args = {'WINDOW_START' : 100,
'WINDOW_END' : 3e4,
'BASELINE_POINT_1' : 1e6,
'BASELINE_POINT_2' : 1.5e6,
'BASELINE_RANGE_1' : 40e3,
'BASELINE_RANGE_2' : 40e3}


chunk_size = 5
negative = True
baseline_mode = 'median'
verbose = 1
peak_threshold = 1000
suppression_threshold = 10

overwrite = True
save_path = 'test.h5'
20 changes: 20 additions & 0 deletions packs/tests/data/configs/ana_missing_save_path.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[required]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the configs that are just 'missing argument' can be generalised with a fixture, lets sit down and I can show you how to do this soon :)

files = ['run19.h5']

window_args = {'WINDOW_START' : 100,
'WINDOW_END' : 3e4,
'BASELINE_POINT_1' : 1e6,
'BASELINE_POINT_2' : 1.5e6,
'BASELINE_RANGE_1' : 40e3,
'BASELINE_RANGE_2' : 40e3}

bin_size = 4
chunk_size = 5
negative = True
baseline_mode = 'median'
verbose = 1
peak_threshold = 1000
suppression_threshold = 10

overwrite = True
16 changes: 16 additions & 0 deletions packs/tests/data/configs/ana_missing_window_args.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[required]

files = ['run19.h5']



bin_size = 4
chunk_size = 5
negative = True
baseline_mode = 'median'
verbose = 1
peak_threshold = 1000
suppression_threshold = 10

overwrite = True
save_path = 'test.h5'
20 changes: 20 additions & 0 deletions packs/tests/data/configs/ana_missing_window_key.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[required]

files = ['run19.h5']

window_args = {'WINDOW_START' : 100,
'WINDOW_END' : 3e4,
'BASELINE_POINT_1' : 1e6,
'BASELINE_POINT_2' : 1.5e6,
'BASELINE_RANGE_1' : 40e3}

bin_size = 4
chunk_size = 5
negative = True
baseline_mode = 'median'
verbose = 1
peak_threshold = 1000
suppression_threshold = 10

overwrite = True
save_path = 'test.h5'
21 changes: 21 additions & 0 deletions packs/tests/data/configs/ana_negative_window.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[required]

files = ['run19.h5']

window_args = {'WINDOW_START' : -100,
Comment thread
jwaiton marked this conversation as resolved.
Resolved
'WINDOW_END' : 3e4,
'BASELINE_POINT_1' : 1e6,
'BASELINE_POINT_2' : 1.5e6,
'BASELINE_RANGE_1' : 40e3,
'BASELINE_RANGE_2' : 40e3}

bin_size = 4
chunk_size = 5
negative = True
baseline_mode = 'median'
verbose = 1
peak_threshold = 1000
suppression_threshold = 10

overwrite = True
save_path = 'test.h5'
21 changes: 21 additions & 0 deletions packs/tests/data/configs/ana_nonexistent_file.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[required]

files = ['secretfakefile.h5']

window_args = {'WINDOW_START' : 100,
'WINDOW_END' : 3e4,
'BASELINE_POINT_1' : 1e6,
'BASELINE_POINT_2' : 1.5e6,
'BASELINE_RANGE_1' : 40e3,
'BASELINE_RANGE_2' : 40e3}

bin_size = 4
chunk_size = 5
negative = True
baseline_mode = 'median'
verbose = 1
peak_threshold = 1000
suppression_threshold = 10

overwrite = True
save_path = 'test.h5'
21 changes: 21 additions & 0 deletions packs/tests/data/configs/ana_save_dir_missing.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[required]

files = ['run19.h5']

window_args = {'WINDOW_START' : 100,
'WINDOW_END' : 3e4,
'BASELINE_POINT_1' : 1e6,
'BASELINE_POINT_2' : 1.5e6,
'BASELINE_RANGE_1' : 40e3,
'BASELINE_RANGE_2' : 40e3}

bin_size = 4
chunk_size = 5
negative = True
baseline_mode = 'median'
verbose = 1
peak_threshold = 1000
suppression_threshold = 10

overwrite = True
save_path = 'nosuchthing/test.h5'
23 changes: 23 additions & 0 deletions packs/tests/data/configs/ana_unknown_key.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[required]

files = ['run19.h5']

window_args = {'WINDOW_START' : 100,
'WINDOW_END' : 3e4,
'BASELINE_POINT_1' : 1e6,
'BASELINE_POINT_2' : 1.5e6,
'BASELINE_RANGE_1' : 40e3,
'BASELINE_RANGE_2' : 40e3}

bin_size = 4
chunk_size = 5
negative = True
baseline_mode = 'median'
verbose = 1
peak_threshold = 1000
suppression_threshold = 10

overwrite = True
save_path = 'test.h5'

mules = 'bad'
Loading
Loading