From d13e4eb4b9965890c655ba88351aefdde777d9d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Fernando=20S=C3=A1nchez?= Date: Mon, 24 Apr 2023 18:06:37 +0200 Subject: [PATCH] Plot env without agent reporters --- soil/analysis.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/soil/analysis.py b/soil/analysis.py index ae259e1..645a7b6 100644 --- a/soil/analysis.py +++ b/soil/analysis.py @@ -1,12 +1,11 @@ import os +import sys import sqlalchemy import pandas as pd from collections import namedtuple def plot(env, agent_df=None, model_df=None, steps=False, ignore=["agent_count", ]): """Plot the model dataframe and agent dataframe together.""" - if agent_df is None: - agent_df = env.agent_df() if model_df is None: model_df = env.model_df() ignore = list(ignore) @@ -16,9 +15,15 @@ def plot(env, agent_df=None, model_df=None, steps=False, ignore=["agent_count", ignore.append("time") ax = model_df.drop(ignore, axis='columns').plot(); - if not agent_df.empty: - agent_df.unstack().apply(lambda x: x.value_counts(), - axis=1).fillna(0).plot(ax=ax, secondary_y=True); + if agent_df is None: + try: + agent_df = env.agent_df() + except UserWarning: + print("No agent dataframe provided and no agent reporters found. Skipping agent plot.", file=sys.stderr) + return + agent_df.unstack().apply(lambda x: x.value_counts(), + axis=1).fillna(0).plot(ax=ax, secondary_y=True); + Results = namedtuple("Results", ["config", "parameters", "env", "agents"]) #TODO implement reading from CSV and SQLITE