Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
qim3d
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
QIM
Tools
qim3d
Commits
ae03e0fd
Commit
ae03e0fd
authored
6 months ago
by
Christian Kento Rasmussen
Browse files
Options
Downloads
Patches
Plain Diff
pasted code from old pull request
parent
191449a5
Branches
Branches containing commit
No related tags found
1 merge request
!147
Draft: Convert tiff stacks to zarr
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
qim3d/io/_convert.py
+31
-0
31 additions, 0 deletions
qim3d/io/_convert.py
with
31 additions
and
0 deletions
qim3d/io/_convert.py
+
31
−
0
View file @
ae03e0fd
...
@@ -52,6 +52,10 @@ class Convert:
...
@@ -52,6 +52,10 @@ class Convert:
return
self
.
convert_zarr_to_nifti
(
input_path
,
output_path
)
return
self
.
convert_zarr_to_nifti
(
input_path
,
output_path
)
case
(
"
.zarr
"
,
"
.nii.gz
"
):
case
(
"
.zarr
"
,
"
.nii.gz
"
):
return
self
.
convert_zarr_to_nifti
(
input_path
,
output_path
,
compression
=
True
)
return
self
.
convert_zarr_to_nifti
(
input_path
,
output_path
,
compression
=
True
)
case
(
"
.zarr
"
,
""
):
self
.
convert_zarr_to_tiff_stack
(
input_path
,
output_path
)
case
(
""
,
"
.zarr
"
):
return
self
.
convert_tiff_stack_to_zarr
(
input_path
,
output_path
)
case
_
:
case
_
:
raise
ValueError
(
"
Unsupported file format
"
)
raise
ValueError
(
"
Unsupported file format
"
)
# Fail
# Fail
...
@@ -111,6 +115,33 @@ class Convert:
...
@@ -111,6 +115,33 @@ class Convert:
z
=
zarr
.
open
(
zarr_path
)
z
=
zarr
.
open
(
zarr_path
)
save
(
tif_path
,
z
)
save
(
tif_path
,
z
)
def
convert_zarr_to_tiff_stack
(
self
,
zarr_path
,
tiff_stack_path
):
"""
Convert a zarr file to a tiff stack
Args:
zarr_path (str): path to the zarr file
tiff_stack_path (str): path to the tiff stack
Returns:
None
"""
z
=
zarr
.
open
(
zarr_path
)
save
(
tiff_stack_path
,
z
,
basename
=
self
.
base_name
)
def
convert_tiff_stack_to_zarr
(
self
,
tiff_stack_path
,
zarr_path
):
"""
Convert a tiff stack to a zarr file
Args:
tiff_stack_path (str): path to the tiff stack
zarr_path (str): path to the zarr file
Returns:
zarr.core.Array: zarr array containing the data from the tiff stack
"""
# ! tiff stack memmap is stored as slices on disk and not as a single file, making assignments to blocks slow.
vol
=
load
(
tiff_stack_path
,
virtual_stack
=
True
,
contains
=
self
.
contains
)
return
self
.
_save_zarr
(
zarr_path
,
vol
)
def
convert_nifti_to_zarr
(
self
,
nifti_path
:
str
,
zarr_path
:
str
)
->
zarr
.
core
.
Array
:
def
convert_nifti_to_zarr
(
self
,
nifti_path
:
str
,
zarr_path
:
str
)
->
zarr
.
core
.
Array
:
"""
Convert a nifti file to a zarr file
"""
Convert a nifti file to a zarr file
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment