Skip to content

TxtinoutReader

TxtinoutReader

__init__(path: str) -> None

Initialize a TxtinoutReader instance for working with SWAT model data.

Parameters: path (str, os.PathLike): The path to the SWAT model folder.

TypeError: If the provided path is not a string or a Path object, or if the folder does not exist, or if there is more than one .exe file in the folder, or if no .exe file is found.

Attributes: root_folder (Path): The path to the root folder of the SWAT model. swat_exe_path (Path): The path to the main SWAT executable file.

copy_and_run(dir: str, overwrite: bool = False, params: Dict[str, Tuple[str, List[Tuple[Union[None, str, re.Pattern], str, int]]]] = {}, show_output: bool = True) -> str

Copy the SWAT model files to a specified directory, modify input parameters, and run the simulation.

Parameters: dir (str): The target directory where the SWAT model files will be copied. overwrite (bool, optional): If True, overwrite the content of 'dir'; if False, create a new folder inside 'dir' (default is False). params (Dict[str, Tuple[str, List[Tuple[Union[None, str, re.Pattern], str, int]]]], optional): A dictionary containing modifications to input files. Format: {filename: (id_col, [(id, col, value)])}. Format: {filename: (id_col, [(id, col, value)])}. show_output (bool, optional): If True, print the simulation output; if False, suppress output (default is True).

Returns: str: The path to the directory where the SWAT simulation was executed.

copy_and_run_star(args: Tuple[str, bool, Dict[str, Tuple[str, List[Tuple[Union[None, str, re.Pattern], str, int]]]], bool]) -> str

Copy the SWAT model files to a specified directory, modify input parameters, and run the simulation using arguments provided as a tuple.

args (Tuple[Dict[str, Tuple[str, List[Tuple[Union[None, str, re.Pattern], str, int]]]]], bool]): A tuple containing simulation parameters. The first element is a dictionary with input parameter modifications, the second element is a boolean to show output.

Returns: str: The path to the directory where the SWAT simulation was executed.

copy_swat(dir: str = None, overwrite: bool = False) -> str

Copy the SWAT model files to a specified directory.

If 'overwrite' is True, the content of the 'dir' folder will be deleted, and the 'txtinout' folder will be copied there. If 'overwrite' is False, the 'txtinout' folder will be copied to a new folder inside 'dir'.

Parameters: dir (str, optional): The target directory where the SWAT model files will be copied. If None, a temporary folder will be created (default is None). overwrite (bool, optional): If True, overwrite the content of 'dir'; if False, create a new folder inside dir(default is False).

Returns: str: The path to the directory where the SWAT model files were copied.

disable_csv_print() -> None

Disable CSV print in the 'print.prt' file.

Returns: None

enable_csv_print() -> None

Enable CSV print in the 'print.prt' file.

Returns: None

enable_object_in_print_prt(obj: str, daily: bool, monthly: bool, yearly: bool, avann: bool) -> None

Enable or update an object in the 'print.prt' file. If obj is not a default identifier, it will be added at the end of the file.

Parameters: obj (str): The object name or identifier. daily (bool): Flag for daily print frequency. monthly (bool): Flag for monthly print frequency. yearly (bool): Flag for yearly print frequency. avann (bool): Flag for average annual print frequency.

Returns: None

register_file(filename: str, has_units: bool = False, index: Optional[str] = None, usecols: Optional[List[str]] = None, filter_by: Dict[str, List[str]] = {}) -> FileReader

Register a file to work with in the SWAT model.

Parameters: filename (str): The name of the file to register. has_units (bool): Indicates if the file has units information (default is False). index (str, optional): The name of the index column (default is None). usecols (List[str], optional): A list of column names to read (default is None). filter_by (Dict[str, List[str]], optional): A dictionary of column names and values (list of str) to filter by (default is an empty dictionary).

Returns: FileReader: A FileReader instance for the registered file.

run_parallel_swat(params: List[Dict[str, Tuple[str, List[Tuple[Union[None, str, re.Pattern], str, int]]]]], n_workers: int = 1, dir: str = None, parallelization: str = 'threads') -> List[str]

Run SWAT simulations in parallel with modified input parameters.

params (Dict[str, Tuple[str, List[Tuple[Union[None, str, re.Pattern], str, int]]]], optional): A dictionary containing modifications to input files. Format: {filename: (id_col, [(id, col, value)])}. n_workers (int, optional): The number of parallel workers to use (default is 1). dir (str, optional): The target directory where the SWAT model files will be copied (default is None). parallelization (str, optional): The parallelization method to use ('threads' or 'processes') (default is 'threads').

Returns: List[str]: A list of paths to the directories where the SWAT simulations were executed.

run_swat(params: Dict[str, Tuple[str, List[Tuple[Union[None, str, re.Pattern], str, int]]]] = {}, show_output: bool = True) -> str

Run the SWAT simulation with modified input parameters.

params (Dict[str, Tuple[str, List[Tuple[Union[None, str, re.Pattern], str, int]]]], optional): A dictionary containing modifications to input files. Format: {filename: (id_col, [(id, col, value)])}. 'id' can be None to apply the value to all rows or a regex pattern to match multiple IDs. show_output (bool, optional): If True, print the simulation output; if False, suppress output (default is True).

Returns: str: The path to the directory where the SWAT simulation was executed.

run_swat_star(args: Tuple[Dict[str, Tuple[str, List[Tuple[Union[None, str, re.Pattern], str, int]]]], bool]) -> str

Run the SWAT simulation with modified input parameters using arguments provided as a tuple.

args (Tuple[Dict[str, Tuple[str, List[Tuple[Union[None, str, re.Pattern], str, int]]]]], bool]): A tuple containing simulation parameters. The first element is a dictionary with input parameter modifications, the second element is a boolean to show output.

Returns: str: The path to the directory where the SWAT simulation was executed.

set_beginning_and_end_year(beginning: int, end: int) -> None

Modify the beginning and end year in the 'time.sim' file.

Parameters: beginning (int): The new beginning year. end (int): The new end year.

Returns: None

set_warmup(warmup: int) -> None

Modify the warmup period in the 'time.sim' file.

Parameters: warmup (int): The new warmup period value.

Returns: None