From 601d36e52c4ffccfd21b6d00f35f4953f322ee9b Mon Sep 17 00:00:00 2001 From: abaucher <achille.baucher@inria.fr> Date: Mon, 21 Feb 2022 15:14:06 +0100 Subject: [PATCH] Added comments --- pydynamo/core/plot_system.py | 4 +- pydynamo/core/system.py | 71 ++++++++++++++++++++++++++++++++++-- 2 files changed, 69 insertions(+), 6 deletions(-) diff --git a/pydynamo/core/plot_system.py b/pydynamo/core/plot_system.py index e0794653..a98d81ab 100644 --- a/pydynamo/core/plot_system.py +++ b/pydynamo/core/plot_system.py @@ -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: diff --git a/pydynamo/core/system.py b/pydynamo/core/system.py index 7926d8eb..4d56a09e 100644 --- a/pydynamo/core/system.py +++ b/pydynamo/core/system.py @@ -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} -- GitLab