updating disability to match main API - #139
Merged
Merged
Conversation
…requests The Census Data API began requiring an API key on every request as of 2026-05-12. Unauthenticated calls now 302-redirect to an HTML "missing key" page, which requests silently follows and returns as a 200, breaking JSON parsing with a cryptic "Expecting value: line 2 column 1" error. Read the key from the CENSUS_API_KEY environment variable and append it to each request in obtain_census_api. Disable redirect-following so the missing-key 302 is caught directly, detect the X-DataWebAPI-KeyError header to flag an invalid key, and wrap .json() to report non-JSON responses clearly. Keep the key out of logs by printing the URL without it. Add CENSUS_API_KEY.md with signup and env-var setup instructions for macOS, Linux, and Windows.
…rkflow Add two optional flags, generate_figures and generate_codebook, to generate_hui_functions (ncoda_07a) and process_community_workflow (ncoda_07i). Both default to True, so existing IN-CORE runs are completely unchanged. Context: the figure and PDF codebook steps have moved in and out of the use_incore guard a couple of times (a streamlining pass, followed by a revert to keep the codebook pdf). Tying figure and codebook output to use_incore conflates "am I uploading to IN-CORE" with "do I want figures and a codebook" -- and those are not the same question. This change decouples the two concerns. This matters because BRAILS drives the same workflow but only needs the raw housing-unit assignment. It cannot run effectively with figure and codebook generation on. With explicit flags, both sides get what they want without stepping on each other: IN-CORE runs keep figures and the codebook by default, and BRAILS passes generate_figures=False / generate_codebook=False to skip them. No behavior changes unless a caller deliberately opts out.
…ial buildings
In predict_residential_addresspoints (round 2), the per-building weight
used to redistribute a block's surplus housing units, Res_Area, was
assigned only to buildings with residentialAP1 == 1. I believe this is
a bug. It limits the redistribution to single-unit buildings and
excludes every multi-unit building. Two lines earlier in the same
function the residential test is written as residentialAP1 >= 1, and the
binary 'residential' flag is likewise defined with >= 1, so the == 1
here reads like an earlier assumption from when every residential
building received exactly one unit.
A block's surplus is DiffCount1 = census_HU - sum(residentialAP1),
spread as (Res_Area / Sum_Res_Area) * DiffCount1. With Res_Area set only
for == 1 buildings, this produced two distinct issues:
1. Distribution bias. In blocks containing at least one single-unit
building, the whole surplus is dumped onto those single-unit
buildings while multi-unit buildings receive none -- a single-family
home can be inflated to many units while a neighboring apartment
gets nothing. The block total still matches the census, so the
skew is silent.
2. Division-by-zero collapse. In blocks that have residential buildings
but none with exactly one unit (can happen with multi-unit archetypes,
and more so when user-supplied unit counts are used), Res_Area is
0 for every building, so Sum_Res_Area is 0 and residentialAP2 becomes
0/0 = NaN. The block's estimated sum then collapses to 0, the block
is reclassified as Error 5 (HU>0, AP=0), and round 3 falls back to a
single unit per building. The block's real capacity is lost and the
leftover census housing units end up unassigned ('missing building
id').
Fix: assign Res_Area to all residential buildings (residentialAP1 >= 1),
matching the sibling tests in the same function. The surplus is then
spread across every residential building weighted by floor area, so
larger (typically multi-unit) buildings absorb proportionally more.
feat(census-api): require and send CENSUS_API_KEY on Census Data API requests
Make figures/codebook optional and fix block unit-surplus distribution Great fixes and new options. I look forward to reruning to see if it also fixes #issue #133 (#133 (comment)) Note that I do not think that the forrce rerun is needed. If the code iterates with a different seed number the probabilistic elements of the new iteration will be rerun automatically. If the see is the same the run will be identical.
- Added required Census API Key information in the Jupyter notebook. - Updated version references from v2.0.0 to v2.2.0 in generate_hui, generate_addpt, run_hua_workflow, and process_communities scripts. - Adjusted output descriptions to reflect the new versioning.
…spatial join function
…stimation Correct round 3 DiffCount3 calculation to compare expected AP count against residentialAP2v3_sum (final estimated AP total), not building count. Update block_error_check_addresspoints to preserve missing-HU handling with explicit error code 0 (HU = Missing) and avoid duplicate key overwrite. Fix metadata labeling so residential gets its own label/note instead of reusing residentialAP1 metadata. Improves consistency of round-3 diagnostics and block-level error categorization outputs.
…e_addpt.py to ensure unnecessary columns are removed from the address point GeoDataFrame.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Main branch has new API features