Пример #1
0
def coefficients(category = None, rebin_type = 'log', n = 80, legend = True, save = True, show = False):
	data_path = get.data('pca', category)
	mkdir.plots(category = 'all', data_type = 'pca/coefficients')
	for i in range(n):
		x = np.zeros([100])
		k = 0
		plt.figure()
		plt.grid()
		for data_file in data_path:
			data_category = data_file.split('/')[1]
			dataset = h5py.File(data_file, 'r')	
			coefficients_normal = dataset['coefficients_normal']
			[m,n] = coefficients_normal.shape
			plt.scatter(x[:n], coefficients_normal[i,:], color = COLORS[k%len(COLORS)], label = data_category)
			x += 1
			k += 1
			dataset.close()

		plt.scatter(x[0] + 2, np.array([0]), color = 'white')
		plt.title('coefficient ' + str(i))
		if legend:
			plt.legend()
		if save:
			name = 'supernova_data/all/plots/pca/coefficients/coefficient_' + str(i) + '.eps'
			plt.savefig(name, format='eps', dpi = 3500)
		if show:
			plt.show()
		plt.close()
Пример #2
0
def pcomponents(category = None, components = [[0,1]], legend = True, save = True, show = False):
	data_path = get.data('pca', category)
	mkdir.plots(category = 'all', data_type = 'pca/pcomponents')
	for component in components:
		k = 0
		plots = []
		plot_names = []
		plt.figure()
		plt.grid()
		i = component[0]
		j = component[1]
		for data_file in data_path:
			data_category = data_file.split('/')[1]
			dataset = h5py.File(data_file, 'r')	
			coefficients_reduced = dataset['coefficients_reduced'][:]
			cx = coefficients_reduced[i,:]
			cy = coefficients_reduced[j,:]
			p = plt.scatter(cx, cy, color = COLORS[k%len(COLORS)], label = category)
			plots.append(p)
			plot_names.append(data_category)
			k += 1
		if legend:
			plt.legend(plot_names, loc='right', bbox_to_anchor = (1.1, 0.2), fancybox = True)
		plt.grid()
		plt.xlabel('c' + str(i))
		plt.ylabel('c' + str(j))
		plt.title('c' + str(i) + ' vs ' + 'c' + str(j))
		if save:
			name = 'supernova_data/all/plots/pca/pcomponents/' + 'c' + str(i) + '_vs_' + 'c' + str(j) + '.eps'
			plt.savefig(name, format='eps', dpi = 3500)
		if show:
			plt.show()
		plt.close()