ImageD11.sinograms.geometry module#
Sinogram-related geometric functions pulled from various places. The choice of reference frames is tricky. In regular 3DXRD, the origin of the lab reference frame is defined as the intersection between the middle of the beam and the rotation axis. However, because the rotation axis is moving, this gets more difficult for scanning 3DXRD. I have therefore defined the reference frames in the following way:
Static lab frame - vectors defined by the beam vector and the dty translation axis vector. Its origin is defined directly as (0,0,0): x: The intersection of the beam vector and the dty translation axis vector y: The centre of the beam horizontally z: The centre of the beam vertically dtyi is a discretisation of the dty motor values.
Sample frame Origin is the rotation axis The rotation axis is translated by dty. The sample frame rotates with omega This translates with dty and rotates with omega, CW about the rotation axis (looking top down). This has the rotation axis at its origin. y0 is the true value of dty when the rotation axis intersects the beam.
Step space An integer discretisation of the sample frame, in units of ystep:
si = sx / ystep sj = -sy / ystep
The rotation axis sits at the centre of pixel (0, 0).
Reconstruction space: Step space shifted so that every index is positive. Units are (ystep), coords are (ri, rj), and the array is plotted with origin=”lower” to match iradon output:
ri = si + recon_shape[0] // 2 rj = sj + recon_shape[1] // 2
As in step space, integer (ri, rj) label pixel centres, so index (0, 0) is the centre of the corner pixel rather than the outer corner of the image.
Note the integer division. The rotation axis always lands exactly on index (recon_shape[0] // 2, recon_shape[1] // 2), i.e. always on a pixel centre. When the reconstruction has an odd size that pixel is also the geometric middle of the array. When it has an even size there is no middle pixel: the geometric centre is at (N - 1) / 2, and the rotation axis sits half a pixel beyond it. Any code with its own opinion about where the centre of a volume is has to be told which convention we use, or it will be half a pixel out for even sizes. ASTRA is one such case, as it centres its volume on (N - 1) / 2.
Sinogram rows (dty and dtyi): dtyi is an integer discretisation of the dty motor values, counted from ymin:
dtyi = round((dty - ymin) / ystep)
As above, an integer dtyi labels the centre of a dty bin, so dtyi_to_dty returns bin centres and matches ds.ybincens.
The rotation axis is usually not on the middle row of the sinogram, because y0 is rarely exactly at the centre of the scanned dty range. sino_shift_and_pad returns the shift that moves it there, against the same ny // 2 convention as above:
shift = ny // 2 - (y0 - ymin) / ystep
The reconstruction routines treat sinogram row r as lying at (r - ny // 2 + shift) relative to the rotation axis, so this puts the axis at 0 as intended. Using ny / 2 here instead would place the axis half a pixel off for odd ny.
Diagrams are below, S indicates the rotation axis
lab frame:
x
- <——- O (0, 0) centre of beam
y
sample frame (could be rotated about omega then translated along lab y by dty):
x
- <——- S (0, 0)
y
Step space:
+ve ^ |
- i |
- -ve <——– S (0, 0)——–> +ve
- j
v
-ve
Reconstruction space (iradon output when plotted with origin=”lower”). S is at (recon_shape[0] // 2, recon_shape[1] // 2), and each label marks a pixel centre, so (0, 0) is the centre of the lower-left pixel:
- i | S = (recon_shape[0] // 2, recon_shape[1] // 2)
- (0, 0) ——->
j
- ImageD11.sinograms.geometry.dty_to_dtyi(dty, ystep, ymin)#
We take continuous dty space and discretise it We do this by counting the number of ysteps away from ymin ymin should probably be ds.ymin This should be equivalent to determining the closest bin in ds.ybincens But this is neater as it accounts for values outside the ds.ybincens range
dtyi = (dty - ymin) / ystep
- ImageD11.sinograms.geometry.dty_values_grain_in_beam(sx, sy, y0, omega)#
Calls dty_values_grain_in_beam_sincos after converting omega (degrees) into sinomega, cosomega
- ImageD11.sinograms.geometry.dty_values_grain_in_beam_sincos(sx, sy, y0, sinomega, cosomega)#
Take a grain positioned at (sx, sy) in the sample reference frame Determine the dty values needed to bring the grain into the beam as you rotate by omega. Equivalently, solve the sample<->lab conversion where ly = 0 (grain is in-beam). From sample_to_lab_sincos:
sxr = sx * cosomega - sy * sinomega syr = sx * sinomega + sy * cosomega
lx = sxr ly = syr + dty - y0
Therefore: ly = sx * sinomega + sy * cosomega + dty - y0
Solving for ly = 0: 0 = sx * sinomega + sy * cosomega + dty - y0 dty = y0 - sx * sinomega - sy * cosomega
- ImageD11.sinograms.geometry.dtycalc(omega, x, y, y0)#
- ImageD11.sinograms.geometry.dtyi_to_dty(dtyi, ystep, ymin)#
Simply: dty = (dtyi * ystep) + ymin
- ImageD11.sinograms.geometry.dtyimask_from_recon(ri, rj, omega, dtyi, y0, ystep, ymin, recon_shape)#
Given a position in recon space (ri, rj) and arrays of (omega, dtyi) values Convert recon space (ri, rj) to sample space (sx, sy) Mask each (omega, dtyi) value if they put the position (sx, sy) into the beam
- ImageD11.sinograms.geometry.dtyimask_from_recon_sincos(ri, rj, sinomega, cosomega, dtyi, y0, ystep, ymin, recon_shape)#
Given a position in recon space (ri, rj) and arrays of (sinomega, cosomega, dtyi) values Convert recon space (ri, rj) to sample space (sx, sy) Mask each (sinomega, cosomega, dtyi) value if they put the position (sx, sy) into the beam
- ImageD11.sinograms.geometry.dtyimask_from_sample(sx, sy, omega, dtyi, y0, ystep, ymin)#
Given a position in the sample (sx, sy) and arrays of (omega, dtyi) values Mask each (omega, dtyi) value if they put the position (sx, sy) into the beam
- ImageD11.sinograms.geometry.dtyimask_from_sample_sincos(sx, sy, sinomega, cosomega, dtyi, y0, ystep, ymin)#
Given a position in the sample (sx, sy) and arrays of (sinomega, cosomega, dtyi) values Mask each (sinomega, cosomega, dtyi) value if they put the position (sx, sy) into the beam
- ImageD11.sinograms.geometry.dtyimask_from_step(si, sj, omega, dtyi, y0, ystep, ymin)#
Given a position in step space (si, sj) and arrays of (omega, dtyi) values Convert step space (si, sj) to sample space (sx, sy) Mask each (omega, dtyi) value if they put the position (sx, sy) into the beam
- ImageD11.sinograms.geometry.dtyimask_from_step_sincos(si, sj, sinomega, cosomega, dtyi, y0, ystep, ymin)#
Given a position in step space (si, sj) and arrays of (sinomega, cosomega, dtyi) values Convert step space (si, sj) to sample space (sx, sy) Mask each (sinomega, cosomega, dtyi) value if they put the position (sx, sy) into the beam
- ImageD11.sinograms.geometry.fit_sample_position_from_recon(recon, ystep)#
Fits grain position in sample space by doing a LoG search with skimage on the reconstruction image Useful if grain is very small (close to pointlike) Returns position in sample frame (unit matches ystep) Returns None if we couldn’t find any blobs
- ImageD11.sinograms.geometry.fit_sine_wave(omega, dty, initial_guess, weights=None)#
Take a series of (omega, dty) values that originate from the same point in the sample. Determine the point in sample coordinates (sx, sy) by fitting a sine wave to the data. Includes a possible shift of the rotation axis in y (y0). In practice, we perform a curve_fit on dty_values_grain_in_beam to determine sx, sy, y0
- ImageD11.sinograms.geometry.lab_to_recon(lx, ly, y0, dty, omega, recon_shape, ystep)#
Converts lab space (lx, ly) to recon space (ri, rj)
- ImageD11.sinograms.geometry.lab_to_sample(lx, ly, y0, dty, omega)#
Calls lab_to_sample_sincos after converting omega (degrees) into sinomega, cosomega
- ImageD11.sinograms.geometry.lab_to_sample_sincos(lx, ly, y0, dty, sinomega, cosomega)#
Converts position in lab frame (lx, ly) to position in lab frame (sx, sy). The units of sx, sy, y0, and dty must agree.
- Parameters:
lx ((float, np.ndarray)) – X-coordinate in lab reference frame
ly ((float, np.ndarray)) – Y-coordinate in lab reference frame
y0 (float) – the true value of dty when the rotation axis intersects the beam
dty ((float, np.ndarray)) – the dty motor underneath the rotation axis
sinomega ((float, np.ndarray)) – the sine of the omega value of the rotation axis
cosomega ((float, np.ndarray)) – the cosine of the omega value of the rotation axis
- Returns:
sx, su: the x and y coordinates in the sample reference frame
- Return type:
((float, np.ndarray), (float, np.ndarray))
- ImageD11.sinograms.geometry.lab_to_step(lx, ly, y0, dty, omega, ystep)#
Converts lab space (lx, ly) to step space (si, sj)
- ImageD11.sinograms.geometry.recon_bins(ybincens, ymin, ystep, y0)#
Bin edges for the padded/shifted reconstruction, in sample-frame units (i.e. distance from the rotation axis S), centered on S.
- ImageD11.sinograms.geometry.recon_omega_to_dty(ri, rj, omega, y0, recon_shape, ystep)#
Convert recon space (ri, rj) to step space (si, sj) Then get corresponding dty values which puts (si, sj) into the beam given omega
- ImageD11.sinograms.geometry.recon_omega_to_dtyi(ri, rj, omega, y0, recon_shape, ystep, ymin)#
Convert recon space (ri, rj) to step space (si, sj) Then get corresponding dtyi values which puts (si, sj) into the beam given omega Then converts dty to dtyi
- ImageD11.sinograms.geometry.recon_to_lab(ri, rj, y0, dty, omega, recon_shape, ystep)#
Converts recon space (ri, rj) to lab space (lx, ly)
- ImageD11.sinograms.geometry.recon_to_sample(ri, rj, recon_shape, ystep)#
Converts reconstruction space (ri, rj) to sample space (sx, sy)
- ImageD11.sinograms.geometry.recon_to_step(ri, rj, recon_shape)#
Converts reconstruction space (ri, rj) to step space (si, sj)
- ImageD11.sinograms.geometry.sample_to_lab(sx, sy, y0, dty, omega)#
Calls sample_to_lab_sincos after converting omega (degrees) into sinomega, cosomega
- ImageD11.sinograms.geometry.sample_to_lab_sincos(sx, sy, y0, dty, sinomega, cosomega)#
Converts position in sample frame (sx, sy) to position in lab frame (lx, ly). The units of sx, sy, y0, and dty must agree.
- Parameters:
sx ((float, np.ndarray)) – X-coordinate in sample reference frame
sy ((float, np.ndarray)) – Y-coordinate in sample reference frame
y0 (float) – the true value of dty when the rotation axis intersects the beam
dty ((float, np.ndarray)) – the dty motor underneath the rotation axis
sinomega ((float, np.ndarray)) – the sine of the omega value of the rotation axis
cosomega ((float, np.ndarray)) – the cosine of the omega value of the rotation axis
- Returns:
lx, ly: the x and y coordinates in the lab reference frame
- Return type:
((float, np.ndarray), (float, np.ndarray))
- ImageD11.sinograms.geometry.sample_to_recon(sx, sy, recon_shape, ystep)#
Converts sample space (sx, sy) to reconstruction space (ri, rj)
- ImageD11.sinograms.geometry.sample_to_step(sx, sy, ystep)#
Converts sample (sx, sy) position to step space (si, sj)
- ImageD11.sinograms.geometry.sino_shift_and_pad(y0, ny, ymin, ystep)#
Determine the difference in sinogram pixels between the central dtyi value of the sinogram and the dtyi value of the rotation axis (from y0) To do this, we convert y0 into dtyi without rounding Also determine the minimum pad to get the whole sample in the frame Which should be double the shift
- ImageD11.sinograms.geometry.step_grid_from_ybincens(ybincens, step_size, gridstep, y0)#
Produce a grid in (si, sj) step space to reconstruct on. Constructs a symmetric grid with the origin on y0 Therefore the step space is truly aligned to the rotation axis. The size of the grid is determined by the extremes of ybincens. The grid will always be symmetric such that (0, 0) is the centre of an image formed from the grid :param ybincens: An evenly sampled dty space :type ybincens: np.ndarray :param step_size: the step size of the grid (same units as ybincens and y0) :type step_size: float :param gridstep: the sampling resolution of the grid (e.g 2 = [0, 2, 4, 6, …]) :type gridstep: int :return: (si, sj) for si in ints for sj in ints :rtype: tuple(int, int)
- ImageD11.sinograms.geometry.step_omega_to_dty(si, sj, omega, y0, ystep)#
Convert step space (si, sj) to sample space (sx, sy) Then get corresponding dty values which puts (sx, sy) into the beam given omega
- ImageD11.sinograms.geometry.step_omega_to_dtyi(si, sj, omega, y0, ystep, ymin)#
Convert step space (si, sj) to sample space (sx, sy) Then get corresponding dty values which puts (sx, sy) into the beam given omega Then converts dty to dtyi
- ImageD11.sinograms.geometry.step_to_lab(si, sj, y0, dty, omega, ystep)#
Converts step space (si, sj) to lab space (lx, ly)
- ImageD11.sinograms.geometry.step_to_recon(si, sj, recon_shape)#
Converts step space (si, sj) to reconstruction space (ri, rj)
- ImageD11.sinograms.geometry.step_to_sample(si, sj, ystep)#
Converts step space (si, sj) to sample position (sx, sy)
- ImageD11.sinograms.geometry.sx_sy_y0_from_dty_omega(dty, omega, y0=0, weights=None)#
Fits sine wave to dty vs omega plot, extracts sx, sy, y0
- ImageD11.sinograms.geometry.x_y_y0_omega_to_dty(omega, x, y, y0)#