Example #1
0
def test_error_for_to_many_with_depression():
    """Check that an error is thrown when to_many methods started DF."""

    mg0 = RasterModelGrid((10, 10), spacing=(1, 1))
    z0 = mg0.add_field("topographic__elevation",
                       mg0.node_x**2 + mg0.node_y**2,
                       at="node")

    mg1 = RasterModelGrid((10, 10), spacing=(1, 1))
    z1 = mg1.add_field("topographic__elevation",
                       mg1.node_x**2 + mg1.node_y**2,
                       at="node")

    with pytest.raises(NotImplementedError):
        FlowAccumulator(mg0,
                        flow_director="MFD",
                        depression_finder="DepressionFinderAndRouter")
    with pytest.raises(NotImplementedError):
        FlowAccumulator(mg0,
                        flow_director="DINF",
                        depression_finder="DepressionFinderAndRouter")

    fa0 = FlowAccumulator(mg0, flow_director="MFD")
    fa0.run_one_step()
    with pytest.raises(NotImplementedError):
        DepressionFinderAndRouter(mg0)

    fa1 = FlowAccumulator(mg1, flow_director="DINF")
    fa1.run_one_step()
    with pytest.raises(NotImplementedError):
        DepressionFinderAndRouter(mg1)
def test_error_for_to_many_with_depression():
    """Check that an error is thrown when to_many methods started DF."""

    mg0 = RasterModelGrid((10, 10), spacing=(1, 1))
    z0 = mg0.add_field('topographic__elevation',
                       mg0.node_x**2 + mg0.node_y**2,
                       at='node')

    mg1 = RasterModelGrid((10, 10), spacing=(1, 1))
    z1 = mg1.add_field('topographic__elevation',
                       mg1.node_x**2 + mg1.node_y**2,
                       at='node')

    with pytest.raises(ValueError):
        FlowAccumulator(mg0,
                        flow_director='MFD',
                        depression_finder='DepressionFinderAndRouter')
    with pytest.raises(ValueError):
        FlowAccumulator(mg0,
                        flow_director='DINF',
                        depression_finder='DepressionFinderAndRouter')

    fa0 = FlowAccumulator(mg0, flow_director='MFD')
    fa0.run_one_step()
    with pytest.raises(ValueError):
        DepressionFinderAndRouter(mg0)

    fa1 = FlowAccumulator(mg1, flow_director='DINF')
    fa1.run_one_step()
    with pytest.raises(ValueError):
        DepressionFinderAndRouter(mg1)
Example #3
0
def test_depression_finder_as_instance():
    mg = RasterModelGrid((5, 5), spacing=(1, 1))
    z = mg.add_field("topographic__elevation",
                     mg.node_x + mg.node_y,
                     at="node")
    df = DepressionFinderAndRouter(mg)
    fa = FlowAccumulator(mg, flow_director="D8", depression_finder=df)
def test_instantiated_depression_finder_with_kwargs():
    mg = RasterModelGrid((5, 5), xy_spacing=(1, 1))
    mg.add_field("topographic__elevation", mg.node_x + mg.node_y, at="node")
    df = DepressionFinderAndRouter(mg)
    with pytest.raises(ValueError):
        LossyFlowAccumulator(
            mg, flow_director="D8", depression_finder=df, routing="eggs"
        )
def test_specifying_routing_method_wrong():
    """Test specifying incorrect method for routing compatability with DepressionFinderAndRouter."""
    mg = RasterModelGrid((10, 10), xy_spacing=(1, 1))
    mg.add_field("topographic__elevation", mg.node_x + mg.node_y, at="node")

    with pytest.raises(ValueError):
        LossyFlowAccumulator(
            mg, flow_director="D4", depression_finder="DepressionFinderAndRouter"
        )

    df = DepressionFinderAndRouter(mg)
    with pytest.raises(ValueError):
        LossyFlowAccumulator(mg, flow_director="D4", depression_finder=df)
def test_specifying_routing_method_wrong():
    """Test specifying incorrect method for routing compatability with DepressionFinderAndRouter."""
    mg = RasterModelGrid((10, 10), spacing=(1, 1))
    z = mg.add_field('topographic__elevation',
                     mg.node_x + mg.node_y,
                     at='node')

    with pytest.raises(ValueError):
        FlowAccumulator(mg,
                        flow_director='D4',
                        depression_finder='DepressionFinderAndRouter')

    df = DepressionFinderAndRouter(mg)
    with pytest.raises(ValueError):
        FlowAccumulator(mg, flow_director='D4', depression_finder=df)