msr-reader 0.2.1.dev0__tar.gz → 0.3.1__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.
Files changed (38) hide show
  1. msr_reader-0.3.1/.gitignore +6 -0
  2. {msr_reader-0.2.1.dev0 → msr_reader-0.3.1}/PKG-INFO +27 -2
  3. msr_reader-0.3.1/README.md +67 -0
  4. {msr_reader-0.2.1.dev0 → msr_reader-0.3.1}/pyproject.toml +4 -1
  5. msr_reader-0.3.1/src/msr_reader/__init__.py +2 -0
  6. msr_reader-0.3.1/src/msr_reader/obffile.py +617 -0
  7. msr_reader-0.3.1/src/msr_reader/xarray_io.py +168 -0
  8. msr_reader-0.3.1/test.ipynb +797 -0
  9. msr_reader-0.3.1/tests/__init__.py +6 -0
  10. msr_reader-0.3.1/tests/data/20261019tests_4d.msr +0 -0
  11. msr_reader-0.3.1/tests/data/20261019tests_incomplete_measurement.msr +0 -0
  12. msr_reader-0.3.1/tests/data/20261019tests_lightbox.obf +0 -0
  13. msr_reader-0.3.1/tests/data/20261019tests_overwritten_measurement1.msr +0 -0
  14. msr_reader-0.3.1/tests/data/2889b245416cd9783c627f413caa45c9_overview_1.msr +0 -0
  15. msr_reader-0.3.1/tests/data/bad44489_field_0.msr +0 -0
  16. msr_reader-0.3.1/tests/data/bad44489_field_0_sted_0.msr +0 -0
  17. msr_reader-0.3.1/tests/data/conf01_continuous_point_measurement.msr +0 -0
  18. msr_reader-0.3.1/tests/data/groupa_cell01.msr +0 -0
  19. msr_reader-0.3.1/tests/data/mesc_yoyo2_img_001.msr +0 -0
  20. msr_reader-0.3.1/tests/synthetic_obf.py +217 -0
  21. msr_reader-0.3.1/tests/test_real_files.py +223 -0
  22. msr_reader-0.3.1/tests/test_synthetic_format.py +236 -0
  23. msr_reader-0.3.1/tests/test_synthetic_grouping.py +157 -0
  24. msr_reader-0.3.1/tests/test_xarray.py +218 -0
  25. msr_reader-0.2.1.dev0/.gitignore +0 -2
  26. msr_reader-0.2.1.dev0/.idea/.gitignore +0 -8
  27. msr_reader-0.2.1.dev0/.idea/inspectionProfiles/profiles_settings.xml +0 -6
  28. msr_reader-0.2.1.dev0/.idea/misc.xml +0 -4
  29. msr_reader-0.2.1.dev0/.idea/modules.xml +0 -8
  30. msr_reader-0.2.1.dev0/.idea/msr-reader.iml +0 -12
  31. msr_reader-0.2.1.dev0/.idea/vcs.xml +0 -6
  32. msr_reader-0.2.1.dev0/.idea/workspace.xml +0 -62
  33. msr_reader-0.2.1.dev0/README.md +0 -44
  34. msr_reader-0.2.1.dev0/src/msr_reader/__init__.py +0 -2
  35. msr_reader-0.2.1.dev0/src/msr_reader/obffile.py +0 -356
  36. msr_reader-0.2.1.dev0/test.ipynb +0 -114
  37. {msr_reader-0.2.1.dev0 → msr_reader-0.3.1}/LICENSE +0 -0
  38. {msr_reader-0.2.1.dev0 → msr_reader-0.3.1}/src/msr_reader/xml_metadata.py +0 -0
@@ -0,0 +1,6 @@
1
+ *.egg-info
2
+ dist
3
+ .idea
4
+ *__pycache__
5
+ msr-test-files
6
+ .DS_Store
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: msr-reader
3
- Version: 0.2.1.dev0
3
+ Version: 0.3.1
4
4
  Summary: Pure Python reader for MSR/OBF (Imspector) image data
5
5
  Project-URL: Homepage, https://github.com/hoerlteam/msr-reader
6
6
  Project-URL: Bug Tracker, https://github.com/hoerlteam/msr-reader/issues
@@ -12,6 +12,8 @@ Classifier: Operating System :: OS Independent
12
12
  Classifier: Programming Language :: Python :: 3
13
13
  Requires-Python: >=3.7
14
14
  Requires-Dist: numpy
15
+ Provides-Extra: xarray
16
+ Requires-Dist: xarray; extra == 'xarray'
15
17
  Description-Content-Type: text/markdown
16
18
 
17
19
  # msr
@@ -41,6 +43,29 @@ with OBFFile('file_path.msr') as f:
41
43
  idx = 0
42
44
  img = f.read_stack(idx) # read stack with index idx into numpy array
43
45
 
46
+ # multi-channel (or confocal + STED) data is acquired into separate stacks by Imspector.
47
+ # stack_groups groups stacks with same series number in the stack name and identical geometry.
48
+ # every stack belongs to exactly one group, unmatched stacks
49
+ # (e.g. line profiles, rescue_info maps) form single-member groups.
50
+ groups = f.stack_groups # list of StackGroup
51
+ img = f.read_stack_group(0) # read all "channels", stacked along a new first axis: e.g. (C, Z, Y, X)
52
+
53
+ # xarray integration (optional dependency: pip install msr-reader[xarray]):
54
+ # stacks as xarray.DataArray with labelled dims and physical coordinates
55
+ # (SI units of the file: meters for spatial axes, seconds for time)
56
+ da = f.read_stack_xr(idx) # dims e.g. ('z', 'y', 'x'), coords in meters
57
+ dag = f.read_stack_group_xr(0) # one DataArray with a leading 'channel' dim, labelled with channel names
58
+
59
+ # stacks without names (sometimes found in old files) can be grouped by geometry alone:
60
+ # with OBFFile('file_path.msr', group_unnamed_stacks=True) as f:
61
+
62
+ # Lightbox files use hierarchical stack names ('Overview 1/Image 1/14:03:01/STAR RED'):
63
+ # for .obf files, grouping by the path up to the last component (the
64
+ # acquisition) and the last component (the channel name) is enabled by
65
+ # default. for .msr files (Imspector), enable it explicitly:
66
+ # with OBFFile('file_path.msr', group_hierarchical_stacks=True) as f:
67
+ # pass group_hierarchical_stacks=False to disable it for .obf files.
68
+
44
69
  # metadata
45
70
  stack_shapes = f.shapes # list of stack shapes, including stack and dimension names
46
71
  pixel_sizes = f.pixel_sizes # like shapes, but with pixel sizes (unit: meters)
@@ -0,0 +1,67 @@
1
+ # msr
2
+
3
+ Pure Python and cross-platform reader for MSR/OBF image files as created by Imspector.
4
+
5
+ Implementation follows the description at: https://imspectordocs.readthedocs.io/en/latest/fileformat.html
6
+
7
+ **WARNING:** Only tested on data from our own Abberior Expert Line STED microscope with a narrow range of Imspector versions.
8
+
9
+ ## Installation
10
+
11
+ ```
12
+ pip install msr-reader
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```python
18
+ from msr_reader import OBFFile
19
+ from xml.etree import ElementTree
20
+ import ome_types
21
+
22
+ with OBFFile('file_path.msr') as f:
23
+
24
+ # reading image data
25
+ idx = 0
26
+ img = f.read_stack(idx) # read stack with index idx into numpy array
27
+
28
+ # multi-channel (or confocal + STED) data is acquired into separate stacks by Imspector.
29
+ # stack_groups groups stacks with same series number in the stack name and identical geometry.
30
+ # every stack belongs to exactly one group, unmatched stacks
31
+ # (e.g. line profiles, rescue_info maps) form single-member groups.
32
+ groups = f.stack_groups # list of StackGroup
33
+ img = f.read_stack_group(0) # read all "channels", stacked along a new first axis: e.g. (C, Z, Y, X)
34
+
35
+ # xarray integration (optional dependency: pip install msr-reader[xarray]):
36
+ # stacks as xarray.DataArray with labelled dims and physical coordinates
37
+ # (SI units of the file: meters for spatial axes, seconds for time)
38
+ da = f.read_stack_xr(idx) # dims e.g. ('z', 'y', 'x'), coords in meters
39
+ dag = f.read_stack_group_xr(0) # one DataArray with a leading 'channel' dim, labelled with channel names
40
+
41
+ # stacks without names (sometimes found in old files) can be grouped by geometry alone:
42
+ # with OBFFile('file_path.msr', group_unnamed_stacks=True) as f:
43
+
44
+ # Lightbox files use hierarchical stack names ('Overview 1/Image 1/14:03:01/STAR RED'):
45
+ # for .obf files, grouping by the path up to the last component (the
46
+ # acquisition) and the last component (the channel name) is enabled by
47
+ # default. for .msr files (Imspector), enable it explicitly:
48
+ # with OBFFile('file_path.msr', group_hierarchical_stacks=True) as f:
49
+ # pass group_hierarchical_stacks=False to disable it for .obf files.
50
+
51
+ # metadata
52
+ stack_shapes = f.shapes # list of stack shapes, including stack and dimension names
53
+ pixel_sizes = f.pixel_sizes # like shapes, but with pixel sizes (unit: meters)
54
+
55
+ # imspector metadata as xml string
56
+ xml_imspector_metadata = f.get_imspector_xml_metadata(idx)
57
+
58
+ # can be parsed with ElementTree, for example
59
+ et = ElementTree.fromstring(xml_imspector_metadata)
60
+ # find, e.g. x pixel size in XML
61
+ et.find('doc/ExpControl/scan/range/x/psz').text
62
+
63
+ # OME-XML metadata as xml string
64
+ xml_ome_metadata = f.get_ome_xml_metadata()
65
+ # can be parsed with ome-types, for example
66
+ ome_meta = ome_types.from_xml(xml_ome_metadata)
67
+ ```
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "msr-reader"
7
- version = "0.2.1-dev"
7
+ version = "0.3.1"
8
8
  authors = [
9
9
  { name="David Hörl", email="hoerldavid@gmail.com" },
10
10
  ]
@@ -19,6 +19,9 @@ classifiers = [
19
19
  ]
20
20
  dependencies = ["numpy"]
21
21
 
22
+ [project.optional-dependencies]
23
+ xarray = ["xarray"]
24
+
22
25
  [project.urls]
23
26
  "Homepage" = "https://github.com/hoerlteam/msr-reader"
24
27
  "Bug Tracker" = "https://github.com/hoerlteam/msr-reader/issues"
@@ -0,0 +1,2 @@
1
+ from .obffile import OBFFile, OBFHeader, OBFStackHeader, OBFStackFooter, OBFSIFraction, OBFSIUnit, StackGroup, StackSizes
2
+ from .xml_metadata import imspector_xml_to_dict