fixed some python2 to python3 changes as well as dat time formats

This commit is contained in:
2026-07-06 20:40:59 +02:00
parent 3bfb2670eb
commit c181e15aa8
+41 -1
View File
@@ -1160,6 +1160,26 @@ def read_from_hdf(hdf_node):
earliest_time=None earliest_time=None
if "earliest_time" in dir(hdf_node._v_attrs): if "earliest_time" in dir(hdf_node._v_attrs):
timestring=hdf_node._v_attrs.__getattr__("earliest_time") timestring=hdf_node._v_attrs.__getattr__("earliest_time")
# Handle both formats: "20260705 19:13:59.162" and "2026-07-05 19:13:59.162"
if '-' in timestring:
# New format: "2026-07-05 19:13:59.162"
try:
earliest_time=datetime.datetime.strptime(str(timestring), '%Y-%m-%d %H:%M:%S.%f')
except ValueError:
# Fallback to manual parsing
parts = timestring.split()
if len(parts) >= 2:
date_parts = parts[0].split('-')
time_parts = parts[1].split(':')
if len(date_parts) == 3 and len(time_parts) >= 2:
year, month, day = int(date_parts[0]), int(date_parts[1]), int(date_parts[2])
hour, minute = int(time_parts[0]), int(time_parts[1])
second_parts = time_parts[2].split('.') if len(time_parts) > 2 else ['0']
second = int(second_parts[0])
microsecond = int(second_parts[1].ljust(6, '0')[:6]) if len(second_parts) > 1 else 0
earliest_time=datetime.datetime(year, month, day, hour, minute, second, microsecond)
else:
# Old format: "20260705 19:13:59.162"
earliest_time=datetime.datetime(int(timestring[:4]), # year earliest_time=datetime.datetime(int(timestring[:4]), # year
int(timestring[4:6]), # month int(timestring[4:6]), # month
int(timestring[6:8]), # day int(timestring[6:8]), # day
@@ -1172,6 +1192,26 @@ def read_from_hdf(hdf_node):
oldest_time=None oldest_time=None
if "oldest_time" in dir(hdf_node._v_attrs): if "oldest_time" in dir(hdf_node._v_attrs):
timestring=hdf_node._v_attrs.__getattr__("oldest_time") timestring=hdf_node._v_attrs.__getattr__("oldest_time")
# Handle both formats: "20260705 19:13:59.162" and "2026-07-05 19:13:59.162"
if '-' in timestring:
# New format: "2026-07-05 19:13:59.162"
try:
oldest_time=datetime.datetime.strptime(str(timestring), '%Y-%m-%d %H:%M:%S.%f')
except ValueError:
# Fallback to manual parsing
parts = timestring.split()
if len(parts) >= 2:
date_parts = parts[0].split('-')
time_parts = parts[1].split(':')
if len(date_parts) == 3 and len(time_parts) >= 2:
year, month, day = int(date_parts[0]), int(date_parts[1]), int(date_parts[2])
hour, minute = int(time_parts[0]), int(time_parts[1])
second_parts = time_parts[2].split('.') if len(time_parts) > 2 else ['0']
second = int(second_parts[0])
microsecond = int(second_parts[1].ljust(6, '0')[:6]) if len(second_parts) > 1 else 0
oldest_time=datetime.datetime(year, month, day, hour, minute, second, microsecond)
else:
# Old format: "20260705 19:13:59.162"
oldest_time=datetime.datetime(int(timestring[:4]), # year oldest_time=datetime.datetime(int(timestring[:4]), # year
int(timestring[4:6]), # month int(timestring[4:6]), # month
int(timestring[6:8]), # day int(timestring[6:8]), # day
@@ -1212,7 +1252,7 @@ def read_from_hdf(hdf_node):
accu.y_square=[] accu.y_square=[]
accu.use_error=False accu.use_error=False
for ch in range(accu_data.shape[1]/2): for ch in range(accu_data.shape[1] // 2):
accu.y.append(accu_data[:,ch*2]*accu.n) accu.y.append(accu_data[:,ch*2]*accu.n)
if accu.n<2 or numpy.all(accu_data[:,ch*2+1]==0.0): if accu.n<2 or numpy.all(accu_data[:,ch*2+1]==0.0):
accu.y_square.append(numpy.zeros((accu_data.shape[0]) ,dtype="float32")) accu.y_square.append(numpy.zeros((accu_data.shape[0]) ,dtype="float32"))