Skip to content

Rescale data inference#393

Open
edyoshikun wants to merge 4 commits intomainfrom
rescale_data_inference
Open

Rescale data inference#393
edyoshikun wants to merge 4 commits intomainfrom
rescale_data_inference

Conversation

@edyoshikun
Copy link
Copy Markdown
Member

No description provided.

Soorya19Pradeep and others added 4 commits March 26, 2026 07:54
Introduces BatchedRescaleYX(d) transforms that resize the YX spatial
dimensions of 5D tensors using bilinear interpolation with anti-aliasing.

Adds reference_pixel_size parameter to TripletDataModule: when set, the
module reads the pixel size from the inference dataset's OME-Zarr metadata
and automatically computes the initial patch size so that the same physical
area is captured as during training, then rescales to final_yx_patch_size.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds a two-step CLI for cross-platform embedding batch correction using
Linear Optimal Transport (POT LinearTransport):

  viscy-dynaclr fit-lot-correction  -c config.yaml
  viscy-dynaclr apply-lot-correction -c config.yaml

Core logic in viscy/representation/evaluation/lot_correction.py:
- fit_lot_correction: fits shared StandardScaler + PCA + LOT on uninfected
  reference cells from source (e.g. light-sheet) and target (e.g. confocal)
  embedding zarrs. Cell selection is driven by flexible obs-column filters
  (startswith / equals).
- apply_lot_correction: transforms all cells in a source zarr through the
  fitted pipeline (scaler → PCA → LOT) and writes a corrected AnnData zarr
  preserving all obs metadata.
- save/load_lot_pipeline: joblib serialisation of the fitted pipeline.

Pydantic config models (LotFitConfig, LotApplyConfig, UninfFilter) validate
all inputs before running. Example YAML configs are provided under
applications/DynaCLR/evaluation/lot_correction/configs/.

Tested end-to-end on organelle channel zarrs: fit on LS1 + confocal 223-patch,
apply to LS1 → output shape (39170, 50), all obs metadata preserved.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds a general-purpose `viscy-dynaclr compute-mmd` command that computes
MMD² between any two groups of cell embeddings from AnnData zarrs. Supports
within-zarr (biological signal) and cross-zarr (batch effect) comparisons,
optional per-group breakdowns, shared PCA preprocessing, and permutation tests.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Comment thread viscy/transforms/_zoom.py
from typing_extensions import Literal


class BatchedRescaleYX(Transform):
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Comment thread viscy/transforms/_zoom.py
return resized.view(b, c, z, *self.target_yx_size)


class BatchedRescaleYXd(MapTransform):
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

wont need this since we have the zoom and batchedzoom

Comment thread viscy/data/triplet.py
self.return_negative = return_negative
self.augment_validation = augment_validation
self._cache_pool_bytes = cache_pool_bytes
if reference_pixel_size is not None:
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this logic is good.

Comment thread viscy/data/triplet.py
return BatchedRescaleYXd(
keys=self.source_channel,
target_yx_size=self.yx_patch_size,
mode="bilinear",
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

lets change this to use the ZoomTransform in viscy-transforms. also this is a

@edyoshikun
Copy link
Copy Markdown
Member Author

we are missing test that evaluate the algorithm

from viscy.transforms._zoom import (
BatchedRescaleYX,
BatchedRescaleYXd,
BatchedZoom,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

use this one @Soorya19Pradeep it's the same thing.

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.

2 participants