def main(): file_name, interactive = lib_args.get_args() header, pixels = lib_fits.read_first_image(file_name) background, dispersion, _ = lib_background.compute_background(pixels) # search for clusters clustering = RecursiveClustering() clusters = clustering(pixels, background, dispersion) max_cluster = clusters[0] wcs = lib_wcs.get_wcs(header) pxy = lib_wcs.PixelXY(max_cluster.column, max_cluster.row) radec = lib_wcs.xy_to_radec(wcs, pxy) cobjects, _, _ = lib_stars.get_celestial_objects(radec) # console output print( 'number of clusters: {:2d}, greatest integral: {:7d}, x: {:4.1f}, y: {:4.1f}' .format(len(clusters), max_cluster.integral, max_cluster.column, max_cluster.row)) for cobj in cobjects.keys(): print('celestial object: {}'.format(cobj)) # graphic output if interactive: _, axis = plt.subplots() axis.imshow(lib_cluster.add_crosses(pixels, clusters)) plt.show() return 0
def main(): file_name, interactive = lib_args.get_args() # importing image pixels = None pixels, header = lib_fits.read_first_image(file_name) my_wcs = lib_wcs.get_wcs(header) clusters = ex3_clusters.find_clusters(pixels, False) for j in range(len(clusters)): peak_pixel = lib_wcs.PixelXY(clusters[j].y, clusters[j].x) cel_coord = lib_wcs.xy_to_radec(my_wcs, peak_pixel) acc_radius = 0.001 celestial_objects, out, req = lib_stars.get_celestial_objects( cel_coord, acc_radius) signature_fmt_1 = 'RESULT: right_ascension_{:d} = {:.3f}'.format( j, cel_coord[0]) signature_fmt_2 = 'RESULT: declination_{:d} = {:.3f}'.format( j, cel_coord[1]) print(signature_fmt_1) print(signature_fmt_2) for i, key in enumerate(celestial_objects.keys()): signature_fmt_3 = 'RESULT: celestial_object_{:d}_{:d} = {}'.format( j, i, key) print(signature_fmt_3) # graphic output if interactive: fig, main_axes = plt.subplots() handler = Handler(fig, main_axes, my_wcs) main_axes.imshow(pixels) #fig.canvas.mpl_connect('motion_notify_event', handler.move) fig.canvas.mpl_connect('button_press_event', handler.on_click) plt.show() # end return 0
def on_click(self, event): if event.button == 1: # Create a transformation matrix axis = event.inaxes for txt in self.texts: txt.remove() for patch in self.patches: patch.remove() self.texts = [] self.patches = [] display_to_image = axis.transData.inverted() # Image coordinates returned as a list image_x_y = display_to_image.transform((event.x, event.y)) peak_pixel = lib_wcs.PixelXY(*image_x_y) cel_coord = lib_wcs.xy_to_radec(self.wcs, peak_pixel) #text = axis.text(*image_x_y, str(cel_coord[0]) + "\n" + str(cel_coord[1]), fontsize=10, color='white') acc_radius = 0.001 celestial_objects, out, req = lib_stars.get_celestial_objects( cel_coord, acc_radius) for i, key in enumerate(celestial_objects.keys()): patch = axis.add_patch( patches.Rectangle(image_x_y - 5, 10, 10, fill=False, color='white')) text = axis.text(image_x_y[0] + 6, image_x_y[1] - i * 5, key, fontsize=10, color='white') self.patches.append(patch) self.texts.append(text) print(key) event.canvas.draw() return
def main(): # analyse command line arguments file_name, interactive = lib_args.get_args() # importing image pixels = None pixels, header = lib_fits.read_first_image(file_name) my_wcs = lib_wcs.get_wcs(header) sorted_clusters = ex3_clusters.find_clusters(pixels, False) peak_pixel = lib_wcs.PixelXY(sorted_clusters[0].y, sorted_clusters[0].x) cel_coord = lib_wcs.xy_to_radec(my_wcs, peak_pixel) acc_radius = 0.001 celestial_objects, out, req = lib_stars.get_celestial_objects( cel_coord, acc_radius) signature_fmt_1 = 'RESULT: right_ascension = {:.3f}'.format(cel_coord[0]) signature_fmt_2 = 'RESULT: declination = {:.3f}'.format(cel_coord[1]) print(signature_fmt_1) print(signature_fmt_2) i = 0 for key in celestial_objects.keys(): signature_fmt_3 = 'RESULT: celestial_object_{:d} = {}'.format(i, key) print(signature_fmt_3) i += 1 # graphic output if interactive: # ... pass # end return 0
def get_celestial_objects(wcs, cluster): pxy = lib_wcs.PixelXY(cluster.column, cluster.row) radec = lib_wcs.xy_to_radec(wcs, pxy) return lib_stars.get_celestial_objects(radec)
if ((cl.row < pattern_diameter) or (cl.row >= (pixels.shape[0]-pattern_diameter)) or (cl.column < pattern_diameter) or (cl.column >= (pixels.shape[1]-pattern_diameter))): print('cluster {:d} is in the border'.format(icl, cl)) nb_patho += 1 # check max integral clusters are not too similar if len(clusters) > 1 and ((clusters[0].integral - clusters[1].integral) < 10.): print('clusters 0 and 1 are too similar') nb_patho += 1 # check lacking or multiple celestial objects for max cluster wcs = lib_wcs.get_wcs(header) pxy = lib_wcs.PixelXY(clusters[0].column, clusters[0].row) radec = lib_wcs.xy_to_radec(wcs, pxy) cobjects, _, _ = lib_stars.get_celestial_objects(radec) if len(cobjects) < 1: print('clusters 0 is associated with no celestial object') nb_patho += 1 if len(cobjects) > 1: print('clusters 0 is associated with multiple celestial objects') for icobj, cobj in enumerate(sorted(cobjects.keys())): print('celestial object {}: {}'.format(icobj, cobj)) nb_symptom += 1 # conclusion print('{} pathologies'.format(nb_patho)) print('{} symptoms'.format(nb_symptom)) sys.exit(nb_patho)