Esempio n. 1
0
 def test_heatmap(self):
     sp = Spectrum()
     sp.from_surface(surface=np.ones([10, 10]))
     pl = sp.heatmap()
     os.makedirs('data/test_data')
     pl.savefig('data/test_data/heatmap.png')
     self.assertEqual(os.path.exists('data/test_data/heatmap.png'), True)
     shutil.rmtree('data/test_data/')
Esempio n. 2
0
def plot_average_heatmaps(inputfile, outputfolder, **kwargs):
    """
    Plot heatmaps for group-averaged SPHARM spectra.

    Parameters
    ----------
    inputfile : str
        Path to the file with spectral data.    
    outputfolder : str
        Output directory to save the heatmaps.
    kwargs : key, value pairings
            Arbitrary keyword arguments to pass to the Spectrum.heatmap function.
    """
    filelib.make_folders([os.path.dirname(outputfolder), outputfolder + 'timepoints/'])
    stat = pd.read_csv(inputfile, sep='\t', index_col=0)
    stat.loc[:, 'Time'] = np.int_(np.round_(stat['Time'] / 10.)) * 10
    if 'Group' not in stat.columns:
        for name in stat['Name'].unique():
            group = name.split('/')[0]
            stat = stat.set_value(stat[stat['Name'] == name].index, 'Group', group)

    data = stat.groupby(['degree', 'order', 'Group']).mean().reset_index()
    for gr in data['Group'].unique():
        curdata = data[data['Group'] == gr]
        s = Spectrum()
        s.harmonics_csv = curdata
        pl = s.heatmap(title=gr + ' average', **kwargs)
        pl.savefig(outputfolder + gr + '.png')
        pl.clf()

    # plot separate time points
    stat = stat.groupby(['Time', 'Group', 'degree', 'order']).mean().reset_index()

    for t in stat['Time'].unique():
        for gr in stat['Group'].unique():
            curdata = stat[(stat['Group'] == gr) & (stat['Time'] == t)]
            if len(curdata) > 0:
                s = Spectrum()
                s.harmonics_csv = curdata
                pl = s.heatmap(title=gr + ' average, time point ' + str(t), **kwargs)
                pl.savefig(outputfolder + 'timepoints/' + gr + '_time=' + str(t) + '.png')
                pl.clf()
Esempio n. 3
0
def plot_individual_heatmaps(inputfolder, outputfolder, **kwargs):
    """
    Plot heatmaps of individual SPHARM spectra in a given directory.

    Parameters
    ----------
    inputfolder : str
        Input directory with spectra to plot.
    outputfolder : str
        Output directory to save the heatmaps.
    kwargs : key, value pairings
            Arbitrary keyword arguments to pass to the Spectrum.heatmap function.
    """
    files = filelib.list_subfolders(inputfolder, extensions=['csv'])

    for fn in files:
        s = Spectrum(filename=inputfolder + fn)
        pl = s.heatmap(title=fn[:-4], **kwargs)
        filelib.make_folders([os.path.dirname(outputfolder + fn[:-4])])
        pl.savefig(outputfolder + fn[:-4] + '.png')
        pl.clf()