def main(): """ Exercise 4: Clusters """ lib_fits.init() print(lib_fits.file_name) header, pixels = lib_fits.read_first_image(lib_fits.file_name) thres = lib_background.threshold(pixels) peaks = lib_conv.complete_peaks_search(pixels) lums = lib_cluster.peak_lum(pixels, peaks) clusters = [] for i in range(len(peaks)): clust = lib_cluster.build_cluster(pixels, peaks[i], thres) if clust == None: continue else: clusters.append(clust) signature_fmt_1 = 'RESULT: clusters_number={:d}'.format(len(clusters)) signature_fmt_2 = 'RESULT: cluster_max_top={:d}'.format(max(lums)) print(signature_fmt_1) print(signature_fmt_2) sort_clus = lib_cluster.sort_clusters(clusters) bcfe = sort_clus[0] fig, main_axes = plt.subplots() main_axes.imshow(pixels) # Draws clusters arround peaks. for i in range(len(clusters)): xleft = clusters[i].coord[0] - clusters[i].ext xright = clusters[i].coord[0] + clusters[i].ext ybottom = clusters[i].coord[1] - clusters[i].ext ytop = clusters[i].coord[1] + clusters[i].ext squarex = [xleft, xright, xright, xleft, xleft] squarey = [ybottom, ybottom, ytop, ytop, ybottom] plt.plot(squarey, squarex, 'r--') plt.show() signature_fmt_3 = 'RESULT: cluster_max_integral={:d}'.format(bcfe.lum) signature_fmt_4 = 'RESULT: cluster_max_column={:d}'.format(bcfe.coord[1]) signature_fmt_5 = 'RESULT: cluster_max_row={:d}'.format(bcfe.coord[0]) signature_fmt_6 = 'RESULT: cluster_max_extension={:d}'.format(bcfe.ext) print(signature_fmt_3) print(signature_fmt_4) print(signature_fmt_5) print(signature_fmt_6) return 0
def main(): """ Exercise 6: Display stars """ lib_fits.init() print(lib_fits.file_name) global pixels global header header, pixels = lib_fits.read_first_image(lib_fits.file_name) clusters = lib_cluster.find_clusters(pixels) for i in range(6): rad = lib_stars.cluster_radec(clusters, i, header, pixels) lib_stars.celestial_objects(rad, i) return 0
def main(): """ Exercise 5: Stars """ lib_fits.init() print(lib_fits.file_name) global pixels global header header, pixels = lib_fits.read_first_image(lib_fits.file_name) clusters = lib_cluster.find_clusters(pixels) clusters_radec = [] for i in range(len(clusters)): clusters_radec.append( lib_stars.get_radec(clusters[i].coord[0], clusters[i].coord[1], header, pixels)) signature_fmt_1 = 'RESULT: right_ascension = {:.3f}'.format( clusters_radec[0][0]) signature_fmt_2 = 'RESULT: declination = {:.3f}'.format( clusters_radec[0][1]) print(signature_fmt_1) print(signature_fmt_2) celestial_objects = stars.get_celestial_objects(clusters_radec[0]) #print(celestial_objects) for i in range(len(celestial_objects[0])): signature_fmt_3 = 'RESULT: celestial_object_{:02d} = {:s}'.format( i, list(celestial_objects[0].keys())[i]) signature_fmt_4 = 'RESULT: dist_{:02d} = {:5.1f}'.format( i, list(celestial_objects[0].values())[i]) print(signature_fmt_3) print(signature_fmt_4) return 0
def main(): """ Exercise 1: Read Image """ #taking file name lib_fits.init() print(lib_fits.file_name) header, pixels = lib_fits.read_first_image(lib_fits.file_name) # show figure if lib_fits.interactive: fig, main_axes = plt.subplots() main_axes.imshow(pixels) plt.show() #signature signature_fmt_1 = 'RESULT: CRPIX1 = {:.0f}'.format(header.get("CRPIX1")) signature_fmt_2 = 'RESULT: CRPIX2 = {:.0f}'.format(header.get("CRPIX2")) print(signature_fmt_1) print(signature_fmt_2) return 0
def main(): """ Exercise 3: Peaks """ lib_fits.init() print(lib_fits.file_name) header, pixels = lib_fits.read_first_image(lib_fits.file_name) # Build Gaussian pattern pattern = lib_conv.pattern(9) plt.imshow(pattern) #plt.show() sum_pat = np.sum(pattern) pattern = pattern/sum_pat sum_pat_norm = np.sum(pattern) max_pat_norm = np.max(pattern) signature_fmt_1 = 'RESULT: pattern_sum={:.5f}'.format(sum_pat_norm) signature_fmt_2 = 'RESULT: pattern_max={:.5f}'.format(max_pat_norm) print(signature_fmt_1) print(signature_fmt_2) # Extend the image extended = lib_conv.extend(pixels, 4) plt.imshow(extended) plt.show() height = len(extended) width = len(extended[0]) sum = np.sum(extended) signature_fmt_3 = 'RESULT: extended_image_width={:d}'.format(width) signature_fmt_4 = 'RESULT: extended_image_height={:d}'.format(height) signature_fmt_5 = 'RESULT: extended_image_sum={:.0f}'.format(sum) print(signature_fmt_3) print(signature_fmt_4) print(signature_fmt_5) # Convoluted conv = lib_conv.scan(extended, 4, pattern) plt.imshow(conv) plt.show() conv_height = len(conv) conv_width = len(conv[0]) conv_sum = np.sum(conv) signature_fmt_6 = 'RESULT: convoluted_image_width={:d}'.format(conv_width) signature_fmt_7 = 'RESULT: convoluted_image_height={:d}'.format(conv_height) signature_fmt_8 = 'RESULT: convoluted_image_sum={:.0f}'.format(conv_sum) print(signature_fmt_6) print(signature_fmt_7) print(signature_fmt_8) # Extend the convolution image conv_ext = lib_conv.extend(conv, 1) conv_ext_height = len(conv_ext) conv_ext_width = len(conv_ext[0]) conv_ext_sum = np.sum(conv_ext) signature_fmt_9 = 'RESULT: extended_convoluted_image_width={:d}'.format(conv_ext_width) signature_fmt_10 = 'RESULT: extended_convoluted_image_height={:d}'.format(conv_ext_height) signature_fmt_11 = 'RESULT: extended_convoluted_image_sum={:.0f}'.format(conv_ext_sum) print(signature_fmt_9) print(signature_fmt_10) print(signature_fmt_11) # Identify the Peaks threshold = lib_background.threshold(pixels) print(threshold) peaks = lib_conv.peaks(conv_ext, 1, threshold) signature_fmt_12 = 'RESULT: peaks_number={:d}'.format(len(peaks)) print(signature_fmt_12) # end return 0