|
12 | 12 | from NiBAx.core.baseplugin import BasePlugin |
13 | 13 | from NiBAx.core.gui.SearchableQComboBox import SearchableQComboBox |
14 | 14 |
|
| 15 | +from NiBAx.core import iStagingLogger |
| 16 | + |
| 17 | +logger = iStagingLogger.get_logger(__name__) |
| 18 | + |
15 | 19 | class Harmonization(QtWidgets.QWidget,BasePlugin): |
16 | 20 |
|
17 | 21 | #constructor |
@@ -112,6 +116,15 @@ def PopulateROI(self): |
112 | 116 | roiList = list(set(self.datamodel.GetColumnHeaderNames()).intersection(set(MUSEDictDataFrame[MUSEDictDataFrame['ROI_LEVEL']=='SINGLE']['ROI_COL']))) |
113 | 117 | roiList.sort() |
114 | 118 | roiList = ['(MUSE) ' + list(map(MUSEDictIDtoNAME.get, [k]))[0] if k.startswith('MUSE_') else k for k in roiList] |
| 119 | + |
| 120 | + if ('MUSE_Volume_301' in list(self.datamodel.harmonization_model['ROIs'])): |
| 121 | + logger.info('Model includes derived volumes') |
| 122 | + derivedROIs = list(set(self.datamodel.GetColumnHeaderNames()).intersection(set(MUSEDictDataFrame[MUSEDictDataFrame['ROI_LEVEL']=='DERIVED']['ROI_COL']))) |
| 123 | + derivedROIs.sort() |
| 124 | + derivedROIs = ['(MUSE) ' + list(map(MUSEDictIDtoNAME.get, [k]))[0] if k.startswith('MUSE_') else k for k in derivedROIs] |
| 125 | + roiList = roiList + derivedROIs |
| 126 | + else: |
| 127 | + logger.info('No derived volumes in model') |
115 | 128 |
|
116 | 129 | #add the list items to comboBox |
117 | 130 | self.ui.comboBoxROI.blockSignals(True) |
@@ -310,11 +323,17 @@ def plotMUSE(self,plotOptions): |
310 | 323 |
|
311 | 324 | def OnAddToDataFrame(self): |
312 | 325 | print('Saving modified data to pickle file...') |
313 | | - MUSEDictDataFrame= self.datamodel.GetMUSEDictDataFrame() |
314 | | - Derived_numbers = list(MUSEDictDataFrame[MUSEDictDataFrame['ROI_LEVEL']=='DERIVED']['ROI_INDEX']) |
315 | | - Derived_MUSE_Volumes = list('MUSE_Volume_' + str(x) for x in Derived_numbers) |
316 | | - ROI_list = list(self.datamodel.harmonization_model['ROIs']) + Derived_MUSE_Volumes |
317 | | - ROI_list.remove('MUSE_Volume_702') |
| 326 | + |
| 327 | + ROI_list = list(self.datamodel.harmonization_model['ROIs']) |
| 328 | + if ('MUSE_Volume_301' not in ROI_list): |
| 329 | + logger.info('No derived volumes in model') |
| 330 | + MUSEDictDataFrame= self.datamodel.GetMUSEDictDataFrame() |
| 331 | + Derived_numbers = list(MUSEDictDataFrame[MUSEDictDataFrame['ROI_LEVEL']=='DERIVED']['ROI_INDEX']) |
| 332 | + Derived_MUSE_Volumes = list('MUSE_Volume_' + str(x) for x in Derived_numbers) |
| 333 | + ROI_list = ROI_list + Derived_MUSE_Volumes |
| 334 | + ROI_list.remove('MUSE_Volume_702') |
| 335 | + else: |
| 336 | + logger.info('Model includes derived volumes') |
318 | 337 | H_ROIs = list('H_' + str(x) for x in ROI_list) |
319 | 338 | ROIs_ICV_Sex_Residuals = ['RES_ICV_Sex_' + x for x in self.datamodel.harmonization_model['ROIs']] |
320 | 339 | ROIs_Residuals = ['RES_' + x for x in self.datamodel.harmonization_model['ROIs']] |
@@ -430,14 +449,17 @@ def DoHarmonization(self): |
430 | 449 | else: |
431 | 450 | muse = pd.concat([covars,pd.DataFrame(bayes_data, columns=['H_' + s for s in self.datamodel.harmonization_model['ROIs']])],axis=1) |
432 | 451 |
|
433 | | - # harmonize derived volumes |
434 | | - MUSEDictDataFrame= self.datamodel.GetMUSEDictDataFrame() |
435 | | - muse_mappings = self.datamodel.GetDerivedMUSEMap() |
436 | | - for ROI in MUSEDictDataFrame[MUSEDictDataFrame['ROI_LEVEL']=='DERIVED']['ROI_INDEX']: |
437 | | - single_ROIs = muse_mappings.loc[ROI].replace('NaN',np.nan).dropna().astype(np.float) |
438 | | - single_ROIs = ['H_MUSE_Volume_%0d' % x for x in single_ROIs] |
439 | | - muse['H_MUSE_Volume_%d' % ROI] = muse[single_ROIs].sum(axis=1,skipna=False) |
440 | | - muse.drop(columns=['H_MUSE_Volume_702'], inplace=True) |
| 452 | + # harmonize derived volumes |
| 453 | + if ('MUSE_Volume_301' not in list(self.datamodel.harmonization_model['ROIs'])): |
| 454 | + logger.info('No derived volumes in model.') |
| 455 | + logger.info('Calculating using derived mapping dictionary.') |
| 456 | + MUSEDictDataFrame= self.datamodel.GetMUSEDictDataFrame() |
| 457 | + muse_mappings = self.datamodel.GetDerivedMUSEMap() |
| 458 | + for ROI in MUSEDictDataFrame[MUSEDictDataFrame['ROI_LEVEL']=='DERIVED']['ROI_INDEX']: |
| 459 | + single_ROIs = muse_mappings.loc[ROI].replace('NaN',np.nan).dropna().astype(np.float) |
| 460 | + single_ROIs = ['H_MUSE_Volume_%0d' % x for x in single_ROIs] |
| 461 | + muse['H_MUSE_Volume_%d' % ROI] = muse[single_ROIs].sum(axis=1,skipna=False) |
| 462 | + muse.drop(columns=['H_MUSE_Volume_702'], inplace=True) |
441 | 463 |
|
442 | 464 | start_index = len(self.datamodel.harmonization_model['SITE_labels']) |
443 | 465 | sex_icv_effect = np.dot(muse[['Sex','DLICV_baseline']].copy(), self.datamodel.harmonization_model['B_hat'][start_index:(start_index+2),:]) |
|
0 commit comments