def test_export_import_measurement(tmp_path): d = tmp_path / 'sub' d.mkdir() path = d / 'measurement.hdf5' calibrations = calibrations_from_grid((512, 256), (.1, .3), ['x', 'y'], 'Å') measurement = Measurement(np.random.rand(512, 256), calibrations) measurement.write(path) imported_measurement = Measurement.read(path) assert np.allclose(measurement.array, imported_measurement.array) assert measurement.calibrations[0] == imported_measurement.calibrations[0] assert measurement.calibrations[1] == imported_measurement.calibrations[1]
def allocate_measurement(self, waves, scan: AbstractScan) -> Measurement: """ Allocate a Measurement object or an hdf5 file. Parameters ---------- waves : Waves or SMatrix object The wave function that will define the shape of the diffraction patterns. scan: Scan object The scan object that will define the scan dimensions the measurement. Returns ------- Measurement object or str The allocated measurement or path to hdf5 file with the measurement data. """ waves.grid.check_is_defined() calibrations = calibrations_from_grid(waves.gpts, waves.sampling, names=['x', 'y'], units='Å') array = np.zeros(scan.shape + waves.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 allocate_measurement(self, grid: Grid, wavelength: float, scan: AbstractScan) -> Measurement: inner, outer, nbins_radial, nbins_azimuthal = self._get_bins( grid.antialiased_sampling, wavelength) shape = scan.shape calibrations = scan.calibrations if nbins_radial > 1: shape += (nbins_radial, ) calibrations += (Calibration(offset=inner, sampling=self._radial_steps, units='mrad'), ) if nbins_azimuthal > 1: shape += (nbins_azimuthal, ) calibrations += (Calibration(offset=0, sampling=self._azimuthal_steps, units='rad'), ) array = np.zeros(shape, dtype=np.float32) measurement = Measurement(array, calibrations=calibrations) if isinstance(self.save_file, str): measurement = measurement.write(self.save_file) return measurement
def allocate_measurement(self, waves, scan: AbstractScan = None) -> Measurement: """ Allocate a Measurement object or an hdf5 file. Parameters ---------- waves : Waves or SMatrix object The wave function that will define the shape of the diffraction patterns. scan: Scan object The scan object that will define the scan dimensions the measurement. Returns ------- Measurement object or str The allocated measurement or path to hdf5 file with the measurement data. """ waves.grid.check_is_defined() waves.accelerator.check_is_defined() check_max_angle_exceeded(waves, self.max_angle) gpts = waves.downsampled_gpts(self.max_angle) gpts, new_angular_sampling = self._resampled_gpts( gpts, angular_sampling=waves.angular_sampling) sampling = (1 / new_angular_sampling[0] / gpts[0] * waves.wavelength * 1000, 1 / new_angular_sampling[1] / gpts[1] * waves.wavelength * 1000) calibrations = calibrations_from_grid(gpts, sampling, names=['alpha_x', 'alpha_y'], units='mrad', scale_factor=waves.wavelength * 1000, fourier_space=True) if scan is None: scan_shape = () scan_calibrations = () elif isinstance(scan, tuple): scan_shape = scan scan_calibrations = (None, ) * len(scan) else: scan_shape = scan.shape scan_calibrations = scan.calibrations array = np.zeros(scan_shape + gpts) measurement = Measurement(array, calibrations=scan_calibrations + calibrations) if isinstance(self.save_file, str): measurement = measurement.write(self.save_file) return measurement
def allocate_measurement(self, waves, scan: AbstractScan = None) -> Measurement: """ Allocate a Measurement object or an hdf5 file. Parameters ---------- waves : Waves object An example of the scan : Scan object The scan object that will define the scan dimensions the measurement. Returns ------- Measurement object or str The allocated measurement or path to hdf5 file with the measurement data. """ waves.grid.check_is_defined() waves.accelerator.check_is_defined() if scan is None: shape = () calibrations = () else: shape = scan.shape calibrations = scan.calibrations nbins_radial, nbins_azimuthal, inner, _ = self._get_bins( min(waves.cutoff_scattering_angles)) if nbins_radial > 1: shape += (nbins_radial, ) calibrations += (Calibration(offset=inner, sampling=self._radial_steps, units='mrad'), ) if nbins_azimuthal > 1: shape += (nbins_azimuthal, ) calibrations += (Calibration(offset=0, sampling=self._azimuthal_steps, units='rad'), ) array = np.zeros(shape, dtype=np.float32) measurement = Measurement(array, calibrations=calibrations) if isinstance(self.save_file, str): measurement = measurement.write(self.save_file) return measurement
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 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