コード例 #1
0
def mapper(qresult, target_tp, target_radius):
	obj = lsd.colgroup.fromiter(qresult, blocks=True)
	
	if (obj != None) and (len(obj) > 0):
		# Find nearest target center to each star
		theta = np.pi/180. * (90. - obj['b'])
		phi = np.pi/180. * obj['l']
		tp_star = np.array([theta, phi]).T
		d = great_circle_dist(tp_star, target_tp) / target_radius
		min_idx = np.argmin(d, axis=1)
		
		# Group together stars belonging to the same target
		for target_idx, block_idx in iterators.index_by_key(min_idx):
			yield (target_idx, (d[block_idx,target_idx], obj[block_idx]))
コード例 #2
0
ファイル: mwgc.py プロジェクト: gregreen/galstar
def mapper(qresult, index, pos):
	obj = lsd.colgroup.fromiter(qresult, blocks=True)
	
	if (obj != None) and (len(obj) > 0):
		# Find nearest cluster center to each star
		theta_star = (90. - obj['b']) * np.pi/180.
		phi_star = obj['l'] * np.pi/180.
		tp_star = np.array([theta_star, phi_star]).T
		tp_gc = pos[:2].T
		d = great_circle_dist(tp_star, tp_gc)
		min_idx = np.argmin(d, axis=1)
		#d_min = np.min(d, axis=1)
		
		for gc_idx,block_idx in index_by_key(min_idx):
			yield (gc_idx, obj[block_idx])
コード例 #3
0
def mapper(qresult, nside, nest, bounds):
	obj = lsd.colgroup.fromiter(qresult, blocks=True)
	
	if (obj != None) and (len(obj) > 0):
		# Determine healpix index of each star
		theta = np.pi/180. * (90. - obj['b'])
		phi = np.pi/180. * obj['l']
		pix_indices = hp.ang2pix(nside, theta, phi, nest=nest)
		
		# Group together stars having same index
		for pix_index, block_indices in iterators.index_by_key(pix_indices):
			# Filter out pixels by bounds
			if bounds != None:
				theta_0, phi_0 = hp.pix2ang(nside, pix_index, nest=nest)
				l_0 = 180./np.pi * phi_0
				b_0 = 90. - 180./np.pi * theta_0
				if (l_0 < bounds[0]) or (l_0 > bounds[1]) or (b_0 < bounds[2]) or (b_0 > bounds[3]):
					continue
			
			yield (pix_index, obj[block_indices])
コード例 #4
0
def grid_models(d):
	# Select stars with reasonable SDSS photometry
	idx = (d['PSFMAG_u'] > 0.) & (d['PSFMAG_g'] > 0.) & (d['PSFMAG_r'] > 0.) & (d['PSFMAG_i'] > 0.) & (d['PSFMAG_z'] > 0.)
	idx = idx & (d['PSFMAGERR_u'] < 0.1) & (d['PSFMAGERR_g'] < 0.1) & (d['PSFMAGERR_r'] < 0.1) & (d['PSFMAGERR_i'] < 0.1) & (d['PSFMAGERR_z'] < 0.1)
	d = d[idx]
	print '# %d stars have acceptable SDSS photometry.' % len(d)
	
	# Determine stellar colors
	color = np.empty((4,len(d)), dtype=np.float32)
	color[0] = d['PSFMAG_u'] - d['PSFMAG_g']
	color[1] = d['PSFMAG_g'] - d['PSFMAG_r']
	color[2] = d['PSFMAG_r'] - d['PSFMAG_i']
	color[3] = d['PSFMAG_i'] - d['PSFMAG_z']
	
	# Grid spectra by stellar parameters
	N_Teff = 30
	N_FeH = 10
	N_logg = 2
	Teff = np.linspace(np.min(d['teff'])-1.e-10, np.max(d['teff'])+1.e-10, N_Teff)
	FeH = np.linspace(np.min(d['feh'])-1.e-10, np.max(d['feh'])+1.e-10, N_FeH)
	logg = np.linspace(np.min(d['logg'])-1.e-10, np.max(d['logg'])+1.e-10, N_logg)
	
	index_grid = np.mgrid[0:N_Teff, 0:N_FeH, 0:N_logg]
	Teff_grid = Teff[index_grid[0]].flatten()
	FeH_grid = FeH[index_grid[1]].flatten()
	logg_grid = logg[index_grid[2]].flatten()
	param_grid = np.vstack((Teff_grid, FeH_grid, logg_grid)).T
	#for i in range(100):
	#	print param_grid[i]
	
	idx_Teff = np.digitize(d['teff'], Teff) - 1
	idx_FeH = np.digitize(d['feh'], FeH) - 1
	idx_logg = np.digitize(d['logg'], logg) - 1
	grid_index = N_logg*N_FeH * idx_Teff + N_logg * idx_FeH + idx_logg
	mean_color = np.zeros((4,N_Teff*N_FeH*N_logg), dtype=np.float32)
	#mean_color.fill(np.nan)
	#weight = np.empty(50*20*20, dtype=np.float32)
	#weight.fill(0.)
	
	print np.min(idx_Teff), np.max(idx_Teff)
	print np.min(idx_FeH), np.max(idx_FeH)
	print np.min(idx_logg), np.max(idx_logg)
	
	for n,i in iterators.index_by_key(grid_index):
		for j in range(4):
			mean_color[j,n] = np.mean(color[j,i])
		#weight[n] = 1.
	
	#mean_color.shape = (4, 50, 20, 20)
	#weight.shape = (50, 20, 20)
	
	fig = plt.figure(figsize=(8,8))
	ax = fig.add_subplot(1,1,1)
	ax.plot(mean_color[0], mean_color[1], '.')
	
	# Interpolate colors over grid
	color_interp = []
	for j in range(4):
		idx = ~np.isnan(mean_color[j])
		fuzz = 0.001 * (np.random.random((np.sum(idx), 3)) - 0.5)
		print param_grid[idx]
		color_interp.append(scipy.interpolate.LinearNDInterpolator(param_grid, mean_color[j]))
	
	# Plot colors
	fig = plt.figure(figsize=(8,8))
	
	for i,FeH_i in enumerate([-2.5, -1.5, -0.5, 0.]):
		ax = fig.add_subplot(2,2,i+1)
		x = np.empty((200,3), dtype=np.float32)
		x[:,0] = np.linspace(np.min(d['teff']), np.max(d['teff']), 200)
		x[:,1] = FeH_i
		x[:,2] = np.mean(d['logg'])
		#print x
		ug = color_interp[0](x)
		gr = color_interp[1](x)
		idx = (ug != 0.) & (gr != 0.)
		#print ug
		#print gr
		ax.plot(ug[idx], gr[idx])
	
	return color_interp