Skip to content

Commit

Permalink
feat(starrynight): update modules and pipelines to comply with new spec
Browse files Browse the repository at this point in the history
  • Loading branch information
leoank committed Jan 7, 2025
1 parent 8c1b561 commit eccc85e
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 14 deletions.
16 changes: 14 additions & 2 deletions starrynight/src/starrynight/experiments/pcp_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Self

import polars as pl
from cloudpathlib import CloudPath
from pydantic import BaseModel, Field

from starrynight.experiments.common import (
Expand All @@ -24,6 +25,7 @@ class SBSConfig(BaseModel):
img_frame_type: ImageFrameType = Field(ImageFrameType.ROUND)
channel_dict: dict
acquisition_order: AcquisitionOrderType = Field(AcquisitionOrderType.SNAKE)
barcode_csv_path: Path | CloudPath


class CPConfig(BaseModel):
Expand All @@ -36,15 +38,25 @@ class CPConfig(BaseModel):
acquisition_order: AcquisitionOrderType = Field(AcquisitionOrderType.SNAKE)


class PCPGenericInitConfig(BaseModel):
"""PCP generic config for auto init from index."""

barcode_csv_path: Path | CloudPath


class PCPGeneric(Experiment):
"""PCP experiment configuration."""

path_parser: Callable[[str], MeasuredInventory]
sbs_config: SBSConfig
cp_config: CPConfig
path_parser: Callable[[str], MeasuredInventory] | None

# users should not access it directly
_init_config: PCPGenericInitConfig | None

@staticmethod
def from_index(index_path: Path) -> Self:
def from_index(index_path: Path, init_config: PCPGenericInitConfig) -> Self:
"""Configure experiment with index."""
if index_path.name.endswith(".csv"):
index_df = pl.scan_csv(index_path)
else:
Expand Down
7 changes: 6 additions & 1 deletion starrynight/src/starrynight/modules/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ class Config:

@staticmethod
@abstractmethod
def from_config(experiment: Experiment, data: DataConfig, **kwargs: Unpack) -> Self:
def from_config(
experiment: Experiment,
data: DataConfig,
updated_spec_dict: dict[str, Container] = {},
**kwargs: Unpack,
) -> Self:
"""Create module from experiment and data config."""
raise NotImplementedError

Expand Down
26 changes: 21 additions & 5 deletions starrynight/src/starrynight/modules/gen_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@

from starrynight.experiments.common import Experiment
from starrynight.modules.common import StarrynightModule
from starrynight.modules.schema import Container as SpecContainer
from starrynight.modules.schema import ExecFunction, TypeCitations
from starrynight.modules.schema import (
Container as SpecContainer,
)
from starrynight.modules.schema import (
ExecFunction,
TypeAlgorithmFromCitation,
TypeCitations,
)
from starrynight.schema import DataConfig


Expand Down Expand Up @@ -41,12 +47,14 @@ def create_work_unit_gen_index(out_dir: Path | CloudPath) -> list[UnitOfWork]:


def create_pipe_gen_index(
inventory_path: Path | CloudPath, out_dir: Path | CloudPath
uid: str, inventory_path: Path | CloudPath, out_dir: Path | CloudPath
) -> Pipeline:
"""Create pipeline for gen index.
Parameters
----------
uid: str
Module unique id.
inventory_path : Path | CloudPath
Inventory path. Can be local or cloud.
out_dir : Path | CloudPath
Expand All @@ -61,7 +69,7 @@ def create_pipe_gen_index(
gen_index_pipe = Seq(
[
Container(
"GenerateIndex",
name=uid,
input_paths={"inventory": [inventory_path.resolve().__str__()]},
output_paths={
"index": [out_dir.joinpath("index.parquet").resolve().__str__()]
Expand Down Expand Up @@ -113,9 +121,17 @@ def from_config(
),
docker_image=None,
algorithm_folder_name=None,
citations=TypeCitations(algorithm=[]),
citations=TypeCitations(
algorithm=[
TypeAlgorithmFromCitation(
name="Starrynight indexing module",
description="This module generates an index for the dataset.",
)
]
),
)
pipe = create_pipe_gen_index(
uid=GenIndexModule.uid(),
inventory_path=data.dataset_path,
out_dir=data.storage_path.joinpath("inventory"),
)
Expand Down
25 changes: 20 additions & 5 deletions starrynight/src/starrynight/modules/gen_inv.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@

from starrynight.experiments.common import Experiment
from starrynight.modules.common import StarrynightModule
from starrynight.modules.schema import Container as SpecContainer
from starrynight.modules.schema import (
Container as SpecContainer,
)
from starrynight.modules.schema import (
ExecFunction,
TypeAlgorithmFromCitation,
TypeCitations,
TypeEnum,
TypeInput,
Expand Down Expand Up @@ -47,12 +50,17 @@ def create_work_unit_gen_inv(out_dir: Path | CloudPath) -> list[UnitOfWork]:


def create_pipe_gen_inv(
spec: SpecContainer, dataset_path: Path | CloudPath, out_dir: Path | CloudPath
uid: str,
spec: SpecContainer,
dataset_path: Path | CloudPath,
out_dir: Path | CloudPath,
) -> Pipeline:
"""Create pipeline for gen inv.
Parameters
----------
uid: str
Module unique id.
spec: SpecContainer
GenInvModule specification.
dataset_path : Path | CloudPath
Expand Down Expand Up @@ -83,7 +91,7 @@ def create_pipe_gen_inv(
gen_inv_pipe = Seq(
[
Container(
"GenerateInventory",
name=uid,
input_paths={},
output_paths={"inventory": [spec.outputs[0].path]},
config=ContainerConfig(
Expand Down Expand Up @@ -145,7 +153,14 @@ def _spec() -> SpecContainer:
),
docker_image=None,
algorithm_folder_name=None,
citations=TypeCitations(algorithm=[]),
citations=TypeCitations(
algorithm=[
TypeAlgorithmFromCitation(
name="Starrynight inventory module",
description="This module generates an inventory for the dataset.",
)
]
),
)

@staticmethod
Expand All @@ -161,7 +176,7 @@ def from_config(
.resolve()
.__str__()
)
pipe = create_pipe_gen_inv(spec=spec)
pipe = create_pipe_gen_inv(uid=GenInvModule.uid(), spec=spec)
uow = create_work_unit_gen_inv(out_dir=data.storage_path.joinpath("inventory"))

return GenInvModule(spec=spec, pipe=pipe, uow=uow)
2 changes: 1 addition & 1 deletion starrynight/src/starrynight/modules/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from starrynight.modules.gen_index import GenIndexModule
from starrynight.modules.gen_inv import GenInvModule

MODULE_REGISTRY: dict[str, StarrynightModule] = {
MODULE_REGISTRY: dict[str, type(StarrynightModule)] = {
GenInvModule.uid(): GenInvModule,
GenIndexModule.uid(): GenIndexModule,
}

0 comments on commit eccc85e

Please sign in to comment.