コード例 #1
0
ファイル: test_delay.py プロジェクト: tomjanus/pywr
def test_delay_param_load():
    """Test that the `.load` method of `FlowDelayParameter` works correctly"""

    model = Model()
    model.timestepper.start = "2015/01/01"
    model.timestepper.end = "2015/01/31"
    catchment = Catchment(model, name="input", flow=1)
    output = Output(model, name="output")
    catchment.connect(output)

    data = {"name": "delay", "node": "input", "days": 2}

    param = FlowDelayParameter.load(model, data)

    assert param.days == 2

    data = {"name": "delay2", "node": "input", "timesteps": 2}

    param2 = FlowDelayParameter.load(model, data)

    assert param2.timesteps == 2

    expected = np.concatenate([np.zeros(2), np.ones(29)]).reshape(31, 1)

    AssertionRecorder(model, param, name="rec1", expected_data=expected)
    AssertionRecorder(model, param2, name="rec2", expected_data=expected)

    model.setup()
    model.run()
コード例 #2
0
ファイル: nodes.py プロジェクト: rbravov/pywr
    def __init__(self, model, name, **kwargs):
        self.allow_isolated = True
        output_name = "{} Output".format(name)
        input_name = "{} Input".format(name)
        param_name = "{} - delay parameter".format(name)
        assert (output_name not in model.nodes)
        assert (input_name not in model.nodes)
        assert (param_name not in model.parameters)

        days = kwargs.pop('days', 0)
        timesteps = kwargs.pop('timesteps', 0)
        initial_flow = kwargs.pop('initial_flow', 0.0)

        self.output = Output(model, name=output_name)
        self.delay_param = FlowDelayParameter(model,
                                              self.output,
                                              timesteps=timesteps,
                                              days=days,
                                              initial_flow=initial_flow,
                                              name=param_name)
        self.input = Input(model,
                           name=input_name,
                           min_flow=self.delay_param,
                           max_flow=self.delay_param)
        super().__init__(model, name, **kwargs)
コード例 #3
0
ファイル: nodes.py プロジェクト: tomjanus/pywr
    def __init__(self, model, name, **kwargs):
        self.allow_isolated = True
        output_name = "{} Output".format(name)
        input_name = "{} Input".format(name)
        param_name = "{} - delay parameter".format(name)
        assert output_name not in model.nodes
        assert input_name not in model.nodes
        assert param_name not in model.parameters

        days = kwargs.pop("days", 0)
        timesteps = kwargs.pop("timesteps", 0)
        initial_flow = kwargs.pop("initial_flow", 0.0)

        self.output = Output(model, name=output_name, parent=self)
        self.delay_param = FlowDelayParameter(
            model,
            self.output,
            timesteps=timesteps,
            days=days,
            initial_flow=initial_flow,
            name=param_name,
        )
        self.input = Input(
            model,
            name=input_name,
            min_flow=self.delay_param,
            max_flow=self.delay_param,
            parent=self,
        )
        super().__init__(model, name, **kwargs)
コード例 #4
0
ファイル: test_delay.py プロジェクト: tomjanus/pywr
def test_delay_failure(key, delay):
    """Test the FlowDelayParameter returns a ValueError when the input value of the `days` attribute is not
    divisible exactly by the model timestep delta and when the `timesteps` attribute is less than 1
    """

    model = Model()
    model.timestepper.start = "2015/01/01"
    model.timestepper.end = "2015/01/31"
    model.timestepper.delta = 3

    catchment = Catchment(model, name="input", flow=1)
    output = Output(model, name="output")
    catchment.connect(output)

    FlowDelayParameter(model, catchment, **{key: delay})

    with pytest.raises(ValueError):
        model.setup()