|
14 | 14 | from collections import defaultdict |
15 | 15 | from typing import Dict, List, Optional, Tuple |
16 | 16 |
|
| 17 | +import h5py |
17 | 18 | import numpy as np |
18 | 19 | import pandas as pd |
19 | 20 | from scipy import sparse |
@@ -668,6 +669,7 @@ def _process_single_clone( |
668 | 669 | entity_hh_idx_map = sd.get("entity_hh_idx_map", {}) |
669 | 670 | entity_to_person_idx = sd.get("entity_to_person_idx", {}) |
670 | 671 | precomputed_rates = sd.get("precomputed_rates", {}) |
| 672 | + reported_takeup_anchors = sd.get("reported_takeup_anchors", {}) |
671 | 673 |
|
672 | 674 | # Slice geography for this clone |
673 | 675 | clone_states = geo_states[col_start:col_end] |
@@ -789,6 +791,7 @@ def _process_single_clone( |
789 | 791 | ent_blocks, |
790 | 792 | ent_hh_ids, |
791 | 793 | ent_ci, |
| 794 | + reported_mask=reported_takeup_anchors.get(takeup_var), |
792 | 795 | ) |
793 | 796 |
|
794 | 797 | ent_values = (ent_eligible * ent_takeup).astype(np.float32) |
@@ -2132,6 +2135,7 @@ def build_matrix( |
2132 | 2135 | from policyengine_us_data.utils.takeup import ( |
2133 | 2136 | TAKEUP_AFFECTED_TARGETS, |
2134 | 2137 | compute_block_takeup_for_entities, |
| 2138 | + reported_subsidized_marketplace_by_tax_unit, |
2135 | 2139 | ) |
2136 | 2140 | from policyengine_us_data.parameters import ( |
2137 | 2141 | load_take_up_rate, |
@@ -2160,6 +2164,37 @@ def build_matrix( |
2160 | 2164 | "person": person_hh_indices, |
2161 | 2165 | } |
2162 | 2166 |
|
| 2167 | + reported_takeup_anchors = {} |
| 2168 | + with h5py.File(self.dataset_path, "r") as f: |
| 2169 | + period_key = str(self.time_period) |
| 2170 | + if ( |
| 2171 | + "reported_has_subsidized_marketplace_health_coverage_at_interview" |
| 2172 | + in f |
| 2173 | + and period_key |
| 2174 | + in f[ |
| 2175 | + "reported_has_subsidized_marketplace_health_coverage_at_interview" |
| 2176 | + ] |
| 2177 | + ): |
| 2178 | + person_marketplace = f[ |
| 2179 | + "reported_has_subsidized_marketplace_health_coverage_at_interview" |
| 2180 | + ][period_key][...].astype(bool) |
| 2181 | + person_tax_unit_ids = f["person_tax_unit_id"][period_key][...] |
| 2182 | + tax_unit_ids = f["tax_unit_id"][period_key][...] |
| 2183 | + reported_takeup_anchors["takes_up_aca_if_eligible"] = ( |
| 2184 | + reported_subsidized_marketplace_by_tax_unit( |
| 2185 | + person_tax_unit_ids, |
| 2186 | + tax_unit_ids, |
| 2187 | + person_marketplace, |
| 2188 | + ) |
| 2189 | + ) |
| 2190 | + if ( |
| 2191 | + "has_medicaid_health_coverage_at_interview" in f |
| 2192 | + and period_key in f["has_medicaid_health_coverage_at_interview"] |
| 2193 | + ): |
| 2194 | + reported_takeup_anchors["takes_up_medicaid_if_eligible"] = f[ |
| 2195 | + "has_medicaid_health_coverage_at_interview" |
| 2196 | + ][period_key][...].astype(bool) |
| 2197 | + |
2163 | 2198 | entity_to_person_idx = {} |
2164 | 2199 | for entity_level in ("spm_unit", "tax_unit"): |
2165 | 2200 | ent_ids = sim.calculate( |
@@ -2200,6 +2235,7 @@ def build_matrix( |
2200 | 2235 | self.household_ids = household_ids |
2201 | 2236 | self.precomputed_rates = precomputed_rates |
2202 | 2237 | self.affected_target_info = affected_target_info |
| 2238 | + self.reported_takeup_anchors = reported_takeup_anchors |
2203 | 2239 |
|
2204 | 2240 | # 5d. Clone loop |
2205 | 2241 | from pathlib import Path |
@@ -2249,6 +2285,7 @@ def build_matrix( |
2249 | 2285 | shared_data["entity_hh_idx_map"] = entity_hh_idx_map |
2250 | 2286 | shared_data["entity_to_person_idx"] = entity_to_person_idx |
2251 | 2287 | shared_data["precomputed_rates"] = precomputed_rates |
| 2288 | + shared_data["reported_takeup_anchors"] = reported_takeup_anchors |
2252 | 2289 |
|
2253 | 2290 | logger.info( |
2254 | 2291 | "Starting parallel clone processing: %d clones, %d workers", |
@@ -2452,6 +2489,7 @@ def build_matrix( |
2452 | 2489 | ent_blocks, |
2453 | 2490 | ent_hh_ids, |
2454 | 2491 | ent_ci, |
| 2492 | + reported_mask=reported_takeup_anchors.get(takeup_var), |
2455 | 2493 | ) |
2456 | 2494 |
|
2457 | 2495 | ent_values = (ent_eligible * ent_takeup).astype(np.float32) |
|
0 commit comments