def load_catalog(filename=False, header=False, wcs=False, ra_key=False, dec_key=False): ''' From Anna Marini: get positions from catalog. ''' if filename and not header: header = get_fits_header(filename) if header and not wcs: wcs = WCS(header) if ra_key and dec_key: ra = header[ra_key] dec = header[dec_key] ra = wcs.wcs.crval[0] dec = wcs.wcs.crval[1] # Diagonal diag_bound = wcs.pixel_to_world_values([[0, 0], wcs.pixel_shape]) radius = np.mean(diag_bound[1] - diag_bound[0]) / 2 catalog = Catalogs.query_region( f'{ra} {dec}', # frame='icrs', # unit="deg", radius=radius, catalog='Gaia', version=2) return catalog
def counts(filename, bias1='1_CCD_Image_34.fits', bias2='1_CCD_Image_47.fits', bias3='1_CCD_Image_75.fits', bias4='2_CCD_Image_191.fits', bias5='2_CCD_Image_244.fits', bias6='2_CCD_Image_277.fits', bias7='3_CCD_Image_52.fits', bias8='3_CCD_Image_103.fits', bias9='3_CCD_Image_152.fits'): header = get_fits_header(filename) camera = header['INSTRUME'] temp = header['CCD-TEMP'] if camera == 'Atik Cameras': if temp <= 0.3: mean_sub = np.mean( get_fits_data(filename)[1007:3007, 631:2040]) - np.mean( get_fits_data(bias1)) elif 0.3 < temp <= 1.3: mean_sub = np.mean( get_fits_data(filename)[1007:3007, 631:2040]) - np.mean( get_fits_data(bias2)) else: mean_sub = np.mean( get_fits_data(filename)[1007:3007, 631:2040]) - np.mean( get_fits_data(bias3)) #intorno a 3 elif camera == 'SBIG STL-11000 3 CCD Camera w/ AO': if -5.5 <= temp <= -3.7: mean_sub = np.mean( get_fits_data(filename)[500:3508, 500:2172]) - np.mean( get_fits_data(bias4)) elif temp < -5.5: mean_sub = np.mean( get_fits_data(filename)[500:3508, 500:2172]) - np.mean( get_fits_data(bias5)) else: mean_sub = np.mean( get_fits_data(filename)[500:3508, 500:2172]) - np.mean( get_fits_data(bias6)) elif camera == 'SBIG STX-16801 3 CCD Camera w/ AO': if temp <= -19.3: mean_sub = np.mean( get_fits_data(filename)[500:3500, 500:3500]) - np.mean( get_fits_data(bias7)) elif -19.2 < temp <= -14.3: mean_sub = np.mean( get_fits_data(filename)[500:3500, 500:3500]) - np.mean( get_fits_data(bias8)) else: mean_sub = np.mean( get_fits_data(filename)[500:3500, 500:3500]) - np.mean( get_fits_data(bias9)) return (mean_sub)
def ins_temp(filename): header = get_fits_header(filename) instru = [header['INSTRUME']] if 'CCD-TEMP' in header: temp = [header['CCD-TEMP']] else: temp = [' '] return(instru, temp)
def __init__(self, filenames, fast=FAST): filenames = sorted(filenames) self.filenames = filenames lfil = len(filenames) log.info(f"dfits {lfil} files. It can take some seconds.") self.heads = [get_fits_header(f, fast=False) for f in filenames] for i, p in enumerate(filenames): self.heads[i]["FULLPATH"] = filenames[i] self.data = self.heads
def instrument_temperature_time_dateobs(filename): header = get_fits_header(filename) instru = [header['INSTRUME']] if 'CCD-TEMP' in header: temp = [header['CCD-TEMP']] else: temp = [' '] time = [header['EXPTIME']] date_obs = header['DATE-OBS'] return (instru, temp, time, date_obs)
def tab(filenames): filenames = sorted(filenames) time_table = Table() counts_unique_table = Table() for filename in filenames: header = get_fits_header(filename) counts_unique = counts(filename) time = header['EXPTIME'] time_table.add_column([time], rename_duplicate = True) counts_unique_table.add_column([counts_unique], rename_duplicate = True) return(time_table, counts_unique_table)
def signal_noise(filenames, my_instr="Mexman"): for filename in filenames: catalog = load_catalog(filename) apers = set_apertures(catalog) data = get_fits_data(filename) header = get_fits_header(filename) wcs = WCS(header) phot_table = do_photometry(data, apers=apers, wcs=wcs) pixar = apers[0].to_pixel(wcs) pixan = apers[1].to_pixel(wcs) bkg_mean = phot_table['aperture_sum_1'] / pixan.area R_star = phot_table['residual_aperture_sum'] R_sky = bkg_mean * pixar.area n_pix_aperture = pixan.area with open('instruments.json') as jfile: instrument_dict = json.load(jfile) instrument = instrument_dict[my_instr] # if header['INSTRUME'] == 'Mexman': # key = instrument_dict['Mexman'] # elif header['INSTRUME'] == 'DFOSC_FASU': # key = instrument_dict['DFOSC_FASU'] # elif header['INSTRUME'] == 'STL-11000 3 CCD Camera': # key = instrument_dict['STL-11000 3 CCD Camera'] # else: # log.warning('INSTRUMENT NOT FOUND ') gain = instrument['gain'] RON = instrument['ron'] if gain is None: log.warning(f'Gain not found for {instrument}') if ron is None: log.warning(f'Ron not found for {instrument}') signal_noise = (R_star)/[(R_star + R_sky + RON + (gain/2)**2)**1/2] # for now I'm neglecting Dark Current effects return(signal_noise)
flats = glob.glob("gj3470/*/flat/*.fit*") keys = ['ccdxbin', 'filter'] mbias = 'arp.MBIAS.ccdxbin=2.fits' master_flat(flats, keys, mbias=mbias) obj_all = glob.glob("gj3470/*/object/*.fit*") objects = Dfits(obj_all, fast=True).fitsort(['object']).unique_names_for( ('GJ3470', )) mflat = "arp.MFLAT.ccdxbin=2.filter=vacio+V3.fits" correct_image(objects, keys, mbias=mbias, mflat=mflat, new_header="Mexman") solver("*CLEAN*fits") solved = sorted(glob.glob("solved/*CLEAN*.new")) datas = [get_fits_header(f, fast=True)["MJD-OBS"] for f in solved] airmass = [get_fits_header(f, fast=True)["AIRMASS"] for f in solved] tables = apphot(solved, r=6, r_in=15.5, r_out=25) tabellone = np.array([tables[0][k] for k in tables[0].keys()]) tabellone = np.insert(tabellone, 0, [datas, airmass], axis=1) errorone = np.array([tables[1][k] for k in tables[1].keys()]) ascii.write(np.concatenate((tabellone, errorone), axis=1), "tabellone.txt", overwrite=True) #plot f u ($1-58800):(-2.5*log10($5/($4+$14+$16))) w lp pt 7, g u ($2-2458800):($8+2.5*log10(10**(-$10*.4)+10**(-$12*.4)+10**(-$13*0.4) ))-0.000 w lp pt 7 lc rgb "orange" #################################### # Main ####################################
def apphot(filenames, reference=0, display=DISPLAY, r=False, r_in=False, r_out=False): ''' Perform the aperture photometry ''' filenames = sorted(filenames) header0 = get_fits_header(filenames[reference]) wcs0 = WCS(header0) catalog = load_catalog(wcs=wcs0) if r and r_in and r_out: apers = set_apertures(catalog, r=r, r_in=r_in, r_out=r_out) else: apers = set_apertures(catalog) tables = Table() err_table = Table() if display: d = pyds9.DS9("ds9") for filename in filenames: header = get_fits_header(filename) data = get_fits_data(filename) wcs = WCS(header) #catalog = load_catalog(wcs=wcs) #apers = set_apertures(catalog, r=r, r_in=r_in, r_out=r_out) ron, gain, dark_current = ron_gain_dark() phot_table = do_photometry(data, apers, wcs, ron, gain, dark_current, obstime=header['MJD-OBS']) # phot_table = do_photometry(data, apers, wcs, obstime=header['MJD-OBS'], # flux=False, zero_point_flux=1) # positions = SkyCoord(catalog['ra'], catalog['dec'], # frame='icrs', # unit=(u.deg, u.deg)) if display: d.set(f"file {filename}") # for i,pos in enumerate(positions): # p = pos.to_pixel(wcs) # circ = f'circle({p[0]}, {p[1]}, {10})' # d.set("regions", circ) # d.set("region", f"text {p[0]} {p[1]} "+"{"+str(i)+"}") for i, aper in enumerate(apers[0].to_pixel(wcs)): circ = f'circle({aper.positions[0]}, {aper.positions[1]}, {aper.r})' d.set("regions", circ) d.set( "region", f"text {aper.positions[0]}, {aper.positions[1]} " + "{" + str(i) + "}") for aper in apers[1].to_pixel(wcs): circ = f'circle({aper.positions[0]}, {aper.positions[1]}, {aper.r_in})' d.set("regions", circ) circ = f'circle({aper.positions[0]}, {aper.positions[1]}, {aper.r_out})' d.set("regions", circ) tables.add_column(phot_table["residual_aperture_sum"], rename_duplicate=True) err_table.add_column(phot_table["error"], rename_duplicate=True) log.info(f"Done {filename}") return tables, err_table
def filename(self, value): ''' Setter for filename ''' self._filename = value self.head = get_fits_header(value)