iode.Identities.execute
- Identities.execute(identities: str | List[str] = None, from_period: str | Period = None, to_period: str | Period = None, var_files: str | List[str] = None, scalar_files: str | List[str] = None, trace: bool = False) bool[source]
Execute the specified identity(ies).
- Parameters:
- identitiesstr or List[str], optional
The identities to execute. If not provided, all identities are executed.
- from_periodstr or Period, optional
The starting period of the execution range. Defaults to the starting period of the current Variables sample.
- to_periodstr or Period, optional
The ending period of the execution range. Defaults to the ending period of the current Variables sample.
- var_filesstr or List[str], optional
The variable files from which the required Variables are temporarily loaded. The Variables database is left unchanged after the execution of the identity(ies). Defaults to None (current content of the Variables database is used).
- scalar_filesstr or List[str], optional
The scalar files from which the required Scalars are temporarily loaded. The Variables database is left unchanged after the execution of the identity(ies). Defaults to None (current content of the Scalars database is used).
- tracebool, optional
If True, prints the source of the variables and scalars.
- Returns:
- bool
Examples
>>> from iode import identities, variables, SAMPLE_DATA_DIR >>> identities.load(f"{SAMPLE_DATA_DIR}/fun.idt") Loading .../fun.idt 48 objects loaded >>> variables.load(f"{SAMPLE_DATA_DIR}/fun.var") Loading .../fun.var 394 objects loaded >>> sample = variables.sample >>> sample Sample("1960Y1:2015Y1") >>> identities["GAP_"] Identity('100*((QAF_/Q_F)-1)') >>> identities["GAP2"] Identity('100*(QAFF_/(Q_F+Q_I))') >>> # reset variables GAP_ and GAP2 >>> variables["GAP_"] = 0. >>> variables["GAP_"] Workspace: Variables nb variables: 1 filename: ...fun.var description: Modèle fun - Simulation 1 sample: 1960Y1:2015Y1 mode: LEVEL name 1960Y1 1961Y1 1962Y1 ... 2013Y1 2014Y1 2015Y1 GAP_ 0.00 0.00 0.00 ... 0.00 0.00 0.00 >>> variables["GAP2"] = 0. >>> variables["GAP2"] Workspace: Variables nb variables: 1 filename: ...fun.var description: Modèle fun - Simulation 1 sample: 1960Y1:2015Y1 mode: LEVEL name 1960Y1 1961Y1 1962Y1 ... 2013Y1 2014Y1 2015Y1 GAP2 0.00 0.00 0.00 ... 0.00 0.00 0.00
>>> # compute GAP_ and GAP2 (assuming Scalars and Variables are already loaded) >>> identities.execute("GAP_;GAP2") True >>> variables["GAP_"] Workspace: Variables nb variables: 1 filename: ...fun.var description: Modèle fun - Simulation 1 sample: 1960Y1:2015Y1 mode: LEVEL name 1960Y1 1961Y1 1962Y1 ... 2013Y1 2014Y1 2015Y1 GAP_ -3.20 -3.98 -2.12 ... 4.06 3.78 3.24 >>> variables["GAP2"] Workspace: Variables nb variables: 1 filename: ...fun.var description: Modèle fun - Simulation 1 sample: 1960Y1:2015Y1 mode: LEVEL name 1960Y1 1961Y1 1962Y1 ... 2013Y1 2014Y1 2015Y1 GAP2 96.93 97.40 98.37 ... 102.50 102.15 101.59
>>> # compute GAP_ and GAP2 over a subset of the sample >>> variables["GAP_"] = 0. >>> variables["GAP2"] = 0. >>> identities.execute("GAP_;GAP2", "2000Y1", "2005Y1") True >>> variables["GAP_", "2000Y1:2005Y1"] Workspace: Variables nb variables: 1 filename: ...fun.var description: Modèle fun - Simulation 1 sample: 2000Y1:2005Y1 mode: LEVEL name 2000Y1 2001Y1 2002Y1 2003Y1 2004Y1 2005Y1 GAP_ 4.51 3.31 2.62 3.46 5.48 5.58 >>> variables["GAP2", "2000Y1:2005Y1"] Workspace: Variables nb variables: 1 filename: ...fun.var description: Modèle fun - Simulation 1 sample: 2000Y1:2005Y1 mode: LEVEL name 2000Y1 2001Y1 2002Y1 2003Y1 2004Y1 2005Y1 GAP2 104.61 103.06 102.17 102.82 104.47 104.36
>>> # compute GAP_ and GAP2 assuming Variables are not already loaded >>> variables.clear() >>> variables.sample = "1960Y1:2015Y1" >>> variables.names [] >>> # setting the var_files argument will fetch the required values of >>> # 'QAF_', 'QAFF_', 'Q_F' and 'Q_I' from the passed Variables file >>> success = identities.execute("GAP_;GAP2", var_files=f"{SAMPLE_DATA_DIR}/fun.var") Loading ...fun.var 394 objects loaded >>> success True >>> variables["GAP_"] Workspace: Variables nb variables: 1 filename: ws sample: 1960Y1:2015Y1 mode: LEVEL name 1960Y1 1961Y1 1962Y1 1963Y1 ... 2012Y1 2013Y1 2014Y1 2015Y1 GAP_ -3.20 -3.98 -2.12 -2.65 ... 3.61 4.06 3.78 3.24 >>> variables["GAP2"] Workspace: Variables nb variables: 1 filename: ws sample: 1960Y1:2015Y1 mode: LEVEL name 1960Y1 1961Y1 1962Y1 1963Y1 ... 2012Y1 2013Y1 2014Y1 2015Y1 GAP2 96.93 97.40 98.37 97.71 ... 102.19 102.50 102.15 101.59 >>> # note that the variables 'QAF_', 'QAFF_', 'Q_F' and 'Q_I' are not >>> # present in the Variables database after running identities.execute >>> variables.names ['GAP2', 'GAP_']