Created
March 12, 2025 14:11
-
-
Save dvida/fa37985c424d36daa0ad029d2d15f277 to your computer and use it in GitHub Desktop.
Exploring astrometry.net fits files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # %% | |
| dir_path = "C:\\Users\\denis\\Downloads" | |
| corr_file = "corr.fits" | |
| imgradec_file = "image-radec.fits" | |
| rdls_file = "rdls.fits" | |
| import os | |
| from astropy.io import fits | |
| # %% | |
| # Load the FITS file | |
| corr_hdulist = fits.open(os.path.join(dir_path, corr_file)) | |
| corr_hdulist.info() | |
| # Select the second HDU | |
| corr_hdu = corr_hdulist[1] | |
| # Display the header information | |
| corr_hdu.header | |
| # Extract the data | |
| corr_data = corr_hdu.data | |
| #print(data) | |
| # Print the data with column names and then the first row | |
| print(corr_data.columns) | |
| print(corr_data[0]) | |
| print(corr_data[1]) | |
| # Extract the first four columns of data into a numpy array | |
| import numpy as np | |
| x_data = corr_data['field_x'] | |
| y_data = corr_data['field_y'] | |
| ra_data = corr_data['index_ra'] | |
| dec_data = corr_data['index_dec'] | |
| data_array = np.array([x_data, y_data, ra_data, dec_data]).T | |
| print(data_array) | |
| # %% | |
| # Load the image-radec FITS file | |
| imgradec_hdulist = fits.open(os.path.join(dir_path, imgradec_file)) | |
| imgradec_hdulist.info() | |
| # Select the second HDU | |
| imgradec_hdu = imgradec_hdulist[1] | |
| # Display the header information | |
| imgradec_hdu.header | |
| # Extract the data | |
| imgradec_data = imgradec_hdu.data | |
| print(imgradec_data.columns) | |
| print(imgradec_data[0]) | |
| # %% | |
| # Load the rdls FITS file | |
| rdls_hdulist = fits.open(os.path.join(dir_path, rdls_file)) | |
| rdls_hdulist.info() | |
| # Select the second HDU | |
| rdls_hdu = rdls_hdulist[1] | |
| # Display the header information | |
| rdls_hdu.header | |
| # Extract the data | |
| rdls_data = rdls_hdu.data | |
| print(rdls_data.columns) | |
| print(rdls_data[0]) | |
| print(rdls_data[1]) | |
| print(rdls_data[2]) | |
| # %% | |
| # Extract the index_id from corr_data and find the associated data in rdls_data | |
| field_id = corr_data['field_id'] | |
| match_wieght = corr_data['match_weight'] | |
| flux_data = corr_data['flux'] | |
| print(field_id) | |
| ra_data = [] | |
| dec_data = [] | |
| for mw, ind, x, y, flux in zip(match_wieght, field_id, x_data, y_data, flux_data): | |
| # # Skip all entires with a match weight smaller than 0.5 | |
| # if mw < 0.5: | |
| # continue | |
| # # Skip all entries with a flux smaller than 5 | |
| # if flux <= 5: | |
| # continue | |
| rdls_entry = rdls_data[ind] | |
| ra = rdls_entry['RA'] | |
| dec = rdls_entry['DEC'] | |
| print("x = {:8.2f}, y = {:8.2f}, ra = {:8.2f}, dec = {:8.2f}, weight = {:8.2f}, flux = {:8d}".format(x, y, ra, dec, mw, int(flux))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment