def get_run_artifact_path(region: Region, artifact: RunArtifact, 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. """ output_dir = output_dir or OUTPUT_DIR if region.level is AggregationLevel.COUNTY: state_name = region.get_state_region().state_obj().name county = combined_datasets.get_county_name(region) readable_name = f"{state_name}__{county}__{region.fips}" folder = REPORTS_FOLDER(output_dir, state_name) elif region.level is AggregationLevel.STATE: state_name = region.state_obj().name readable_name = f"{state_name}__{region.fips}" folder = os.path.join(STATE_SUMMARY_FOLDER(output_dir), "reports") elif region.level is AggregationLevel.CBSA: readable_name = f"CBSA__{region.fips}" folder = os.path.join(STATE_SUMMARY_FOLDER(output_dir), "reports") elif region.level is AggregationLevel.PLACE: state_name = region.get_state_region().state_obj().name readable_name = f"{state_name}__{region.fips}" folder = os.path.join(STATE_SUMMARY_FOLDER(output_dir), "reports") elif region.level is AggregationLevel.COUNTRY: readable_name = region.country folder = os.path.join(output_dir, "pyseir", "reports") else: raise AssertionError(f"Unsupported aggregation level {region.level}") artifact = RunArtifact(artifact) if artifact is RunArtifact.RT_INFERENCE_REPORT: path = os.path.join(folder, f"Rt_results__{readable_name}.pdf") elif artifact is RunArtifact.RT_SMOOTHING_REPORT: path = os.path.join(folder, f"Rt_smoothing__{readable_name}.pdf") else: raise ValueError(f"No paths available for artifact {RunArtifact}") os.makedirs(os.path.dirname(path), exist_ok=True) return path
def test_get_county_name(): assert combined_datasets.get_county_name(Region.from_fips("06059")) == "Orange County" assert combined_datasets.get_county_name(Region.from_fips("48201")) == "Harris County"
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