-
Notifications
You must be signed in to change notification settings - Fork 10
feat: add dry run functionality to autopipeline and add sensitive dicom tags to metadata #430
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?
Changes from 3 commits
54dac55
8c90996
37df848
c8a1c13
ce5f490
47567a8
4f06061
8cf0f35
70cc33d
86493d7
f14f3e1
9507a17
64958ad
2204176
1ecc5ba
91ef21a
f5e79b2
5e69eca
c1957ab
de9c9f8
42b8369
a913545
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
strixy16 marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,6 +82,8 @@ def save( | |
| ---------- | ||
| data : np.ndarray | sitk.Image | dict[str, np.ndarray | sitk.Image] | ||
| The data to save. Can be a single image or a dictionary of images. | ||
| **kwargs : object | ||
| Additional context for filename generation. | ||
|
|
||
| Returns | ||
| ------- | ||
|
|
@@ -95,29 +97,32 @@ def save( | |
| """ | ||
| out_path = self.resolve_path(**kwargs) | ||
|
|
||
| if isinstance(data, (np.ndarray, sitk.Image)): | ||
| # Single image or array | ||
| array, metadata = self._to_numpy(data) | ||
| np.savez_compressed(out_path, image_array=array, **metadata) | ||
| elif isinstance(data, dict): | ||
| # Multiple images or arrays | ||
| arrays = {} | ||
| metadata = {} | ||
| for key, value in data.items(): | ||
| array, meta = self._to_numpy(value) | ||
| arrays[key] = array | ||
| for meta_key, meta_value in meta.items(): | ||
| metadata[f"{key}_{meta_key}"] = meta_value | ||
| if self.compressed: | ||
| np.savez_compressed( | ||
| out_path, allow_pickle=False, **arrays, **metadata | ||
| ) | ||
| if not self.dry_run: | ||
| if isinstance(data, (np.ndarray, sitk.Image)): | ||
| # Single image or array | ||
| array, metadata = self._to_numpy(data) | ||
| np.savez_compressed(out_path, image_array=array, **metadata) | ||
| elif isinstance(data, dict): | ||
| # Multiple images or arrays | ||
| arrays = {} | ||
| metadata = {} | ||
| for key, value in data.items(): | ||
| array, meta = self._to_numpy(value) | ||
| arrays[key] = array | ||
| for meta_key, meta_value in meta.items(): | ||
| metadata[f"{key}_{meta_key}"] = meta_value | ||
| if self.compressed: | ||
| np.savez_compressed( | ||
| out_path, allow_pickle=False, **arrays, **metadata | ||
| ) | ||
| else: | ||
| np.savez( | ||
| out_path, allow_pickle=False, **arrays, **metadata | ||
| ) | ||
| else: | ||
| np.savez(out_path, allow_pickle=False, **arrays, **metadata) | ||
| else: | ||
| raise NumpyWriterValidationError( | ||
| "Data must be a NumPy array, SimpleITK image, or a dictionary of these types." | ||
| ) | ||
| raise NumpyWriterValidationError( | ||
| "Data must be a NumPy array, SimpleITK image, or a dictionary of these types." | ||
| ) | ||
|
Comment on lines
+100
to
+125
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preserve data validation behavior under The dry-run guard cleanly skips actual filesystem writes, but it currently also skips all type validation:
To keep dry-run useful for catching pipeline issues while still avoiding I/O, consider validating - out_path = self.resolve_path(**kwargs)
-
- if not self.dry_run:
- if isinstance(data, (np.ndarray, sitk.Image)):
+ out_path = self.resolve_path(**kwargs)
+
+ # Validate input type regardless of dry-run to surface misuses early.
+ if isinstance(data, (np.ndarray, sitk.Image)):
+ to_save = ("single", data)
+ elif isinstance(data, dict):
+ to_save = ("dict", data)
+ else:
+ raise NumpyWriterValidationError(
+ "Data must be a NumPy array, SimpleITK image, or a dictionary of these types."
+ )
+
+ if not self.dry_run:
+ kind, payload = to_save
+ if kind == "single":
+ data_single = payload
# Single image or array
- array, metadata = self._to_numpy(data)
+ array, metadata = self._to_numpy(data_single)
np.savez_compressed(out_path, image_array=array, **metadata)
- elif isinstance(data, dict):
+ else: # dict
# Multiple images or arrays
- arrays = {}
- metadata = {}
- for key, value in data.items():
+ arrays: dict[str, np.ndarray] = {}
+ metadata: dict[str, object] = {}
+ for key, value in payload.items():
...
- else:
- raise NumpyWriterValidationError(
- "Data must be a NumPy array, SimpleITK image, or a dictionary of these types."
- )This keeps validation semantics identical between normal and dry-run modes while still avoiding writes. Optionally, to satisfy TRY003 and improve reuse, you could move the long error message into a class-level constant on
🧰 Tools🪛 Ruff (0.14.5)123-125: Avoid specifying long messages outside the exception class (TRY003) 🤖 Prompt for AI Agents |
||
|
|
||
| self.add_to_index( | ||
| out_path, | ||
|
|
||
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.
"no output files, check the directory" sounds a bit confusing? what are they checking?
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.
Can you send the full output