def main(): """ Reading a FITS file and finding the clusters in the image, after background removal. We use multithreading to accelerate the cluster exploration. """ input_file_path = "/Users/npac09/PycharmProjects/npac09/data/specific.fits" # open file and retrieve data header, pixels = mylib.open_fits(input_file_path) # creation of the histogram from the data bin_number = 200 bin_values, bin_boundaries = np.histogram(pixels.ravel(), bin_number) # apply the fit (no need for the amplitude (first parameter)) _, background, dispersion = mylib.gaussian_fit(bin_boundaries[:-1], bin_values) # We define the threshold at 6 standard deviations above the mean bkg value threshold = background + (6.0 * dispersion) cluster_list = find_cluster(header, pixels, threshold) print cluster_list return 0
def main(): """ Reading and displaying a FITS file """ input_file_path = "/Users/npac09/PycharmProjects/npac09/data/specific.fits" output_file_path = "/Users/npac09/PycharmProjects/npac09/src/ex1.txt" # open file and retrieve data header, pixels = mylib.open_fits(input_file_path) # plot _, pads = plt.subplots() pads.imshow(pixels) plt.show() # write result to output file try: with open(output_file_path, 'w') as output_file: output_file.write('cd1_1: %.10f, cd1_2: %.10f, cd2_1: %.10f, cd2_2: %.10f' \ % (header['CD1_1'], header['CD1_2'], header['CD2_1'], header['CD2_2'])) except IOError: print "File not found :", output_file_path return 2 return 0
def main(): """ Display the FITS image with a slider controlling the background level to be removed. Given this background, displays the number of clusters found """ input_file_path = "/Users/npac09/PycharmProjects/npac09/data/specific.fits" # open file and retrieve data header, pixels = mylib.open_fits(input_file_path) # creation of the histogram from the data bin_number = 200 bin_values, bin_boundaries = np.histogram(pixels.ravel(), bin_number) # apply the fit _, background, dispersion = mylib.gaussian_fit(bin_boundaries[:-1], bin_values) # Call the event handler event_handler(header, pixels, background, dispersion) # display plt.show() return 0
def main(): """ Display the FITS image with a slider controlling the background level to be removed """ input_file_path = "/Users/npac09/PycharmProjects/npac09/data/specific.fits" # open file and retrieve data _, pixels = mylib.open_fits(input_file_path) # creation of the histogram from the data bin_number = 200 bin_values, bin_boundaries = np.histogram(pixels.ravel(), bin_number) # apply the fit _, background, dispersion = mylib.gaussian_fit(bin_boundaries[:-1], bin_values) # Call the event handler event_handler(pixels, background, dispersion) # display plt.show() return 0
def main(): """ We read a FITS file, find the clusters, and convert their centroid coordinates to WCS coordinates. Then we display the WCS coordinates on the image, following the mouse movement. """ input_file_path = "/Users/npac09/PycharmProjects/npac09/data/specific.fits" output_file_path = "/Users/npac09/PycharmProjects/npac09/src/ex4.txt" # open file and retrieve data and header header, pixels = mylib.open_fits(input_file_path) # creation of the histogram from the data bin_number = 200 bin_values, bin_boundaries = np.histogram(pixels.ravel(), bin_number) # apply the fit (no need for the amplitude (first parameter)) _, background, dispersion = mylib.gaussian_fit(bin_boundaries[:-1], bin_values) # We define the threshold at 6 standard deviations above the mean bkg value threshold = background + (6.0 * dispersion) # plot fig, pads = plt.subplots() # visualization of the image after bkg removal pads.imshow(mylib.remove_background(pixels, background, threshold)) # find the clusters. cluster_list = mylib.find_clusters(header, pixels, threshold) cluster_dico = mylib.build_cluster_dico(cluster_list) # find the maximum-integral cluster max_integral_key = mylib.find_max_integral_cluster(cluster_list) # call the event handler event_handler(fig, header, pixels) # display plt.show() # write result to output file try: with open(output_file_path, 'w') as output_file: output_file.write('right ascension: %.3f, declination: %.3f' \ % (cluster_dico[max_integral_key][0].centroid_wcs)) except IOError: print "File not found :", output_file_path return 2 return 0
def main(): """ Reading a FITS file and determining the background parameters. """ input_file_path = "/Users/npac09/PycharmProjects/npac09/data/specific.fits" output_file_path = "/Users/npac09/PycharmProjects/npac09/src/ex2.txt" # open file and retrieve data _, pixels = mylib.open_fits(input_file_path) # creation of the histogram from the data bin_number = 200 bin_values, bin_boundaries = np.histogram(pixels.ravel(), bin_number) bin_lower_boundaries = bin_boundaries[:-1] # apply the fit maxvalue, background, dispersion = mylib.gaussian_fit( bin_lower_boundaries, bin_values) threshold = 6.0 * dispersion # visualization of the histogram and the fit _, pads = plt.subplots(1, 3) # 0: image before bkg removal; # 1: image after bkg removal; 2: histogram and fit pads[2].plot(bin_lower_boundaries, bin_values, 'b+:', label='data') pads[2].plot(bin_lower_boundaries, \ mylib.gaussian(bin_lower_boundaries, maxvalue, background, dispersion), \ 'r.:', label='fit') pads[2].legend() pads[2].set_title('Flux distribution') pads[2].set_xlabel('Amplitude') pads[2].set_ylabel('Frequency') # visualization of the image before and after bkg removal pads[0].imshow(pixels) pads[1].imshow(mylib.remove_background(pixels, background, threshold)) plt.show() # write result to output file try: with open(output_file_path, 'w') as output_file: output_file.write('background: %d, dispersion: %d' % (int(background), int(dispersion))) except IOError: print "File not found :", output_file_path return 2 return 0
def main(): """ Reading a FITS file and determining the background parameters. """ input_file_path = "/Users/npac09/PycharmProjects/npac09/data/specific.fits" output_file_path = "/Users/npac09/PycharmProjects/npac09/src/ex2.txt" # open file and retrieve data _, pixels = mylib.open_fits(input_file_path) # creation of the histogram from the data bin_number = 200 bin_values, bin_boundaries = np.histogram(pixels.ravel(), bin_number) bin_lower_boundaries = bin_boundaries[:-1] # apply the fit maxvalue, background, dispersion = mylib.gaussian_fit(bin_lower_boundaries, bin_values) threshold = 6.0 * dispersion # visualization of the histogram and the fit _, pads = plt.subplots(1, 3) # 0: image before bkg removal; # 1: image after bkg removal; 2: histogram and fit pads[2].plot(bin_lower_boundaries, bin_values, 'b+:', label='data') pads[2].plot(bin_lower_boundaries, \ mylib.gaussian(bin_lower_boundaries, maxvalue, background, dispersion), \ 'r.:', label='fit') pads[2].legend() pads[2].set_title('Flux distribution') pads[2].set_xlabel('Amplitude') pads[2].set_ylabel('Frequency') # visualization of the image before and after bkg removal pads[0].imshow(pixels) pads[1].imshow(mylib.remove_background(pixels, background, threshold)) plt.show() # write result to output file try: with open(output_file_path, 'w') as output_file: output_file.write('background: %d, dispersion: %d' % (int(background), int(dispersion))) except IOError: print "File not found :", output_file_path return 2 return 0
def main(): """ Reading a FITS file and finding the clusters in the image, after background removal. """ input_file_path = "/Users/npac09/PycharmProjects/npac09/data/specific.fits" output_file_path = "/Users/npac09/PycharmProjects/npac09/src/ex3.txt" # open file and retrieve data header, pixels = mylib.open_fits(input_file_path) # creation of the histogram from the data bin_number = 200 bin_values, bin_boundaries = np.histogram(pixels.ravel(), bin_number) # apply the fit (no need for the amplitude (first parameter)) _, background, dispersion = mylib.gaussian_fit(bin_boundaries[:-1], bin_values) # We define the threshold at 6 standard deviations above the mean bkg value threshold = background + (6.0 * dispersion) # find the clusters. cluster_list = mylib.find_clusters(header, pixels, threshold) cluster_dico = mylib.build_cluster_dico(cluster_list) # find the maximum-integral cluster max_integral_key = mylib.find_max_integral_cluster(cluster_list) # write result to output file try: with open(output_file_path, 'w') as output_file: output_file.write( 'number of clusters: %2d, greatest integral: %7d, ' 'centroid x: %4.1f, centroid y: %4.1f' % (len(cluster_list), cluster_dico[max_integral_key][0].integral, cluster_dico[max_integral_key][0].centroid[0], cluster_dico[max_integral_key][0].centroid[1])) except IOError: print "File not found :", output_file_path return 2 return 0
def main(): """ Reading a FITS file and finding the clusters in the image, after background removal. """ input_file_path = "/Users/npac09/PycharmProjects/npac09/data/specific.fits" output_file_path = "/Users/npac09/PycharmProjects/npac09/src/ex3.txt" # open file and retrieve data header, pixels = mylib.open_fits(input_file_path) # creation of the histogram from the data bin_number = 200 bin_values, bin_boundaries = np.histogram(pixels.ravel(), bin_number) # apply the fit (no need for the amplitude (first parameter)) _, background, dispersion = mylib.gaussian_fit(bin_boundaries[:-1], bin_values) # We define the threshold at 6 standard deviations above the mean bkg value threshold = background + (6.0 * dispersion) # find the clusters. cluster_list = mylib.find_clusters(header, pixels, threshold) cluster_dico = mylib.build_cluster_dico(cluster_list) # find the maximum-integral cluster max_integral_key = mylib.find_max_integral_cluster(cluster_list) # write result to output file try: with open(output_file_path, 'w') as output_file: output_file.write('number of clusters: %2d, greatest integral: %7d, ' 'centroid x: %4.1f, centroid y: %4.1f' % (len(cluster_list), cluster_dico[max_integral_key][0].integral, cluster_dico[max_integral_key][0].centroid[0], cluster_dico[max_integral_key][0].centroid[1])) except IOError: print "File not found :", output_file_path return 2 return 0
def main(): """ We read a FITS file, find the clusters, and convert their centroid coordinates to WCS coordinates. Then we display the celestial objects names on the image, at click on the corresponding object on the image. """ input_file_path = "/Users/npac09/PycharmProjects/npac09/data/specific.fits" output_file_path = "/Users/npac09/PycharmProjects/npac09/src/ex5.txt" # open file and retrieve data and header header, pixels = mylib.open_fits(input_file_path) # creation of the histogram from the data bin_number = 200 bin_values, bin_boundaries = np.histogram(pixels.ravel(), bin_number) # apply the fit (no need for the amplitude (first parameter)) _, background, dispersion = mylib.gaussian_fit(bin_boundaries[:-1], bin_values) # We define the threshold at 6 standard deviations above the mean bkg value threshold = background + (6.0 * dispersion) # define an accetance radius around a given position to get the name from Simbad radius = 0.003 cluster_list = mylib.find_clusters(header, pixels, threshold) cluster_dico = mylib.build_cluster_dico(cluster_list, radius) # plot fig, pads = plt.subplots() # Display the image without background pads.imshow(mylib.remove_background(pixels, background, threshold)) # Display the boxes around clusters for cluster in cluster_list: pads.add_patch( patches.Rectangle((cluster.box_xmin, cluster.box_ymin), cluster.box_xmax - cluster.box_xmin, cluster.box_ymax - cluster.box_ymin, fill=False, color='white')) # find the maximum-integral cluster max_integral_key = mylib.find_max_integral_cluster(cluster_list) # call the event handler event_handler(fig, header, pixels, cluster_list, cluster_dico) plt.show() # write result to output file try: with open(output_file_path, 'w') as output_file: output_file.write('celestial object: %s' % cluster_dico[max_integral_key][1]) except IOError: print "File not found :", output_file_path return 2 return 0