Skip to content

Commit

Permalink
Merge pull request #121 from fmi-faim/imagexpress-patterns
Browse files Browse the repository at this point in the history
ImageXpress: support time dimension
  • Loading branch information
imagejan authored May 3, 2024
2 parents ca9fe96 + ce7408a commit 0268686
Show file tree
Hide file tree
Showing 237 changed files with 106 additions and 53 deletions.
5 changes: 4 additions & 1 deletion examples/ImageXpressSinglePlaneAcquisitionExample.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ def main():

# Parse MD plate acquisition.
plate_acquisition = SinglePlaneAcquisition(
acquisition_dir=Path(__file__).parent.parent / "resources" / "Projection-Mix",
acquisition_dir=Path(__file__).parent.parent
/ "resources"
/ "ImageXpress"
/ "Projection-Mix",
alignment=TileAlignmentOptions.GRID,
)

Expand Down
5 changes: 4 additions & 1 deletion examples/ImageXpressStackAcquisitionExample.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ def main():

# Parse MD plate acquisition.
plate_acquisition = StackAcquisition(
acquisition_dir=Path(__file__).parent.parent / "resources" / "Projection-Mix",
acquisition_dir=Path(__file__).parent.parent
/ "resources"
/ "ImageXpress"
/ "Projection-Mix",
alignment=TileAlignmentOptions.GRID,
)

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
11 changes: 7 additions & 4 deletions src/faim_ipa/hcs/imagexpress/ImageXpressWellAcquisition.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def _assemble_tiles(self) -> list[Tile]:
tiles = []
for i, row in self._files.iterrows():
file = row["path"]
time_point = 0
time_point = row["t"] if "t" in row.index and row["t"] is not None else 0
channel = row["channel"]
metadata = load_metaseries_tiff_metadata(file)
if self._z_spacing is None:
Expand Down Expand Up @@ -77,12 +77,15 @@ def get_z_spacing(self) -> Optional[float]:
return self._z_spacing

def get_axes(self) -> list[str]:
axes = ["y", "x"]

if "z" in self._files.columns:
axes = ["z", "y", "x"]
else:
axes = ["y", "x"]
axes = ["z"] + axes

if self._files["channel"].nunique() > 1:
axes = ["c"] + axes

if "t" in self._files.columns and self._files["t"].nunique() > 1:
axes = ["t"] + axes

return axes
2 changes: 1 addition & 1 deletion src/faim_ipa/hcs/imagexpress/MixedAcquisition.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def _filter_mips(self, files: pd.DataFrame) -> pd.DataFrame:

def _get_root_re(self) -> re.Pattern:
return re.compile(
r".*[\/\\](?P<date>\d{4}-\d{2}-\d{2})[\/\\](?P<acq_id>\d+)(?:[\/\\]ZStep_(?P<z>\d+))?.*"
r".*[\/\\](?P<date>\d{4}-\d{2}-\d{2})[\/\\](?P<acq_id>\d+)(?:[\/\\]TimePoint_(?P<t>\d+))?(?:[\/\\]ZStep_(?P<z>\d+))?.*"
)

def _get_filename_re(self) -> re.Pattern:
Expand Down
4 changes: 3 additions & 1 deletion src/faim_ipa/hcs/imagexpress/SinglePlaneAcquisition.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ def __init__(
)

def _get_root_re(self) -> re.Pattern:
return re.compile(r".*[\/\\](?P<date>\d{4}-\d{2}-\d{2})[\/\\](?P<acq_id>\d+)")
return re.compile(
r".*[\/\\](?P<date>\d{4}-\d{2}-\d{2})[\/\\](?P<acq_id>\d+)(?:[\/\\]TimePoint_(?P<t>\d+))?"
)

def _get_filename_re(self) -> re.Pattern:
return re.compile(
Expand Down
2 changes: 1 addition & 1 deletion src/faim_ipa/hcs/imagexpress/StackAcquisition.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def _parse_files(self) -> pd.DataFrame:

def _get_root_re(self) -> re.Pattern:
return re.compile(
r".*[\/\\](?P<date>\d{4}-\d{2}-\d{2})[\/\\](?P<acq_id>\d+)(?:[\/\\]ZStep_(?P<z>\d+))"
r".*[\/\\](?P<date>\d{4}-\d{2}-\d{2})[\/\\](?P<acq_id>\d+)(?:[\/\\]TimePoint_(?P<t>\d+))?(?:[\/\\]ZStep_(?P<z>\d+))"
)

def _get_filename_re(self) -> re.Pattern:
Expand Down
84 changes: 42 additions & 42 deletions tests/hcs/imagexpress/files.csv

Large diffs are not rendered by default.

45 changes: 43 additions & 2 deletions tests/hcs/imagexpress/test_ImageXpress.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@

@pytest.fixture
def acquisition_dir():
return Path(__file__).parent.parent.parent.parent / "resources" / "Projection-Mix"
return (
Path(__file__).parent.parent.parent.parent
/ "resources"
/ "ImageXpress"
/ "Projection-Mix"
)


@pytest.fixture
Expand Down Expand Up @@ -270,7 +275,12 @@ def test_raise_not_implemented_error(dummy_plate):

@pytest.fixture
def acquisition_dir_single_channel():
return Path(__file__).parent.parent.parent.parent / "resources" / "SingleChannel"
return (
Path(__file__).parent.parent.parent.parent
/ "resources"
/ "ImageXpress"
/ "SingleChannel"
)


@pytest.fixture
Expand Down Expand Up @@ -314,3 +324,34 @@ def test_single_channel_acquistion(single_channel_acquisition: PlateAcquisition)
assert tile.position.y in [0]
assert tile.position.x in [0, 512]
assert tile.shape == (512, 512)


@pytest.fixture
def acquisition_dir_time_lapse():
return (
Path(__file__).parent.parent.parent.parent
/ "resources"
/ "ImageXpress"
/ "1well-3C-2S-Zmix-T"
)


@pytest.fixture
def time_lapse_acquisition(acquisition_dir_time_lapse):
return SinglePlaneAcquisition(
acquisition_dir_time_lapse, alignment=TileAlignmentOptions.STAGE_POSITION
)


def test_time_lapse_acquistion(time_lapse_acquisition: PlateAcquisition):
wells = time_lapse_acquisition.get_well_acquisitions()
for well in wells:
assert isinstance(well, WellAcquisition)
assert len(well.get_tiles()) == 12
for tile in well.get_tiles():
assert tile.position.time in [0, 1]
assert tile.position.channel in [0, 1, 2]
assert tile.position.z == 0
assert tile.position.y in [0, 256]
assert tile.position.x in [0]
assert tile.shape == (256, 256)
1 change: 1 addition & 0 deletions tests/io/test_MetaSeriesTiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def test_load_metaseries_tiff(self):
path = join(
ROOT_DIR.parent,
"resources",
"ImageXpress",
"Projection-Mix",
"2023-02-21",
"1334",
Expand Down

0 comments on commit 0268686

Please sign in to comment.