-
Notifications
You must be signed in to change notification settings - Fork 6
Added numpy_to_h5sc function #353
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
Conversation
…hout creating an scPortrait project
src/scportrait/io/h5sc.py
Outdated
| img_size = channel_imgs.shape[2:4] | ||
| cell_ids = cell_ids.astype(DEFAULT_SEGMENTATION_DTYPE, copy=False) | ||
| all_imgs = np.concatenate([mask_imgs, channel_imgs], axis=1) | ||
| all_imgs = all_imgs.astype(DEFAULT_SINGLE_CELL_IMAGE_DTYPE, copy=False) |
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 type of conversion can be dangerous because it can corrupt your data. we should implement correct conversions for standard types for image data (float, uint16, uint8).
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.
we should also add a check to ensure that images conform with scPortrait conventions
…s are not in the expected ranges
for more information, see https://pre-commit.ci
|
Added an additional warning in case the provided single-cell images do not confirm with scPortrait's convention of [0,1] normalized ranges. |
…tible with out-of-memory file structures
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.
Pull request overview
This PR adds the numpy_to_h5sc function to enable creation of scPortrait .h5sc files directly from numpy arrays, bypassing the need for an scPortrait project when segmentations already exist. Additionally, visualization improvements allow mask contour overlays on cell grids.
Changes:
- Added
numpy_to_h5scfunction insrc/scportrait/io/h5sc.pyto create .h5sc files from numpy arrays with comprehensive validation and metadata handling - Added
_plot_contour_gridhelper function to overlay mask contours on existing image grids - Extended
cell_grid_single_channelwithmask_id,vmin, andvmaxparameters for enhanced visualization control
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/scportrait/io/h5sc.py | Implements numpy_to_h5sc function with input validation, metadata preparation, and HDF5 file creation for .h5sc format |
| src/scportrait/plotting/h5sc.py | Adds contour plotting capability and extends visualization parameters for single-channel cell grids |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
PR Checklist
docsis updatedDescription of changes
Added numpy_to_h5sc to io. This function allows the creation of scPortrait .h5sc files from numpy arrays without an scPortrait project. This is useful when segmentations have already been created externally and no extraction is needed.