def load(filename, lazy=False): """Load data into pyxem objects. Parameters ---------- filename : str A single filename of a previously saved pyxem object. Other arguments may succeed, but will have fallen back on hyperspy load and warn accordingly lazy : bool If True the file will be opened lazily, i.e. without actually reading the data from the disk until required. Allows datasets much larger than available memory to be loaded. Returns ------- s : Signal A pyxem Signal object containing loaded data. """ s = hyperspyload(filename, lazy=lazy) if lazy: # pragma: no cover try: s = lazy_signal_dictionary[s.metadata.Signal.signal_type](s) except KeyError: raise ValueError("Invalid signal_type in saved data for pyxem, " "please use load_hspy for this data. ") else: try: s = signal_dictionary[s.metadata.Signal.signal_type](s) except KeyError: raise ValueError("Invalid signal_type in saved data for pyxem, " "please use load_hspy for this data. ") return s
def load_hspy(filename, lazy=False, assign_to=None): """Wraps hyperspy.load to load various file formats and assigns suitable loaded data to user specified pyxem signals. Parameters ---------- filename : str A single filename of a previously saved pyxem object. Other arguments may succeed, but will have fallen back on hyperspy load and warn accordingly lazy : bool If True the file will be opened lazily, i.e. without actually reading the data from the disk until required. Allows datasets much larger than available memory to be loaded. assign_to : str The signal class type the loaded data should be assigned to. If None, follows default hyperspy behaviour. Returns ------- s : Signal A pyxem Signal object containing loaded data. """ s = hyperspyload(filename, lazy=lazy) if assign_to: if lazy: # pragma: no cover try: s = lazy_signal_dictionary[assign_to](s) except KeyError: raise ValueError( "Invalid value of assign_to for lazy loading " "please specify a lazy pyXem signal or None. ") else: try: s = signal_dictionary[assign_to](s) except KeyError: raise ValueError("Invalid value of assign_to for loading " "please specify a pyXem signal or None. ") return s