1818 reported_subsidized_marketplace_by_tax_unit ,
1919)
2020
21+ from .builder import PayloadPostProcessorSpec
2122from .payload import H5Payload , PayloadBuildContext
2223from .selection import CloneSelection
2324from .simulation_access import calculate_variable_values
2425from .variables import GEOGRAPHY_VARIABLES
2526
2627__all__ = [
2728 "TAKEUP_VARIABLE_ENTITIES" ,
29+ "US_ENTITY_POSTPROCESSOR_KEY" ,
30+ "US_GEOGRAPHY_POSTPROCESSOR_KEY" ,
31+ "US_TAKEUP_POSTPROCESSOR_KEY" ,
2832 "USEntityPostProcessor" ,
2933 "USEntityPostProcessorResult" ,
3034 "USGeographyPostProcessor" ,
4246 str (spec ["variable" ]): str (spec ["entity" ]) for spec in SIMPLE_TAKEUP_VARS
4347}
4448REQUIRED_TAKEUP_SUBENTITIES = ("tax_unit" , "spm_unit" )
49+ US_ENTITY_POSTPROCESSOR_KEY = "us_entity"
50+ US_GEOGRAPHY_POSTPROCESSOR_KEY = "us_geography"
51+ US_TAKEUP_POSTPROCESSOR_KEY = "us_takeup"
4552
4653
4754@pipeline_node (
@@ -141,6 +148,8 @@ def data(self) -> PayloadData:
141148class USEntityPostProcessor :
142149 """Apply US entity IDs and calibrated household weights."""
143150
151+ spec = PayloadPostProcessorSpec (key = US_ENTITY_POSTPROCESSOR_KEY )
152+
144153 def apply (
145154 self ,
146155 * ,
@@ -192,6 +201,8 @@ def apply(
192201class USGeographyPostProcessor :
193202 """Apply block-derived US geography overrides."""
194203
204+ spec = PayloadPostProcessorSpec (key = US_GEOGRAPHY_POSTPROCESSOR_KEY )
205+
195206 geography_deriver : GeographyDeriver = derive_geography_from_blocks
196207 _string_geography_variables : tuple [str , ...] = field (
197208 default = GEOGRAPHY_VARIABLES ,
@@ -295,6 +306,10 @@ def _apply_los_angeles_zip_patch(
295306class USTakeupPostProcessor :
296307 """Apply US take-up draws after entity and geography postprocessing."""
297308
309+ spec = PayloadPostProcessorSpec (
310+ key = US_TAKEUP_POSTPROCESSOR_KEY ,
311+ requires = (US_ENTITY_POSTPROCESSOR_KEY , US_GEOGRAPHY_POSTPROCESSOR_KEY ),
312+ )
298313 takeup_applier : TakeupApplier = apply_block_takeup_to_arrays
299314 sum_person_values_to_tax_units : Callable [
300315 [np .ndarray , np .ndarray , np .ndarray ],
@@ -312,6 +327,7 @@ def apply(
312327 self ._validate_required_subentities (context )
313328 output = _copy_payload (payload .data )
314329 time_period = context .time_period
330+ self ._validate_required_payload_fields (output , time_period )
315331 results = self ._build_takeup_results (output , context )
316332 takeup_variables = tuple (str (variable ) for variable in results )
317333 self ._validate_takeup_variables (takeup_variables )
@@ -349,6 +365,32 @@ def _validate_required_subentities(self, context: PayloadBuildContext) -> None:
349365 f"US take-up requires reindexed subentities: { ', ' .join (missing )} "
350366 )
351367
368+ def _validate_required_payload_fields (
369+ self ,
370+ data : PayloadData ,
371+ time_period : int ,
372+ ) -> None :
373+ _required_period_array (
374+ data ,
375+ "state_fips" ,
376+ time_period ,
377+ "US take-up requires state_fips from USGeographyPostProcessor" ,
378+ )
379+ if _has_period_array (
380+ data ,
381+ "reported_has_subsidized_marketplace_health_coverage_at_interview" ,
382+ time_period ,
383+ ):
384+ for variable in ("person_tax_unit_id" , "tax_unit_id" ):
385+ _required_period_array (
386+ data ,
387+ variable ,
388+ time_period ,
389+ "US take-up reported ACA anchors require "
390+ "person_tax_unit_id and tax_unit_id from "
391+ "USEntityPostProcessor" ,
392+ )
393+
352394 def _build_takeup_results (
353395 self ,
354396 data : PayloadData ,
@@ -481,6 +523,14 @@ def _required_period_array(
481523 return np .asarray (data [variable ][time_period ])
482524
483525
526+ def _has_period_array (
527+ data : Mapping [str , Mapping [Any , np .ndarray ]],
528+ variable : str ,
529+ time_period : int ,
530+ ) -> bool :
531+ return variable in data and time_period in data [variable ]
532+
533+
484534def _build_reported_takeup_anchors (
485535 data : Mapping [str , Mapping [Any , np .ndarray ]],
486536 time_period : int ,
0 commit comments