Beispiel #1
0
def test_activity_timecourse_with_inlay():
    import pandas as pd
    import matplotlib.pyplot as plt
    import samri.plotting.maps as maps
    import seaborn as sns
    from os import path

    # Style elements
    palette = ["#56B4E9", "#E69F00"]

    data_dir = path.join(path.dirname(path.realpath(__file__)),
                         "../../tests/data")
    data_path = path.join(data_dir, 'drs_activity.csv')
    df = pd.read_csv(data_path)

    df = df.rename(columns={'t': 'Mean t-Statistic'})
    df['Session'] = df['Session'].map({
        'ofM': 'naïve',
        'ofMaF': 'acute',
        'ofMcF1': 'chronic/2w',
        'ofMcF2': 'chronic/4w',
        'ofMpF': 'post',
    })

    # definitions for the axes
    left, width = 0.06, 0.9
    bottom, height = 0.06, 0.9

    session_coordinates = [left, bottom, width, height]
    roi_coordinates = [left + 0.02, bottom + 0.7, 0.3, 0.2]

    fig = plt.figure(1)

    ax1 = plt.axes(session_coordinates)
    sns.pointplot(
        x='Session',
        y='Mean t-Statistic',
        units='subject',
        data=df,
        hue='treatment',
        dodge=True,
        palette=palette,
        order=['naïve', 'acute', 'chronic/2w', 'chronic/4w', 'post'],
        ax=ax1,
        ci=95,
    )

    ax2 = plt.axes(roi_coordinates)
    maps.atlas_label(
        '/usr/share/mouse-brain-atlases/dsurqec_200micron_roi-dr.nii',
        scale=0.3,
        color="#E69F00",
        ax=ax2,
        annotate=False,
        alpha=0.8,
    )

    plt.savefig('_activity_timecourse_with_inlay.png')
Beispiel #2
0
def test_activity_timecourse_with_inlay():
	import pandas as pd
	import matplotlib.pyplot as plt
	import samri.plotting.maps as maps
	import seaborn as sns
	from os import path

	# Style elements
	palette=["#56B4E9", "#E69F00"]

	data_dir = path.join(path.dirname(path.realpath(__file__)),"../../tests/data")
	data_path = path.join(data_dir,'drs_activity.csv')
	df = pd.read_csv(data_path)

	df = df.rename(columns={'t':'Mean t-Statistic'})
	df['Session']=df['Session'].map({
		'ofM':'naïve',
		'ofMaF':'acute',
		'ofMcF1':'chronic/2w',
		'ofMcF2':'chronic/4w',
		'ofMpF':'post',
		})


	# definitions for the axes
	left, width = 0.06, 0.9
	bottom, height = 0.06, 0.9

	session_coordinates = [left, bottom, width, height]
	roi_coordinates = [left+0.02, bottom+0.7, 0.3, 0.2]

	fig = plt.figure(1)

	ax1 = plt.axes(session_coordinates)
	sns.pointplot(
	       x='Session',
	       y='Mean t-Statistic',
	       units='subject',
	       data=df,
	       hue='treatment',
	       dodge=True,
	       palette=palette,
	       order=['naïve','acute','chronic/2w','chronic/4w','post'],
	       ax=ax1,
	       ci=95,
	       )

	ax2 = plt.axes(roi_coordinates)
	maps.atlas_label("/usr/share/mouse-brain-atlases/dsurqec_200micron_roi-dr.nii",
		scale=0.3,
		color="#E69F00",
		ax=ax2,
		annotate=False,
		alpha=0.8,
		)

	plt.savefig('_activity_timecourse_with_inlay.png')
Beispiel #3
0
def plot_roi_by_label(label_names,
	save_as="",
	):
	roi = roi_from_atlaslabel("~/ni_data/templates/roi/DSURQEc_200micron_labels.nii",
		mapping="~/ni_data/templates/roi/DSURQE_mapping.csv",
		label_names=label_names,
		save_as=save_as
		)
	maps.atlas_label(roi)
	plt.show()
Beispiel #4
0
    x='Session',
    y='Mean t-Statistic',
    condition='treatment',
    unit='subject',
    ci=90,
    palette=["#56B4E9", "#E69F00"],
    order=['nave', 'acute', 'chronic (2w)', 'chronic (4w)', 'post'],
    bp_style=False,
    renames={
        'Session': {
            'ofM': 'nave',
            'ofMaF': 'acute',
            'ofMcF1': 'chronic (2w)',
            'ofMcF2': 'chronic (4w)',
            'ofMpF': 'post',
        },
    },
)

