diff --git a/eos/file_reader.py b/eos/file_reader.py index e233128..4a30ad8 100644 --- a/eos/file_reader.py +++ b/eos/file_reader.py @@ -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)