Ejemplo n.º 1
0
    def _set_model(self, mdl, skip_validation=False, validate_wltc_data=False):
        from wltp.datamodel import get_model_base, merge

        merged_model = get_model_base()
        merge(merged_model, mdl)
        if not skip_validation:
            datamodel.validate_model(merged_model,
                                     validate_wltc_data=validate_wltc_data)
        self._model = merged_model
Ejemplo n.º 2
0
 def test_default_resistance_coeffs_None(self):
     mdl = goodVehicle()
     mdl["f0"] = mdl["f1"] = mdl["f1"] = None
     mdl = datamodel.merge(datamodel.get_model_base(), mdl)
     with pytest.raises(ValidationError,
                        match="None is not of type 'number'"):
         self.checkModel_valid(mdl)
Ejemplo n.º 3
0
    def testFullLoadCurve_invalid(self):
        import numpy as np
        import pandas as pd

        cases = [
            None,
            [],
            {},
            [[1, 2, 3], [4, 5, 6]],
            np.array([[1, 2, 3], [4, 5, 6]]),
            pd.DataFrame({
                "speed": [10, 11, 12],
                "foo": [1, 2, 3]
            }),
            pd.DataFrame({
                "velocity": [100, 200, 300],
                "alt": [0, 1, 0]
            }),
            #             pd.Series([5,6,'a']),
        ]

        for c in cases:
            mdl = datamodel.get_model_base()
            mdl = datamodel.merge(datamodel.get_model_base(), mdl)
            mdl["wot"] = c
            self.checkModel_invalid(mdl)
Ejemplo n.º 4
0
    def test_validate_wltc_data(self):
        mdl = datamodel.get_model_base()
        mdl = datamodel.merge(mdl, goodVehicle())
        validator = datamodel.model_validator(validate_wltc_data=True,
                                              validate_schema=True)

        validator.validate(mdl)
Ejemplo n.º 5
0
 def test_default_resistance_coeffs_None(self):
     mdl = goodVehicle()
     mdl["f0"] = mdl["f1"] = mdl["f1"] = None
     mdl = datamodel.merge(datamodel.get_model_base(), mdl)
     with pytest.raises(ValidationError,
                        match="'f0' is a required property"):
         self.checkModel_valid(mdl)
Ejemplo n.º 6
0
def testOverlayOnInit():
    mdl = goodVehicle()
    n_rated = 6000
    mdl2 = {"n_rated": n_rated}

    exp = Experiment(datamodel.merge(mdl, mdl2))
    mdl = exp._model
    assert mdl["n_rated"] == n_rated
Ejemplo n.º 7
0
def testFullLoadCurve_invalid(case):
    import numpy as np
    import pandas as pd

    mdl = datamodel.get_model_base()
    mdl = datamodel.merge(datamodel.get_model_base(), mdl)
    mdl["wot"] = case
    _checkModel_invalid(mdl)
Ejemplo n.º 8
0
    def _set_model(self, mdl, skip_validation, validate_wltc_data,
                   additional_properties):
        from wltp.datamodel import get_model_base, merge

        merged_model = get_model_base()
        merge(merged_model, mdl)
        if not skip_validation:
            errors = list(
                datamodel.validate_model(
                    merged_model,
                    validate_wltc_data=validate_wltc_data,
                    additional_properties=additional_properties,
                    iter_errors=True,
                ))
            if errors:
                err_msg = "\n  ".join(str(e) for e in errors)
                raise ValueError(f"Model validation errors: {err_msg}")
        self._model = merged_model
Ejemplo n.º 9
0
 def test_default_resistance_coeffs_missing(self):
     mdl = goodVehicle()
     mdl = datamodel.merge(datamodel.get_model_base(), mdl)
     self.checkModel_valid(mdl)