Skip to content

Commit

Permalink
Apply scaling factor when reading the cube files
Browse files Browse the repository at this point in the history
  • Loading branch information
yakutovicha committed Dec 17, 2024
1 parent 7a38c6c commit 43278cc
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions cubehandler/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -131,18 +131,20 @@ 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):

Expand Down

0 comments on commit 43278cc

Please sign in to comment.