Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Z
zolfa-nd2reader
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Lorenzo ZOLFANELLI
zolfa-nd2reader
Commits
d0e4abcf
Commit
d0e4abcf
authored
5 years ago
by
Ruben Verweij
Browse files
Options
Downloads
Patches
Plain Diff
Fix issue #34
parent
b4967743
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
nd2reader/raw_metadata.py
+30
-11
30 additions, 11 deletions
nd2reader/raw_metadata.py
setup.py
+0
-1
0 additions, 1 deletion
setup.py
tests/test_raw_metadata.py
+11
-0
11 additions, 0 deletions
tests/test_raw_metadata.py
tests/test_version.py
+2
-6
2 additions, 6 deletions
tests/test_version.py
with
43 additions
and
18 deletions
nd2reader/raw_metadata.py
+
30
−
11
View file @
d0e4abcf
...
...
@@ -158,18 +158,34 @@ class RawMetadata(object):
def
_parse_z_levels
(
self
):
"""
The different levels in the Z-plane.
If they are not available from the _parse_dimension function AND there
is NO
'
Dimensions:
'
textinfo item in the file, we return a range with
the length of z_coordinates if available, otherwise an empty list.
Returns:
list: the z levels, just a sequence from 0 to n.
"""
z_levels
=
self
.
_parse_dimension
(
r
"""
.*?Z\((\d+)\).*?
"""
)
if
0
!=
len
(
z_levels
):
# get the dimension text to check if we should apply the fallback or not
dimension_text
=
self
.
_parse_dimension_text
()
# this returns range(len(z_levels))
z_levels
=
self
.
_parse_dimension
(
r
"""
.*?Z\((\d+)\).*?
"""
,
dimension_text
)
if
len
(
z_levels
)
>
0
or
len
(
dimension_text
)
>
0
:
# Either we have found the z_levels (first condition) so return, or
# don't fallback, because Z is apparently not in Dimensions, so
# there should be no z_levels
return
z_levels
# Not available from dimension, get from z_coordinates
z_levels
=
parse_if_not_none
(
self
.
z_data
,
self
.
_parse_z_coordinates
)
if
z_levels
is
None
:
z_levels
=
[]
else
:
z_levels
=
range
(
len
(
z_levels
))
# No z coordinates, return empty list
return
[]
warnings
.
warn
(
"
Z-levels details missing in metadata. Using Z-coordinates instead.
"
)
return
z_levels
return
range
(
len
(
z_levels
))
def
_parse_z_coordinates
(
self
):
"""
The coordinate in micron for all z planes.
...
...
@@ -201,15 +217,18 @@ class RawMetadata(object):
return
dimension_text
def
_parse_dimension
(
self
,
pattern
):
dimension_text
=
self
.
_parse_dimension_text
()
def
_parse_dimension
(
self
,
pattern
,
dimension_text
=
None
):
dimension_text
=
self
.
_parse_dimension_text
()
if
dimension_text
is
None
else
dimension_text
if
dimension_text
is
None
:
return
[]
if
six
.
PY3
:
dimension_text
=
dimension_text
.
decode
(
"
utf8
"
)
match
=
re
.
match
(
pattern
,
dimension_text
)
if
not
match
:
return
[]
count
=
int
(
match
.
group
(
1
))
return
range
(
count
)
...
...
This diff is collapsed.
Click to expand it.
setup.py
+
0
−
1
View file @
d0e4abcf
from
os
import
path
from
setuptools
import
setup
from
nd2reader
import
__version__
as
VERSION
...
...
This diff is collapsed.
Click to expand it.
tests/test_raw_metadata.py
+
11
−
0
View file @
d0e4abcf
...
...
@@ -30,6 +30,17 @@ class TestRawMetadata(unittest.TestCase):
self
.
assertEqual
(
parse_dimension_text_line
(
line
),
six
.
b
(
'
Dimensions: T(443) x
\xce\xbb
(1)
'
))
self
.
assertIsNone
(
parse_dimension_text_line
(
six
.
b
(
'
Dim: nothing
'
)))
def
test_parse_z_levels
(
self
):
# smokescreen test to check if the fallback to z_coordinates is working
# for details, see RawMetadata._parse_z_levels()
dimension_text
=
self
.
metadata
.
_parse_dimension_text
()
z_levels
=
self
.
metadata
.
_parse_dimension
(
r
"""
.*?Z\((\d+)\).*?
"""
,
dimension_text
)
z_coords
=
self
.
metadata
.
_parse_z_coordinates
()
self
.
assertEqual
(
len
(
dimension_text
),
0
)
self
.
assertEqual
(
len
(
z_levels
),
0
)
self
.
assertEqual
(
len
(
self
.
metadata
.
_parse_z_levels
()),
len
(
z_coords
))
def
test_dict
(
self
):
self
.
assertTrue
(
type
(
self
.
metadata
.
__dict__
)
is
dict
)
...
...
This diff is collapsed.
Click to expand it.
tests/test_version.py
+
2
−
6
View file @
d0e4abcf
import
nd2reader
import
unittest
from
setup
import
VERSION
from
nd2reader
import
__version__
as
VERSION
class
TestVersion
(
unittest
.
TestCase
):
def
test_module_version_type
(
self
):
# just make sure the version number exists and is the type we expect
self
.
assertEqual
(
type
(
nd2reader
.
__version__
),
str
)
def
test_versions_in_sync
(
self
):
self
.
assertEqual
(
nd2reader
.
__version__
,
VERSION
)
self
.
assertEqual
(
type
(
VERSION
),
str
)
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