def make_center_priors(im, z_range_extents=5, xy_uncertainty_pixels=1, z_range_units=None): """ Make sensible default priors for the center of a sphere in a hologram Parameters ---------- im : xarray The image you wish to make priors for z_range_extents : float (optional) What range to extend a uniform prior for z over, measured in multiples of the total extent of the image. The default is 5 times the extent of the image, a large range, but since tempering is quite good at refining this, it is safer to just choose a large range to be sure to include the correct value. xy_uncertainty_pixels: float (optional) The number of pixels of uncertainty to assume for the centerfinder. The default is 1 pixel, and this is probably correct for most images. z_range_units : float Specify the range of the z prior in your data units. If this is provided, z_range_extents is ignored. """ if z_range_units is not None: z_range = z_range_units else: extents = get_extents(im) extent = max(extents['x'], extents['y']) z_range = 0, extent * z_range_extents spacing = get_spacing(im) center = center_find(im) * spacing + [im.x[0], im.y[0]] xy_sd = xy_uncertainty_pixels * spacing return [Gaussian(c, s) for c, s in zip(center, xy_sd)] + [Uniform(*z_range)]
def test_on_detector_grid_when_size_is_1(self): shape = (1, 1) spacing = 0.1 true_extents = {'x': 0, 'y': 0, 'z': 0} detector = detector_grid(shape, spacing) extents = get_extents(detector) self.assertEqual(extents, true_extents)
def test_on_detector_grid_when_spacing_is_0(self): shape = (10, 12) # (x, y) spacing = 0.0 true_extents = {'x': 0, 'y': 0, 'z': 0} detector = detector_grid(shape, spacing) extents = get_extents(detector) self.assertEqual(extents, true_extents)
def _make_center_priors(self, params): image_x_values = self.data.x.values image_min_x = image_x_values.min() image_max_x = image_x_values.max() image_y_values = self.data.y.values image_min_y = image_y_values.min() image_max_y = image_y_values.max() if ('x' not in params) or ('y' not in params): pixel_spacing = get_spacing(self.data) image_lower_left = np.array([image_min_x, image_min_y]) center = center_find(self.data) * pixel_spacing + image_lower_left else: center = [params['x'], params['y']] xpar = prior.Uniform(image_min_x, image_max_x, guess=center[0]) ypar = prior.Uniform(image_min_y, image_max_y, guess=center[1]) extents = get_extents(self.data) extent = max(extents['x'], extents['y']) zextent = 5 zpar = prior.Uniform( -extent * zextent, extent * zextent, guess=params['z']) return xpar, ypar, zpar
def test_on_detector_grid_when_spacing_is_anisotropic(self): shape = (10, 12) # (x, y) spacing = (0.1, 0.2) true_extents = { 'x': shape[0] * spacing[0], 'y': shape[1] * spacing[1], 'z': 0 } detector = detector_grid(shape, spacing) extents = get_extents(detector) self.assertEqual(extents, true_extents)
def _make_center_priors(self, data, guess): image_x_values = data.x.values image_min_x = image_x_values.min() image_max_x = image_x_values.max() image_y_values = data.y.values image_min_y = image_y_values.min() image_max_y = image_y_values.max() if ('x' in guess) and ('y' in guess): x_guess = guess['x'] y_guess = guess['y'] elif ('center.0' in guess) and ('center.1' in guess): x_guess = guess['center.0'] y_guess = guess['center.1'] else: pixel_spacing = get_spacing(data) image_lower_left = np.array([image_min_x, image_min_y]) x_guess, y_guess = (center_find(data) * pixel_spacing + image_lower_left) extents = get_extents(data) # FIXME: 5 is a magic number. zextent = 5 * max(extents['x'], extents['y']) z_guess = guess['z'] if 'z' in guess else guess['center.2'] x = Parameter(name='x', value=x_guess, min=image_min_x, max=image_max_x) y = Parameter(name='y', value=y_guess, min=image_min_y, max=image_max_y) z = Parameter(name='z', value=z_guess, min=-zextent, max=zextent) return x, y, z