ax2 = plt.axes(roi_coordinates)
maps.atlas_label(
    "~/ni_data/templates/roi/DSURQEc_drp.nii.gz",
    scale=0.3,
    color="#E69F00",
    ax=ax2,
    annotate=False,
    alpha=0.8,
)

save_as(drp_activity.py)
Beispiel #5
0
def plot_roi_per_session(
    df,
    x='Session',
    y='Mean t-Statistic',
    condition='treatment',
    unit='subject',
    ci=90,
    palette=["#56B4E9", "#E69F00"],
    dodge=True,
    order=[],
    feature_map=True,
    roi_left=0.02,
    roi_bottom=0.74,
    roi_width=0.3,
    roi_height=0.2,
    roi_anat="/usr/share/mouse-brain-atlases/dsurqec_40micron_masked.nii",
    roi_threshold=None,
    cut_coords=None,
    samri_style=True,
    renames=[],
    save_as='',
    ax=None,
    fig=None,
):
    """Plot a ROI t-values over the session timecourse
	"""

    if samri_style:
        plt.style.use(u'seaborn-darkgrid')
        plt.style.use('ggplot')

    try:
        df = path.abspath(path.expanduser(df))
    except AttributeError:
        pass

    # definitions for the axes
    height = rcParams['figure.subplot.top']
    bottom = rcParams['figure.subplot.bottom']
    left = rcParams['figure.subplot.left']
    width = rcParams['figure.subplot.right']

    session_coordinates = [left, bottom, width, height]

    roi_coordinates = [
        left + roi_left, bottom + roi_bottom, roi_width, roi_height
    ]

    if not fig:
        fig = plt.figure(1)

    if renames:
        for key in renames:
            for subkey in renames[key]:
                df.loc[df[key] == subkey, key] = renames[key][subkey]

    if not ax:
        ax1 = plt.axes(session_coordinates)
    else:
        ax1 = ax
    ax = sns.pointplot(
        x=x,
        y=y,
        units=unit,
        data=df,
        hue=condition,
        dodge=dodge,
        palette=sns.color_palette(palette),
        order=order,
        ax=ax1,
        ci=ci,
    )
    ax.set_ylabel(y)

    if isinstance(feature_map, str):
        ax2 = plt.axes(roi_coordinates)
        if roi_threshold and cut_coords:
            maps.stat(
                feature,
                cut_coords=cut_coords,
                template=roi_anat,
                annotate=False,
                scale=0.3,
                show_plot=False,
                interpolation=None,
                threshold=roi_threshold,
                draw_colorbar=False,
                ax=ax2,
            )
        else:
            maps.atlas_label(
                feature_map,
                scale=0.3,
                color="#E69F00",
                ax=ax2,
                annotate=False,
                alpha=0.8,
            )
    elif feature_map:
        try:
            features = df['feature'].unique()
        except KeyError:
            pass
        else:
            if len(features) > 1:
                print(
                    'WARNING: The features list contains more than one feature. We will highlight the first one in the list. This may be incorrect.'
                )
            feature = features[0]
            ax2 = plt.axes(roi_coordinates)
            if path.isfile(feature):
                if roi_threshold and cut_coords:
                    maps.stat(
                        stat_maps=feature,
                        cut_coords=cut_coords,
                        template=roi_anat,
                        annotate=False,
                        scale=0.3,
                        show_plot=False,
                        interpolation=None,
                        threshold=roi_threshold,
                        draw_colorbar=False,
                        ax=ax2,
                    )
                else:
                    maps.atlas_label(
                        feature,
                        scale=0.3,
                        color="#E69F00",
                        ax=ax2,
                        annotate=False,
                        alpha=0.8,
                    )
            else:
                atlas = df['atlas'].unique()[0]
                mapping = df['mapping'].unique()[0]
                if isinstance(feature, str):
                    feature = [feature]
                maps.atlas_label(
                    atlas,
                    scale=0.3,
                    color="#E69F00",
                    ax=ax2,
                    mapping=mapping,
                    label_names=feature,
                    alpha=0.8,
                    annotate=False,
                )

    if save_as:
        plt.savefig(path.abspath(path.expanduser(save_as)),
                    bbox_inches='tight')

    return fig, ax
Beispiel #6
0
def plot_my_roi():
	maps.atlas_label("~/ni_data/templates/roi/DSURQEc_dr.nii.gz",
		)
	plt.show()