def fetch_photometry_for_dataset(conn,ref_image_file): query = 'SELECT * FROM reference_images WHERE filename="'+str(ref_image_file)+'"' refimg = phot_db.query_to_astropy_table(conn, query, args=()) query = 'SELECT * FROM phot WHERE reference_image="'+str(refimg['refimg_id'][0])+'"' phot_table = phot_db.query_to_astropy_table(conn, query, args=()) return phot_table
def fetch_primary_reference_image_from_phot_db(conn): query = 'SELECT reference_image FROM stars' pri_refimg_id = phot_db.query_to_astropy_table(conn, query, args=()) query = 'SELECT * FROM reference_images WHERE refimg_id="'+str(pri_refimg_id['reference_image'][0])+'"' pri_refimg = phot_db.query_to_astropy_table(conn, query, args=()) return pri_refimg
def get_dataset_identifier(conn,entry): query = 'SELECT * FROM facilities WHERE facility_id="'+str(entry['facility'])+'"' facility = phot_db.query_to_astropy_table(conn, query, args=()) query = 'SELECT * FROM filters WHERE filter_id="'+str(entry['filter'])+'"' f = phot_db.query_to_astropy_table(conn, query, args=()) dataset_code = facility['facility_code'][0]+'_'+f['filter_name'][0] return dataset_code
def fetch_reference_component_image(conn, refimage_id): query = 'SELECT * FROM reference_components WHERE reference_image="'+str(refimage_id)+'"' ref_comp = phot_db.query_to_astropy_table(conn, query, args=()) if len(ref_comp) > 0: query = 'SELECT * FROM images WHERE img_id="'+str(ref_comp['image'][0])+'"' image = phot_db.query_to_astropy_table(conn, query, args=()) return image
def fetch_photometry_for_star(conn, star_id, log=None): query = 'SELECT * FROM phot WHERE star_id="'+str(star_id)+'"' phot_table = phot_db.query_to_astropy_table(conn, query, args=()) if log != None: log.info('Extracted '+str(len(phot_table))+' datapoints for star '+str(star_id)) return phot_table
def fetch_primary_reference_photometry(conn,pri_refimg): query = 'SELECT * FROM phot WHERE reference_image="'+str(pri_refimg['refimg_id'][0])+'"' print(query) pri_phot_table = phot_db.query_to_astropy_table(conn, query, args=()) print('Extracted '+str(len(pri_phot_table))+' photometric datapoints for the primary reference image') return pri_phot_table
def fetch_starlist_from_phot_db(conn,pri_refimg,log=None): query = 'SELECT * FROM stars WHERE reference_image="'+str(pri_refimg['refimg_id'][0])+'"' stars_table = phot_db.query_to_astropy_table(conn, query, args=()) if log != None: log.info('Found '+str(len(stars_table))+' stars in the photometric database') return stars_table
def extract_med_poisson(conn, ra, dec, radius, filt, telo): center = SkyCoord(ra, dec, frame='icrs', unit=(units.hourangle, units.deg)) results = phot_db.box_search_on_position(conn, center.ra.deg, center.dec.deg, radius, radius) medians = [] stds = [] if len(results) > 0: for star_id in tqdm(results['star_id']): query = 'SELECT filter, image, facility, hjd, calibrated_mag, calibrated_mag_err, calibrated_flux, calibrated_flux_err FROM phot WHERE star_id="' + str( star_id) + '" AND filter="' + str( filt_choice) + '" AND facility="' + str(telo) + '"' phot_table = phot_db.query_to_astropy_table(conn, query, args=()) #import pdb; pdb.set_trace() datasets = identify_unique_datasets(phot_table, facilities, filters) mask = phot_table['calibrated_mag'] > 0 uncerts = np.asarray(phot_table['calibrated_mag_err'][mask]) mags = np.asarray(phot_table['calibrated_mag'][mask]) flux = np.asarray(phot_table['calibrated_flux']) fluxuncerts = np.asarray(phot_table['calibrated_flux_err']) exposure_times = [] for image in np.asarray(phot_table['image']): query = 'SELECT exposure_time FROM images WHERE img_id = "' + str( image) + '"' phot_table = phot_db.query_to_astropy_table(conn, query, args=()) exposure_times.append(phot_table[0][0]) flux = flux * exposure_times fluxuncerts = fluxuncerts * exposure_times mean = weighted_mean(mags, uncerts) std = np.sqrt(weighted_mean(flux, fluxuncerts)) if (mean > 10) and (len(mags) > 5) and (std > 0): medians.append(mean) stds.append(std) return medians, stds
def get_image_entry(conn, image_id): query = 'SELECT * FROM images WHERE img_id="' + str(image_id) + '"' image = phot_db.query_to_astropy_table(conn, query, args=()) return image
def fetch_dataset_list(conn): query = 'SELECT * FROM reference_images' datasets = phot_db.query_to_astropy_table(conn, query, args=()) return datasets
def fetch_star_colours(conn): query = 'SELECT * FROM star_colours' star_colours = phot_db.query_to_astropy_table(conn, query, args=()) return star_colours