Beispiel #1
0
def test_atlas_value_to_name():
    structure_df = load_structures_as_df(structures_csv)
    assert "Interpeduncular nucleus" == structures_tree.atlas_value_to_name(
        100, structure_df)

    with pytest.raises(structures_tree.UnknownAtlasValue):
        structures_tree.atlas_value_to_name(100000, structure_df)
Beispiel #2
0
def display_brain_region_name(layer, structures_df):
    val = layer.get_value()
    if val != 0 and val is not None:
        try:
            region = atlas_value_to_name(val, structures_df)
            msg = f"{region}"
        except UnknownAtlasValue:
            msg = "Unknown region"
    else:
        msg = "No label here!"
    layer.help = msg
Beispiel #3
0
 def get_connected_component_shape(layer, event):
     val = layer.get_value()
     if val != 0 and val is not None:
         try:
             region = atlas_value_to_name(val, structures_df)
             msg = f"{region}"
         except UnknownAtlasValue:
             msg = "Unknown region"
     else:
         msg = "No label here!"
     layer.help = msg
Beispiel #4
0
def add_structure_volume_to_df(
    df,
    atlas_value,
    structures_reference_df,
    unique_vals_left,
    unique_vals_right,
    counts_left,
    counts_right,
    voxel_volume,
    total_volume_voxels=None,
):
    name = atlas_value_to_name(atlas_value, structures_reference_df)

    left_volume, left_percentage = get_volume_in_hemisphere(
        atlas_value,
        unique_vals_left,
        counts_left,
        total_volume_voxels,
        voxel_volume,
    )
    right_volume, right_percentage = get_volume_in_hemisphere(
        atlas_value,
        unique_vals_right,
        counts_right,
        total_volume_voxels,
        voxel_volume,
    )
    if total_volume_voxels is not None:
        total_percentage = left_percentage + right_percentage
    else:
        total_percentage = 0

    df = df.append(
        {
            "structure_name": name,
            "left_volume_mm3": left_volume,
            "left_percentage_of_total": left_percentage,
            "right_volume_mm3": right_volume,
            "right_percentage_of_total": right_percentage,
            "total_volume_mm3": left_volume + right_volume,
            "percentage_of_total": total_percentage,
        },
        ignore_index=True,
    )
    return df
Beispiel #5
0
def add_structure_volume_to_df(
    df,
    atlas_value,
    structures_reference_df,
    unique_vals_left,
    unique_vals_right,
    counts_left,
    counts_right,
    voxel_volume,
):

    name = atlas_value_to_name(atlas_value, structures_reference_df)

    try:
        left_index = np.where(unique_vals_left == atlas_value)[0][0]
        left_volume = counts_left[left_index] * voxel_volume
    except IndexError:
        logging.warning("Atlas value: {} not found in registered atlas. "
                        "Setting registered volume to 0.".format(atlas_value))
        left_volume = 0

    try:
        right_index = np.where(unique_vals_right == atlas_value)[0][0]
        right_volume = counts_right[right_index] * voxel_volume
    except IndexError:
        logging.warning("Atlas value: {} not found in registered atlas. "
                        "Setting registered volume to 0.".format(atlas_value))
        right_volume = 0

    df = df.append(
        {
            "structure_name": name,
            "left_volume_mm3": left_volume,
            "right_volume_mm3": right_volume,
            "total_volume_mm3": left_volume + right_volume,
        },
        ignore_index=True,
    )
    return df