diff --git a/cubehandler/cube.py b/cubehandler/cube.py index f16c31e..a231783 100644 --- a/cubehandler/cube.py +++ b/cubehandler/cube.py @@ -75,7 +75,7 @@ def __init__( self.cell_n = cell_n @classmethod - def from_file_handle(cls, filehandle, read_data=True): + def from_file_handle(cls, filehandle, read_data=True, apply_scaling=True): f = filehandle c = cls() c.title = f.readline().rstrip() @@ -131,18 +131,24 @@ def from_file_handle(cls, filehandle, read_data=True): # data = np.array(f.read().split(), dtype=float) c.data = c.data.reshape(c.cell_n) + if apply_scaling: + c.data *= c.scaling_factor return c @classmethod - def from_file(cls, filepath, read_data=True): + def from_file(cls, filepath, read_data=True, apply_scaling=True): with open(filepath) as f: - c = cls.from_file_handle(f, read_data=read_data) + c = cls.from_file_handle( + f, read_data=read_data, apply_scaling=apply_scaling + ) return c @classmethod - def from_content(cls, content, read_data=True): - return cls.from_file_handle(io.StringIO(content), read_data=read_data) + def from_content(cls, content, read_data=True, apply_scaling=True): + return cls.from_file_handle( + io.StringIO(content), read_data=read_data, apply_scaling=apply_scaling + ) def write_cube_file(self, filename, low_precision=False): diff --git a/tests/test_cube.py b/tests/test_cube.py index 34155ae..162e638 100644 --- a/tests/test_cube.py +++ b/tests/test_cube.py @@ -88,6 +88,6 @@ def test_reduce_data_density(): cube.reduce_data_density(points_per_angstrom=2) cube.write_cube_file("low_res.cube", low_precision=True) low_res = Cube.from_file("low_res.cube") - low_res_integral = np.sum(low_res.data**2) * low_res.dv_au * low_res.scaling_f**2 + low_res_integral = np.sum(low_res.data**2) * low_res.dv_au assert np.abs(low_res_integral - integral) < 0.01 assert cube.scaling_f == 0.2848452