34 lines
987 B
Python
34 lines
987 B
Python
import re
|
|
import numpy as np
|
|
|
|
def sep_num_from_units(powerbox_output :str)->list:
|
|
'''
|
|
Receives a string as input and separates the numberic value and unit and returns it as a list.
|
|
|
|
Parameters
|
|
----------
|
|
powerbox_output : str
|
|
string output from the attocube powerbox, e.g. 1.35325kG
|
|
|
|
Returns
|
|
-------
|
|
list
|
|
list of float value and string (b value and it's units). If string is purely alphabets, then return a single element list
|
|
|
|
'''
|
|
match = re.match(r'\s*([+-]?\d*\.?\d+)([A-Za-z]+)', powerbox_output)
|
|
if match:
|
|
numeric_part = float(match.group(1)) # Convert the numeric part to a float
|
|
alphabetic_part = match.group(2) # Get the alphabetic part
|
|
return [numeric_part, alphabetic_part]
|
|
else:
|
|
return [powerbox_output,]
|
|
|
|
angles = [1,2,3]
|
|
|
|
print(str(angles[0]) +"\n"+ str(angles[-1]))
|
|
|
|
rates_lst = list(sep_num_from_units(el) for el in "0.0kG;1.0kG".split(";"))
|
|
|
|
print(rates_lst[1][0])
|