From 99dde264f0fa3731e4b56f5c43be0e695a3b789d Mon Sep 17 00:00:00 2001 From: Fletcher Foti Date: Mon, 8 Dec 2014 12:58:46 -0800 Subject: [PATCH 1/8] addings some basic data sources there are three basic change here: * addings activitysim/defaults/datasources.py which are similar to urbansim_defaults * an example directory which is similar to bayarea_urbansim (i.e. has data and config dirs right now) * and some sample notebooks for typical workflows We might separate some of this stuff into separate repos in the future but for now I think there is no need. --- .gitignore | 2 + activitysim/defaults/__init__.py | 0 activitysim/defaults/datasources.py | 54 + example/configs/settings.yaml | 1 + example/data/.gitignore | 1 + notebooks/data_mover.ipynb | 85 ++ notebooks/estimation.ipynb | 1747 +++++++++++++++++++++++++++ 7 files changed, 1890 insertions(+) create mode 100644 activitysim/defaults/__init__.py create mode 100644 activitysim/defaults/datasources.py create mode 100644 example/configs/settings.yaml create mode 100644 example/data/.gitignore create mode 100644 notebooks/data_mover.ipynb create mode 100644 notebooks/estimation.ipynb diff --git a/.gitignore b/.gitignore index 414b218cbd..6cc0db7827 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +.ipynb_checkpoints + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/activitysim/defaults/__init__.py b/activitysim/defaults/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/activitysim/defaults/datasources.py b/activitysim/defaults/datasources.py new file mode 100644 index 0000000000..c1b820eb55 --- /dev/null +++ b/activitysim/defaults/datasources.py @@ -0,0 +1,54 @@ +import numpy as np +import pandas as pd +import os +import uuid +import yaml +from urbansim.utils import misc +import urbansim.sim.simulation as sim + +import warnings + +warnings.filterwarnings('ignore', category=pd.io.pytables.PerformanceWarning) +pd.options.mode.chained_assignment = None + + +@sim.injectable('settings', cache=True) +def settings(): + with open(os.path.join(misc.configs_dir(), "settings.yaml")) as f: + settings = yaml.load(f) + # monkey patch on the settings object since it's pretty global + # but will also be available as injectable + sim.settings = settings + return settings + + +@sim.injectable('run_number') +def run_number(): + return misc.get_run_number() + + +@sim.injectable('uuid', cache=True) +def uuid_hex(): + return uuid.uuid4().hex + + +@sim.injectable('store', cache=True) +def hdfstore(settings): + return pd.HDFStore( + os.path.join(misc.data_dir(), settings["store"]), + mode='r') + + +@sim.injectable("scenario") +def scenario(settings): + return settings["scenario"] + + +@sim.table("land_use_data", cache=True) +def land_use_data(store): + return store["land_use/taz_data"] + + +@sim.table("accessibility", cache=True) +def land_use(store): + return store["skims/accessibility"] diff --git a/example/configs/settings.yaml b/example/configs/settings.yaml new file mode 100644 index 0000000000..bca18cbd9a --- /dev/null +++ b/example/configs/settings.yaml @@ -0,0 +1 @@ +store: mtc_asim.h5 diff --git a/example/data/.gitignore b/example/data/.gitignore new file mode 100644 index 0000000000..72e8ffc0db --- /dev/null +++ b/example/data/.gitignore @@ -0,0 +1 @@ +* diff --git a/notebooks/data_mover.ipynb b/notebooks/data_mover.ipynb new file mode 100644 index 0000000000..2a76f9be6b --- /dev/null +++ b/notebooks/data_mover.ipynb @@ -0,0 +1,85 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:6bef9f426e05b910a6f3914895e5db43939296d083b6b9803d36ebdab66e2131" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import pandas as pd\n", + "import os\n", + "# this is where I unzipped the MTC data\n", + "SRCDIR = \"/Users/ffoti/data/activitysim\"\n", + "# and where it's going to\n", + "TGTFILE = \"../example/data/mtc_asim.h5\"" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 1 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "store = pd.HDFStore(TGTFILE, \"w\")" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 2 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "df = pd.read_csv(os.path.join(SRCDIR, \"landuse\", \"tazData.csv\"))\n", + "store[\"land_use/taz_data\"] = df" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 3 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "df = pd.read_csv(os.path.join(SRCDIR, \"skims\", \"accessibility.csv\"))\n", + "store[\"skims/accessibility\"] = df" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 4 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "store.close()" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 5 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/notebooks/estimation.ipynb b/notebooks/estimation.ipynb new file mode 100644 index 0000000000..fcf0dd37a6 --- /dev/null +++ b/notebooks/estimation.ipynb @@ -0,0 +1,1747 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:77db7fbc506105b1febb38146b2296ba8a89643619750ef1c7fe2579637de527" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "code", + "collapsed": false, + "input": [ + "%load_ext autoreload\n", + "%autoreload 2\n", + "if 'sim' not in globals():\n", + " import os; os.chdir('../example')\n", + "import urbansim.sim.simulation as sim\n", + "from activitysim.defaults import datasources" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 1 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "sim.get_table(\"land_use_data\").to_frame()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "html": [ + "
\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
ZONEDISTRICTSDCOUNTYTOTHHHHPOPTOTPOPEMPRESSFDUMFDU...AREATYPEHSENROLLCOLLFTECOLLPTETOPOLOGYTERMINALZEROhhldssftazgqpop
0 1 1 1 1 43 69 77 29 1 42... 0 0.00000 0.00000 0.00000 3 5.45336 0 43 1 8
1 2 1 1 1 141 223 248 93 5 136... 0 0.00000 0.00000 0.00000 1 5.44111 0 141 2 25
2 3 1 1 1 256 406 452 170 8 248... 0 0.00000 0.00000 0.00000 1 5.41257 0 256 3 46
3 4 1 1 1 74 116 129 49 2 72... 0 0.00000 0.00000 0.00000 2 5.45635 0 74 4 13
4 5 1 1 1 496 784 874 328 16 480... 0 0.00000 62.68835 0.00000 1 5.48443 0 496 5 90
5 6 1 1 1 2194 3217 3833 1660 0 2194... 0 0.00000 0.00000 0.00000 1 4.66107 0 2194 6 616
6 7 1 1 1 3657 5362 5807 2739 0 3657... 0 0.00000 0.00000 0.00000 1 4.79331 0 3657 7 445
7 8 1 1 1 4261 6978 9192 2173 17 4244... 0 0.00000 0.00000 0.00000 2 4.34911 0 4261 8 2214
8 9 1 1 1 4952 8410 9050 3537 32 4920... 0 23.39647 1768.71545 17.90704 2 4.58932 0 4952 9 640
9 10 1 1 1 1643 2807 2904 1356 9 1634... 0 0.00000 600.01837 0.00000 3 4.50066 0 1643 10 97
10 11 1 1 1 2656 4537 4693 2192 14 2642... 0 0.00000 0.00000 0.00000 3 4.54921 0 2656 11 156
11 12 1 1 1 167 250 259 151 0 167... 0 0.00000 2983.98755 2065.14697 3 5.12652 0 167 12 9
12 13 1 1 1 163 247 256 149 0 163... 0 302.97360 1493.77795 3323.39771 3 5.14603 0 163 13 9
13 14 1 1 1 121 182 188 110 0 121... 0 0.00000 739.72437 218.51707 3 5.15788 0 121 14 6
14 15 1 1 1 767 1151 1196 696 0 767... 0 0.00000 0.00000 0.00000 3 5.11058 0 767 15 45
15 16 1 1 1 1319 2153 2275 1427 9 1310... 0 0.00000 0.00000 0.00000 2 5.07109 0 1319 16 122
16 17 1 1 1 4248 6930 7324 4592 27 4221... 1 0.00000 0.00000 0.00000 1 5.12843 0 4248 17 394
17 18 1 1 1 291 476 820 394 15 276... 1 0.00000 0.00000 0.00000 3 4.44244 0 291 18 344
18 19 1 1 1 1208 1972 3401 1633 63 1145... 1 0.00000 0.00000 0.00000 3 4.44473 0 1208 19 1429
19 20 1 1 1 2014 3332 3658 1357 140 1874... 1 0.00000 0.00000 0.00000 3 4.63788 0 2014 20 326
20 21 1 1 1 2398 3969 4357 1616 167 2231... 1 0.00000 0.00000 0.00000 3 4.59820 0 2398 21 388
21 22 1 1 1 1212 1918 1936 929 86 1126... 0 0.00000 0.00000 0.00000 3 4.77502 0 1212 22 18
22 23 1 1 1 470 743 749 360 34 436... 1 0.00000 0.00000 0.00000 1 4.81119 0 470 23 6
23 24 1 1 1 618 987 994 274 0 618... 0 0.00000 0.00000 0.00000 1 5.05426 0 618 24 7
24 25 1 1 1 1517 3308 3314 854 117 1400... 0 0.00000 0.00000 0.00000 1 4.58840 0 1517 25 6
25 26 1 1 1 695 1487 1500 533 7 688... 0 0.00000 0.00000 0.00000 1 5.08988 0 695 26 13
26 27 1 1 1 1527 3142 3142 1215 64 1463... 0 0.00000 0.00000 0.00000 1 4.02670 0 1527 27 0
27 28 1 1 1 1858 3284 3286 1785 0 1858... 0 0.00000 0.00000 0.00000 1 4.44760 0 1858 28 2
28 29 1 1 1 3095 4677 5006 2613 0 3095... 0 0.00000 0.00000 0.00000 1 4.67778 0 3095 29 329
29 30 1 1 1 4181 7024 7553 3561 26 4155... 1 0.00000 0.00000 0.00000 1 4.09015 0 4181 30 529
..................................................................
1424 1425 33 33 9 2122 5146 5625 2221 1615 507... 4 0.00000 0.00000 0.00000 1 1.22266 0 2122 1425 479
1425 1426 33 33 9 2220 5327 5327 2057 2210 10... 4 0.00000 0.00000 0.00000 1 1.01019 0 2220 1426 0
1426 1427 33 33 9 2335 5109 5849 2430 1582 753... 4 949.12695 649.44434 459.57358 1 1.19565 0 2335 1427 740
1427 1428 33 33 9 2966 11923 12026 3639 707 2259... 3 0.00000 0.00000 0.00000 2 2.41621 0 2966 1428 103
1428 1429 33 33 9 1836 4306 4315 1945 1230 606... 4 0.00000 0.00000 0.00000 1 1.33576 0 1836 1429 9
1429 1430 33 33 9 2645 5456 5852 2988 999 1646... 3 0.00000 0.00000 0.00000 1 1.98616 0 2645 1430 396
1430 1431 33 33 9 3560 7788 7808 3666 2015 1545... 4 401.55109 0.00000 0.00000 1 1.19191 0 3560 1431 20
1431 1432 33 33 9 2051 4501 4526 2052 1336 715... 4 0.00000 108.49641 354.17001 1 1.26906 0 2051 1432 25
1432 1433 33 33 9 1308 3057 3070 1470 1045 263... 4 1062.81934 0.00000 0.00000 1 1.18111 0 1308 1433 13
1433 1434 33 33 9 2305 5127 5134 2427 1866 439... 4 0.00000 0.00000 0.00000 1 1.17519 0 2305 1434 7
1434 1435 33 33 9 798 2355 2407 651 776 22... 5 333.76257 0.00000 0.00000 1 0.99539 0 798 1435 52
1435 1436 34 34 9 1874 4596 4610 2174 1536 338... 4 789.55035 1235.34143 5376.92627 1 0.98217 0 1874 1436 14
1436 1437 34 34 9 3134 6527 6649 8748 1481 1653... 4 0.00000 0.00000 0.00000 1 1.28406 0 3134 1437 122
1437 1438 34 34 9 2417 5601 5601 4028 1491 926... 4 0.00000 0.00000 0.00000 1 1.46413 0 2417 1438 0
1438 1439 34 34 9 0 0 4855 0 0 0... 4 0.00000 0.00000 0.00000 3 7.31020 0 0 1439 4855
1439 1440 34 34 9 2827 6017 6026 9970 1742 1085... 4 1439.34253 0.00000 0.00000 1 1.13516 0 2827 1440 9
1440 1441 34 34 9 2197 5175 5174 1942 1579 618... 4 0.00000 0.00000 0.00000 1 1.33296 0 2197 1441 -1
1441 1442 34 34 9 2352 5808 5807 2055 2072 280... 4 0.00000 0.00000 0.00000 1 1.18622 0 2352 1442 -1
1442 1443 34 34 9 2052 4178 4249 1443 1018 1034... 4 973.11682 0.00000 0.00000 1 1.29862 0 2052 1443 71
1443 1444 34 34 9 1912 4016 4261 2021 843 1069... 4 0.00000 255.74797 0.00000 1 1.21144 0 1912 1444 245
1444 1445 34 34 9 2259 5441 5441 2146 1449 810... 4 0.00000 0.00000 0.00000 1 1.06519 0 2259 1445 0
1445 1446 34 34 9 2458 5588 5626 2114 1553 905... 4 0.00000 0.00000 0.00000 1 1.07095 0 2458 1446 38
1446 1447 34 34 9 929 2074 2073 697 818 111... 4 0.00000 0.00000 0.00000 1 1.15845 0 929 1447 -1
1447 1448 34 34 9 4457 7631 7644 4865 2107 2350... 4 0.00000 0.00000 0.00000 1 1.36052 0 4457 1448 13
1448 1449 34 34 9 1007 2359 2360 1108 251 756... 4 0.00000 0.00000 0.00000 1 1.15822 0 1007 1449 1
1449 1450 34 34 9 2752 6492 6506 3260 2366 386... 4 0.00000 0.00000 0.00000 1 1.14586 0 2752 1450 14
1450 1451 34 34 9 1926 4582 4581 2064 1772 154... 4 0.00000 0.00000 0.00000 1 1.18198 0 1926 1451 -1
1451 1452 34 34 9 1989 4574 4580 1750 1572 417... 4 0.00000 0.00000 0.00000 1 1.13975 0 1989 1452 6
1452 1453 34 34 9 262 573 688 259 216 46... 5 0.00000 0.00000 0.00000 1 0.99757 0 262 1453 115
1453 1454 34 34 9 1069 2116 2311 924 986 83... 5 0.00000 0.00000 0.00000 1 0.97576 0 1069 1454 195
\n", + "

1454 rows \u00d7 42 columns

