-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
7,991 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# GitHub syntax highlighting | ||
pixi.lock linguist-language=YAML linguist-generated=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,9 @@ name: test | |
|
||
on: | ||
push: | ||
branches: [main, master] | ||
branches: [main] | ||
pull_request: | ||
branches: [main, master] | ||
branches: [main] | ||
|
||
concurrency: | ||
group: test-${{ github.head_ref }} | ||
|
@@ -16,27 +16,27 @@ env: | |
|
||
jobs: | ||
run: | ||
name: Python ${{ matrix.python-version }} on ${{ startsWith(matrix.os, 'macos-') && 'macOS' || startsWith(matrix.os, 'windows-') && 'Windows' || 'Linux' }} | ||
name: ${{ matrix.pixi-environment }} - ${{ matrix.os }} | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ubuntu-latest, windows-latest, macos-latest] | ||
python-version: ['3.10', '3.11', '3.12'] | ||
|
||
pixi-environment: | ||
- py310-base | ||
- py310-xarray | ||
- py311-base | ||
- py311-xarray | ||
- py312-base | ||
- py312-xarray | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install Hatch | ||
run: pip install --upgrade hatch | ||
|
||
- name: Run static analysis | ||
run: hatch fmt --check | ||
|
||
- name: Run tests | ||
run: hatch run cov | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Pixi | ||
uses: prefix-dev/[email protected] | ||
with: | ||
cache: true | ||
environments: ${{ matrix.pixi-environment }} | ||
|
||
- name: Run tests | ||
run: pixi run --environment ${{ matrix.pixi-environment }} test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
dist | ||
__pycache__ | ||
.coverage* | ||
# pixi environments | ||
.pixi | ||
*.egg-info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
try: | ||
import dask.array as da | ||
import xarray as xr | ||
from tifffile.tifffile import imread | ||
from pandas import DataFrame | ||
HAS_XARRAY = True | ||
except ImportError: | ||
HAS_XARRAY = False | ||
|
||
|
||
def dataarray_from_dataframe(df: "DataFrame", channels_3d: list[bool]): | ||
required_columns = ["path", "channel", "position", "time"] | ||
missing_columns = [col for col in required_columns if col not in df.columns] | ||
if missing_columns: | ||
msg = f"Missing columns: {missing_columns}" | ||
raise ValueError(msg) | ||
if df["channel"].max() > len(channels_3d): | ||
msg = f"No dimension information available for certain channels." | ||
raise ValueError(msg) | ||
data_arrays = [_load_file(row, channels_3d) for _, row in df.iterrows()] | ||
return xr.combine_by_coords(data_arrays)["intensity"] | ||
|
||
|
||
def _load_file(row, channels_3d: list[bool]): | ||
path = row['path'] | ||
position = row['position'] | ||
time = row['time'] | ||
channel = row['channel'] | ||
|
||
chunks = (-1,) * (3 if channels_3d[channel] else 2) | ||
with imread(path, aszarr=True) as store: | ||
data = da.from_zarr(store, chunks=chunks) | ||
|
||
# Determine if the array is 2D or 3D | ||
if data.ndim == 2: | ||
data = data[None, ...] # Add a dummy Z dimension | ||
|
||
data_array = xr.DataArray( | ||
data[None, None, None, ...], # Add singleton dimensions for position, time, and channel | ||
dims=['position', 'time', 'channel', 'z', 'y', 'x'], | ||
coords={ | ||
'position': [int(position)], | ||
'time': [int(time)], | ||
'channel': [int(channel)], | ||
'z': range(data.shape[0]), | ||
'y': range(data.shape[1]), | ||
'x': range(data.shape[2]) | ||
} | ||
) | ||
|
||
return xr.Dataset({'intensity': data_array}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
"NDInfoFile", Version 1.0 | ||
"Description", File recreated from images. | ||
"StartTime1", 20241001 12:00:00.000 | ||
"DoTimelapse", FALSE | ||
"DoStage", TRUE | ||
"NStagePositions", 2 | ||
"Stage1", "Position1" | ||
"Stage2", "Position2" | ||
"DoWave", TRUE | ||
"NWavelengths", 3 | ||
"WaveName1", "Conf640" | ||
"WaveDoZ1", FALSE | ||
"WaveName2", "Conf561" | ||
"WaveDoZ2", TRUE | ||
"WaveName3", "Conf488" | ||
"WaveDoZ3", TRUE | ||
"DoZSeries", TRUE | ||
"NZSteps", 42 | ||
"ZStepSize", 3 | ||
"WaveInFileName", TRUE | ||
"EndFile" |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import pytest | ||
from pathlib import Path | ||
|
||
from metamorph_mda_parser.nd import NdInfo | ||
|
||
pytest.importorskip("xarray") | ||
|
||
@pytest.fixture | ||
def sample_3ch_2pos_mixed_z(): | ||
return Path("tests/resources/data/sample_3ch_2pos_mixed-z.nd") | ||
|
||
def test_data_array_from_nd(sample_3ch_2pos_mixed_z): | ||
ndinfo = NdInfo.from_path(sample_3ch_2pos_mixed_z) | ||
dataarray2d = ndinfo.get_data_array(channels=[0]) | ||
dataarray3d = ndinfo.get_data_array(channels=[1, 2]) | ||
|
||
assert dataarray2d.dims == ("position", "time", "channel", "z", "y", "x") | ||
assert dataarray2d[0, 0, 0, 0, :, :].data.compute().tolist() == [[0,0], [0,128], [0,0]] | ||
assert dataarray2d[1, 0, 0, 0, :, :].data.compute().tolist() == [[0,1], [0,128], [0,0]] | ||
|
||
assert dataarray3d.dims == ("position", "time", "channel", "z", "y", "x") | ||
assert dataarray3d[0, 0, 0, 0, :, :].data.compute().tolist() == [[1,0], [0,128], [0,0]] | ||
assert dataarray3d[0, 0, 1, 0, :, :].data.compute().tolist() == [[2,0], [0,128], [0,0]] | ||
assert dataarray3d[1, 0, 0, 0, :, :].data.compute().tolist() == [[1,1], [0,128], [0,0]] | ||
assert dataarray3d[1, 0, 1, 0, :, :].data.compute().tolist() == [[2,1], [0,128], [0,0]] |