Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
db0bc50
Include WD1/2 processing functions
jwaiton Nov 11, 2024
90c51df
Refactor code, introduce generic function
jwaiton Nov 13, 2024
2d6ddb3
add type hints
jwaiton Nov 14, 2024
1e692b6
Add channels column for single channel samples
jwaiton Nov 14, 2024
1703365
add io for event information & types
jwaiton Nov 14, 2024
205d329
Develop tests and alter test infrastructure
jwaiton Nov 14, 2024
dac8535
generalise data types for binary collection
jwaiton Nov 16, 2024
8d20d34
improve file safety
jwaiton Nov 16, 2024
f64be0e
Modify `check_save_path` to produce consistent results.
jwaiton Nov 16, 2024
20e227e
fix bugs and cosmetics
jwaiton Nov 18, 2024
8f2a35e
add tests
jwaiton Nov 18, 2024
f17717b
Add executable functionality for WD2 decoding
jwaiton Nov 19, 2024
b5d9f3d
Introduce skip for executable tests
jwaiton Nov 19, 2024
6275472
add fix to tests
jwaiton Nov 19, 2024
afaad71
add newlines
jwaiton Nov 21, 2024
e0cb2e8
add tests for executable & config
jwaiton Nov 21, 2024
3eded44
Move `generate_rwf_type()` to `types.py`
jwaiton Nov 21, 2024
f604efb
Add tests
jwaiton Nov 21, 2024
076dc95
add file to ensure folder exists for tests
jwaiton Nov 21, 2024
7e1b08c
Add explicit decoding tests for WD2
jwaiton Nov 22, 2024
89e3c43
Fix test to ensure both chunking conditions are tests
jwaiton Nov 22, 2024
792eed9
Fixed bug that forced chunking, and upload correct h5 files for compa…
jwaiton Nov 22, 2024
a3cafc7
remove `binary_to_h5` and add comments
jwaiton Nov 22, 2024
b9c3e58
Add final tests
jwaiton Nov 22, 2024
a4c02e4
add catch and test to ensure malformed WD2 files return useful error
jwaiton Nov 25, 2024
6cb3177
Add catch for edge case with
jwaiton Jan 31, 2025
0116e9c
Alter dataframe mapping
jwaiton Feb 12, 2025
f78427a
Force flaky to newest version to fix incompatibility
jwaiton Feb 12, 2025
4e6f32d
Fix dependencies to known working version
jwaiton Feb 12, 2025
e2b51dc
Add docstrings and cosmetic changes to io functions
jwaiton Feb 12, 2025
9e9c501
Add information to endian comment and cosmetics
jwaiton Feb 12, 2025
6f11b2c
Alter 'finally' logic and cosmetics
jwaiton Feb 12, 2025
b86e083
Alter process_header() and test to ensure unwanted errors are raised
jwaiton Feb 12, 2025
c30dafb
Cosmetics
jwaiton Feb 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,9 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/


# ignore the new .txt files generated in test
/packs/tests/data/repetitive_data/test_*.txt
# temporary h5 files get ignored
*tmp.h5
38 changes: 19 additions & 19 deletions MULE_environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ name: MULE-3.12-10-24
channels:
- defaults
dependencies:
- python=3.12
- numpy
- iminuit
- matplotlib
- seaborn
- tables
- h5py
- pandas
- tqdm
- scipy
- cython
- pytables
- coverage
- pytest
- hypothesis
- jupyterlab
- jupyter
- flaky
- sphinx
- python = 3.12
- numpy = 1.26.4
- iminuit = 2.18.0
- matplotlib = 3.9.2
- seaborn = 0.13.2
- tables = 3.9.2
- h5py = 3.11.0
- pandas = 2.2.2
- tqdm = 4.66.5
- scipy = 1.13.1
- cython = 3.0.11
- pytables = 3.10.1
- coverage = 7.6.1
- pytest = 7.4.4
- hypothesis = 6.111.0
- jupyterlab = 4.2.5
- jupyter = 1.0.0
- flaky = 3.7.0
- sphinx = 7.3.7
prefix: /home/e78368jw/anaconda3/envs/MULE-3.12-10-24
10 changes: 5 additions & 5 deletions bin/mule
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ MULE pack runtime executable
Use 'mule --help' for more information
======================================''', formatter_class=argparse.RawTextHelpFormatter)

parser.add_argument("pack", choices = ['acq','proc', 'test'], help = '''The pack implemented:
acq - Acquisition of data using wavedump 1
proc - Processing of data
test - Testing directory (IGNORE)
parser.add_argument("pack", choices = ['acq','proc', 'tests'], help = '''The pack implemented:
acq - Acquisition of data using wavedump 1
proc - Processing of data
tests - Testing directory (IGNORE)
''')
parser.add_argument("config", help = 'The config file provided to the pack, this differs based on which pack youre using')
# acquire arguments
Expand All @@ -46,4 +46,4 @@ except ModuleNotFoundError:
traceback.print_exc()
exit(1)
else:
pack()
pack(args.config)
9 changes: 8 additions & 1 deletion packs/acq/acq.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
def acq():
from packs.core.core_utils import check_test


