Esempio n. 1
0
def write(data_category, data_name, data_filename, spectrum):
	'''
	write() takes in a numpy array and outputs to a HDF5 file

	Parameters
	----------
	data_category : a string of the supernova's category

	data_name : a string of the name of the raw data

	data_filename : a string of the output filename

	spectrum : numpy array of the data that is going to be output
	'''
	if data_category != 'all':	
		mkdir.init(data_category)
	mkdir.data(data_category)
	data_file = h5py.File('supernova_data/' + data_category + '/data/' + data_filename + '.hdf5', 'a')
	if data_name in data_file.keys():
		if data_file[data_name].shape != spectrum.shape:
			data_file.__delitem__(data_name)
			data_file[data_name] = spectrum
		else:
			data_file[data_name][...] = spectrum
	else:
		data_file.create_dataset(data_name, data = spectrum)
	data_file.close()
Esempio n. 2
0
rebin_type = 'log'
show = False
compare = None
min_wave = 4000
max_wave = 8000
num_coefs = 80
data_file = None

if opts.init:
	if '[' in opts.init and ']' in opts.init and ',' in opts.init:
		category = opts.init.split('[')[1].split(']')[0].split(',')
	elif ',' in opts.init:
		category = opts.init.split(',')
	else:
		category = opts.init
	mkdir.init(category)
	sys.exit()

if opts.category:
	if '[' in opts.category and ']' in opts.category and ',' in opts.category:
		category = opts.category.split('[')[1].split(']')[0].split(',')
	elif ',' in opts.category:
		category = opts.category.split(',')
	else:
		category = opts.category
if opts.components:
	comps = opts.components.split('[')[1].split(']')[0].split(',')
	if len(comps) % 2 > 0:
		print 'Please enter an even number of principal components you want to analysis'
		sys.exit()
	else: