-
Notifications
You must be signed in to change notification settings - Fork 0
Export mark object to JSON and NPZ files #89
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
base: main
Are you sure you want to change the base?
Conversation
Diff CoverageDiff: origin/main..HEAD, staged and unstaged changes
Summary
|
Minimum allowed line rate is |
| @@ -0,0 +1,396 @@ | |||
| """Unit tests for the mark serialization module.""" | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe rename file to test_mark.py?
| json_path.write_text(_to_json(mark)) | ||
|
|
||
|
|
||
| def _save_binary(mark: Mark, file_path: Path) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe either the function name can be more specific on what's being saved, or you can generalize the input, by passing the mark.scan_image.data as parameter instead of the entire mark? The latter would make it more in line with _load_binary()
| raise FileNotFoundError(f'File "{file_path}" does not exist') | ||
|
|
||
|
|
||
| def _to_json(mark: Mark) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function I would expect in the Mark class; that also makes it easier to refactor should any fields change. maybe then it would be called as_json or json instead of _to_json
| _save_binary(mark, file_path) | ||
|
|
||
|
|
||
| def from_path(path: Path, name: str) -> Mark: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| def from_path(path: Path, name: str) -> Mark: | |
| def load_mark_from_path(directory: Path, file_name: str) -> Mark: |
makes the signature more intuitive
| # Load and validate metadata | ||
| json_file = file_path.with_suffix(".json") | ||
| _check_file_exists(json_file) | ||
| meta = _load_json(json_file) | ||
|
|
||
| # Load binary data | ||
| npz_file = file_path.with_suffix(".npz") | ||
| _check_file_exists(npz_file) | ||
| data = _load_binary(npz_file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the grouping of metadata and binary data loading function is nice, but maybe it's cleaner to first check that both files exist before doing read/load operations for the json file (since the json is very lightweight, it's more a nth)
|
|
||
| :param mark: Mark object to save | ||
| :param path: Directory path where files will be saved | ||
| :param name: Base filename (without extension) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| :param name: Base filename (without extension) | |
| :param name: Base filename |
| mark_type: MarkType | ||
| crop_type: CropType | ||
| center: tuple[float, float] | ||
| scan_image: ScanImageMetaData |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| scan_image: ScanImageMetaData | |
| scan_image_scales: ScanImageMetaData |
Or something along those lines. since it never really relates back to the actual Mask class, this term can be more accurate
| ) | ||
| assert data.mark_type == MarkType.BREECH_FACE_IMPRESSION | ||
| assert data.crop_type == CropType.RECTANGLE | ||
| assert data.center == (1.0, 2.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then the scan_image.scale* can also be asserted
| assert json_file.exists() | ||
| assert npz_file.exists() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe is_file() would be a more correct check,
| @@ -0,0 +1,191 @@ | |||
| """ | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to save_mask.py or export_mask.py to differentiate from mask.py in root conversion folder?
Conversion of "SaveToMatlabFile.m"