Skip to content

Commit

Permalink
ENH(mdl): check wot <= n_min_set, REORDER nmins before wot validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ankostis committed Aug 11, 2019
1 parent 9c153b3 commit 3b02b70
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
12 changes: 10 additions & 2 deletions tests/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,17 @@ def test_validate_wot_errors(mdl, wot, n_idle, n_rated, p_rated, err):
p_rated = mdl["p_rated"]
wot = engine.denorm_wot(wot, n_idle, n_rated, p_rated)
wot = engine.norm_wot(wot, n_idle, n_rated, p_rated)
n_min_drive_set = None
with pytest.raises(type(err), match=str(err)):
for err in engine.validate_wot(wot, n_idle, n_rated, p_rated):
raise err
for verr in engine.validate_wot(wot, n_idle, n_rated, p_rated, n_min_drive_set):
raise verr

n_min_drive_set = n_idle + 0.125 * (n_rated - n_idle)
with pytest.raises(type(err), match=str(err)):
for verr in engine.validate_wot(wot, n_idle, n_rated, p_rated, n_min_drive_set):
raise verr

## Needs more tests.


@pytest.mark.parametrize(
Expand Down
10 changes: 8 additions & 2 deletions wltp/datamodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,8 +883,8 @@ def validate_model(
)
validators = [
validator.iter_errors(mdl),
yield_load_curve_errors(mdl),
yield_n_min_errors(mdl),
yield_load_curve_errors(mdl),
yield_forced_cycle_errors(mdl, additional_properties),
]
errors = it.chain(*[v for v in validators if not v is None])
Expand Down Expand Up @@ -934,7 +934,8 @@ def yield_load_curve_errors(mdl):
yield ValidationError(f"Failed (de)normalizing wot due to: {ex}")
return

for err in engine.validate_wot(wot, n_idle, n_rated, p_rated):
n_min_drive_set = mdl.get(d.n_min_drive_set)
for err in engine.validate_wot(wot, n_idle, n_rated, p_rated, n_min_drive_set):
raise err


Expand All @@ -950,6 +951,11 @@ def yield_n_min_errors(mdl):
# Bail out, jsonschema errors already reported.
return

if mdl[d.n_rated] <= mdl[d.n_idle]:
yield ValidationError(
f"n_idle({mdl[d.n_idle]}) is higher than n_rated({mdl[d.n_rated]}!"
)

try:
nmins = engine.calc_fixed_n_min_drives(mdl, mdl[d.n_idle], mdl[d.n_rated])
for n in (
Expand Down
17 changes: 14 additions & 3 deletions wltp/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ def parse_wot(wot) -> pd.DataFrame:
return wot


def validate_wot(wot: pd.DataFrame, n_idle, n_rated, p_rated) -> pd.DataFrame:
def validate_wot(
wot: pd.DataFrame, n_idle, n_rated, p_rated, n_min_drive_set
) -> pd.DataFrame:
"""Higher-level validation of the wot-curves with repect to model."""
w = wio.pstep_factory.get().wot

Expand All @@ -173,6 +175,10 @@ def validate_wot(wot: pd.DataFrame, n_idle, n_rated, p_rated) -> pd.DataFrame:
f"`p_wot_max`({wot[w.p].max()}) much lower than p_rated({p_rated})!\n{wot}"
)

if n_min_drive_set and wot[w.n].min() > n_min_drive_set:
yield ValidationError(
f"wot(N) starts above n_min_drive_set({n_min_drive_set})!\n{wot}"
)
if wot[w.n_norm].min() < -0.1:
yield ValidationError(f"wot(N) starts much lower than n_idle({n_idle})!\n{wot}")
if wot[w.n].max() < n_rated <= wot[w.n].max():
Expand Down Expand Up @@ -205,7 +211,7 @@ def preproc_wot(mdl: Mapping, wot) -> pd.DataFrame:
wot = denorm_wot(wot, n_idle, n_rated, p_rated)
wot = norm_wot(wot, n_idle, n_rated, p_rated)

for err in validate_wot(wot, n_idle, n_rated, p_rated):
for err in validate_wot(wot, n_idle, n_rated, p_rated, mdl.get(d.n_min_drive_set)):
raise err

return wot
Expand All @@ -227,7 +233,12 @@ def calc_p_available(P: Column, ASM: Column, f_safety_margin) -> Column:


def interpolate_wot_on_v_grid(wot: pd.DataFrame):
"""Return a new linearly interpolated df on v with v_decimals. """
"""
Interpolated wot on a v-grid from v_min_wot --> v_max_wot, rounded.
:param wot:
must contain aat least `v` column
"""
w = wio.pstep_factory.get().wot

assert wot.size, "Empty wot!"
Expand Down

0 comments on commit 3b02b70

Please sign in to comment.