-
Notifications
You must be signed in to change notification settings - Fork 5
Develop WD2 decoding #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
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 90c51df
Refactor code, introduce generic function
jwaiton 2d6ddb3
add type hints
jwaiton 1e692b6
Add channels column for single channel samples
jwaiton 1703365
add io for event information & types
jwaiton 205d329
Develop tests and alter test infrastructure
jwaiton dac8535
generalise data types for binary collection
jwaiton 8d20d34
improve file safety
jwaiton f64be0e
Modify `check_save_path` to produce consistent results.
jwaiton 20e227e
fix bugs and cosmetics
jwaiton 8f2a35e
add tests
jwaiton f17717b
Add executable functionality for WD2 decoding
jwaiton b5d9f3d
Introduce skip for executable tests
jwaiton 6275472
add fix to tests
jwaiton afaad71
add newlines
jwaiton e0cb2e8
add tests for executable & config
jwaiton 3eded44
Move `generate_rwf_type()` to `types.py`
jwaiton f604efb
Add tests
jwaiton 076dc95
add file to ensure folder exists for tests
jwaiton 7e1b08c
Add explicit decoding tests for WD2
jwaiton 89e3c43
Fix test to ensure both chunking conditions are tests
jwaiton 792eed9
Fixed bug that forced chunking, and upload correct h5 files for compa…
jwaiton a3cafc7
remove `binary_to_h5` and add comments
jwaiton b9c3e58
Add final tests
jwaiton a4c02e4
add catch and test to ensure malformed WD2 files return useful error
jwaiton 6cb3177
Add catch for edge case with
jwaiton 0116e9c
Alter dataframe mapping
jwaiton f78427a
Force flaky to newest version to fix incompatibility
jwaiton 4e6f32d
Fix dependencies to known working version
jwaiton e2b51dc
Add docstrings and cosmetic changes to io functions
jwaiton 9e9c501
Add information to endian comment and cosmetics
jwaiton 6f11b2c
Alter 'finally' logic and cosmetics
jwaiton b86e083
Alter process_header() and test to ensure unwanted errors are raised
jwaiton c30dafb
Cosmetics
jwaiton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
bpalmeiro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| 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 | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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...") | ||
|
|
||
jwaiton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # checks if test, if so ends run | ||
| if check_test(config_file): | ||
| return | ||
bpalmeiro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # 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 | ||
bpalmeiro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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.") | ||
bpalmeiro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| case default: | ||
| raise RuntimeError(f"process {conf_dict['process']} not currently implemented.") | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.