Exemplo n.º 1
0
def compute_all_volumes(filtered_data):
    """ Loop over all properties to show asymmetry."""

    # Process & plot the data.
    out_data = PINGData(dict(SubjID=filtered_data.data_dict['SubjID']))
    for rh_key_area in [k for k in filtered_data.get_twohemi_keys()
                          if k.startswith('MRI_cort_area.ctx')]:
        assert which_hemi(rh_key_area) == 'rh'
        try:
            rh_key_thick = rh_key_area.replace('MRI_cort_area.ctx', 'MRI_cort_thick.ctx')
            rh_key_vol = rh_key_area.replace('MRI_cort_area.ctx', 'MRI_cort_vol.ctx')
            lh_key_area = get_lh_key_from_rh_key(rh_key_area)
            lh_key_thick = get_lh_key_from_rh_key(rh_key_thick)
            lh_key_vol = get_lh_key_from_rh_key(rh_key_vol)
            dest_key = get_nonhemi_key(rh_key_vol)
            out_data.data_dict[dest_key] = filtered_data.data_dict[rh_key_vol] + filtered_data.data_dict[lh_key_vol]
        except Exception as e:
            print(e)
            continue

    return out_data
Exemplo n.º 2
0
def compute_all_totals(filtered_data):
    """Computes total surface area / volume."""

    # Process & plot the data.
    out_data = PINGData(dict(SubjID=filtered_data.data_dict['SubjID']))
    for rh_key in filtered_data.get_twohemi_keys():
        assert which_hemi(rh_key) == 'rh'
        lh_key = get_lh_key_from_rh_key(rh_key)
        dest_key = get_nonhemi_key(rh_key)
        dest_key += '_LH_PLUS_RH'
        out_data.data_dict[dest_key] = filtered_data.data_dict[rh_key] + filtered_data.data_dict[lh_key]

    def is_sum_key(key):
        return key.endswith('_LH_PLUS_RH')
    def get_sum_key(key):
        return '%s_LH_PLUS_RH' % key

    # Add one property for total asymmetry
    n_subj = out_data.get_num_subjects()
    for p in filtered_data.IMAGING_PREFIX:
        good_keys = filter(lambda k: (k.startswith(p) and 
                                      is_sum_key(k)),
                           out_data.data_dict.keys())
        good_keys = list(good_keys)
        if len(good_keys) == 0:
            continue

        # Compute total LH+RH, per subject
        total_area = np.zeros((n_subj,))
        total_measures = np.zeros((n_subj,))
        for key in good_keys:
            values = out_data.data_dict[key]
            good_idx = np.logical_not(np.isnan(values))
            total_area[good_idx] += values[good_idx]**2
            total_measures[good_idx] += 1
        total_sum_key = get_sum_key(p + '_TOTAL')
        out_data.data_dict[total_sum_key] = np.sqrt(total_area / total_measures)
    return out_data