Ignore missing data when joining measurements
Unit Testing / test (3.10) (push) Successful in 54s
Unit Testing / test (3.11) (push) Successful in 51s
Unit Testing / test (3.12) (push) Successful in 52s
Unit Testing / test (3.8) (push) Successful in 51s
Unit Testing / test (3.9) (push) Successful in 51s

This commit is contained in:
2026-06-12 14:32:32 +02:00
parent 7cb99da2f2
commit 28eaa47a1d
+18 -1
View File
@@ -568,13 +568,30 @@ class AmorEventData(AmorHeader):
output += '\n'
return output
@staticmethod
def concatenate_dropmissing(a1, a2):
"""
Concatenate to recarrays that might have different fields. Drop fields that
are not present in either array and give a warning for the missing data.
"""
try:
return np.concatenate([a1, a2]).view(np.recarray)
except np.exceptions.DTypePromotionError:
new_fields = np.dtype([(key, dtype) for key, (dtype, length) in a2.dtype.fields.items() if key in a1.dtype.fields])
output = np.recarray(a1.shape[0]+a2.shape[0], dtype=new_fields)
for field in new_fields.fields.keys():
output[field] = np.concatenate([a1[field], a2[field]])
logging.warning("Missing data when combining datasets, "
f"{tuple(a1.dtype.fields.keys())} != {tuple(a2.dtype.fields.keys())}")
return output
def append(self, other):
"""
Append event streams from another file to this one. Adjusts the event indices in the
packets to stay valid.
"""
new_events = np.concatenate([self.data.events, other.data.events]).view(np.recarray)
new_pulses = np.concatenate([self.data.pulses, other.data.pulses]).view(np.recarray)
new_pulses = self.concatenate_dropmissing(self.data.pulses, other.data.pulses)
new_proton_current = np.concatenate([self.data.proton_current, other.data.proton_current]).view(np.recarray)
new_beam_monitor = np.concatenate([self.data.beam_monitor, other.data.beam_monitor]).view(np.recarray)
new_packets = np.concatenate([self.data.packets, other.data.packets]).view(np.recarray)