ogs5py.fileclasses.mpd

Class for the ogs MEDIUM_PROPERTIES_DISTRIBUTED file.

File Class

MPD([name, file_ext]) Class for the ogs MEDIUM_PROPERTIES_DISTRIBUTED file.

class MPD(name=None, file_ext='.mpd', **OGS_Config)[source]

Bases: ogs5py.fileclasses.base.BlockFile

Class for the ogs MEDIUM_PROPERTIES_DISTRIBUTED file.

Parameters:
  • name (str, optional) – File name for the MPD file. If None, the task_id is used. Default: None
  • file_ext (str, optional) – extension of the file (with leading dot “.mpd”) Default: “.mpd”
  • 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 (#):
  • MEDIUM_PROPERTIES_DISTRIBUTED
Sub-Keywords ($) per Main-Keyword:
  • MEDIUM_PROPERTIES_DISTRIBUTED

    • MSH_TYPE
    • MMP_TYPE
    • DIS_TYPE
    • CONVERSION_FACTOR
    • DATA
Standard block:
None
Keyword documentation:
https://ogs5-keywords.netlify.com/ogs/wiki/public/doc-auto/by_ext/mmp
Reading routines:
https://github.com/ufz/ogs5/blob/master/FEM/rf_mmp_new.cpp#L5706

See also

add_block

Attributes:
block_no

Number of blocks in the file.

file_name

str: base name of the file with extension.

file_path

str: save path of the file.

force_writing

bool: state if the file is written even if empty.

is_empty

State if the OGS file is empty.

name

str: name of the file without extension.

top_com

Top comment is ‘None’ for the MPD file.

Methods

add_block(self[, index, main_key]) Add a new Block to the actual file.
add_content(self, content[, main_index, …]) Add single-line content to the actual file.
add_copy_link(self, path[, symlink]) Add a link to copy a file instead of writing.
add_main_keyword(self, key[, main_index]) Add a new main keyword (#key) to the actual file.
add_multi_content(self, content[, …]) Add multiple content to the actual file.
add_sub_keyword(self, key[, main_index, …]) Add a new sub keyword ($key) to the actual file.
append_to_block(self[, index]) Append data to an existing Block in the actual file.
check(self[, verbose]) Check if the given file is valid.
del_block(self[, index, del_all]) Delete a block by its index.
del_content(self[, main_index, sub_index, …]) Delete content by its position.
del_copy_link(self) Remove a former given link to an external file.
del_main_keyword(self[, main_index, del_all]) Delete a main keyword (#key) by its position.
del_sub_keyword(self[, main_index, …]) Delete a sub keyword ($key) by its position.
get_block(self[, index, as_dict]) Get a Block from the actual file.
get_block_no(self) Get the number of blocks in the file.
get_file_type(self) Get the OGS file class name.
get_multi_keys(self[, index]) State if a block has a unique set of sub keywords.
is_block_unique(self[, index]) State if a block has a unique set of sub keywords.
read_file(self, path[, encoding, verbose]) Read an existing OGS input file.
reset(self) Delete every content.
save(self, path, \*\*kwargs) Save the actual OGS input file in the given path.
update_block(self[, index, main_key]) Update a Block from the actual file.
write_file(self) Write the actual OGS input file to the given folder.
add_block(self, index=None, main_key=None, **block)

Add a new Block to the actual file.

Keywords are the sub keywords of the actual file type:

#MAIN_KEY
$SUBKEY1
content1 …
$SUBKEY2
content2 …

which looks like the following:

FILE.add_block(SUBKEY1=content1, SUBKEY2=content2)

Parameters:
  • index (int or None, optional) – Positional index, where to insert the given Block. As default, it will be added at the end. Default: None.
  • main_key (string, optional) – Main keyword of the block that should be added (see: MKEYS) Default: the first main keyword of the file-type
  • **block (keyword dict) – here the dict-keywords are the ogs-subkeywords and the value is the content that should be added with this ogs-subkeyword If a block should contain content directly connected to a main keyword, use this main keyword as input-keyword and the content as value: SUBKEY=content
add_content(self, content, main_index=None, sub_index=None, line_index=None)

Add single-line content to the actual file.

Parameters:
  • content (list) – list containing one line of content given as a list of single statements
  • main_index (int, optional) – index of the corresponding main keyword where the sub keyword should be added. As default, the last main keyword is taken.
  • sub_index (int, optional) – index of the corresponding sub keyword where the content should be added. As default, the last sub keyword is taken.
  • line_index (int, optional) – position, where the new line of content should be added between the existing ones. As default, it is placed at the end.

Notes

There needs to be at least one main keyword, otherwise the content is not added.

If no sub keyword is present, a blank one (“”) will be added and the content is then directly connected to the actual main keyword.

Add a link to copy a file instead of writing.

Instead of writing a file, you can give a path to an existing file, that will be copied/linked to the target folder.

Parameters:
  • path (str) – path to the existing file that should be copied
  • symlink (bool, optional) – on UNIX systems it is possible to use a symbolic link to save time if the file is big. Default: False
add_main_keyword(self, key, main_index=None)

Add a new main keyword (#key) to the actual file.

Parameters:
  • key (string) – key name
  • main_index (int, optional) – position, where the new main keyword should be added between the existing ones. As default, it is placed at the end.
add_multi_content(self, content, main_index=None, sub_index=None)

Add multiple content to the actual file.

Parameters:
  • content (list) – list containing lines of content, each given as a list of single statements
  • main_index (int, optional) – index of the corresponding main keyword where the sub keyword should be added. As default, the last main keyword is taken.
  • sub_index (int, optional) – index of the corresponding sub keyword where the content should be added. As default, the last sub keyword is taken.

Notes

There needs to be at least one main keyword, otherwise the content is not added.

The content will be added at the end of the actual subkeyword.

If no sub keyword is present, a blank one (“”) will be added and the content is then directly connected to the actual main keyword.

add_sub_keyword(self, key, main_index=None, sub_index=None)

Add a new sub keyword ($key) to the actual file.

Parameters:
  • key (string) – key name
  • main_index (int, optional) – index of the corresponding main keyword where the sub keyword should be added. As default, the last main keyword is taken.
  • sub_index (int, optional) – position, where the new sub keyword should be added between the existing ones. As default, it is placed at the end.

Notes

There needs to be at least one main keyword, otherwise the subkeyword is not added.

append_to_block(self, index=None, **block)

Append data to an existing Block in the actual file.

Keywords are the sub keywords of the actual file type:

#MAIN_KEY
$SUBKEY1
content1 …
$SUBKEY2
content2 …

which looks like the following:

FILE.append_to_block(SUBKEY1=content1, SUBKEY2=content2)

Parameters:
  • index (int or None, optional) – Positional index, where to insert the given Block. As default, it will be added at the end. Default: None.
  • **block (keyword dict) – here the dict-keywords are the ogs-subkeywords and the value is the content that should be added with this ogs-subkeyword If a block should contain content directly connected to a main keyword, use this main keyword as input-keyword and the content as value: SUBKEY=content
check(self, verbose=True)

Check if the given file is valid.

Parameters:verbose (bool, optional) – Print information for the executed checks. Default: True
Returns:result – Validity of the given file.
Return type:bool
del_block(self, index=None, del_all=False)

Delete a block by its index.

Parameters:
  • index (int or None, optional) – Positional index of the block of interest. As default, the last one is returned. Default: None
  • del_all (bool, optional) – State, if all blocks shall be deleted. Default: False
del_content(self, main_index=-1, sub_index=-1, line_index=-1, del_all=False)

Delete content by its position.

Parameters:
  • main_index (int, optional) – index of the corresponding main keyword where the sub keyword should be deleted. As default, the last main keyword is taken.
  • sub_index (int, optional) – index of the corresponding sub keyword where the content should be deleted. As default, the last sub keyword is taken.
  • line_index (int, optional) – position of the content line, that should be deleted. Default: -1
  • del_all (bool, optional) – State, if all content shall be deleted. Default: False

Remove a former given link to an external file.

del_main_keyword(self, main_index=None, del_all=False)

Delete a main keyword (#key) by its position.

Parameters:
  • main_index (int, optional) – position, which main keyword should be deleted. Default: -1
  • del_all (bool, optional) – State, if all main keywords shall be deleted. Default: False
del_sub_keyword(self, main_index=-1, sub_index=-1, del_all=False)

Delete a sub keyword ($key) by its position.

Parameters:
  • main_index (int, optional) – index of the corresponding main keyword where the sub keyword should be deleted. As default, the last main keyword is taken.
  • pos (int, optional) – position, which sub keyword should be deleted. Default: -1
  • del_all (bool, optional) – State, if all sub keywords shall be deleted. Default: False
get_block(self, index=None, as_dict=True)

Get a Block from the actual file.

Parameters:
  • index (int or None, optional) – Positional index of the block of interest. As default, the last one is returned. Default: None
  • as_dict (bool, optional) – Here you can state of you want the output as a dictionary, which can be used as key-word-arguments for add_block. If False, you get the main-key, a list of sub-keys and a list of content. Default: True
get_block_no(self)

Get the number of blocks in the file.

get_file_type(self)

Get the OGS file class name.

get_multi_keys(self, index=None)

State if a block has a unique set of sub keywords.

is_block_unique(self, index=None)

State if a block has a unique set of sub keywords.

read_file(self, path, encoding=None, verbose=False)

Read an existing OGS input file.

Parameters:
  • path (str) – path to the existing file that should be read
  • encoding (str or None, optional) – encoding of the given file. If None is given, the system standard is used. Default: None
  • verbose (bool, optional) – Print information of the reading process. Default: False
reset(self)

Delete every content.

save(self, path, **kwargs)

Save the actual OGS input file in the given path.

Parameters:
  • path (str) – path to where to file should be saved
  • update (bool, optional) – state if the content should be updated before saving. Default: True
update_block(self, index=None, main_key=None, **block)

Update a Block from the actual file.

Parameters:
  • index (int or None, optional) – Positional index of the block of interest. As default, the last one is used. Default: None
  • main_key (string, optional) – Main keyword of the block that should be updated (see: MKEYS) This shouldn’t be done. Default: None
  • **block (keyword dict) – here the dict-keywords are the ogs-subkeywords and the value is the content that should be added with this ogs-subkeyword If a block should contain content directly connected to a main keyword, use this main keyword as input-keyword and the content as value: SUBKEY=content
write_file(self)

Write the actual OGS input file to the given folder.

Its path is given by “task_root+task_id+file_ext”.

MKEYS = ['MEDIUM_PROPERTIES_DISTRIBUTED']
SKEYS = [['MSH_TYPE', 'MMP_TYPE', 'DIS_TYPE', 'CONVERSION_FACTOR', 'DATA']]
STD = {}
block_no

Number of blocks in the file.

file_name

base name of the file with extension.

Type:str
file_path

save path of the file.

Type:str
force_writing

state if the file is written even if empty.

Type:bool
is_empty

State if the OGS file is empty.

name

name of the file without extension.

Type:str
top_com

Top comment is ‘None’ for the MPD file.