Repository: rl-institut/spice_ev
Issue: SoC AssertionError in generate_from_simbev.py

Hey @stefansc1,

I was happy to see that you have some plausibility checks implemented for the simulation based upon simBEV data in `generate_from_simbev.py`. I just stumbled across an AssertionError that I'd like to hear your opinion about:

```python
Traceback (most recent call last):
  File "generate_from_simbev.py", line 257, in <module>
    assert simbev_soc_start > 0 and simbev_soc_end > 0, \\
AssertionError: SimBEV created negative SoC for phev_luxury_00000_standing_t in row 61
```

In these lines
https://github.com/rl-institut/spice_ev/blob/416fb6d9e9dddd0cce8e85e2234c8cba9dde1ba5/generate_from_simbev.py#L257-L259
you check the SoCs which gives an assertion error for a simBEV csv line such as

|     | car_type    | bat_cap | location | netto_charging_capacity | SoC_start | SoC_end | chargingdemand | charge_time | park_start | park_end | drive_start | drive_end | consumption        |
|-----|-------------|---------|----------|-------------------------|-----------|---------|----------------|-------------|------------|----------|-------------|-----------|--------------------|
| ... | ...         | ...     | ...      | ...                     | ...       | ...     | ...            | ...         | ...        | ...      | ...         | ...       |                    |
| 59  | phev_luxury | 40      | driving  | 0.0                     | 1.0       | 0.0     | 0.0            | 0           | 0          | 0        | 937         | 956       | 106.20382399999998 |
| ... | ...         | ...     | ...      | ...                     | ...       | ...     | ...            | ...         | ...        | ...      | ...         | ...       |                    |

since `SoC_end`=0. Althought the consumption seems to be flawed (cf. https://github.com/rl-institut/simbev/issues/26) it is realistic to have a fully discharged EV after a trip, right?
So shouldn't the SoC should rather checked with `simbev_soc_start >= 0 and simbev_soc_end >= 0`?


Changed files:
generate_from_simbev.py

diff --git a/generate_from_simbev.py b/generate_from_simbev.py
index f1cd3e7..e6e47f7 100755
--- a/generate_from_simbev.py
+++ b/generate_from_simbev.py
@@ -23,6 +23,8 @@ if __name__ == '__main__':
                         Negative values for fixed price in cents')
     parser.add_argument('--min-soc', metavar='S', type=float, default=0.5,
                         help='Set minimum desired SoC for each charging event. Default: 0.5')
+    parser.add_argument('--min-soc-threshold', type=float, default=0.05,
+                        help='SoC below this threshold trigger a warning. Default: 0.05')
 
     # csv files
     parser.add_argument('--include-ext-load-csv',
@@ -254,9 +256,16 @@ if __name__ == '__main__':
                 # general sanity checks
                 simbev_soc_start = float(row["SoC_start"])
                 simbev_soc_end = float(row["SoC_end"])
-                assert simbev_soc_start > 0 and simbev_soc_end > 0, \\
+                # SoC must not be negative
+                assert simbev_soc_start >= 0 and simbev_soc_end >= 0, \\
                     "SimBEV created negative SoC for {} in row {}".format(
                         vehicle_name, idx + 2)
+                # might want to avoid very low battery levels (configurable in config)
+                soc_threshold = args.min_soc_threshold
+                if simbev_soc_start < soc_threshold or simbev_soc_end < soc_threshold:
+                    print("WARNING: SimBEV created very low SoC for {} in row {}"
+                          .format(vehicle_name, idx + 2))
+
                 simbev_demand = float(row["chargingdemand"])
                 assert capacity > 0 or simbev_demand == 0, \\
                     "Charging event without charging station: {} @ row {}".format(