scitiff 0__py3-none-any.whl
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.
- scitiff/__init__.py +12 -0
- scitiff/_resources/schema.json +12 -0
- scitiff/_resources/scipp_dataarray_schema.json +31 -0
- scitiff/_resources/scipp_variable_schema.json +40 -0
- scitiff/io.py +96 -0
- scitiff/py.typed +0 -0
- scitiff-0.dist-info/LICENSE +33 -0
- scitiff-0.dist-info/METADATA +79 -0
- scitiff-0.dist-info/RECORD +11 -0
- scitiff-0.dist-info/WHEEL +5 -0
- scitiff-0.dist-info/top_level.txt +1 -0
scitiff/__init__.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# SPDX-License-Identifier: BSD-3-Clause
|
|
2
|
+
# Copyright (c) 2025 Ess-dmsc-dram contributors (https://github.com/ess-dmsc-dram)
|
|
3
|
+
# ruff: noqa: E402, F401, I
|
|
4
|
+
|
|
5
|
+
import importlib.metadata
|
|
6
|
+
|
|
7
|
+
try:
|
|
8
|
+
__version__ = importlib.metadata.version(__package__ or __name__)
|
|
9
|
+
except importlib.metadata.PackageNotFoundError:
|
|
10
|
+
__version__ = "0.0.0"
|
|
11
|
+
|
|
12
|
+
del importlib
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://github.com/YooSunYoung/esstiff/v0/src/esstiff/_resources/schema.json",
|
|
4
|
+
"title": "ESSTIFFMETA",
|
|
5
|
+
"description": "Neutron Imaging TIFF Metadata Schema",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"image": {
|
|
9
|
+
"$ref": "https://github.com/YooSunYoung/esstiff/v0/src/esstiff/_resources/scipp_dataarray_schema.json"
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://github.com/YooSunYoung/esstiff/v0/src/esstiff/_resources/scipp_dataarray_schema.json",
|
|
4
|
+
"title": "SCIPPDATAARRAY",
|
|
5
|
+
"description": "Scipp DataArray Schema",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"masks": {
|
|
9
|
+
"type": "object",
|
|
10
|
+
"items": {
|
|
11
|
+
"$ref": "https://github.com/YooSunYoung/esstiff/v0/src/esstiff/_resources/scipp_variable_schema.json"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"description": "Masks of the DataArray."
|
|
15
|
+
},
|
|
16
|
+
"coords": {
|
|
17
|
+
"type": "object",
|
|
18
|
+
"items": {
|
|
19
|
+
"$ref": "https://github.com/YooSunYoung/esstiff/v0/src/esstiff/_resources/scipp_variable_schema.json"
|
|
20
|
+
},
|
|
21
|
+
"description": "Coordinates of the DataArray."
|
|
22
|
+
},
|
|
23
|
+
"data": {
|
|
24
|
+
"$ref": "https://github.com/YooSunYoung/esstiff/v0/src/esstiff/_resources/scipp_variable_schema.json"
|
|
25
|
+
},
|
|
26
|
+
"name": {
|
|
27
|
+
"type": "string",
|
|
28
|
+
"description": "Name of the DataArray."
|
|
29
|
+
},
|
|
30
|
+
"required": ["data"]
|
|
31
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://github.com/YooSunYoung/esstiff/v0/src/esstiff/_resources/scipp_variable_schema.json",
|
|
4
|
+
"title": "SCIPPVARIABLE",
|
|
5
|
+
"description": "Scipp Variable Schema",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"dims": {
|
|
9
|
+
"type": "array",
|
|
10
|
+
"items": {
|
|
11
|
+
"type": "string"
|
|
12
|
+
},
|
|
13
|
+
"description": "Dimension names of the variable."
|
|
14
|
+
},
|
|
15
|
+
"shape": {
|
|
16
|
+
"type": "array",
|
|
17
|
+
"items": {
|
|
18
|
+
"type": "integer"
|
|
19
|
+
},
|
|
20
|
+
"description": "Shape of the variable."
|
|
21
|
+
},
|
|
22
|
+
"unit": {
|
|
23
|
+
"type": "string",
|
|
24
|
+
"description": "Unit of the variable."
|
|
25
|
+
},
|
|
26
|
+
"dtype": {
|
|
27
|
+
"type": "string",
|
|
28
|
+
"description": "Data type of the variable."
|
|
29
|
+
},
|
|
30
|
+
"values": {
|
|
31
|
+
"type": "array",
|
|
32
|
+
"description": "Values of the variable."
|
|
33
|
+
},
|
|
34
|
+
"variance": {
|
|
35
|
+
"type": "array",
|
|
36
|
+
"description": "Variance of the variable."
|
|
37
|
+
},
|
|
38
|
+
"required": ["dims", "shape", "unit", "dtype"]
|
|
39
|
+
}
|
|
40
|
+
}
|
scitiff/io.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import pathlib
|
|
3
|
+
|
|
4
|
+
import scipp as sc
|
|
5
|
+
import tifffile as tf
|
|
6
|
+
from scipp.compat.dict import from_dict, to_dict
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def _ensure_dimension_order(sizes: dict) -> dict:
|
|
10
|
+
# Order of the dimensions is according to the HyperStacks tiff format.
|
|
11
|
+
order = ['c', 't', 'z', 'y', 'x']
|
|
12
|
+
return {key: sizes[key] for key in order if key in sizes}
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _to_dict(var: sc.Variable) -> dict:
|
|
16
|
+
dict_var = to_dict(var)
|
|
17
|
+
dict_var['dtype'] = str(var.dtype)
|
|
18
|
+
dict_var['unit'] = str(var.unit)
|
|
19
|
+
dict_var['values'] = var.values.tolist()
|
|
20
|
+
return dict_var
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _extract_metadata_from_dataarray(da: sc.DataArray) -> dict:
|
|
24
|
+
default_sizes = {'x': 1, 'y': 1, 'z': 1, 't': 1, 'c': 1}
|
|
25
|
+
final_sizes = _ensure_dimension_order({**default_sizes, **da.sizes})
|
|
26
|
+
return {
|
|
27
|
+
'masks': {},
|
|
28
|
+
'coords': {key: _to_dict(da.coords[key]) for key in da.coords},
|
|
29
|
+
'data': {
|
|
30
|
+
'dims': tuple(final_sizes.keys()),
|
|
31
|
+
'shape': tuple(final_sizes.values()),
|
|
32
|
+
'unit': str(da.unit),
|
|
33
|
+
'dtype': str(da.dtype),
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _extract_metadata_from_datagroup(dg: sc.DataGroup) -> dict:
|
|
39
|
+
raise NotImplementedError(
|
|
40
|
+
"Extracting metadata from DataGroup to ESSTIFF is not yet implemented."
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def extract_metadata(dg: sc.DataGroup | sc.DataArray) -> dict:
|
|
45
|
+
if isinstance(dg, sc.DataArray):
|
|
46
|
+
return _extract_metadata_from_dataarray(dg)
|
|
47
|
+
else:
|
|
48
|
+
return _extract_metadata_from_datagroup(dg)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _export_data_array(da: sc.DataArray, file_path: str | pathlib.Path) -> None:
|
|
52
|
+
metadata = _extract_metadata_from_dataarray(da)
|
|
53
|
+
# Make sure the data is consistent with the metadata
|
|
54
|
+
# It is because ``z`` dimension and ``c`` dimension are often not present
|
|
55
|
+
# but it is require by the HyperStacks and esstiffmeta schema.
|
|
56
|
+
# Also, HyperStacks require specific order of dimensions.
|
|
57
|
+
dims = metadata['data']['dims']
|
|
58
|
+
shape = metadata['data']['shape']
|
|
59
|
+
sizes = dict(zip(dims, shape, strict=True))
|
|
60
|
+
final_image = sc.broadcast(da, sizes=sizes)
|
|
61
|
+
tf.imwrite(
|
|
62
|
+
file_path,
|
|
63
|
+
final_image.values,
|
|
64
|
+
imagej=True,
|
|
65
|
+
metadata={'esstiffmeta': json.dumps(metadata)},
|
|
66
|
+
dtype=str(final_image.dtype),
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _export_data_group(dg: sc.DataGroup, file_path: str | pathlib.Path) -> None:
|
|
71
|
+
raise NotImplementedError('Exporting DataGroup to ESSTIFF is not yet implemented.')
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def export(dg: sc.DataGroup | sc.DataArray, file_path: str | pathlib.Path) -> None:
|
|
75
|
+
if isinstance(dg, sc.DataArray):
|
|
76
|
+
_export_data_array(dg, file_path)
|
|
77
|
+
else:
|
|
78
|
+
_export_data_group(dg, file_path)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def load(file_path: str | pathlib.Path) -> sc.DataArray | sc.DataGroup:
|
|
82
|
+
with tf.TiffFile(file_path) as tif:
|
|
83
|
+
metadata = json.loads(tif.imagej_metadata['esstiffmeta'])
|
|
84
|
+
# metadata = tif.imagej_metadata['esstiffmeta']
|
|
85
|
+
|
|
86
|
+
img = tf.imread(file_path, squeeze=True)
|
|
87
|
+
# imread squeezes the dimensions, so we need to keep the original sizes
|
|
88
|
+
# if not squeezed, the sizes have 1 extra dimension that I do not understand...
|
|
89
|
+
sizes = dict(zip(metadata['data']['dims'], metadata['data']['shape'], strict=True))
|
|
90
|
+
# Drop 1 size dimensions
|
|
91
|
+
sizes = {key: value for key, value in sizes.items() if value > 1}
|
|
92
|
+
# Update the metadata with the correct sizes
|
|
93
|
+
metadata['data']['dims'] = tuple(sizes.keys())
|
|
94
|
+
metadata['data']['shape'] = tuple(sizes.values())
|
|
95
|
+
metadata['data']['values'] = img
|
|
96
|
+
return from_dict(metadata)
|
scitiff/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
<<<<<<< before updating
|
|
4
|
+
Copyright (c) 2025, Ess dmsc dram contributors (https://github.com/ESS-DMSC-DRAM)
|
|
5
|
+
=======
|
|
6
|
+
Copyright (c) 2025, Ess-dmsc-dram contributors (https://github.com/ess-dmsc-dram)
|
|
7
|
+
>>>>>>> after updating
|
|
8
|
+
All rights reserved.
|
|
9
|
+
|
|
10
|
+
Redistribution and use in source and binary forms, with or without
|
|
11
|
+
modification, are permitted provided that the following conditions are met:
|
|
12
|
+
|
|
13
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
14
|
+
list of conditions and the following disclaimer.
|
|
15
|
+
|
|
16
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
17
|
+
this list of conditions and the following disclaimer in the documentation
|
|
18
|
+
and/or other materials provided with the distribution.
|
|
19
|
+
|
|
20
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
21
|
+
contributors may be used to endorse or promote products derived from
|
|
22
|
+
this software without specific prior written permission.
|
|
23
|
+
|
|
24
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
25
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
26
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
27
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
28
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
29
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
30
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
31
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
32
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
33
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: scitiff
|
|
3
|
+
Version: 0
|
|
4
|
+
Summary: Scientific tiff format for imaging experiments.
|
|
5
|
+
Author: Scipp contributors
|
|
6
|
+
License: BSD 3-Clause License
|
|
7
|
+
|
|
8
|
+
<<<<<<< before updating
|
|
9
|
+
Copyright (c) 2025, Ess dmsc dram contributors (https://github.com/ESS-DMSC-DRAM)
|
|
10
|
+
=======
|
|
11
|
+
Copyright (c) 2025, Ess-dmsc-dram contributors (https://github.com/ess-dmsc-dram)
|
|
12
|
+
>>>>>>> after updating
|
|
13
|
+
All rights reserved.
|
|
14
|
+
|
|
15
|
+
Redistribution and use in source and binary forms, with or without
|
|
16
|
+
modification, are permitted provided that the following conditions are met:
|
|
17
|
+
|
|
18
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
19
|
+
list of conditions and the following disclaimer.
|
|
20
|
+
|
|
21
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
22
|
+
this list of conditions and the following disclaimer in the documentation
|
|
23
|
+
and/or other materials provided with the distribution.
|
|
24
|
+
|
|
25
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
26
|
+
contributors may be used to endorse or promote products derived from
|
|
27
|
+
this software without specific prior written permission.
|
|
28
|
+
|
|
29
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
30
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
31
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
32
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
33
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
34
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
35
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
36
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
37
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
38
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
39
|
+
|
|
40
|
+
Project-URL: Bug Tracker, https://github.com/ess-dmsc-dram/scitiff/issues
|
|
41
|
+
Project-URL: Documentation, https://ess-dmsc-dram.github.io/scitiff
|
|
42
|
+
Project-URL: Source, https://github.com/ess-dmsc-dram/scitiff
|
|
43
|
+
Classifier: Intended Audience :: Science/Research
|
|
44
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
45
|
+
Classifier: Natural Language :: English
|
|
46
|
+
Classifier: Operating System :: OS Independent
|
|
47
|
+
Classifier: Programming Language :: Python :: 3
|
|
48
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
49
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
50
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
51
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
52
|
+
Classifier: Topic :: Scientific/Engineering
|
|
53
|
+
Classifier: Typing :: Typed
|
|
54
|
+
Requires-Python: >=3.10
|
|
55
|
+
Description-Content-Type: text/markdown
|
|
56
|
+
License-File: LICENSE
|
|
57
|
+
Requires-Dist: scipp
|
|
58
|
+
Requires-Dist: tifffile
|
|
59
|
+
Provides-Extra: test
|
|
60
|
+
Requires-Dist: pytest; extra == "test"
|
|
61
|
+
Provides-Extra: gui
|
|
62
|
+
Requires-Dist: textual; extra == "gui"
|
|
63
|
+
|
|
64
|
+
[](CODE_OF_CONDUCT.md)
|
|
65
|
+
[](https://pypi.python.org/pypi/scitiff)
|
|
66
|
+
[](https://anaconda.org/ess-dmsc-dram/scitiff)
|
|
67
|
+
[](LICENSE)
|
|
68
|
+
|
|
69
|
+
# SciTiff
|
|
70
|
+
|
|
71
|
+
## About
|
|
72
|
+
|
|
73
|
+
Scientific tiff format for imaging experiments.
|
|
74
|
+
|
|
75
|
+
## Installation
|
|
76
|
+
|
|
77
|
+
```sh
|
|
78
|
+
python -m pip install scitiff
|
|
79
|
+
```
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
scitiff/__init__.py,sha256=u5kTAwqcNRmhMusGAymmQwUmaFe2cUb5Z6nli38NEMs,343
|
|
2
|
+
scitiff/io.py,sha256=H50nzuKi-mcGjLpmU6uUlOTDNLTxDwZOQVyNe44g18E,3455
|
|
3
|
+
scitiff/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
scitiff/_resources/schema.json,sha256=tzN5QVap3ZaP89pWUDlq9VKPirVbSi4C2ACJuGAdurQ,437
|
|
5
|
+
scitiff/_resources/scipp_dataarray_schema.json,sha256=nAdl1LCpPMlx4R4GHRChZyEZRmFlgx71XY52jOK_HbM,1146
|
|
6
|
+
scitiff/_resources/scipp_variable_schema.json,sha256=5ImZxhmdrA9pA48Sf2h_XESfqQ2ImCWTDsvr8u1gZfw,1180
|
|
7
|
+
scitiff-0.dist-info/LICENSE,sha256=_Bh9c1E9tOIWkC1UNiP2s20o0B2fKMvjkIToYwyD_Ak,1706
|
|
8
|
+
scitiff-0.dist-info/METADATA,sha256=hqaK-HOiPYOvybjd9elzTq54wXc65gi_0Vh5d5n-Ofw,3654
|
|
9
|
+
scitiff-0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
10
|
+
scitiff-0.dist-info/top_level.txt,sha256=3myw3OlrZB26nwhtLRK3cdKmzfKbOAQ7GKuiUEzFxNM,8
|
|
11
|
+
scitiff-0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
scitiff
|