Esempio n. 1
0
def plot_overlay_withcolorbar(imgbase, imgcolor, title=None, figsize=None, vmin=None, vmax=None, overlay_alpha=1.0,
                              overlay_colormap='viridis', overlay_steps=None, display_contours=False, contour_fmt=None,
                              contour_steps=None, contour_alpha=None, show=True):
    ''' Plot an image with a colorbar '''
    fig, axis = plt.subplots(1, 1, figsize=figsize, squeeze=False)
    base = axis[0][0].imshow(imgbase)
    if overlay_steps is not None:
        overlay_colormap = cm.get_cmap(overlay_colormap, overlay_steps)
    rad2 = axis[0][0].imshow(imgcolor, vmin=vmin, vmax=vmax, alpha=overlay_alpha, cmap=overlay_colormap)
    if display_contours:
        if contour_steps is None:
            contour_steps = overlay_steps
        if contour_alpha is None:
            contour_alpha = overlay_alpha
        contour_cmap = cm.get_cmap(overlay_colormap, contour_steps)
        contour_list = np.arange(vmin, vmax, (vmax - vmin) / contour_steps)
        rad3 = axis[0][0].contour(imgcolor, contour_list, cmap=contour_cmap, alpha=contour_alpha)
        fontsize = 8 + (max(figsize) / 10) * 2
        axis[0][0].clabel(rad3, rad3.levels, inline=True, fontsize=fontsize, fmt=contour_fmt)
    axis[0][0].set_title(title)
    divider = make_axes_locatable(axis[0][0])
    cax = divider.append_axes("right", size="3%", pad=0.05)
    fig.colorbar(rad2, cax=cax)
    plt.tight_layout()
    if show:
        plt.show()
    return fig, axis[0][0]
Esempio n. 2
0
    def plot_trips(self, trips, title='Trips', newplot=True):
        n = len(trips) + 2
        # create the new map
        cmap = cm.get_cmap('winter')
        colors = [cmap(1. * i / n) for i in range(n)]
        if newplot:
            plt.figure(title, figsize=(12, 8))
            plt.subplot(211)
        else:
            plt.subplot(212)
        plt.scatter(self.gifts.Longitude, gifts.Latitude, color='gray')
        c = 0
        coords = [360, 0, 180, 0]
        for tripid in trips:
            #range(510,530):#
            self.plot_trip(tripid, newplot=False, color=colors[c + 1])
            c += 1
            # Get boundries
            if self.T[tripid].Longitude.min() + 180 < coords[0]:
                coords[0] = self.T[tripid].Longitude.min() + 180
            if self.T[tripid].Longitude.max() + 180 > coords[1]:
                coords[1] = self.T[tripid].Longitude.max() + 180
            if self.T[tripid].Latitude.min() + 90 < coords[2]:
                coords[2] = self.T[tripid].Latitude.min() + 90
            if self.T[tripid].Latitude.max() + 90 > coords[3]:
                coords[3] = self.T[tripid].Latitude.max() + 90

        band = .1
        plt.xlim(coords[0] * (1 - band) - 180, coords[1] * (1 + band) - 180)
        plt.ylim(coords[2] * (1 - band) - 90, coords[3] * (1 + band) - 90)
        plt.title(title, fontsize=20)
        plt.tight_layout()
Esempio n. 3
0
def plot_trips(trips, title=''):
    n = len(trips) + 2
    # create the new map
    cmap = cm.get_cmap('winter')
    colors = [cmap(1. * i / n) for i in range(n)]

    plt.figure('Smallest Trips', figsize=(17, 11))
    plt.scatter(gifts.Longitude, gifts.Latitude, color='gray')
    c = 0
    coords = [360, 0, 180, 0]
    for tripid in trips:
        #range(510,530):#
        plot_trip(T, tripid, newplot=False, color=colors[c + 1])
        c += 1
        # Get boundries
        if T[tripid].iloc[1:-1].Longitude.min() + 180 < coords[0]:
            coords[0] = T[tripid].iloc[1:-1].Longitude.min() + 180
        if T[tripid].iloc[1:-1].Longitude.max() + 180 > coords[1]:
            coords[1] = T[tripid].iloc[1:-1].Longitude.max() + 180
        if T[tripid].iloc[1:-1].Latitude.min() + 90 < coords[2]:
            coords[2] = T[tripid].iloc[1:-1].Latitude.min() + 90
        if T[tripid].iloc[1:-1].Latitude.max() + 90 > coords[3]:
            coords[3] = T[tripid].iloc[1:-1].Latitude.max() + 90

    band = .1
    plt.xlim(coords[0] * (1 - band) - 180, coords[1] * (1 + band) - 180)
    plt.ylim(coords[2] * (1 - band) - 90, coords[3] * (1 + band) - 90)
    plt.title(title, fontsize=20)
    plt.tight_layout()
