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
tomotools
Nabu
Commits
3e1056f2
Commit
3e1056f2
authored
Oct 01, 2020
by
myron
Committed by
Pierre Paleo
Oct 08, 2020
Browse files
it works correctly
parent
3470f4fd
Changes
2
Hide whitespace changes
Inline
Side-by-side
nabu/preproc/alignment.py
View file @
3e1056f2
...
...
@@ -607,8 +607,8 @@ class CenterOfRotationAdaptiveSearch(CenterOfRotation):
The whole image is spanned during several applications of the apodisation. At each application
the apodisation function, which is a gaussian, is moved to a new guess position.
The lenght of the step, by which the gaussian is moved, and its sigma are
obtained by multiplying the shortest distance
to
the left or right border with
step_fraction and sigma_fraction factors
obtained by multiplying the shortest distance
from
the left or right border with
a self.
step_fraction and
self.
sigma_fraction factors
which ensure global overlapping
"""
sigma_fraction
=
1.0
/
4.0
step_fraction
=
1.0
/
6.0
...
...
@@ -673,7 +673,6 @@ class CenterOfRotationAdaptiveSearch(CenterOfRotation):
if margins is None or in the form of (margin1,margin2) the search is done between margin1 and dim_x-1-margin2.
If left to None then by default (margin1,margin2) = ( 10, 10 )
Raises
------
ValueError
...
...
@@ -789,7 +788,7 @@ class CenterOfRotationAdaptiveSearch(CenterOfRotation):
if
not
np
.
isnan
(
cost
):
found_centers
.
append
([
cost
,
abs
(
Xcor_rel
-
cor_position
),
cor_position
,
energy
])
Xcor
=
min
(
Xcor
+
Xcor
,
Xcor
+
(
dim_radio
-
Xcor
)
)
*
self
.
step_fraction
Xcor
=
min
(
Xcor
+
Xcor
*
self
.
step_fraction
,
Xcor
+
(
dim_radio
-
Xcor
)
*
self
.
step_fraction
)
found_centers
.
sort
()
cor_position
=
found_centers
[
0
][
2
]
...
...
nabu/preproc/tests/test_alignment.py
View file @
3e1056f2
...
...
@@ -158,12 +158,12 @@ def get_focus_data(*dataset_path):
return
data
,
img_pos
,
pixel_size
,
(
calib_data_std
,
calib_data_angle
)
def
_peaks2im
(
poss
Y
,
poss
X
,
widths
,
NY
,
NX
):
def
_peaks2im
(
poss
_y
,
poss
_x
,
widths
,
ny
,
nx
):
"""Given a set of positions, widths and the image shape creates an image with spots"""
res
=
np
.
zeros
([
NY
,
NX
],
"f"
)
ys
=
np
.
arange
(
NY
)
xs
=
np
.
arange
(
NX
)
for
py
,
px
,
w
in
zip
(
poss
Y
,
poss
X
,
widths
):
res
=
np
.
zeros
([
ny
,
nx
],
"f"
)
ys
=
np
.
arange
(
ny
)
xs
=
np
.
arange
(
nx
)
for
py
,
px
,
w
in
zip
(
poss
_y
,
poss
_x
,
widths
):
y
=
ys
-
py
x
=
xs
-
px
add
=
np
.
exp
(
-
((
y
*
y
)[:,
None
]
+
x
*
x
)
/
(
2.0
*
w
*
w
))
...
...
@@ -176,49 +176,49 @@ def _get_challenging_ImsCouple_for_halftomo_cor():
np
.
random
.
seed
(
0
)
NY
=
400
NX
=
500
ny
=
400
nx
=
500
npoints
=
2000
poss
X
=
-
NX
/
2.0
+
2
*
NX
*
np
.
random
.
random
(
npoints
)
poss
Y
=
-
NY
/
2.0
+
2
*
NY
*
np
.
random
.
random
(
npoints
)
poss
_x
=
-
nx
/
2.0
+
2
*
nx
*
np
.
random
.
random
(
npoints
)
poss
_y
=
-
ny
/
2.0
+
2
*
ny
*
np
.
random
.
random
(
npoints
)
widths
=
3
*
np
.
random
.
random
(
npoints
)
im1
=
_peaks2im
(
poss
Y
,
poss
X
,
widths
,
NY
,
NX
)
im1
=
_peaks2im
(
poss
_y
,
poss
_x
,
widths
,
ny
,
nx
)
CHT
=
201.67
CenterX
=
400.123
shiftY
=
3.1415
poss
X
_2
=
2
*
CenterX
-
poss
X
poss
Y
_2
=
shiftY
+
poss
Y
poss
_x
_2
=
2
*
CenterX
-
poss
_x
poss
_y
_2
=
shiftY
+
poss
_y
im2
=
_peaks2im
(
poss
Y
_2
,
poss
X
_2
,
widths
,
NY
,
NX
)
im2
=
_peaks2im
(
poss
_y
_2
,
poss
_x
_2
,
widths
,
ny
,
nx
)
npoints_spurious
=
200
spurious_poss
X
=
NX
*
np
.
random
.
random
(
npoints_spurious
)
spurious_poss
Y
=
NY
*
np
.
random
.
random
(
npoints_spurious
)
spurious_poss
_x
=
nx
*
np
.
random
.
random
(
npoints_spurious
)
spurious_poss
_y
=
ny
*
np
.
random
.
random
(
npoints_spurious
)
widths
=
[
20.0
]
*
npoints_spurious
spurious_im
=
_peaks2im
(
spurious_poss
Y
,
spurious_poss
X
,
widths
,
NY
,
NX
)
spurious_im
=
_peaks2im
(
spurious_poss
_y
,
spurious_poss
_x
,
widths
,
ny
,
nx
)
im1
[:]
+=
spurious_im
*
0.1
spurious_poss
X
=
NX
*
np
.
random
.
random
(
npoints_spurious
)
spurious_poss
Y
=
NY
*
np
.
random
.
random
(
npoints_spurious
)
spurious_poss
_x
=
nx
*
np
.
random
.
random
(
npoints_spurious
)
spurious_poss
_y
=
ny
*
np
.
random
.
random
(
npoints_spurious
)
widths
=
[
20.0
]
*
npoints_spurious
spurious_im
=
_peaks2im
(
spurious_poss
Y
,
spurious_poss
X
,
widths
,
NY
,
NX
)
spurious_im
=
_peaks2im
(
spurious_poss
_y
,
spurious_poss
_x
,
widths
,
ny
,
nx
)
im2
[:]
+=
spurious_im
*
0.1
noise_level
=
0.2
noise_ima1
=
np
.
random
.
normal
(
0.0
,
size
=
[
NY
,
NX
])
*
noise_level
noise_ima2
=
np
.
random
.
normal
(
0.0
,
size
=
[
NY
,
NX
])
*
noise_level
noise_ima1
=
np
.
random
.
normal
(
0.0
,
size
=
[
ny
,
nx
])
*
noise_level
noise_ima2
=
np
.
random
.
normal
(
0.0
,
size
=
[
ny
,
nx
])
*
noise_level
im1
[:]
+=
noise_ima1
im2
[:]
+=
noise_ima2
return
im1
,
im2
,
(
CenterX
-
(
NX
-
1
)
/
2.0
)
return
im1
,
im2
,
(
CenterX
-
(
nx
-
1
)
/
2.0
)
@
pytest
.
mark
.
usefixtures
(
"bootstrap_base"
)
...
...
@@ -365,10 +365,10 @@ class TestCor(object):
radios
=
nabu_get_data
(
"ha_autocor_radios.npz"
)
radio1
=
radios
[
"radio1"
]
radio2
=
radios
[
"radio2"
]
cor_pos
=
radios
[
"cor_pos"
]
radio2
=
np
.
fliplr
(
radio2
)
cor_pos
=
983.107
CoR_calc
=
alignment
.
CenterOfRotationAdaptiveSearch
()
...
...
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