Commit 3e1056f2 authored by myron's avatar myron Committed by Pierre Paleo
Browse files

it works correctly

parent 3470f4fd
......@@ -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]
......
......@@ -158,12 +158,12 @@ def get_focus_data(*dataset_path):
return data, img_pos, pixel_size, (calib_data_std, calib_data_angle)
def _peaks2im(possY, possX, 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(possY, possX, 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
possX = -NX / 2.0 + 2 * NX * np.random.random(npoints)
possY = -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(possY, possX, widths, NY, NX)
im1 = _peaks2im(poss_y, poss_x, widths, ny, nx)
CHT = 201.67
CenterX = 400.123
shiftY = 3.1415
possX_2 = 2 * CenterX - possX
possY_2 = shiftY + possY
poss_x_2 = 2 * CenterX - poss_x
poss_y_2 = shiftY + poss_y
im2 = _peaks2im(possY_2, possX_2, widths, NY, NX)
im2 = _peaks2im(poss_y_2, poss_x_2, widths, ny, nx)
npoints_spurious = 200
spurious_possX = NX * np.random.random(npoints_spurious)
spurious_possY = 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_possY, spurious_possX, widths, NY, NX)
spurious_im = _peaks2im(spurious_poss_y, spurious_poss_x, widths, ny, nx)
im1[:] += spurious_im * 0.1
spurious_possX = NX * np.random.random(npoints_spurious)
spurious_possY = 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_possY, spurious_possX, 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()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment