iode.Comments.compare
- Comments.compare(filepath: str | Path, only_in_workspace_list_name: str = None, only_in_file_list_name: str = None, equal_objects_list_name: str = None, different_objects_list_name: str = None) Dict[str, List[str]]
The objects of the current database are compared with those stored in the file filepath.
The result of this comparison is composed of 4 lists:
only_in_workspace_list: objects only found in the current database
only_in_file_list: objects only found in the file filepath
equal_objects_list: objects found in both with the same value
different_objects_list: objects found in both but with a different value
The comparison is made according to current database type.
For the IODE Variables, the comparison between two variables is made according to the threshold defined by
iode.Variables.threshold().- Parameters:
- filepath: str or Path
path to the file to be compared with the current database
- only_in_workspace_list_name: str, optional
name of the list of objects only found in the current database. Defaults to “OLD_<IODE_TYPE>”.
- only_in_file_list_name: str, optional
name of the list of objects only found in the file filepath. Defaults to “NEW_<IODE_TYPE>”.
- equal_objects_list_name: str, optional
- name of the list of objects found in both with the same value.
Defaults to “SAME_<IODE_TYPE>”.
- different_objects_list_name: str, optional
name of the list of objects found in both but with a different value. Defaults to “CHANGED_<IODE_TYPE>”.
- Returns:
- dict(str, list(str))
dictionary containing the 4 lists of objects
Examples
>>> import numpy as np >>> from iode import SAMPLE_DATA_DIR >>> from iode import variables >>> output_dir = getfixture('tmp_path')
>>> variables.load(f"{SAMPLE_DATA_DIR}/fun.var") Loading ...fun.var 394 objects loaded >>> variables.threshold 1e-07
>>> # ---- create Variables file to compare with ---- >>> vars_other_filepath = str(output_dir / "fun_other.var") >>> vars_other = variables.copy() >>> # add two variables >>> vars_other["NEW_VAR"] = 0.0 >>> vars_other["NEW_VAR_2"] = 0.0 >>> # delete two variables >>> del vars_other["AOUC"] >>> del vars_other["AQC"] >>> # change the value of two variables (above threshold) >>> vars_other["ACAF"] = "ACAF + 1.e-5" >>> vars_other["ACAG"] = "ACAG + 1.e-5" >>> # change the value of two variables (below threshold) >>> vars_other["BENEF"] = "BENEF + 1.e-8" >>> vars_other["BQY"] = "BQY + 1.e-8" >>> # save the Variables file to compare with >>> vars_other.save(vars_other_filepath) Saving fun_other.var 394 objects saved
>>> # ---- compare the current Variables database ---- >>> # ---- with the content of the saved file ---- >>> lists_compare = variables.compare(vars_other_filepath) Loading ...fun_other.var 394 objects loaded >>> for name, value in lists_compare.items(): ... print(f"{name}: {value}") OLD_VAR: ['AOUC', 'AQC'] NEW_VAR: ['NEW_VAR', 'NEW_VAR_2'] SAME_VAR: ['AOUC_', 'BENEF', 'BQY', 'BRUGP', ..., 'ZKFO', 'ZX', 'ZZF_'] CHANGED_VAR: ['ACAF', 'ACAG']