Source code for ogs5py.fileclasses.pct.core

# -*- coding: utf-8 -*-
"""Class for the ogs PARTICLE DEFINITION file for RANDOM_WALK."""
import numpy as np

from ogs5py.fileclasses.base import File

[docs]class PCT(File): """ Class for the ogs Particle file, if the PCS TYPE is RANDOM_WALK. Parameters ---------- data : np.array or None particle data. Default: None s_flag : int, optional 1 for same pseudo-random series, 0 for different pseudo-random series. Default: 1 task_root : str, optional Path to the destiny model folder. Default: cwd+"ogs5model" task_id : str, optional Name for the ogs task. Default: "model" """ def __init__(self, data=None, s_flag=1, task_root=None, task_id="model"): super().__init__(task_root, task_id) self.s_flag = s_flag self.file_ext = ".pct" if data: = np.array(data) else: = np.zeros((0, 10)) @property def is_empty(self): """State if the OGS file is empty.""" # check if the data is empty if self.check(False): return not[0] >= 1 # if check is not passed, handle it as empty file return True
[docs] def check(self, verbose=True): """ Check if the external geometry definition is valid. In the sence, that the contained data is consistent. Parameters ---------- verbose : bool, optional Print information for the executed checks. Default: True Returns ------- result : bool Validity of the given gli. """ if != 2: if verbose: print("PCT: Data shape incorect. Need 2 dimensions.") return False elif[1] != 10: if verbose: print("PCT: Data shape incorect. Need 10 columns.") return False return True
[docs] def reset(self): """Delete every content.""" = np.zeros((0, 10))
[docs] def save(self, path): """ Save the actual PCT external file in the given path. Parameters ---------- path : str path to where to file should be saved """ if not self.is_empty: with open(path, "w") as fout: print(str(self.s_flag), file=fout) print(str([0]), file=fout) np.savetxt(fout,
[docs] def read_file(self, path, **kwargs): """ Write the actual OGS input file to the given folder. Its path is given by "task_root+task_id+file_ext". """ with open(path, "r") as fin: self.s_flag = int(fin.readline().split(";")[0].split()[0]) # use numpy to read the data = np.loadtxt(path, skiprows=2)
def __repr__(self): """Representation.""" out = str(self.s_flag) + "\n" out += str([0]) + "\n" out += str( return out