def acq(config_file):
print("This works as expected: acquisition")
print("In here you should read the config provided")

if check_test(config_file):
return

11 changes: 11 additions & 0 deletions packs/configs/process_WD2_3channel.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[required]

process = 'decode'
wavedump_edition = 2
file_path = '/path/to/file.bin'
save_path = '/path/to/file.h5'

[optional]

overwrite = True
counts = -1
Empty file added packs/core/__init__.py
Empty file.
14 changes: 14 additions & 0 deletions packs/core/core_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def flatten(xss):
'''
Flattens a 2D list
eg: [[0,1,2,3], [4,5,6,7]] -> [0,1,2,3,4,5,6,7]
'''
return [x for xs in xss for x in xs]

def check_test(file):
# quick check for test config
if file == "test_config":
print("Test config executable run successfully")
return True
else:
return False
101 changes: 101 additions & 0 deletions packs/core/io.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import pandas as pd

import h5py
import ast
import configparser


from packs.types import types


def load_evt_info(file_path, merge = False):
'''
Loads in a processed WD .h5 file as pandas DataFrame, extracting event information tables.

Parameters
----------

file_path (str) : Path to saved data
merge (bool) : Flag for merging chunked data

Returns
-------

(pd.DataFrame) : Dataframe of event information
'''

h5_data = []
with h5py.File(file_path) as f:
# extract event info
evt_info = f.get('event_information')
for i in evt_info.keys():
q = evt_info.get(str(i))
for j in q:
h5_data.append(j)


return pd.DataFrame(map(list, h5_data), columns = (types.event_info_type).names)


def load_rwf_info(file_path : str,
samples : int) -> list:
'''
Loads in a processed WD .h5 file as pandas dataframe, extracting raw waveform tables.
Samples must be provided, and can be found using `load_evt_info()`.

Parameters
----------

file_path (str) : Path to saved data
samples (int) : Number of samples in each raw waveform

Returns
-------

(pd.DataFrame) : Dataframe of raw waveform information
'''
h5_data = []
with h5py.File(file_path) as f:
rwf_info = f.get('rwf')
for i in rwf_info.keys():
q = rwf_info.get(str(i))
for j in q:
h5_data.append(j)

return pd.DataFrame(map(list, h5_data), columns = (types.rwf_type(samples)).names)


def read_config_file(file_path : str) -> dict:
'''
Read config file passed in via 'mule' and extract relevant information for pack.
Example:

>> mule proc config.conf

This function collects the relevant information from `config.conf` and passes it to the `proc` pack.

Parameters
----------

file_path (str) : Path to config file

Returns
-------

arg_dict (dict) : Dictionary of relevant arguments for the pack
'''
# setup config parser
config = configparser.ConfigParser()

# read in arguments, require the required ones
config.read(file_path)
arg_dict = {}
for section in config.sections():
for key in config[section]:
# the config should be written in such a way that the python evaluator
# can determine its type
#
# we can setup stricter rules at some other time
arg_dict[key] = ast.literal_eval(config[section][key])

return arg_dict
97 changes: 0 additions & 97 deletions packs/core/processing_utils.py

This file was deleted.

31 changes: 28 additions & 3 deletions packs/proc/proc.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
def proc():
print("This works as expected: processing")
print("In here you should read the config provided")
import os

from packs.core.io import read_config_file
from packs.proc.processing_utils import process_bin_WD2
from packs.core.core_utils import check_test

def proc(config_file):
print("Starting the processing pack...")

# checks if test, if so ends run
if check_test(config_file):
return

# take full path
full_path = os.path.expandvars(config_file)

conf_dict = read_config_file(full_path)
# removing the first two components so that they can be fed into functions
arg_dict = dict(list(conf_dict.items())[2:])
# check the method implemented, currently just process
match conf_dict['process']:
case 'decode':
if conf_dict['wavedump_edition'] == 2:
process_bin_WD2(**arg_dict)
else:
raise RuntimeError(f"wavedump edition {conf_dict['wavedump_edition']} decoding isn't currently implemented.")
case default:
raise RuntimeError(f"process {conf_dict['process']} not currently implemented.")
Loading
Loading