def test_alternate_fails_unless_squashed(self): tmp_dir = mkdtemp() + os.path.sep cols, rows, alternate = 3000, 2000, True self.steps_to_do = cols * rows xs = LineGenerator("x", "mm", 0.0, 0.5, cols, alternate=alternate) ys = LineGenerator("y", "mm", 0.0, 0.1, rows) self.generator = CompoundGenerator([ys, xs], [], [], 0.1) self.generator.prepare() with self.assertRaises(BadValueError): self.o.on_configure( self.context, self.completed_steps, self.steps_to_do, generator=self.generator, fileDir=tmp_dir, formatName="odin3", ) self.generator = CompoundGenerator( [ys, xs], [SquashingExcluder(axes=["x", "y"])], [], 0.1) self.generator.prepare() self.o.on_configure( self.context, self.completed_steps, self.steps_to_do, generator=self.generator, fileDir=tmp_dir, formatName="odin2", )
def test_from_dict(self): _dict = dict() _dict['axes'] = ["x", "y"] e = SquashingExcluder.from_dict(_dict) self.assertEqual(["x", "y"], e.axes)
def _configure_args( self, generator: AGenerator, file_dir: AFileDir, detectors: ADetectorTable = None, axes_to_move: AAxesToMove = None, breakpoints: ABreakpoints = None, file_template: AFileTemplate = "%s.h5", ) -> Tuple[bool, int, Dict[str, Any]]: # Check the detector table to see what we need to do assert detectors, "No detectors" for enable, name, mri, exposure, frames in detectors.rows(): if name == self.name and enable: # Found a row saying to take part assert mri == self.mri, "%s has mri %s, passed %s" % ( name, self.mri, mri, ) break else: # Didn't find a row or no frames, don't take part return False, 0, {} # If we had more than one frame per point, multiply out if frames > 1: axis_name = name + "_frames_per_step" axes_to_move = list(cast(Iterable, axes_to_move)) + [axis_name] # We need to multiply up the last dimension by frames serialized = dict(generator.to_dict()) serialized["generators"] = list(serialized["generators"]) + [ StaticPointGenerator(frames, axes=[axis_name]) ] # Squash it down with the axes of the fastest generator squash_axes = list(generator.generators[-1].axes) + [axis_name] serialized["excluders"] = list(serialized["excluders"]) + [ SquashingExcluder(axes=squash_axes) ] # Divide it down serialized["duration"] = float(serialized["duration"]) / frames generator = CompoundGenerator.from_dict(serialized) kwargs = dict( generator=generator, axesToMove=axes_to_move, breakpoints=breakpoints, fileDir=file_dir, # formatName is the unique part of the HDF filename, so use the part # name for this formatName=self.name, fileTemplate=file_template, ) if exposure > 0.0: kwargs["exposure"] = exposure return enable, frames, kwargs
class TestCreateMask(ScanPointGeneratorTest): def setUp(self): self.e = SquashingExcluder(["x", "y"]) def test_create_mask_returns_all_points(self): x_points = np.array([1, 2, 3, 4]) y_points = np.array([10, 10, 20, 20]) expected_mask = np.array([True, True, True, True]) mask = self.e.create_mask(x_points, y_points) self.assertEqual(expected_mask.tolist(), mask.tolist())
def make_generator(squashed=False, include_z=False): line0 = LineGenerator("z", "mm", 0, 2, 4) line1 = LineGenerator("y", "mm", 0, 2, 3) line2 = LineGenerator("x", "mm", 0, 2, 2, alternate=True) if squashed: excluders = [SquashingExcluder(axes=("x", "y"))] else: excluders = [] if include_z: generators = [line0, line1, line2] else: generators = [line1, line2] compound = CompoundGenerator(generators, excluders, []) return compound
def test_configure_multiple_no_exposure(self): xs = LineGenerator("x", "mm", 0.0, 0.3, 4) ys = LineGenerator("y", "mm", 0.0, 0.1, 2) generator = CompoundGenerator([ys, xs], [], [], 1.0) generator.prepare() detectors = DetectorTable.from_rows([[True, "det", "DET", 0.0, 5]]) self.o.on_configure(self.context, generator, detectors) assert self.o.generator_duration == 1.0 assert self.o.frames_per_step == 5 # Detector would normally be configured by DetectorChildPart detector = self.process.block_view("DET") spg = StaticPointGenerator(5, axes=["det_frames_per_step"]) ex = SquashingExcluder(axes=["det_frames_per_step", "x"]) generatormultiplied = CompoundGenerator([ys, xs, spg], [ex], [], 0.2) detector.configure(generatormultiplied, self.tmpdir) self.o.on_post_configure() self.check_pulse_mocks(0.19899, 0.2, 0.000505, 5)
def on_validate(self, generator: AGenerator, axesToMove: AAxesToMove) -> UParameterTweakInfos: if len(axesToMove) in (0, 1): # We can't have multiple dimensions here, so this must be ok return None # Check that we have a Squashing excluder in the generator which # contains all the axesToMove for excluder in generator.excluders: if isinstance(excluder, SquashingExcluder) and set( excluder.axes) == set(axesToMove): # We have already squashed the axes, so nothing to do return None # We need to squash any dimension containing axesToMove down serialized = dict(generator.to_dict()) serialized["excluders"] = list( serialized["excluders"]) + [SquashingExcluder(axes=axesToMove)] new_generator = CompoundGenerator.from_dict(serialized) return ParameterTweakInfo("generator", new_generator)
class TestSerialisation(unittest.TestCase): def setUp(self): self.e = SquashingExcluder(["x", "y"]) def test_to_dict(self): expected_dict = dict() expected_dict['typeid'] = \ "scanpointgenerator:excluder/SquashingExcluder:1.0" expected_dict['axes'] = ["x", "y"] d = self.e.to_dict() self.assertEqual(expected_dict, d) def test_from_dict(self): _dict = dict() _dict['axes'] = ["x", "y"] e = SquashingExcluder.from_dict(_dict) self.assertEqual(["x", "y"], e.axes)
def setUp(self): self.e = SquashingExcluder(["x", "y"])