From 432327401044bf7af82bdd06b1197179a10b17c7 Mon Sep 17 00:00:00 2001 From: Lenz Fiedler Date: Wed, 9 Oct 2024 18:36:00 +0200 Subject: [PATCH] Make from_numpy_file useable for DOS --- mala/targets/dos.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/mala/targets/dos.py b/mala/targets/dos.py index a6fcadf5d..faac8dfa4 100644 --- a/mala/targets/dos.py +++ b/mala/targets/dos.py @@ -509,6 +509,36 @@ def read_from_array(self, array, units="1/eV"): self.density_of_states = array return array + def read_from_numpy_file( + self, path, units=None, array=None, reshape=False + ): + """ + Read the data from a numpy file. + + Parameters + ---------- + path : string + Path to the numpy file. + + units : string + Units the data is saved in. + + array : np.ndarray + If not None, the array to save the data into. + The array has to be 4-dimensional. + + Returns + ------- + data : numpy.ndarray or None + If array is None, a numpy array containing the data. + Elsewise, None, as the data will be saved into the provided + array. + + """ + loaded_array = np.load(path) + self._process_loaded_array(loaded_array, units=units) + return loaded_array + # Calculations ##############