"""Get information needed to call the special function in the `node`, and also change the `node` to include appropriate parameter names.
Parameters
----------
node : ast.Module
Function call to handle.
node_name : str
Name of the node (variable or constant) which uses this function to be upated. This name is useful to determine the new name of the function (es: `tabhl_io` for the funciton `tabhl` and the updated variable `io`.
Returns
-------
dict
All useful information to generate the special function. Depends on the type of the function.
"""
name=node.func.id
name=node.func.id
# For every type of special function, different treatments apply.
"""Get information needed to execute the equation `node`, and also change `node` with appropriate parameters.
Parameters
----------
node : ast.Module
Equation.
node_name : str
Name of the node (variable or constant) which uses this function to be upated. This name is useful to determine the new name of the function (es: `tabhl_io` for the funciton `tabhl` and the updated variable `io`.
Returns
-------
(ast.Module, dict)
The modified node and all useful information to generate the equation.
"""
root=root.body[0].value
root=root.body[0].value
# The node is walked through to detect and change a special function call
# Only one special DYNAMO function is allowed in an equation ...
"""Check if every line in the file can be parsed by the ast module. If not, raise an error.
Parameters
----------
filename : str
Files in which every pydynamo equations are written.
"""
withopen(filename,'r')asf:
withopen(filename,'r')asf:
fori,linenumerate(f.readlines()):
fori,linenumerate(f.readlines()):
try:
try:
...
@@ -105,43 +191,125 @@ def check_file(filename):
...
@@ -105,43 +191,125 @@ def check_file(filename):
e.lineno=i+1
e.lineno=i+1
raise
raise
defnew_cst_politic(s,cst,year,val2):
defnew_system(raw,s=None):
"""Add new equations for cst, which becomes a variable changing from initval to endval during time interval from year"""
"""Create a new system from either a file, a list, or a function, including pydynamo equations.
Parameters
----------
raw : str, iterable(str) or function
If str, open the file named `raw` and read pydynamo equations inside (see parse_system.system_from_file`). If iterable(str), each element is a pydynamo equations (see `parse_system.system_from_lines`). If function, read pydynamo equations written inside (see `parse_system.system_from_fun`).
Returns
-------
System
System object.
"""
ifcallable(raw):
returnsystem_from_fun(raw,s=s)
elifisinstance(raw,list):
returnsystem_from_lines(raw,s=s)
elifisinstance(raw,str):
returnsystem_from_file(raw,s=s)
defnew_cst_politic(s,cst,date,new_value):
"""Add a new equations to `s` for the constant `cst`, which becomes a variable changing from its former value to `new_value` after the `date`.
Parameters
----------
s : System
The system to implement the new politic.
cst : str
Constant name.
date : float
Date of politic application.
new_value : float
The new value that `cst` will take after the date `date`.
"""
assertcstins.eqs['cst'],f"{cst} is not a constant"
assertcstins.eqs['cst'],f"{cst} is not a constant"