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

    # Asymmetry index
    out_data = PINGData(dict(SubjID=filtered_data.data_dict['SubjID']))

    for key in filtered_data.get_twohemi_keys():
        dest_key = get_ai_key(key)
        out_data.data_dict[dest_key] = get_asymmetry_index(filtered_data.data_dict,
                                                           key, mask_nan=False)

    # 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_ai_key(k)),
                           out_data.data_dict.keys())
        good_keys = list(good_keys)
        if len(good_keys) == 0:
            continue

        # Compute total asymmetry per subject
        total_asymmetry = 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_asymmetry[good_idx] += values[good_idx]**2
            total_measures[good_idx] += 1
        total_ai_key = get_ai_key(p + '%s') % '_TOTAL'
        out_data.data_dict[total_ai_key] = np.sqrt(total_asymmetry / total_measures)

    return out_data
Ejemplo 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