Esempio n. 4
0
def plot_worst_trips(n_trips=10, lightest=False):
    ## Plots
    ############################################
    # Find Worst Trips
    if lightest:
        headroom = Santa.trip_metrics.Weight.copy()
        headroom.sort_values(inplace=True)
    else:
        headroom = (Santa.trip_metrics.WRW - Santa.trip_metrics.LB)  #-1
        headroom.sort_values(inplace=True, ascending=False)

    # create the new map
    cmap = cm.get_cmap('winter')
    colors = [cmap(1. * i / (n_trips + 2)) for i in range(n_trips + 2)]
    # create the new map
    cmap = cm.get_cmap('winter', n_trips + 2)

    plt.figure('Worst Trips', figsize=(17, 11))
    plt.scatter(Santa.gifts.Longitude, gifts.Latitude, color='gray')
    c = 0
    coords = [360, 0, 180, 0]
    for tripid in headroom.index[:n_trips]:
        #range(510,530):#
        plot_trip(Santa.T, tripid, newplot=False, color=colors[c + 1])
        c += 1
        # Get boundries
        if Santa.T[tripid].Longitude.min() + 182 < coords[0]:
            coords[0] = Santa.T[tripid].Longitude.min() + 182
        if Santa.T[tripid].Longitude.max() + 182 > coords[1]:
            coords[1] = Santa.T[tripid].Longitude.max() + 182
        if Santa.T[tripid].Latitude.min() + 92 < coords[2]:
            coords[2] = Santa.T[tripid].Latitude.min() + 92
        if Santa.T[tripid].Latitude.max() + 92 > coords[3]:
            coords[3] = Santa.T[tripid].Latitude.max() + 92

    band = .1
    plt.xlim(coords[0] * (1 - band) - 182,
             min(coords[1] * (1 + band) - 182, 180))
    plt.ylim(coords[2] * (1 - band) - 92, min(coords[3] * (1 + band) - 92, 90))
    plt.title('Worst Trips - Most Wasted Movement', fontsize=20)
    plt.tight_layout()
Esempio n. 5
0
def visualize_save(test_image, heatmaps, prediction, param, model):
    directory = '../results/'
    if not os.path.exists(directory):
        os.makedirs(directory)

    colormap = cm.jet_r
    oriImg = cv.imread(test_image)
    prediction = prediction.astype(np.int)

    prefix = os.path.basename(test_image).split('.')[0]
    npart = model['np']

    # save heatmap superimposed and marked images
    for c in range(heatmaps.shape[2]):
        colorized = colormap(heatmaps[:, :, c])
        img_superimposed = (colorized[:, :, 0:3] * 255 + oriImg) / 2
        img_superimposed = img_superimposed.astype(np.uint8)
        #print img_superimposed
        if c != npart:
            img_superimposed = drawCross(img_superimposed, prediction[c])
        cv.imwrite('%s/%s_heatmap%d.png' % (directory, prefix, c + 1),
                   img_superimposed)

    # draw limbs
    limbs = model['limbs']
    colormap = cm.get_cmap('hsv_r')
    facealpha = 0.6

    bodyHeight = np.max(prediction[:, 0]) - np.min(prediction[:, 0])
    stickwidth = oriImg.shape[0] / 30.0
    thre = 0.05

    img_stickman = oriImg.copy()
    for p in range(limbs.shape[0]):
        x1 = prediction[limbs[p, 0] - 1, 0]
        y1 = prediction[limbs[p, 0] - 1, 1]
        if heatmaps[x1, y1, limbs[p, 0] - 1] < thre:
            continue
        x2 = prediction[limbs[p, 1] - 1, 0]
        y2 = prediction[limbs[p, 1] - 1, 1]
        if heatmaps[x2, y2, limbs[p, 1] - 1] < thre:
            continue

        X = prediction[limbs[p, :] - 1, 0]
        Y = prediction[limbs[p, :] - 1, 1]
        mX = np.mean(X)
        mY = np.mean(Y)
        length = ((X[0] - X[1])**2 + (Y[0] - Y[1])**2)**0.5
        if Y[0] - Y[1] == 0:
            angle = 90
        else:
            angle = math.degrees(
                math.atan(float(X[0] - X[1]) / float(Y[0] - Y[1])))
        polygon = cv.ellipse2Poly(
            (int(mY), int(mX)), (int(length / 2), int(stickwidth)), int(angle),
            0, 360, 1)
        color = [x * 255 for x in list(colormap(float(p) / limbs.shape[0]))]
        color = tuple(color[0:3])
        cv.fillConvexPoly(img_stickman, polygon, color)

    for c in range(heatmaps.shape[2] - 1):
        img_stickman = drawDot(img_stickman, prediction[c])

    cv.addWeighted(img_stickman, facealpha, oriImg, 1 - facealpha, 0,
                   img_stickman)
    cv.imwrite('%s/%s_stickman.png' % (directory, prefix), img_stickman)
Esempio n. 6
0
def visualize_save(test_image, heatmaps, prediction, param, model):
	directory = '../results/'
	if not os.path.exists(directory):
		os.makedirs(directory)

	colormap = cm.jet_r
	oriImg = cv.imread(test_image)
	prediction = prediction.astype(np.int)

	prefix = os.path.basename(test_image).split('.')[0]
	npart = model['np']

	# save heatmap superimposed and marked images
	for c in range(heatmaps.shape[2]):
		colorized = colormap(heatmaps[:,:,c])
		img_superimposed = (colorized[:,:,0:3] * 255 + oriImg)/2
		img_superimposed = img_superimposed.astype(np.uint8)
		#print img_superimposed
		if c != npart:
			img_superimposed = drawCross(img_superimposed, prediction[c])
		cv.imwrite('%s/%s_heatmap%d.png' % (directory, prefix, c+1), img_superimposed)

	# draw limbs
	limbs = model['limbs']
	colormap = cm.get_cmap('hsv_r')
	facealpha = 0.6

	bodyHeight = np.max(prediction[:,0]) - np.min(prediction[:,0])
	stickwidth = oriImg.shape[0]/30.0
	thre = 0.05

	img_stickman = oriImg.copy()
	for p in range(limbs.shape[0]):
		x1 = prediction[limbs[p,0]-1, 0]
		y1 = prediction[limbs[p,0]-1, 1]
		if heatmaps[x1,y1,limbs[p,0]-1] < thre:
			continue
		x2 = prediction[limbs[p,1]-1, 0]
		y2 = prediction[limbs[p,1]-1, 1]
		if heatmaps[x2,y2,limbs[p,1]-1] < thre:
			continue

		X = prediction[limbs[p,:]-1, 0]
		Y = prediction[limbs[p,:]-1, 1]
		mX = np.mean(X)
		mY = np.mean(Y)
		length = ((X[0] - X[1]) ** 2 + (Y[0] - Y[1]) ** 2) ** 0.5
		if Y[0] - Y[1] == 0:
			angle = 90
		else:
			angle = math.degrees(math.atan(float(X[0] - X[1]) / float(Y[0] - Y[1])))
		polygon = cv.ellipse2Poly((int(mY),int(mX)), (int(length/2), int(stickwidth)), int(angle), 0, 360, 1)
		color = [x * 255 for x in list(colormap(float(p)/limbs.shape[0]))]
		color = tuple(color[0:3])
		cv.fillConvexPoly(img_stickman, polygon, color)
		
	for c in range(heatmaps.shape[2]-1):
		img_stickman = drawDot(img_stickman, prediction[c])

	cv.addWeighted(img_stickman, facealpha, oriImg, 1 - facealpha, 0, img_stickman)
	cv.imwrite('%s/%s_stickman.png' % (directory, prefix), img_stickman)
Esempio n. 7
0
    matplotlib.use(
        'Agg')  #makes sure matplotlib doesn't look for a display when plotting

import matplotlib.pylab as plt
import tangos
import pynbody
from tangos.examples import mergers
from pynbody.plot import image
from matplotlib.pylab import cm
from scipy.stats import binned_statistic
import gc

plot_rain = False
plot_zoom = False
plot_mixing = True
cmap = cm.get_cmap('magma')

#load particles
basename = '/nobackupp2/mtremmel/Romulus/'
datadir = basename + 'h1.cosmo50/h1.cosmo50PLK.1536gst1bwK1BH.004096'

#load halo database
db = tangos.get_simulation('h1.cosmo50')
steps = db.timesteps
stepname = [step.relative_filename for step in steps]
steptime = [step.time_gyr for step in steps]
stepnum = -1
halonum = 0  #generalize these later
halo = steps[stepnum].halos[halonum]
bh = halo['BH_central'][0]
halonum_pb = halo.halo_number
Esempio n. 8
0
g_LB = (g_temp.LB * g_temp.Weight).sum() + Dmax
room = g_LB - WRW_start

g1, g2 = split_trip(g_temp)

WRW1 = wrw_trip(g1)
WRW2 = wrw_trip(g2)

print 'WRW 2 seperate trips =', WRW2 + WRW1

##################################
# Plot

n = 3
# create the new map
cmap = cm.get_cmap('winter')
colors = [cmap(1. * i / n) for i in range(n)]
# create the new map
cmap = cm.get_cmap('winter', 33)

plt.figure('2 Trips', figsize=(17, 11))
plt.scatter(gifts.Longitude, gifts.Latitude, color='gray')

plt.scatter(g1['Longitude'], g1['Latitude'], s=g1['Weight'], color='red')
plt.plot(g1['Longitude'], g1['Latitude'], color=colors[1])

plt.scatter(g2['Longitude'], g2['Latitude'], s=g2['Weight'], color='red')
plt.plot(g2['Longitude'], g2['Latitude'], color=colors[2])

coords = [
    g_temp.Longitude.min(),