def allocate_measurement(self, grid: Grid, wavelength: float, scan: AbstractScan) -> Measurement: grid.check_is_defined() calibrations = calibrations_from_grid(grid.gpts, grid.sampling, names=['x', 'y'], units='Å') array = np.zeros(scan.shape + grid.gpts, dtype=np.complex64) measurement = Measurement(array, calibrations=scan.calibrations + calibrations) if isinstance(self.save_file, str): measurement = measurement.write(self.save_file) return measurement
def test_create_grid(): grid = Grid(extent=5, sampling=.2) assert (grid.extent[0] == 5.) & (grid.extent[1] == 5.) assert (grid.gpts[0] == 25) & (grid.gpts[1] == 25) assert (grid.sampling[0] == .2) & (grid.sampling[1] == .2) grid = Grid(sampling=.2, gpts=10) assert (grid.extent[0] == 2.) & (grid.extent[1] == 2.) grid = Grid(extent=(8, 6), gpts=10) assert (grid.sampling[0] == .8) & (grid.sampling[1] == .6) grid = Grid() with pytest.raises(RuntimeError): grid.check_is_defined()
def allocate_measurement(self, grid: Grid, wavelength: float, scan: AbstractScan) -> Measurement: grid.check_is_defined() shape = (grid.gpts[0] // 2, grid.gpts[1] // 2) calibrations = calibrations_from_grid(grid.antialiased_gpts, grid.antialiased_sampling, names=['alpha_x', 'alpha_y'], units='mrad', scale_factor=wavelength * 1000, fourier_space=True) array = np.zeros(scan.shape + shape) measurement = Measurement(array, calibrations=scan.calibrations + calibrations) if isinstance(self.save_file, str): measurement = measurement.write(self.save_file) return measurement
def show(self, grid: Grid, wavelength: float, cbar_label: str = 'Detector regions', **kwargs): grid.check_is_defined() array = np.full(grid.antialiased_gpts, -1, dtype=np.int) for i, indices in enumerate( self._get_regions(grid.antialiased_gpts, grid.antialiased_sampling, wavelength)): array.ravel()[indices] = i calibrations = calibrations_from_grid(grid.antialiased_gpts, grid.antialiased_sampling, names=['alpha_x', 'alpha_y'], units='mrad.', scale_factor=wavelength * 1000, fourier_space=True) return show_image(array, calibrations, cbar_label=cbar_label, discrete=True, **kwargs)