diff --git a/ogs5py/fileclasses/asc/core.py b/ogs5py/fileclasses/asc/core.py index 73df2b5..19745d9 100644 --- a/ogs5py/fileclasses/asc/core.py +++ b/ogs5py/fileclasses/asc/core.py @@ -1,41 +1,41 @@ -# -*- coding: utf-8 -*- -""" -Class for the ogs ASC file. -""" - -from __future__ import absolute_import, division, print_function -from ogs5py.fileclasses.base import LineFile - - -class ASC(LineFile): - """ - Class for the ogs ASC file. - - Parameters - ---------- - lines : list of str, optional - content of the file as a list of lines - Default: None - file_name : str, optional - name of the file without extension - Default: "textfile" - task_root : str, optional - Path to the destiny folder. - Default: cwd+"ogs5model" - task_id : str, optional - Name for the ogs task. (a place holder) - Default: "model" - - Notes - ----- - This is just handled as a line-wise file. You can access the data by line - with: - - ASC.lines - - This file type comes either from .tim .pcs or .gem - """ - - def __init__(self, **OGS_Config): - super(ASC, self).__init__(**OGS_Config) - self.file_ext = ".asc" +# -*- coding: utf-8 -*- +""" +Class for the ogs ASC file. +""" + +from __future__ import absolute_import, division, print_function +from ogs5py.fileclasses.base import LineFile + + +class ASC(LineFile): + """ + Class for the ogs ASC file. + + Parameters + ---------- + lines : list of str, optional + content of the file as a list of lines + Default: None + name : str, optional + name of the file without extension + Default: "textfile" + task_root : str, optional + Path to the destiny folder. + Default: cwd+"ogs5model" + task_id : str, optional + Name for the ogs task. (a place holder) + Default: "model" + + Notes + ----- + This is just handled as a line-wise file. You can access the data by line + with: + + ASC.lines + + This file type comes either from .tim .pcs or .gem + """ + + def __init__(self, **OGS_Config): + super(ASC, self).__init__(**OGS_Config) + self.file_ext = ".asc" diff --git a/ogs5py/fileclasses/base.py b/ogs5py/fileclasses/base.py index e72dc04..3de5c23 100644 --- a/ogs5py/fileclasses/base.py +++ b/ogs5py/fileclasses/base.py @@ -64,6 +64,8 @@ class File(object): """ def __init__(self, task_root=None, task_id="model", file_ext=".std"): + self._name = None + self.name_from_id = True if task_root is None: task_root = os.path.join(CWD, "ogs5model") self.task_root = task_root @@ -85,14 +87,30 @@ def get_file_type(self): """Get the OGS file class name.""" return self._get_clsname() + @property + def name(self): + """:class:`str`: name of the file without extension.""" + if self.name_from_id: + return self.task_id + return self._name + + @name.setter + def name(self, value=None): + if value is None: + self.name_from_id = True + self._name = None + else: + self._name = str(value) + self.name_from_id = False + @property def file_path(self): """:class:`str`: save path of the file.""" - return os.path.join(self.task_root, self.task_id + self.file_ext) + return os.path.join(self.task_root, self.name + self.file_ext) @property - def name(self): - """:class:`str`: base name of the file.""" + def file_name(self): + """:class:`str`: base name of the file with extension.""" return os.path.basename(self.file_path) @property @@ -229,7 +247,7 @@ class LineFile(File): lines : list of str, optional content of the file as a list of lines Default: None - file_name : str, optional + name : str, optional name of the file without extension Default: "textfile" file_ext : str, optional @@ -246,22 +264,14 @@ class LineFile(File): def __init__( self, lines=None, - file_name="textfile", + name=None, file_ext=".txt", task_root=None, task_id="model", ): super(LineFile, self).__init__(task_root, task_id, file_ext) - if lines is not None: - self.lines = lines - else: - self.lines = [] - self.file_name = file_name - - @property - def file_path(self): - """:class:`str`: save path of the file.""" - return os.path.join(self.task_root, self.file_name + self.file_ext) + self.lines = [] if lines is None else lines + self.name = name @property def is_empty(self): diff --git a/ogs5py/fileclasses/gem/core.py b/ogs5py/fileclasses/gem/core.py index 55fa1fc..8ba94c1 100644 --- a/ogs5py/fileclasses/gem/core.py +++ b/ogs5py/fileclasses/gem/core.py @@ -1,385 +1,385 @@ -# -*- coding: utf-8 -*- -""" -Class for the ogs GEOCHEMICAL THERMODYNAMIC MODELING COUPLING file. -""" - -from __future__ import absolute_import, division, print_function -import os -from ogs5py.fileclasses.base import BlockFile, LineFile - -# current working directory -CWD = os.getcwd() - - -class GEM(BlockFile): - """ - Class for the ogs GEOCHEMICAL THERMODYNAMIC MODELING COUPLING file. - - Parameters - ---------- - task_root : str, optional - Path to the destiny model folder. - Default: cwd+"ogs5model" - task_id : str, optional - Name for the ogs task. - Default: "model" - - Notes - ----- - Main-Keywords (#): - - GEM_PROPERTIES - - Sub-Keywords ($) per Main-Keyword: - - GEM_PROPERTIES - - - CALCULATE_BOUNDARY_NODES - - DISABLE_GEMS - - FLAG_COUPLING_HYDROLOGY - - FLAG_DISABLE_GEM - - FLAG_POROSITY_CHANGE - - GEM_CALCULATE_BOUNDARY_NODES - - GEM_INIT_FILE - - GEM_THREADS - - ITERATIVE_SCHEME - - KINETIC_GEM - - MAX_FAILED_NODES - - MAX_POROSITY - - MIN_POROSITY - - MY_SMART_GEMS - - PRESSURE_GEM - - TEMPERATURE_GEM - - TRANSPORT_B - - Standard block: - None - - Keyword documentation: - https://ogs5-keywords.netlify.com/ogs/wiki/public/doc-auto/by_ext/gem - - Reading routines: - https://github.com/ufz/ogs5/blob/master/FEM/rf_REACT_GEM.cpp#L2644 - - See Also - -------- - add_block - """ - - MKEYS = ["GEM_PROPERTIES"] - # sorted - SKEYS = [ - [ - "GEM_INIT_FILE", - "GEM_THREADS", - "TRANSPORT_B", - "FLAG_POROSITY_CHANGE", - "MIN_POROSITY", - "MAX_POROSITY", - "FLAG_COUPLING_HYDROLOGY", - "ITERATIVE_SCHEME", - "CALCULATE_BOUNDARY_NODES", - "TEMPERATURE_GEM", - "PRESSURE_GEM", - "MAX_FAILED_NODES", - "MY_SMART_GEMS", - "FLAG_DISABLE_GEM", - "KINETIC_GEM", - "DISABLE_GEMS", # really? - "GEM_CALCULATE_BOUNDARY_NODES", # really? - "GEM_SMART", # really? - "FLAG_NODE_ELEMENT", # really? - "FLAG_CALCULATE_BOUNDARY_NODE", # really? - ] - ] - - STD = {} - - def __init__(self, **OGS_Config): - super(GEM, self).__init__(**OGS_Config) - self.file_ext = ".gem" - - -class GEMinit(object): - """ - Class for GEMS3K input file (lst file) that contains the names of - - * the GEMS data file (dch file), - * the GEMS numerical settings (ipm file) - * the example setup (dbr file) - - used to initialize the GEMS3K kernel. - - Parameters - ---------- - lst_name: :class:`str` or :class:`None`, optional - name of the lst file - dch: :any:`LineFile` or :class:`None` - the GEMS data file - ipm: :any:`LineFile` or :class:`None` - the GEMS data file - dbr: :any:`LineFile` or :class:`None` - the GEMS data file - task_root : str, optional - Path to the destiny model folder. - Default: cwd+"ogs5model" - task_id : str, optional - Name for the ogs task. - Default: "model" - - Notes - ----- - http://gems.web.psi.ch/GEMS3/index.html - - http://gems.web.psi.ch/GEMS3K/ - - http://gems.web.psi.ch/GEMS3K/doc/html/gems3k-iofiles.html - """ - - def __init__( - self, - lst_name="model-dat.lst", - dch=None, - ipm=None, - dbr=None, - task_root=None, - task_id="model", - ): - if task_root is None: - task_root = os.path.join(CWD, "ogs5model") - self._task_root = task_root - self.task_id = task_id - self.lst_name = lst_name - # add files - if dch is not None: - self.dch = dch - else: - self.dch = LineFile( - file_name=self.task_id + "-dch", - file_ext=".dat", - task_root=self.task_root, - ) - if ipm is not None: - self.ipm = ipm - else: - self.ipm = LineFile( - file_name=self.task_id + "-ipm", - file_ext=".dat", - task_root=self.task_root, - ) - if dbr is not None: - self.dbr = dbr - else: - self.dbr = LineFile( - file_name=self.task_id + "-dbr", - file_ext=".dat", - task_root=self.task_root, - ) - - def get_file_type(self): - """Get the OGS file class name""" - return "lst" - - @property - def files(self): - """ - List of the included files: dch, ipm, dbr. - """ - out_list = [] - if self.dch is not None: - out_list.append(self.dch) - if self.ipm is not None: - out_list.append(self.ipm) - if self.dbr is not None: - out_list.append(self.dbr) - return out_list - - @property - def file_name(self): - """ - The name of the lst file. - """ - return os.path.splitext(self.lst_name)[0] - - @property - def file_ext(self): - """ - The extension of the lst file. - """ - return os.path.splitext(self.lst_name)[1] - - @property - def file_names(self): - """ - The names of the included files. - """ - out_list = [] - for file in self.files: - out_list.append(file.file_name + file.file_ext) - return out_list - - def __bool__(self): - return not self.is_empty - - def __nonzero__(self): - return self.__bool__() - - @property - def is_empty(self): - """state if the file is empty""" - # check if the files are empty - if self.check(False): - return not any(self.files) - # if check is not passed, handle it as empty file - return True - - @property - def task_root(self): - """ - Get and set the task_root path of the ogs model. - """ - return self._task_root - - @task_root.setter - def task_root(self, value): - self._task_root = value - self.dch.task_root = value - self.ipm.task_root = value - self.dbr.task_root = value - - def reset(self): - """ - Delete every content. - """ - self.dch = LineFile( - file_name=self.task_id + "-dch", - file_ext=".dat", - task_root=self.task_root, - ) - self.ipm = LineFile( - file_name=self.task_id + "-ipm", - file_ext=".dat", - task_root=self.task_root, - ) - self.dbr = LineFile( - file_name=self.task_id + "-dbr", - file_ext=".dat", - task_root=self.task_root, - ) - - def check(self, verbose=True): - """ - Check if the GEM external file is valid. - - Parameters - ---------- - verbose : bool, optional - Print information for the executed checks. Default: True - - Returns - ------- - result : bool - Validity. - """ - # no checks are performed - out = True - for file in self.files: - out &= file.check(verbose) - return out - - def save(self, path): - """ - Save the actual GEM external file in the given path. - lst file containing: dch, ipm, dbr - - Parameters - ---------- - path : str - path to where to file should be saved - """ - for file in self.files: - file.write_file() - with open(path, "w") as fout: - fout.write(str(self)) - - def read_file(self, path, encoding=None, verbose=False): - """ - Read a given GEM external input lst-file. - - Parameters - ---------- - path : str - path to the file - - Notes - ----- - This also reads the given files in the lst-file. (dch, ipm, dbr) - """ - # in python3 open was replaced with io.open - # so we can use encoding key word in python2 - from io import open - - root = os.path.dirname(path) - - self.reset() - try: - with open(path, "r", encoding=encoding) as fin: - for line in fin: - if line.strip().startswith("-t"): - file_names = [] - # get rid of leading "-t" - for file_name in line.split()[1:]: - # get rid of " and ' around strings - file_names.append(file_name.strip('"').strip("'")) - break - except IOError: - if verbose: - print( - "ogs5py " - + self.get_file_type() - + ": could not read lst-file: " - + path - ) - else: - # hard coded order of files - self.dch.file_name = os.path.splitext(file_names[0])[0] - self.dch.file_ext = os.path.splitext(file_names[0])[1] - self.dch.read_file( - path=os.path.join(root, file_names[0]), - encoding=encoding, - verbose=verbose, - ) - self.ipm.file_name = os.path.splitext(file_names[1])[0] - self.ipm.file_ext = os.path.splitext(file_names[1])[1] - self.ipm.read_file( - path=os.path.join(root, file_names[1]), - encoding=encoding, - verbose=verbose, - ) - self.dbr.file_name = os.path.splitext(file_names[2])[0] - self.dbr.file_ext = os.path.splitext(file_names[2])[1] - self.dbr.read_file( - path=os.path.join(root, file_names[2]), - encoding=encoding, - verbose=verbose, - ) - - def write_file(self): - """ - Write the actual OGS input file to the given folder. - Its path is given by "task_root+task_id+file_ext". - """ - # create the file path - if not os.path.exists(self.task_root): - os.makedirs(self.task_root) - f_path = os.path.join(self.task_root, self.lst_name) - # save the data - if not self.is_empty: - self.save(f_path) - - def __repr__(self): - out_str = "-t" - for file_name in self.file_names: - out_str += ' "' + file_name + '"' - return out_str - - def __str__(self): - return self.__repr__() +# -*- coding: utf-8 -*- +""" +Class for the ogs GEOCHEMICAL THERMODYNAMIC MODELING COUPLING file. +""" + +from __future__ import absolute_import, division, print_function +import os +from ogs5py.fileclasses.base import BlockFile, LineFile + +# current working directory +CWD = os.getcwd() + + +class GEM(BlockFile): + """ + Class for the ogs GEOCHEMICAL THERMODYNAMIC MODELING COUPLING file. + + Parameters + ---------- + task_root : str, optional + Path to the destiny model folder. + Default: cwd+"ogs5model" + task_id : str, optional + Name for the ogs task. + Default: "model" + + Notes + ----- + Main-Keywords (#): + - GEM_PROPERTIES + + Sub-Keywords ($) per Main-Keyword: + - GEM_PROPERTIES + + - CALCULATE_BOUNDARY_NODES + - DISABLE_GEMS + - FLAG_COUPLING_HYDROLOGY + - FLAG_DISABLE_GEM + - FLAG_POROSITY_CHANGE + - GEM_CALCULATE_BOUNDARY_NODES + - GEM_INIT_FILE + - GEM_THREADS + - ITERATIVE_SCHEME + - KINETIC_GEM + - MAX_FAILED_NODES + - MAX_POROSITY + - MIN_POROSITY + - MY_SMART_GEMS + - PRESSURE_GEM + - TEMPERATURE_GEM + - TRANSPORT_B + + Standard block: + None + + Keyword documentation: + https://ogs5-keywords.netlify.com/ogs/wiki/public/doc-auto/by_ext/gem + + Reading routines: + https://github.com/ufz/ogs5/blob/master/FEM/rf_REACT_GEM.cpp#L2644 + + See Also + -------- + add_block + """ + + MKEYS = ["GEM_PROPERTIES"] + # sorted + SKEYS = [ + [ + "GEM_INIT_FILE", + "GEM_THREADS", + "TRANSPORT_B", + "FLAG_POROSITY_CHANGE", + "MIN_POROSITY", + "MAX_POROSITY", + "FLAG_COUPLING_HYDROLOGY", + "ITERATIVE_SCHEME", + "CALCULATE_BOUNDARY_NODES", + "TEMPERATURE_GEM", + "PRESSURE_GEM", + "MAX_FAILED_NODES", + "MY_SMART_GEMS", + "FLAG_DISABLE_GEM", + "KINETIC_GEM", + "DISABLE_GEMS", # really? + "GEM_CALCULATE_BOUNDARY_NODES", # really? + "GEM_SMART", # really? + "FLAG_NODE_ELEMENT", # really? + "FLAG_CALCULATE_BOUNDARY_NODE", # really? + ] + ] + + STD = {} + + def __init__(self, **OGS_Config): + super(GEM, self).__init__(**OGS_Config) + self.file_ext = ".gem" + + +class GEMinit(object): + """ + Class for GEMS3K input file (lst file) that contains the names of + + * the GEMS data file (dch file), + * the GEMS numerical settings (ipm file) + * the example setup (dbr file) + + used to initialize the GEMS3K kernel. + + Parameters + ---------- + lst_name: :class:`str` or :class:`None`, optional + name of the lst file + dch: :any:`LineFile` or :class:`None` + the GEMS data file + ipm: :any:`LineFile` or :class:`None` + the GEMS data file + dbr: :any:`LineFile` or :class:`None` + the GEMS data file + task_root : str, optional + Path to the destiny model folder. + Default: cwd+"ogs5model" + task_id : str, optional + Name for the ogs task. + Default: "model" + + Notes + ----- + http://gems.web.psi.ch/GEMS3/index.html + + http://gems.web.psi.ch/GEMS3K/ + + http://gems.web.psi.ch/GEMS3K/doc/html/gems3k-iofiles.html + """ + + def __init__( + self, + lst_name="model-dat.lst", + dch=None, + ipm=None, + dbr=None, + task_root=None, + task_id="model", + ): + if task_root is None: + task_root = os.path.join(CWD, "ogs5model") + self._task_root = task_root + self.task_id = task_id + self.lst_name = lst_name + # add files + if dch is not None: + self.dch = dch + else: + self.dch = LineFile( + name=self.task_id + "-dch", + file_ext=".dat", + task_root=self.task_root, + ) + if ipm is not None: + self.ipm = ipm + else: + self.ipm = LineFile( + name=self.task_id + "-ipm", + file_ext=".dat", + task_root=self.task_root, + ) + if dbr is not None: + self.dbr = dbr + else: + self.dbr = LineFile( + name=self.task_id + "-dbr", + file_ext=".dat", + task_root=self.task_root, + ) + + def get_file_type(self): + """Get the OGS file class name""" + return "lst" + + @property + def files(self): + """ + List of the included files: dch, ipm, dbr. + """ + out_list = [] + if self.dch is not None: + out_list.append(self.dch) + if self.ipm is not None: + out_list.append(self.ipm) + if self.dbr is not None: + out_list.append(self.dbr) + return out_list + + @property + def name(self): + """ + The name of the lst file. + """ + return os.path.splitext(self.lst_name)[0] + + @property + def file_ext(self): + """ + The extension of the lst file. + """ + return os.path.splitext(self.lst_name)[1] + + @property + def file_names(self): + """ + The names of the included files. + """ + out_list = [] + for file in self.files: + out_list.append(file.name + file.file_ext) + return out_list + + def __bool__(self): + return not self.is_empty + + def __nonzero__(self): + return self.__bool__() + + @property + def is_empty(self): + """state if the file is empty""" + # check if the files are empty + if self.check(False): + return not any(self.files) + # if check is not passed, handle it as empty file + return True + + @property + def task_root(self): + """ + Get and set the task_root path of the ogs model. + """ + return self._task_root + + @task_root.setter + def task_root(self, value): + self._task_root = value + self.dch.task_root = value + self.ipm.task_root = value + self.dbr.task_root = value + + def reset(self): + """ + Delete every content. + """ + self.dch = LineFile( + name=self.task_id + "-dch", + file_ext=".dat", + task_root=self.task_root, + ) + self.ipm = LineFile( + name=self.task_id + "-ipm", + file_ext=".dat", + task_root=self.task_root, + ) + self.dbr = LineFile( + name=self.task_id + "-dbr", + file_ext=".dat", + task_root=self.task_root, + ) + + def check(self, verbose=True): + """ + Check if the GEM external file is valid. + + Parameters + ---------- + verbose : bool, optional + Print information for the executed checks. Default: True + + Returns + ------- + result : bool + Validity. + """ + # no checks are performed + out = True + for file in self.files: + out &= file.check(verbose) + return out + + def save(self, path): + """ + Save the actual GEM external file in the given path. + lst file containing: dch, ipm, dbr + + Parameters + ---------- + path : str + path to where to file should be saved + """ + for file in self.files: + file.write_file() + with open(path, "w") as fout: + fout.write(str(self)) + + def read_file(self, path, encoding=None, verbose=False): + """ + Read a given GEM external input lst-file. + + Parameters + ---------- + path : str + path to the file + + Notes + ----- + This also reads the given files in the lst-file. (dch, ipm, dbr) + """ + # in python3 open was replaced with io.open + # so we can use encoding key word in python2 + from io import open + + root = os.path.dirname(path) + + self.reset() + try: + with open(path, "r", encoding=encoding) as fin: + for line in fin: + if line.strip().startswith("-t"): + file_names = [] + # get rid of leading "-t" + for file_name in line.split()[1:]: + # get rid of " and ' around strings + file_names.append(file_name.strip('"').strip("'")) + break + except IOError: + if verbose: + print( + "ogs5py " + + self.get_file_type() + + ": could not read lst-file: " + + path + ) + else: + # hard coded order of files + self.dch.name = os.path.splitext(file_names[0])[0] + self.dch.file_ext = os.path.splitext(file_names[0])[1] + self.dch.read_file( + path=os.path.join(root, file_names[0]), + encoding=encoding, + verbose=verbose, + ) + self.ipm.name = os.path.splitext(file_names[1])[0] + self.ipm.file_ext = os.path.splitext(file_names[1])[1] + self.ipm.read_file( + path=os.path.join(root, file_names[1]), + encoding=encoding, + verbose=verbose, + ) + self.dbr.name = os.path.splitext(file_names[2])[0] + self.dbr.file_ext = os.path.splitext(file_names[2])[1] + self.dbr.read_file( + path=os.path.join(root, file_names[2]), + encoding=encoding, + verbose=verbose, + ) + + def write_file(self): + """ + Write the actual OGS input file to the given folder. + Its path is given by "task_root+task_id+file_ext". + """ + # create the file path + if not os.path.exists(self.task_root): + os.makedirs(self.task_root) + f_path = os.path.join(self.task_root, self.lst_name) + # save the data + if not self.is_empty: + self.save(f_path) + + def __repr__(self): + out_str = "-t" + for file_name in self.file_names: + out_str += ' "' + file_name + '"' + return out_str + + def __str__(self): + return self.__repr__() diff --git a/ogs5py/fileclasses/gli/core.py b/ogs5py/fileclasses/gli/core.py index 337d382..7786779 100644 --- a/ogs5py/fileclasses/gli/core.py +++ b/ogs5py/fileclasses/gli/core.py @@ -962,7 +962,7 @@ class GLIext(File): data : :any:`numpy.ndarray`, optional Data for the external geometry definition. Default: :class:`None` - file_name : str, optional + name : str, optional File name for the RFR file. If :class:`None`, the task_id is used. Default: :class:`None` file_ext : :class:`str`, optional @@ -980,7 +980,7 @@ def __init__( self, typ="TIN", data=None, - file_name=None, + name=None, file_ext=None, task_root=None, task_id="model", @@ -990,9 +990,7 @@ def __init__( if typ not in ["TIN", "POINT_VECTOR"]: raise ValueError("typ needs to be either 'TIN' or 'POINT_VECTOR'") self.typ = typ - if file_name is None: - file_name = task_id - self.file_name = file_name + self.name = name if file_ext is None: if typ == "TIN": file_ext = ".tin" @@ -1014,11 +1012,6 @@ def is_empty(self): """state if the OGS file is empty""" return self.data.shape[0] == 0 - @property - def file_path(self): - """:class:`str`: save path of the file""" - return os.path.join(self.task_root, self.file_name + self.file_ext) - def check(self, verbose=True): """ Check if the external geometry definition is valid in the sence, diff --git a/ogs5py/fileclasses/ic/core.py b/ogs5py/fileclasses/ic/core.py index 33927ea..7f586f6 100644 --- a/ogs5py/fileclasses/ic/core.py +++ b/ogs5py/fileclasses/ic/core.py @@ -94,7 +94,7 @@ class RFR(File): First four lines of the RFR file. If :class:`None`, a standard header is written. Default: :class:`None` - file_name : str, optional + name : str, optional File name for the RFR file. If :class:`None`, the task_id is used. Default: :class:`None` file_ext : :class:`str`, optional @@ -112,13 +112,14 @@ def __init__( self, data=None, line1_4=None, - file_name=None, + name=None, file_ext=".rfr", task_root=None, task_id="model", ): super(RFR, self).__init__(task_root, task_id, file_ext) + self.name = name if line1_4 is None: line1_4 = [ "#0#0#0#1#100000#0" @@ -128,11 +129,6 @@ def __init__( "HEAD, m", ] self.line1_4 = line1_4 - - if file_name is None: - file_name = task_id - self.file_name = file_name - if data: self.data = np.array(data) else: @@ -143,11 +139,6 @@ def is_empty(self): """state if the OGS file is empty""" return bool(self.data.shape) and self.data.shape[0] > 0 - @property - def file_path(self): - """:class:`str`: save path of the file""" - return os.path.join(self.task_root, self.file_name + self.file_ext) - def check(self, verbose=True): """ Check if the external geometry definition is valid in the sence, diff --git a/ogs5py/fileclasses/mpd/core.py b/ogs5py/fileclasses/mpd/core.py index 124afa8..5c04251 100644 --- a/ogs5py/fileclasses/mpd/core.py +++ b/ogs5py/fileclasses/mpd/core.py @@ -12,7 +12,7 @@ class MPD(BlockFile): Parameters ---------- - file_name : str, optional + name : str, optional File name for the MPD file. If :class:`None`, the task_id is used. Default: :class:`None` file_ext : :class:`str`, optional @@ -59,11 +59,9 @@ class MPD(BlockFile): STD = {} - def __init__(self, file_name=None, file_ext=".mpd", **OGS_Config): + def __init__(self, name=None, file_ext=".mpd", **OGS_Config): super(MPD, self).__init__(**OGS_Config) - if file_name is None: - file_name = self.task_id - self.file_name = file_name + self.name = name self.file_ext = file_ext # no top comment allowed in the MPD file @@ -75,8 +73,3 @@ def top_com(self): @top_com.setter def top_com(self, val): pass - - @property - def file_path(self): - """:class:`str`: save path of the file""" - return os.path.join(self.task_root, self.file_name + self.file_ext) diff --git a/ogs5py/fileclasses/pqc/core.py b/ogs5py/fileclasses/pqc/core.py index cd94fce..293136c 100644 --- a/ogs5py/fileclasses/pqc/core.py +++ b/ogs5py/fileclasses/pqc/core.py @@ -1,80 +1,72 @@ -# -*- coding: utf-8 -*- -""" -Class for the ogs PHREEQC interface file. -""" - -from __future__ import absolute_import, division, print_function -from ogs5py.fileclasses.base import LineFile - - -class PQC(LineFile): - """ - Class for the ogs PHREEQC interface file. - - Parameters - ---------- - task_root : str, optional - Path to the destiny model folder. - Default: cwd+"ogs5model" - task_id : str, optional - Name for the ogs task. - Default: "model" - - Notes - ----- - This is just handled as a line-wise file. You can access the data by line - with: - - PQC.lines - - Keyword documentation: - https://ogs5-keywords.netlify.com/ogs/wiki/public/doc-auto/by_ext/pqc - - Reading routines: - https://github.com/ufz/ogs5/blob/master/FEM/rf_react.cpp#L2136 - """ - - def __init__(self, **OGS_Config): - super(PQC, self).__init__(**OGS_Config) - self.file_ext = ".pqc" - - @property - def file_name(self): - return self.task_id - - @file_name.setter - def file_name(self, value): - self.task_id = value - - -class PQCdat(LineFile): - """ - Class for the ogs PHREEQC dat file. - - Parameters - ---------- - task_root : str, optional - Path to the destiny model folder. - Default: cwd+"ogs5model" - task_id : str, optional - Name for the ogs task. - Default: "model" - - Notes - ----- - This is just handled as a line-wise file. You can access the data by line - with: - - PQCdat.lines - - Keyword documentation: - https://ogs5-keywords.netlify.com/ogs/wiki/public/doc-auto/by_ext/pqc - - Reading routines: - https://github.com/ufz/ogs5/blob/master/FEM/rf_react.cpp#L2136 - """ - - def __init__(self, **OGS_Config): - super(PQCdat, self).__init__(**OGS_Config) - self.file_name = "phreeqc" - self.file_ext = ".dat" +# -*- coding: utf-8 -*- +""" +Class for the ogs PHREEQC interface file. +""" + +from __future__ import absolute_import, division, print_function +from ogs5py.fileclasses.base import LineFile + + +class PQC(LineFile): + """ + Class for the ogs PHREEQC interface file. + + Parameters + ---------- + task_root : str, optional + Path to the destiny model folder. + Default: cwd+"ogs5model" + task_id : str, optional + Name for the ogs task. + Default: "model" + + Notes + ----- + This is just handled as a line-wise file. You can access the data by line + with: + + PQC.lines + + Keyword documentation: + https://ogs5-keywords.netlify.com/ogs/wiki/public/doc-auto/by_ext/pqc + + Reading routines: + https://github.com/ufz/ogs5/blob/master/FEM/rf_react.cpp#L2136 + """ + + def __init__(self, **OGS_Config): + super(PQC, self).__init__(**OGS_Config) + self.file_ext = ".pqc" + + +class PQCdat(LineFile): + """ + Class for the ogs PHREEQC dat file. + + Parameters + ---------- + task_root : str, optional + Path to the destiny model folder. + Default: cwd+"ogs5model" + task_id : str, optional + Name for the ogs task. + Default: "model" + + Notes + ----- + This is just handled as a line-wise file. You can access the data by line + with: + + PQCdat.lines + + Keyword documentation: + https://ogs5-keywords.netlify.com/ogs/wiki/public/doc-auto/by_ext/pqc + + Reading routines: + https://github.com/ufz/ogs5/blob/master/FEM/rf_react.cpp#L2136 + """ + + def __init__(self, **OGS_Config): + super(PQCdat, self).__init__(**OGS_Config) + self.name = "phreeqc" + self.file_ext = ".dat" diff --git a/ogs5py/ogs.py b/ogs5py/ogs.py index 31025f5..4c4646d 100644 --- a/ogs5py/ogs.py +++ b/ogs5py/ogs.py @@ -251,10 +251,9 @@ def task_id(self): @task_id.setter def task_id(self, value): + # workaround for asc for i in range(len(self.asc)): - self.asc[i].file_name = ( - value + self.asc[i].file_name[len(self._task_id) :] - ) + self.asc[i].name = value + self.asc[i].name[len(self._task_id) :] self._task_id = value for ext in OGS_EXT: getattr(self, ext[1:]).task_id = value @@ -675,11 +674,11 @@ def load_model( # POINT_VECTOR definition of a POLYLINE ext_name = ply["POINT_VECTOR"] if ext_name is not None: - raw_file_name = os.path.basename(ext_name) - f_name, f_ext = os.path.splitext(raw_file_name) + raw_name = os.path.basename(ext_name) + f_name, f_ext = os.path.splitext(raw_name) ext_file = GLIext( typ="POINT_VECTOR", - file_name=f_name, + name=f_name, file_ext=f_ext, task_root=self.task_root, ) @@ -690,11 +689,11 @@ def load_model( # Triangulation definition of a SURFACE ext_name = srf["TIN"] if ext_name is not None: - raw_file_name = os.path.basename(ext_name) - f_name, f_ext = os.path.splitext(raw_file_name) + raw_name = os.path.basename(ext_name) + f_name, f_ext = os.path.splitext(raw_name) ext_file = GLIext( typ="TIN", - file_name=f_name, + name=f_name, file_ext=f_ext, task_root=self.task_root, ) @@ -711,10 +710,10 @@ def load_model( "PERMEABILITY_DISTRIBUTION" ) ext_name = self.mmp.cont[i][index][0][0] - raw_file_name = os.path.basename(ext_name) - f_name, f_ext = os.path.splitext(raw_file_name) + raw_name = os.path.basename(ext_name) + f_name, f_ext = os.path.splitext(raw_name) ext_file = MPD( - file_name=f_name, + name=f_name, file_ext=f_ext, task_root=self.task_root, ) @@ -727,10 +726,10 @@ def load_model( "POROSITY_DISTRIBUTION" ) ext_name = self.mmp.cont[i][index][0][0] - raw_file_name = os.path.basename(ext_name) - f_name, f_ext = os.path.splitext(raw_file_name) + raw_name = os.path.basename(ext_name) + f_name, f_ext = os.path.splitext(raw_name) ext_file = MPD( - file_name=f_name, + name=f_name, file_ext=f_ext, task_root=self.task_root, ) @@ -742,10 +741,10 @@ def load_model( index = self.mmp.subkw[i].index("GEOMETRY_AREA") if self.mmp.cont[i][index][0][0] == "FILE": ext_name = self.mmp.cont[i][index][0][1] - raw_file_name = os.path.basename(ext_name) - f_name, f_ext = os.path.splitext(raw_file_name) + raw_name = os.path.basename(ext_name) + f_name, f_ext = os.path.splitext(raw_name) ext_file = MPD( - file_name=f_name, + name=f_name, file_ext=f_ext, task_root=self.task_root, ) @@ -774,10 +773,10 @@ def load_model( if self.ic.cont[i][index][0][0] != "RESTART": continue ext_name = self.ic.cont[i][index][0][1] - raw_file_name = os.path.basename(ext_name) - f_name, f_ext = os.path.splitext(raw_file_name) + raw_name = os.path.basename(ext_name) + f_name, f_ext = os.path.splitext(raw_name) ext_file = RFR( - file_name=f_name, + name=f_name, file_ext=f_ext, task_root=self.task_root, ) @@ -795,10 +794,10 @@ def load_model( # load ASC files files = glob.glob(os.path.join(task_root, task_id + "*.asc")) for fil in files: - raw_file_name = os.path.basename(fil) - f_name, f_ext = os.path.splitext(raw_file_name) + raw_name = os.path.basename(fil) + f_name, f_ext = os.path.splitext(raw_name) ext_file = ASC( - file_name=self.task_id + f_name[len(task_id) :], + name=self.task_id + f_name[len(task_id) :], task_root=self.task_root, ) path = os.path.join(task_root, fil) diff --git a/ogs5py/tools/script.py b/ogs5py/tools/script.py index e4bb841..6ce155c 100644 --- a/ogs5py/tools/script.py +++ b/ogs5py/tools/script.py @@ -180,14 +180,14 @@ def add_list_file(list_file, script, base, cls_name, ogs_cls_name="model"): add = "add_asc" list_file.write_file() - file_name = list_file.file_name + name = list_file.name file_ext = list_file.file_ext - name = file_name + file_ext + file_name = name + file_ext print(cls_name + " = " + base + "(", file=script) - print(tab(1) + "file_name=" + formater(file_name) + ",", file=script) + print(tab(1) + "name=" + formater(name) + ",", file=script) print(tab(1) + "file_ext=" + formater(file_ext) + ",", file=script) print(")", file=script) - print(cls_name + ".read_file(" + formater(name) + ")", file=script) + print(cls_name + ".read_file(" + formater(file_name) + ")", file=script) print(ogs_cls_name + "." + add + "(" + cls_name + ")", file=script)