def test_multiscan(self): """A 2D scan.""" other = LinearMotor() values_0 = np.linspace(0, 10, 2) * q.mm values_1 = np.linspace(5, 10, 3) * q.mm range_0 = Region(self.motor['position'], values_0) range_1 = Region(other['position'], values_1) def feedback(): return self.motor.position, other.position gen = resolve(scan(feedback, [range_0, range_1])) p_0, p_1, result = zip(*gen) result_x, result_y = zip(*result) first_expected = [0 * q.mm, 10 * q.mm] second_expected = [5 * q.mm, 7.5 * q.mm, 10 * q.mm] combined = list(product(first_expected, second_expected)) p_0_exp, p_1_exp = zip(*combined) # test parameter values compare_sequences(p_0, p_0_exp, assert_almost_equal) compare_sequences(p_1, p_1_exp, assert_almost_equal) # feedback result is a tuple in this case, test both parts compare_sequences(result_x, p_0_exp, assert_almost_equal) compare_sequences(result_y, p_1_exp, assert_almost_equal)
def make_images(self, x_angle, z_angle, intervals=10): self.x_motor.position = z_angle self.z_motor.position = x_angle values = np.linspace(0, 2 * np.pi, intervals) * q.rad prange = Region(self.y_motor["position"], values) result = [f.result()[1] for f in scan(self.image_source.grab, prange)] return result
async def run(): other = LinearMotor() scanned = [] async for pair in scan((self.motor['position'], other['position']), (values_0, values_1), self.feedback): vec, res = pair scanned.append((vec[0], vec[1], res)) return scanned
def test_process(self): def feedback(): return self.motor.position values = np.linspace(1, 10, 12) * q.mm param_range = Region(self.motor['position'], values) x, y = zip(*list(resolve(scan(feedback, param_range)))) compare_sequences(x, y, self.assertEqual)
def test_callback(self): called = [] motor = LinearMotor() values = np.linspace(0, 2, 3) * q.mm qrange = Region(motor['position'], values) def callback(): called.append(motor.position.to(q.mm).magnitude) list(resolve(scan(lambda: None, qrange, callbacks={qrange: callback}))) np.testing.assert_almost_equal(called, range(3))
async def run(): scanned = [] async for pair in scan(self.motor['position'], np.arange(0, 10, 5) * q.mm, self.feedback): scanned.append(pair) return scanned
async def make_images(self, x_angle, z_angle, intervals=10): await self.x_motor.set_position(z_angle) await self.z_motor.set_position(x_angle) values = np.linspace(0, 2 * np.pi, intervals) * q.rad async for pair in scan(self.y_motor["position"], values, self.image_source.grab): yield pair[1]
def get_exposure_result(region): def get_mean_frame_value(): return np.mean(camera.grab()) return scan(get_mean_frame_value, region)