Spaces:
Sleeping

dn commited on
Commit
a762449
·
1 Parent(s): 3ae18ac

README, clinerules, kilo agent

Browse files
Files changed (4) hide show
  1. .clinerules +1 -1
  2. .kilo/plans/1779384655934-witty-wizard.md +126 -0
  3. AGENTS.md +16 -0
  4. README.md +10 -53
.clinerules CHANGED
@@ -13,7 +13,7 @@
13
 
14
  # Pandas Lib Rules
15
  - Prefer vectorization over loops or .apply()
16
- - If you just want to see the schema and some of the data then use `read_file(filename, rows=25)` to reduce the time to open a file
17
 
18
  # Marimo Framework Rules
19
  - Remember that the variables are tied to the cells, so you will need to change variable names if it is in a different cell.
 
13
 
14
  # Pandas Lib Rules
15
  - Prefer vectorization over loops or .apply()
16
+ - If you just want to see the schema and some of the data then use `pd.read_file(filename, rows=25)` to reduce the time to open a file
17
 
18
  # Marimo Framework Rules
19
  - Remember that the variables are tied to the cells, so you will need to change variable names if it is in a different cell.
.kilo/plans/1779384655934-witty-wizard.md ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Refactor `create_buffer_donuts` to use `clip_to_buffer_rings`
2
+
3
+ ## Current State
4
+
5
+ - **`sb79map.py`** (notebook) defines `create_buffer_donuts` inline in `app.setup()`. It:
6
+ 1. Calls `trim_around_stations` 3× for 200ft, 1320ft, 2640ft
7
+ 2. Manually creates donuts via `gpd.overlay(..., how="difference")`
8
+ 3. Concatenates, computes area, assigns zone density, aggregates by APN
9
+
10
+ - **`geoprocessing.py`** has `clip_to_buffer_rings` which does sjoin → overlay(intersection) → donut subtraction — exactly matching steps 1–2 above, but returns results in the buffer CRS and passes full buffer columns to the internal overlay (causing column suffix noise).
11
+
12
+ - **`sb79.py`** already has `ZONE_DENSITIES`, `compute_scag_density`, and `trim_around_stations` (standalone, with its own Tier-renaming logic). The new method belongs here.
13
+
14
+ ## Changes
15
+
16
+ ### 1. `shared/utils/geoprocessing.py` — fix overlay column noise
17
+
18
+ Change line 63 in `clip_to_buffer_rings`:
19
+
20
+ ```
21
+ gpd.overlay( gpd.sjoin(...), buf, how="intersection")
22
+ ^^^
23
+ ```
24
+ →
25
+ ```
26
+ gpd.overlay( gpd.sjoin(...), buf[["geometry"]], how="intersection")
27
+ ```
28
+
29
+ This avoids duplicate columns (with `_1`/`_2` suffixes) in the output. All buffer attributes already flow through from the `gpd.sjoin` step.
30
+
31
+ ### 2. `shared/pipelines/sb79.py` — add `create_buffer_donuts`
32
+
33
+ Add a new function after `compute_scag_density` (around line 180):
34
+
35
+ ```python
36
+ def create_buffer_donuts(
37
+ stops_gdf: gpd.GeoDataFrame,
38
+ scag_density: gpd.GeoDataFrame,
39
+ ) -> gpd.GeoDataFrame:
40
+ ```
41
+
42
+ Logic:
43
+ 1. Trim stops to `["stop_id", "Tier", "geometry"]` (only columns needed)
44
+ 2. Call `clip_to_buffer_rings(scag_density, stops_trimmed, [200, 1320, 2640], "EPSG:2229", "difference")`
45
+ 3. Tag each of the 3 rings with `buffer_zone_id` (`"200ft"`, `"qtr_mi"`, `"half_mi"`)
46
+ 4. `pd.concat` rings into one GDF (`residential`, already in EPSG:2229)
47
+ 5. `area_sqft = residential.area` (no reprojection needed — result is already EPSG:2229)
48
+ 6. Map `zone_density` from `ZONE_DENSITIES` dict via `(buffer_zone_id, Tier)` multi-index
49
+ 7. Aggregate by `APN20` (same vectorized logic as current: weighted density, dwelling units, `unary_union` geometry, `additional_du`)
50
+ 8. Return the result GDF
51
+
52
+ Imports to add at top of `sb79.py`:
53
+ - `from shared.utils.geoprocessing import clip_to_buffer_rings`
54
+
55
+ ### 3. `notebooks/sb79map.py` — replace inline definition with import
56
+
57
+ - **Import**: Add `create_buffer_donuts` to existing import at line 15:
58
+ ```python
59
+ from shared.pipelines.sb79 import assign_tier_to_stops_from_gtfs, compute_scag_density, create_buffer_donuts
60
+ ```
61
+ - **Remove**: Delete the `create_buffer_donuts` function definition at lines 157–267 from `app.setup()`
62
+
63
+ ## Tests
64
+
65
+ ### 1. Existing test updates
66
+
67
+ **`tests/test_geoprocessing.py`** — All 9 existing tests should pass unchanged (they only assert geometry, not columns). The `buf[["geometry"]]` fix is transparent to them.
68
+
69
+ **`tests/test_gtfs_to_parcels.py`** — Change line 9:
70
+ ```python
71
+ from notebooks.sb79map import (
72
+ ...
73
+ create_buffer_donuts, # ← remove from here
74
+ ...
75
+ )
76
+ ```
77
+ →
78
+ ```python
79
+ from shared.pipelines.sb79 import create_buffer_donuts # ← new location
80
+ from notebooks.sb79map import (
81
+ aggregate_parcels_to_stops,
82
+ assign_nearest_stop,
83
+ join_scag_ca_parcels,
84
+ )
85
+ ```
86
+ The existing `test_weighted_density` test calls `create_buffer_donuts` with `(stops, parcels)` — the new function uses the same signature and should produce the same output, so the test will pass without change.
87
+
88
+ ### 2. New tests in `tests/pipelines/test_sb79.py`
89
+
90
+ Add a `TestCreateBufferDonuts` class after `TestTrimAroundStations` (after line 513):
91
+
92
+ #### `test_basic_density` — smoke test (ports existing `test_weighted_density`)
93
+ One stop (Tier 1), one parcel near it. Asserts:
94
+ - `len(result) >= 1`
95
+ - Expected columns present (`new_density_du_per_ac`, `new_dwelling_units`, `current_dwelling_units`, `additional_du`, `buffer_zone_id`)
96
+ - `result["new_density_du_per_ac"].iloc[0] > 0`
97
+ - Parcel intersects the 200ft zone (Tier 1 → 160 du/ac)
98
+
99
+ #### `test_multiple_stops_different_zones`
100
+ Two stops far apart (e.g. 1 mi), a single large parcel spanning both. Asserts:
101
+ - Result has rows for multiple buffer zones
102
+ - Parcel pieces get correct `buffer_zone_id` tags (`"200ft"`, `"qtr_mi"`, `"half_mi"` all present)
103
+
104
+ #### `test_tier_density_mapping`
105
+ Two stops at the same location, one Tier 1, one Tier 2, with separate parcels nearby. Asserts:
106
+ - Tier 1 parcel in 200ft zone → `new_density_du_per_ac` ≈ 160 (from ZONE_DENSITIES)
107
+ - Tier 2 parcel in 200ft zone → `new_density_du_per_ac` ≈ 140
108
+
109
+ #### `test_no_intersection_empty`
110
+ One stop, one parcel far away (e.g. 10 miles). Asserts `len(result) == 0`.
111
+
112
+ #### `test_additional_du`
113
+ One stop Tier 1, one parcel with `current_density_du_per_ac = 10`. Asserts:
114
+ - `result["additional_du"].iloc[0] >= 0` (new - current, clamped at 0)
115
+
116
+ #### `test_multiple_apn_aggregation`
117
+ Two parcels with different APNs, both near the same stop. Asserts:
118
+ - Result has 2 rows (one per APN)
119
+ - Each row has a unique `APN20`
120
+ - `area_acres` is per-APN
121
+
122
+ ### 3. Run after implementation
123
+
124
+ ```bash
125
+ pytest tests/utils/test_geoprocessing.py tests/pipelines/test_sb79.py tests/test_gtfs_to_parcels.py -v
126
+ ```
AGENTS.md ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Python Environment Rule
2
+ - Python environment is managed by uv
3
+ - NEVER run system `python` or `python3` commands directly
4
+ - ALWAYS use `uv run python` to execute scripts and test code
5
+ - ALWAYS use `uv run` for script execution and testing
6
+ - Package management must use `uv add` instead of `pip install`
7
+ - Use `uv pip list` or `uv run pip list` to view installed packages
8
+ - The virtual environment is located at ./venv/
9
+
10
+ # Windows Environment Rules
11
+ - Most dev is done in Windows environment
12
+ - WSL is available for any linux commands that need to be run
13
+
14
+ # Pandas Lib Rules
15
+ - Prefer vectorization over loops or .apply()
16
+ - If you just want to see the schema and some of the data then use `pd.read_file(filename, rows=25)` to reduce the time to open a file
README.md CHANGED
@@ -1,7 +1,7 @@
1
  # Missing Metro Marimo
