def count_rois_differences():
    """
    counts average differences between no. pixels in ROIs
    """
    h =[[len(l) for l in get_animal_rois(get_name('H',i))] for i in INDICES]
    d =[[len(l) for l in get_animal_rois(get_name('D',i))] for i in INDICES]
    h = np.sum(np.asarray(h),axis=0)
    d = np.sum(np.asarray(d),axis=0)
    diff = np.abs(h-d)
    print (100*np.mean([np.median(diff/h),np.median(diff/d)]))
    print ("average difference: {:0.2f}({:0.2f})".format(100*np.mean([np.mean(diff/h),np.mean(diff/d)]),100*np.mean([np.std(diff/h),np.std(diff/d)])))
Exemplo n.º 2
0
def get_roi_group_a(atype='H',roi_group=[8,9],a_indices=INDICES):
    """
    returns ROI groups for every animal of a given species as a concatenated vector
    
    parameters:
        atype = animal type [H,D]
        roi_group -  list of rois to include
        a_indices - animal indices
    
    return:
        a dictinary indexed by animals with individual roi vectors
        a concatenated roi vector
    """
    animals = {}
    for a in a_indices:
        animals[a]=[]
        
    for a in a_indices:
        name=get_name(atype,a)
        rois = get_animal_rois(name)
        for r in roi_group: 
            animals[a].append(rois[r-1])
    for a in a_indices:
        animals[a]=np.concatenate(animals[a])
    
    data = np.concatenate([animals[a] for a in animals])
    
    return animals,data
def get_roi_differences(rid):
    """
    returns (and prints) differences between animals in ROI
    parameters:
        rid: ROI id
    
    returns:
        dictionary of differences i.e. 
        {diff: roi difference,H:<horse roi stats>,D:<donkey roi stats>} 
    """
    temps = {}
    rets = {}
    for atype in ATYPES:
        temps[atype]=[]
        for i in INDICES:
            name = get_name(atype,i)
            rois = get_animal_rois(name)
            temps[atype].append(rois[rid-1])
        temps[atype] = np.concatenate(temps[atype])
        rmin,rmean,rmedian,rmax = np.min(temps[atype]),np.mean(temps[atype]),np.median(temps[atype]),np.max(temps[atype])
        rets[atype] = [rmin,rmean,rmedian,rmax]
    dd = np.abs(rets['H'][1]-rets['D'][1])
    print ("{}: {:0.2f}, {}".format(rid,dd,rets))
    rets['diff'] = dd    
    return rets    
def plot_roi_histo(rid,small=False,show=GLOBAL_SHOW):
    """
    plots hhistogram of temperatures for a given ROI
    parameters:
        rid - ROI id or 0 for all
        small - True/False: wheather to generate small (half-size) histograms
        show: True/False: show or save image
    """
    assert rid>=0 and rid<16,"{}".format(rid) 
    temps = {}
    for atype in ATYPES:
        temps[atype]=[]
        for i in INDICES:
            name = get_name(atype,i)
            rois = get_animal_rois(name)
            if rid>0:
                temps[atype].append(rois[rid-1])
            else:    
                temps[atype].append(np.concatenate(rois))
        temps[atype] = np.concatenate(temps[atype])
        print ("{} ROI {}: mean: {:0.2f}, std: {:0.2f}, skew:{:0.2f}, kurtosis:{:0.2f}".format(atype,rid
                                                                                               ,np.mean(temps[atype])
                                                                                               ,np.std(temps[atype])
                                                                                               ,skew(temps[atype])
                                                                                               ,kurtosis(temps[atype])))    

    if not small:
        plt.rcParams.update({'font.size': 12})
        plt.figure(figsize=(4,3),dpi=300)
    else:    
        plt.rcParams.update({'font.size': 10})
        plt.figure(figsize=(2,1.5),dpi=300)
    nbins = int(np.max([np.sqrt(len(temps[atype])) for atype in ['H','D']]))
    
    plt.hist(temps['H'],color='#DC3220',alpha=0.7,density=True,bins=nbins,label='Horses')
    plt.hist(temps['D'],color='#005AB5',alpha=0.7,density=True,bins=nbins,label='Donkeys')
    if not small:
        plt.xlabel("Temperature")
    else:
        txt="[ROI {}] Temp.".format(rid) if rid>0 else 'Combined Temp.'
        plt.xlabel(txt)
    plt.ylabel("Density")
    if not small:
        plt.legend()        
    plt.tight_layout(0.1,0.1,0.1)
    ss = '_small' if small else ''
    if show:
        plt.show()
    else:    
        plt.savefig('fig/histo_{}{}.pdf'.format(rid,ss),bbox_inches='tight',pad_inches=0)
    plt.close()
