Total Complexity | 1 |
Total Lines | 35 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | """ |
||
2 | Sanity checks for motorized individual travel |
||
3 | """ |
||
4 | |||
5 | from numpy.testing import assert_allclose |
||
6 | |||
7 | from egon.data.datasets.emobility.motorized_individual_travel.helpers import ( |
||
8 | CONFIG_EV, |
||
9 | ) |
||
10 | |||
11 | |||
12 | def validate_electric_vehicles_numbers(dataset_name, ev_data, ev_target): |
||
13 | """Validate cumulative numbers of electric vehicles' distribution. |
||
14 | |||
15 | Tests |
||
16 | * Check if all cells are not NaN |
||
17 | * Check if total number matches produced results (tolerance: 0.01 %) |
||
18 | |||
19 | Parameters |
||
20 | ---------- |
||
21 | dataset_name : str |
||
22 | Name of data, used for error printing |
||
23 | ev_data : pd.DataFrame |
||
24 | EV data |
||
25 | ev_target : int |
||
26 | Desired number of EVs |
||
27 | """ |
||
28 | assert not ev_data.isna().any().any() |
||
29 | |||
30 | assert_allclose( |
||
31 | ev_data[[_ for _ in CONFIG_EV.keys()]].sum().sum(), |
||
32 | ev_target, |
||
33 | rtol=0.0001, |
||
34 | err_msg=f"Dataset on EV numbers [{dataset_name}] seems to be flawed.", |
||
35 | ) |
||
36 |