@@ -786,11 +786,9 @@ def _write_ecg_bike_tensors(ecgs, xml_field, hd5, sample_id, stats):
786786 for ecg in ecgs :
787787 root = et .parse (ecg ).getroot ()
788788 date = datetime .datetime .strptime (_date_str_from_ecg (root ), '%Y-%m-%d' )
789- write_to_hd5 = partial (create_tensor_in_hd5 , hd5 = hd5 , path_prefix = 'ukb_ecg_bike' , stats = stats , date = date )
790- logging .info ('Got ECG for sample:{} XML field:{}' .format (sample_id , xml_field ))
791-
792789 instance = ecg .split (JOIN_CHAR )[- 2 ]
793- write_to_hd5 (storage_type = StorageType .STRING , name = 'instance' , value = instance )
790+ write_to_hd5 = partial (create_tensor_in_hd5 , hd5 = hd5 , path_prefix = 'ukb_ecg_bike' , instance = instance , stats = stats , date = date )
791+ logging .info (f'Got ECG for sample:{ sample_id } XML field:{ xml_field } ' )
794792
795793 protocol = root .findall ('./Protocol/Phase' )[0 ].find ('ProtocolName' ).text
796794 write_to_hd5 (storage_type = StorageType .STRING , name = 'protocol' , value = protocol )
@@ -881,10 +879,13 @@ def _write_ecg_bike_tensors(ecgs, xml_field, hd5, sample_id, stats):
881879 if field_val is False :
882880 continue
883881 trends [lead_field ][i , lead_to_int [lead_num ]] = field_val
884- trends ['time' ][i ] = SECONDS_PER_MINUTE * int (trend_entry .find ("EntryTime/Minute" ).text ) + int (trend_entry .find ("EntryTime/Second" ).text )
885- trends ['PhaseTime' ][i ] = SECONDS_PER_MINUTE * int (trend_entry .find ("PhaseTime/Minute" ).text ) + int (trend_entry .find ("PhaseTime/Second" ).text )
886- trends ['PhaseName' ][i ] = phase_to_int [trend_entry .find ('PhaseName' ).text ]
887- trends ['Artifact' ][i ] = float (trend_entry .find ('Artifact' ).text .strip ('%' )) / 100 # Artifact is reported as a percentage
882+ try :
883+ trends ['time' ][i ] = SECONDS_PER_MINUTE * int (trend_entry .find ("EntryTime/Minute" ).text ) + int (trend_entry .find ("EntryTime/Second" ).text )
884+ trends ['PhaseTime' ][i ] = SECONDS_PER_MINUTE * int (trend_entry .find ("PhaseTime/Minute" ).text ) + int (trend_entry .find ("PhaseTime/Second" ).text )
885+ trends ['PhaseName' ][i ] = phase_to_int [trend_entry .find ('PhaseName' ).text ]
886+ trends ['Artifact' ][i ] = float (trend_entry .find ('Artifact' ).text .strip ('%' )) / 100 # Artifact is reported as a percentage
887+ except AttributeError as e :
888+ stats ['AttributeError on Trend Data' ] += 1
888889
889890 for field , trend_list in trends .items ():
890891 write_to_hd5 (name = f'trend_{ str .lower (field )} ' , value = trend_list )
@@ -900,12 +901,15 @@ def _write_ecg_bike_tensors(ecgs, xml_field, hd5, sample_id, stats):
900901 write_to_hd5 (name = f'{ str .lower (phase_name )} _duration' , value = [phase_duration ])
901902
902903 # HR stats
903- max_hr = _xml_path_to_float (root , './ExerciseMeasurements/MaxHeartRate' )
904- resting_hr = _xml_path_to_float (root , './ExerciseMeasurements/RestingStats/RestHR' )
905- max_pred_hr = _xml_path_to_float (root , './ExerciseMeasurements/MaxPredictedHR' )
906- write_to_hd5 (name = 'max_hr' , value = [max_hr ])
907- write_to_hd5 (name = 'resting_hr' , value = [resting_hr ])
908- write_to_hd5 (name = 'max_pred_hr' , value = [max_pred_hr ])
904+ try :
905+ max_hr = _xml_path_to_float (root , './ExerciseMeasurements/MaxHeartRate' )
906+ write_to_hd5 (name = 'max_hr' , value = [max_hr ])
907+ resting_hr = _xml_path_to_float (root , './ExerciseMeasurements/RestingStats/RestHR' )
908+ write_to_hd5 (name = 'resting_hr' , value = [resting_hr ])
909+ max_pred_hr = _xml_path_to_float (root , './ExerciseMeasurements/MaxPredictedHR' )
910+ write_to_hd5 (name = 'max_pred_hr' , value = [max_pred_hr ])
911+ except AttributeError as e :
912+ stats ['AttributeError on HR Stats' ] += 1
909913
910914
911915def _write_tensors_from_niftis (folder : str , hd5 : h5py .File , field_id : str , stats : Counter ):
0 commit comments