Exemplo n.º 5
0
def print_global_temperatures():
    """
    prints global temperature stats for animals
    """
    temps = {}
    for atype in ATYPES:
        temps[atype] = []
        for i in INDICES:
            arr, anno = get_animal(get_name(atype, i))
            temps[atype].append(arr[anno != 0])
        temps[atype] = np.concatenate(temps[atype])
        print(
            atype,
            'min: {:0.2f},mean:{:0.2f}({:0.2f}), median:{:0.2f},  max: {:0.2f}'
            .format(np.min(temps[atype]), np.mean(temps[atype]),
                    np.std(temps[atype]), np.median(temps[atype]),
                    np.max(temps[atype])))
Exemplo n.º 6
0
def get_roi_group_a(atype='H', roi_group=[8, 9]):
    """
    returns a GOR of all animals of a given species as a vector
    
    parameters:
        atype = animal type [H,D]
        roi_group -  list of rois to include (GOR)
    
    return:
        vector of temperature values of all animals in GOR
    """
    data = []
    for i in INDICES:
        name = get_name(atype, i)
        rois = get_animal_rois(name)
        for r in roi_group:
            data.append(rois[r - 1])
    return np.concatenate(data)
Exemplo n.º 7
0
def plot_groups(stat=np.mean,normalise=False,show=GLOBAL_SHOW):
    """
    Compare ROI features with t-SNE (expecting observable structure in data)
    warning: t-SNE is a nondeterministic algorithm
    paramters:
        stat: feature extraction statistics
        normalise: normalise features by removing the global average
        show: True/False: show or save image   
    """
    
    data = []
    y = []
    for atype in ATYPES:
        for a in INDICES:
            rois = get_animal_rois(get_name(atype=atype,index=a))
            if rois != None:
                y.append(0 if atype =='H' else 1)
                if normalise:
                    gv = np.mean(np.concatenate(rois))
                    rois = [v-gv for v in rois]
                temp = [stat(v) for v in rois]
                data.append(temp) 
    
    plt.rcParams.update({'font.size': 12})
    
    X = np.array(data)
    y=np.array(y)
    tsne = TSNE(perplexity=5)
    X = tsne.fit_transform(X)
    where = y==0
    plt.scatter(X[where,0],X[where,1],color = '#DC3220', label='Horses')
    where = y==1
    plt.scatter(X[where,0],X[where,1],color = '#005AB5', label='Donkeys')
    plt.legend()
    nstr = '_norm' if normalise else ''
    if show:
        plt.show()
    else:
        plt.savefig('fig/tsne_{}{}.pdf'.format(stat.__name__,nstr),bbox_inches='tight',pad_inches=0)
    plt.close()    
def plot_box(atype='H',show=GLOBAL_SHOW):
    """
    plots boxplot of temperatures in rois for a given animal type
    parameters:
        
        atype - animal type ['H','D']
    """
    arr = [] 
    for i in INDICES:
        name = get_name(atype,i)
        rois = get_animal_rois(name)
        arr.append(rois)
    
    rois = []
    for rid in range(15):
        rois.append(np.concatenate([v[rid] for v in arr]))
    
    plt.rcParams.update({'font.size': 10})
    plt.figure(figsize=(4,3),dpi=300)
    
    medians = [np.median(v) for v in rois]
    arg = np.argsort(medians)[::-1]
    rois=np.array(rois)
    rois=rois[arg]
    indices = np.arange(15)+1
    
    plt.boxplot(rois,widths = 0.6,flierprops={'marker':'o','markersize':1,'alpha':0.7,'markeredgecolor':'#DC3220','linestyle':'none'})

    plt.ylim(10,30)
    plt.xticks(np.arange(15)+1,indices[arg])
    plt.xlabel("ROI")
    plt.ylabel("Temperature")
    plt.tight_layout(0.2,0.2,0.2)
    if show:
        plt.show()
    else:
        plt.savefig('fig/box_{}.pdf'.format(atype),bbox_inches='tight',pad_inches=0)#
    plt.close()
Exemplo n.º 9
0
    else:
        name = '{}.pdf'.format(
            custom_name) if custom_name is not None else 'fig/{}{}.pdf'.format(
                name, indstr)
        plt.savefig(name, bbox_inches='tight', pad_inches=0)
    plt.close()


if __name__ == '__main__':
    plot_animal_heatmap(name='D.3',
                        gmin=8.80,
                        gmax=30.65,
                        cutb=[20, 201, 52, 300],
                        is_bg=False,
                        custom_name='fig/heat')
    plot_animal_heatmap(name='D.3',
                        gmin=8.80,
                        gmax=30.65,
                        cutb=[20, 201, 52, 300],
                        is_bg=True,
                        custom_name='fig/heat_all')
    print_global_temperatures()
    plot_animal_heatmap('D.17', gmin=8.80, gmax=30.65)
    plot_animal_heatmap('D.18', gmin=8.80, gmax=30.65)
    plot_animal_heatmap('D.12', gmin=None, gmax=None)
    plot_animal_heatmap('H.11', gmin=None, gmax=None)
    if True:
        for atype in ATYPES:
            for i in INDICES:
                plot_animal_heatmap(get_name(atype, i))