Ejemplo n.º 1
0
def load_nomograph_mapping(context: Dict[str, Any]) -> Dict[str, Callable]:

    met_table, msg = load_ref_data("met_table", context)

    data_path = Path(context["data_path"])

    met_context = context.get("project_reference_data", {}).get("met_table")

    vol_nomo_context = met_context["volume_nomo"]
    flow_nomo_context = met_context["flow_nomo"]

    vol_nomos = [
        ("VolumeNomograph", file, vol_nomo_context)
        for file in met_table["volume_nomograph"].unique()
    ]
    flow_nomos = [
        ("FlowNomograph", file, flow_nomo_context)
        for file in met_table["flow_nomograph"].unique()
    ]

    nomo_map = {}
    for obj_name, file, nomo_context in vol_nomos + flow_nomos:
        nomo_map[file] = build_nomo(obj_name, data_path / file, **nomo_context)

    return nomo_map
Ejemplo n.º 2
0
def land_surface_ids():

    context = get_request_context()
    ls_data, _ = load_ref_data("land_surface_table", context)
    ls_ids = ls_data["surface_id"].to_list()

    yield ls_ids
Ejemplo n.º 3
0
def test_get_flow_nomograph(contexts):
    context = contexts["default"]

    met, _ = load_ref_data("met_table", context)
    paths = met["flow_nomograph"].unique()

    for path in paths:
        nomo = get_flow_nomograph(context=context, nomo_path=path)
        tc = 15
        res = nomo(intensity=nomo.nomo.x_data[nomo.nomo.t_data == tc], tc=tc)
        assert all((nomo.nomo.y_data[nomo.nomo.t_data == tc] - res) < 1e-6)
Ejemplo n.º 4
0
def test_get_volume_nomograph(contexts):
    context = contexts["default"]

    met, _ = load_ref_data("met_table", context)
    paths = met["volume_nomograph"].unique()

    for path in paths:
        nomo = get_volume_nomograph(context=context, nomo_path=path)
        ddt = 3
        res = nomo(size=nomo.nomo.x_data[nomo.nomo.t_data == ddt], ddt=ddt)
        assert all((nomo.nomo.y_data[nomo.nomo.t_data == ddt] - res) < 1e-6)
Ejemplo n.º 5
0
def generate_random_land_surface_request(node_list,
                                         context,
                                         sliver_min=5,
                                         sliver_max=25,
                                         **kwargs):
    ls_data, _ = load_ref_data("land_surface_table", context)
    surface_keys = ls_data["surface_id"]

    nodes = []
    for node_id in node_list:
        node = generate_random_land_surface_request_node(
            node_id, surface_keys, sliver_min, sliver_max, **kwargs)
        nodes.extend(node)

    return {"land_surfaces": nodes}
Ejemplo n.º 6
0
def effluent_function_map(
        tablename: str,
        context: Dict[str, Any]) -> Mapping[Tuple[str, str], Callable]:

    df, msg = io.load_ref_data(tablename, context)

    tmnt_context = context.get("project_reference_data", {}).get(tablename, {})

    facility_column = tmnt_context.get("facility_column", "facility_type")
    pollutant_column = tmnt_context.get("pollutant_column", "pollutant")

    eff_conc_map = build_effluent_function_map(df, facility_column,
                                               pollutant_column)

    return eff_conc_map
Ejemplo n.º 7
0
def generate_random_land_surface_request_node(node_id="default",
                                              surface_keys=None,
                                              sliver_min=5,
                                              sliver_max=25,
                                              **kwargs):
    if surface_keys is None:  # pragma: no cover
        ls_data, _ = load_ref_data("land_surface_table", context)
        surface_keys = ls_data["surface_id"]

    node = []
    for _ in range(numpy.random.randint(sliver_min, sliver_max)):
        surface_key = numpy.random.choice(surface_keys)
        sliver = generate_random_land_surface_request_sliver(
            node_id, surface_key, **kwargs)
        node.append(sliver)
    return node
Ejemplo n.º 8
0
def generate_random_treatment_facility_request(node_list, context):

    ls_data, _ = load_ref_data("land_surface_table", context)
    subbasins = ls_data["subbasin"]

    mapping = context["api_recognize"]["treatment_facility"]["facility_type"]
    facility_types = list(mapping.keys())

    nodes = []
    for node_id in node_list:
        facility_type = numpy.random.choice(facility_types)
        model_str = mapping[facility_type]["validator"]
        subbasin = numpy.random.choice(subbasins)
        node = generate_random_treatment_facility_request_node(
            model_str, facility_type, ref_data_key=subbasin, node_id=node_id)
        nodes.append(node)

    return {"treatment_facilities": nodes}