def test_save_load_hspy(self, save_path_hdf5): s = load(EMSOFT_FILE) axes_manager = setup_axes_manager(["energy", "height", "width"]) assert isinstance(s, EBSDMasterPattern) assert s.axes_manager.as_dictionary() == axes_manager assert_dictionary(s.metadata.as_dictionary(), METADATA) s.save(save_path_hdf5) s2 = hs_load(save_path_hdf5, signal_type="EBSDMasterPattern") assert isinstance(s2, EBSDMasterPattern) assert s2.axes_manager.as_dictionary() == axes_manager assert_dictionary(s2.metadata.as_dictionary(), METADATA) s3 = hs_load(save_path_hdf5) assert isinstance(s3, Signal2D) s3.set_signal_type("EBSDMasterPattern") assert isinstance(s3, EBSDMasterPattern) assert s3.axes_manager.as_dictionary() == axes_manager assert_dictionary(s.metadata.as_dictionary(), METADATA)
def test_original_metadata_save_load_cycle(self, save_path_hdf5): s = nickel_ebsd_master_pattern_small() omd_dict_keys = s.original_metadata.as_dictionary().keys() desired_keys = [ "BetheList", "EBSDMasterNameList", "MCCLNameList", "AtomData", "Atomtypes", "CrystalSystem", "LatticeParameters", "Natomtypes", ] assert [k in omd_dict_keys for k in desired_keys] s.save(save_path_hdf5) s2 = hs_load(save_path_hdf5, signal_type="EBSDMasterPattern") assert isinstance(s2, EBSDMasterPattern) omd_dict_keys2 = s2.original_metadata.as_dictionary().keys() assert [k in omd_dict_keys2 for k in desired_keys]
def test_load_save_hyperspy_cycle(self, tmp_path): s = load(KIKUCHIPY_FILE) # Perform decomposition to tests if learning results are # maintained after saving, reloading and using set_signal_type s.change_dtype(np.float32) s.decomposition() # Write both patterns and learning results to the HSpy file # format # file = tmp_path / "patterns.hspy" os.chdir(tmp_path) file = "patterns.hspy" s.save(file) # Reload data and use HyperSpy's set_signal_type function s_reload = hs_load(file) s_reload.set_signal_type("EBSD") # Check signal type, patterns and learning results assert isinstance(s_reload, EBSD) assert np.allclose(s.data, s_reload.data) assert np.allclose(s.learning_results.factors, s_reload.learning_results.factors)