def test_MappingsCalibration_HierarchyReversal_SemioBrainBeta_TLd(self): """ Test the mappings TL for mapping calibration visualisation in the systReview (SemioBrain Database - beta version) i.e. not dummy data """ patient = Semiology('mappings TLd', Laterality.NEUTRAL, Laterality.NEUTRAL) patient.data_frame = self.use_SemioBrainBeta_notDummyData() patient.granular = False inspect_result, _ = patient.query_semiology() hierarchy_df = Hierarchy(inspect_result) hierarchy_df.all_hierarchy_reversal() # deafult max option inspect_result_reversed = hierarchy_df.new_df # test postcodes assert (inspect_result['TL'].sum() == 1) assert (inspect_result['Lateral Temporal'].sum() == 1) assert (inspect_result[ 'STG (includes Transverse Temporal Gyrus, Both Planum)'].sum() == 1 ) assert 'Planum Temporale' not in inspect_result # test hierarchy reversal assert (inspect_result_reversed['TL'].sum() == 0) assert (inspect_result_reversed['Lateral Temporal'].sum() == 0) assert (inspect_result_reversed[ 'STG (includes Transverse Temporal Gyrus, Both Planum)'].sum() == 1 ) assert 'Planum Temporale' not in inspect_result assert 'Planum Polare' not in inspect_result
def test_temporal_and_frontal_hierarchy_reversal(self): """ test combined temporal and frontals """ patient = Semiology('Aphasia', Laterality.NEUTRAL, Laterality.NEUTRAL) patient.data_frame = self.df patient.granular = False inspect_result, _ = patient.query_semiology() hierarchy_df = Hierarchy(inspect_result) hierarchy_df.temporal_hierarchy_reversal() # deafult max option hierarchy_df.frontal_hierarchy_reversal() inspect_result_reversed = hierarchy_df.new_df assert hierarchy_df.frontal_hr.equals(hierarchy_df.new_df) assert inspect_result.all().all() == inspect_result_reversed.all().all( ) assert not hierarchy_df.temporal_hr.equals(hierarchy_df.new_df) # ^ because self.new_df.copy() in the Hierarchy.temporal_hierarchy_reversal() method, so order matters. assert (inspect_result_reversed['TL'].sum() == 3) assert (inspect_result_reversed['Anterior (temporal pole)'].sum() == 5) assert (inspect_result_reversed['Lateral Temporal'].sum() == 0) assert (inspect_result_reversed['ITG'].sum() == 4) assert (inspect_result_reversed['Mesial Temporal'].sum() == 5) assert (inspect_result_reversed['FL'].sum() == 0) assert (inspect_result_reversed['IFG (F3)\n(BA 44,45,47)'].sum() == 1) print('\n10 combined T & F hierarchy reversals\n')
def test_only_postictal_cases(self): """ Include only the single postictal aphasia. Note Dominant in dummy data. cf test_postictal_exclusions """ # Low level test df_postictal = only_postictal_cases(self.df) query, num_query_lat, num_query_loc = QUERY_SEMIOLOGY( df_postictal, semiology_term=['aphasia'], ignore_case=True, semiology_dict_path=None, col1='Reported Semiology', col2='Semiology Category', ) assert (query['Localising'].sum() == 1) assert (query['Lateralising'].sum() == 1) # High level test patient = Semiology('aphasia', Laterality.NEUTRAL, dominant_hemisphere=Laterality.LEFT) patient.data_frame = self.df patient.include_postictals = True patient.include_only_postictals = True patient.granular = True lat_allgifs = patient.query_lateralisation(one_map_dummy) lat_allgifs = lat_allgifs[['Gif Parcellations', 'pt #s']].astype({ 'Gif Parcellations': 'int32', 'pt #s': 'int32' }) lat_allgifs.set_index('Gif Parcellations', inplace=True) # note that dominant_hemisphere == Laterality.LEFT as set above. Just to clarify results change if dominace changes. Also 1's become 2's if not granular. assert (lat_allgifs.loc[164, 'pt #s'] == 1) assert (lat_allgifs.loc[166, 'pt #s'] == 1) assert (lat_allgifs.loc[163, 'pt #s'] == 0) assert (lat_allgifs.loc[165, 'pt #s'] == 0) lat_allgifs = lat_allgifs.loc[lat_allgifs['pt #s'] != 0, :] SVT_output, _ = patient.get_num_datapoints_dict(method='minmax') assert SVT_output == dict((lat_allgifs)['pt #s'])
def test_hierarchy(self): """ first tested postcode system which duplicates mapping before testing its reversal. """ patient = Semiology('Aphasia', Laterality.NEUTRAL, Laterality.NEUTRAL) patient.data_frame = self.df # default behaviour of query_semiology changed to use granular hierarchy reversal: patient.granular = False inspect_result, _ = patient.query_semiology() assert (inspect_result['TL'].sum() == 12) assert (inspect_result['Anterior (temporal pole)'].sum() == 5) assert (inspect_result['Lateral Temporal'].sum() == 4) assert (inspect_result['ITG'].sum() == 4) assert (inspect_result['Mesial Temporal'].sum() == 5) # # by default postictal are excluded. Otherwise add +1 to both below assert (inspect_result['FL'].sum() == 1) assert (inspect_result['IFG (F3)\n(BA 44,45,47)'].sum() == 1) print('\n7 hierarchy\n')
def test_temporal_hierarchy_reversal(self): """ now test reversal postcode system which duplicates mapping for new class Hierarchy """ patient = Semiology('Aphasia', Laterality.NEUTRAL, Laterality.NEUTRAL) patient.data_frame = self.df patient.granular = False inspect_result, _ = patient.query_semiology() # # the three lines below were integrated into default query_semiology() using.granular = True hierarchy_df = Hierarchy(inspect_result) hierarchy_df.temporal_hierarchy_reversal() # deafult max option inspect_result_reversed = hierarchy_df.temporal_hr assert (inspect_result_reversed['TL'].sum() == 3) assert (inspect_result_reversed['Anterior (temporal pole)'].sum() == 5) assert (inspect_result_reversed['Lateral Temporal'].sum() == 0) assert (inspect_result_reversed['ITG'].sum() == 4) assert (inspect_result_reversed['Mesial Temporal'].sum() == 5) print('\n8 temporal hierarchy reversal\n')
def p_GIFs( global_lateralisation=False, include_paeds_and_adults=True, include_only_postictals=False, symptom_laterality='NEUTRAL', dominance='NEUTRAL', hierarchy_reversal: bool = True, include_spontaneous_semiology: bool = False, # TS only ): """ Return the normalised/unnormalised marginal probabilities for each GIF parcellation. for ictal semiologies only (excluding postictals) see marginal_GIF_probabilities() for sensitivity analyses e.g. by adding include_concordance=False for data queries excluding concordance or changing laterality or age """ # normalised patient_all_semiology_norm = Semiology( ".*", symptoms_side=Laterality.NEUTRAL, dominant_hemisphere=Laterality.NEUTRAL, include_postictals=False, include_paeds_and_adults=include_paeds_and_adults, normalise_to_localising_values=True, global_lateralisation=global_lateralisation, include_spontaneous_semiology=include_spontaneous_semiology, ) if symptom_laterality == 'left': patient_all_semiology_norm.symptoms_side = Laterality.LEFT if dominance == 'left': patient_all_semiology_norm.dominant_hemisphere = Laterality.LEFT patient_all_semiology_norm.include_only_postictals = include_only_postictals patient_all_semiology_norm.granular = hierarchy_reversal all_combined_gifs_norm, _ = patient_all_semiology_norm.get_num_datapoints_dict( ) p_GIF_norm = marginal_GIF_probabilities(all_combined_gifs_norm) # now not normalised version patient_all_semiology_notnorm = Semiology( ".*", symptoms_side=Laterality.NEUTRAL, dominant_hemisphere=Laterality.NEUTRAL, include_postictals=False, include_paeds_and_adults=include_paeds_and_adults, normalise_to_localising_values=False, global_lateralisation=global_lateralisation, ) if symptom_laterality == 'left': patient_all_semiology_notnorm.symptoms_side = Laterality.LEFT if dominance == 'left': patient_all_semiology_notnorm.dominant_hemisphere = Laterality.LEFT patient_all_semiology_notnorm.include_only_postictals = include_only_postictals patient_all_semiology_notnorm.granular = hierarchy_reversal all_combined_gifs_notnorm, _ = patient_all_semiology_notnorm.get_num_datapoints_dict( ) p_GIF_notnorm = marginal_GIF_probabilities(all_combined_gifs_notnorm) return p_GIF_norm, p_GIF_notnorm