diff --git a/Makefile b/Makefile index 87ec7ac1..3fff98ae 100755 --- a/Makefile +++ b/Makefile @@ -16,6 +16,7 @@ test: FORCE test_all: FORCE ./scripts/clean.sh ./scripts/lint.sh + ./scripts/test.sh ./scripts/test_notebooks.sh test_notebooks: FORCE diff --git a/data/minneapolis/.pgpass b/data/minneapolis/.pgpass new file mode 100644 index 00000000..ec7b3921 --- /dev/null +++ b/data/minneapolis/.pgpass @@ -0,0 +1 @@ +34.123.100.76:5432:cities:postgres:VA.TlSR#Z%mu**Q9 \ No newline at end of file diff --git a/docs/experimental_notebooks/.Rhistory b/docs/experimental_notebooks/.Rhistory new file mode 100644 index 00000000..e86675ec --- /dev/null +++ b/docs/experimental_notebooks/.Rhistory @@ -0,0 +1,87 @@ +require(dagitty) +# with zones +zones_dag <- dagitty('dag { +year [pos="0,2"] +month [pos="1,2"] +limit_con [pos="2,1"] +parcel_area [pos="2,0"] +ward_id [pos="3.5,0.2"] +zone_id [pos = "1, 0"] +neighborhood_id [pos = "4, 0"] +housing_units [pos = "5,1"] +past_reform [pos ="0, .5"] +past_reform_by_zone [pos = "0,1"] +year -> housing_units +month -> housing_units +limit_con -> housing_units +parcel_area -> housing_units +ward_id -> housing_units +zone_id -> housing_units +neighborhood_id -> housing_units +neighborhood_id -> parcel_area +zone_id -> past_reform_by_zone +zone_id -> parcel_area +past_reform -> past_reform_by_zone +past_reform_by_zone -> limit_con +}') +plot(zones_dag) +paths(zones_dag,"limit_con","housing_units") +adjustmentSets(zones_dag,"limit_con","housing_units",type = "all") +impliedConditionalIndependencies(zones_dag) +#--------------------------------------------------------------------------------------- +# with distances +zones_dag <- dagitty('dag { +year [pos="0,2"] +month [pos="1,2"] +limit_con [pos="2,1"] +parcel_area [pos="2,0"] +ward_id [pos="3.5,0.2"] +zone_id [pos = "1, 0"] +neighborhood_id [pos = "4, 0"] +housing_units [pos = "5,1"] +past_reform [pos ="0, .5"] +past_reform_by_zone [pos = "0,1"] +year -> housing_units +month -> housing_units +limit_con -> housing_units +parcel_area -> housing_units +ward_id -> housing_units +zone_id -> housing_units +neighborhood_id -> housing_units +neighborhood_id -> parcel_area +zone_id -> past_reform_by_zone +zone_id -> parcel_area +past_reform -> past_reform_by_zone +past_reform_by_zone -> limit_con +}') +plot(zones_dag) +paths(zones_dag,"limit_con","housing_units") +adjustmentSets(zones_dag,"limit_con","housing_units",type = "all") +impliedConditionalIndependencies(zones_dag) +require(dagitty) +# with zones +tracts_dag <- dagitty('dag { +year [pos="0,2"] +distance [pos = "0,0"] +total_value [pos = "1,0"] +median_value [pos = "1.2,0.3"] +limit [pos="1,1"] +units [pos = "2,1"] +distance -> limit +distance -> total_value +distance -> median_value +distance -> units +year -> limit +year -> total_value +year -> median_value +year -> units +total_value -> units +median_value -> units +limit -> total_value +limit -> median_value +limit -> units +}') +plot(tracts_dag) +paths(tracts_dag,"limit","units") +adjustmentSets(tracts_dag,"limit","units", type = "all") +impliedConditionalIndependencies(tracts_dag) diff --git a/docs/experimental_notebooks/.Rproj.user/735F60EC/pcs/files-pane.pper b/docs/experimental_notebooks/.Rproj.user/735F60EC/pcs/files-pane.pper new file mode 100644 index 00000000..257a7704 --- /dev/null +++ b/docs/experimental_notebooks/.Rproj.user/735F60EC/pcs/files-pane.pper @@ -0,0 +1,9 @@ +{ + "sortOrder": [ + { + "columnIndex": 2, + "ascending": true + } + ], + "path": "~/s78projects/cities/docs/experimental_notebooks/zoning" +} \ No newline at end of file diff --git a/docs/experimental_notebooks/.Rproj.user/735F60EC/pcs/source-pane.pper b/docs/experimental_notebooks/.Rproj.user/735F60EC/pcs/source-pane.pper new file mode 100644 index 00000000..b074a4fe --- /dev/null +++ b/docs/experimental_notebooks/.Rproj.user/735F60EC/pcs/source-pane.pper @@ -0,0 +1,3 @@ +{ + "activeTab": 1 +} \ No newline at end of file diff --git a/docs/experimental_notebooks/.Rproj.user/735F60EC/pcs/windowlayoutstate.pper b/docs/experimental_notebooks/.Rproj.user/735F60EC/pcs/windowlayoutstate.pper new file mode 100644 index 00000000..5563078a --- /dev/null +++ b/docs/experimental_notebooks/.Rproj.user/735F60EC/pcs/windowlayoutstate.pper @@ -0,0 +1,14 @@ +{ + "left": { + "splitterpos": 463, + "topwindowstate": "NORMAL", + "panelheight": 1120, + "windowheight": 1158 + }, + "right": { + "splitterpos": 694, + "topwindowstate": "NORMAL", + "panelheight": 1120, + "windowheight": 1158 + } +} \ No newline at end of file diff --git a/docs/experimental_notebooks/.Rproj.user/735F60EC/pcs/workbench-pane.pper b/docs/experimental_notebooks/.Rproj.user/735F60EC/pcs/workbench-pane.pper new file mode 100644 index 00000000..d3c76342 --- /dev/null +++ b/docs/experimental_notebooks/.Rproj.user/735F60EC/pcs/workbench-pane.pper @@ -0,0 +1,5 @@ +{ + "TabSet1": 0, + "TabSet2": 1, + "TabZoom": {} +} \ No newline at end of file diff --git a/docs/experimental_notebooks/.Rproj.user/735F60EC/rmd-outputs b/docs/experimental_notebooks/.Rproj.user/735F60EC/rmd-outputs new file mode 100644 index 00000000..3f2ff2d6 --- /dev/null +++ b/docs/experimental_notebooks/.Rproj.user/735F60EC/rmd-outputs @@ -0,0 +1,5 @@ + + + + + diff --git a/docs/experimental_notebooks/.Rproj.user/735F60EC/saved_source_markers b/docs/experimental_notebooks/.Rproj.user/735F60EC/saved_source_markers new file mode 100644 index 00000000..2b1bef11 --- /dev/null +++ b/docs/experimental_notebooks/.Rproj.user/735F60EC/saved_source_markers @@ -0,0 +1 @@ +{"active_set":"","sets":[]} \ No newline at end of file diff --git a/docs/experimental_notebooks/.Rproj.user/735F60EC/sources/per/t/4EAFCA4F b/docs/experimental_notebooks/.Rproj.user/735F60EC/sources/per/t/4EAFCA4F new file mode 100644 index 00000000..fc4c1eb3 --- /dev/null +++ b/docs/experimental_notebooks/.Rproj.user/735F60EC/sources/per/t/4EAFCA4F @@ -0,0 +1,26 @@ +{ + "id": "4EAFCA4F", + "path": "~/s78projects/cities/docs/experimental_notebooks/zoning/tracts_dags.R", + "project_path": "zoning/tracts_dags.R", + "type": "r_source", + "hash": "2157559845", + "contents": "", + "dirty": true, + "created": 1724161369201.0, + "source_on_save": false, + "relative_order": 2, + "properties": { + "source_window_id": "", + "Source": "Source", + "cursorPosition": "21,24", + "scrollLine": "4" + }, + "folds": "", + "lastKnownWriteTime": 1724161086, + "encoding": "UTF-8", + "collab_server": "", + "source_window": "", + "last_content_update": 1724161086, + "read_only": false, + "read_only_alternatives": [] +} \ No newline at end of file diff --git a/docs/experimental_notebooks/.Rproj.user/735F60EC/sources/per/t/4EAFCA4F-contents b/docs/experimental_notebooks/.Rproj.user/735F60EC/sources/per/t/4EAFCA4F-contents new file mode 100644 index 00000000..56daab70 --- /dev/null +++ b/docs/experimental_notebooks/.Rproj.user/735F60EC/sources/per/t/4EAFCA4F-contents @@ -0,0 +1,37 @@ +require(dagitty) + +# with zones +tracts_dag <- dagitty('dag { + year [pos="0,2"] + distance [pos = "0,0"] + total_value [pos = "1,0"] + median_value [pos = "1.2,0.3"] + limit [pos="1,1"] + units [pos = "2,1"] + + distance -> limit + distance -> total_value + distance -> median_value + distance -> units + + year -> limit + year -> total_value + year -> median_value + year -> units + + total_value -> units + median_value -> units + + + limit -> total_value + limit -> median_value + limit -> units + + }') + + + +plot(tracts_dag) +paths(tracts_dag,"limit","units") +adjustmentSets(tracts_dag,"limit","units", type = "all") +impliedConditionalIndependencies(tracts_dag) diff --git a/docs/experimental_notebooks/.Rproj.user/735F60EC/sources/per/t/FFB1EEE4 b/docs/experimental_notebooks/.Rproj.user/735F60EC/sources/per/t/FFB1EEE4 new file mode 100644 index 00000000..1ab31a63 --- /dev/null +++ b/docs/experimental_notebooks/.Rproj.user/735F60EC/sources/per/t/FFB1EEE4 @@ -0,0 +1,26 @@ +{ + "id": "FFB1EEE4", + "path": "~/s78projects/cities/docs/experimental_notebooks/zoning/zoning_dags.R", + "project_path": "zoning/zoning_dags.R", + "type": "r_source", + "hash": "150867923", + "contents": "", + "dirty": false, + "created": 1724161317981.0, + "source_on_save": false, + "relative_order": 1, + "properties": { + "source_window_id": "", + "Source": "Source", + "cursorPosition": "2,2", + "scrollLine": "0" + }, + "folds": "", + "lastKnownWriteTime": 1724161086, + "encoding": "UTF-8", + "collab_server": "", + "source_window": "", + "last_content_update": 1724161086, + "read_only": false, + "read_only_alternatives": [] +} \ No newline at end of file diff --git a/docs/experimental_notebooks/.Rproj.user/735F60EC/sources/per/t/FFB1EEE4-contents b/docs/experimental_notebooks/.Rproj.user/735F60EC/sources/per/t/FFB1EEE4-contents new file mode 100644 index 00000000..eef85bf9 --- /dev/null +++ b/docs/experimental_notebooks/.Rproj.user/735F60EC/sources/per/t/FFB1EEE4-contents @@ -0,0 +1,79 @@ +require(dagitty) + +# with zones +zones_dag <- dagitty('dag { + year [pos="0,2"] + month [pos="1,2"] + limit_con [pos="2,1"] + parcel_area [pos="2,0"] + ward_id [pos="3.5,0.2"] + zone_id [pos = "1, 0"] + neighborhood_id [pos = "4, 0"] + housing_units [pos = "5,1"] + past_reform [pos ="0, .5"] + past_reform_by_zone [pos = "0,1"] + + + year -> housing_units + month -> housing_units + limit_con -> housing_units + parcel_area -> housing_units + ward_id -> housing_units + zone_id -> housing_units + neighborhood_id -> housing_units + + neighborhood_id -> parcel_area + zone_id -> past_reform_by_zone + zone_id -> parcel_area + past_reform -> past_reform_by_zone + past_reform_by_zone -> limit_con + +}') + + + +plot(zones_dag) +paths(zones_dag,"limit_con","housing_units") +adjustmentSets(zones_dag,"limit_con","housing_units",type = "all") +impliedConditionalIndependencies(zones_dag) + + + + +#--------------------------------------------------------------------------------------- +# with distances +zones_dag <- dagitty('dag { + year [pos="0,2"] + month [pos="1,2"] + limit_con [pos="2,1"] + parcel_area [pos="2,0"] + ward_id [pos="3.5,0.2"] + zone_id [pos = "1, 0"] + neighborhood_id [pos = "4, 0"] + housing_units [pos = "5,1"] + past_reform [pos ="0, .5"] + past_reform_by_zone [pos = "0,1"] + + + year -> housing_units + month -> housing_units + limit_con -> housing_units + parcel_area -> housing_units + ward_id -> housing_units + zone_id -> housing_units + neighborhood_id -> housing_units + + neighborhood_id -> parcel_area + zone_id -> past_reform_by_zone + zone_id -> parcel_area + past_reform -> past_reform_by_zone + past_reform_by_zone -> limit_con + +}') + + + +plot(zones_dag) +paths(zones_dag,"limit_con","housing_units") +adjustmentSets(zones_dag,"limit_con","housing_units",type = "all") +impliedConditionalIndependencies(zones_dag) diff --git a/docs/experimental_notebooks/.Rproj.user/735F60EC/sources/prop/B2BF0B6B b/docs/experimental_notebooks/.Rproj.user/735F60EC/sources/prop/B2BF0B6B new file mode 100644 index 00000000..b67e905d --- /dev/null +++ b/docs/experimental_notebooks/.Rproj.user/735F60EC/sources/prop/B2BF0B6B @@ -0,0 +1,6 @@ +{ + "source_window_id": "", + "Source": "Source", + "cursorPosition": "2,2", + "scrollLine": "0" +} \ No newline at end of file diff --git a/docs/experimental_notebooks/.Rproj.user/735F60EC/sources/prop/D2FE184D b/docs/experimental_notebooks/.Rproj.user/735F60EC/sources/prop/D2FE184D new file mode 100644 index 00000000..4102d7f5 --- /dev/null +++ b/docs/experimental_notebooks/.Rproj.user/735F60EC/sources/prop/D2FE184D @@ -0,0 +1,6 @@ +{ + "source_window_id": "", + "Source": "Source", + "cursorPosition": "21,24", + "scrollLine": "4" +} \ No newline at end of file diff --git a/docs/experimental_notebooks/.Rproj.user/735F60EC/sources/prop/INDEX b/docs/experimental_notebooks/.Rproj.user/735F60EC/sources/prop/INDEX new file mode 100644 index 00000000..f24983a6 --- /dev/null +++ b/docs/experimental_notebooks/.Rproj.user/735F60EC/sources/prop/INDEX @@ -0,0 +1,2 @@ +~%2Fs78projects%2Fcities%2Fdocs%2Fexperimental_notebooks%2Fzoning%2Ftracts_dags.R="D2FE184D" +~%2Fs78projects%2Fcities%2Fdocs%2Fexperimental_notebooks%2Fzoning%2Fzoning_dags.R="B2BF0B6B" diff --git a/docs/experimental_notebooks/.Rproj.user/shared/notebooks/patch-chunk-names b/docs/experimental_notebooks/.Rproj.user/shared/notebooks/patch-chunk-names new file mode 100644 index 00000000..e69de29b diff --git a/docs/testing_notebooks/causal_insights_demo.ipynb b/docs/testing_notebooks/causal_insights_demo.ipynb index 61c1d424..a104e02f 100644 --- a/docs/testing_notebooks/causal_insights_demo.ipynb +++ b/docs/testing_notebooks/causal_insights_demo.ipynb @@ -10,8 +10,7 @@ "import random\n", "\n", "from cities.queries.causal_insight import CausalInsight\n", - "from cities.utils.data_grabber import (DataGrabber, list_interventions,\n", - " list_outcomes)\n", + "from cities.utils.data_grabber import DataGrabber, list_interventions, list_outcomes\n", "\n", "smoke_test = \"CI\" in os.environ\n", "num_samples = 10 if smoke_test else 1000" diff --git a/docs/testing_notebooks/slider.ipynb b/docs/testing_notebooks/slider.ipynb index 90691e87..db8a6f79 100644 --- a/docs/testing_notebooks/slider.ipynb +++ b/docs/testing_notebooks/slider.ipynb @@ -6,12 +6,14 @@ "metadata": {}, "outputs": [], "source": [ - "import os \n", + "import os\n", + "\n", + "import numpy as np\n", + "\n", "from cities.queries.causal_insight import CausalInsight as CausalInsight\n", "from cities.queries.causal_insight_slim import CausalInsightSlim as CausalInsightSlim\n", "from cities.utils.data_grabber import DataGrabber\n", "\n", - "import numpy as np\n", "smoke_test = \"CI\" in os.environ\n", "num_samples = 10 if smoke_test else 1000" ] @@ -53,7 +55,7 @@ "intervention = \"spending_commerce\"\n", "year = 2018\n", "\n", - "#the object instantiation doesn't change\n", + "# the object instantiation doesn't change\n", "ci = CausalInsight(\n", " outcome_dataset=outcome,\n", " intervention_dataset=intervention,\n", @@ -61,8 +63,7 @@ ")\n", "\n", "\n", - "\n", - "percent_calc = ci.slider_values_to_interventions(intervened_percent=50, year = year)\n", + "percent_calc = ci.slider_values_to_interventions(intervened_percent=50, year=year)\n", "\n", "display(percent_calc)\n", "\n", @@ -70,12 +71,15 @@ "\n", "ci.get_tau_samples()\n", "\n", - "ci.get_fips_predictions(intervened_value= percent_calc['intervened_transformed'],\n", - " fips=fips, year = year)\n", + "ci.get_fips_predictions(\n", + " intervened_value=percent_calc[\"intervened_transformed\"], fips=fips, year=year\n", + ")\n", "\n", "ci.plot_predictions(range_multiplier=1)\n", "\n", - "assert np.allclose(ci.intervened_value_original, percent_calc['intervened_original'], rtol = 0.01)\n" + "assert np.allclose(\n", + " ci.intervened_value_original, percent_calc[\"intervened_original\"], rtol=0.01\n", + ")" ] }, { @@ -2161,7 +2165,6 @@ } ], "source": [ - "\n", "ci_slim = CausalInsightSlim(\n", " outcome_dataset=outcome,\n", " intervention_dataset=intervention,\n", @@ -2170,17 +2173,21 @@ "\n", "\n", "ci_slim.get_tau_samples()\n", - "ci_slim.get_fips_predictions(intervened_value= percent_calc['intervened_transformed'],\n", - " fips=fips, year = year)\n", + "ci_slim.get_fips_predictions(\n", + " intervened_value=percent_calc[\"intervened_transformed\"], fips=fips, year=year\n", + ")\n", "\n", "ci_slim.plot_predictions(range_multiplier=1)\n", "\n", - "ci_slim.plot_predictions(range_multiplier =1, scaling = \"original\")\n", + "ci_slim.plot_predictions(range_multiplier=1, scaling=\"original\")\n", "\n", - "percent_calc_slim = ci.slider_values_to_interventions(intervened_percent=50, year = year)\n", + "percent_calc_slim = ci.slider_values_to_interventions(intervened_percent=50, year=year)\n", "\n", - "assert np.allclose(ci_slim.intervened_value_original, percent_calc_slim['intervened_original'], rtol = 0.01)\n", - " " + "assert np.allclose(\n", + " ci_slim.intervened_value_original,\n", + " percent_calc_slim[\"intervened_original\"],\n", + " rtol=0.01,\n", + ")" ] } ], diff --git a/docs/testing_notebooks/slim_insight.ipynb b/docs/testing_notebooks/slim_insight.ipynb index 0ad30bd8..0b4e6aea 100644 --- a/docs/testing_notebooks/slim_insight.ipynb +++ b/docs/testing_notebooks/slim_insight.ipynb @@ -6,12 +6,11 @@ "metadata": {}, "outputs": [], "source": [ - "import os\n", "import cProfile\n", + "import os\n", "\n", "from cities.queries.causal_insight import CausalInsight\n", - "from cities.utils.data_grabber import (DataGrabber, list_interventions,\n", - " list_outcomes)\n", + "from cities.utils.data_grabber import DataGrabber, list_interventions, list_outcomes\n", "\n", "smoke_test = \"CI\" in os.environ\n", "num_samples = 10 if smoke_test else 1000" @@ -36,8 +35,8 @@ "data = DataGrabber()\n", "data.get_features_wide([\"gdp\"])\n", "gdp = data.wide[\"gdp\"]\n", - "fips = gdp[\"GeoFIPS\"][5] #1011\n", - "fips2 = gdp[\"GeoFIPS\"][6] #1013" + "fips = gdp[\"GeoFIPS\"][5] # 1011\n", + "fips2 = gdp[\"GeoFIPS\"][6] # 1013" ] }, { @@ -4777,9 +4776,9 @@ "\n", "# confirming that the time consuming moves involve the model\n", "# gettign samples, etc.\n", - "profiler_basic.print_stats(sort='cumulative')\n", + "profiler_basic.print_stats(sort=\"cumulative\")\n", "\n", - "# note: restricting sites to tau drops time from 8s to 5s. " + "# note: restricting sites to tau drops time from 8s to 5s." ] }, { @@ -4800,11 +4799,11 @@ "# this is prep pipeline\n", "print(smoke_test)\n", "ci = CausalInsight(\n", - " outcome_dataset=outcome,\n", - " intervention_dataset=intervention2,\n", - " num_samples=num_samples,\n", - " smoke_test=smoke_test\n", - " )\n", + " outcome_dataset=outcome,\n", + " intervention_dataset=intervention2,\n", + " num_samples=num_samples,\n", + " smoke_test=smoke_test,\n", + ")\n", "ci.generate_tensed_samples()" ] }, @@ -7368,7 +7367,7 @@ } ], "source": [ - "# this is the slim execution \n", + "# this is the slim execution\n", "def slim_run():\n", " ci = CausalInsight(\n", " outcome_dataset=outcome,\n", @@ -7388,7 +7387,7 @@ "profiler_slim.disable()\n", "\n", "\n", - "profiler_slim.print_stats(sort='cumulative')" + "profiler_slim.print_stats(sort=\"cumulative\")" ] } ],