def test_detailed_land_surface_loading_results( land_surface_loading_response_dicts, contexts, key, n_rows, n_nodes): land_surfaces = land_surface_loading_response_dicts[(n_rows, n_nodes)] land_surfaces_list = land_surfaces["land_surfaces"] df = pandas.DataFrame(land_surfaces_list) context = contexts[key] df["imp_pct"] = 100 * df["imp_area_acres"] / df["area_acres"] df, msg = parse_configuration_logic( df=df, config_section="api_recognize", config_object="land_surfaces", context=context, ) land_surfaces_df = clean_land_surface_dataframe(df) wet_weather_parameters = init_wq_parameters("land_surface_emc_table", context) dry_weather_parameters = init_wq_parameters( "dry_weather_land_surface_emc_table", context) seasons = (context.get("project_reference_data", {}).get("dry_weather_flow_table", {}).get("seasons", {})) t = detailed_loading_results( land_surfaces_df, wet_weather_parameters, dry_weather_parameters, seasons, ) assert t["area_acres"].sum() == land_surfaces_df["area_acres"].sum() assert len(t) == len(land_surfaces_list) if not "no_joins" in key and not "no_params" in key: assert any(["conc" in c for c in t.columns]) assert any(["load" in c for c in t.columns]) t = detailed_volume_loading_results(land_surfaces_df) assert t["area_acres"].sum() == land_surfaces_df["area_acres"].sum() assert len(t) == len(land_surfaces_list) assert t["runoff_volume_cuft"].sum() > 0 t = detailed_pollutant_loading_results( land_surfaces_df, wet_weather_parameters, dry_weather_parameters, seasons.keys(), ) assert t["area_acres"].sum() == land_surfaces_df["area_acres"].sum() assert len(t) == len(land_surfaces_list) if not "no_joins" in key and not "no_params" in key: assert any(["conc" in c for c in t.columns]) assert any(["load" in c for c in t.columns])
def land_surface_loading( land_surfaces: Dict[str, Any], details: bool, context: Dict[str, Any] ) -> Dict[str, List]: """computes loading for volume runoff and pollutants for each land surface 'sliver' and aggregates values for each node. Returning results for the slivers is toggled by the `details` kwarg. if 'true' the resonse includes a 'details' key with the sliver loading. the 'summary' values aggregate the load to each node_id, and are always returned. """ df = pandas.DataFrame(land_surfaces["land_surfaces"]) df["imp_pct"] = 100 * df["imp_area_acres"] / df["area_acres"] response: Dict[str, Any] = {} response["errors"] = [] df, messages = parse_configuration_logic( df=df, config_section="api_recognize", config_object="land_surfaces", context=context, ) if len(messages) > 0: response["errors"].extend(messages) wet_weather_parameters = init_wq_parameters("land_surface_emc_table", context) dry_weather_parameters = init_wq_parameters( "dry_weather_land_surface_emc_table", context ) seasons = ( context.get("project_reference_data", {}) .get("dry_weather_flow_table", {}) .get("seasons", {}) ) detailed_results = detailed_loading_results( df, wet_weather_parameters, dry_weather_parameters, seasons, ) summary_results = summary_loading_results( detailed_results, wet_weather_parameters, dry_weather_parameters, season_names=seasons.keys(), ) response["summary"] = summary_results.fillna(0).to_dict(orient="records") if details: response["details"] = detailed_results.fillna(0).to_dict(orient="records") return response
def test_build_treatment_facility_nodes_from_long_list( contexts, valid_treatment_facilities, ctxt_key, has_met_data): context = contexts[ctxt_key] tmnt_facilities = pandas.DataFrame(valid_treatment_facilities) df, messages = parse_configuration_logic( df=tmnt_facilities, config_section="api_recognize", config_object="treatment_facility", context=context, ) nodes = build_treatment_facility_nodes(df) for n in nodes: if has_met_data: assert n.get("rain_gauge") is not None else: assert n.get("rain_gauge") is None
def test_build_diversion_facility_months_operational( contexts, valid_treatment_facilities, months_operational, is_zero): context = contexts["default"] tmnt_facilities = (pandas.DataFrame(valid_treatment_facilities).query( "facility_type=='LowFlowFacility'").assign( months_operational=months_operational)) df, messages = parse_configuration_logic( df=tmnt_facilities, config_section="api_recognize", config_object="treatment_facility", context=context, ) nodes = build_treatment_facility_nodes(df) for n in nodes: if is_zero: assert n.get("summer_dry_weather_retention_rate_cfs") == 0.0 else: assert n.get("summer_dry_weather_retention_rate_cfs") > 0.0
def test_build_treatment_facility_nodes(contexts, valid_treatment_facility_dicts, ctxt_key, has_met_data, model, checkfor): context = contexts[ctxt_key] tmnt_facilities = pandas.DataFrame([valid_treatment_facility_dicts[model]]) df, messages = parse_configuration_logic( df=pandas.DataFrame(tmnt_facilities), config_section="api_recognize", config_object="treatment_facility", context=context, ) node = build_treatment_facility_nodes(df)[0] check_val = node.get(checkfor) assert isinstance(check_val, float) if has_met_data: assert node.get("rain_gauge") is not None else: assert node.get("rain_gauge") is None