- Notifications
You must be signed in to change notification settings - Fork269
Open
Description
Hi,
I noticed that innibabel/ecat.py, thepatient_birth_date field is defined as:
('patient_birth_date',np.uint32),
This causes incorrect date interpretations, for example producing birth dates in the future rather than before the Unix epoch. It seems this field should be asigned integer (np.int32) to correctly handle dates.
At least in the ECAT files I have,patient_birth_datemust be signed integers to interpret dates correctly. Tools like Vinci read these files correctly when treated as signed.
Example:
importnumpyasnpimportdatetime,calendar# 19 Dec 1915 at midnight UTCts=calendar.timegm(datetime.datetime(1915,12,19).timetuple())# Structured array with wrong dtypedtype_wrong= [('patient_birth_date',np.uint32)]arr_wrong=np.array([(ts,)],dtype=dtype_wrong)# Structured array with correct dtypedtype_right= [('patient_birth_date',np.int32)]arr_right=np.array([(ts,)],dtype=dtype_right)# Convert back to datetimedt_wrong=datetime.datetime.utcfromtimestamp(arr_wrong['patient_birth_date'][0])dt_right=datetime.datetime.utcfromtimestamp(arr_right['patient_birth_date'][0])print("Unsigned (wrong):",arr_wrong['patient_birth_date'][0],"->",dt_wrong)print("Signed (correct):",arr_right['patient_birth_date'][0],"->",dt_right)
Example output:
Unsigned (wrong): 2589690496 -> 2052-01-24 06:28:16Signed (correct): -1705276800 -> 1915-12-19 00:00:00Changing it tonp.int32 fixes this issue. I can also prepare aPR for this update if that’s helpful.
Thanks!
Metadata
Metadata
Assignees
Labels
No labels