def from_substate_region(region: pipeline.Region, state_fitter: "ModelFitter") -> "RegionalInput": """Creates a RegionalInput for given substate/county region. Args: region: a sub-state region such as a county state_fitter: ModelFitter for the state containing region """ assert region.is_county() assert state_fitter hospitalization_df = load_data.get_hospitalization_data_for_region( region) return RegionalInput( region=region, _combined_data=combined_datasets.RegionalData.from_region(region), _state_mle_fit_result=state_fitter.fit_results, _hospitalization_df=hospitalization_df, )
def get_run_artifact_path(region: Region, artifact, output_dir=None) -> str: """ Get an artifact path for a given locale and artifact type. Parameters ---------- fips: str State or county fips code. Can also be a 2 character state abbreviation. If arbitrary string (e.g. for tests) then passed through artifact: RunArtifact The artifact type to retrieve the pointer for. output_dir: str or NoneType Output directory to obtain the path for. Returns ------- path: str Location of the artifact. """ if region.is_county(): agg_level = AggregationLevel.COUNTY state_obj = region.get_state_region().state_obj() county = combined_datasets.get_county_name(region) elif region.is_state(): agg_level = AggregationLevel.STATE state_obj = region.state_obj() county = None else: raise AssertionError(f"No state_obj for {region}") fips = region.fips artifact = RunArtifact(artifact) output_dir = output_dir or OUTPUT_DIR if artifact is RunArtifact.RT_INFERENCE_REPORT: if agg_level is AggregationLevel.COUNTY: path = os.path.join( REPORTS_FOLDER(output_dir, state_obj.name), f"Rt_results__{state_obj.name}__{county}__{fips}.pdf", ) else: path = os.path.join( STATE_SUMMARY_FOLDER(output_dir), "reports", f"Rt_results__{state_obj.name}__{fips}.pdf", ) elif artifact is RunArtifact.RT_SMOOTHING_REPORT: if agg_level is AggregationLevel.COUNTY: path = os.path.join( REPORTS_FOLDER(output_dir, state_obj.name), f"Rt_smoothing__{state_obj.name}__{county}__{fips}.pdf", ) elif agg_level is AggregationLevel.STATE: path = os.path.join( STATE_SUMMARY_FOLDER(output_dir), "reports", f"Rt_smoothing__{state_obj.name}__{fips}.pdf", ) else: # For tests path = os.path.join( STATE_SUMMARY_FOLDER(output_dir), "reports", f"Rt_smoothing__{state_obj.name}__{fips}.pdf", ) elif artifact is RunArtifact.MLE_FIT_REPORT: if agg_level is AggregationLevel.COUNTY: path = os.path.join( REPORTS_FOLDER(output_dir, state_obj.name), f"mle_fit_results__{state_obj.name}__{county}__{fips}.pdf", ) else: path = os.path.join( STATE_SUMMARY_FOLDER(output_dir), "reports", f"mle_fit_results__{state_obj.name}__{fips}.pdf", ) elif artifact is RunArtifact.WEB_UI_RESULT: path = os.path.join(WEB_UI_FOLDER(output_dir), f"{fips}.__INTERVENTION_IDX__.json") elif artifact is RunArtifact.BACKTEST_RESULT: if agg_level is AggregationLevel.COUNTY: path = os.path.join( REPORTS_FOLDER(output_dir, state_obj.name), f"backtest_results__{state_obj.name}__{county}__{fips}.pdf", ) else: path = os.path.join( STATE_SUMMARY_FOLDER(output_dir), "reports", f"backtest_results__{state_obj.name}__{fips}.pdf", ) else: raise ValueError(f"No paths available for artifact {RunArtifact}") os.makedirs(os.path.dirname(path), exist_ok=True) return path