2
  ## Development
3
 
4
- Using uv, install instructions [in repo](https://github.com/astral-sh/uv)
5
 
6
  ### Setup
7
 
@@ -11,10 +11,17 @@ uv sync
11
  ```
12
 
13
  ### Editing notebook
14
- The marimo VSCode extension is buggy, so open the notebook in watch mode to edit in VSCode and run the notebook in the browser.
15
 
16
  ```bash
17
- marimo edit --watch
 
 
 
 
 
 
 
18
  ```
19
 
20
  ### Running Tests
@@ -30,53 +37,3 @@ uv run ruff check .
30
  uv run ruff format .
31
  ```
32
 
33
-
34
- ## Including data or assets
35
-
36
- To include data or assets in your notebooks, add them to the `public/` directory.
37
-
38
- For example, the `apps/charts.py` notebook loads an image asset from the `public/` directory.
39
-
40
- ```markdown
41
- <img src="public/logo.png" width="200" />
42
- ```
43
-
44
- And the `notebooks/penguins.py` notebook loads a CSV dataset from the `public/` directory.
45
-
46
- ```python
47
- import polars as pl
48
- df = pl.read_csv(mo.notebook_location() / "public" / "penguins.csv")
49
- ```
50
-
51
- ## 🎨 Templates
52
-
53
- This repository includes several templates for the generated site:
54
-
55
- 1. `index.html.j2` (default): A template with styling and a footer
56
- 2. `bare.html.j2`: A minimal template with basic styling
57
- 3. `tailwind.html.j2`: A minimal and lean template using Tailwind CSS
58
-
59
- To use a specific template, pass the `--template` parameter to the build script:
60
-
61
- ```bash
62
- uv run .github/scripts/build.py --template templates/tailwind.html.j2
63
- ```
64
-
65
- You can also create your own custom templates. See the [templates/README.md](templates/README.md) for more information.
66
-
67
- ## Local build/deploy
68
-
69
- To test the export process, run `.github/scripts/build.py` from the root directory.
70
-
71
- ```bash
72
- uv run .github/scripts/build.py
73
- ```
74
-
75
- This will export all notebooks in a folder called `_site/` in the root directory. Then to serve the site, run:
76
-
77
- ```bash
78
- python -m http.server -d _site
79
- ```
80
-
81
- This will serve the site at `http://localhost:8000`.
82
-
 
1
  # Missing Metro Marimo
2
  ## Development
3
 
4
+ Using uv, install instructions [in uv repo](https://github.com/astral-sh/uv)
5
 
6
  ### Setup
7
 
 
11
  ```
12
 
13
  ### Editing notebook
14
+ The marimo VSCode extension is buggy, so run the notebook in the browser.
15
 
16
  ```bash
17
+ # To run all of the notebooks in edit mode
18
+ uv run marimo edit
19
+
20
+ # To run a specific notebook
21
+ uv run marimo edit .\notebooks\sb79map.py
22
+
23
+ # To run a specific notebook in app mode
24
+ uv run marimo run .\notebooks\sb79map.py
25
  ```
26
 
27
  ### Running Tests
 
37
  uv run ruff format .
38
  ```
39