{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import geopandas as gpd\n", "import pandas as pd\n", "import numpy as np\n", "pd.options.display.max_columns=100\n", "import plotly.graph_objects as go\n", "import plotly.express as px\n", "import ipywidgets as widgets\n", "from ipywidgets import Layout,interact,interact_manual,HTML\n", "import pyproj\n", "pyproj.datadir.set_data_dir('/Users/shai/anaconda3/envs/geo_env/share/proj')\n", "from arcgis.gis import GIS\n", "from arcgis.mapping import WebScene\n", "from arcgis.mapping import WebMap\n", "from arcgis.features import FeatureLayer\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "incomeDict = {'Low':9000,'Medium':19500,'High':1000000}\n", "Age = {'Under 65':65,\n", " 'Above 65':65}\n", "gridBG = '#f2f2f2'\n", "heightD=375\n", "projectDict = {1:'Addition',\n", " 2:'Reconstruction',\n", " 3:'Raze and Rebuild'}" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdin", "output_type": "stream", "text": [ "Enter password: ·········\n" ] } ], "source": [ "gis = GIS(\"https://technion-gis.maps.arcgis.com\", \"shai@technion\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "geoDF = gpd.read_file('simBldgsData09042021.geojson',driver='GeoJSON')\n", "bldDictAddress = dict(zip(geoDF['bld_addres'],geoDF['hebrew_adr']))\n", "aggResByTic = pd.read_excel('aggregated_results_by_project_april17.xlsx')\n", "agentsFile = 'AgentsTimeSeries_Results_april12_1435.xlsx'\n", "res_df = pd.read_excel(agentsFile)\n", "colorFile ='colors_dict_April_13_2021.xlsx'\n", "colorAgeIncomeExcel='age_income_by_color_april_14.xlsx'\n", "colorExcel = pd.read_excel(colorFile)\n", "movementsByProject = pd.read_excel('AggByProjectBeforeAfter_april_18.xlsx', header=[0,1])\n", "projNumberTicDict = dict(zip(aggResByTic['tic'],aggResByTic['ProjNumber']))\n", "projBldNumberDict = dict(zip(geoDF[['project_nu','bld_addres']].groupby('project_nu').agg({'bld_addres':lambda x: x.value_counts().index[0]}).reset_index()['project_nu'],\n", " geoDF[['project_nu','bld_addres']].groupby('project_nu').agg({'bld_addres':lambda x: x.value_counts().index[0]}).reset_index()['bld_addres']))\n", "#TICS\n", "ticsIndex = aggResByTic['tic']" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/Users/shai/anaconda3/envs/geo_env/lib/python3.7/site-packages/pyproj/crs/crs.py:53: FutureWarning: '+init=:' syntax is deprecated. ':' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6\n", " return _prepare_from_string(\" \".join(pjargs))\n" ] } ], "source": [ "interFeature = geoDF.to_crs(\"+proj=tmerc +lat_0=31.7343936111111 +lon_0=35.2045169444445 +k=1.0000067 +x_0=219529.584 +y_0=626907.39 +ellps=GRS80 +towgs84=-23.772,-17.490,-17.859,-0.31320,-1.85274,1.67299,5.4262 +units=m +no_defs\")\n", "crs_4326 = {'init': 'epsg:4326'}\n", "bldgsInwgs84 = interFeature.to_crs(crs_4326)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "res_df['stay'] = 0\n", "res_df['stay'] = res_df['status'].apply(lambda x: 1 if x=='stay' else 0)\n", "res_df['leave'] = 0\n", "res_df['leave'] = res_df['status'].apply(lambda x: 1 if x=='leave' else 0)\n", "res_df['New Comers'] = 0\n", "res_df['New Comers'] = res_df['status'].apply(lambda x: 1 if x=='New Comers' else 0)\n", "res_df.fillna(0,inplace=True)\n", "res_df['Under 65'] = 0\n", "res_df['Above 65'] = 0\n", "res_df['Low Income'] = 0\n", "res_df['Medium Income'] = 0\n", "res_df['High Income'] = 0\n", "\n", "res_df['Under 65'] = res_df['age'].apply(lambda x: 1 if x<65 else 0)\n", "res_df['Above 65'] = res_df['age'].apply(lambda x: 1 if x>=65 else 0)\n", "res_df['Low Income'] = res_df['income'].apply(lambda x: 1 if (x=incomeDict['Low']) & (x=incomeDict['Medium']) else 0)\n", "subset_before_after = res_df.copy()\n", "subset_before_after = subset_before_after[subset_before_after['status']!='leave']\n", "subset_before_after['simulationState'] =subset_before_after['tic'].apply(lambda x: 'Before Renewal' if x==0 else 'After Renewal')" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "ageIncome = subset_before_after[['simulationState','income','age','agentID','tic','ProjNumber']].copy()\n", "ageIncome['ageGroup'] = ageIncome['age'].apply(lambda x: 'Under 65' if x<65 else 'Above 65')\n", "ageIncome['incomeGroup'] = ageIncome['income'].apply(lambda x: 'High Income' if x>=19500 \n", " else ('Medium Income' if ((x>=9000)&(x<19500)) else 'Low Income'))\n", "\n", "ageIncome = ageIncome[['simulationState','incomeGroup','agentID','ageGroup','tic','ProjNumber']].copy()" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "res2 = aggResByTic.loc[1:].copy()\n", "res2 = res2[res2.columns[res2.notnull().loc[1].values]].copy()\n", "res2['ProjectTypeDesc'] = res2['prjectType'].apply(lambda x:projectDict[x])" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/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", "
Unnamed: 0aprtmentSizeMeanProjNumberyearsInBldgMeanaprtmentSizeMeanStayaprtmentSizeNewComerAgeMeanAgeMeanNewAgeMeanStayAgeOldStayNewAgeYoungStayNewAgeOldStayAgeYoungStayAgeOldNewAgeYoungNewIncomeHighStayIncomeMedStayIncomeLowStayIncomeHighNewIncomeMedNewIncomeLowNewIncomeHighStayNewIncomeMedStayNewIncomeLowStayNewmeanIncomeStaymeanIncomeNewComersmeanIncomeStay_N_newrentCountownCountrentStayCountrentNewCountownStayCountownNewCountTotalAgentsCountprjectTypeticstaynew comersCostForStayingrentPriceleaveProjectTypeDesc
1175.3376912018098822.81045875.08144882.00000048.40958648.47058848.407240255.0663.0248.0636.07.027.00.0369.0515.023.011.00.023.0380.0515.07699.25113120246.7631588163.973799321597310.011.0574.023.09181188434.0255.628170013Addition
2275.6163792010013322.14116475.17511582.00000048.48383648.48333348.483871256.0672.0243.0625.013.047.00.0364.0504.040.020.00.040.0384.0504.07697.44930920174.9780708504.186082325603304.021.0564.039.09281286860.0441.070496029Addition
3375.5873022018081221.43915375.62997775.18681348.36613849.30769248.265808256.0689.0236.0618.020.071.00.0356.0498.040.051.00.040.0407.0498.07658.19437918781.0433788729.283542324621297.027.0557.064.09451385491.0606.108847043Addition
4476.0271122018109220.61731075.60523279.03389848.44212750.06779748.214031258.0701.0231.0610.027.091.00.0350.0491.066.052.00.066.0402.0491.07639.38525619569.9223919107.376269329630291.038.0550.080.095914841118.0810.857831056Addition
5576.6279072017197419.78867575.89423180.51592448.54297350.25477748.219952264.0725.0228.0604.036.0121.00.0346.0486.098.059.00.098.0405.0486.07620.58293319983.3183049583.120297339650286.053.0546.0104.098925832157.01067.265228065Reconstruction
\n", "
" ], "text/plain": [ " Unnamed: 0 aprtmentSizeMean ProjNumber yearsInBldgMean \\\n", "1 1 75.337691 20180988 22.810458 \n", "2 2 75.616379 20100133 22.141164 \n", "3 3 75.587302 20180812 21.439153 \n", "4 4 76.027112 20181092 20.617310 \n", "5 5 76.627907 20171974 19.788675 \n", "\n", " aprtmentSizeMeanStay aprtmentSizeNewComer AgeMean AgeMeanNew \\\n", "1 75.081448 82.000000 48.409586 48.470588 \n", "2 75.175115 82.000000 48.483836 48.483333 \n", "3 75.629977 75.186813 48.366138 49.307692 \n", "4 75.605232 79.033898 48.442127 50.067797 \n", "5 75.894231 80.515924 48.542973 50.254777 \n", "\n", " AgeMeanStay AgeOldStayNew AgeYoungStayNew AgeOldStay AgeYoungStay \\\n", "1 48.407240 255.0 663.0 248.0 636.0 \n", "2 48.483871 256.0 672.0 243.0 625.0 \n", "3 48.265808 256.0 689.0 236.0 618.0 \n", "4 48.214031 258.0 701.0 231.0 610.0 \n", "5 48.219952 264.0 725.0 228.0 604.0 \n", "\n", " AgeOldNew AgeYoungNew IncomeHighStay IncomeMedStay IncomeLowStay \\\n", "1 7.0 27.0 0.0 369.0 515.0 \n", "2 13.0 47.0 0.0 364.0 504.0 \n", "3 20.0 71.0 0.0 356.0 498.0 \n", "4 27.0 91.0 0.0 350.0 491.0 \n", "5 36.0 121.0 0.0 346.0 486.0 \n", "\n", " IncomeHighNew IncomeMedNew IncomeLowNew IncomeHighStayNew \\\n", "1 23.0 11.0 0.0 23.0 \n", "2 40.0 20.0 0.0 40.0 \n", "3 40.0 51.0 0.0 40.0 \n", "4 66.0 52.0 0.0 66.0 \n", "5 98.0 59.0 0.0 98.0 \n", "\n", " IncomeMedStayNew IncomeLowStayNew meanIncomeStay meanIncomeNewComers \\\n", "1 380.0 515.0 7699.251131 20246.763158 \n", "2 384.0 504.0 7697.449309 20174.978070 \n", "3 407.0 498.0 7658.194379 18781.043378 \n", "4 402.0 491.0 7639.385256 19569.922391 \n", "5 405.0 486.0 7620.582933 19983.318304 \n", "\n", " meanIncomeStay_N_new rentCount ownCount rentStayCount rentNewCount \\\n", "1 8163.973799 321 597 310.0 11.0 \n", "2 8504.186082 325 603 304.0 21.0 \n", "3 8729.283542 324 621 297.0 27.0 \n", "4 9107.376269 329 630 291.0 38.0 \n", "5 9583.120297 339 650 286.0 53.0 \n", "\n", " ownStayCount ownNewCount TotalAgentsCount prjectType tic stay \\\n", "1 574.0 23.0 918 1 1 884 \n", "2 564.0 39.0 928 1 2 868 \n", "3 557.0 64.0 945 1 3 854 \n", "4 550.0 80.0 959 1 4 841 \n", "5 546.0 104.0 989 2 5 832 \n", "\n", " new comers CostForStaying rentPrice leave ProjectTypeDesc \n", "1 34.0 255.628170 0 13 Addition \n", "2 60.0 441.070496 0 29 Addition \n", "3 91.0 606.108847 0 43 Addition \n", "4 118.0 810.857831 0 56 Addition \n", "5 157.0 1067.265228 0 65 Reconstruction " ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "res2.head()" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "class simWidgets:\n", " styled = {'description_width': 'initial'}\n", " def __init__(self):\n", " self.tics =widgets.IntRangeSlider(\n", " value=[0, 1],\n", " min=0,\n", " max=30,\n", " step=1,\n", " description='Simulation Tics:',\n", " disabled=False,\n", " continuous_update=False,\n", " orientation='horizontal',\n", " readout=True,\n", " readout_format='d',\n", " layout=Layout(width='100%'),\n", " style=simWidgets.styled\n", " )\n" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "simWidg = simWidgets()\n", "simWidg.tics.min = ticsIndex.values.min()\n", "simWidg.tics.max = ticsIndex.values.max()" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "def g(x):\n", " startTic = x[0]\n", " lastTic = x[1]\n", " if lastTic>0:\n", " if startTic==11:\n", " startTic=12\n", " if lastTic==11:\n", " lastTic=12\n", " projectNum = projNumberTicDict[lastTic]\n", " bldNumber = projBldNumberDict[projectNum]\n", " hebAddres = bldDictAddress[bldNumber]\n", " projectTypeDesc = res2.query(f'tic=={lastTic}')['ProjectTypeDesc'].values[0]\n", " h = HTML(value=f\"

Execution: {x[1]}   Project Number: {projectNum}
Hebrew Address: {hebAddres}
Project Type: {projectTypeDesc}

\")\n", " figure_1(startTic,lastTic)\n", " figure_2(startTic,lastTic)\n", " figure_3(startTic,lastTic)\n", " figure_4(startTic,lastTic)\n", " figure_5(startTic,lastTic)\n", " figure_6(lastTic)\n", " figure_7(lastTic)\n", " figure_9(projectNum)\n", " display(h)\n", " else:\n", " h = HTML(value=f\"

Tick: {x[1]}

\")\n", " display(h)\n", " #return (x[0]*2)" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "a648a29dd4d54a65a494e5fe4ab531f2", "version_major": 2, "version_minor": 0 }, "text/plain": [ "interactive(children=(IntRangeSlider(value=(0, 1), continuous_update=False, description='Simulation Tics:', la…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "i = interact_manual(g, x=simWidg.tics)\n", "i.widget.children[1].description = 'Submit'\n" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'Reconstruction'" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "res2.query(f'tic=={10}')['ProjectTypeDesc'].values[0]" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/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", "
Unnamed: 0aprtmentSizeMeanProjNumberyearsInBldgMeanaprtmentSizeMeanStayaprtmentSizeNewComerAgeMeanAgeMeanNewAgeMeanStayAgeOldStayNewAgeYoungStayNewAgeOldStayAgeYoungStayAgeOldNewAgeYoungNewIncomeHighStayIncomeMedStayIncomeLowStayIncomeHighNewIncomeMedNewIncomeLowNewIncomeHighStayNewIncomeMedStayNewIncomeLowStayNewmeanIncomeStaymeanIncomeNewComersmeanIncomeStay_N_newrentCountownCountrentStayCountrentNewCountownStayCountownNewCountTotalAgentsCountprjectTypeticstaynew comersCostForStayingrentPriceleave
0074.914158NaN23.526198NaNNaN48.357860NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN318579NaNNaNNaNNaN89700897NaNNaN00
1175.3376912018098822.81045875.08144882.00000048.40958648.47058848.407240255.0663.0248.0636.07.027.00.0369.0515.023.011.00.023.0380.0515.07699.25113120246.7631588163.973799321597310.011.0574.023.09181188434.0255.628170013
2275.6163792010013322.14116475.17511582.00000048.48383648.48333348.483871256.0672.0243.0625.013.047.00.0364.0504.040.020.00.040.0384.0504.07697.44930920174.9780708504.186082325603304.021.0564.039.09281286860.0441.070496029
3375.5873022018081221.43915375.62997775.18681348.36613849.30769248.265808256.0689.0236.0618.020.071.00.0356.0498.040.051.00.040.0407.0498.07658.19437918781.0433788729.283542324621297.027.0557.064.09451385491.0606.108847043
4476.0271122018109220.61731075.60523279.03389848.44212750.06779748.214031258.0701.0231.0610.027.091.00.0350.0491.066.052.00.066.0402.0491.07639.38525619569.9223919107.376269329630291.038.0550.080.095914841118.0810.857831056
\n", "
" ], "text/plain": [ " Unnamed: 0 aprtmentSizeMean ProjNumber yearsInBldgMean \\\n", "0 0 74.914158 NaN 23.526198 \n", "1 1 75.337691 20180988 22.810458 \n", "2 2 75.616379 20100133 22.141164 \n", "3 3 75.587302 20180812 21.439153 \n", "4 4 76.027112 20181092 20.617310 \n", "\n", " aprtmentSizeMeanStay aprtmentSizeNewComer AgeMean AgeMeanNew \\\n", "0 NaN NaN 48.357860 NaN \n", "1 75.081448 82.000000 48.409586 48.470588 \n", "2 75.175115 82.000000 48.483836 48.483333 \n", "3 75.629977 75.186813 48.366138 49.307692 \n", "4 75.605232 79.033898 48.442127 50.067797 \n", "\n", " AgeMeanStay AgeOldStayNew AgeYoungStayNew AgeOldStay AgeYoungStay \\\n", "0 NaN NaN NaN NaN NaN \n", "1 48.407240 255.0 663.0 248.0 636.0 \n", "2 48.483871 256.0 672.0 243.0 625.0 \n", "3 48.265808 256.0 689.0 236.0 618.0 \n", "4 48.214031 258.0 701.0 231.0 610.0 \n", "\n", " AgeOldNew AgeYoungNew IncomeHighStay IncomeMedStay IncomeLowStay \\\n", "0 NaN NaN NaN NaN NaN \n", "1 7.0 27.0 0.0 369.0 515.0 \n", "2 13.0 47.0 0.0 364.0 504.0 \n", "3 20.0 71.0 0.0 356.0 498.0 \n", "4 27.0 91.0 0.0 350.0 491.0 \n", "\n", " IncomeHighNew IncomeMedNew IncomeLowNew IncomeHighStayNew \\\n", "0 NaN NaN NaN NaN \n", "1 23.0 11.0 0.0 23.0 \n", "2 40.0 20.0 0.0 40.0 \n", "3 40.0 51.0 0.0 40.0 \n", "4 66.0 52.0 0.0 66.0 \n", "\n", " IncomeMedStayNew IncomeLowStayNew meanIncomeStay meanIncomeNewComers \\\n", "0 NaN NaN NaN NaN \n", "1 380.0 515.0 7699.251131 20246.763158 \n", "2 384.0 504.0 7697.449309 20174.978070 \n", "3 407.0 498.0 7658.194379 18781.043378 \n", "4 402.0 491.0 7639.385256 19569.922391 \n", "\n", " meanIncomeStay_N_new rentCount ownCount rentStayCount rentNewCount \\\n", "0 NaN 318 579 NaN NaN \n", "1 8163.973799 321 597 310.0 11.0 \n", "2 8504.186082 325 603 304.0 21.0 \n", "3 8729.283542 324 621 297.0 27.0 \n", "4 9107.376269 329 630 291.0 38.0 \n", "\n", " ownStayCount ownNewCount TotalAgentsCount prjectType tic stay \\\n", "0 NaN NaN 897 0 0 897 \n", "1 574.0 23.0 918 1 1 884 \n", "2 564.0 39.0 928 1 2 868 \n", "3 557.0 64.0 945 1 3 854 \n", "4 550.0 80.0 959 1 4 841 \n", "\n", " new comers CostForStaying rentPrice leave \n", "0 NaN NaN 0 0 \n", "1 34.0 255.628170 0 13 \n", "2 60.0 441.070496 0 29 \n", "3 91.0 606.108847 0 43 \n", "4 118.0 810.857831 0 56 " ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "aggResByTic.head()" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ " stayingC = colorExcel.query('label==\"Staying\"')['colors_'].values[0]\n", " leavingC = colorExcel.query('label==\"Leaving\"')['colors_'].values[0]\n", " newComerC = colorExcel.query('label==\"New Comers\"')['colors_'].values[0]\n", " aC = colorExcel.query('label==\"Addition\"')['colors_'].values[0]\n", " rC = colorExcel.query('label==\"Reconstruction\"')['colors_'].values[0]\n", " rrC = colorExcel.query('label==\"Raze and Rebuild\"')['colors_'].values[0]\n", " totalPopC = colorExcel.query('label==\"Total Pop\"')['colors_'].values[0]\n", "\n", " lowIncomeC = colorExcel.loc[colorExcel['label']=='Moderate','colors_'].values[0]\n", " medIncomeC = colorExcel.loc[colorExcel['label']=='Middle','colors_'].values[0]\n", " upIncomeC = colorExcel.loc[colorExcel['label']=='Upper','colors_'].values[0]\n" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "def figure_1(start=1,end=1):\n", " widthD=800\n", " genericGraph = res2.query(f\"tic>={start} & tic<={end}\").copy()\n", " genericGraph.loc[genericGraph['prjectType']==1,'Project Type '] = 'Addition'\n", " genericGraph.loc[genericGraph['prjectType']==2,'Project Type '] = 'Reconstruction'\n", " genericGraph.loc[genericGraph['prjectType']==3,'Project Type '] = 'Raze and Rebuild'\n", " genericGraph['y_shift'] =-20\n", " # Change the bar mode\n", " aTics = genericGraph.loc[genericGraph['prjectType'] == 1, 'tic']\n", " aYshift =genericGraph.loc[genericGraph['prjectType'] == 1, 'y_shift']\n", "\n", " rTics = genericGraph.loc[genericGraph['prjectType'] == 2, 'tic']\n", " rYshift = genericGraph.loc[genericGraph['prjectType'] == 2, 'y_shift']\n", "\n", " rrTics = genericGraph.loc[genericGraph['prjectType'] == 3, 'tic']\n", " rrYshift = genericGraph.loc[genericGraph['prjectType'] == 3, 'y_shift']\n", " titlesList = ['Staying','New Comers','Total (Staying+New Comers)']\n", " colList = ['stay','new comers','TotalAgentsCount']\n", " colorList = [stayingC,newComerC,totalPopC]\n", " styleList = [dict(color=stayingC, width=4), dict(color=newComerC, width=4), dict(color=totalPopC, dash='dash')] \n", "\n", "\n", " fig = go.Figure()\n", " for i in range(3):\n", " fig.add_trace(go.Scatter(\n", " x=genericGraph['tic'],\n", " y=genericGraph[colList[i]],\n", " line=styleList[i],\n", " name=titlesList[i]\n", " ))\n", "\n", "\n", " maxY=3300\n", " for xtic in aTics:\n", " fig.add_shape(type=\"line\", x0=xtic, y0=0, x1=xtic, y1=maxY, line=dict(\n", " color=aC, width=1.5, dash=\"dot\"), layer=\"below\")\n", "\n", " for xtic in rTics:\n", " fig.add_shape(type=\"line\", x0=xtic, y0=0, x1=xtic, y1=maxY, line=dict(\n", " color=rC, width=1.5, dash=\"dot\"), layer=\"below\")\n", "\n", " for xtic in rrTics:\n", " fig.add_shape(type=\"line\", x0=xtic, y0=0, x1=xtic, y1=maxY,\n", " line=dict(color=rrC, width=1.5, dash=\"dot\"), layer=\"below\")\n", "\n", "\n", " fig.add_trace(go.Scatter(name='Addition', x=aTics, y=aYshift,\n", " mode='markers', marker=dict(color=aC)))\n", " fig.add_trace(go.Scatter(name='Reconstruction', x=rTics, y=rYshift,\n", " mode='markers', marker=dict(color=rC)))\n", " fig.add_trace(go.Scatter(name='Raze and Rebuild', x=rrTics,\n", " y=rrYshift, mode='markers', marker=dict(color=rrC)))\n", "\n", " fig.update_layout(width=widthD,height=heightD, title='Household Absolute change within simulation tics')\n", " fig.update_yaxes(title='Household Count',range=[-100, maxY],gridwidth=1, gridcolor=gridBG,zerolinewidth=1,zerolinecolor='lightgrey')\n", " fig.update_xaxes(title='Simulation tic',gridwidth=1, gridcolor=gridBG,zerolinewidth=1,zerolinecolor='lightgrey')\n", " fig.update_layout(showlegend=True,plot_bgcolor='rgba(0,0,0,0)',legend=dict(yanchor=\"top\", y=0.99, xanchor=\"left\", x=0.01,bgcolor='rgba(255,255,255,0.75)'))\n", " with out1:\n", " out1.clear_output()\n", " fig.show()" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "16c88d9693724167a687f075892b0640", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Output()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "out1 = widgets.Output()\n", "out1" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [], "source": [ "def figure_2(start,end):\n", " widthD=800\n", " genericGraph = res2.query(f\"tic>={start} & tic<={end}\").copy()\n", " title_ ='Percent Income by Group Staying Vs New Comers'\n", " y_title = 'Household Percent'\n", " columnsList = ['IncomeHighStay','IncomeMedStay','IncomeLowStay','IncomeHighNew','IncomeMedNew','IncomeLowNew','IncomeHighStayNew','IncomeMedStayNew','IncomeLowStayNew']\n", " titlesList = ['High Stay','Med Stay','Low Stay','High New Comer','Med New Comer','Low New Comer','High (average)','Medium (average)','Low (average)']\n", " legendGroup =['Staying','Staying','Staying','New Comers','New Comers','New Comers','Average','Average','Average']\n", " styleList = [dict(color=upIncomeC,width=2),\n", " dict(color=medIncomeC,width=2),\n", " dict(color=lowIncomeC,width=2),\n", " dict(color=upIncomeC,width=4),\n", " dict(color=medIncomeC,width=4),\n", " dict(color=lowIncomeC,width=4),\n", " dict(color='hsv(30,50%,100%)',dash='dash'),\n", " dict(color='hsv(30,75%,100%)', dash='dash'),\n", " dict(color='hsv(30,100%,50%)', dash='dash')]\n", " percentList=[]\n", " for i in range(9):\n", " percentList.append(f'{columnsList[i]}Percent')\n", " genericGraph[percentList[i]] = genericGraph[columnsList[i]]/genericGraph['TotalAgentsCount']\n", " genericGraph['y_shift'] =-0.02\n", " # Change the bar mode\n", " aTics = genericGraph.loc[genericGraph['prjectType'] == 1, 'tic']\n", " rTics = genericGraph.loc[genericGraph['prjectType'] == 2, 'tic']\n", " rrTics = genericGraph.loc[genericGraph['prjectType'] == 3, 'tic']\n", " \n", " aYshift =genericGraph.loc[genericGraph['prjectType'] == 1, 'y_shift']\n", " rYshift = genericGraph.loc[genericGraph['prjectType'] == 2, 'y_shift']\n", " rrYshift = genericGraph.loc[genericGraph['prjectType'] == 3, 'y_shift']\n", " maxY=1\n", " fig = go.Figure()\n", " for i in range(9):\n", " fig.add_trace(go.Scatter(\n", " x=genericGraph['tic'],\n", " y=genericGraph[percentList[i]],\n", " legendgroup = legendGroup[i],\n", " line=styleList[i],\n", " name=titlesList[i]\n", " ))\n", " for xtic in aTics:\n", " fig.add_shape(type=\"line\", x0=xtic, y0=0, x1=xtic, y1=maxY, line=dict(\n", " color=aC, width=1.5, dash=\"dot\"), layer=\"below\")\n", "\n", " for xtic in rTics:\n", " fig.add_shape(type=\"line\", x0=xtic, y0=0, x1=xtic, y1=maxY, line=dict(\n", " color=rC, width=1.5, dash=\"dot\"), layer=\"below\")\n", "\n", " for xtic in rrTics:\n", " fig.add_shape(type=\"line\", x0=xtic, y0=0, x1=xtic, y1=maxY,\n", " line=dict(color=rrC, width=1.5, dash=\"dot\"), layer=\"below\")\n", "\n", " fig.add_trace(go.Scatter(name='Addition', x=aTics, y=aYshift,\n", " mode='markers', legendgroup='Building Type', marker=dict(color=aC)))\n", " fig.add_trace(go.Scatter(name='Reconstruction',legendgroup='Building Type', x=rTics, y=rYshift,\n", " mode='markers', marker=dict(color=rC)))\n", " fig.add_trace(go.Scatter(name='Raze and Rebuild',legendgroup='Building Type', x=rrTics,\n", " y=rrYshift, mode='markers', marker=dict(color=rrC)))\n", "\n", "\n", " fig.update_layout(width=widthD,height=heightD, title=title_)\n", " fig.update_yaxes(title=y_title,range=[-0.05, maxY],gridwidth=1, gridcolor=gridBG,zerolinewidth=1,zerolinecolor='lightgrey')\n", "\n", " fig.update_xaxes(title='Simulation tic',gridwidth=1, gridcolor=gridBG,zerolinewidth=1,zerolinecolor='lightgrey')\n", " fig.update_layout(showlegend=True,plot_bgcolor='rgba(0,0,0,0)',legend=dict(orientation='h',yanchor=\"top\", y=1.0, xanchor=\"left\", x=0.03,bgcolor='rgba(255,255,255,0.5)'))\n", "\n", " with out2:\n", " out2.clear_output()\n", " fig.show()" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "5bb7c06f171449f78dfc52b1c620b959", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Output()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "out2 = widgets.Output()\n", "out2" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [], "source": [ "figure_2(1,10)" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "def figure_3(start,end):\n", " widthD=800\n", "\n", " genericGraph = res2.query(f\"tic>={start} & tic<={end}\").copy()\n", " above65C = colorExcel.loc[colorExcel['label']=='65-84','colors_'].values[0]\n", " below65C = colorExcel.loc[colorExcel['label']=='18-44','colors_'].values[0]\n", " averageBelowAgeC = colorExcel.loc[colorExcel['label']=='45-64','colors_'].values[0]\n", " averageAboveAgeC = colorExcel.loc[colorExcel['label']=='85+','colors_'].values[0]\n", " \n", " title_ ='Above and Below 65 troughout the simulation'\n", " y_title = 'Household Percent'\n", " #totalPopC\n", " columnsList = ['AgeYoungStay','AgeOldStay','AgeYoungNew','AgeOldNew','AgeYoungStayNew','AgeOldStayNew']\n", " titlesList = ['Under 65 Stay','Above 65 Stay','Under 65 New Comers','Above 65 New Comers','Under 65 (Average)','Above 65 (Average)']\n", " legendGroup =['Staying','Staying','New Comers','New Comers','Average','Average']\n", " styleList = [dict(color=below65C,width=2),\n", " dict(color=above65C,width=2),\n", " dict(color=below65C,width=4),\n", " dict(color=above65C,width=4),\n", " dict(color=averageBelowAgeC,dash='dash'),\n", " dict(color=averageAboveAgeC, dash='dash')]\n", " percentList=[]\n", " for i in range(6):\n", " percentList.append(f'{columnsList[i]}Percent')\n", " genericGraph[percentList[i]] = genericGraph[columnsList[i]]/genericGraph['TotalAgentsCount']\n", " genericGraph['y_shift'] =-0.02\n", " # Change the bar mode\n", " aTics = genericGraph.loc[genericGraph['prjectType'] == 1, 'tic']\n", " rTics = genericGraph.loc[genericGraph['prjectType'] == 2, 'tic']\n", " rrTics = genericGraph.loc[genericGraph['prjectType'] == 3, 'tic']\n", " \n", " aYshift =genericGraph.loc[genericGraph['prjectType'] == 1, 'y_shift']\n", " rYshift = genericGraph.loc[genericGraph['prjectType'] == 2, 'y_shift']\n", " rrYshift = genericGraph.loc[genericGraph['prjectType'] == 3, 'y_shift']\n", " maxY=1\n", " fig = go.Figure()\n", " for i in range(6):\n", " fig.add_trace(go.Scatter(\n", " x=genericGraph['tic'],\n", " y=genericGraph[percentList[i]],\n", " legendgroup = legendGroup[i],\n", " line=styleList[i],\n", " name=titlesList[i]\n", " ))\n", " for xtic in aTics:\n", " fig.add_shape(type=\"line\", x0=xtic, y0=0, x1=xtic, y1=maxY, line=dict(\n", " color=aC, width=1.5, dash=\"dot\"), layer=\"below\")\n", "\n", " for xtic in rTics:\n", " fig.add_shape(type=\"line\", x0=xtic, y0=0, x1=xtic, y1=maxY, line=dict(\n", " color=rC, width=1.5, dash=\"dot\"), layer=\"below\")\n", "\n", " for xtic in rrTics:\n", " fig.add_shape(type=\"line\", x0=xtic, y0=0, x1=xtic, y1=maxY,\n", " line=dict(color=rrC, width=1.5, dash=\"dot\"), layer=\"below\")\n", "\n", " fig.add_trace(go.Scatter(name='Addition', x=aTics, y=aYshift,\n", " mode='markers', legendgroup='Building Type', marker=dict(color=aC)))\n", " fig.add_trace(go.Scatter(name='Reconstruction',legendgroup='Building Type', x=rTics, y=rYshift,\n", " mode='markers', marker=dict(color=rC)))\n", " fig.add_trace(go.Scatter(name='Raze and Rebuild',legendgroup='Building Type', x=rrTics,\n", " y=rrYshift, mode='markers', marker=dict(color=rrC)))\n", "\n", "\n", " fig.update_layout(width=widthD,height=heightD, title=title_)\n", " fig.update_yaxes(title=y_title,range=[-0.05, maxY],gridwidth=1, gridcolor=gridBG,zerolinewidth=1,zerolinecolor='lightgrey')\n", "\n", " fig.update_xaxes(title='Simulation tic',gridwidth=1, gridcolor=gridBG,zerolinewidth=1,zerolinecolor='lightgrey')\n", " fig.update_layout(showlegend=True,plot_bgcolor='rgba(0,0,0,0)',legend=dict(orientation='h',yanchor=\"top\", y=1.0, xanchor=\"left\", x=0.03,bgcolor='rgba(255,255,255,0.5)'))\n", "\n", " with out3:\n", " out3.clear_output()\n", " fig.show()" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "f265ebd902ca425d9cf8d32666ccac44", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Output()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "out3 = widgets.Output()\n", "out3" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [], "source": [ "def figure_4(start,end):\n", " genericGraph = res2.query(f\"tic>={start} & tic<={end}\").copy()\n", " uniProList = genericGraph['ProjNumber'].unique()\n", " ageIncomeCopy = ageIncome[ageIncome['ProjNumber'].isin(uniProList)].copy()\n", " ageIncomeAgg = ageIncomeCopy.groupby(['simulationState','ageGroup','incomeGroup']).agg({'agentID':'count'}).reset_index()\n", " ageIncomeAgg['Age_income'] = ageIncomeAgg['ageGroup'] + \" \" + ageIncomeAgg['incomeGroup']\n", " ageIncomeAgg.rename(columns={'ageGroup':'Age Group','incomeGroup':'Income Group','agentID':'Count'},inplace=True)\n", "\n", " ageIncomeColr = pd.read_excel(colorAgeIncomeExcel,usecols=['Age_income','color'])\n", " ageIncomeColorDict = dict(zip(ageIncomeColr['Age_income'],ageIncomeColr['color']))\n", " title_ = 'Age Group Vs Income Before and After Renewal'\n", " fig = px.scatter(ageIncomeAgg, x=\"Age Group\", y=\"Income Group\",\n", " size=\"Count\",facet_col='simulationState', title=title_,size_max=30,\n", " category_orders={\"Age Group\": [\"Under 65\",\"Above 65\"],\"Income Group\": ['High Income', 'Medium Income', 'Low Income'],\"simulationState\":['Before Renewal','After Renewal']},color='Age_income',color_discrete_map=ageIncomeColorDict,width=700,height=heightD)\n", " fig.update_yaxes(gridwidth=1, gridcolor='#d9d9d9',zerolinewidth=1,zerolinecolor='lightgrey',title='')\n", " fig.update_xaxes(gridwidth=1, gridcolor='#d9d9d9',zerolinewidth=1,zerolinecolor='lightgrey',title='')\n", " fig.update_layout(plot_bgcolor='#f2f7ff')\n", " fig.layout['annotations'][0]['text'] = 'Before Renewal'\n", " fig.layout['annotations'][1]['text'] = 'After Renewal'\n", " fig.update_traces(showlegend=False)\n", " with out4:\n", " out4.clear_output()\n", " fig.show()" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "24342e136d8e4d30a1c89f1844191fd5", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Output()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "out4 = widgets.Output()\n", "out4" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [], "source": [ "def figure_5(start,end):\n", " startLine = aggResByTic.query(f'tic=={start}')\n", " endLine = aggResByTic.query(f'tic=={end}')\n", " statsDict = {'aprtmentSizeMean:':{'before':round(startLine['aprtmentSizeMean'].values[0],1),\n", " 'after':round(endLine['aprtmentSizeMean'].values[0],1),\n", " 'title':'Apartment Size',\n", " 'units':'sq meters'},\n", " 'yearsInBldgMean:':{'before':round(startLine['yearsInBldgMean'].values[0],1),\n", " 'after':round(endLine['yearsInBldgMean'].values[0],1),\n", " 'title':'Years in Neighborhood',\n", " 'units':'years'},\n", " 'CostForStaying:':{'before':round(startLine['CostForStaying'].values[0],1),\n", " 'after':round(endLine['CostForStaying'].values[0],1),\n", " 'title':'Cost For Staying',\n", " 'units':'₪'},\n", " 'meanIncomeStay_N_new:':{'before':round(startLine['meanIncomeStay_N_new'].values[0],1),\n", " 'after':round(endLine['meanIncomeStay_N_new'].values[0],1),\n", " 'title':'Mean Income',\n", " 'units':'₪'}\n", " }\n", " htmlText = \"\"\n", " for key in statsDict.keys():\n", " htmlText+=(\"\"+f\"{statsDict[key]['title']} Start Marker: {statsDict[key]['before']} {statsDict[key]['units']} End Marker {statsDict[key]['after']} {statsDict[key]['units']}
\")\n", " htmlText = \"
\"+htmlText+\"
\"\n", " Htats = HTML(value=htmlText)\n", " with out5:\n", " out5.clear_output()\n", " display(Htats)" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "aa253c9ce1d04fe78fde0f34a5a77564", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Output()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "out5 = widgets.Output()\n", "out5" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [], "source": [ "def figure_6(end):\n", " projectMovement = movementsByProject[movementsByProject['Tic']['after']==end]\n", " projType = projectMovement['Type of Project']['after'].values[0]\n", " Leaving_Owners = projectMovement['Leaving Owners']['after'].values[0]\n", " Leaving_Renters = projectMovement['Leaving Renters']['after'].values[0]\n", " New_Owners = projectMovement['New Owners']['after'].values[0]\n", " New_Renters = projectMovement['New Renters']['after'].values[0]\n", " Staying = projectMovement['Staying']['after'].values[0]\n", " Total_Households =New_Owners+New_Renters+Staying\n", " Total_Households_before = projectMovement['Total Households']['before'].values[0]\n", "\n", "\n", " if projType>1:\n", " bldX =5\n", " bldY = 1.5\n", " oldBldX = 2.5\n", " oldBldY =1.5\n", " outOwnX = 1\n", " outOwnY = 1.25\n", " outRentX = 1\n", " outRentY = 1.85\n", " inOwnX = 4\n", " inOwnY = 2.25\n", " inRentX = 2\n", " inRentY = 2.25\n", " df = pd.DataFrame({'x':[outOwnX,outRentX,oldBldX,oldBldX,inRentX,inOwnX,bldX],\n", " 'y':[outOwnY,outRentY,oldBldY,oldBldY,inRentY,inOwnY,bldY],\n", " 'Agents':[Leaving_Owners,Leaving_Renters,Total_Households_before,Staying,New_Renters,New_Owners,Total_Households],\n", " 'who':['Leaving Owners','Leaving Renters','Total Before','Surviving Owners','New Renters','New Owners','Total After'],\n", " 'color':['cornflowerblue','lightgreen','lemonchiffon','lightskyblue','green','deepskyblue','white']})\n", " colorDict = dict(zip(df['who'],df['color']))\n", " fig = px.scatter(df, x='x', y='y', color=\"who\",color_discrete_map=colorDict,size='Agents',size_max=50)\n", " #building to Leaving Owners\n", " fig.add_annotation(x=outOwnX,y=outOwnY,ax=oldBldX,ay=oldBldY,xref='x',yref='y',axref='x',ayref='y',arrowcolor='lightgray',text='',showarrow=True,arrowhead=3,arrowsize=1,arrowwidth=3)\n", " #Building Leaving Renters\n", " fig.add_annotation(x=outRentX,y=outRentY,ax=oldBldX,ay=oldBldY,xref='x',yref='y',axref='x',ayref='y',arrowcolor='lightgray',text='',showarrow=True,arrowhead=3,arrowsize=1,arrowwidth=3)\n", " #Entering Owners\n", " fig.add_annotation(x=bldX,y=bldY,ax=inOwnX,ay=inOwnY,xref='x',yref='y',axref='x',ayref='y',arrowcolor='lightgray',text='',showarrow=True,arrowhead=3,arrowsize=1,arrowwidth=3)\n", " #Entering Renters\n", " fig.add_annotation(x=bldX,y=bldY,ax=inRentX,ay=inRentY,xref='x',yref='y',axref='x',ayref='y',arrowcolor='lightgray',text='',showarrow=True,arrowhead=3,arrowsize=1,arrowwidth=3)\n", " # From Old Building to New Building\n", " fig.add_annotation(x=bldX,y=bldY,ax=oldBldX,ay=oldBldY,xref='x',yref='y',axref='x',ayref='y',arrowcolor='lightgray',text='',showarrow=True,arrowhead=3,arrowsize=1,arrowwidth=3)\n", "\n", "\n", " else:\n", " bldX =1.3\n", " bldY = 1.3\n", " outOwnX = 1\n", " outOwnY = 1.25\n", " outRentX = 1.1\n", " outRentY = 1.85\n", " inOwnX = 1.25\n", " inOwnY = 2.25\n", " inRentX = 1.1\n", " inRentY = 2.25\n", " df = pd.DataFrame({'x':[outOwnX,outRentX,bldX,bldX,inRentX,inOwnX,bldX],\n", " 'y':[outOwnY,outRentY,bldY,bldY,inRentY,inRentY,bldY],\n", " 'Agents':[Leaving_Owners,Leaving_Renters,Total_Households_before,Staying,New_Renters,New_Owners,Total_Households],\n", " 'who':['Leaving Owners','Leaving Renters','Total Before','Surviving Owners','New Renters','New Owners','Total After'],\n", " 'color':['cornflowerblue','lightgreen','lemonchiffon','lightskyblue','green','deepskyblue','white']})\n", " colorDict = dict(zip(df['who'],df['color']))\n", " fig = px.scatter(df, x='x', y='y', color=\"who\",color_discrete_map=colorDict,size='Agents',size_max=50)\n", " #building to Leaving Owners\n", " fig.add_annotation(x=outOwnX,y=outOwnY,ax=bldX,ay=bldY,xref='x',yref='y',axref='x',ayref='y',arrowcolor='lightgray',text='',showarrow=True,arrowhead=3,arrowsize=1,arrowwidth=3)\n", " #Building Leaving Renters\n", " fig.add_annotation(x=outRentX,y=outRentY,ax=bldX,ay=bldY,xref='x',yref='y',axref='x',ayref='y',arrowcolor='lightgray',text='',showarrow=True,arrowhead=3,arrowsize=1,arrowwidth=3)\n", " #Entering Owners\n", " fig.add_annotation(x=bldX,y=bldY,ax=inOwnX,ay=inOwnY,xref='x',yref='y',axref='x',ayref='y',arrowcolor='lightgray',text='',showarrow=True,arrowhead=3,arrowsize=1,arrowwidth=3)\n", " #Entering Renters\n", " fig.add_annotation(x=bldX,y=bldY,ax=inRentX,ay=inRentY,xref='x',yref='y',axref='x',ayref='y',arrowcolor='lightgray',text='',showarrow=True,arrowhead=3,arrowsize=1,arrowwidth=3)\n", "\n", "\n", " #old house to displaced owner\n", "\n", "\n", " fig.add_trace(go.Scatter(x=df['x'],y=df['y'],text=df['Agents'],mode=\"text\"))\n", "\n", " fig.update_layout(\n", " margin=dict(l=0, r=0, b=0),\n", " height=400, width=600,\n", " plot_bgcolor=\"white\",\n", " legend=dict(yanchor=\"top\", y=0.95, xanchor=\"left\", x=0.95)\n", " )\n", " fig.update_traces(marker=dict(line=dict(width=2,color='DarkSlateGrey')))\n", " fig.update_yaxes(visible=False, showticklabels=False)\n", " fig.update_xaxes(visible=False, showticklabels=False)\n", " with out6:\n", " out6.clear_output()\n", " fig.show()" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "6e34af6434ec455593882b642d3d4cb4", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Output()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "out6 = widgets.Output()\n", "out6" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [], "source": [ "figure_6(32)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "ename": "NameError", "evalue": "name 'projectMovement' is not defined", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprojectMovement\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;31mNameError\u001b[0m: name 'projectMovement' is not defined" ] } ], "source": [ "projectMovement" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [ { "ename": "NameError", "evalue": "name 'floorsAfter' is not defined", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mfloorsAfter\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;31mNameError\u001b[0m: name 'floorsAfter' is not defined" ] } ], "source": [ "floorsAfter" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "ename": "NameError", "evalue": "name 'bldAfter' is not defined", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mbldAfter\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;31mNameError\u001b[0m: name 'bldAfter' is not defined" ] } ], "source": [ "bldAfter" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "ename": "NameError", "evalue": "name 'projType' is not defined", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprojType\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;31mNameError\u001b[0m: name 'projType' is not defined" ] } ], "source": [ "projType" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [], "source": [ "def figure_7(end):\n", " projectMovement = movementsByProject[movementsByProject['Tic']['after']==end].copy()\n", " projType = projectMovement['Type of Project']['after'].values[0]\n", " bldBefore = projectMovement['bldCode']['before'].values[0]\n", " bldAfter = projectMovement['bldCode']['after'].values[0]\n", " floorsBefore = projectMovement['Avg Floors']['before'].values[0]\n", " floorsAfter = projectMovement['Avg Floors']['after'].values[0]\n", "\n", " bldNumList = [i for i in range(1,int(bldBefore)+1)] + [i for i in range(1,int(bldAfter)+1)]\n", " if projType>1:\n", " floorList = [4 for i in range(1,int(bldBefore)+1)] + [floorsAfter for i in range(1,int(bldAfter)+1)]\n", " else:\n", " floorList = [4 for i in range(1,int(bldBefore)+1)] + [floorsAfter-4 for i in range(1,int(bldAfter)+1)]\n", " beforeAfterList = ['Before' for i in range(1,int(bldBefore)+1)]+ ['after' for i in range(1,int(bldAfter)+1)]\n", " df = pd.DataFrame({'bldCount':bldNumList,'beforeAfter':beforeAfterList,'floors':floorList})\n", " if projType>1:\n", " fig = px.bar(df, x='bldCount', y='floors',color='beforeAfter',facet_col='beforeAfter')\n", " else:\n", " fig = px.bar(df, x='bldCount', y='floors',color='beforeAfter')\n", " fig.update_layout(\n", " margin=dict(l=0, r=0, b=0),\n", " height=300, width=600,\n", " plot_bgcolor=\"oldlace\",\n", " legend=dict(yanchor=\"top\", y=0.95, xanchor=\"left\", x=0.05)\n", " )\n", " fig.update_traces(marker=dict(line=dict(width=2,color='DarkSlateGrey')))\n", "\n", " with out7:\n", " out7.clear_output()\n", " fig.show()" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "9b579554a1ea4d4f967560614b1e1892", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Output()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "out7 = widgets.Output()\n", "out7" ] }, { "cell_type": "code", "execution_count": 46, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "59da72b0c4ae4d0cade2712f972c87d1", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Output()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "out8 = widgets.Output()\n", "out8" ] }, { "cell_type": "code", "execution_count": 47, "metadata": {}, "outputs": [], "source": [ " htmlText = ''\n", " webAppHTML = HTML(value=htmlText)\n", " with out8:\n", " out8.clear_output()\n", " display(webAppHTML)" ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [], "source": [ "def webmapSetup():\n", " webmap = gis.content.get('8a44060b70d243179d6dbd38513cfd70')\n", " wm = WebMap(webmap)\n", " map1 = gis.map()\n", " map1.zoom=16\n", " map1.center = [32.028, 34.743]\n", " map1.basemap='dark-gray-vector'\n", " for item in wm.layers[2:]:\n", " add_item = gis.content.get(item['itemId'])\n", " map1.add_layer(add_item)\n", " add_item = gis.content.get('49d0351f66e341d388eb086c8e575720')\n", " map1.add_layer(add_item)\n", " return map1" ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [], "source": [ "map1 = webmapSetup()" ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [], "source": [ "def figure_9(projRef):\n", " geom = bldgsInwgs84.query(f'project_nu==\"{projRef}\"').copy()\n", " geom['x'] = geom['geometry'].apply(lambda x: x.centroid.x)\n", " geom['y'] = geom['geometry'].apply(lambda x: x.centroid.y)\n", " x = geom['x'].mean()\n", " y = geom['y'].mean()\n", " map1.center = [y,x]\n", " map1.zoom = 17\n", " with out9:\n", " out9.clear_output()\n", " display(map1)\n" ] }, { "cell_type": "code", "execution_count": 42, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "7f8c9e36108649208460f3e2f746ef56", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Output()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "out9 = widgets.Output()\n", "out9\n" ] }, { "cell_type": "code", "execution_count": 43, "metadata": {}, "outputs": [], "source": [ "from arcgis.features import FeatureLayer" ] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [], "source": [ "figure_9('502-0196659')" ] }, { "cell_type": "code", "execution_count": 45, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ]" ] }, "execution_count": 45, "metadata": {}, "output_type": "execute_result" } ], "source": [ "map1.layers" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 738, "metadata": {}, "outputs": [], "source": [ "# for i in range(len(wmLayers)):\n", "# addLayer = wmLayers[i]\n", "# map1.add_layer(addLayer)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "geo_env", "language": "python", "name": "geo_env" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.9" } }, "nbformat": 4, "nbformat_minor": 4 }