Add optional metadata output (DatasetSpecs fields) to DataLoader - #27
Merged
Conversation
- Added return_metadata parameter to ZarrDataset.__init__ - Metadata includes filename and data_scale from collection - Metadata is appended as last element in output tuple - Created zarrdataset_collate_fn to handle non-numeric metadata - Exported collate function in __init__.py - Added comprehensive tests for metadata functionality Co-authored-by: fercer <17553283+fercer@users.noreply.github.com>
- Clarified data_scale documentation - Improved metadata detection logic in collate function - Cleaned up zarr attribute checking - Fixed line continuation in test file Co-authored-by: fercer <17553283+fercer@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add optional filename and data scale outputs to DataLoader
Add optional metadata output (filename, data_scale) to DataLoader
Dec 31, 2025
fercer
requested changes
Jan 2, 2026
| return_worker_id: bool | ||
| Return the worker id that extracted the sample. | ||
| return_metadata: bool | ||
| Return metadata dictionary containing `filename` and `data_scale` for |
Collaborator
There was a problem hiding this comment.
This really should return the standard metadata from the DatasetSpecs class
Contributor
Author
There was a problem hiding this comment.
Updated the docstring to clarify that return_metadata returns all standard DatasetSpecs fields (filenames, source_axes, axes, data_group, roi) for each modality. (3883974)
| source_axes=mod_metadata[im_id]["source_axes"], | ||
| axes=mod_metadata[im_id]["axes"], | ||
| data_group=mod_metadata[im_id]["data_group"], | ||
| roi=mod_metadata[im_id]["roi"] |
Collaborator
There was a problem hiding this comment.
Should roi be also converted into a string. Maybe with the format used to define ROIs within the same context.
Contributor
Author
There was a problem hiding this comment.
Added format_roi() helper function that converts ROI slices to string format (start_coords):(lengths), consistent with the format used in the metadata parsing context. For example: (0,10,5):(100,50,3) or : for full slices. (3883974)
- Updated docstring to reflect that return_metadata returns all standard DatasetSpecs fields - Added format_roi() helper function to convert ROI slices to string format - ROI is now returned as string in format "(start):(length)" for better readability Co-authored-by: fercer <17553283+fercer@users.noreply.github.com>
Copilot
AI
changed the title
Add optional metadata output (filename, data_scale) to DataLoader
Add optional metadata output (DatasetSpecs fields) to DataLoader
Jan 2, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Extends
ZarrDatasetto optionally return complete DatasetSpecs metadata alongside samples for tracking sample provenance during training/inference workflows.Changes
Added
return_metadataparameter toZarrDataset: When enabled, appends metadata dict as last element in output tuple containing all standard DatasetSpecs fields for each modality:filenames(string representation of source),source_axes,axes,data_group(resolution level), androi(formatted as human-readable string)Created
zarrdataset_collate_fn: Custom collate function required for PyTorchDataLoaderto properly batch non-numeric metadata separately from tensors. Detects metadata by checking for expected DatasetSpecs keys.Added
format_roi()helper function: Converts ROI slices to human-readable string format(start_coords):(lengths), consistent with the ROI parsing convention (e.g.,(10,20,0):(100,100,-1)or:for full selection)Maintains backward compatibility: Metadata placed last in output tuple (after worker_id, positions, arrays). Existing code unaffected when flag disabled.
Usage
Output Order
worker_id→positions→arrays→metadataOriginal prompt
filenameanddata_scaleOutputs to DataLoader #24💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.