Skip to content
Snippets Groups Projects
Commit 601d36e5 authored by abaucher's avatar abaucher
Browse files

Added comments

parent a573fccd
No related branches found
No related tags found
No related merge requests found
......@@ -5,13 +5,13 @@ import numpy as np
def plot_system(s, v_names=None, rescale=False, com=True, filter_no=None, scales=None, colors=None, title='', linestyle='-', outside_legend_number=2, legend=True):
assert 'time' in dir(s), "Aucune simulation n'a été lancée pour le système !"
if not v_names:
v_names = s.get_vars()
v_names = s.get_all_variable_names()
if isinstance(v_names, str):
v_names = [v_names]
if filter_no:
v_names = [n for n in v_names if n not in filter_no]
for name in v_names:
v = s.get_var(name)
v = getattr(s, name)
try:
v[0]
except:
......
......@@ -24,7 +24,7 @@ class System:
"""
def __init__(self):
"""Initialise a System with nodes and equations dictionnaries"""
"""Initialise an empty System with nodes and equations dictionnaries"""
self.nodes = {
'cst': set(),
'var': set(),
......@@ -106,15 +106,58 @@ class System:
return self.nodes[node_type]
def get_vars(self):
def get_all_variable_names(self):
"""
Returns
-------
list(str):
List of name of all variables
"""
return self.nodes['var']
def get_var(self, name):
"""
Parameters
----------
name: str
Name of variable.
Returns
-------
np.array(float):
Array of values of the variable for the last run
"""
assert name in self.nodes['var'], f"{name} is not a variable"
return getattr(self, name)
def get_time(self):
"""
Returns
-------
np.array(float):
Array of system time.
"""
return self.time
def get_tabhl_args(self, name):
"""
Get indications about a tabhl function.
Parameters
----------
name: str
Name of the variable using a tabhl function.
Returns
-------
np.array, np.array, str, str, str:
x, f(x), x label, y label, title
"""
aa = list(self.eqs['update'][name]['args']['var'])
argname = aa[0][0].split('.')[0]
assert 'tabhl_' + name in dir(self), 'Error, no such tabhl function'
......@@ -652,7 +695,17 @@ class System:
return s
def get_out_nodes(self, node, with_definitions=False):
"""Returns the list of the nodes using the node to be compted"""
"""Returns the list of the nodes using the node to be computed.
Parameters
----------
node: str
Name of the node
with_definitions: bool
If yes, returns a dictionnary with each node definition.
"""
out_nodes = [b for (a, b) in self.get_influence_graph().out_edges(node)]
if with_definitions:
return {a: self.get_comment(a) for a in out_nodes}
......@@ -660,7 +713,17 @@ class System:
return out_nodes
def get_in_nodes(self, node, with_definitions=False):
"""Returns the list of the nodes that this node needs to be compted"""
"""Returns the list of the nodes that this node needs to be computed.
Parameters
----------
node: str
Name of the node
with_definitions: bool
If yes, returns a dictionnary with each node definition.
"""
in_nodes = [a for (a, b) in self.get_influence_graph().in_edges(node)]
if with_definitions:
return {a: self.get_comment(a) for a in in_nodes}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment