Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
tomoscan
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tomotools
tomoscan
Commits
e9fa8141
Commit
e9fa8141
authored
1 month ago
by
payno
Browse files
Options
Downloads
Plain Diff
Merge branch 'cherry-pick-
b7cfba9c
' into 'main'
Merge branch 'fix_jp2k' into '2.1' See merge request
!256
parents
e67fb0f1
f2baa7a2
No related branches found
No related tags found
1 merge request
!256
Merge branch 'fix_jp2k' into '2.1'
Pipeline
#230518
passed
1 week ago
Stage: style
Stage: linting
Stage: test
Changes
2
Pipelines
5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tomoscan/esrf/volume/jp2kvolume.py
+8
-11
8 additions, 11 deletions
tomoscan/esrf/volume/jp2kvolume.py
tomoscan/esrf/volume/tests/test_jp2kvolume.py
+17
-9
17 additions, 9 deletions
tomoscan/esrf/volume/tests/test_jp2kvolume.py
with
25 additions
and
20 deletions
tomoscan/esrf/volume/jp2kvolume.py
+
8
−
11
View file @
e9fa8141
...
...
@@ -183,13 +183,16 @@ class JP2KVolume(VolumeSingleFrameBase):
if
not
has_glymur
:
raise
RuntimeError
(
_MISSING_GLYMUR_MSG
)
expected_output_dtype
=
frame
.
dtype
if
self
.
clip_values
is
not
None
:
frame
=
numpy
.
clip
(
frame
,
self
.
clip_values
[
0
],
self
.
clip_values
[
1
])
if
expected_output_dtype
not
in
(
numpy
.
uint8
,
numpy
.
uint16
):
_logger
.
info
(
f
"
{
self
.
get_identifier
().
to_str
()
}
get
{
frame
.
dtype
}
. Cast it as
{
numpy
.
uint16
}
"
)
expected_output_dtype
=
numpy
.
uint16
if
self
.
rescale_data
:
if
frame
.
dtype
in
(
numpy
.
uint8
,
numpy
.
uint16
):
max_uint
=
numpy
.
iinfo
(
frame
.
dtype
).
max
else
:
max_uint
=
numpy
.
iinfo
(
numpy
.
uint16
).
max
max_uint
=
numpy
.
iinfo
(
expected_output_dtype
).
max
frame
=
rescale_data
(
data
=
frame
,
new_min
=
0
,
...
...
@@ -197,13 +200,7 @@ class JP2KVolume(VolumeSingleFrameBase):
data_min
=
self
.
clip_values
[
0
]
if
self
.
clip_values
is
not
None
else
None
,
data_max
=
self
.
clip_values
[
1
]
if
self
.
clip_values
is
not
None
else
None
,
)
if
not
isinstance
(
frame
.
dtype
,
(
numpy
.
uint8
,
numpy
.
uint16
)):
if
self
.
_cast_already_logged
:
self
.
_cast_already_logged
=
True
_logger
.
info
(
f
"
{
self
.
get_identifier
().
to_str
()
}
get
{
frame
.
dtype
}
. Cast it as
{
numpy
.
uint16
}
"
)
frame
=
frame
.
astype
(
numpy
.
uint16
)
frame
=
frame
.
astype
(
expected_output_dtype
)
if
scheme
==
"
glymur
"
:
glymur
.
Jp2k
(
file_name
,
data
=
frame
,
psnr
=
self
.
psnr
,
cratios
=
self
.
cratios
)
...
...
This diff is collapsed.
Click to expand it.
tomoscan/esrf/volume/tests/test_jp2kvolume.py
+
17
−
9
View file @
e9fa8141
...
...
@@ -2,19 +2,24 @@
import
os
import
numpy
import
pytest
from
tomoscan.esrf.volume.jp2kvolume
import
JP2KVolume
from
tomoscan.esrf.volume.mock
import
create_volume
_data
=
create_volume
(
frame_dims
=
(
100
,
100
),
z_size
=
11
)
# z_size need to be at least 10 to check loading from file name works
for
i
in
range
(
len
(
_data
)):
_data
[
i
]
+=
1
_data
=
_data
.
astype
(
numpy
.
uint16
)
@pytest.fixture
def
raw_data
(
dtype
:
numpy
.
dtype
):
data
=
create_volume
(
frame_dims
=
(
100
,
100
),
z_size
=
11
)
# z_size need to be at least 10 to check loading from file name works
for
i
in
range
(
len
(
data
)):
data
[
i
]
+=
1
return
data
.
astype
(
dtype
)
def
test_jp2kvolume_rescale
(
tmp_path
):
@pytest.mark.parametrize
(
"
dtype
"
,
(
numpy
.
uint8
,
numpy
.
uint16
))
def
test_jp2kvolume_rescale
(
raw_data
,
dtype
,
tmp_path
):
"""
Test that rescale is correctly applied by default by the JP2KVolume
"""
...
...
@@ -22,10 +27,13 @@ def test_jp2kvolume_rescale(tmp_path):
os
.
makedirs
(
acquisition_dir
)
volume_dir
=
str
(
acquisition_dir
/
"
volume
"
)
os
.
makedirs
(
volume_dir
)
volume
=
JP2KVolume
(
folder
=
volume_dir
,
data
=
_data
,
metadata
=
{})
assert
raw_data
.
dtype
==
dtype
volume
=
JP2KVolume
(
folder
=
volume_dir
,
data
=
raw_data
,
metadata
=
{})
assert
volume
.
data
.
dtype
==
dtype
volume
.
save
()
volume
.
clear_cache
()
volume
.
load
()
assert
volume
.
data
.
dtype
==
dtype
assert
volume
.
data
.
min
()
==
0
assert
volume
.
data
.
max
()
==
numpy
.
iinfo
(
numpy
.
u
in
t16
).
max
assert
volume
.
data
.
max
()
in
(
numpy
.
iinfo
(
dtype
).
max
,
numpy
.
i
in
fo
(
dtype
).
max
-
1
)
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