\n", + "
" + ], + "metadata": {}, + "output_type": "pyout", + "prompt_number": 2, + "text": [ + " ZONE DISTRICT SD COUNTY TOTHH HHPOP TOTPOP EMPRES SFDU MFDU \\\n", + "0 1 1 1 1 43 69 77 29 1 42 \n", + "1 2 1 1 1 141 223 248 93 5 136 \n", + "2 3 1 1 1 256 406 452 170 8 248 \n", + "3 4 1 1 1 74 116 129 49 2 72 \n", + "4 5 1 1 1 496 784 874 328 16 480 \n", + "5 6 1 1 1 2194 3217 3833 1660 0 2194 \n", + "6 7 1 1 1 3657 5362 5807 2739 0 3657 \n", + "7 8 1 1 1 4261 6978 9192 2173 17 4244 \n", + "8 9 1 1 1 4952 8410 9050 3537 32 4920 \n", + "9 10 1 1 1 1643 2807 2904 1356 9 1634 \n", + "10 11 1 1 1 2656 4537 4693 2192 14 2642 \n", + "11 12 1 1 1 167 250 259 151 0 167 \n", + "12 13 1 1 1 163 247 256 149 0 163 \n", + "13 14 1 1 1 121 182 188 110 0 121 \n", + "14 15 1 1 1 767 1151 1196 696 0 767 \n", + "15 16 1 1 1 1319 2153 2275 1427 9 1310 \n", + "16 17 1 1 1 4248 6930 7324 4592 27 4221 \n", + "17 18 1 1 1 291 476 820 394 15 276 \n", + "18 19 1 1 1 1208 1972 3401 1633 63 1145 \n", + "19 20 1 1 1 2014 3332 3658 1357 140 1874 \n", + "20 21 1 1 1 2398 3969 4357 1616 167 2231 \n", + "21 22 1 1 1 1212 1918 1936 929 86 1126 \n", + "22 23 1 1 1 470 743 749 360 34 436 \n", + "23 24 1 1 1 618 987 994 274 0 618 \n", + "24 25 1 1 1 1517 3308 3314 854 117 1400 \n", + "25 26 1 1 1 695 1487 1500 533 7 688 \n", + "26 27 1 1 1 1527 3142 3142 1215 64 1463 \n", + "27 28 1 1 1 1858 3284 3286 1785 0 1858 \n", + "28 29 1 1 1 3095 4677 5006 2613 0 3095 \n", + "29 30 1 1 1 4181 7024 7553 3561 26 4155 \n", + "... ... ... .. ... ... ... ... ... ... ... \n", + "1424 1425 33 33 9 2122 5146 5625 2221 1615 507 \n", + "1425 1426 33 33 9 2220 5327 5327 2057 2210 10 \n", + "1426 1427 33 33 9 2335 5109 5849 2430 1582 753 \n", + "1427 1428 33 33 9 2966 11923 12026 3639 707 2259 \n", + "1428 1429 33 33 9 1836 4306 4315 1945 1230 606 \n", + "1429 1430 33 33 9 2645 5456 5852 2988 999 1646 \n", + "1430 1431 33 33 9 3560 7788 7808 3666 2015 1545 \n", + "1431 1432 33 33 9 2051 4501 4526 2052 1336 715 \n", + "1432 1433 33 33 9 1308 3057 3070 1470 1045 263 \n", + "1433 1434 33 33 9 2305 5127 5134 2427 1866 439 \n", + "1434 1435 33 33 9 798 2355 2407 651 776 22 \n", + "1435 1436 34 34 9 1874 4596 4610 2174 1536 338 \n", + "1436 1437 34 34 9 3134 6527 6649 8748 1481 1653 \n", + "1437 1438 34 34 9 2417 5601 5601 4028 1491 926 \n", + "1438 1439 34 34 9 0 0 4855 0 0 0 \n", + "1439 1440 34 34 9 2827 6017 6026 9970 1742 1085 \n", + "1440 1441 34 34 9 2197 5175 5174 1942 1579 618 \n", + "1441 1442 34 34 9 2352 5808 5807 2055 2072 280 \n", + "1442 1443 34 34 9 2052 4178 4249 1443 1018 1034 \n", + "1443 1444 34 34 9 1912 4016 4261 2021 843 1069 \n", + "1444 1445 34 34 9 2259 5441 5441 2146 1449 810 \n", + "1445 1446 34 34 9 2458 5588 5626 2114 1553 905 \n", + "1446 1447 34 34 9 929 2074 2073 697 818 111 \n", + "1447 1448 34 34 9 4457 7631 7644 4865 2107 2350 \n", + "1448 1449 34 34 9 1007 2359 2360 1108 251 756 \n", + "1449 1450 34 34 9 2752 6492 6506 3260 2366 386 \n", + "1450 1451 34 34 9 1926 4582 4581 2064 1772 154 \n", + "1451 1452 34 34 9 1989 4574 4580 1750 1572 417 \n", + "1452 1453 34 34 9 262 573 688 259 216 46 \n", + "1453 1454 34 34 9 1069 2116 2311 924 986 83 \n", + "\n", + " ... AREATYPE HSENROLL COLLFTE COLLPTE TOPOLOGY TERMINAL \\\n", + "0 ... 0 0.00000 0.00000 0.00000 3 5.45336 \n", + "1 ... 0 0.00000 0.00000 0.00000 1 5.44111 \n", + "2 ... 0 0.00000 0.00000 0.00000 1 5.41257 \n", + "3 ... 0 0.00000 0.00000 0.00000 2 5.45635 \n", + "4 ... 0 0.00000 62.68835 0.00000 1 5.48443 \n", + "5 ... 0 0.00000 0.00000 0.00000 1 4.66107 \n", + "6 ... 0 0.00000 0.00000 0.00000 1 4.79331 \n", + "7 ... 0 0.00000 0.00000 0.00000 2 4.34911 \n", + "8 ... 0 23.39647 1768.71545 17.90704 2 4.58932 \n", + "9 ... 0 0.00000 600.01837 0.00000 3 4.50066 \n", + "10 ... 0 0.00000 0.00000 0.00000 3 4.54921 \n", + "11 ... 0 0.00000 2983.98755 2065.14697 3 5.12652 \n", + "12 ... 0 302.97360 1493.77795 3323.39771 3 5.14603 \n", + "13 ... 0 0.00000 739.72437 218.51707 3 5.15788 \n", + "14 ... 0 0.00000 0.00000 0.00000 3 5.11058 \n", + "15 ... 0 0.00000 0.00000 0.00000 2 5.07109 \n", + "16 ... 1 0.00000 0.00000 0.00000 1 5.12843 \n", + "17 ... 1 0.00000 0.00000 0.00000 3 4.44244 \n", + "18 ... 1 0.00000 0.00000 0.00000 3 4.44473 \n", + "19 ... 1 0.00000 0.00000 0.00000 3 4.63788 \n", + "20 ... 1 0.00000 0.00000 0.00000 3 4.59820 \n", + "21 ... 0 0.00000 0.00000 0.00000 3 4.77502 \n", + "22 ... 1 0.00000 0.00000 0.00000 1 4.81119 \n", + "23 ... 0 0.00000 0.00000 0.00000 1 5.05426 \n", + "24 ... 0 0.00000 0.00000 0.00000 1 4.58840 \n", + "25 ... 0 0.00000 0.00000 0.00000 1 5.08988 \n", + "26 ... 0 0.00000 0.00000 0.00000 1 4.02670 \n", + "27 ... 0 0.00000 0.00000 0.00000 1 4.44760 \n", + "28 ... 0 0.00000 0.00000 0.00000 1 4.67778 \n", + "29 ... 1 0.00000 0.00000 0.00000 1 4.09015 \n", + "... ... ... ... ... ... ... ... \n", + "1424 ... 4 0.00000 0.00000 0.00000 1 1.22266 \n", + "1425 ... 4 0.00000 0.00000 0.00000 1 1.01019 \n", + "1426 ... 4 949.12695 649.44434 459.57358 1 1.19565 \n", + "1427 ... 3 0.00000 0.00000 0.00000 2 2.41621 \n", + "1428 ... 4 0.00000 0.00000 0.00000 1 1.33576 \n", + "1429 ... 3 0.00000 0.00000 0.00000 1 1.98616 \n", + "1430 ... 4 401.55109 0.00000 0.00000 1 1.19191 \n", + "1431 ... 4 0.00000 108.49641 354.17001 1 1.26906 \n", + "1432 ... 4 1062.81934 0.00000 0.00000 1 1.18111 \n", + "1433 ... 4 0.00000 0.00000 0.00000 1 1.17519 \n", + "1434 ... 5 333.76257 0.00000 0.00000 1 0.99539 \n", + "1435 ... 4 789.55035 1235.34143 5376.92627 1 0.98217 \n", + "1436 ... 4 0.00000 0.00000 0.00000 1 1.28406 \n", + "1437 ... 4 0.00000 0.00000 0.00000 1 1.46413 \n", + "1438 ... 4 0.00000 0.00000 0.00000 3 7.31020 \n", + "1439 ... 4 1439.34253 0.00000 0.00000 1 1.13516 \n", + "1440 ... 4 0.00000 0.00000 0.00000 1 1.33296 \n", + "1441 ... 4 0.00000 0.00000 0.00000 1 1.18622 \n", + "1442 ... 4 973.11682 0.00000 0.00000 1 1.29862 \n", + "1443 ... 4 0.00000 255.74797 0.00000 1 1.21144 \n", + "1444 ... 4 0.00000 0.00000 0.00000 1 1.06519 \n", + "1445 ... 4 0.00000 0.00000 0.00000 1 1.07095 \n", + "1446 ... 4 0.00000 0.00000 0.00000 1 1.15845 \n", + "1447 ... 4 0.00000 0.00000 0.00000 1 1.36052 \n", + "1448 ... 4 0.00000 0.00000 0.00000 1 1.15822 \n", + "1449 ... 4 0.00000 0.00000 0.00000 1 1.14586 \n", + "1450 ... 4 0.00000 0.00000 0.00000 1 1.18198 \n", + "1451 ... 4 0.00000 0.00000 0.00000 1 1.13975 \n", + "1452 ... 5 0.00000 0.00000 0.00000 1 0.99757 \n", + "1453 ... 5 0.00000 0.00000 0.00000 1 0.97576 \n", + "\n", + " ZERO hhlds sftaz gqpop \n", + "0 0 43 1 8 \n", + "1 0 141 2 25 \n", + "2 0 256 3 46 \n", + "3 0 74 4 13 \n", + "4 0 496 5 90 \n", + "5 0 2194 6 616 \n", + "6 0 3657 7 445 \n", + "7 0 4261 8 2214 \n", + "8 0 4952 9 640 \n", + "9 0 1643 10 97 \n", + "10 0 2656 11 156 \n", + "11 0 167 12 9 \n", + "12 0 163 13 9 \n", + "13 0 121 14 6 \n", + "14 0 767 15 45 \n", + "15 0 1319 16 122 \n", + "16 0 4248 17 394 \n", + "17 0 291 18 344 \n", + "18 0 1208 19 1429 \n", + "19 0 2014 20 326 \n", + "20 0 2398 21 388 \n", + "21 0 1212 22 18 \n", + "22 0 470 23 6 \n", + "23 0 618 24 7 \n", + "24 0 1517 25 6 \n", + "25 0 695 26 13 \n", + "26 0 1527 27 0 \n", + "27 0 1858 28 2 \n", + "28 0 3095 29 329 \n", + "29 0 4181 30 529 \n", + "... ... ... ... ... \n", + "1424 0 2122 1425 479 \n", + "1425 0 2220 1426 0 \n", + "1426 0 2335 1427 740 \n", + "1427 0 2966 1428 103 \n", + "1428 0 1836 1429 9 \n", + "1429 0 2645 1430 396 \n", + "1430 0 3560 1431 20 \n", + "1431 0 2051 1432 25 \n", + "1432 0 1308 1433 13 \n", + "1433 0 2305 1434 7 \n", + "1434 0 798 1435 52 \n", + "1435 0 1874 1436 14 \n", + "1436 0 3134 1437 122 \n", + "1437 0 2417 1438 0 \n", + "1438 0 0 1439 4855 \n", + "1439 0 2827 1440 9 \n", + "1440 0 2197 1441 -1 \n", + "1441 0 2352 1442 -1 \n", + "1442 0 2052 1443 71 \n", + "1443 0 1912 1444 245 \n", + "1444 0 2259 1445 0 \n", + "1445 0 2458 1446 38 \n", + "1446 0 929 1447 -1 \n", + "1447 0 4457 1448 13 \n", + "1448 0 1007 1449 1 \n", + "1449 0 2752 1450 14 \n", + "1450 0 1926 1451 -1 \n", + "1451 0 1989 1452 6 \n", + "1452 0 262 1453 115 \n", + "1453 0 1069 1454 195 \n", + "\n", + "[1454 rows x 42 columns]" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file From 09cfe10e226132216aee1a6a78356073b257086e Mon Sep 17 00:00:00 2001 From: Fletcher Foti Date: Mon, 8 Dec 2014 16:41:18 -0800 Subject: [PATCH 2/8] all basic variables implemented for auto ownership --- activitysim/defaults/datasources.py | 12 +- activitysim/defaults/variables.py | 72 + example/configs/settings.yaml | 11 + notebooks/data_mover.ipynb | 67 +- notebooks/estimation.ipynb | 2201 +++++++-------------------- 5 files changed, 701 insertions(+), 1662 deletions(-) create mode 100644 activitysim/defaults/variables.py diff --git a/activitysim/defaults/datasources.py b/activitysim/defaults/datasources.py index c1b820eb55..55ea25f057 100644 --- a/activitysim/defaults/datasources.py +++ b/activitysim/defaults/datasources.py @@ -44,7 +44,7 @@ def scenario(settings): return settings["scenario"] -@sim.table("land_use_data", cache=True) +@sim.table("land_use", cache=True) def land_use_data(store): return store["land_use/taz_data"] @@ -52,3 +52,13 @@ def land_use_data(store): @sim.table("accessibility", cache=True) def land_use(store): return store["skims/accessibility"] + + +@sim.table("households", cache=True) +def land_use(store): + return store["households"] + + +@sim.table("persons", cache=True) +def land_use(store): + return store["persons"] diff --git a/activitysim/defaults/variables.py b/activitysim/defaults/variables.py new file mode 100644 index 0000000000..da3901842f --- /dev/null +++ b/activitysim/defaults/variables.py @@ -0,0 +1,72 @@ +import urbansim.sim.simulation as sim +from activitysim.defaults import datasources + + +@sim.column("households") +def income_in_thousands(households): + return households.income / 1000 + + +@sim.column("households") +def drivers(households, persons): + # we assume that everyone 16 and older is a potential driver + return persons.local.query("16 <= age").\ + groupby("household_id").size().\ + reindex(households.index).fillna(0) + + +@sim.column("households") +def num_young_children(households, persons): + return persons.local.query("age <= 4").\ + groupby("household_id").size().\ + reindex(households.index).fillna(0) + + +@sim.column("households") +def num_children(households, persons): + return persons.local.query("5 <= age <= 15").\ + groupby("household_id").size().\ + reindex(households.index).fillna(0) + + +@sim.column("households") +def num_adolescents(households, persons): + return persons.local.query("16 <= age <= 17").\ + groupby("household_id").size().\ + reindex(households.index).fillna(0) + + +@sim.column("households") +def num_college_age(households, persons): + return persons.local.query("18 <= age <= 24").\ + groupby("household_id").size().\ + reindex(households.index).fillna(0) + + +@sim.column("households") +def num_young_adults(households, persons): + return persons.local.query("25 <= age <= 34").\ + groupby("household_id").size().\ + reindex(households.index).fillna(0) + + +@sim.column("land_use") +def household_density(land_use): + return land_use.total_households / land_use.total_acres + + +@sim.column("land_use") +def employment_density(land_use): + return land_use.total_employment / land_use.total_acres + + +@sim.column("land_use") +def density_index(land_use): + return (land_use.household_density * land_use.employment_density) / \ + (land_use.household_density + land_use.employment_density) + + +@sim.column("land_use") +def county_name(land_use, settings): + assert "county_map" in settings + return land_use.county_id.map(settings["county_map"]) diff --git a/example/configs/settings.yaml b/example/configs/settings.yaml index bca18cbd9a..e80d5134d8 100644 --- a/example/configs/settings.yaml +++ b/example/configs/settings.yaml @@ -1 +1,12 @@ store: mtc_asim.h5 + +county_map: + San Francico: 1 + San Mateo: 2 + Santa Clara: 3 + Alameda: 4 + Contra Costa: 5 + Solano: 6 + Napa: 7 + Sonoma: 8 + Marin: 9 diff --git a/notebooks/data_mover.ipynb b/notebooks/data_mover.ipynb index 2a76f9be6b..b9c9f37eff 100644 --- a/notebooks/data_mover.ipynb +++ b/notebooks/data_mover.ipynb @@ -1,7 +1,7 @@ { "metadata": { "name": "", - "signature": "sha256:6bef9f426e05b910a6f3914895e5db43939296d083b6b9803d36ebdab66e2131" + "signature": "sha256:b9b5094000883a97d7687aa911926f2d0f45c0546957b83f82fc449cce6edc6c" }, "nbformat": 3, "nbformat_minor": 0, @@ -22,7 +22,7 @@ "language": "python", "metadata": {}, "outputs": [], - "prompt_number": 1 + "prompt_number": 17 }, { "cell_type": "code", @@ -33,31 +33,79 @@ "language": "python", "metadata": {}, "outputs": [], - "prompt_number": 2 + "prompt_number": 18 }, { "cell_type": "code", "collapsed": false, "input": [ - "df = pd.read_csv(os.path.join(SRCDIR, \"landuse\", \"tazData.csv\"))\n", + "col_map = {\n", + " \"HHID\": \"household_id\",\n", + " \"AGE\": \"age\",\n", + " \"TOTHH\": \"total_households\",\n", + " \"TOTEMP\": \"total_employment\",\n", + " \"TOTACRE\": \"total_acres\",\n", + " \"COUNTY\": \"county_id\",\n", + " \"hworkers\": \"workers\",\n", + " \"HINC\": \"income\"\n", + "}" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 19 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "df = pd.read_csv(os.path.join(SRCDIR, \"landuse\", \"tazData.csv\"), index_col=\"ZONE\")\n", + "df.columns = [col_map.get(s, s) for s in df.columns]\n", "store[\"land_use/taz_data\"] = df" ], "language": "python", "metadata": {}, "outputs": [], - "prompt_number": 3 + "prompt_number": 20 }, { "cell_type": "code", "collapsed": false, "input": [ - "df = pd.read_csv(os.path.join(SRCDIR, \"skims\", \"accessibility.csv\"))\n", + "df = pd.read_csv(os.path.join(SRCDIR, \"skims\", \"accessibility.csv\"), index_col=\"taz\")\n", + "df.columns = [col_map.get(s, s) for s in df.columns]\n", "store[\"skims/accessibility\"] = df" ], "language": "python", "metadata": {}, "outputs": [], - "prompt_number": 4 + "prompt_number": 21 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "df = pd.read_csv(os.path.join(SRCDIR, \"popsyn\", \"hhFile.p2011s3a1.2010.csv\"), index_col=\"HHID\")\n", + "df.columns = [col_map.get(s, s) for s in df.columns]\n", + "store[\"households\"] = df" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 22 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "df = pd.read_csv(os.path.join(SRCDIR, \"popsyn\", \"personFile.p2011s3a1.2010.csv\"), index_col=\"PERID\")\n", + "df.columns = [col_map.get(s, s) for s in df.columns]\n", + "store[\"persons\"] = df" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 23 }, { "cell_type": "code", @@ -68,7 +116,7 @@ "language": "python", "metadata": {}, "outputs": [], - "prompt_number": 5 + "prompt_number": 24 }, { "cell_type": "code", @@ -76,7 +124,8 @@ "input": [], "language": "python", "metadata": {}, - "outputs": [] + "outputs": [], + "prompt_number": 24 } ], "metadata": {} diff --git a/notebooks/estimation.ipynb b/notebooks/estimation.ipynb index fcf0dd37a6..fc32eeccd0 100644 --- a/notebooks/estimation.ipynb +++ b/notebooks/estimation.ipynb @@ -1,7 +1,7 @@ { "metadata": { "name": "", - "signature": "sha256:77db7fbc506105b1febb38146b2296ba8a89643619750ef1c7fe2579637de527" + "signature": "sha256:0af8ad519a9a50cb2b446b20f0d48d14f7731475e53b8217e74fe78fe3293413" }, "nbformat": 3, "nbformat_minor": 0, @@ -17,7 +17,7 @@ "if 'sim' not in globals():\n", " import os; os.chdir('../example')\n", "import urbansim.sim.simulation as sim\n", - "from activitysim.defaults import datasources" + "from activitysim.defaults import variables" ], "language": "python", "metadata": {}, @@ -28,7 +28,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "sim.get_table(\"land_use_data\").to_frame()" + "sim.get_table(\"land_use\").to_frame().describe()" ], "language": "python", "metadata": {}, @@ -40,1697 +40,593 @@ " \n", " \n", " \n", - " ZONE\n", " DISTRICT\n", " SD\n", - " COUNTY\n", - " TOTHH\n", + " county_id\n", + " total_households\n", " HHPOP\n", " TOTPOP\n", " EMPRES\n", " SFDU\n", " MFDU\n", + " HHINCQ1\n", " ...\n", - " AREATYPE\n", - " HSENROLL\n", - " COLLFTE\n", - " COLLPTE\n", " TOPOLOGY\n", " TERMINAL\n", " ZERO\n", " hhlds\n", " sftaz\n", " gqpop\n", + " employment_density\n", + " household_density\n", + " density_index\n", + " county_name\n", " \n", " \n", " \n", " \n", - " 0 \n", - " 1\n", - " 1\n", - " 1\n", - " 1\n", - " 43\n", - " 69\n", - " 77\n", - " 29\n", - " 1\n", - " 42\n", - " ...\n", - " 0\n", - " 0.00000\n", - " 0.00000\n", - " 0.00000\n", - " 3\n", - " 5.45336\n", - " 0\n", - " 43\n", - " 1\n", - " 8\n", - " \n", - " \n", - " 1 \n", - " 2\n", - " 1\n", - " 1\n", - " 1\n", - " 141\n", - " 223\n", - " 248\n", - " 93\n", - " 5\n", - " 136\n", - " ...\n", - " 0\n", - " 0.00000\n", - " 0.00000\n", - " 0.00000\n", - " 1\n", - " 5.44111\n", - " 0\n", - " 141\n", - " 2\n", - " 25\n", - " \n", - " \n", - " 2 \n", - " 3\n", - " 1\n", - " 1\n", - " 1\n", - " 256\n", - " 406\n", - " 452\n", - " 170\n", - " 8\n", - " 248\n", - " ...\n", - " 0\n", - " 0.00000\n", - " 0.00000\n", - " 0.00000\n", - " 1\n", - " 5.41257\n", - " 0\n", - " 256\n", - " 3\n", - " 46\n", - " \n", - " \n", - " 3 \n", - " 4\n", - " 1\n", - " 1\n", - " 1\n", - " 74\n", - " 116\n", - " 129\n", - " 49\n", - " 2\n", - " 72\n", - " ...\n", - " 0\n", - " 0.00000\n", - " 0.00000\n", - " 0.00000\n", - " 2\n", - " 5.45635\n", - " 0\n", - " 74\n", - " 4\n", - " 13\n", - " \n", - " \n", - " 4 \n", - " 5\n", - " 1\n", - " 1\n", - " 1\n", - " 496\n", - " 784\n", - " 874\n", - " 328\n", - " 16\n", - " 480\n", - " ...\n", - " 0\n", - " 0.00000\n", - " 62.68835\n", - " 0.00000\n", - " 1\n", - " 5.48443\n", - " 0\n", - " 496\n", - " 5\n", - " 90\n", - " \n", - " \n", - " 5 \n", - " 6\n", - " 1\n", - " 1\n", - " 1\n", - " 2194\n", - " 3217\n", - " 3833\n", - " 1660\n", + " count\n", + " 1454.000000\n", + " 1454.000000\n", + " 1454.000000\n", + " 1454.000000\n", + " 1454.000000\n", + " 1454.000000\n", + " 1454.000000\n", + " 1454.000000\n", + " 1454.000000\n", + " 1454.000000\n", + " ...\n", + " 1454.000000\n", + " 1454.000000\n", + " 1454\n", + " 1454.000000\n", + " 1454.000000\n", + " 1454.000000\n", + " 1454.000000\n", + " 1454.000000\n", + " 1453.000000\n", + " 0\n", + " \n", + " \n", + " mean\n", + " 14.908528\n", + " 14.908528\n", + " 3.835626\n", + " 1793.688446\n", + " 4816.408528\n", + " 4917.978680\n", + " 2168.684319\n", + " 1122.798487\n", + " 670.889959\n", + " 508.134801\n", + " ...\n", + " 2.063274\n", + " 1.630505\n", " 0\n", - " 2194\n", - " ...\n", - " 0\n", - " 0.00000\n", - " 0.00000\n", - " 0.00000\n", - " 1\n", - " 4.66107\n", - " 0\n", - " 2194\n", - " 6\n", - " 616\n", - " \n", - " \n", - " 6 \n", - " 7\n", - " 1\n", - " 1\n", - " 1\n", - " 3657\n", - " 5362\n", - " 5807\n", - " 2739\n", + " 1793.688446\n", + " 727.500000\n", + " 101.570151\n", + " 9.596395\n", + " 6.008186\n", + " 2.279554\n", + " NaN\n", + " \n", + " \n", + " std\n", + " 8.701078\n", + " 8.701078\n", + " 2.040153\n", + " 961.021405\n", + " 2686.029808\n", + " 2690.352928\n", + " 1211.109335\n", + " 854.895353\n", + " 717.261660\n", + " 378.753528\n", + " ...\n", + " 0.926842\n", + " 0.879441\n", " 0\n", - " 3657\n", - " ...\n", - " 0\n", - " 0.00000\n", - " 0.00000\n", - " 0.00000\n", - " 1\n", - " 4.79331\n", - " 0\n", - " 3657\n", - " 7\n", - " 445\n", - " \n", - " \n", - " 7 \n", - " 8\n", - " 1\n", - " 1\n", - " 1\n", - " 4261\n", - " 6978\n", - " 9192\n", - " 2173\n", - " 17\n", - " 4244\n", - " ...\n", - " 0\n", - " 0.00000\n", - " 0.00000\n", - " 0.00000\n", - " 2\n", - " 4.34911\n", - " 0\n", - " 4261\n", - " 8\n", - " 2214\n", - " \n", - " \n", - " 8 \n", - " 9\n", - " 1\n", - " 1\n", - " 1\n", - " 4952\n", - " 8410\n", - " 9050\n", - " 3537\n", - " 32\n", - " 4920\n", - " ...\n", - " 0\n", - " 23.39647\n", - " 1768.71545\n", - " 17.90704\n", - " 2\n", - " 4.58932\n", - " 0\n", - " 4952\n", - " 9\n", - " 640\n", - " \n", - " \n", - " 9 \n", - " 10\n", - " 1\n", - " 1\n", - " 1\n", - " 1643\n", - " 2807\n", - " 2904\n", - " 1356\n", - " 9\n", - " 1634\n", - " ...\n", - " 0\n", - " 0.00000\n", - " 600.01837\n", - " 0.00000\n", - " 3\n", - " 4.50066\n", - " 0\n", - " 1643\n", - " 10\n", - " 97\n", - " \n", - " \n", - " 10 \n", - " 11\n", - " 1\n", - " 1\n", - " 1\n", - " 2656\n", - " 4537\n", - " 4693\n", - " 2192\n", - " 14\n", - " 2642\n", - " ...\n", - " 0\n", - " 0.00000\n", - " 0.00000\n", - " 0.00000\n", - " 3\n", - " 4.54921\n", - " 0\n", - " 2656\n", - " 11\n", - " 156\n", - " \n", - " \n", - " 11 \n", - " 12\n", - " 1\n", - " 1\n", - " 1\n", - " 167\n", - " 250\n", - " 259\n", - " 151\n", + " 961.021405\n", + " 419.877958\n", + " 393.886676\n", + " 45.067313\n", + " 8.565908\n", + " 3.945717\n", + " NaN\n", + " \n", + " \n", + " min\n", + " 1.000000\n", + " 1.000000\n", + " 1.000000\n", + " 0.000000\n", + " 0.000000\n", + " 0.000000\n", + " 0.000000\n", + " 0.000000\n", + " 0.000000\n", + " 0.000000\n", + " ...\n", + " 1.000000\n", + " 0.904320\n", " 0\n", - " 167\n", - " ...\n", - " 0\n", - " 0.00000\n", - " 2983.98755\n", - " 2065.14697\n", - " 3\n", - " 5.12652\n", - " 0\n", - " 167\n", - " 12\n", - " 9\n", - " \n", - " \n", - " 12 \n", - " 13\n", - " 1\n", - " 1\n", - " 1\n", - " 163\n", - " 247\n", - " 256\n", - " 149\n", + " 0.000000\n", + " 1.000000\n", + " -1.000000\n", + " 0.000000\n", + " 0.000000\n", + " 0.000000\n", + " NaN\n", + " \n", + " \n", + " 25%\n", + " 8.000000\n", + " 8.000000\n", + " 3.000000\n", + " 1200.250000\n", + " 3288.250000\n", + " 3384.500000\n", + " 1460.500000\n", + " 602.000000\n", + " 144.500000\n", + " 257.000000\n", + " ...\n", + " 1.000000\n", + " 1.167372\n", " 0\n", - " 163\n", - " ...\n", - " 0\n", - " 302.97360\n", - " 1493.77795\n", - " 3323.39771\n", - " 3\n", - " 5.14603\n", - " 0\n", - " 163\n", - " 13\n", - " 9\n", - " \n", - " \n", - " 13 \n", - " 14\n", - " 1\n", - " 1\n", - " 1\n", - " 121\n", - " 182\n", - " 188\n", - " 110\n", + " 1200.250000\n", + " 364.250000\n", + " 5.000000\n", + " 0.877829\n", + " 1.910701\n", + " 0.550232\n", + " NaN\n", + " \n", + " \n", + " 50%\n", + " 15.000000\n", + " 15.000000\n", + " 4.000000\n", + " 1681.500000\n", + " 4504.500000\n", + " 4577.000000\n", + " 2016.000000\n", + " 1034.000000\n", + " 460.000000\n", + " 434.000000\n", + " ...\n", + " 2.000000\n", + " 1.323075\n", " 0\n", - " 121\n", - " ...\n", - " 0\n", - " 0.00000\n", - " 739.72437\n", - " 218.51707\n", - " 3\n", - " 5.15788\n", - " 0\n", - " 121\n", - " 14\n", - " 6\n", - " \n", - " \n", - " 14 \n", - " 15\n", - " 1\n", - " 1\n", - " 1\n", - " 767\n", - " 1151\n", - " 1196\n", - " 696\n", + " 1681.500000\n", + " 727.500000\n", + " 18.000000\n", + " 2.158701\n", + " 3.939122\n", + " 1.289224\n", + " NaN\n", + " \n", + " \n", + " 75%\n", + " 20.750000\n", + " 20.750000\n", + " 5.000000\n", + " 2259.750000\n", + " 6033.750000\n", + " 6098.500000\n", + " 2735.500000\n", + " 1496.000000\n", + " 907.750000\n", + " 674.750000\n", + " ...\n", + " 3.000000\n", + " 1.632443\n", " 0\n", - " 767\n", - " ...\n", - " 0\n", - " 0.00000\n", - " 0.00000\n", - " 0.00000\n", - " 3\n", - " 5.11058\n", - " 0\n", - " 767\n", - " 15\n", - " 45\n", - " \n", - " \n", - " 15 \n", - " 16\n", - " 1\n", - " 1\n", - " 1\n", - " 1319\n", - " 2153\n", - " 2275\n", - " 1427\n", - " 9\n", - " 1310\n", - " ...\n", - " 0\n", - " 0.00000\n", - " 0.00000\n", - " 0.00000\n", - " 2\n", - " 5.07109\n", - " 0\n", - " 1319\n", - " 16\n", - " 122\n", - " \n", - " \n", - " 16 \n", - " 17\n", - " 1\n", - " 1\n", - " 1\n", - " 4248\n", - " 6930\n", - " 7324\n", - " 4592\n", - " 27\n", - " 4221\n", - " ...\n", - " 1\n", - " 0.00000\n", - " 0.00000\n", - " 0.00000\n", - " 1\n", - " 5.12843\n", - " 0\n", - " 4248\n", - " 17\n", - " 394\n", - " \n", - " \n", - " 17 \n", - " 18\n", - " 1\n", - " 1\n", - " 1\n", - " 291\n", - " 476\n", - " 820\n", - " 394\n", - " 15\n", - " 276\n", - " ...\n", - " 1\n", - " 0.00000\n", - " 0.00000\n", - " 0.00000\n", - " 3\n", - " 4.44244\n", - " 0\n", - " 291\n", - " 18\n", - " 344\n", - " \n", - " \n", - " 18 \n", - " 19\n", - " 1\n", - " 1\n", - " 1\n", - " 1208\n", - " 1972\n", - " 3401\n", - " 1633\n", - " 63\n", - " 1145\n", - " ...\n", - " 1\n", - " 0.00000\n", - " 0.00000\n", - " 0.00000\n", - " 3\n", - " 4.44473\n", - " 0\n", - " 1208\n", - " 19\n", - " 1429\n", - " \n", - " \n", - " 19 \n", - " 20\n", - " 1\n", - " 1\n", - " 1\n", - " 2014\n", - " 3332\n", - " 3658\n", - " 1357\n", - " 140\n", - " 1874\n", - " ...\n", - " 1\n", - " 0.00000\n", - " 0.00000\n", - " 0.00000\n", - " 3\n", - " 4.63788\n", - " 0\n", - " 2014\n", - " 20\n", - " 326\n", - " \n", - " \n", - " 20 \n", - " 21\n", - " 1\n", - " 1\n", - " 1\n", - " 2398\n", - " 3969\n", - " 4357\n", - " 1616\n", - " 167\n", - " 2231\n", - " ...\n", - " 1\n", - " 0.00000\n", - " 0.00000\n", - " 0.00000\n", - " 3\n", - " 4.59820\n", - " 0\n", - " 2398\n", - " 21\n", - " 388\n", - " \n", - " \n", - " 21 \n", - " 22\n", - " 1\n", - " 1\n", - " 1\n", - " 1212\n", - " 1918\n", - " 1936\n", - " 929\n", - " 86\n", - " 1126\n", - " ...\n", - " 0\n", - " 0.00000\n", - " 0.00000\n", - " 0.00000\n", - " 3\n", - " 4.77502\n", - " 0\n", - " 1212\n", - " 22\n", - " 18\n", - " \n", - " \n", - " 22 \n", - " 23\n", - " 1\n", - " 1\n", - " 1\n", - " 470\n", - " 743\n", - " 749\n", - " 360\n", - " 34\n", - " 436\n", - " ...\n", - " 1\n", - " 0.00000\n", - " 0.00000\n", - " 0.00000\n", - " 1\n", - " 4.81119\n", - " 0\n", - " 470\n", - " 23\n", - " 6\n", - " \n", - " \n", - " 23 \n", - " 24\n", - " 1\n", - " 1\n", - " 1\n", - " 618\n", - " 987\n", - " 994\n", - " 274\n", - " 0\n", - " 618\n", - " ...\n", - " 0\n", - " 0.00000\n", - " 0.00000\n", - " 0.00000\n", - " 1\n", - " 5.05426\n", - " 0\n", - " 618\n", - " 24\n", - " 7\n", - " \n", - " \n", - " 24 \n", - " 25\n", - " 1\n", - " 1\n", - " 1\n", - " 1517\n", - " 3308\n", - " 3314\n", - " 854\n", - " 117\n", - " 1400\n", - " ...\n", - " 0\n", - " 0.00000\n", - " 0.00000\n", - " 0.00000\n", - " 1\n", - " 4.58840\n", - " 0\n", - " 1517\n", - " 25\n", - " 6\n", - " \n", - " \n", - " 25 \n", - " 26\n", - " 1\n", - " 1\n", - " 1\n", - " 695\n", - " 1487\n", - " 1500\n", - " 533\n", - " 7\n", - " 688\n", - " ...\n", - " 0\n", - " 0.00000\n", - " 0.00000\n", - " 0.00000\n", - " 1\n", - " 5.08988\n", - " 0\n", - " 695\n", - " 26\n", - " 13\n", - " \n", - " \n", - " 26 \n", - " 27\n", - " 1\n", - " 1\n", - " 1\n", - " 1527\n", - " 3142\n", - " 3142\n", - " 1215\n", - " 64\n", - " 1463\n", - " ...\n", - " 0\n", - " 0.00000\n", - " 0.00000\n", - " 0.00000\n", - " 1\n", - " 4.02670\n", - " 0\n", - " 1527\n", - " 27\n", - " 0\n", - " \n", - " \n", - " 27 \n", - " 28\n", - " 1\n", - " 1\n", - " 1\n", - " 1858\n", - " 3284\n", - " 3286\n", - " 1785\n", - " 0\n", - " 1858\n", - " ...\n", - " 0\n", - " 0.00000\n", - " 0.00000\n", - " 0.00000\n", - " 1\n", - " 4.44760\n", - " 0\n", - " 1858\n", - " 28\n", - " 2\n", - " \n", - " \n", - " 28 \n", - " 29\n", - " 1\n", - " 1\n", - " 1\n", - " 3095\n", - " 4677\n", - " 5006\n", - " 2613\n", + " 2259.750000\n", + " 1090.750000\n", + " 71.000000\n", + " 5.492696\n", + " 6.693238\n", + " 2.337577\n", + " NaN\n", + " \n", + " \n", + " max\n", + " 34.000000\n", + " 34.000000\n", + " 9.000000\n", + " 12542.000000\n", + " 39671.000000\n", + " 40020.000000\n", + " 16799.000000\n", + " 12413.000000\n", + " 4920.000000\n", + " 3754.000000\n", + " ...\n", + " 3.000000\n", + " 7.310200\n", " 0\n", - " 3095\n", - " ...\n", - " 0\n", - " 0.00000\n", - " 0.00000\n", - " 0.00000\n", - " 1\n", - " 4.67778\n", - " 0\n", - " 3095\n", - " 29\n", - " 329\n", - " \n", - " \n", - " 29 \n", - " 30\n", - " 1\n", - " 1\n", - " 1\n", - " 4181\n", - " 7024\n", - " 7553\n", - " 3561\n", - " 26\n", - " 4155\n", - " ...\n", - " 1\n", - " 0.00000\n", - " 0.00000\n", - " 0.00000\n", - " 1\n", - " 4.09015\n", - " 0\n", - " 4181\n", - " 30\n", - " 529\n", + " 12542.000000\n", + " 1454.000000\n", + " 7810.000000\n", + " 877.564767\n", + " 90.891304\n", + " 46.360371\n", + " NaN\n", " \n", - " \n", + " \n", + "\n", + "

8 rows \u00d7 45 columns

\n", + "" + ], + "metadata": {}, + "output_type": "pyout", + "prompt_number": 2, + "text": [ + " DISTRICT SD county_id total_households HHPOP \\\n", + "count 1454.000000 1454.000000 1454.000000 1454.000000 1454.000000 \n", + "mean 14.908528 14.908528 3.835626 1793.688446 4816.408528 \n", + "std 8.701078 8.701078 2.040153 961.021405 2686.029808 \n", + "min 1.000000 1.000000 1.000000 0.000000 0.000000 \n", + "25% 8.000000 8.000000 3.000000 1200.250000 3288.250000 \n", + "50% 15.000000 15.000000 4.000000 1681.500000 4504.500000 \n", + "75% 20.750000 20.750000 5.000000 2259.750000 6033.750000 \n", + "max 34.000000 34.000000 9.000000 12542.000000 39671.000000 \n", + "\n", + " TOTPOP EMPRES SFDU MFDU HHINCQ1 \\\n", + "count 1454.000000 1454.000000 1454.000000 1454.000000 1454.000000 \n", + "mean 4917.978680 2168.684319 1122.798487 670.889959 508.134801 \n", + "std 2690.352928 1211.109335 854.895353 717.261660 378.753528 \n", + "min 0.000000 0.000000 0.000000 0.000000 0.000000 \n", + "25% 3384.500000 1460.500000 602.000000 144.500000 257.000000 \n", + "50% 4577.000000 2016.000000 1034.000000 460.000000 434.000000 \n", + "75% 6098.500000 2735.500000 1496.000000 907.750000 674.750000 \n", + "max 40020.000000 16799.000000 12413.000000 4920.000000 3754.000000 \n", + "\n", + " ... TOPOLOGY TERMINAL ZERO hhlds sftaz \\\n", + "count ... 1454.000000 1454.000000 1454 1454.000000 1454.000000 \n", + "mean ... 2.063274 1.630505 0 1793.688446 727.500000 \n", + "std ... 0.926842 0.879441 0 961.021405 419.877958 \n", + "min ... 1.000000 0.904320 0 0.000000 1.000000 \n", + "25% ... 1.000000 1.167372 0 1200.250000 364.250000 \n", + "50% ... 2.000000 1.323075 0 1681.500000 727.500000 \n", + "75% ... 3.000000 1.632443 0 2259.750000 1090.750000 \n", + "max ... 3.000000 7.310200 0 12542.000000 1454.000000 \n", + "\n", + " gqpop employment_density household_density density_index \\\n", + "count 1454.000000 1454.000000 1454.000000 1453.000000 \n", + "mean 101.570151 9.596395 6.008186 2.279554 \n", + "std 393.886676 45.067313 8.565908 3.945717 \n", + "min -1.000000 0.000000 0.000000 0.000000 \n", + "25% 5.000000 0.877829 1.910701 0.550232 \n", + "50% 18.000000 2.158701 3.939122 1.289224 \n", + "75% 71.000000 5.492696 6.693238 2.337577 \n", + "max 7810.000000 877.564767 90.891304 46.360371 \n", + "\n", + " county_name \n", + "count 0 \n", + "mean NaN \n", + "std NaN \n", + "min NaN \n", + "25% NaN \n", + "50% NaN \n", + "75% NaN \n", + "max NaN \n", + "\n", + "[8 rows x 45 columns]" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "sim.get_table(\"households\").to_frame().describe()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "html": [ + "
\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", + " \n", + " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", "
TAZSERIALNOPUMA5incomePERSONSHHTUNITTYPENOCBLDGSZTENURE..................................................................
1424 1425 33 33 9 2122 5146 5625 2221 1615 507... 4 0.00000 0.00000 0.00000 1 1.22266 0 2122 1425 479
1425 1426 33 33 9 2220 5327 5327 2057 2210 10... 4 0.00000 0.00000 0.00000 1 1.01019 0 2220 1426 0
1426 1427 33 33 9 2335 5109 5849 2430 1582 753... 4 949.12695 649.44434 459.57358 1 1.19565 0 2335 1427 740
1427 1428 33 33 9 2966 11923 12026 3639 707 2259... 3 0.00000 0.00000 0.00000 2 2.41621 0 2966 1428 103
1428 1429 33 33 9 1836 4306 4315 1945 1230 606... 4 0.00000 0.00000 0.00000 1 1.33576 0 1836 1429 9
1429 1430 33 33 9 2645 5456 5852 2988 999 1646... 3 0.00000 0.00000 0.00000 1 1.98616 0 2645 1430 396
1430 1431 33 33 9 3560 7788 7808 3666 2015 1545... 4 401.55109 0.00000 0.00000 1 1.19191 0 3560 1431 20
1431 1432 33 33 9 2051 4501 4526 2052 1336 715... 4 0.00000 108.49641 354.17001 1 1.26906 0 2051 1432 25
1432 1433 33 33 9 1308 3057 3070 1470 1045 263... 4 1062.81934 0.00000 0.00000 1 1.18111 0 1308 1433 13
1433 1434 33 33 9 2305 5127 5134 2427 1866 439... 4 0.00000 0.00000 0.00000 1 1.17519 0 2305 1434 7
1434 1435 33 33 9 798 2355 2407 651 776 22... 5 333.76257 0.00000 0.00000 1 0.99539 0 798 1435 52
1435 1436 34 34 9 1874 4596 4610 2174 1536 338... 4 789.55035 1235.34143 5376.92627 1 0.98217 0 1874 1436 14
1436 1437 34 34 9 3134 6527 6649 8748 1481 1653... 4 0.00000 0.00000 0.00000 1 1.28406 0 3134 1437 122
1437 1438 34 34 9 2417 5601 5601 4028 1491 926... 4 0.00000 0.00000 0.00000 1 1.46413 0 2417 1438 0
1438 1439 34 34 9 0 0 4855 0 0 0... 4 0.00000 0.00000 0.00000 3 7.31020 0 0 1439 4855
1439 1440 34 34 9 2827 6017 6026 9970 1742 1085... 4 1439.34253 0.00000 0.00000 1 1.13516 0 2827 1440 9
1440 1441 34 34 9 2197 5175 5174 1942 1579 618... 4 0.00000 0.00000 0.00000 1 1.33296 0 2197 1441 -1
1441 1442 34 34 9 2352 5808 5807 2055 2072 280... 4 0.00000 0.00000 0.00000 1 1.18622 0 2352 1442 -1
1442 1443 34 34 9 2052 4178 4249 1443 1018 1034... 4 973.11682 0.00000 0.00000 1 1.29862 0 2052 1443 71
1443 1444 34 34 9 1912 4016 4261 2021 843 1069... 4 0.00000 255.74797 0.00000 1 1.21144 0 1912 1444 245
1444 1445 34 34 9 2259 5441 5441 2146 1449 810... 4 0.00000 0.00000 0.00000 1 1.06519 0 2259 1445 0
1445 1446 34 34 9 2458 5588 5626 2114 1553 905... 4 0.00000 0.00000 0.00000 1 1.07095 0 2458 1446 38
1446 1447 34 34 9 929 2074 2073 697 818 111... 4 0.00000 0.00000 0.00000 1 1.15845 0 929 1447 -1
1447 1448 34 34 9 4457 7631 7644 4865 2107 2350... 4 0.00000 0.00000 0.00000 1 1.36052 0 4457 1448 13
1448 1449 34 34 9 1007 2359 2360 1108 251 756... 4 0.00000 0.00000 0.00000 1 1.15822 0 1007 1449 1
1449 1450 34 34 9 2752 6492 6506 3260 2366 386... 4 0.00000 0.00000 0.00000 1 1.14586 0 2752 1450 14
1450 1451 34 34 9 1926 4582 4581 2064 1772 154... 4 0.00000 0.00000 0.00000 1 1.18198 0 1926 1451 -1
1451 1452 34 34 9 1989 4574 4580 1750 1572 417... 4 0.00000 0.00000 0.00000 1 1.13975 0 1989 1452 6bucketBinoriginalPUMAhmultiunitnum_young_adultsdriversnum_childrennum_adolescentsincome_in_thousandsnum_young_childrennum_college_age
1452 1453 34 34 9 262 573 688 259 216 46... 5 0.00000 0.00000 0.00000 1 0.99757 0 262 1453 115
1453 1454 34 34 9 1069 2116 2311 924 986 83... 5 0.00000 0.00000 0.00000 1 0.97576 0 1069 1454 195count 2732722.000000 2732722.000000 2732722.000000 2732722.000000 2732722.000000 2732722.000000 2732722.000000 2732722.000000 2732722.000000 2732722.000000... 2732722.000000 2732722.000000 2732722.000000 2732722.000000 2732722.000000 2732722.000000 2732722.000000 2732722.000000 2732722.000000 2732722.000000
mean 751.134174 4923397.817272 2168.537679 77670.162133 2.581065 2.640939 0.076833 0.468948 3.528608 1.893538... 4.492757 2168.537679 0.401827 0.396906 2.062626 0.359349 0.059565 77.670162 0.159090 0.223251
std 430.938788 2857497.525312 516.128215 81405.085003 1.605801 2.065958 0.365144 0.917211 2.516513 1.010827... 2.871945 516.128215 0.490267 0.728451 1.117948 0.764597 0.254209 81.405085 0.462614 0.581043
min 1.000000 20.000000 1000.000000 -20000.000000 1.000000 0.000000 0.000000 0.000000 0.000000 0.000000... 0.000000 1000.000000 0.000000 0.000000 0.000000 0.000000 0.000000 -20.000000 0.000000 0.000000
25% 372.000000 2463830.000000 2104.000000 26500.000000 1.000000 1.000000 0.000000 0.000000 2.000000 1.000000... 2.000000 2104.000000 0.000000 0.000000 1.000000 0.000000 0.000000 26.500000 0.000000 0.000000
50% 762.000000 4901786.000000 2303.000000 58000.000000 2.000000 1.000000 0.000000 0.000000 2.000000 2.000000... 4.000000 2303.000000 0.000000 0.000000 2.000000 0.000000 0.000000 58.000000 0.000000 0.000000
75% 1144.000000 7361646.000000 2410.000000 100000.000000 4.000000 4.000000 0.000000 1.000000 5.000000 3.000000... 7.000000 2410.000000 1.000000 1.000000 2.000000 0.000000 0.000000 100.000000 0.000000 0.000000
max 1454.000000 9999899.000000 2714.000000 1968504.000000 25.000000 7.000000 2.000000 12.000000 10.000000 4.000000... 9.000000 2714.000000 1.000000 9.000000 25.000000 9.000000 5.000000 1968.504000 8.000000 24.000000
\n", - "

1454 rows \u00d7 42 columns

\n", + "

8 rows \u00d7 53 columns

\n", "
" ], "metadata": {}, "output_type": "pyout", - "prompt_number": 2, + "prompt_number": 3, "text": [ - " ZONE DISTRICT SD COUNTY TOTHH HHPOP TOTPOP EMPRES SFDU MFDU \\\n", - "0 1 1 1 1 43 69 77 29 1 42 \n", - "1 2 1 1 1 141 223 248 93 5 136 \n", - "2 3 1 1 1 256 406 452 170 8 248 \n", - "3 4 1 1 1 74 116 129 49 2 72 \n", - "4 5 1 1 1 496 784 874 328 16 480 \n", - "5 6 1 1 1 2194 3217 3833 1660 0 2194 \n", - "6 7 1 1 1 3657 5362 5807 2739 0 3657 \n", - "7 8 1 1 1 4261 6978 9192 2173 17 4244 \n", - "8 9 1 1 1 4952 8410 9050 3537 32 4920 \n", - "9 10 1 1 1 1643 2807 2904 1356 9 1634 \n", - "10 11 1 1 1 2656 4537 4693 2192 14 2642 \n", - "11 12 1 1 1 167 250 259 151 0 167 \n", - "12 13 1 1 1 163 247 256 149 0 163 \n", - "13 14 1 1 1 121 182 188 110 0 121 \n", - "14 15 1 1 1 767 1151 1196 696 0 767 \n", - "15 16 1 1 1 1319 2153 2275 1427 9 1310 \n", - "16 17 1 1 1 4248 6930 7324 4592 27 4221 \n", - "17 18 1 1 1 291 476 820 394 15 276 \n", - "18 19 1 1 1 1208 1972 3401 1633 63 1145 \n", - "19 20 1 1 1 2014 3332 3658 1357 140 1874 \n", - "20 21 1 1 1 2398 3969 4357 1616 167 2231 \n", - "21 22 1 1 1 1212 1918 1936 929 86 1126 \n", - "22 23 1 1 1 470 743 749 360 34 436 \n", - "23 24 1 1 1 618 987 994 274 0 618 \n", - "24 25 1 1 1 1517 3308 3314 854 117 1400 \n", - "25 26 1 1 1 695 1487 1500 533 7 688 \n", - "26 27 1 1 1 1527 3142 3142 1215 64 1463 \n", - "27 28 1 1 1 1858 3284 3286 1785 0 1858 \n", - "28 29 1 1 1 3095 4677 5006 2613 0 3095 \n", - "29 30 1 1 1 4181 7024 7553 3561 26 4155 \n", - "... ... ... .. ... ... ... ... ... ... ... \n", - "1424 1425 33 33 9 2122 5146 5625 2221 1615 507 \n", - "1425 1426 33 33 9 2220 5327 5327 2057 2210 10 \n", - "1426 1427 33 33 9 2335 5109 5849 2430 1582 753 \n", - "1427 1428 33 33 9 2966 11923 12026 3639 707 2259 \n", - "1428 1429 33 33 9 1836 4306 4315 1945 1230 606 \n", - "1429 1430 33 33 9 2645 5456 5852 2988 999 1646 \n", - "1430 1431 33 33 9 3560 7788 7808 3666 2015 1545 \n", - "1431 1432 33 33 9 2051 4501 4526 2052 1336 715 \n", - "1432 1433 33 33 9 1308 3057 3070 1470 1045 263 \n", - "1433 1434 33 33 9 2305 5127 5134 2427 1866 439 \n", - "1434 1435 33 33 9 798 2355 2407 651 776 22 \n", - "1435 1436 34 34 9 1874 4596 4610 2174 1536 338 \n", - "1436 1437 34 34 9 3134 6527 6649 8748 1481 1653 \n", - "1437 1438 34 34 9 2417 5601 5601 4028 1491 926 \n", - "1438 1439 34 34 9 0 0 4855 0 0 0 \n", - "1439 1440 34 34 9 2827 6017 6026 9970 1742 1085 \n", - "1440 1441 34 34 9 2197 5175 5174 1942 1579 618 \n", - "1441 1442 34 34 9 2352 5808 5807 2055 2072 280 \n", - "1442 1443 34 34 9 2052 4178 4249 1443 1018 1034 \n", - "1443 1444 34 34 9 1912 4016 4261 2021 843 1069 \n", - "1444 1445 34 34 9 2259 5441 5441 2146 1449 810 \n", - "1445 1446 34 34 9 2458 5588 5626 2114 1553 905 \n", - "1446 1447 34 34 9 929 2074 2073 697 818 111 \n", - "1447 1448 34 34 9 4457 7631 7644 4865 2107 2350 \n", - "1448 1449 34 34 9 1007 2359 2360 1108 251 756 \n", - "1449 1450 34 34 9 2752 6492 6506 3260 2366 386 \n", - "1450 1451 34 34 9 1926 4582 4581 2064 1772 154 \n", - "1451 1452 34 34 9 1989 4574 4580 1750 1572 417 \n", - "1452 1453 34 34 9 262 573 688 259 216 46 \n", - "1453 1454 34 34 9 1069 2116 2311 924 986 83 \n", + " TAZ SERIALNO PUMA5 income \\\n", + "count 2732722.000000 2732722.000000 2732722.000000 2732722.000000 \n", + "mean 751.134174 4923397.817272 2168.537679 77670.162133 \n", + "std 430.938788 2857497.525312 516.128215 81405.085003 \n", + "min 1.000000 20.000000 1000.000000 -20000.000000 \n", + "25% 372.000000 2463830.000000 2104.000000 26500.000000 \n", + "50% 762.000000 4901786.000000 2303.000000 58000.000000 \n", + "75% 1144.000000 7361646.000000 2410.000000 100000.000000 \n", + "max 1454.000000 9999899.000000 2714.000000 1968504.000000 \n", + "\n", + " PERSONS HHT UNITTYPE NOC \\\n", + "count 2732722.000000 2732722.000000 2732722.000000 2732722.000000 \n", + "mean 2.581065 2.640939 0.076833 0.468948 \n", + "std 1.605801 2.065958 0.365144 0.917211 \n", + "min 1.000000 0.000000 0.000000 0.000000 \n", + "25% 1.000000 1.000000 0.000000 0.000000 \n", + "50% 2.000000 1.000000 0.000000 0.000000 \n", + "75% 4.000000 4.000000 0.000000 1.000000 \n", + "max 25.000000 7.000000 2.000000 12.000000 \n", + "\n", + " BLDGSZ TENURE ... bucketBin \\\n", + "count 2732722.000000 2732722.000000 ... 2732722.000000 \n", + "mean 3.528608 1.893538 ... 4.492757 \n", + "std 2.516513 1.010827 ... 2.871945 \n", + "min 0.000000 0.000000 ... 0.000000 \n", + "25% 2.000000 1.000000 ... 2.000000 \n", + "50% 2.000000 2.000000 ... 4.000000 \n", + "75% 5.000000 3.000000 ... 7.000000 \n", + "max 10.000000 4.000000 ... 9.000000 \n", "\n", - " ... AREATYPE HSENROLL COLLFTE COLLPTE TOPOLOGY TERMINAL \\\n", - "0 ... 0 0.00000 0.00000 0.00000 3 5.45336 \n", - "1 ... 0 0.00000 0.00000 0.00000 1 5.44111 \n", - "2 ... 0 0.00000 0.00000 0.00000 1 5.41257 \n", - "3 ... 0 0.00000 0.00000 0.00000 2 5.45635 \n", - "4 ... 0 0.00000 62.68835 0.00000 1 5.48443 \n", - "5 ... 0 0.00000 0.00000 0.00000 1 4.66107 \n", - "6 ... 0 0.00000 0.00000 0.00000 1 4.79331 \n", - "7 ... 0 0.00000 0.00000 0.00000 2 4.34911 \n", - "8 ... 0 23.39647 1768.71545 17.90704 2 4.58932 \n", - "9 ... 0 0.00000 600.01837 0.00000 3 4.50066 \n", - "10 ... 0 0.00000 0.00000 0.00000 3 4.54921 \n", - "11 ... 0 0.00000 2983.98755 2065.14697 3 5.12652 \n", - "12 ... 0 302.97360 1493.77795 3323.39771 3 5.14603 \n", - "13 ... 0 0.00000 739.72437 218.51707 3 5.15788 \n", - "14 ... 0 0.00000 0.00000 0.00000 3 5.11058 \n", - "15 ... 0 0.00000 0.00000 0.00000 2 5.07109 \n", - "16 ... 1 0.00000 0.00000 0.00000 1 5.12843 \n", - "17 ... 1 0.00000 0.00000 0.00000 3 4.44244 \n", - "18 ... 1 0.00000 0.00000 0.00000 3 4.44473 \n", - "19 ... 1 0.00000 0.00000 0.00000 3 4.63788 \n", - "20 ... 1 0.00000 0.00000 0.00000 3 4.59820 \n", - "21 ... 0 0.00000 0.00000 0.00000 3 4.77502 \n", - "22 ... 1 0.00000 0.00000 0.00000 1 4.81119 \n", - "23 ... 0 0.00000 0.00000 0.00000 1 5.05426 \n", - "24 ... 0 0.00000 0.00000 0.00000 1 4.58840 \n", - "25 ... 0 0.00000 0.00000 0.00000 1 5.08988 \n", - "26 ... 0 0.00000 0.00000 0.00000 1 4.02670 \n", - "27 ... 0 0.00000 0.00000 0.00000 1 4.44760 \n", - "28 ... 0 0.00000 0.00000 0.00000 1 4.67778 \n", - "29 ... 1 0.00000 0.00000 0.00000 1 4.09015 \n", - "... ... ... ... ... ... ... ... \n", - "1424 ... 4 0.00000 0.00000 0.00000 1 1.22266 \n", - "1425 ... 4 0.00000 0.00000 0.00000 1 1.01019 \n", - "1426 ... 4 949.12695 649.44434 459.57358 1 1.19565 \n", - "1427 ... 3 0.00000 0.00000 0.00000 2 2.41621 \n", - "1428 ... 4 0.00000 0.00000 0.00000 1 1.33576 \n", - "1429 ... 3 0.00000 0.00000 0.00000 1 1.98616 \n", - "1430 ... 4 401.55109 0.00000 0.00000 1 1.19191 \n", - "1431 ... 4 0.00000 108.49641 354.17001 1 1.26906 \n", - "1432 ... 4 1062.81934 0.00000 0.00000 1 1.18111 \n", - "1433 ... 4 0.00000 0.00000 0.00000 1 1.17519 \n", - "1434 ... 5 333.76257 0.00000 0.00000 1 0.99539 \n", - "1435 ... 4 789.55035 1235.34143 5376.92627 1 0.98217 \n", - "1436 ... 4 0.00000 0.00000 0.00000 1 1.28406 \n", - "1437 ... 4 0.00000 0.00000 0.00000 1 1.46413 \n", - "1438 ... 4 0.00000 0.00000 0.00000 3 7.31020 \n", - "1439 ... 4 1439.34253 0.00000 0.00000 1 1.13516 \n", - "1440 ... 4 0.00000 0.00000 0.00000 1 1.33296 \n", - "1441 ... 4 0.00000 0.00000 0.00000 1 1.18622 \n", - "1442 ... 4 973.11682 0.00000 0.00000 1 1.29862 \n", - "1443 ... 4 0.00000 255.74797 0.00000 1 1.21144 \n", - "1444 ... 4 0.00000 0.00000 0.00000 1 1.06519 \n", - "1445 ... 4 0.00000 0.00000 0.00000 1 1.07095 \n", - "1446 ... 4 0.00000 0.00000 0.00000 1 1.15845 \n", - "1447 ... 4 0.00000 0.00000 0.00000 1 1.36052 \n", - "1448 ... 4 0.00000 0.00000 0.00000 1 1.15822 \n", - "1449 ... 4 0.00000 0.00000 0.00000 1 1.14586 \n", - "1450 ... 4 0.00000 0.00000 0.00000 1 1.18198 \n", - "1451 ... 4 0.00000 0.00000 0.00000 1 1.13975 \n", - "1452 ... 5 0.00000 0.00000 0.00000 1 0.99757 \n", - "1453 ... 5 0.00000 0.00000 0.00000 1 0.97576 \n", + " originalPUMA hmultiunit num_young_adults drivers \\\n", + "count 2732722.000000 2732722.000000 2732722.000000 2732722.000000 \n", + "mean 2168.537679 0.401827 0.396906 2.062626 \n", + "std 516.128215 0.490267 0.728451 1.117948 \n", + "min 1000.000000 0.000000 0.000000 0.000000 \n", + "25% 2104.000000 0.000000 0.000000 1.000000 \n", + "50% 2303.000000 0.000000 0.000000 2.000000 \n", + "75% 2410.000000 1.000000 1.000000 2.000000 \n", + "max 2714.000000 1.000000 9.000000 25.000000 \n", "\n", - " ZERO hhlds sftaz gqpop \n", - "0 0 43 1 8 \n", - "1 0 141 2 25 \n", - "2 0 256 3 46 \n", - "3 0 74 4 13 \n", - "4 0 496 5 90 \n", - "5 0 2194 6 616 \n", - "6 0 3657 7 445 \n", - "7 0 4261 8 2214 \n", - "8 0 4952 9 640 \n", - "9 0 1643 10 97 \n", - "10 0 2656 11 156 \n", - "11 0 167 12 9 \n", - "12 0 163 13 9 \n", - "13 0 121 14 6 \n", - "14 0 767 15 45 \n", - "15 0 1319 16 122 \n", - "16 0 4248 17 394 \n", - "17 0 291 18 344 \n", - "18 0 1208 19 1429 \n", - "19 0 2014 20 326 \n", - "20 0 2398 21 388 \n", - "21 0 1212 22 18 \n", - "22 0 470 23 6 \n", - "23 0 618 24 7 \n", - "24 0 1517 25 6 \n", - "25 0 695 26 13 \n", - "26 0 1527 27 0 \n", - "27 0 1858 28 2 \n", - "28 0 3095 29 329 \n", - "29 0 4181 30 529 \n", - "... ... ... ... ... \n", - "1424 0 2122 1425 479 \n", - "1425 0 2220 1426 0 \n", - "1426 0 2335 1427 740 \n", - "1427 0 2966 1428 103 \n", - "1428 0 1836 1429 9 \n", - "1429 0 2645 1430 396 \n", - "1430 0 3560 1431 20 \n", - "1431 0 2051 1432 25 \n", - "1432 0 1308 1433 13 \n", - "1433 0 2305 1434 7 \n", - "1434 0 798 1435 52 \n", - "1435 0 1874 1436 14 \n", - "1436 0 3134 1437 122 \n", - "1437 0 2417 1438 0 \n", - "1438 0 0 1439 4855 \n", - "1439 0 2827 1440 9 \n", - "1440 0 2197 1441 -1 \n", - "1441 0 2352 1442 -1 \n", - "1442 0 2052 1443 71 \n", - "1443 0 1912 1444 245 \n", - "1444 0 2259 1445 0 \n", - "1445 0 2458 1446 38 \n", - "1446 0 929 1447 -1 \n", - "1447 0 4457 1448 13 \n", - "1448 0 1007 1449 1 \n", - "1449 0 2752 1450 14 \n", - "1450 0 1926 1451 -1 \n", - "1451 0 1989 1452 6 \n", - "1452 0 262 1453 115 \n", - "1453 0 1069 1454 195 \n", + " num_children num_adolescents income_in_thousands \\\n", + "count 2732722.000000 2732722.000000 2732722.000000 \n", + "mean 0.359349 0.059565 77.670162 \n", + "std 0.764597 0.254209 81.405085 \n", + "min 0.000000 0.000000 -20.000000 \n", + "25% 0.000000 0.000000 26.500000 \n", + "50% 0.000000 0.000000 58.000000 \n", + "75% 0.000000 0.000000 100.000000 \n", + "max 9.000000 5.000000 1968.504000 \n", "\n", - "[1454 rows x 42 columns]" + " num_young_children num_college_age \n", + "count 2732722.000000 2732722.000000 \n", + "mean 0.159090 0.223251 \n", + "std 0.462614 0.581043 \n", + "min 0.000000 0.000000 \n", + "25% 0.000000 0.000000 \n", + "50% 0.000000 0.000000 \n", + "75% 0.000000 0.000000 \n", + "max 8.000000 24.000000 \n", + "\n", + "[8 rows x 53 columns]" ] } ], - "prompt_number": 2 + "prompt_number": 3 }, { "cell_type": "code", @@ -1738,7 +634,8 @@ "input": [], "language": "python", "metadata": {}, - "outputs": [] + "outputs": [], + "prompt_number": 3 } ], "metadata": {} From c11328066e65c194866108fd382028fecac1e2cc Mon Sep 17 00:00:00 2001 From: Fletcher Foti Date: Tue, 9 Dec 2014 13:49:52 -0800 Subject: [PATCH 3/8] auto ownership is simulating right now only using the first 8 rows of the spec, but we're successfully simulating choices This works by taking the UEC spreadsheet and keeping the coefficients almost formatted as-is. I say almost because the filters and alt names had to be tweaked a bit to match Pandas conventions. This commit is working but brings up a few questions that I will post as issues on github in a bit. This is clearly not a final implementation but something to elicit early feedback. --- .gitignore | 2 + example/configs/auto_ownership_coeffs.csv | 1 + example/data/.gitignore | 1 - example/data/README.md | 1 + example/models.py | 70 +++++++++++++++ .../{estimation.ipynb => simulation.ipynb} | 90 ++++++++++++++++++- 6 files changed, 160 insertions(+), 5 deletions(-) create mode 100644 example/configs/auto_ownership_coeffs.csv delete mode 100644 example/data/.gitignore create mode 100644 example/data/README.md create mode 100644 example/models.py rename notebooks/{estimation.ipynb => simulation.ipynb} (89%) diff --git a/.gitignore b/.gitignore index 6cc0db7827..5547e6bed0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +example/data/* + .ipynb_checkpoints # Byte-compiled / optimized / DLL files diff --git a/example/configs/auto_ownership_coeffs.csv b/example/configs/auto_ownership_coeffs.csv new file mode 100644 index 0000000000..e32214451c --- /dev/null +++ b/example/configs/auto_ownership_coeffs.csv @@ -0,0 +1 @@ +Description,Expression,cars0,cars1,cars2,cars3,cars4 2 Adults (age 16+),drivers==2,,0.0000,3.0773,3.1962,2.6616 3 Adults (age 16+),drivers==3,,0.0000,3.5401,5.5131,5.2080 4+ Adults (age 16+),"if(drivers>3,1,0)",,2.0107,6.3662,8.5148,9.5807 Persons age 16-17,numPersAge16to17,,0.0000,-0.8810,-1.7313,-1.7313 Persons age 18-24,numPersAge18to24,,-0.4087,-1.0095,-1.0107,-1.0107 Persons age 35-34,numPersAge25to34,,0.0000,-0.4849,-0.8596,-0.8596 Presence of children age 0-4,"if(numPersAge0to4>0,1,0)",,0.3669,0.7627,0.7627,0.7627 Presence of children age 5-17,"if((numPersAge5to15+numPersAge16to17)>0,1,0)",,0.0158,0.2936,0.4769,0.4769 "Number of workers, capped at 3","min(workers,3)",,0.0000,0.2936,0.6389,0.8797 "Piecewise Linear household income, $0-30k","if(hhinc1000s<30,hhinc1000s,30)",,0.0383,0.0540,0.0559,0.0619 "Piecewise Linear household income, $30-75k","if(hhinc1000s<75,hhinc1000s-30,45)",,0.0000,0.0083,0.0110,0.0147 "Piecewise Linear household income, $75k+, capped at $125k","if(hhinc1000s<125,hhinc1000s-75,50)",,0.0000,0.0083,0.0110,0.0147 "Density index up to 10, if 0 workers","if(densityIndex<=10,densityIndex,10)",,0.0000,-0.2028,-0.3654,-0.3654 "Density index in excess of 10, if 0 workers","if(densityIndex>10,(densityIndex-10),0)",,-0.0152,-0.1106,-0.1766,-0.1766 "Density index up to 10, if 1+ workers","if(densityIndex<=10,densityIndex,10)",,0.0000,-0.2028,-0.3654,-0.3654 "Density index in excess of 10, if 1+ workers","if(densityIndex>10,(densityIndex-10),0)",,-0.0152,-0.1106,-0.1766,-0.1766 "Retail accessibility (0.66*PK + 0.34*OP) by auto, if 0 workers",0.66*AUTOPEAKRETAIL+0.34*AUTOOFFPEAKRETAIL,,0.0626,0.0626,0.0626,0.0626 "Retail accessibility (0.66*PK + 0.34*OP) by auto, if 1+ workers",0.66*AUTOPEAKRETAIL+0.34*AUTOOFFPEAKRETAIL,,0.1646,0.1646,0.1646,0.1646 "Retail accessibility (0.66*PK + 0.34*OP) by transit, if 0 workers",0.66*TRANSITPEAKRETAIL+0.34*TRANSITOFFPEAKRETAIL,,-0.3053,-0.3053,-0.3053,-0.3053 "Retail accessibility (0.66*PK + 0.34*OP) by transit, if 1+ workers",0.66*TRANSITPEAKRETAIL+0.34*TRANSITOFFPEAKRETAIL,,-0.5117,-0.5117,-0.5117,-0.5117 "Retail accessibility by non-motorized, if 0 workers",NONMOTORIZEDRETAIL,,-0.0300,-0.0300,-0.0300,-0.0300 "Retail accessibility by non-motorized, if 1+ workers",NONMOTORIZEDRETAIL,,-0.0300,-0.0300,-0.0300,-0.0300 "Auto time savings per worker (over walk or transit, max 120) to work",workTourAutoTimeSavings/workers,,0.4707,0.6142,0.5705,0.7693 Constants,1,,1.1865,-1.0846,-3.2502,-5.3130 San Francisco county,"IF(COUNTY==cSanFrancisco,1,0)",,0.4259,0.4683,0.1458,0.1458 Solano county,"IF(COUNTY==cSolano,1,0)",,-0.5660,-0.4429,-0.2372,-0.2372 Napa county,"IF(COUNTY==cNapa,1,0)",,-0.5660,-0.4429,-0.2372,-0.2372 Sonoma county,"IF(COUNTY==cSonoma,1,0)",,-0.5660,-0.4429,-0.2372,-0.2372 Marin county,"IF(COUNTY==cMarin,1,0)",,-0.2434,0.0000,0.0000,0.0000 \ No newline at end of file diff --git a/example/data/.gitignore b/example/data/.gitignore deleted file mode 100644 index 72e8ffc0db..0000000000 --- a/example/data/.gitignore +++ /dev/null @@ -1 +0,0 @@ -* diff --git a/example/data/README.md b/example/data/README.md new file mode 100644 index 0000000000..b48eb98b28 --- /dev/null +++ b/example/data/README.md @@ -0,0 +1 @@ +Keep data here diff --git a/example/models.py b/example/models.py new file mode 100644 index 0000000000..f3033881c3 --- /dev/null +++ b/example/models.py @@ -0,0 +1,70 @@ +import urbansim.sim.simulation as sim +from urbansim.utils import misc +from urbansim.urbanchoice import interaction, mnl +import pandas as pd +import numpy as np +import os + + +def read_model_spec(fname, + description_name="Description", + expression_name="Expression"): + """ + Read in the excel file and reformat for machines + """ + cfg = pd.read_csv(fname) + # don't need description and set the expression to the index + cfg = cfg.drop(description_name, axis=1).set_index(expression_name).stack() + # expressions are index names times column names + cfg.index = ["({}) * {}".format(*k) for k in cfg.index] + return cfg + + +def identity_matrix(alt_names): + return pd.DataFrame(np.identity(len(alt_names)), + columns=alt_names, + index=alt_names) + + +def simple_simulate(choosers, alternatives, spec): + exprs = spec.index + coeffs = spec.values + + # merge choosers and alternatives + _, merged, _ = interaction.mnl_interaction_dataset( + choosers, alternatives, len(alternatives)) + + # evaluate the expressions to build the final matrix + model_design=pd.concat([merged.eval(s) for s in exprs], axis=1) + print "Describe of design matrix:\n", model_design.describe() + + probabilities = mnl.mnl_simulate( + model_design.as_matrix(), + coeffs, + numalts=len(alternatives), returnprobs=True) + + def rand(x): return np.random.choice(alternatives.index, p=x) + choices = np.apply_along_axis(rand, 1, probabilities) + + return pd.Series(choices, index=choosers.index) + + +@sim.table() +def auto_alts(): + return identity_matrix(["cars%d"%i for i in range(5)]) + + +@sim.injectable() +def auto_ownership_spec(): + f = os.path.join(misc.configs_dir(), "auto_ownership_coeffs.csv") + return read_model_spec(f).head(8) + + +@sim.model() +def auto_ownership_simulate(households, auto_alts, auto_ownership_spec): + print auto_ownership_spec + choosers = households.to_frame() + alternatives = auto_alts.to_frame() + choices = simple_simulate(choosers, alternatives, auto_ownership_spec) + + print "Choices\n", choices.describe() diff --git a/notebooks/estimation.ipynb b/notebooks/simulation.ipynb similarity index 89% rename from notebooks/estimation.ipynb rename to notebooks/simulation.ipynb index fc32eeccd0..60d3cdaba3 100644 --- a/notebooks/estimation.ipynb +++ b/notebooks/simulation.ipynb @@ -1,7 +1,7 @@ { "metadata": { "name": "", - "signature": "sha256:0af8ad519a9a50cb2b446b20f0d48d14f7731475e53b8217e74fe78fe3293413" + "signature": "sha256:3ac9ac5a8b1937899659190e4f52f35950bba5b8faa4e62eb6fbac3858178c25" }, "nbformat": 3, "nbformat_minor": 0, @@ -17,13 +17,96 @@ "if 'sim' not in globals():\n", " import os; os.chdir('../example')\n", "import urbansim.sim.simulation as sim\n", - "from activitysim.defaults import variables" + "from activitysim.defaults import variables\n", + "import models" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 1 }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "sim.run([\"auto_ownership_simulate\"])" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Running model 'auto_ownership_simulate'\n", + "(drivers==2) * cars1 0.0000\n", + "(drivers==2) * cars2 3.0773\n", + "(drivers==2) * cars3 3.1962\n", + "(drivers==2) * cars4 2.6616\n", + "(drivers==3) * cars1 0.0000\n", + "(drivers==3) * cars2 3.5401\n", + "(drivers==3) * cars3 5.5131\n", + "(drivers==3) * cars4 5.2080\n", + "dtype: float64" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Describe of design matrix:\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " 0 1 2 3 \\\n", + "count 13663610.000000 13663610.000000 13663610.000000 13663610.000000 \n", + "mean 0.087207 0.087207 0.087207 0.087207 \n", + "std 0.282137 0.282137 0.282137 0.282137 \n", + "min 0.000000 0.000000 0.000000 0.000000 \n", + "25% 0.000000 0.000000 0.000000 0.000000 \n", + "50% 0.000000 0.000000 0.000000 0.000000 \n", + "75% 0.000000 0.000000 0.000000 0.000000 \n", + "max 1.000000 1.000000 1.000000 1.000000 \n", + "\n", + " 4 5 6 7 \n", + "count 13663610.000000 13663610.000000 13663610.000000 13663610.000000 \n", + "mean 0.027380 0.027380 0.027380 0.027380 \n", + "std 0.163188 0.163188 0.163188 0.163188 \n", + "min 0.000000 0.000000 0.000000 0.000000 \n", + "25% 0.000000 0.000000 0.000000 0.000000 \n", + "50% 0.000000 0.000000 0.000000 0.000000 \n", + "75% 0.000000 0.000000 0.000000 0.000000 \n", + "max 1.000000 1.000000 1.000000 1.000000 \n", + "Choices\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "count 2732722\n", + "unique 5\n", + "top cars3\n", + "freq 896983\n", + "dtype: object\n", + "Time to execute model 'auto_ownership_simulate': 204.31s" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Total time to execute: 204.31s\n" + ] + } + ], + "prompt_number": 2 + }, { "cell_type": "code", "collapsed": false, @@ -634,8 +717,7 @@ "input": [], "language": "python", "metadata": {}, - "outputs": [], - "prompt_number": 3 + "outputs": [] } ], "metadata": {} From 6692d0da58cc3b68dc0edf2fcbba76d0902d767c Mon Sep 17 00:00:00 2001 From: Fletcher Foti Date: Wed, 10 Dec 2014 10:34:11 -0800 Subject: [PATCH 4/8] performance improvements --- activitysim/defaults/datasources.py | 16 ++++++++-------- example/models.py | 10 ++++------ notebooks/simulation.ipynb | 17 +++++++++-------- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/activitysim/defaults/datasources.py b/activitysim/defaults/datasources.py index 55ea25f057..fc0d698d94 100644 --- a/activitysim/defaults/datasources.py +++ b/activitysim/defaults/datasources.py @@ -44,21 +44,21 @@ def scenario(settings): return settings["scenario"] -@sim.table("land_use", cache=True) -def land_use_data(store): +@sim.table(cache=True) +def land_use(store): return store["land_use/taz_data"] -@sim.table("accessibility", cache=True) -def land_use(store): +@sim.table(cache=True) +def accessibility(store): return store["skims/accessibility"] -@sim.table("households", cache=True) -def land_use(store): +@sim.table(cache=True) +def households(store): return store["households"] -@sim.table("persons", cache=True) -def land_use(store): +@sim.table(cache=True) +def persons(store): return store["persons"] diff --git a/example/models.py b/example/models.py index f3033881c3..19676f8bec 100644 --- a/example/models.py +++ b/example/models.py @@ -38,13 +38,11 @@ def simple_simulate(choosers, alternatives, spec): model_design=pd.concat([merged.eval(s) for s in exprs], axis=1) print "Describe of design matrix:\n", model_design.describe() - probabilities = mnl.mnl_simulate( + choices = mnl.mnl_simulate( model_design.as_matrix(), coeffs, - numalts=len(alternatives), returnprobs=True) - - def rand(x): return np.random.choice(alternatives.index, p=x) - choices = np.apply_along_axis(rand, 1, probabilities) + numalts=len(alternatives), + returnprobs=False) return pd.Series(choices, index=choosers.index) @@ -67,4 +65,4 @@ def auto_ownership_simulate(households, auto_alts, auto_ownership_spec): alternatives = auto_alts.to_frame() choices = simple_simulate(choosers, alternatives, auto_ownership_spec) - print "Choices\n", choices.describe() + print "Choices\n", choices.value_counts() diff --git a/notebooks/simulation.ipynb b/notebooks/simulation.ipynb index 60d3cdaba3..2ea0af381c 100644 --- a/notebooks/simulation.ipynb +++ b/notebooks/simulation.ipynb @@ -1,7 +1,7 @@ { "metadata": { "name": "", - "signature": "sha256:3ac9ac5a8b1937899659190e4f52f35950bba5b8faa4e62eb6fbac3858178c25" + "signature": "sha256:31c6a068d594150ba859a9c6b7d13ffe52bbb723e77bd5d05ca3001e30785dfd" }, "nbformat": 3, "nbformat_minor": 0, @@ -88,12 +88,13 @@ "output_type": "stream", "stream": "stdout", "text": [ - "count 2732722\n", - "unique 5\n", - "top cars3\n", - "freq 896983\n", - "dtype: object\n", - "Time to execute model 'auto_ownership_simulate': 204.31s" + "3 899448\n", + "2 674746\n", + "4 651817\n", + "1 254014\n", + "0 252697\n", + "dtype: int64\n", + "Time to execute model 'auto_ownership_simulate': 43.75s" ] }, { @@ -101,7 +102,7 @@ "stream": "stdout", "text": [ "\n", - "Total time to execute: 204.31s\n" + "Total time to execute: 43.75s\n" ] } ], From a8a9c7eaeddbfa5088a320f96de32d42c40dc020 Mon Sep 17 00:00:00 2001 From: Fletcher Foti Date: Wed, 10 Dec 2014 15:19:08 -0800 Subject: [PATCH 5/8] adding columns (now 88) to the auto ownership model the big change here is that a lot of the columns could not be expressed as DataFrame.eval calls and so I'm directly making Python "eval" calls if the expression starts with an "@". This is a proposal and not necessarily permanent functionality - something else to talk about. I like the way this works though as it puts quite a bit of power directly in the spreadsheet for the model specs, much the same way it is now. We have the option of never doing a DataFrame.eval call but these calls are a bit easier to express and are apparently much faster. This checkin also has the performance improvements on the choices and converts windows newlines to regular newlines so you can see the spec on github now --- activitysim/defaults/datasources.py | 3 + activitysim/defaults/variables.py | 3 +- example/configs/auto_ownership_coeffs.csv | 31 ++++- example/configs/settings.yaml | 2 +- example/models.py | 57 +++++++-- notebooks/simulation.ipynb | 140 ++++++++-------------- 6 files changed, 130 insertions(+), 106 deletions(-) diff --git a/activitysim/defaults/datasources.py b/activitysim/defaults/datasources.py index fc0d698d94..1b38bce91c 100644 --- a/activitysim/defaults/datasources.py +++ b/activitysim/defaults/datasources.py @@ -62,3 +62,6 @@ def households(store): @sim.table(cache=True) def persons(store): return store["persons"] + + +sim.broadcast('land_use', 'households', cast_index=True, onto_on='TAZ') diff --git a/activitysim/defaults/variables.py b/activitysim/defaults/variables.py index da3901842f..db85f06885 100644 --- a/activitysim/defaults/variables.py +++ b/activitysim/defaults/variables.py @@ -69,4 +69,5 @@ def density_index(land_use): @sim.column("land_use") def county_name(land_use, settings): assert "county_map" in settings - return land_use.county_id.map(settings["county_map"]) + inv_map = {v: k for k, v in settings["county_map"].items()} + return land_use.county_id.map(inv_map) diff --git a/example/configs/auto_ownership_coeffs.csv b/example/configs/auto_ownership_coeffs.csv index e32214451c..412e081bc6 100644 --- a/example/configs/auto_ownership_coeffs.csv +++ b/example/configs/auto_ownership_coeffs.csv @@ -1 +1,30 @@ -Description,Expression,cars0,cars1,cars2,cars3,cars4 2 Adults (age 16+),drivers==2,,0.0000,3.0773,3.1962,2.6616 3 Adults (age 16+),drivers==3,,0.0000,3.5401,5.5131,5.2080 4+ Adults (age 16+),"if(drivers>3,1,0)",,2.0107,6.3662,8.5148,9.5807 Persons age 16-17,numPersAge16to17,,0.0000,-0.8810,-1.7313,-1.7313 Persons age 18-24,numPersAge18to24,,-0.4087,-1.0095,-1.0107,-1.0107 Persons age 35-34,numPersAge25to34,,0.0000,-0.4849,-0.8596,-0.8596 Presence of children age 0-4,"if(numPersAge0to4>0,1,0)",,0.3669,0.7627,0.7627,0.7627 Presence of children age 5-17,"if((numPersAge5to15+numPersAge16to17)>0,1,0)",,0.0158,0.2936,0.4769,0.4769 "Number of workers, capped at 3","min(workers,3)",,0.0000,0.2936,0.6389,0.8797 "Piecewise Linear household income, $0-30k","if(hhinc1000s<30,hhinc1000s,30)",,0.0383,0.0540,0.0559,0.0619 "Piecewise Linear household income, $30-75k","if(hhinc1000s<75,hhinc1000s-30,45)",,0.0000,0.0083,0.0110,0.0147 "Piecewise Linear household income, $75k+, capped at $125k","if(hhinc1000s<125,hhinc1000s-75,50)",,0.0000,0.0083,0.0110,0.0147 "Density index up to 10, if 0 workers","if(densityIndex<=10,densityIndex,10)",,0.0000,-0.2028,-0.3654,-0.3654 "Density index in excess of 10, if 0 workers","if(densityIndex>10,(densityIndex-10),0)",,-0.0152,-0.1106,-0.1766,-0.1766 "Density index up to 10, if 1+ workers","if(densityIndex<=10,densityIndex,10)",,0.0000,-0.2028,-0.3654,-0.3654 "Density index in excess of 10, if 1+ workers","if(densityIndex>10,(densityIndex-10),0)",,-0.0152,-0.1106,-0.1766,-0.1766 "Retail accessibility (0.66*PK + 0.34*OP) by auto, if 0 workers",0.66*AUTOPEAKRETAIL+0.34*AUTOOFFPEAKRETAIL,,0.0626,0.0626,0.0626,0.0626 "Retail accessibility (0.66*PK + 0.34*OP) by auto, if 1+ workers",0.66*AUTOPEAKRETAIL+0.34*AUTOOFFPEAKRETAIL,,0.1646,0.1646,0.1646,0.1646 "Retail accessibility (0.66*PK + 0.34*OP) by transit, if 0 workers",0.66*TRANSITPEAKRETAIL+0.34*TRANSITOFFPEAKRETAIL,,-0.3053,-0.3053,-0.3053,-0.3053 "Retail accessibility (0.66*PK + 0.34*OP) by transit, if 1+ workers",0.66*TRANSITPEAKRETAIL+0.34*TRANSITOFFPEAKRETAIL,,-0.5117,-0.5117,-0.5117,-0.5117 "Retail accessibility by non-motorized, if 0 workers",NONMOTORIZEDRETAIL,,-0.0300,-0.0300,-0.0300,-0.0300 "Retail accessibility by non-motorized, if 1+ workers",NONMOTORIZEDRETAIL,,-0.0300,-0.0300,-0.0300,-0.0300 "Auto time savings per worker (over walk or transit, max 120) to work",workTourAutoTimeSavings/workers,,0.4707,0.6142,0.5705,0.7693 Constants,1,,1.1865,-1.0846,-3.2502,-5.3130 San Francisco county,"IF(COUNTY==cSanFrancisco,1,0)",,0.4259,0.4683,0.1458,0.1458 Solano county,"IF(COUNTY==cSolano,1,0)",,-0.5660,-0.4429,-0.2372,-0.2372 Napa county,"IF(COUNTY==cNapa,1,0)",,-0.5660,-0.4429,-0.2372,-0.2372 Sonoma county,"IF(COUNTY==cSonoma,1,0)",,-0.5660,-0.4429,-0.2372,-0.2372 Marin county,"IF(COUNTY==cMarin,1,0)",,-0.2434,0.0000,0.0000,0.0000 \ No newline at end of file +Description,Expression,cars0,cars1,cars2,cars3,cars4 +2 Adults (age 16+),drivers==2,,0,3.0773,3.1962,2.6616 +3 Adults (age 16+),drivers==3,,0,3.5401,5.5131,5.208 +4+ Adults (age 16+),drivers>3,,2.0107,6.3662,8.5148,9.5807 +Persons age 16-17,num_adolescents,,0,-0.881,-1.7313,-1.7313 +Persons age 18-24,num_college_age,,-0.4087,-1.0095,-1.0107,-1.0107 +Persons age 35-34,num_young_adults,,0,-0.4849,-0.8596,-0.8596 +Presence of children age 0-4,num_young_children>0,,0.3669,0.7627,0.7627,0.7627 +Presence of children age 5-17,(num_children+num_adolescents)>0,,0.0158,0.2936,0.4769,0.4769 +"Number of workers, capped at 3",@df.workers.clip(upper=3),,0,0.2936,0.6389,0.8797 +"Piecewise Linear household income, $0-30k","@df.income_in_thousands.clip(0, 30)",,0.0383,0.054,0.0559,0.0619 +"Piecewise Linear household income, $30-75k","@(df.income_in_thousands-30).clip(0, 45)",,0,0.0083,0.011,0.0147 +"Piecewise Linear household income, $75k+, capped at $125k","@(df.income_in_thousands-75).clip(0, 50)",,0,0.0083,0.011,0.0147 +"Density index up to 10, if 0 workers","@(df.workers==0)*df.density_index.clip(0, 10)",,0,-0.2028,-0.3654,-0.3654 +"Density index in excess of 10, if 0 workers",@(df.workers==0)*(df.density_index-10).clip(0),,-0.0152,-0.1106,-0.1766,-0.1766 +"Density index up to 10, if 1+ workers","@(df.workers>0)*df.density_index.clip(0, 10)",,0,-0.2028,-0.3654,-0.3654 +"Density index in excess of 10, if 1+ workers",@(df.workers>0)*(df.density_index-10).clip(0),,-0.0152,-0.1106,-0.1766,-0.1766 +Constants,@1,,1.1865,-1.0846,-3.2502,-5.313 +San Francisco county,county_name == 'San Francisco',,0.4259,0.4683,0.1458,0.1458 +Solano county,county_name == 'Solano',,-0.566,-0.4429,-0.2372,-0.2372 +Napa county,county_name == 'Napa',,-0.566,-0.4429,-0.2372,-0.2372 +Sonoma county,county_name == 'Sonoma',,-0.566,-0.4429,-0.2372,-0.2372 +Marin county,county_name == 'Marin',,-0.2434,0,0,0 +"Retail accessibility (0.66*PK + 0.34*OP) by auto, if 0 workers",0.66*AUTOPEAKRETAIL+0.34*AUTOOFFPEAKRETAIL,,0.0626,0.0626,0.0626,0.0626 +"Retail accessibility (0.66*PK + 0.34*OP) by auto, if 1+ workers",0.66*AUTOPEAKRETAIL+0.34*AUTOOFFPEAKRETAIL,,0.1646,0.1646,0.1646,0.1646 +"Retail accessibility (0.66*PK + 0.34*OP) by transit, if 0 workers",0.66*TRANSITPEAKRETAIL+0.34*TRANSITOFFPEAKRETAIL,,-0.3053,-0.3053,-0.3053,-0.3053 +"Retail accessibility (0.66*PK + 0.34*OP) by transit, if 1+ workers",0.66*TRANSITPEAKRETAIL+0.34*TRANSITOFFPEAKRETAIL,,-0.5117,-0.5117,-0.5117,-0.5117 +"Retail accessibility by non-motorized, if 0 workers",NONMOTORIZEDRETAIL,,-0.03,-0.03,-0.03,-0.03 +"Retail accessibility by non-motorized, if 1+ workers",NONMOTORIZEDRETAIL,,-0.03,-0.03,-0.03,-0.03 +"Auto time savings per worker (over walk or transit, max 120) to work",workTourAutoTimeSavings/workers,,0.4707,0.6142,0.5705,0.7693 \ No newline at end of file diff --git a/example/configs/settings.yaml b/example/configs/settings.yaml index e80d5134d8..b7d6254a25 100644 --- a/example/configs/settings.yaml +++ b/example/configs/settings.yaml @@ -1,7 +1,7 @@ store: mtc_asim.h5 county_map: - San Francico: 1 + San Francisco: 1 San Mateo: 2 Santa Clara: 3 Alameda: 4 diff --git a/example/models.py b/example/models.py index 19676f8bec..0ca207750d 100644 --- a/example/models.py +++ b/example/models.py @@ -6,6 +6,10 @@ import os +def random_rows(df, n): + return df.take(np.random.randint(0, len(df), n)) + + def read_model_spec(fname, description_name="Description", expression_name="Expression"): @@ -15,8 +19,6 @@ def read_model_spec(fname, cfg = pd.read_csv(fname) # don't need description and set the expression to the index cfg = cfg.drop(description_name, axis=1).set_index(expression_name).stack() - # expressions are index names times column names - cfg.index = ["({}) * {}".format(*k) for k in cfg.index] return cfg @@ -31,12 +33,35 @@ def simple_simulate(choosers, alternatives, spec): coeffs = spec.values # merge choosers and alternatives - _, merged, _ = interaction.mnl_interaction_dataset( + _, df, _ = interaction.mnl_interaction_dataset( choosers, alternatives, len(alternatives)) # evaluate the expressions to build the final matrix - model_design=pd.concat([merged.eval(s) for s in exprs], axis=1) - print "Describe of design matrix:\n", model_design.describe() + vars, names = [], [] + for expr in exprs: + if expr[0][0] == "@": + expr = "({}) * df.{}".format(expr[0][1:], expr[1]) + try: + s = eval(expr) + except Exception as e: + print "Failed with Python eval:\n%s" % expr + raise e + else: + expr = "({}) * {}".format(*expr) + try: + s = df.eval(expr) + except Exception as e: + print "Failed with DataFrame eval:\n%s" % expr + raise e + names.append(expr) + vars.append(s) + model_design=pd.concat(vars, axis=1) + model_design.columns = names + + df = random_rows(model_design, 100000).describe().transpose() + df = df[df["std"] == 0] + if len(df): + print "WARNING: Describe of columns with no variability:\n", df choices = mnl.mnl_simulate( model_design.as_matrix(), @@ -44,7 +69,7 @@ def simple_simulate(choosers, alternatives, spec): numalts=len(alternatives), returnprobs=False) - return pd.Series(choices, index=choosers.index) + return pd.Series(choices, index=choosers.index), model_design @sim.table() @@ -55,14 +80,22 @@ def auto_alts(): @sim.injectable() def auto_ownership_spec(): f = os.path.join(misc.configs_dir(), "auto_ownership_coeffs.csv") - return read_model_spec(f).head(8) + return read_model_spec(f).head(4*20) @sim.model() -def auto_ownership_simulate(households, auto_alts, auto_ownership_spec): - print auto_ownership_spec - choosers = households.to_frame() +def auto_ownership_simulate(households, + auto_alts, + auto_ownership_spec, + land_use): + + choosers = sim.merge_tables(households.name, tables=[households, land_use]) alternatives = auto_alts.to_frame() - choices = simple_simulate(choosers, alternatives, auto_ownership_spec) - print "Choices\n", choices.value_counts() + choices, model_design = \ + simple_simulate(choosers, alternatives, auto_ownership_spec) + + print "Choices:\n", choices.value_counts() + sim.add_column("households", "auto_ownership", choices) + + return model_design diff --git a/notebooks/simulation.ipynb b/notebooks/simulation.ipynb index 2ea0af381c..ffad308134 100644 --- a/notebooks/simulation.ipynb +++ b/notebooks/simulation.ipynb @@ -1,7 +1,7 @@ { "metadata": { "name": "", - "signature": "sha256:31c6a068d594150ba859a9c6b7d13ffe52bbb723e77bd5d05ca3001e30785dfd" + "signature": "sha256:9538d1e98425ccf99082cd66b6de30113546b74b1f622af89caa7806bc97181e" }, "nbformat": 3, "nbformat_minor": 0, @@ -39,62 +39,20 @@ "stream": "stdout", "text": [ "Running model 'auto_ownership_simulate'\n", - "(drivers==2) * cars1 0.0000\n", - "(drivers==2) * cars2 3.0773\n", - "(drivers==2) * cars3 3.1962\n", - "(drivers==2) * cars4 2.6616\n", - "(drivers==3) * cars1 0.0000\n", - "(drivers==3) * cars2 3.5401\n", - "(drivers==3) * cars3 5.5131\n", - "(drivers==3) * cars4 5.2080\n", - "dtype: float64" + "Choices:\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ - "\n", - "Describe of design matrix:\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - " 0 1 2 3 \\\n", - "count 13663610.000000 13663610.000000 13663610.000000 13663610.000000 \n", - "mean 0.087207 0.087207 0.087207 0.087207 \n", - "std 0.282137 0.282137 0.282137 0.282137 \n", - "min 0.000000 0.000000 0.000000 0.000000 \n", - "25% 0.000000 0.000000 0.000000 0.000000 \n", - "50% 0.000000 0.000000 0.000000 0.000000 \n", - "75% 0.000000 0.000000 0.000000 0.000000 \n", - "max 1.000000 1.000000 1.000000 1.000000 \n", - "\n", - " 4 5 6 7 \n", - "count 13663610.000000 13663610.000000 13663610.000000 13663610.000000 \n", - "mean 0.027380 0.027380 0.027380 0.027380 \n", - "std 0.163188 0.163188 0.163188 0.163188 \n", - "min 0.000000 0.000000 0.000000 0.000000 \n", - "25% 0.000000 0.000000 0.000000 0.000000 \n", - "50% 0.000000 0.000000 0.000000 0.000000 \n", - "75% 0.000000 0.000000 0.000000 0.000000 \n", - "max 1.000000 1.000000 1.000000 1.000000 \n", - "Choices\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "3 899448\n", - "2 674746\n", - "4 651817\n", - "1 254014\n", - "0 252697\n", + "2 1084366\n", + "1 972662\n", + "3 392971\n", + "0 144940\n", + "4 137783\n", "dtype: int64\n", - "Time to execute model 'auto_ownership_simulate': 43.75s" + "Time to execute model 'auto_ownership_simulate': 109.91s" ] }, { @@ -102,7 +60,7 @@ "stream": "stdout", "text": [ "\n", - "Total time to execute: 43.75s\n" + "Total time to execute: 109.91s\n" ] } ], @@ -135,6 +93,7 @@ " MFDU\n", " HHINCQ1\n", " ...\n", + " COLLPTE\n", " TOPOLOGY\n", " TERMINAL\n", " ZERO\n", @@ -144,7 +103,6 @@ " employment_density\n", " household_density\n", " density_index\n", - " county_name\n", " \n", " \n", " \n", @@ -161,6 +119,7 @@ " 1454.000000\n", " 1454.000000\n", " ...\n", + " 1454.000000\n", " 1454.000000\n", " 1454.000000\n", " 1454\n", @@ -170,7 +129,6 @@ " 1454.000000\n", " 1454.000000\n", " 1453.000000\n", - " 0\n", " \n", " \n", " mean\n", @@ -185,6 +143,7 @@ " 670.889959\n", " 508.134801\n", " ...\n", + " 166.744054\n", " 2.063274\n", " 1.630505\n", " 0\n", @@ -194,7 +153,6 @@ " 9.596395\n", " 6.008186\n", " 2.279554\n", - " NaN\n", " \n", " \n", " std\n", @@ -209,6 +167,7 @@ " 717.261660\n", " 378.753528\n", " ...\n", + " 1234.717238\n", " 0.926842\n", " 0.879441\n", " 0\n", @@ -218,7 +177,6 @@ " 45.067313\n", " 8.565908\n", " 3.945717\n", - " NaN\n", " \n", " \n", " min\n", @@ -233,6 +191,7 @@ " 0.000000\n", " 0.000000\n", " ...\n", + " 0.000000\n", " 1.000000\n", " 0.904320\n", " 0\n", @@ -242,7 +201,6 @@ " 0.000000\n", " 0.000000\n", " 0.000000\n", - " NaN\n", " \n", " \n", " 25%\n", @@ -257,6 +215,7 @@ " 144.500000\n", " 257.000000\n", " ...\n", + " 0.000000\n", " 1.000000\n", " 1.167372\n", " 0\n", @@ -266,7 +225,6 @@ " 0.877829\n", " 1.910701\n", " 0.550232\n", - " NaN\n", " \n", " \n", " 50%\n", @@ -281,6 +239,7 @@ " 460.000000\n", " 434.000000\n", " ...\n", + " 0.000000\n", " 2.000000\n", " 1.323075\n", " 0\n", @@ -290,7 +249,6 @@ " 2.158701\n", " 3.939122\n", " 1.289224\n", - " NaN\n", " \n", " \n", " 75%\n", @@ -305,6 +263,7 @@ " 907.750000\n", " 674.750000\n", " ...\n", + " 0.000000\n", " 3.000000\n", " 1.632443\n", " 0\n", @@ -314,7 +273,6 @@ " 5.492696\n", " 6.693238\n", " 2.337577\n", - " NaN\n", " \n", " \n", " max\n", @@ -329,6 +287,7 @@ " 4920.000000\n", " 3754.000000\n", " ...\n", + " 19570.523440\n", " 3.000000\n", " 7.310200\n", " 0\n", @@ -338,16 +297,15 @@ " 877.564767\n", " 90.891304\n", " 46.360371\n", - " NaN\n", " \n", " \n", "\n", - "

8 rows \u00d7 45 columns

\n", + "

8 rows \u00d7 44 columns

\n", "" ], "metadata": {}, "output_type": "pyout", - "prompt_number": 2, + "prompt_number": 16, "text": [ " DISTRICT SD county_id total_households HHPOP \\\n", "count 1454.000000 1454.000000 1454.000000 1454.000000 1454.000000 \n", @@ -369,41 +327,41 @@ "75% 6098.500000 2735.500000 1496.000000 907.750000 674.750000 \n", "max 40020.000000 16799.000000 12413.000000 4920.000000 3754.000000 \n", "\n", - " ... TOPOLOGY TERMINAL ZERO hhlds sftaz \\\n", - "count ... 1454.000000 1454.000000 1454 1454.000000 1454.000000 \n", - "mean ... 2.063274 1.630505 0 1793.688446 727.500000 \n", - "std ... 0.926842 0.879441 0 961.021405 419.877958 \n", - "min ... 1.000000 0.904320 0 0.000000 1.000000 \n", - "25% ... 1.000000 1.167372 0 1200.250000 364.250000 \n", - "50% ... 2.000000 1.323075 0 1681.500000 727.500000 \n", - "75% ... 3.000000 1.632443 0 2259.750000 1090.750000 \n", - "max ... 3.000000 7.310200 0 12542.000000 1454.000000 \n", + " ... COLLPTE TOPOLOGY TERMINAL ZERO \\\n", + "count ... 1454.000000 1454.000000 1454.000000 1454 \n", + "mean ... 166.744054 2.063274 1.630505 0 \n", + "std ... 1234.717238 0.926842 0.879441 0 \n", + "min ... 0.000000 1.000000 0.904320 0 \n", + "25% ... 0.000000 1.000000 1.167372 0 \n", + "50% ... 0.000000 2.000000 1.323075 0 \n", + "75% ... 0.000000 3.000000 1.632443 0 \n", + "max ... 19570.523440 3.000000 7.310200 0 \n", "\n", - " gqpop employment_density household_density density_index \\\n", - "count 1454.000000 1454.000000 1454.000000 1453.000000 \n", - "mean 101.570151 9.596395 6.008186 2.279554 \n", - "std 393.886676 45.067313 8.565908 3.945717 \n", - "min -1.000000 0.000000 0.000000 0.000000 \n", - "25% 5.000000 0.877829 1.910701 0.550232 \n", - "50% 18.000000 2.158701 3.939122 1.289224 \n", - "75% 71.000000 5.492696 6.693238 2.337577 \n", - "max 7810.000000 877.564767 90.891304 46.360371 \n", + " hhlds sftaz gqpop employment_density \\\n", + "count 1454.000000 1454.000000 1454.000000 1454.000000 \n", + "mean 1793.688446 727.500000 101.570151 9.596395 \n", + "std 961.021405 419.877958 393.886676 45.067313 \n", + "min 0.000000 1.000000 -1.000000 0.000000 \n", + "25% 1200.250000 364.250000 5.000000 0.877829 \n", + "50% 1681.500000 727.500000 18.000000 2.158701 \n", + "75% 2259.750000 1090.750000 71.000000 5.492696 \n", + "max 12542.000000 1454.000000 7810.000000 877.564767 \n", "\n", - " county_name \n", - "count 0 \n", - "mean NaN \n", - "std NaN \n", - "min NaN \n", - "25% NaN \n", - "50% NaN \n", - "75% NaN \n", - "max NaN \n", + " household_density density_index \n", + "count 1454.000000 1453.000000 \n", + "mean 6.008186 2.279554 \n", + "std 8.565908 3.945717 \n", + "min 0.000000 0.000000 \n", + "25% 1.910701 0.550232 \n", + "50% 3.939122 1.289224 \n", + "75% 6.693238 2.337577 \n", + "max 90.891304 46.360371 \n", "\n", - "[8 rows x 45 columns]" + "[8 rows x 44 columns]" ] } ], - "prompt_number": 2 + "prompt_number": 16 }, { "cell_type": "code", From 109cd47397b36c2603e6c987d690a2178d1a1eb9 Mon Sep 17 00:00:00 2001 From: Fletcher Foti Date: Thu, 11 Dec 2014 09:48:45 -0800 Subject: [PATCH 6/8] just figured out that the variables like AUTOPEAKRETAIL are in accessibility.csv Easier to add the logsums than I thought it would be. Also moved the standard methods into a new module - activitysim.py - will add unit tests and docstrings if we all think this is the right direction to be headed Also added a global param to settings.yaml called household_sample_size to run with a subset of the total households when debugging --- activitysim/defaults/datasources.py | 11 ++- example/configs/auto_ownership_coeffs.csv | 31 +------- example/configs/settings.yaml | 2 + example/models.py | 86 +++-------------------- notebooks/simulation.ipynb | 16 ++--- 5 files changed, 30 insertions(+), 116 deletions(-) diff --git a/activitysim/defaults/datasources.py b/activitysim/defaults/datasources.py index 1b38bce91c..59c12f1f14 100644 --- a/activitysim/defaults/datasources.py +++ b/activitysim/defaults/datasources.py @@ -5,6 +5,7 @@ import yaml from urbansim.utils import misc import urbansim.sim.simulation as sim +from .. import activitysim as asim import warnings @@ -51,11 +52,16 @@ def land_use(store): @sim.table(cache=True) def accessibility(store): - return store["skims/accessibility"] + df = store["skims/accessibility"] + df.columns = [c.upper() for c in df.columns] + return df @sim.table(cache=True) -def households(store): +def households(store, settings): + if "households_sample_size" in settings: + return asim.random_rows(store["households"], + settings["households_sample_size"]) return store["households"] @@ -65,3 +71,4 @@ def persons(store): sim.broadcast('land_use', 'households', cast_index=True, onto_on='TAZ') +sim.broadcast('accessibility', 'households', cast_index=True, onto_on='TAZ') diff --git a/example/configs/auto_ownership_coeffs.csv b/example/configs/auto_ownership_coeffs.csv index 412e081bc6..0fe176c110 100644 --- a/example/configs/auto_ownership_coeffs.csv +++ b/example/configs/auto_ownership_coeffs.csv @@ -1,30 +1 @@ -Description,Expression,cars0,cars1,cars2,cars3,cars4 -2 Adults (age 16+),drivers==2,,0,3.0773,3.1962,2.6616 -3 Adults (age 16+),drivers==3,,0,3.5401,5.5131,5.208 -4+ Adults (age 16+),drivers>3,,2.0107,6.3662,8.5148,9.5807 -Persons age 16-17,num_adolescents,,0,-0.881,-1.7313,-1.7313 -Persons age 18-24,num_college_age,,-0.4087,-1.0095,-1.0107,-1.0107 -Persons age 35-34,num_young_adults,,0,-0.4849,-0.8596,-0.8596 -Presence of children age 0-4,num_young_children>0,,0.3669,0.7627,0.7627,0.7627 -Presence of children age 5-17,(num_children+num_adolescents)>0,,0.0158,0.2936,0.4769,0.4769 -"Number of workers, capped at 3",@df.workers.clip(upper=3),,0,0.2936,0.6389,0.8797 -"Piecewise Linear household income, $0-30k","@df.income_in_thousands.clip(0, 30)",,0.0383,0.054,0.0559,0.0619 -"Piecewise Linear household income, $30-75k","@(df.income_in_thousands-30).clip(0, 45)",,0,0.0083,0.011,0.0147 -"Piecewise Linear household income, $75k+, capped at $125k","@(df.income_in_thousands-75).clip(0, 50)",,0,0.0083,0.011,0.0147 -"Density index up to 10, if 0 workers","@(df.workers==0)*df.density_index.clip(0, 10)",,0,-0.2028,-0.3654,-0.3654 -"Density index in excess of 10, if 0 workers",@(df.workers==0)*(df.density_index-10).clip(0),,-0.0152,-0.1106,-0.1766,-0.1766 -"Density index up to 10, if 1+ workers","@(df.workers>0)*df.density_index.clip(0, 10)",,0,-0.2028,-0.3654,-0.3654 -"Density index in excess of 10, if 1+ workers",@(df.workers>0)*(df.density_index-10).clip(0),,-0.0152,-0.1106,-0.1766,-0.1766 -Constants,@1,,1.1865,-1.0846,-3.2502,-5.313 -San Francisco county,county_name == 'San Francisco',,0.4259,0.4683,0.1458,0.1458 -Solano county,county_name == 'Solano',,-0.566,-0.4429,-0.2372,-0.2372 -Napa county,county_name == 'Napa',,-0.566,-0.4429,-0.2372,-0.2372 -Sonoma county,county_name == 'Sonoma',,-0.566,-0.4429,-0.2372,-0.2372 -Marin county,county_name == 'Marin',,-0.2434,0,0,0 -"Retail accessibility (0.66*PK + 0.34*OP) by auto, if 0 workers",0.66*AUTOPEAKRETAIL+0.34*AUTOOFFPEAKRETAIL,,0.0626,0.0626,0.0626,0.0626 -"Retail accessibility (0.66*PK + 0.34*OP) by auto, if 1+ workers",0.66*AUTOPEAKRETAIL+0.34*AUTOOFFPEAKRETAIL,,0.1646,0.1646,0.1646,0.1646 -"Retail accessibility (0.66*PK + 0.34*OP) by transit, if 0 workers",0.66*TRANSITPEAKRETAIL+0.34*TRANSITOFFPEAKRETAIL,,-0.3053,-0.3053,-0.3053,-0.3053 -"Retail accessibility (0.66*PK + 0.34*OP) by transit, if 1+ workers",0.66*TRANSITPEAKRETAIL+0.34*TRANSITOFFPEAKRETAIL,,-0.5117,-0.5117,-0.5117,-0.5117 -"Retail accessibility by non-motorized, if 0 workers",NONMOTORIZEDRETAIL,,-0.03,-0.03,-0.03,-0.03 -"Retail accessibility by non-motorized, if 1+ workers",NONMOTORIZEDRETAIL,,-0.03,-0.03,-0.03,-0.03 -"Auto time savings per worker (over walk or transit, max 120) to work",workTourAutoTimeSavings/workers,,0.4707,0.6142,0.5705,0.7693 \ No newline at end of file +Description,Expression,cars0,cars1,cars2,cars3,cars4 2 Adults (age 16+),drivers==2,,0,3.0773,3.1962,2.6616 3 Adults (age 16+),drivers==3,,0,3.5401,5.5131,5.208 4+ Adults (age 16+),drivers>3,,2.0107,6.3662,8.5148,9.5807 Persons age 16-17,num_adolescents,,0,-0.881,-1.7313,-1.7313 Persons age 18-24,num_college_age,,-0.4087,-1.0095,-1.0107,-1.0107 Persons age 35-34,num_young_adults,,0,-0.4849,-0.8596,-0.8596 Presence of children age 0-4,num_young_children>0,,0.3669,0.7627,0.7627,0.7627 Presence of children age 5-17,(num_children+num_adolescents)>0,,0.0158,0.2936,0.4769,0.4769 "Number of workers, capped at 3",@df.workers.clip(upper=3),,0,0.2936,0.6389,0.8797 "Piecewise Linear household income, $0-30k","@df.income_in_thousands.clip(0, 30)",,0.0383,0.054,0.0559,0.0619 "Piecewise Linear household income, $30-75k","@(df.income_in_thousands-30).clip(0, 45)",,0,0.0083,0.011,0.0147 "Piecewise Linear household income, $75k+, capped at $125k","@(df.income_in_thousands-75).clip(0, 50)",,0,0.0083,0.011,0.0147 "Density index up to 10, if 0 workers","@(df.workers==0)*df.density_index.clip(0, 10)",,0,-0.2028,-0.3654,-0.3654 "Density index in excess of 10, if 0 workers",@(df.workers==0)*(df.density_index-10).clip(0),,-0.0152,-0.1106,-0.1766,-0.1766 "Density index up to 10, if 1+ workers","@(df.workers>0)*df.density_index.clip(0, 10)",,0,-0.2028,-0.3654,-0.3654 "Density index in excess of 10, if 1+ workers",@(df.workers>0)*(df.density_index-10).clip(0),,-0.0152,-0.1106,-0.1766,-0.1766 Constants,@1,,1.1865,-1.0846,-3.2502,-5.313 San Francisco county,county_name == 'San Francisco',,0.4259,0.4683,0.1458,0.1458 Solano county,county_name == 'Solano',,-0.566,-0.4429,-0.2372,-0.2372 Napa county,county_name == 'Napa',,-0.566,-0.4429,-0.2372,-0.2372 Sonoma county,county_name == 'Sonoma',,-0.566,-0.4429,-0.2372,-0.2372 Marin county,county_name == 'Marin',,-0.2434,0,0,0 "Retail accessibility (0.66*PK + 0.34*OP) by auto, if 0 workers",(workers==0)*(0.66*AUTOPEAKRETAIL+0.34*AUTOOFFPEAKRETAIL),,0.0626,0.0626,0.0626,0.0626 "Retail accessibility (0.66*PK + 0.34*OP) by auto, if 1+ workers",(workers>0)*(0.66*AUTOPEAKRETAIL+0.34*AUTOOFFPEAKRETAIL),,0.1646,0.1646,0.1646,0.1646 "Retail accessibility (0.66*PK + 0.34*OP) by transit, if 0 workers",(workers==0)*(0.66*TRANSITPEAKRETAIL+0.34*TRANSITOFFPEAKRETAIL),,-0.3053,-0.3053,-0.3053,-0.3053 "Retail accessibility (0.66*PK + 0.34*OP) by transit, if 1+ workers",(workers>0)*(0.66*TRANSITPEAKRETAIL+0.34*TRANSITOFFPEAKRETAIL),,-0.5117,-0.5117,-0.5117,-0.5117 "Retail accessibility by non-motorized, if 0 workers",(workers==0)*NONMOTORIZEDRETAIL,,-0.03,-0.03,-0.03,-0.03 "Retail accessibility by non-motorized, if 1+ workers",(workers>0)*NONMOTORIZEDRETAIL,,-0.03,-0.03,-0.03,-0.03 "Auto time savings per worker (over walk or transit, max 120) to work",workTourAutoTimeSavings/workers,,0.4707,0.6142,0.5705,0.7693 \ No newline at end of file diff --git a/example/configs/settings.yaml b/example/configs/settings.yaml index b7d6254a25..05cf2cdb08 100644 --- a/example/configs/settings.yaml +++ b/example/configs/settings.yaml @@ -1,5 +1,7 @@ store: mtc_asim.h5 +households_sample_size: 100000 + county_map: San Francisco: 1 San Mateo: 2 diff --git a/example/models.py b/example/models.py index 0ca207750d..9af2841f8b 100644 --- a/example/models.py +++ b/example/models.py @@ -1,99 +1,33 @@ import urbansim.sim.simulation as sim -from urbansim.utils import misc -from urbansim.urbanchoice import interaction, mnl -import pandas as pd -import numpy as np import os - - -def random_rows(df, n): - return df.take(np.random.randint(0, len(df), n)) - - -def read_model_spec(fname, - description_name="Description", - expression_name="Expression"): - """ - Read in the excel file and reformat for machines - """ - cfg = pd.read_csv(fname) - # don't need description and set the expression to the index - cfg = cfg.drop(description_name, axis=1).set_index(expression_name).stack() - return cfg - - -def identity_matrix(alt_names): - return pd.DataFrame(np.identity(len(alt_names)), - columns=alt_names, - index=alt_names) - - -def simple_simulate(choosers, alternatives, spec): - exprs = spec.index - coeffs = spec.values - - # merge choosers and alternatives - _, df, _ = interaction.mnl_interaction_dataset( - choosers, alternatives, len(alternatives)) - - # evaluate the expressions to build the final matrix - vars, names = [], [] - for expr in exprs: - if expr[0][0] == "@": - expr = "({}) * df.{}".format(expr[0][1:], expr[1]) - try: - s = eval(expr) - except Exception as e: - print "Failed with Python eval:\n%s" % expr - raise e - else: - expr = "({}) * {}".format(*expr) - try: - s = df.eval(expr) - except Exception as e: - print "Failed with DataFrame eval:\n%s" % expr - raise e - names.append(expr) - vars.append(s) - model_design=pd.concat(vars, axis=1) - model_design.columns = names - - df = random_rows(model_design, 100000).describe().transpose() - df = df[df["std"] == 0] - if len(df): - print "WARNING: Describe of columns with no variability:\n", df - - choices = mnl.mnl_simulate( - model_design.as_matrix(), - coeffs, - numalts=len(alternatives), - returnprobs=False) - - return pd.Series(choices, index=choosers.index), model_design +from activitysim import activitysim as asim @sim.table() def auto_alts(): - return identity_matrix(["cars%d"%i for i in range(5)]) + return asim.identity_matrix(["cars%d"%i for i in range(5)]) @sim.injectable() def auto_ownership_spec(): - f = os.path.join(misc.configs_dir(), "auto_ownership_coeffs.csv") - return read_model_spec(f).head(4*20) + f = os.path.join('configs', "auto_ownership_coeffs.csv") + return asim.read_model_spec(f).head(4*26) @sim.model() def auto_ownership_simulate(households, auto_alts, auto_ownership_spec, - land_use): + land_use, + accessibility): - choosers = sim.merge_tables(households.name, tables=[households, land_use]) + choosers = sim.merge_tables(households.name, tables=[households, + land_use, + accessibility]) alternatives = auto_alts.to_frame() choices, model_design = \ - simple_simulate(choosers, alternatives, auto_ownership_spec) + asim.simple_simulate(choosers, alternatives, auto_ownership_spec) print "Choices:\n", choices.value_counts() sim.add_column("households", "auto_ownership", choices) diff --git a/notebooks/simulation.ipynb b/notebooks/simulation.ipynb index ffad308134..31776e6a61 100644 --- a/notebooks/simulation.ipynb +++ b/notebooks/simulation.ipynb @@ -1,7 +1,7 @@ { "metadata": { "name": "", - "signature": "sha256:9538d1e98425ccf99082cd66b6de30113546b74b1f622af89caa7806bc97181e" + "signature": "sha256:e753195d2dede5dd16ee412a8640e8afb7012fd102f13ac2ca2f0086ebdcdb09" }, "nbformat": 3, "nbformat_minor": 0, @@ -46,13 +46,13 @@ "output_type": "stream", "stream": "stdout", "text": [ - "2 1084366\n", - "1 972662\n", - "3 392971\n", - "0 144940\n", - "4 137783\n", + "2 39441\n", + "1 32330\n", + "3 14788\n", + "0 8397\n", + "4 5044\n", "dtype: int64\n", - "Time to execute model 'auto_ownership_simulate': 109.91s" + "Time to execute model 'auto_ownership_simulate': 10.16s" ] }, { @@ -60,7 +60,7 @@ "stream": "stdout", "text": [ "\n", - "Total time to execute: 109.91s\n" + "Total time to execute: 10.16s\n" ] } ], From d72c2c164ac45c8b214bc6e4e84ec3278ee353c1 Mon Sep 17 00:00:00 2001 From: Fletcher Foti Date: Thu, 11 Dec 2014 09:50:41 -0800 Subject: [PATCH 7/8] add the activitysim.py module too --- activitysim/activitysim.py | 71 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 activitysim/activitysim.py diff --git a/activitysim/activitysim.py b/activitysim/activitysim.py new file mode 100644 index 0000000000..0671d9d368 --- /dev/null +++ b/activitysim/activitysim.py @@ -0,0 +1,71 @@ +import urbansim.sim.simulation as sim +from urbansim.urbanchoice import interaction, mnl +import pandas as pd +import numpy as np +import os + + +def random_rows(df, n): + return df.take(np.random.choice(len(df), size=n, replace=False)) + + +def read_model_spec(fname, + description_name="Description", + expression_name="Expression"): + """ + Read in the excel file and reformat for machines + """ + cfg = pd.read_csv(fname) + # don't need description and set the expression to the index + cfg = cfg.drop(description_name, axis=1).set_index(expression_name).stack() + return cfg + + +def identity_matrix(alt_names): + return pd.DataFrame(np.identity(len(alt_names)), + columns=alt_names, + index=alt_names) + + +def simple_simulate(choosers, alternatives, spec): + exprs = spec.index + coeffs = spec.values + + # merge choosers and alternatives + _, df, _ = interaction.mnl_interaction_dataset( + choosers, alternatives, len(alternatives)) + + # evaluate the expressions to build the final matrix + vars, names = [], [] + for expr in exprs: + if expr[0][0] == "@": + expr = "({}) * df.{}".format(expr[0][1:], expr[1]) + try: + s = eval(expr) + except Exception as e: + print "Failed with Python eval:\n%s" % expr + raise e + else: + expr = "({}) * {}".format(*expr) + try: + s = df.eval(expr) + except Exception as e: + print "Failed with DataFrame eval:\n%s" % expr + raise e + names.append(expr) + vars.append(s) + model_design=pd.concat(vars, axis=1) + model_design.columns = names + + df = random_rows(model_design, 100000).describe().transpose() + df = df[df["std"] == 0] + if len(df): + print "WARNING: Describe of columns with no variability:\n", df + + choices = mnl.mnl_simulate( + model_design.as_matrix(), + coeffs, + numalts=len(alternatives), + returnprobs=False) + + return pd.Series(choices, index=choosers.index), model_design From 4e878897401566632706ba12f9efa686e660cbe4 Mon Sep 17 00:00:00 2001 From: Fletcher Foti Date: Thu, 11 Dec 2014 10:18:39 -0800 Subject: [PATCH 8/8] pep8 --- activitysim/activitysim.py | 2 +- example/models.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/activitysim/activitysim.py b/activitysim/activitysim.py index 0671d9d368..c2c8268c9c 100644 --- a/activitysim/activitysim.py +++ b/activitysim/activitysim.py @@ -54,7 +54,7 @@ def simple_simulate(choosers, alternatives, spec): raise e names.append(expr) vars.append(s) - model_design=pd.concat(vars, axis=1) + model_design = pd.concat(vars, axis=1) model_design.columns = names df = random_rows(model_design, 100000).describe().transpose() diff --git a/example/models.py b/example/models.py index 9af2841f8b..ab4bfcffd4 100644 --- a/example/models.py +++ b/example/models.py @@ -5,7 +5,7 @@ @sim.table() def auto_alts(): - return asim.identity_matrix(["cars%d"%i for i in range(5)]) + return asim.identity_matrix(["cars%d" % i for i in range(5)]) @sim.injectable()