mlarray 0.0.10__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.
- mlarray/__init__.py +54 -0
- mlarray/cli.py +58 -0
- mlarray/meta.py +578 -0
- mlarray/mlarray.py +576 -0
- mlarray/utils.py +17 -0
- mlarray-0.0.10.data/data/mlarray/assets/banner.png +0 -0
- mlarray-0.0.10.data/data/mlarray/assets/banner.png~ +0 -0
- mlarray-0.0.10.dist-info/METADATA +247 -0
- mlarray-0.0.10.dist-info/RECORD +13 -0
- mlarray-0.0.10.dist-info/WHEEL +5 -0
- mlarray-0.0.10.dist-info/entry_points.txt +3 -0
- mlarray-0.0.10.dist-info/licenses/LICENSE +21 -0
- mlarray-0.0.10.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mlarray
|
|
3
|
+
Version: 0.0.10
|
|
4
|
+
Summary: A standardized blosc2 image reader and writer for medical images.
|
|
5
|
+
Author-email: Karol Gotkowski <karol.gotkowski@dkfz.de>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Karol-G/mlarray
|
|
8
|
+
Project-URL: Source, https://github.com/Karol-G/mlarray
|
|
9
|
+
Project-URL: Issues, https://github.com/Karol-G/mlarray/issues
|
|
10
|
+
Keywords: copier,template,python
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Requires-Python: >=3.10
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: blosc2>=3
|
|
20
|
+
Requires-Dist: numpy>=2
|
|
21
|
+
Provides-Extra: dev
|
|
22
|
+
Requires-Dist: build>=1.0; extra == "dev"
|
|
23
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
24
|
+
Requires-Dist: twine>=4.0; extra == "dev"
|
|
25
|
+
Requires-Dist: setuptools_scm[toml]>=8.0; extra == "dev"
|
|
26
|
+
Provides-Extra: all
|
|
27
|
+
Requires-Dist: medvol; extra == "all"
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
<p align="center">
|
|
31
|
+
<img src="https://raw.githubusercontent.com/Karol-G/mlarray/main/assets/banner.png" alt="{ML Array} banner" width="700" />
|
|
32
|
+
</p>
|
|
33
|
+
|
|
34
|
+
<p align="center">
|
|
35
|
+
<a href="https://pypi.org/project/mlarray/"><img src="https://img.shields.io/pypi/v/mlarray?logo=pypi&color=brightgreen&cacheSeconds=300&v=2026-01-22" alt="PyPI" align="middle" /></a>
|
|
36
|
+
<a href="https://pypi.org/project/mlarray/"><img src="https://img.shields.io/pypi/pyversions/mlarray?logo=python&cacheSeconds=300&v=2026-01-22" alt="Python Version" align="middle" /></a>
|
|
37
|
+
<a href="https://github.com/Karol-G/mlarray/actions"><img src="https://img.shields.io/github/actions/workflow/status/Karol-G/mlarray/workflow.yml?branch=main&logo=github" alt="Tests" align="middle" /></a>
|
|
38
|
+
<a href="https://github.com/copier-org/copier"><img src="https://img.shields.io/badge/template-copier-2ebd59?logo=jinja" alt="Copier Template" align="middle" /></a>
|
|
39
|
+
<a href="https://github.com/Karol-G/mlarray/blob/main/LICENSE"><img src="https://img.shields.io/github/license/Karol-G/mlarray" alt="License" align="middle" /></a>
|
|
40
|
+
</p>
|
|
41
|
+
|
|
42
|
+
**tl;dr:** Using large, medical or scientific images for Machine Learning? => Use MLArray
|
|
43
|
+
|
|
44
|
+
A standardized Blosc2 image reader and writer for medical images. The MLArray
|
|
45
|
+
file format (".mla") is a Blosc2-compressed container with standardized
|
|
46
|
+
metadata support for N-dimensional medical images. Plain ".b2nd" files are also
|
|
47
|
+
supported, but they do not participate in the MLArray metadata standard.
|
|
48
|
+
|
|
49
|
+
## Installation
|
|
50
|
+
|
|
51
|
+
You can install mlarray via [pip](https://pypi.org/project/mlarray/):
|
|
52
|
+
```bash
|
|
53
|
+
pip install mlarray
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
To enable the `mlarray_convert` CLI command, install MLArray with the necessary extra dependencies:
|
|
57
|
+
```bash
|
|
58
|
+
pip install mlarray[all]
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## API
|
|
62
|
+
|
|
63
|
+
See [API.md](API.md) for the full MLArray api, including argument
|
|
64
|
+
descriptions and types.
|
|
65
|
+
|
|
66
|
+
## Metadata schema
|
|
67
|
+
|
|
68
|
+
See [SCHEMA.md](SCHEMA.md) for the full MLArray metadata schema, including field
|
|
69
|
+
descriptions and types.
|
|
70
|
+
|
|
71
|
+
## Usage
|
|
72
|
+
|
|
73
|
+
Below are common usage patterns for loading, saving, and working with metadata.
|
|
74
|
+
|
|
75
|
+
### Default usage
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
import numpy as np
|
|
79
|
+
from mlarray import MLArray
|
|
80
|
+
|
|
81
|
+
array = np.random.random((128, 256, 256))
|
|
82
|
+
image = MLArray(array) # Create MLArray image
|
|
83
|
+
image.save("sample.mla")
|
|
84
|
+
|
|
85
|
+
image = MLArray("sample.mla") # Loads image
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Memory-mapped usage
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
from mlarray import MLArray
|
|
92
|
+
import numpy as np
|
|
93
|
+
|
|
94
|
+
# read-only, partial access (default)
|
|
95
|
+
image = MLArray().open("sample.mla", mmap='r')
|
|
96
|
+
crop = image[10:20, 50:60] # Read crop
|
|
97
|
+
|
|
98
|
+
# read/write, partial access
|
|
99
|
+
image = MLArray().open("sample.mla", mmap='r+')
|
|
100
|
+
image[10:20, 50:60] *= 5 # Modify crop in memory and disk
|
|
101
|
+
|
|
102
|
+
# read/write, partial access, create/overwrite
|
|
103
|
+
array = np.random.random((128, 256, 256))
|
|
104
|
+
image = MLArray().open("sample.mla", shape=array.shape, dtype=array.dtype, mmap='w+')
|
|
105
|
+
image[...] = array # Modify image in memory and disk
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Metadata inspection and manipulation
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
import numpy as np
|
|
112
|
+
from mlarray import MLArray
|
|
113
|
+
|
|
114
|
+
array = np.random.random((64, 128, 128))
|
|
115
|
+
image = MLArray(
|
|
116
|
+
array,
|
|
117
|
+
spacing=(1.0, 1.0, 1.5),
|
|
118
|
+
origin=(10.0, 10.0, 30.0),
|
|
119
|
+
direction=[[1, 0, 0], [0, 1, 0], [0, 0, 1]],
|
|
120
|
+
meta={"patient_id": "123", "modality": "CT"}, # Any image metadata (for example raw DICOM metadata)
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
print(image.spacing) # [1.0, 1.0, 1.5]
|
|
124
|
+
print(image.origin) # [10.0, 10.0, 30.0]
|
|
125
|
+
print(image.meta.image) # {"patient_id": "123", "modality": "CT"}
|
|
126
|
+
|
|
127
|
+
image.spacing[1] = 5.3
|
|
128
|
+
image.meta.image["study_id"] = "study-001"
|
|
129
|
+
image.save("with-metadata.mla")
|
|
130
|
+
|
|
131
|
+
# Open memory-mapped
|
|
132
|
+
image = MLArray().open("with-metadata.mla", mmap='r+')
|
|
133
|
+
image.meta.image["study_id"] = "new-study" # Modify metadata
|
|
134
|
+
image.close() # Close and save metadata, only necessary to save modified metadata
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Copy metadata with overrides
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
import numpy as np
|
|
141
|
+
from mlarray import MLArray
|
|
142
|
+
|
|
143
|
+
base = MLArray("sample.mla")
|
|
144
|
+
array = np.random.random(base.shape)
|
|
145
|
+
|
|
146
|
+
image = MLArray(
|
|
147
|
+
array,
|
|
148
|
+
spacing=(0.8, 0.8, 1.0),
|
|
149
|
+
copy=base, # Copies all non-explicitly set arguments from base
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
image.save("copied-metadata.mla")
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Standardized metadata usage
|
|
156
|
+
|
|
157
|
+
```python
|
|
158
|
+
import numpy as np
|
|
159
|
+
from mlarray import MLArray, Meta
|
|
160
|
+
|
|
161
|
+
array = np.random.random((64, 128, 128))
|
|
162
|
+
image = MLArray(
|
|
163
|
+
array,
|
|
164
|
+
meta=Meta(image={"patient_id": "123", "modality": "CT"}, is_seg=True), # Add metadata in a pre-defined format
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
print(image.meta.image) # {"patient_id": "123", "modality": "CT"}
|
|
168
|
+
print(image.meta.is_seg) # True
|
|
169
|
+
|
|
170
|
+
image.meta.image["study_id"] = "study-001"
|
|
171
|
+
image.meta.is_seg = False
|
|
172
|
+
image.save("with-metadata.mla")
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Patch size variants
|
|
176
|
+
|
|
177
|
+
Default patch size (192):
|
|
178
|
+
```python
|
|
179
|
+
from mlarray import MLArray
|
|
180
|
+
|
|
181
|
+
image = MLArray("sample.mla")
|
|
182
|
+
image.save("default-patch.mla") # Default patch_size is 'default' -> Isotropic patch size of 192 pixels
|
|
183
|
+
image.save("default-patch.mla", patch_size='default')
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Custom isotropic patch size (512):
|
|
187
|
+
```python
|
|
188
|
+
from mlarray import MLArray
|
|
189
|
+
|
|
190
|
+
image = MLArray("sample.mla")
|
|
191
|
+
image.save("patch-512.mla", patch_size=512)
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Custom non-isotropic patch size:
|
|
195
|
+
```python
|
|
196
|
+
from mlarray import MLArray
|
|
197
|
+
|
|
198
|
+
image = MLArray("sample.mla")
|
|
199
|
+
image.save("patch-non-iso.mla", patch_size=(128, 192, 256))
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Manual chunk/block size:
|
|
203
|
+
```python
|
|
204
|
+
from mlarray import MLArray
|
|
205
|
+
|
|
206
|
+
image = MLArray("sample.mla")
|
|
207
|
+
image.save("manual-chunk-block.mla", chunk_size=(1, 128, 128), block_size=(1, 32, 32))
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
Let Blosc2 itself configure chunk/block size:
|
|
211
|
+
```python
|
|
212
|
+
from mlarray import MLArray
|
|
213
|
+
|
|
214
|
+
image = MLArray("sample.mla")
|
|
215
|
+
# If patch_size, chunk_size and block_size are all None, Blosc2 will auto-configure chunk and block size
|
|
216
|
+
image.save("manual-chunk-block.mla", patch_size=None)
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## CLI
|
|
220
|
+
|
|
221
|
+
### mlarray_header
|
|
222
|
+
|
|
223
|
+
Print the metadata header from a `.mla` or `.b2nd` file.
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
mlarray_header sample.mla
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### mlarray_convert
|
|
230
|
+
|
|
231
|
+
Convert a NIfTI or NRRD file to MLArray and copy metadata.
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
mlarray_convert sample.nii.gz output.mla
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## Contributing
|
|
238
|
+
|
|
239
|
+
Contributions are welcome! Please open a pull request with clear changes and add tests when appropriate.
|
|
240
|
+
|
|
241
|
+
## Issues
|
|
242
|
+
|
|
243
|
+
Found a bug or have a request? Open an issue at https://github.com/Karol-G/mlarray/issues.
|
|
244
|
+
|
|
245
|
+
## License
|
|
246
|
+
|
|
247
|
+
Distributed under the MIT license. See `LICENSE` for details.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
mlarray/__init__.py,sha256=TOcW98poFXaGIlgFxoxtndaXa4cM34a7JWydWjqET0E,1757
|
|
2
|
+
mlarray/cli.py,sha256=W2ZBtEc6RU3g40L4ohsjEcmGPqkvL0S8I4imSSaRX9Y,2116
|
|
3
|
+
mlarray/meta.py,sha256=-_C1qJHb50TgRDVJpiwY-FADxf_HieVTq-8rHrcDmi8,22955
|
|
4
|
+
mlarray/mlarray.py,sha256=ozTfw6qW8v4WizcE_ev_t0qJdlpyZOHggUIZEA7vnPU,27349
|
|
5
|
+
mlarray/utils.py,sha256=wJR_vNDh-6fTcsJs6KpPgfDEr740ZHbTF1DW50X1YPk,351
|
|
6
|
+
mlarray-0.0.10.data/data/mlarray/assets/banner.png,sha256=sx280YW77U34X_jxxPW7w0eVI8OVT1SfI0lAkGgK-Hg,543044
|
|
7
|
+
mlarray-0.0.10.data/data/mlarray/assets/banner.png~,sha256=8odiUrP_Kc69NEEmkjiueyTeugE3Q882s4B7_UWP-ho,495025
|
|
8
|
+
mlarray-0.0.10.dist-info/licenses/LICENSE,sha256=97vFIfbV10hv1GHdxsByqvDRqXUGgZLuehZ2073dPLU,1072
|
|
9
|
+
mlarray-0.0.10.dist-info/METADATA,sha256=BNE8OEVG-fGo_KZLWqwlT3-R7MnBzkLcteaqOpEixdw,7270
|
|
10
|
+
mlarray-0.0.10.dist-info/WHEEL,sha256=qELbo2s1Yzl39ZmrAibXA2jjPLUYfnVhUNTlyF1rq0Y,92
|
|
11
|
+
mlarray-0.0.10.dist-info/entry_points.txt,sha256=_jak1nJItC8tmlbrjWewg4_2kyioVt2ZgXP4LAqaeV4,117
|
|
12
|
+
mlarray-0.0.10.dist-info/top_level.txt,sha256=739PKX_F3WKzLltjsUDX8lJlJJUrr67hqNwrx9ZlBNU,8
|
|
13
|
+
mlarray-0.0.10.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Karol Gotkowski
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
mlarray
|