import%20marimo%0A%0A__generated_with%20%3D%20%220.23.9%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22)%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20%23%20St.%20Petersburg%20%E2%80%94%20social%20vulnerability%20(FEMA%20NRI%20SOVI)%0A%0A%20%20%20%20A%20**census-tract%20choropleth**%20of%20Social%20Vulnerability%20(SOVI)%20from%20the%20FEMA%20National%0A%20%20%20%20Risk%20Index.%20SOVI%20is%20an%20*areal*%20measure%20%E2%80%94%20one%20score%20per%20tract%20(~a%20few%20thousand%20people)%2C%0A%20%20%20%20not%20a%20point%20value%20%E2%80%94%20so%20it's%20drawn%20as%20shaded%20tract%20polygons%2C%20the%20natural%20way%20to%20read%20it.%0A%0A%20%20%20%20**What%20SOVI%20is%3A**%20a%20composite%20of%20census%20characteristics%20(poverty%2C%20age%2C%20disability%2C%0A%20%20%20%20housing%2Ftransport%20access%2C%20etc.)%20%E2%80%94%20higher%20%3D%20a%20population%20*less%20able%20to%20prepare%20for%20and%0A%20%20%20%20recover%20from*%20a%20disaster.%20It's%20a%20**community%2Fpopulation**%20measure%2C%20**not**%20a%20property%0A%20%20%20%20or%20physical-risk%20measure.%20Read%20it%20as%20neighborhood%20character%2C%20alongside%20(not%20instead%20of)%0A%20%20%20%20the%20flood%2Fwind%20layers.%0A%0A%20%20%20%20Source%3A%20%60risk_index%60%20(%60ingest_nri.py%60)%20for%20the%20scores%3B%20tract%20boundary%20polygons%20pulled%0A%20%20%20%20from%20the%20same%20NRI%20FeatureServer%20(cached%20under%20%60data%2Fnri%2F%60%2C%20gitignored).%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20from%20pathlib%20import%20Path%0A%20%20%20%20from%20urllib.request%20import%20urlopen%0A%0A%20%20%20%20import%20altair%20as%20alt%0A%20%20%20%20import%20duckdb%0A%20%20%20%20import%20geopandas%20as%20gpd%0A%20%20%20%20import%20marimo%20as%20mo%0A%0A%20%20%20%20return%20Path%2C%20alt%2C%20duckdb%2C%20gpd%2C%20mo%2C%20urlopen%0A%0A%0A%40app.cell%0Adef%20_(Path%2C%20duckdb)%3A%0A%20%20%20%20def%20_find_root()%20-%3E%20Path%3A%0A%20%20%20%20%20%20%20%20for%20d%20in%20%5BPath.cwd()%2C%20*Path.cwd().parents%5D%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20(d%20%2F%20%22analytics.db%22).exists()%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return%20d%0A%20%20%20%20%20%20%20%20raise%20FileNotFoundError(%22analytics.db%20not%20found%20walking%20up%20from%20cwd%22)%0A%0A%20%20%20%20ROOT%20%3D%20_find_root()%0A%20%20%20%20conn%20%3D%20duckdb.connect(str(ROOT%20%2F%20%22analytics.db%22)%2C%20read_only%3DTrue)%20%20%23%20read-only%3A%20project%20convention%0A%20%20%20%20return%20ROOT%2C%20conn%0A%0A%0A%40app.cell%0Adef%20_(conn)%3A%0A%20%20%20%20%23%20The%2097%20census%20tracts%20that%20contain%20St-Pete%20parcels%20(tract%20%3D%20first%2011%20digits%20of%20the%0A%20%20%20%20%23%20block-group%20FIPS).%20Used%20to%20clip%20the%20Pinellas%20tract%20polygons%20to%20the%20city.%0A%20%20%20%20stpete_tracts%20%3D%20(%0A%20%20%20%20%20%20%20%20conn.execute(%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20%20%20%20%20SELECT%20DISTINCT%20LEFT(pbg.block_group%2C%2011)%20AS%20tract_fips%0A%20%20%20%20%20%20%20%20%20%20%20%20FROM%20parcels%20p%0A%20%20%20%20%20%20%20%20%20%20%20%20JOIN%20parcel_block_group%20pbg%20ON%20p.parcel_id%20%3D%20pbg.parcel_id%0A%20%20%20%20%20%20%20%20%20%20%20%20WHERE%20p.municipality%20%3D%20'ST%20PETERSBURG'%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20).fetchdf()%5B%22tract_fips%22%5D.tolist()%0A%20%20%20%20)%0A%20%20%20%20return%20(stpete_tracts%2C)%0A%0A%0A%40app.cell%0Adef%20_(ROOT%2C%20gpd%2C%20stpete_tracts%2C%20urlopen)%3A%0A%20%20%20%20%23%20Tract%20polygons%20%2B%20SOVI%20from%20the%20NRI%20FeatureServer%20(GeoJSON%2C%20WGS84)%2C%20cached%20locally.%0A%20%20%20%20GEO%20%3D%20ROOT%20%2F%20%22data%22%20%2F%20%22nri%22%20%2F%20%22pinellas_tracts_sovi.geojson%22%0A%20%20%20%20if%20not%20GEO.exists()%3A%0A%20%20%20%20%20%20%20%20GEO.parent.mkdir(parents%3DTrue%2C%20exist_ok%3DTrue)%0A%20%20%20%20%20%20%20%20_url%20%3D%20(%0A%20%20%20%20%20%20%20%20%20%20%20%20%22https%3A%2F%2Fservices.arcgis.com%2FXG15cJAlne2vxtgt%2Farcgis%2Frest%2Fservices%2F%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%22National_Risk_Index_Census_Tracts%2FFeatureServer%2F0%2Fquery%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%3Fwhere%3DSTCOFIPS%253D%252712103%2527%26outFields%3DTRACTFIPS%2CSOVI_SCORE%2CSOVI_RATNG%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%26returnGeometry%3Dtrue%26outSR%3D4326%26f%3Dgeojson%22%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20with%20urlopen(_url)%20as%20r%2C%20open(GEO%2C%20%22wb%22)%20as%20f%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20f.write(r.read())%0A%0A%20%20%20%20tracts%20%3D%20gpd.read_file(GEO)%0A%20%20%20%20tracts%20%3D%20tracts%5Btracts%5B%22TRACTFIPS%22%5D.isin(stpete_tracts)%5D.copy()%0A%20%20%20%20tracts%5B%22geometry%22%5D%20%3D%20tracts.geometry.simplify(0.0003)%20%20%23%20~30%20m%3A%20trims%20embed%20size%0A%20%20%20%20tracts%0A%20%20%20%20return%20(tracts%2C)%0A%0A%0A%40app.cell%0Adef%20_(alt%2C%20mo%2C%20tracts)%3A%0A%20%20%20%20_chart%20%3D%20(%0A%20%20%20%20%20%20%20%20alt.Chart(tracts)%0A%20%20%20%20%20%20%20%20.mark_geoshape(stroke%3D%22white%22%2C%20strokeWidth%3D0.5)%0A%20%20%20%20%20%20%20%20.encode(%0A%20%20%20%20%20%20%20%20%20%20%20%20color%3Dalt.Color(%22SOVI_SCORE%3AQ%22%2C%20title%3D%22SOVI%20score%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20scale%3Dalt.Scale(scheme%3D%22yelloworangered%22%2C%20domain%3D%5B0%2C%20100%5D))%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20tooltip%3D%5Balt.Tooltip(%22TRACTFIPS%3AN%22%2C%20title%3D%22tract%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20alt.Tooltip(%22SOVI_SCORE%3AQ%22%2C%20format%3D%22.0f%22%2C%20title%3D%22SOVI%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20alt.Tooltip(%22SOVI_RATNG%3AN%22%2C%20title%3D%22rating%22)%5D%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20.properties(width%3D640%2C%20height%3D640%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20title%3Df%22St-Pete%20social%20vulnerability%20(NRI%20SOVI)%20%E2%80%94%20%7Blen(tracts)%7D%20census%20tracts%22)%0A%20%20%20%20%20%20%20%20%23%20identity%20(planar)%20projection%3A%20draw%20the%20lon%2Flat%20rings%20as%20flat%20paths.%20A%20spherical%0A%20%20%20%20%20%20%20%20%23%20projection%20(e.g.%20mercator)%20interprets%20ring%20winding%20on%20the%20globe%2C%20where%20one%0A%20%20%20%20%20%20%20%20%23%20wrongly-wound%20tract%20reads%20as%20%22everywhere%20but%20here%22%20and%20floods%20the%20whole%20frame.%0A%20%20%20%20%20%20%20%20.project(type%3D%22identity%22%2C%20reflectY%3DTrue)%0A%20%20%20%20)%0A%20%20%20%20mo.vstack(%5B_chart%2C%20mo.md(%0A%20%20%20%20%20%20%20%20%22Each%20shape%20is%20a%20census%20tract%20shaded%20by%20SOVI%20(darker%20%3D%20more%20vulnerable).%20%22%0A%20%20%20%20%20%20%20%20%22Vulnerability%20concentrates%20in%20**south%20and%20inner%20St%20Pete**%20(and%20parts%20of%20the%20beach)%3B%20%22%0A%20%20%20%20%20%20%20%20%22the%20high-and-dry%20ridge%20(33713%2F33710)%20and%20near-north%20read%20pale.%20SOVI%20describes%20the%20%22%0A%20%20%20%20%20%20%20%20%22*community*%2C%20not%20the%20property%20%E2%80%94%20its%20relationship%20to%20flood%20exposure%20is%20mixed%2C%20so%20%22%0A%20%20%20%20%20%20%20%20%22overlay%20it%20on%20the%20risk%20layers%20rather%20than%20reading%20it%20as%20physical%20risk.%22%0A%20%20%20%20)%5D)%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
2170c8924609734f3ed51b708db51d56