From d0634d9f16088768ade2792de6373fc128a78739 Mon Sep 17 00:00:00 2001 From: charwick <1117120+charwick@users.noreply.github.com> Date: Wed, 27 Jul 2022 23:04:24 -0400 Subject: [PATCH] Require Networkx --- README.md | 4 ++-- helipad/agent.py | 4 ++-- helipad/locales/helipad.pot | 4 ---- helipad/model.py | 7 +++---- helipad/param.py | 4 ++-- sample-models/Helicopter.py | 7 ------- setup.py | 5 +++-- 7 files changed, 12 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index e101470..787aa6b 100644 --- a/README.md +++ b/README.md @@ -34,17 +34,17 @@ Helipad requires Python 3.7 or higher. The following libraries are also required * [Matplotlib](https://matplotlib.org/) for visualization * [Pandas](https://pandas.pydata.org/) for data collection +* [NetworkX](http://networkx.github.io/) for network analysis and spatial visualization The following libraries are optional but recommended: * [Jupyter](https://jupyter.org/), [Ipywidgets](https://pypi.org/project/ipywidgets/), and [ipympl](https://github.com/matplotlib/ipympl) to run Helipad in Jupyter notebooks -* [NetworkX](http://networkx.github.io/) for network analysis and spatial visualization * [Readline](https://pypi.org/project/readline/) and Code for the debug console * [Nest-asyncio](https://pypi.org/project/nest-asyncio/) to run Helipad from Spyder ## Version History -* [1.4](https://helipad.dev/2022/07/helipad-1-4/): More consistent container API, miscellaneous interface improvements +* [1.4](https://helipad.dev/2022/07/helipad-1-4/): More consistent container API, localization, miscellaneous interface improvements * [1.3](https://helipad.dev/2021/06/helipad-1-3/): Allow mixing time series and other plots, display networks on spatial maps, goods API improvements * [1.2](https://helipad.dev/2021/02/helipad-1-2/): Extensible visualization API, events, performance profiling, Jupyterlab support * [1.1](https://helipad.dev/2020/10/helipad-1-1/): Virtual parameters, improved Jupyter flexibility, spatial pre-alpha, misc improvements diff --git a/helipad/agent.py b/helipad/agent.py index e993dc6..60dae42 100644 --- a/helipad/agent.py +++ b/helipad/agent.py @@ -397,8 +397,8 @@ def __getitem__(self, key): if isinstance(key, str): return self.goods[key]['quantity'] elif isinstance(key, tuple): if isinstance(key[1], str): return self.goods[key[0]][key[1]] - elif key[1]==True: return self.goods[key[0]] - elif key[1]==False: return self.goods[key]['quantity'] + elif key[1] is True: return self.goods[key[0]] + elif key[1] is False: return self.goods[key]['quantity'] raise KeyError def __setitem__(self, key, val): diff --git a/helipad/locales/helipad.pot b/helipad/locales/helipad.pot index 890c224..8dc3825 100644 --- a/helipad/locales/helipad.pot +++ b/helipad/locales/helipad.pot @@ -190,10 +190,6 @@ msgstr "" msgid "Network density must take a value between 0 and 1." msgstr "" -#: model.py:428 -msgid "Network export requires Networkx." -msgstr "" - #: model.py:482 msgid "Breed '{0}' is not registered for the '{1}' primitive." msgstr "" diff --git a/helipad/model.py b/helipad/model.py index 2760540..183bfb1 100644 --- a/helipad/model.py +++ b/helipad/model.py @@ -4,8 +4,8 @@ # ========== import os, sys, warnings, asyncio, time -import pandas import gettext +import pandas from random import shuffle, choice from numpy import random @@ -22,7 +22,7 @@ def __init__(self, locale='en'): #Have to do this first so that _() is available early if not hasattr(self, 'breed'): gettext.translation('helipad', localedir=os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))+'/locales', languages=[locale]).install() - + self.data = Data(self) self.params = Params(self) self.shocks = Shocks(self) @@ -428,8 +428,7 @@ def createNetwork(self, density, kind='edge', prim=None): return self.network(kind, prim) def network(self, kind='edge', prim=None, excludePatches=False): - try: import networkx as nx - except: warnings.warn(_('Network export requires Networkx.'), None, 2) + import networkx as nx #Have to use DiGraph in order to draw any arrows G = nx.DiGraph(name=kind) diff --git a/helipad/param.py b/helipad/param.py index 222a428..6e7978f 100644 --- a/helipad/param.py +++ b/helipad/param.py @@ -443,10 +443,10 @@ def clear(self): @property def globals(self): return {k:v for k,v in self.items() if v.per is None} - + @property def perBreed(self): return {k:v for k,v in self.items() if v.per=='breed'} - + @property def perGood(self): return {k:v for k,v in self.items() if v.per=='good'} diff --git a/sample-models/Helicopter.py b/sample-models/Helicopter.py index 02b966b..ce3ab41 100644 --- a/sample-models/Helicopter.py +++ b/sample-models/Helicopter.py @@ -54,13 +54,6 @@ def step(self, stage): #Just have a fixed inventory target, but update if params do self.invTarget = {g:self.model.param(('prod','good',g))*self.model.param('num_agent')*2 for g in self.model.goods.nonmonetary} - #Keep track of typical demand - #Target sufficient inventory to handle 2 standard deviations above mean demand for the last 100 periods - # history = pandas.Series(self.model.data.getLast('demand-'+i, 100)) + pandas.Series(self.model.data.getLast('shortage-'+i, 100)) - # avg[i], stdev[i] = history.mean(), history.std() - # itt = (1 if isnan(avg[i]) else avg[i]) + 2 * (1 if isnan(stdev[i]) else stdev[i]) - # self.invTarget[i] = (self.invTarget[i] + itt)/2 #Smooth it a bit - #Produce stuff self.portion[i] = (self.model.param('kImmob') * self.portion[i] + self.price[i]/tPrice) / (self.model.param('kImmob') + 1) #Calculate capital allocation self.stocks[i] = self.stocks[i] + self.portion[i] * labor * self.model.param(('prod', 'good', i)) diff --git a/setup.py b/setup.py index 4e9aba4..4a71716 100644 --- a/setup.py +++ b/setup.py @@ -20,11 +20,12 @@ packages=setuptools.find_packages(), package_dir={'helipad': 'helipad'}, include_package_data=True, - package_data={'': ['*.css']}, + package_data={'': ['*.css', '*.mo', '*.po', '*.pot', '*.png']}, license='MIT', install_requires=[ 'matplotlib', - 'pandas' + 'pandas', + 'networkx' ], classifiers=[ "Programming Language :: Python :: 3",