iode.Database.__setitem__
Note
Below, Database represents either:
Comments
Equations
Identities
Lists
Scalars
Tables
Variables
- Database.__setitem__()
Update/add a (subset of) IODE object(s) referenced by key from/to the current database.
The key can represent a single object name (e.g. “ACAF”) or a list of object names (“ACAF;ACAG;AOUC”) or a pattern (e.g. “A*”) or a list of sub-patterns (e.g. “A*;*_”).
If the key represents a list of object names or of sub-patterns, each name or sub-pattern is separated by a separator character which is either a whitespace ` , or a comma `,, or a semi-colon ;, or a tabulation t, or a newline n.
A (sub-)`pattern` is a list of characters representing a group of object names. It includes some special characters which have a special meaning:
* : any character sequence, even empty
? : any character (one and only one)
@ : any alphanumerical char [A-Za-z0-9]
& : any non alphanumerical char
| : any alphanumeric character or none at the beginning and end of a string
! : any non-alphanumeric character or none at the beginning and end of a string
`` : escape the next character
Note that the key can contain references to IODE lists which are prefixed with the symbol $.
- Parameters:
- key: str or list(str)
(the list of) name(s) of the IODE object(s) to update/add. The list of objects to update/add can be specified by a pattern or by a list of sub-patterns (e.g. “A*;*_”).
- value:
(new) value(s) of the IODE object(s).
Examples
>>> from iode import SAMPLE_DATA_DIR
Comments
>>> from iode import comments >>> comments.load(f"{SAMPLE_DATA_DIR}/fun.cmt") >>> # a) add one comment >>> comments["BDY"] = "Difference net incomes (YN - YK)" >>> comments["BDY"] 'Difference net incomes (YN - YK)'
>>> # b) update one comment >>> comments["ACAF"] 'Ondernemingen: ontvangen kapitaaloverdrachten.' >>> comments["ACAF"] = "New Value" >>> comments["ACAF"] 'New Value'
>>> # c) working on a subset >>> # 1) get subset >>> comments_subset = comments["A*"] >>> comments_subset.names ['ACAF', 'ACAG', 'AOUC', 'AQC'] >>> # 2) add a comment to the subset >>> comments_subset["A0"] = "New Comment" >>> comments_subset["A0"] 'New Comment' >>> # --> new comment also appears in the global workspace >>> "A0" in comments True >>> comments["A0"] 'New Comment' >>> # 3) update a comment in the subset >>> comments_subset["A0"] = "Updated Comment" >>> comments_subset["A0"] 'Updated Comment' >>> # --> comment is also updated in the global workspace >>> comments["A0"] 'Updated Comment'
Equations
>>> from iode import equations, EqMethod >>> equations.load(f"{SAMPLE_DATA_DIR}/fun.eqs") >>> # a) add one equation >>> equations["BDY"] = "BDY := YN - YK" >>> equations["BDY"] Equation(endogenous = 'BDY', lec = 'BDY := YN - YK', method = 'LSQ', from_period = '1960Y1', to_period = '2015Y1')
>>> # b) update one equation >>> equations["ACAF"] Equation(endogenous = 'ACAF', lec = '(ACAF/VAF[-1]) :=acaf1+acaf2*GOSF[-1]+\nacaf4*(TIME=1995)', method = 'LSQ', from_period = '1980Y1', to_period = '1996Y1', block = 'ACAF', tests = {corr = 1, dw = 2.32935, fstat = 32.2732, loglik = 83.8075, meany = 0.00818467, r2 = 0.821761, r2adj = 0.796299, ssres = 5.19945e-05, stderr = 0.00192715, stderrp = 23.5458, stdev = 0.0042699}, date = '12-06-1998') >>> # update only the LEC >>> equations["ACAF"] = "(ACAF/VAF[-1]) := acaf1 + acaf2 * GOSF[-1] + acaf4 * (TIME=1995)" >>> equations["ACAF"] Equation(endogenous = 'ACAF', lec = '(ACAF/VAF[-1]) := acaf1 + acaf2 * GOSF[-1] + acaf4 * (TIME=1995)', method = 'LSQ', from_period = '1980Y1', to_period = '1996Y1', block = 'ACAF', tests = {corr = 1, dw = 2.32935, fstat = 32.2732, loglik = 83.8075, meany = 0.00818467, r2 = 0.821761, r2adj = 0.796299, ssres = 5.19945e-05, stderr = 0.00192715, stderrp = 23.5458, stdev = 0.0042699}, date = '12-06-1998') >>> # upate block and sample of a block of equations to estimation (dictionary) >>> estim_sample = "2000Y1:2010Y1" >>> block = "ACAF; ACAG; AOUC" >>> for eq_name in block.split(';'): ... equations[eq_name] = {"sample": estim_sample, "block": block} >>> (equations["ACAF"].sample, equations["ACAG"].sample, equations["AOUC"].sample) ('2000Y1:2010Y1', '2000Y1:2010Y1', '2000Y1:2010Y1') >>> (equations["ACAF"].block, equations["ACAG"].block, equations["AOUC"].block) ('ACAF; ACAG; AOUC', 'ACAF; ACAG; AOUC', 'ACAF; ACAG; AOUC') >>> # upate sample and block (Equation objects) >>> eq_ACAF = equations["ACAF"] >>> eq_ACAF.lec = "(ACAF/VAF[-1]) := acaf2 * GOSF[-1] + acaf4 * (TIME=1995)" >>> eq_ACAF.method = EqMethod.MAX_LIKELIHOOD >>> # new equation sample is from 1990Y1 to the last year of Variables >>> eq_ACAF.sample = "1990Y1:" >>> eq_ACAF.block = "ACAF" >>> equations["ACAF"] = eq_ACAF >>> equations["ACAF"] Equation(endogenous = 'ACAF', lec = '(ACAF/VAF[-1]) := acaf2 * GOSF[-1] + acaf4 * (TIME=1995)', method = 'MAX_LIKELIHOOD', from_period = '1990Y1', to_period = '2015Y1', block = 'ACAF', tests = {corr = 1, dw = 2.32935, fstat = 32.2732, loglik = 83.8075, meany = 0.00818467, r2 = 0.821761, r2adj = 0.796299, ssres = 5.19945e-05, stderr = 0.00192715, stderrp = 23.5458, stdev = 0.0042699}, date = '12-06-1998')
>>> # c) working on a subset >>> # 1) get subset >>> equations_subset = equations["A*"] >>> equations_subset.names ['ACAF', 'ACAG', 'AOUC'] >>> # 2) add a equation to the subset >>> equations_subset["AOUC_"] = "AOUC_ := ((WCRH/QL)/(WCRH/QL)[1990Y1]) * (VAFF/(VM+VAFF))[-1] + PM * (VM/(VAFF+VM))[-1]" >>> equations_subset["AOUC_"] Equation(endogenous = 'AOUC_', lec = 'AOUC_ := ((WCRH/QL)/(WCRH/QL)[1990Y1]) * (VAFF/(VM+VAFF))[-1] + PM * (VM/(VAFF+VM))[-1]', method = 'LSQ', from_period = '1960Y1', to_period = '2015Y1') >>> # --> new equation also appears in the global workspace >>> "AOUC_" in equations True >>> equations["AOUC_"] Equation(endogenous = 'AOUC_', lec = 'AOUC_ := ((WCRH/QL)/(WCRH/QL)[1990Y1]) * (VAFF/(VM+VAFF))[-1] + PM * (VM/(VAFF+VM))[-1]', method = 'LSQ', from_period = '1960Y1', to_period = '2015Y1') >>> # 3) update a equation in the subset >>> equations_subset["AOUC_"] = "AOUC_ := ((WCRH/QL)/(WCRH/QL)[1990Y1]) * (VAFF/(VM+VAFF))[-1]" >>> equations_subset["AOUC_"] Equation(endogenous = 'AOUC_', lec = 'AOUC_ := ((WCRH/QL)/(WCRH/QL)[1990Y1]) * (VAFF/(VM+VAFF))[-1]', method = 'LSQ', from_period = '1960Y1', to_period = '2015Y1') >>> # --> equation is also updated in the global workspace >>> equations["AOUC_"] Equation(endogenous = 'AOUC_', lec = 'AOUC_ := ((WCRH/QL)/(WCRH/QL)[1990Y1]) * (VAFF/(VM+VAFF))[-1]', method = 'LSQ', from_period = '1960Y1', to_period = '2015Y1')
Identities
>>> from iode import identities >>> identities.load(f"{SAMPLE_DATA_DIR}/fun.idt") >>> # a) add one identity >>> identities["BDY"] = "YN - YK" >>> identities["BDY"] 'YN - YK'
>>> # b) update one identity >>> identities["AOUC"] '((WCRH/QL)/(WCRH/QL)[1990Y1])*(VAFF/(VM+VAFF))[-1]+PM*(VM/(VM+VAFF))[-1]' >>> identities["AOUC"] = '(WCRH / WCRH[1990Y1]) * (VAFF / (VM+VAFF))[-1] + PM * (VM / (VM+VAFF))[-1]' >>> identities["AOUC"] '(WCRH / WCRH[1990Y1]) * (VAFF / (VM+VAFF))[-1] + PM * (VM / (VM+VAFF))[-1]'
>>> # c) working on a subset >>> # 1) get subset >>> identities_subset = identities["X*"] >>> identities_subset.names ['XEX', 'XNATY', 'XPOIL', 'XPWMAB', 'XPWMS', 'XPWXAB', 'XPWXS', 'XQWXAB', 'XQWXS', 'XQWXSS', 'XRLBER', 'XTFP', 'XW'] >>> # 2) add an identity to the subset >>> identities_subset["XDPU"] = "grt DPU" >>> identities_subset["XDPU"] 'grt DPU' >>> # --> new identity also appears in the global workspace >>> "XDPU" in identities True >>> identities["XDPU"] 'grt DPU' >>> # 3) update an identity in the subset >>> identities_subset["XDPU"] = "0" >>> identities_subset["XDPU"] '0' >>> # --> identity is also updated in the global workspace >>> identities["XDPU"] '0'
Lists
>>> from iode import lists, variables >>> lists.load(f"{SAMPLE_DATA_DIR}/fun.lst") >>> variables.load(f"{SAMPLE_DATA_DIR}/fun.var") >>> # a) add one list >>> # --- by passing a string >>> lists["A_VAR"] = "ACAF;ACAG;AOUC;AOUC_;AQC" >>> lists["A_VAR"] ['ACAF', 'ACAG', 'AOUC', 'AOUC_', 'AQC'] >>> # --- by passing a Python list >>> b_vars = variables.get_names("B*") >>> b_vars ['BENEF', 'BQY', 'BRUGP', 'BVY'] >>> lists["B_VAR"] = b_vars >>> lists["B_VAR"] ['BENEF', 'BQY', 'BRUGP', 'BVY']
>>> # b) update one list >>> # --- by passing a string >>> lists["A_VAR"] = "ACAF;ACAG;AOUC;AQC" >>> lists["A_VAR"] ['ACAF', 'ACAG', 'AOUC', 'AQC'] >>> # --- by passing a Python list >>> b_y_vars = variables.get_names("B*Y") >>> b_y_vars ['BQY', 'BVY'] >>> lists["B_VAR"] = b_y_vars >>> lists["B_VAR"] ['BQY', 'BVY']
>>> # c) working on a subset >>> # 1) get subset >>> lists_subset = lists["E*"] >>> lists_subset.names ['ENDO', 'ENDO0', 'ENDO1', 'ENVI'] >>> # 2) add a list to the subset >>> lists_subset["E_VAR"] = variables.get_names("E*") >>> lists_subset["E_VAR"] ['EFMY', 'EFXY', 'EX', 'EXC', 'EXCC', 'EXCCR'] >>> # --> new list also appears in the global workspace >>> "E_VAR" in lists True >>> lists["E_VAR"] ['EFMY', 'EFXY', 'EX', 'EXC', 'EXCC', 'EXCCR'] >>> # 3) update a list in the subset >>> lists_subset["E_VAR"] = "EX;EXC;EXCC;EXCCR" >>> lists_subset["E_VAR"] ['EX', 'EXC', 'EXCC', 'EXCCR'] >>> # --> list is also updated in the global workspace >>> lists["E_VAR"] ['EX', 'EXC', 'EXCC', 'EXCCR']
Scalars
>>> from iode import scalars >>> scalars.load(f"{SAMPLE_DATA_DIR}/fun.scl") >>> # a) -------- add one scalar -------- >>> # 1. default relax to 1.0 >>> scalars["a0"] = 0.1 >>> scalars["a0"] Scalar(0.1, 1, na) >>> # 2. value + relax >>> scalars["a1"] = 0.1, 0.9 >>> scalars["a1"] Scalar(0.1, 0.9, na)
>>> # b) -------- update one scalar -------- >>> scalars["acaf1"] Scalar(0.0157684, 1, 0.00136871) >>> # only update the value >>> scalars["acaf1"] = 0.8 >>> scalars["acaf1"] Scalar(0.8, 1, 0.00136871) >>> # upate value and relax (tuple) >>> scalars["acaf2"] = 0.8, 0.9 >>> scalars["acaf2"] Scalar(0.8, 0.9, na) >>> # update value and relax (list) >>> scalars["acaf2"] = (0.7, 0.8) >>> scalars["acaf2"] Scalar(0.7, 0.8, na) >>> # upate value and relax (dictionary) >>> scalars["acaf3"] = {"relax": 0.9, "value": 0.8} >>> scalars["acaf3"] Scalar(0.8, 0.9, 0.87301) >>> # upate value and/or relax (Scalar object) >>> acaf4 = scalars["acaf4"] >>> acaf4 Scalar(-0.00850518, 1, 0.0020833) >>> acaf4.value = 0.8 >>> acaf4.relax = 0.9 >>> # WARNING: the standard deviation (std) cannot be changed manually >>> scalars["acaf4"] = acaf4 >>> scalars["acaf4"] Scalar(0.8, 0.9, 0.0020833)
>>> # c) working on a subset >>> # 1) get subset >>> scalars_subset = scalars["a*"] >>> scalars_subset.names ['a0', 'a1', 'acaf1', 'acaf2', 'acaf3', 'acaf4'] >>> # 2) add a scalar to the subset >>> scalars_subset["acaf0"] = 1.0, 1.0 >>> scalars_subset["acaf0"] Scalar(1, 1, na) >>> # --> new scalar also appears in the global workspace >>> "acaf0" in scalars True >>> scalars["acaf0"] Scalar(1, 1, na) >>> # 3) update a scalar in the subset >>> scalars_subset["acaf0"] = 0.1 >>> scalars_subset["acaf0"] Scalar(0.1, 1, na) >>> # --> scalar is also updated in the global workspace >>> scalars["acaf0"] Scalar(0.1, 1, na)
Tables
>>> from iode import tables, Table, TableGraphAxis >>> tables.load(f"{SAMPLE_DATA_DIR}/fun.tbl") >>> # a) -------- new table -------- >>> # 1. specify list of line titles and list of LEC expressions >>> lines_titles = ["GOSG:", "YDTG:", "DTH:", "DTF:", "IT:", "YSSG+COTRES:", "RIDG:", "OCUG:"] >>> lines_lecs = ["GOSG", "YDTG", "DTH", "DTF", "IT", "YSSG+COTRES", "RIDG", "OCUG"] >>> tables["TABLE_CELL_LECS"] = {"nb_columns": 2, "table_title": "New Table", "lecs_or_vars": lines_lecs, ... "lines_titles": lines_titles, "mode": True, "files": True, "date": True} >>> tables["TABLE_CELL_LECS"] DIVIS | 1 | TITLE | "New Table" ----- | ---------------------------- CELL | "" | "#S" ----- | ---------------------------- CELL | "GOSG:" | GOSG CELL | "YDTG:" | YDTG CELL | "DTH:" | DTH CELL | "DTF:" | DTF CELL | "IT:" | IT CELL | "YSSG+COTRES:" | YSSG+COTRES CELL | "RIDG:" | RIDG CELL | "OCUG:" | OCUG ----- | ---------------------------- MODE | FILES | DATE | nb lines: 16 nb columns: 2 language: 'ENGLISH' gridx: 'MAJOR' gridy: 'MAJOR' graph_axis: 'VALUES' graph_alignment: 'LEFT'
>>> # 2. specify list of variables >>> vars_list = ["GOSG", "YDTG", "DTH", "DTF", "IT", "YSSG", "COTRES", "RIDG", "OCUG", "$ENVI"] >>> tables["TABLE_VARS"] = {"nb_columns": 2, "table_title": "New Table", "lecs_or_vars": vars_list, ... "mode": True, "files": True, "date": True} >>> tables["TABLE_VARS"] DIVIS | 1 | TITLE | "New Table" ----- | ------------------------------------------------------------------------------ CELL | "" | "#S" ----- | ------------------------------------------------------------------------------ CELL | "Bruto exploitatie-overschot: overheid (= afschrijvingen)." | GOSG CELL | "Overheid: geïnde indirecte belastingen." | YDTG CELL | "Totale overheid: directe belasting van de gezinnen." | DTH CELL | "Totale overheid: directe vennootschapsbelasting." | DTF CELL | "Totale indirecte belastingen." | IT CELL | "Globale overheid: ontvangen sociale zekerheidsbijdragen." | YSSG CELL | "Cotisation de responsabilisation." | COTRES CELL | "Overheid: inkomen uit vermogen." | RIDG CELL | "Globale overheid: saldo van de ontvangen lopendeoverdrachten." | OCUG CELL | "Wisselkoers van de USD t.o.v. de BEF (jaargemiddelde)." | EX CELL | "Index wereldprijs - invoer van niet-energieprodukten, inUSD." | PWMAB CELL | "Index wereldprijs - invoer van diensten, in USD." | PWMS CELL | "Index wereldprijs - uitvoer van niet-energieprodukten, inUSD." | PWXAB CELL | "Index wereldprijs - uitvoer van diensten, in USD." | PWXS CELL | "Indicator van het volume van de wereldvraag naar goederen,1985=1." | QWXAB CELL | "Indicator van het volume van de wereldvraag naar diensten,1985=1." | QWXS CELL | "Brent olieprijs (USD per barrel)." | POIL CELL | "Totale beroepsbevolking (jaargemiddelde)." | NATY CELL | "TFPFHP_" | TFPFHP_ ----- | ------------------------------------------------------------------------------ MODE | FILES | DATE | nb lines: 27 nb columns: 2 language: 'ENGLISH' gridx: 'MAJOR' gridy: 'MAJOR' graph_axis: 'VALUES' graph_alignment: 'LEFT'
>>> # b) -------- update table -------- >>> table = tables["TABLE_CELL_LECS"] >>> table DIVIS | 1 | TITLE | "New Table" ----- | ---------------------------- CELL | "" | "#S" ----- | ---------------------------- CELL | "GOSG:" | GOSG CELL | "YDTG:" | YDTG CELL | "DTH:" | DTH CELL | "DTF:" | DTF CELL | "IT:" | IT CELL | "YSSG+COTRES:" | YSSG+COTRES CELL | "RIDG:" | RIDG CELL | "OCUG:" | OCUG ----- | ---------------------------- MODE | FILES | DATE | nb lines: 16 nb columns: 2 language: 'ENGLISH' gridx: 'MAJOR' gridy: 'MAJOR' graph_axis: 'VALUES' graph_alignment: 'LEFT'
>>> # set graph axis type >>> table.graph_axis = TableGraphAxis.SEMILOG >>> # print last line >>> table[-1] <DATE> >>> # delete last line >>> del table[-1] >>> # get index of line containing YSSG+COTRES >>> index = table.index("YSSG+COTRES") >>> table[index] ('"YSSG+COTRES:"', 'YSSG+COTRES') >>> # get line type >>> table[index].line_type 'CELL' >>> # get line graph type >>> table[index].graph_type 'LINE' >>> # know if axis is left >>> table[index].axis_left True >>> # update cells >>> # double quotes " -> STRING cell >>> # no double quotes " -> LEC cell >>> table[index] = ('"YSSG:"', 'YSSG') >>> table[index] ('"YSSG:"', 'YSSG') >>> # insert a new title line surrounded by two separator lines >>> table.insert(index + 1, '-') >>> table.insert(index + 2, "New Title") >>> table.insert(index + 3, '-') >>> # append a new sepatator line >>> table += '-'
>>> # warning: do not forget to actually update the IODE Table database >>> tables["TABLE_CELL_LECS"] = table >>> tables["TABLE_CELL_LECS"] DIVIS | 1 | TITLE | "New Table" ----- | -------------- CELL | "" | "#S" ----- | -------------- CELL | "GOSG:" | GOSG CELL | "YDTG:" | YDTG CELL | "DTH:" | DTH CELL | "DTF:" | DTF CELL | "IT:" | IT CELL | "YSSG:" | YSSG ----- | -------------- TITLE | "New Title" ----- | -------------- CELL | "RIDG:" | RIDG CELL | "OCUG:" | OCUG ----- | -------------- MODE | FILES | ----- | -------------- nb lines: 19 nb columns: 2 language: 'ENGLISH' gridx: 'MAJOR' gridy: 'MAJOR' graph_axis: 'SEMILOG' graph_alignment: 'LEFT'
>>> # c) working on a subset >>> # 1) get subset >>> tables_subset = tables["C8_*"] >>> tables_subset.names ['C8_1', 'C8_10', 'C8_11', 'C8_13', 'C8_14', 'C8_2', 'C8_3', 'C8_4', 'C8_5', 'C8_6', 'C8_7', 'C8_8', 'C8_9'] >>> # 2) add a table to the subset >>> vars_list = ["XNATY", "XPOIL", "XPWMAB", "XPWXAB"] >>> tables_subset["X_GRT"] = {"nb_columns": 2, "table_title": "Croissance", "lecs_or_vars": vars_list, ... "mode": True, "files": True, "date": True} >>> tables_subset["X_GRT"] DIVIS | 1 | TITLE | "Croissance" ----- | ---------------------------------------------------------------- CELL | "" | "#S" ----- | ---------------------------------------------------------------- CELL | "Croissance de la population active" | XNATY CELL | "Croissance du prix du pétrole" | XPOIL CELL | "Croissance des prix des biens importés" | XPWMAB CELL | "Croissance des prix des marchés pertinents à l'export" | XPWXAB ----- | ---------------------------------------------------------------- MODE | FILES | DATE | nb lines: 12 nb columns: 2 language: 'ENGLISH' gridx: 'MAJOR' gridy: 'MAJOR' graph_axis: 'VALUES' graph_alignment: 'LEFT' >>> # --> new table also appears in the global workspace >>> "X_GRT" in tables True >>> tables["X_GRT"] DIVIS | 1 | TITLE | "Croissance" ----- | ---------------------------------------------------------------- CELL | "" | "#S" ----- | ---------------------------------------------------------------- CELL | "Croissance de la population active" | XNATY CELL | "Croissance du prix du pétrole" | XPOIL CELL | "Croissance des prix des biens importés" | XPWMAB CELL | "Croissance des prix des marchés pertinents à l'export" | XPWXAB ----- | ---------------------------------------------------------------- MODE | FILES | DATE | nb lines: 12 nb columns: 2 language: 'ENGLISH' gridx: 'MAJOR' gridy: 'MAJOR' graph_axis: 'VALUES' graph_alignment: 'LEFT' >>> # 3) update a table in the subset >>> table_x_grt = tables_subset["X_GRT"] >>> index = table_x_grt.index("XPWXAB") >>> table_x_grt.insert(index + 1, (f'"{comments["XQWXSS"]}"', "XQWXSS")) >>> # warning: do not forget to actually update the IODE Table subset >>> tables_subset["X_GRT"] = table_x_grt >>> tables_subset["X_GRT"] DIVIS | 1 | TITLE | "Croissance" ----- | ---------------------------------------------------------------- CELL | "" | "#S" ----- | ---------------------------------------------------------------- CELL | "Croissance de la population active" | XNATY CELL | "Croissance du prix du pétrole" | XPOIL CELL | "Croissance des prix des biens importés" | XPWMAB CELL | "Croissance des prix des marchés pertinents à l'export" | XPWXAB CELL | "Croissance des marchés pertinents" | XQWXSS ----- | ---------------------------------------------------------------- MODE | FILES | DATE | nb lines: 13 nb columns: 2 language: 'ENGLISH' gridx: 'MAJOR' gridy: 'MAJOR' graph_axis: 'VALUES' graph_alignment: 'LEFT' >>> # --> table is also updated in the global workspace >>> tables["X_GRT"] DIVIS | 1 | TITLE | "Croissance" ----- | ---------------------------------------------------------------- CELL | "" | "#S" ----- | ---------------------------------------------------------------- CELL | "Croissance de la population active" | XNATY CELL | "Croissance du prix du pétrole" | XPOIL CELL | "Croissance des prix des biens importés" | XPWMAB CELL | "Croissance des prix des marchés pertinents à l'export" | XPWXAB CELL | "Croissance des marchés pertinents" | XQWXSS ----- | ---------------------------------------------------------------- MODE | FILES | DATE | nb lines: 13 nb columns: 2 language: 'ENGLISH' gridx: 'MAJOR' gridy: 'MAJOR' graph_axis: 'VALUES' graph_alignment: 'LEFT'
Variables
>>> from iode import variables, NA >>> variables.load(f"{SAMPLE_DATA_DIR}/fun.var") >>> # a) -------- add one variable -------- >>> # 1) same value for all periods >>> variables["A0"] = NA >>> variables["A0"] [-2e+37, -2e+37, ..., -2e+37, -2e+37] >>> # 2) vector (list) containing a specific value for each period >>> variables["A1"] = list(range(variables.nb_periods)) >>> variables["A1"] [0.0, 1.0, 2.0, ..., 53.0, 54.0, 55.0] >>> # 3) LEC expression >>> variables["A2"] = "t + 10" >>> variables["A2"] [10.0, 11.0, 12.0, ..., 63.0, 64.0, 65.0]
>>> # b) -------- update one variable -------- >>> # 1) update all values of a Variable >>> variables["ACAF"] [-2e+37, -2e+37, ..., -83.34062511080091, -96.41041982848331] >>> # 1.I) same value for all periods >>> variables["ACAF"] = NA >>> variables["ACAF"] [-2e+37, -2e+37, ..., -2e+37, -2e+37] >>> # 1.II) vector (list) containing a specific value for each period >>> variables["ACAF"] = list(range(variables.nb_periods)) >>> variables["ACAF"] [0.0, 1.0, 2.0, ..., 53.0, 54.0, 55.0] >>> # 1.III) LEC expression >>> variables["ACAF"] = "t + 10" >>> variables["ACAF"] [10.0, 11.0, 12.0, ..., 63.0, 64.0, 65.0]
>>> # 2) set one value of a Variable for a specific period >>> variables["ACAG", "1990Y1"] -28.1721855713507 >>> variables["ACAG", "1990Y1"] = -28.2 >>> variables["ACAG", "1990Y1"] -28.2
>>> # 3) set the variable values for range of periods >>> # 3.I) using a Python slice >>> # 3.I.a) variable(periods) = same value for all periods >>> variables["ACAF", "1991Y1":"1995Y1"] = 0.0 >>> variables["ACAF", "1991Y1":"1995Y1"] [0.0, 0.0, 0.0, 0.0, 0.0] >>> # 3.I.b) variable(periods) = vector (list) containing a specific value for each period >>> variables["ACAF", "1991Y1":"1995Y1"] = [0., 1., 2., 3., 4.] >>> variables["ACAF", "1991Y1":"1995Y1"] [0.0, 1.0, 2.0, 3.0, 4.0] >>> # 3.I.c) variable(periods) = LEC expression >>> variables["ACAF", "1991Y1":"1995Y1"] = "t + 10" >>> variables["ACAF", "1991Y1":"1995Y1"] [41.0, 42.0, 43.0, 44.0, 45.0]
>>> # 3.II) same as above but with the colon ':' inside the periods range string >>> # 3.II.a) variable(periods) = same value for all periods >>> variables["ACAF", "1991Y1:1995Y1"] = 0.0 >>> variables["ACAF", "1991Y1:1995Y1"] [0.0, 0.0, 0.0, 0.0, 0.0] >>> # 3.II.b) variable(periods) = vector (list) containing a specific value for each period >>> variables["ACAF", "1991Y1:1995Y1"] = [0., -1., -2., -3., -4.] >>> variables["ACAF", "1991Y1":"1995Y1"] [0.0, -1.0, -2.0, -3.0, -4.0] >>> # 3.II.c) variable(periods) = LEC expression >>> variables["ACAF", "1991Y1:1995Y1"] = "t - 10" >>> variables["ACAF", "1991Y1:1995Y1"] [21.0, 22.0, 23.0, 24.0, 25.0]
>>> # c) -------- working on a subset -------- >>> # 1) get subset >>> variables_subset = variables["A*"] >>> variables_subset.names ['A0', 'A1', 'A2', 'ACAF', 'ACAG', 'AOUC', 'AOUC_', 'AQC'] >>> # 2) add a variable to the subset >>> from iode import NA >>> variables_subset["A3"] = NA >>> variables_subset["A3"] [-2e+37, -2e+37, ..., -2e+37, -2e+37] >>> # --> new variable also appears in the global workspace >>> "A3" in variables True >>> variables["A3"] [-2e+37, -2e+37, ..., -2e+37, -2e+37] >>> # 3) update a variable in the subset >>> variables_subset["A3"] = 0.0 >>> variables_subset["A3"] [0.0, 0.0, ..., 0.0, 0.0] >>> # --> variable is also updated in the global workspace >>> variables["A3"] [0.0, 0.0, ..., 0.0, 0.0]