Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
XRD
darfix
Commits
cc759976
Commit
cc759976
authored
Jun 17, 2021
by
Julia Garriga Ferrer
Browse files
[core][dataset] Modify shift_detection attributes
parent
040c4edd
Pipeline
#48809
passed with stage
in 2 minutes and 24 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
darfix/core/dataset.py
View file @
cc759976
...
...
@@ -737,7 +737,7 @@ class Dataset():
return
Dataset
(
_dir
=
roi_dir
,
data
=
new_data
,
dims
=
self
.
__dims
,
transformation
=
transformation
,
in_memory
=
self
.
_in_memory
)
def
find_shift
(
self
,
dimension
=
None
,
h_max
=
0.5
,
steps
=
5
0
,
indices
=
None
):
def
find_shift
(
self
,
dimension
=
None
,
steps
=
10
0
,
indices
=
None
):
"""
Find shift of the data or part of it.
...
...
@@ -751,7 +751,7 @@ class Dataset():
:type indices: Union[None, array_like]
:returns: Array with shift per frame.
"""
return
shift_detection
(
self
.
get_data
(
indices
,
dimension
),
h_max
,
steps
)
return
shift_detection
(
self
.
get_data
(
indices
,
dimension
),
steps
)
def
apply_shift
(
self
,
shift
,
dimension
=
None
,
shift_approach
=
"fft"
,
indices
=
None
,
callback
=
None
,
_dir
=
None
):
...
...
@@ -846,7 +846,7 @@ class Dataset():
return
Dataset
(
_dir
=
_dir
,
data
=
data
,
dims
=
self
.
__dims
,
transformation
=
self
.
transformation
,
in_memory
=
self
.
_in_memory
)
def
find_and_apply_shift
(
self
,
dimension
=
None
,
h_max
=
0.5
,
steps
=
5
0
,
shift_approach
=
"fft"
,
def
find_and_apply_shift
(
self
,
dimension
=
None
,
steps
=
10
0
,
shift_approach
=
"fft"
,
indices
=
None
,
callback
=
None
):
"""
Find the shift of the data or part of it and apply it.
...
...
@@ -863,7 +863,7 @@ class Dataset():
:param Union[function, None] callback: Callback
:returns: Dataset with the new data.
"""
shift
=
self
.
find_shift
(
dimension
,
h_max
,
steps
,
indices
=
indices
)
shift
=
self
.
find_shift
(
dimension
,
steps
,
indices
=
indices
)
return
self
.
apply_shift
(
shift
,
dimension
,
indices
=
indices
)
def
_cascade_nmf
(
self
,
num_components
,
iterations
,
vstep
=
None
,
hstep
=
None
,
indices
=
None
):
...
...
darfix/core/test/test_image_registration.py
View file @
cc759976
...
...
@@ -104,7 +104,7 @@ class TestImageRegistration(unittest.TestCase):
for
i
in
range
(
9
):
data
+=
[
numpy
.
fft
.
ifftn
(
scipy
.
ndimage
.
fourier_shift
(
numpy
.
fft
.
fftn
(
data
[
-
1
]),
shift
)).
real
]
data
=
numpy
.
asanyarray
(
data
,
dtype
=
numpy
.
int16
)
optimal_shift
=
imageRegistration
.
shift_detection
(
data
,
2
,
shift_approach
=
"fft"
)
optimal_shift
=
imageRegistration
.
shift_detection
(
data
,
100
,
shift_approach
=
"fft"
)
shift
=
[[
0
,
-
1
,
-
2
,
-
3
,
-
4
,
-
5
,
-
6
,
-
7
,
-
8
,
-
9
],
[
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
]]
...
...
@@ -122,7 +122,7 @@ class TestImageRegistration(unittest.TestCase):
for
i
in
range
(
9
):
data
+=
[
numpy
.
fft
.
ifftn
(
scipy
.
ndimage
.
fourier_shift
(
numpy
.
fft
.
fftn
(
data
[
-
1
]),
shift
)).
real
]
data
=
numpy
.
asanyarray
(
data
,
dtype
=
numpy
.
int16
)
optimal_shift
=
imageRegistration
.
shift_detection
(
data
,
2
,
shift_approach
=
"fft"
)
optimal_shift
=
imageRegistration
.
shift_detection
(
data
,
100
,
shift_approach
=
"fft"
)
shift
=
[[
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
],
[
0
,
-
1
,
-
2
,
-
3
,
-
4
,
-
5
,
-
6
,
-
7
,
-
8
,
-
9
]]
...
...
@@ -141,7 +141,7 @@ class TestImageRegistration(unittest.TestCase):
data
+=
[
numpy
.
fft
.
ifftn
(
scipy
.
ndimage
.
fourier_shift
(
numpy
.
fft
.
fftn
(
data
[
-
1
]),
shift
)).
real
]
data
=
numpy
.
asanyarray
(
data
,
dtype
=
numpy
.
int16
)
optimal_shift
=
imageRegistration
.
shift_detection
(
data
,
2
)
optimal_shift
=
imageRegistration
.
shift_detection
(
data
,
100
)
shift
=
[[
0
,
-
1
,
-
2
,
-
3
,
-
4
,
-
5
,
-
6
,
-
7
,
-
8
,
-
9
],
[
0
,
-
1
,
-
2
,
-
3
,
-
4
,
-
5
,
-
6
,
-
7
,
-
8
,
-
9
]]
...
...
@@ -159,8 +159,7 @@ class TestImageRegistration(unittest.TestCase):
for
i
in
range
(
9
):
data
+=
[
numpy
.
fft
.
ifftn
(
scipy
.
ndimage
.
fourier_shift
(
numpy
.
fft
.
fftn
(
data
[
-
1
]),
shift
)).
real
]
data
=
numpy
.
asanyarray
(
data
,
dtype
=
numpy
.
int16
)
optimal_shift
=
imageRegistration
.
shift_detection
(
data
,
1
)
optimal_shift
=
imageRegistration
.
shift_detection
(
data
,
100
)
shift
=
[[
0
,
-
0.5
,
-
1
,
-
1.5
,
-
2
,
-
2.5
,
-
3
,
-
3.5
,
-
4
,
-
4.5
],
[
0
,
-
0.2
,
-
0.4
,
-
0.6
,
-
0.8
,
-
1
,
-
1.2
,
-
1.4
,
-
1.6
,
-
1.8
]]
...
...
@@ -313,7 +312,7 @@ class TestReshapedShift(unittest.TestCase):
dataset
=
self
.
dataset
.
reshape_data
()
# Detects shift using only images where value 1 of dimension 1 is fixed
optimal_shift
=
dataset
.
find_shift
(
dimension
=
[
1
,
0
]
,
h_max
=
1
)
optimal_shift
=
dataset
.
find_shift
(
dimension
=
[
1
,
0
])
shift
=
[[
0
,
-
0.5
,
-
1
,
-
1.5
,
-
2
],
[
0
,
-
0.2
,
-
0.4
,
-
0.6
,
-
0.8
]]
...
...
@@ -334,7 +333,7 @@ class TestReshapedShift(unittest.TestCase):
dataset
=
self
.
dataset
.
reshape_data
()
# Detects shift using only images where value 1 of dimension 1 is fixed
optimal_shift
=
dataset
.
find_shift
(
dimension
=
[
0
,
0
]
,
h_max
=
3
)
optimal_shift
=
dataset
.
find_shift
(
dimension
=
[
0
,
0
])
shift
=
[[
0
,
-
2.5
],
[
0
,
-
1
]]
...
...
@@ -358,7 +357,7 @@ class TestReshapedShift(unittest.TestCase):
self
.
dataset
.
find_dimensions
(
POSITIONER_METADATA
)
dataset
=
self
.
dataset
.
reshape_data
()
dataset
=
dataset
.
find_and_apply_shift
(
dimension
=
[
1
,
0
]
,
h_max
=
1
)
dataset
=
dataset
.
find_and_apply_shift
(
dimension
=
[
1
,
0
])
for
frame
in
dataset
.
data
.
take
(
0
,
0
):
print
(
numpy
.
max
(
abs
(
data
[
0
]
-
frame
)))
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment