Skip to content

Conversation

@nik-as
Copy link
Collaborator

@nik-as nik-as commented Jan 23, 2026

PR Checklist

  • This comment contains a description of changes (with reason)
  • Referenced issue is linked
  • Documentation in docs is updated

Description 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.

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

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).

Copy link
Collaborator

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

@sophiamaedler
Copy link
Collaborator

Added an additional warning in case the provided single-cell images do not confirm with scPortrait's convention of [0,1] normalized ranges.

@sophiamaedler sophiamaedler requested a review from Copilot January 26, 2026 19:52
Copy link
Contributor

Copilot AI left a 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_h5sc function in src/scportrait/io/h5sc.py to create .h5sc files from numpy arrays with comprehensive validation and metadata handling
  • Added _plot_contour_grid helper function to overlay mask contours on existing image grids
  • Extended cell_grid_single_channel with mask_id, vmin, and vmax parameters 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.

@sophiamaedler sophiamaedler merged commit 374ec85 into main Jan 26, 2026
2 checks passed
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