Skip to content

Conversation

@cfs-data
Copy link
Collaborator

@cfs-data cfs-data commented Jan 15, 2026

Conversion of "SaveToMatlabFile.m"

@cfs-data cfs-data changed the title [WIP] Export marks Export mark object to JSON and NPZ files Jan 19, 2026
@cfs-data cfs-data marked this pull request as ready for review January 19, 2026 14:08
@cfs-data cfs-data requested a review from SimoneAriens January 19, 2026 14:08
@github-actions
Copy link

Diff Coverage

Diff: origin/main..HEAD, staged and unstaged changes

  • packages/scratch-core/src/conversion/data_formats.py (100%)

Summary

  • Total: 3 lines
  • Missing: 0 lines
  • Coverage: 100%

@github-actions
Copy link

Code Coverage

Package Line Rate Branch Rate Health
. 95% 88%
comparators 100% 100%
container_models 99% 100%
conversion 96% 89%
conversion.leveling 100% 100%
conversion.leveling.solver 100% 75%
conversion.preprocess_impression 99% 92%
extractors 95% 75%
parsers 98% 67%
parsers.patches 89% 60%
preprocessors 100% 100%
processors 100% 100%
renders 98% 50%
utils 91% 75%
Summary 97% (1148 / 1182) 84% (133 / 158)

Minimum allowed line rate is 50%

@jokkalt jokkalt self-requested a review January 19, 2026 14:45
@@ -0,0 +1,396 @@
"""Unit tests for the mark serialization module."""
Copy link

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:
Copy link

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:
Copy link

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:
Copy link

Choose a reason for hiding this comment

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

Suggested change
def from_path(path: Path, name: str) -> Mark:
def load_mark_from_path(directory: Path, file_name: str) -> Mark:

makes the signature more intuitive

Comment on lines +95 to +103
# 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)
Copy link

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)
Copy link

Choose a reason for hiding this comment

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

Suggested change
:param name: Base filename (without extension)
:param name: Base filename

mark_type: MarkType
crop_type: CropType
center: tuple[float, float]
scan_image: ScanImageMetaData
Copy link

Choose a reason for hiding this comment

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

Suggested change
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)
Copy link

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

Comment on lines +183 to +184
assert json_file.exists()
assert npz_file.exists()
Copy link

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 @@
"""
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants