コード例 #1
0
ファイル: photometry.py プロジェクト: john-livingston/etp
def get_centroids(cube):
	p = progbar(15, "computing centroids")
	tot = cube.shape[0]
	s = tot / 15
	im = cube[0]
	x0 = y0 = 12
	x1 = y1 = 19
	mask = np.repeat(True, im.size).reshape(im.shape)
	mask[x0:x1,y0:y1] = False
	centroid = []
	for k,im in enumerate(cube):
		ma = np.ma.masked_array(im, mask)
		masked = ma.filled(0)
		centroid.append(centroid_com(masked))
		if (k+1) % s == 0: p.write()
	p.close()
	centroid = np.array(centroid)
	return centroid
コード例 #2
0
ファイル: photometry.py プロジェクト: john-livingston/etp
def subtract_bg(cube):
	p = progbar(15, "subtracting background")
	tot = cube.shape[0]
	s = tot / 15
	mask = np.zeros(cube[0].shape).astype(bool)
	mask[6:-6, 6:-6] = True
	mask[12:16,:] = True
	mask[:,13:15] = True
	mask[:,31] = True
	unc = []
	for k,im in enumerate(cube):
		good = ~np.isnan(im) & ~mask
		fit = stats.norm.fit(im[good])
		unc.append(fit[1])
		im -= fit[0]
		if (k+1) % s == 0: p.write()
	p.close()
	unc = np.array(unc)
	return cube, unc
コード例 #3
0
ファイル: photometry.py プロジェクト: john-livingston/etp
def read_data(data_dir):

	search_str = "*I2*_bcd.fits"
	files = list(find_files(data_dir, search_str))

	hdr = fits.getheader(files[0]).copy()
	if hdr['NAXIS1'] == 256:
		subarray = False
	else:
		subarray = True

	# read data and header keyword values
	p = progbar(15, "reading data")
	tot = len(files)
	s = tot / 15
	data, time_bmjd, obs_length_s = [], [], []
	for i,fp in enumerate(files):
		hdr = fits.getheader(fp).copy()
		im = fits.getdata(fp).copy()
		# hdulist = fits.open(fp)
		# hdr, im = hdulist[0].header.copy(), hdulist[0].data.copy()
		# hdulist.close()
		data.append(im)
		time_bmjd.append(hdr['BMJD_OBS'])
		obs_length_s.append(hdr['ATIMEEND'] - hdr['AINTBEG'])
		if (i+1) % s == 0: p.write()
	p.close()

	# make into arrays and sort by start time
	data, time_bmjd, obs_length_s = map(np.array, [data, time_bmjd, obs_length_s])
	time_bjd = time_bmjd + 2400000.5
	# assert np.all(idx == np.arange(idx.size)) # ensure already time-sorted
	idx = np.argsort(time_bmjd)
	time_bmjd = time_bmjd[idx]
	time_bjd = time_bjd[idx]
	obs_length_s = obs_length_s[idx]
	data = data[idx]
	assert np.all(np.argsort(time_bmjd) == np.arange(idx.size))

	# calculate times for each individual frame
	p = progbar(15, "calculating timestamps")
	tot = len(time_bjd)
	s = tot / 15
	k = 0
	time = []
	for t, length_s in zip(time_bjd, obs_length_s):
		length_d = length_s * (1./60) * (1./60) * (1./24)
		if subarray:
			frame_length = length_d / 64.
			for i in range(64):
				time.append(t + frame_length * i)
		else:
			time.append(t + length_d / 2.)
		if (k+1) % s == 0: p.write()
		k += 1
	p.close()

	time = np.array(time)
	assert all([time[i] < time[i+1] for i in range(time.size-1)]) # another paranoid check

	# create data cube
	if subarray:
		cube = data.reshape(data.shape[0] * data.shape[1], data.shape[2], data.shape[3])
	else:
		cube = np.array([i[-40:-8,8:40] for i in data])
		return time, cube