def test_map_values_std_isset(self, weighted): self._post_setup_method(weighted) m = self.m L = Gaussian(centre=15.) L.centre.free = L.sigma.free = False m.append(L) m.multifit(iterpath="serpentine") nonlinear = L.A.map.copy() L.A.map['is_set'] = False cm = pytest.warns(UserWarning) if weighted and not self.s._lazy else \ dummy_context_manager() with cm: m.multifit(optimizer='lstsq', calculate_errors=True) linear = L.A.map.copy() np.testing.assert_allclose(nonlinear['values'], linear['values']) np.testing.assert_allclose(nonlinear['std'], linear['std']) np.testing.assert_allclose(nonlinear['is_set'], linear['is_set']) cm = pytest.warns(UserWarning) if weighted and not self.s._lazy else \ dummy_context_manager() with cm: m.multifit(optimizer='lstsq', calculate_errors=False) np.testing.assert_equal(L.A.map['std'], np.nan)
def test_offset(self, weighted): self._post_setup_method(weighted) m = self.m L = Offset(offset=1.) m.append(L) m.fit(optimizer='lstsq') single = m.as_signal() m.assign_current_values_to_all() cm = pytest.warns(UserWarning) if weighted and not self.s._lazy else \ dummy_context_manager() with cm: m.multifit(optimizer='lstsq', iterpath='serpentine') multi = m.as_signal() # compare fits from first pixel np.testing.assert_allclose(single(), multi())
def test_gaussian(self, weighted): self._post_setup_method(weighted) m = self.m L = Gaussian(centre=15.) L.centre.free = L.sigma.free = False m.append(L) m.fit(optimizer='lstsq') single = m.as_signal() m.assign_current_values_to_all() cm = pytest.warns(UserWarning) if weighted and not self.s._lazy else \ dummy_context_manager() with cm: m.multifit(optimizer='lstsq', iterpath='serpentine') multi = m.as_signal() np.testing.assert_allclose(single(), multi())
def test_main_header_from_signal(unit, expected_scale_factor, version, fheb, sig, fake_signals, metadata, fake_metadatas): signal = fake_signals[sig] if metadata is not None: signal._metadata = fake_metadatas[metadata] signal.axes_manager[-1].units = unit signal.axes_manager[-2].units = unit original_scale_x = signal.axes_manager[-2].scale if unit == "foo": cm = pytest.warns(UserWarning) else: cm = dummy_context_manager() with cm: header = _get_main_header_from_signal(signal, version, fheb) assert header["size"] == np.dtype(TVIPS_RECORDER_GENERAL_HEADER).itemsize assert header["version"] == version assert header["dimx"] == signal.axes_manager[-2].size assert header["dimy"] == signal.axes_manager[-1].size assert header["offsetx"] == 0 assert header["offsety"] == 0 assert header["pixelsize"] == original_scale_x * expected_scale_factor assert header["frameheaderbytes"] == np.dtype( TVIPS_RECORDER_FRAME_HEADER).itemsize + fheb if metadata == "diffraction" and unit == "1/pm": assert header[ "magtotal"] == signal.metadata.Acquisition_instrument.TEM.camera_length elif metadata == "imaging" and unit == "um": assert header[ "magtotal"] == signal.metadata.Acquisition_instrument.TEM.magnification else: assert header["magtotal"] == 0 if metadata is None: assert header["ht"] == 0 else: assert header[ "ht"] == signal.metadata.Acquisition_instrument.TEM.beam_energy