1
- #
2
- # Private classes and functions for experiment steps
3
- #
1
+ from __future__ import annotations
4
2
import pybamm
5
3
import numpy as np
6
4
from datetime import datetime
@@ -492,6 +490,10 @@ def set_up(self, new_model, new_parameter_values):
492
490
}
493
491
494
492
493
+ def get_unit_from (a_string : str ) -> str :
494
+ return a_string .lstrip ("0123456789.-eE " )
495
+
496
+
495
497
def _convert_time_to_seconds (time_and_units ):
496
498
"""Convert a time in seconds, minutes or hours to a time in seconds"""
497
499
if time_and_units is None :
@@ -501,11 +503,10 @@ def _convert_time_to_seconds(time_and_units):
501
503
if isinstance (time_and_units , numbers .Number ):
502
504
if time_and_units <= 0 :
503
505
raise ValueError ("time must be positive" )
504
- else :
505
- return time_and_units
506
+ return time_and_units
506
507
507
508
# Split number and units
508
- units = time_and_units . lstrip ( "0123456789.- " )
509
+ units = get_unit_from ( time_and_units )
509
510
time = time_and_units [: - len (units )]
510
511
if units in ["second" , "seconds" , "s" , "sec" ]:
511
512
time_in_seconds = float (time )
@@ -528,7 +529,7 @@ def _convert_temperature_to_kelvin(temperature_and_units):
528
529
return temperature_and_units
529
530
530
531
# Split number and units
531
- units = temperature_and_units . lstrip ( "0123456789.- " )
532
+ units = get_unit_from ( temperature_and_units )
532
533
temperature = temperature_and_units [: - len (units )]
533
534
if units in ["K" ]:
534
535
temperature_in_kelvin = float (temperature )
@@ -547,7 +548,7 @@ def _convert_electric(value_string):
547
548
value = 1 / float (value_string [2 :])
548
549
else :
549
550
# All other cases e.g. 4 A, 2.5 V, 1.5 Ohm
550
- unit = value_string . lstrip ( "0123456789.- " )
551
+ unit = get_unit_from ( value_string )
551
552
value = float (value_string [: - len (unit )])
552
553
# Catch milli- prefix
553
554
if unit .startswith ("m" ):
0 commit comments