metamorph-mda-parser 0.2.0__tar.gz → 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {metamorph_mda_parser-0.2.0 → metamorph_mda_parser-0.4.0}/.github/workflows/publish.yml +1 -1
- {metamorph_mda_parser-0.2.0 → metamorph_mda_parser-0.4.0}/.github/workflows/test.yml +1 -1
- {metamorph_mda_parser-0.2.0 → metamorph_mda_parser-0.4.0}/.gitignore +1 -0
- {metamorph_mda_parser-0.2.0 → metamorph_mda_parser-0.4.0}/PKG-INFO +1 -1
- {metamorph_mda_parser-0.2.0 → metamorph_mda_parser-0.4.0}/src/metamorph_mda_parser/lark.py +18 -2
- {metamorph_mda_parser-0.2.0 → metamorph_mda_parser-0.4.0}/src/metamorph_mda_parser/nd.py +11 -3
- {metamorph_mda_parser-0.2.0 → metamorph_mda_parser-0.4.0}/src/metamorph_mda_parser/xarray.py +1 -1
- metamorph_mda_parser-0.4.0/tests/resources/decimal_comma_zstepsize.nd +72 -0
- {metamorph_mda_parser-0.2.0 → metamorph_mda_parser-0.4.0}/tests/test_nd.py +25 -0
- {metamorph_mda_parser-0.2.0 → metamorph_mda_parser-0.4.0}/tests/test_xarray.py +5 -2
- {metamorph_mda_parser-0.2.0 → metamorph_mda_parser-0.4.0}/tests/test_xarray_conditional.py +35 -7
- {metamorph_mda_parser-0.2.0 → metamorph_mda_parser-0.4.0}/.gitattributes +0 -0
- {metamorph_mda_parser-0.2.0 → metamorph_mda_parser-0.4.0}/.github/dependabot.yml +0 -0
- {metamorph_mda_parser-0.2.0 → metamorph_mda_parser-0.4.0}/LICENSE.txt +0 -0
- {metamorph_mda_parser-0.2.0 → metamorph_mda_parser-0.4.0}/README.md +0 -0
- {metamorph_mda_parser-0.2.0 → metamorph_mda_parser-0.4.0}/hk.pkl +0 -0
- {metamorph_mda_parser-0.2.0 → metamorph_mda_parser-0.4.0}/pixi.lock +0 -0
- {metamorph_mda_parser-0.2.0 → metamorph_mda_parser-0.4.0}/pyproject.toml +0 -0
- {metamorph_mda_parser-0.2.0 → metamorph_mda_parser-0.4.0}/src/metamorph_mda_parser/__init__.py +0 -0
- {metamorph_mda_parser-0.2.0 → metamorph_mda_parser-0.4.0}/src/metamorph_mda_parser/nd_grammar.lark +0 -0
- {metamorph_mda_parser-0.2.0 → metamorph_mda_parser-0.4.0}/tests/resources/data/sample_3ch_2pos_mixed-z.nd +0 -0
- {metamorph_mda_parser-0.2.0 → metamorph_mda_parser-0.4.0}/tests/resources/data/sample_3ch_2pos_mixed-z_w1Conf640_s1.tif +0 -0
- {metamorph_mda_parser-0.2.0 → metamorph_mda_parser-0.4.0}/tests/resources/data/sample_3ch_2pos_mixed-z_w1Conf640_s2.tif +0 -0
- {metamorph_mda_parser-0.2.0 → metamorph_mda_parser-0.4.0}/tests/resources/data/sample_3ch_2pos_mixed-z_w2Conf561_s1.stk +0 -0
- {metamorph_mda_parser-0.2.0 → metamorph_mda_parser-0.4.0}/tests/resources/data/sample_3ch_2pos_mixed-z_w2Conf561_s2.stk +0 -0
- {metamorph_mda_parser-0.2.0 → metamorph_mda_parser-0.4.0}/tests/resources/data/sample_3ch_2pos_mixed-z_w3Conf488_s1.stk +0 -0
- {metamorph_mda_parser-0.2.0 → metamorph_mda_parser-0.4.0}/tests/resources/data/sample_3ch_2pos_mixed-z_w3Conf488_s2.stk +0 -0
- {metamorph_mda_parser-0.2.0 → metamorph_mda_parser-0.4.0}/tests/resources/sample_2ch_75pos_361t.nd +0 -0
- {metamorph_mda_parser-0.2.0 → metamorph_mda_parser-0.4.0}/tests/resources/sample_4ch_1pos_1z.nd +0 -0
- {metamorph_mda_parser-0.2.0 → metamorph_mda_parser-0.4.0}/tests/resources/sample_4ch_4pos.nd +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: metamorph-mda-parser
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Light-weight parsing of Metamorph/VisiView .nd files.
|
|
5
5
|
Project-URL: Documentation, https://github.com/fmi-faim/metamorph-mda-parser#readme
|
|
6
6
|
Project-URL: Issues, https://github.com/fmi-faim/metamorph-mda-parser/issues
|
|
@@ -1,5 +1,14 @@
|
|
|
1
|
+
import re
|
|
2
|
+
|
|
1
3
|
from lark import Lark, Transformer
|
|
2
4
|
|
|
5
|
+
# Some files are (incorrectly) written with a comma as decimal separator for ZStepSize.
|
|
6
|
+
_ZSTEPSIZE_COMMA_RE = re.compile(r'("ZStepSize",\s*\d+),(\d+)')
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def sanitize_decimal_comma(content: str) -> str:
|
|
10
|
+
return _ZSTEPSIZE_COMMA_RE.sub(r"\1.\2", content)
|
|
11
|
+
|
|
3
12
|
|
|
4
13
|
class NDInfoTransformer(Transformer):
|
|
5
14
|
def __init__(self):
|
|
@@ -31,6 +40,13 @@ class NDInfoTransformer(Transformer):
|
|
|
31
40
|
return b[0].value == "TRUE"
|
|
32
41
|
|
|
33
42
|
|
|
34
|
-
def parse(content):
|
|
35
|
-
|
|
43
|
+
def parse(content, fix_decimal_comma: bool = False):
|
|
44
|
+
if fix_decimal_comma:
|
|
45
|
+
content = sanitize_decimal_comma(content)
|
|
46
|
+
parser = Lark.open(
|
|
47
|
+
"nd_grammar.lark",
|
|
48
|
+
rel_to=__file__,
|
|
49
|
+
parser="lalr",
|
|
50
|
+
transformer=NDInfoTransformer(),
|
|
51
|
+
)
|
|
36
52
|
return parser.parse(content)
|
|
@@ -44,12 +44,20 @@ class NdInfo(BaseModel):
|
|
|
44
44
|
wave_in_file_name: bool
|
|
45
45
|
|
|
46
46
|
@staticmethod
|
|
47
|
-
def from_path(
|
|
47
|
+
def from_path(
|
|
48
|
+
path: Path,
|
|
49
|
+
fix_decimal_comma: bool = False,
|
|
50
|
+
remove_suffix: str | None = None,
|
|
51
|
+
):
|
|
48
52
|
with open(path) as f:
|
|
49
53
|
content = f.read()
|
|
50
|
-
result = parse(content)
|
|
54
|
+
result = parse(content, fix_decimal_comma=fix_decimal_comma)
|
|
51
55
|
result["Path"] = path
|
|
52
|
-
result["Name"] =
|
|
56
|
+
result["Name"] = (
|
|
57
|
+
path.stem
|
|
58
|
+
if remove_suffix is None
|
|
59
|
+
else path.name.removesuffix(remove_suffix)
|
|
60
|
+
)
|
|
53
61
|
result["Version"] = "1.0" # HACK
|
|
54
62
|
return NdInfo(**result)
|
|
55
63
|
|
{metamorph_mda_parser-0.2.0 → metamorph_mda_parser-0.4.0}/src/metamorph_mda_parser/xarray.py
RENAMED
|
@@ -23,7 +23,7 @@ def dataarray_from_dataframe(df: "DataFrame", channels_3d: list[bool]):
|
|
|
23
23
|
msg = "No dimension information available for certain channels."
|
|
24
24
|
raise ValueError(msg)
|
|
25
25
|
data_arrays = [_load_file(row, channels_3d) for _, row in df.iterrows()]
|
|
26
|
-
return xr.combine_by_coords(data_arrays)["intensity"]
|
|
26
|
+
return xr.combine_by_coords(data_arrays, join="outer")["intensity"]
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
def _load_file(row, channels_3d: list[bool]):
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"NDInfoFile", Version 1.0
|
|
2
|
+
"Description", File recreated from images.
|
|
3
|
+
"StartTime1", 20260313 15:36:49.941
|
|
4
|
+
"DoTimelapse", TRUE
|
|
5
|
+
"NTimePoints", 361
|
|
6
|
+
"DoStage", TRUE
|
|
7
|
+
"NStagePositions", 54
|
|
8
|
+
"Stage1", "let-7p_EV_1"
|
|
9
|
+
"Stage2", "let-7p_EV_2"
|
|
10
|
+
"Stage3", "let-7p_EV_3"
|
|
11
|
+
"Stage4", "let-7p_EV_4"
|
|
12
|
+
"Stage5", "let-7p_EV_5"
|
|
13
|
+
"Stage6", "let-7p_EV_6"
|
|
14
|
+
"Stage7", "let-7p_EV_7"
|
|
15
|
+
"Stage8", "let-7p_EV_8"
|
|
16
|
+
"Stage9", "let-7p_EV_9"
|
|
17
|
+
"Stage10", "let-7p_EV_10"
|
|
18
|
+
"Stage11", "let-7p_EV_11"
|
|
19
|
+
"Stage12", "let-7p_EV_12"
|
|
20
|
+
"Stage13", "let-7p_EV_13"
|
|
21
|
+
"Stage14", "let-7p_EV_14"
|
|
22
|
+
"Stage15", "let-7p_EV_15"
|
|
23
|
+
"Stage16", "let-7p_EV_16"
|
|
24
|
+
"Stage17", "let-7p_EV_17"
|
|
25
|
+
"Stage18", "let-7p_EV_18"
|
|
26
|
+
"Stage19", "let-7p_EV_19"
|
|
27
|
+
"Stage20", "let-7p_EV_20"
|
|
28
|
+
"Stage21", "let-7p_EV_21"
|
|
29
|
+
"Stage22", "let-7p_EV_22"
|
|
30
|
+
"Stage23", "let-7p_EV_23"
|
|
31
|
+
"Stage24", "let-7p_EV_24"
|
|
32
|
+
"Stage25", "let-7p_EV_25"
|
|
33
|
+
"Stage26", "let-7p_EV_26"
|
|
34
|
+
"Stage27", "let-7p_EV_27"
|
|
35
|
+
"Stage28", "let-7p_EV_28"
|
|
36
|
+
"Stage29", "let-7p_EV_29"
|
|
37
|
+
"Stage30", "let-7p_EV_30"
|
|
38
|
+
"Stage31", "let-7p_myrf1RNAi_31"
|
|
39
|
+
"Stage32", "let-7p_myrf1RNAi_32"
|
|
40
|
+
"Stage33", "let-7p_myrf1RNAi_33"
|
|
41
|
+
"Stage34", "let-7p_myrf1RNAi_34"
|
|
42
|
+
"Stage35", "let-7p_myrf1RNAi_35"
|
|
43
|
+
"Stage36", "let-7p_myrf1RNAi_36"
|
|
44
|
+
"Stage37", "let-7p_myrf1RNAi_37"
|
|
45
|
+
"Stage38", "let-7p_myrf1RNAi_38"
|
|
46
|
+
"Stage39", "let-7p_myrf1RNAi_39"
|
|
47
|
+
"Stage40", "let-7p_myrf1RNAi_40"
|
|
48
|
+
"Stage41", "let-7p_myrf1RNAi_41"
|
|
49
|
+
"Stage42", "let-7p_myrf1RNAi_42"
|
|
50
|
+
"Stage43", "let-7p_myrf1RNAi_43"
|
|
51
|
+
"Stage44", "let-7p_myrf1RNAi_44"
|
|
52
|
+
"Stage45", "let-7p_myrf1RNAi_45"
|
|
53
|
+
"Stage46", "let-7p_myrf1RNAi_46"
|
|
54
|
+
"Stage47", "let-7p_myrf1RNAi_47"
|
|
55
|
+
"Stage48", "let-7p_myrf1RNAi_48"
|
|
56
|
+
"Stage49", "let-7p_myrf1RNAi_49"
|
|
57
|
+
"Stage50", "let-7p_myrf1RNAi_50"
|
|
58
|
+
"Stage51", "let-7p_myrf1RNAi_51"
|
|
59
|
+
"Stage52", "let-7p_myrf1RNAi_52"
|
|
60
|
+
"Stage53", "let-7p_myrf1RNAi_53"
|
|
61
|
+
"Stage54", "let-7p_myrf1RNAi_54"
|
|
62
|
+
"DoWave", TRUE
|
|
63
|
+
"NWavelengths", 2
|
|
64
|
+
"WaveName1", "Grosshans-SWI-BF-GFP"
|
|
65
|
+
"WaveDoZ1", TRUE
|
|
66
|
+
"WaveName2", "Grosshans-SWI-GFP-BF"
|
|
67
|
+
"WaveDoZ2", TRUE
|
|
68
|
+
"DoZSeries", TRUE
|
|
69
|
+
"NZSteps", 25
|
|
70
|
+
"ZStepSize", 2,00
|
|
71
|
+
"WaveInFileName", TRUE
|
|
72
|
+
"EndFile"
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from pathlib import Path
|
|
2
2
|
|
|
3
3
|
import pytest
|
|
4
|
+
from lark.exceptions import UnexpectedToken
|
|
4
5
|
|
|
5
6
|
from metamorph_mda_parser.nd import ImageFile, NdInfo
|
|
6
7
|
|
|
@@ -20,6 +21,11 @@ def sample_4ch_1pos_1z():
|
|
|
20
21
|
return Path("tests/resources/sample_4ch_1pos_1z.nd")
|
|
21
22
|
|
|
22
23
|
|
|
24
|
+
@pytest.fixture
|
|
25
|
+
def nd_with_decimal_comma_zstepsize():
|
|
26
|
+
return Path("tests/resources/decimal_comma_zstepsize.nd")
|
|
27
|
+
|
|
28
|
+
|
|
23
29
|
def test_sample_4ch_4pos(sample_4ch_4pos):
|
|
24
30
|
nd_info = NdInfo.from_path(sample_4ch_4pos)
|
|
25
31
|
|
|
@@ -115,3 +121,22 @@ def test_sample_4ch_1pos_1z(sample_4ch_1pos_1z):
|
|
|
115
121
|
|
|
116
122
|
assert len(files) == 4
|
|
117
123
|
assert all(p.suffix == ".tif" for p in files["path"])
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def test_comma_decimal_raises_by_default(nd_with_decimal_comma_zstepsize):
|
|
127
|
+
with pytest.raises(UnexpectedToken):
|
|
128
|
+
NdInfo.from_path(nd_with_decimal_comma_zstepsize)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def test_fix_decimal_comma(nd_with_decimal_comma_zstepsize):
|
|
132
|
+
nd_info = NdInfo.from_path(nd_with_decimal_comma_zstepsize, fix_decimal_comma=True)
|
|
133
|
+
|
|
134
|
+
assert nd_info.do_z_series
|
|
135
|
+
assert nd_info.n_z_steps == 25
|
|
136
|
+
assert nd_info.z_step_size == 2.0
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def test_remove_suffix(sample_4ch_4pos):
|
|
140
|
+
nd_info = NdInfo.from_path(sample_4ch_4pos, remove_suffix=".nd")
|
|
141
|
+
|
|
142
|
+
assert nd_info.name == sample_4ch_4pos.stem
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import pytest
|
|
2
1
|
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
3
5
|
from metamorph_mda_parser.nd import NdInfo
|
|
4
|
-
from metamorph_mda_parser.xarray import HAS_XARRAY
|
|
6
|
+
from metamorph_mda_parser.xarray import HAS_XARRAY
|
|
5
7
|
|
|
6
8
|
|
|
7
9
|
@pytest.fixture
|
|
@@ -9,6 +11,7 @@ def ndinfo():
|
|
|
9
11
|
return NdInfo.from_path(Path("tests/resources/data/sample_3ch_2pos_mixed-z.nd"))
|
|
10
12
|
|
|
11
13
|
|
|
14
|
+
@pytest.mark.filterwarnings("ignore:Missing stk metadata")
|
|
12
15
|
def test_xarray(ndinfo):
|
|
13
16
|
if HAS_XARRAY:
|
|
14
17
|
array = ndinfo.get_data_array()
|
|
@@ -1,25 +1,53 @@
|
|
|
1
|
-
import pytest
|
|
2
1
|
from pathlib import Path
|
|
3
2
|
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
4
5
|
from metamorph_mda_parser.nd import NdInfo
|
|
5
6
|
|
|
6
7
|
pytest.importorskip("xarray")
|
|
7
8
|
|
|
9
|
+
|
|
8
10
|
@pytest.fixture
|
|
9
11
|
def sample_3ch_2pos_mixed_z():
|
|
10
12
|
return Path("tests/resources/data/sample_3ch_2pos_mixed-z.nd")
|
|
11
13
|
|
|
14
|
+
|
|
15
|
+
@pytest.mark.filterwarnings("ignore:Missing stk metadata")
|
|
12
16
|
def test_data_array_from_nd(sample_3ch_2pos_mixed_z):
|
|
13
17
|
ndinfo = NdInfo.from_path(sample_3ch_2pos_mixed_z)
|
|
14
18
|
dataarray2d = ndinfo.get_data_array(channels=[0])
|
|
15
19
|
dataarray3d = ndinfo.get_data_array(channels=[1, 2])
|
|
16
20
|
|
|
17
21
|
assert dataarray2d.dims == ("position", "time", "channel", "z", "y", "x")
|
|
18
|
-
assert dataarray2d[0, 0, 0, 0, :, :].data.compute().tolist() == [
|
|
19
|
-
|
|
22
|
+
assert dataarray2d[0, 0, 0, 0, :, :].data.compute().tolist() == [
|
|
23
|
+
[0, 0],
|
|
24
|
+
[0, 128],
|
|
25
|
+
[0, 0],
|
|
26
|
+
]
|
|
27
|
+
assert dataarray2d[1, 0, 0, 0, :, :].data.compute().tolist() == [
|
|
28
|
+
[0, 1],
|
|
29
|
+
[0, 128],
|
|
30
|
+
[0, 0],
|
|
31
|
+
]
|
|
20
32
|
|
|
21
33
|
assert dataarray3d.dims == ("position", "time", "channel", "z", "y", "x")
|
|
22
|
-
assert dataarray3d[0, 0, 0, 0, :, :].data.compute().tolist() == [
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
34
|
+
assert dataarray3d[0, 0, 0, 0, :, :].data.compute().tolist() == [
|
|
35
|
+
[1, 0],
|
|
36
|
+
[0, 128],
|
|
37
|
+
[0, 0],
|
|
38
|
+
]
|
|
39
|
+
assert dataarray3d[0, 0, 1, 0, :, :].data.compute().tolist() == [
|
|
40
|
+
[2, 0],
|
|
41
|
+
[0, 128],
|
|
42
|
+
[0, 0],
|
|
43
|
+
]
|
|
44
|
+
assert dataarray3d[1, 0, 0, 0, :, :].data.compute().tolist() == [
|
|
45
|
+
[1, 1],
|
|
46
|
+
[0, 128],
|
|
47
|
+
[0, 0],
|
|
48
|
+
]
|
|
49
|
+
assert dataarray3d[1, 0, 1, 0, :, :].data.compute().tolist() == [
|
|
50
|
+
[2, 1],
|
|
51
|
+
[0, 128],
|
|
52
|
+
[0, 0],
|
|
53
|
+
]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{metamorph_mda_parser-0.2.0 → metamorph_mda_parser-0.4.0}/src/metamorph_mda_parser/__init__.py
RENAMED
|
File without changes
|
{metamorph_mda_parser-0.2.0 → metamorph_mda_parser-0.4.0}/src/metamorph_mda_parser/nd_grammar.lark
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{metamorph_mda_parser-0.2.0 → metamorph_mda_parser-0.4.0}/tests/resources/sample_2ch_75pos_361t.nd
RENAMED
|
File without changes
|
{metamorph_mda_parser-0.2.0 → metamorph_mda_parser-0.4.0}/tests/resources/sample_4ch_1pos_1z.nd
RENAMED
|
File without changes
|
{metamorph_mda_parser-0.2.0 → metamorph_mda_parser-0.4.0}/tests/resources/sample_4ch_4pos.nd
RENAMED
|
File without changes
|