コード例 #1
0
def parallelize_single_file(filename, output_file):
	"""This function analyzes a single file in parallel.
	64 FITS images are spread across our available ranks
	This implementation would be distinct from the parallelize_file_set function
	This breaks a single file's analysis into steps, but parallelize_file_set function spreads a set of files
	Beware: this function will fail on a system that has less than 2 threads
	"""
	print '(' + str(comm.Get_rank()) + ')', "Entered parallelizer."
	rank = comm.Get_rank()
	hdulist = fits.open(filename)
	frame_list = hdulist[0].data
	# Responsibilities for process 0, the file distributor
	if rank == 0:
		if size > NUM_FITS_IMAGES:
			print "You have more threads than images in a FITS file."
			print "Suggestion: revise your functions to take advantage of all threads."
		remainder = (NUM_FITS_IMAGES) % size
		imgs_per_rank = NUM_FITS_IMAGES / size
		print "(0) Assigned imgs ", 0, " through ", imgs_per_rank, " to process ", rank
		for process in range(1, size):
			#Distribute image numbers to each process
			if process != (size - 1):
				upper_bound = (process+1) * imgs_per_rank
			else:
				upper_bound = (process+1) * imgs_per_rank + remainder
			comm.send(range(process*imgs_per_rank, upper_bound), dest=process, tag=process)
			print "(0) Assigned imgs ", process*imgs_per_rank, " through ", upper_bound, " to process ", process
	# Responsibilities for all processes
	if rank != 0:
		my_range = comm.recv(source=0, tag=rank)
	if rank == 0:
		my_range = range(0, imgs_per_rank)
	sumA = 0
	sumB = 0
	for i in my_range:
		max_pixel = AC.brightest_region(frame_list[i])
		tmp = AC.frame_aperture(frame_list[i], max_pixel)
		sumA += tmp[0]
		sumB += tmp[1]
	print '(' + str(comm.Get_rank()) + ')', "Intermediate sum: ", (sumA, sumB)
	if rank != 0:
		comm.send((sumA, sumB), dest=0, tag=rank)
	if rank == 0:
		totalA = sumA
		totalB = sumB
		for process in range(1, size):
			z = comm.recv(source=process, tag=process)
			totalA += z[0]
			totalB += z[1]
		avg_apertureA = float(totalA) / (float(NUM_FITS_IMAGES))
		avg_apertureB = float(totalB) / (float(NUM_FITS_IMAGES))
		f = open(output_file, 'a')
		f.write(filename + '\t' + str((avg_apertureA, avg_apertureB)) + '\n')
		print "Final aperture val:", filename + '\t' + str((avg_apertureA, avg_apertureB))
		f.close()
	return
コード例 #2
0
from astropy.io import fits

FOCAL_LENGTH = 10.2				# In meters
DIAMETER = 0.85					# In meters
F_NUM = FOCAL_LENGTH/DIAMETER
WAVELENGTH = 3.6				# In microns

NUM_ROWS = 32					# The dimensions of a FITS image
NUM_COLS = 32

fits_file = "prototype_data/SPITZER_I1_41629440_0000_0000_1_bcd.fits"
hdulist = fits.open(fits_file)
frame_list = hdulist[0].data
avg_frame = ac.mk_avg_frame(frame_list)
max_pixel = ac.brightest_region(avg_frame)
rv = ac.frame_aperture(avg_frame, max_pixel)

s_n = [0.154547861818, 0.403526244264, 0.772498520473, 1.33493102866, 2.11287033914, 3.44958935702, 5.5838167695, 9.28302033016, 15.7997153381, 27.0342961138, 49.8872234858, 95.2443001898, 199.353286902, 454.247471923, 1366.3357413]
#for i in range(len(s_n)):
#	s_n[i] = s_n[i]/s_n[-1]

an_sum = [18560.9447522, 21859.9067966, 22793.8054371, 23751.4771974, 22396.5774943, 25454.3094973, 25498.6133756, 26717.4479049, 27129.5026967, 26564.0617414, 29080.7097892, 28853.3001293, 30392.3182606, 29923.7592573, 31420.1164373, 33063.7496585]

an_weight = [18560.9447522, 21304.8352603, 20565.3608689, 18843.4098908, 14840.8798195, 13381.6042331, 10101.6436409, 7576.32888009, 5230.62754907, 3307.61010714, 2221.22445384, 1284.13386742, 748.627449789, 387.493955085, 203.171683728, 101.40838172]
#for i in range(len(an_weight))


x = (range(NUM_ROWS/2))
y = []
p = []
flux = []