#print((gaia_data1["dec"])[rv_index]) #ra_vals = (gaia_data1["ra"])[rv_index] #dec_vals = (gaia_data1["dec"])[rv_index] gaia_IDs = (gaia_data1b)[rv_index] ticIDs = np.zeros(1265) additive = 0 #print(ra_vals[[0]]) #ra_vals = np.array(ra_vals) #dec_vals = np.array(dec_vals) while additive < 1265: mast_table = Catalogs.query_criteria(catalog="Tic", GAIA=str(gaia_IDs[additive]),objType="STAR") print(additive) ticIDs[additive] = int(mast_table["ID"][0]) additive += 1 print(ticIDs) ''' for element in ra_vals: print(element) print(np.where(ra_vals == element)[0][0]) print(ra_vals[np.where(ra_vals == element)[0][0]]) additive += 1 if additive == 10: break
def create_standard(self, trimmed): ''' Create a standardized table, pulling at least the necessary columns from the raw table and potentially including others too. ''' t = trimmed n = len(t) s = Table() # PICK UP FROM HERE!!!!!!!!!!!!! # pull out the name as the CTOI s['name'] = ['TOI{:.2f}'.format(c) for c in t['CTOI']] s['hostname'] = ['TOI{:.0f}'.format(c) for c in t['CTOI']] s['period'] = t['Period (days)'] s['transit_duration'] = t['Duration (hrs)'] / 24 s['stellar_teff'] = t['Stellar Eff Temp (K)'] s['stellar_radius'] = t['Stellar Radius (R_Sun)'] #t['TIC'].name = 'TIC ID' # search for the table from MAST print('downloading the TIC. this may take a minute? or restart?') tic_table = Catalogs.query_criteria(catalog="Tic", ID=np.unique(t['TIC ID'])) # preface all the columns with TIC so we can keep them straight for k in tic_table.colnames: tic_table[k].name = f'TIC {k}' # make sure the indices are integers tic_table['TIC ID'] = np.array(tic_table['TIC ID']).astype(np.int) withtic = join(t, tic_table, 'TIC ID', join_type='left') # pull out some magnitudes s['Jmag'] = withtic['TIC Jmag'] # KLUDGE!!!!!t['koi_jmag'] s['Vmag'] = withtic['TIC Vmag'] s['G'] = withtic['TIC GAIAmag'] s['T'] = withtic['TIC Tmag'] # planet radius s['radius'] = withtic['Radius (R_Earth)'] s['radius_uncertainty_upper'] = withtic['Radius (R_Earth) Error'] s['radius_uncertainty_lower'] = -withtic['Radius (R_Earth) Error'] #KLUDGE? s['transit_ar'] = withtic['a/Rad_s'] #KLUDGE? #s['rv_semiamplitude'] = t['pl_rvamp'] #t.MaskedColumn(t['K'], mask=t['K']==0.0) s['mass'] = withtic['Mass (M_Earth)'] s['mass_uncertainty_upper'] = withtic['Mass (M_Earth) Error'] s['mass_uncertainty_lower'] = -withtic['Mass (M_Earth) Error'] s['radius_ratio'] = withtic['Radius (R_Earth)'] * u.Rearth / withtic[ 'Stellar Radius (R_Sun)'] / u.Rsun s['ra'] = withtic['RA'] s['dec'] = withtic['Dec'] s['transit_b'] = withtic['Impact Param'] # is this usually Gaia?? s['distance'] = withtic['Stellar Distance (pc)'] s['distance_uncertainty_upper'] = np.zeros(n) + np.nan s['distance_uncertainty_lower'] = np.zeros(n) + np.nan s['disposition'] = withtic['User Disposition'] # a little kludge #s['stellar_teff'][s['name'] == 'GJ 436b'] = 3400.0 #s['stellar_teff'][s['name'] == 'Qatar-1b'] = 4860.0 #s['stellar_radius'][s['name'] == 'WASP-100b'] = 1.5#??? s.sort('name') self.standard = s
def query_mast(self): """ Fetch the data for this star in astroquery.mast using the TICID """ t = Catalogs.query_criteria(target_name=self.ticid) return t
def TIC_byID(ID): from astroquery.mast import Catalogs catTable = Catalogs.query_criteria(ID=ID, catalog="Tic") return catTable
def get_tess_stars_from_sector(sector_num, datapath=utils.TESS_DATAPATH, force_redownload=False, verbose=True): ''' Queries https://tess.mit.edu/observations/target-lists/ for the input catalog from TESS sector 'sector_num', and for each target in that list, gets its data from astroquery and joins the two catalogs. Arguments --------- sector_num : int The TESS sector number for which information is being requested. datapath : str The top-level path to which data should be stored. verbose : bool Whether to print statements on the script's progress. Returns ------- stars : pd.DataFrame The joined TIC and target-list data. ''' # sets up file paths and names sector = str(sector_num).zfill(3) if datapath is None: datapath = os.getcwd() subpath = "tesstargets" + os.path.sep + "TESS_targets_S{}.csv".format( sector) fullpath = os.path.join(datapath, subpath) noises_path = os.path.join( datapath, "tess_photometric_noise" + os.path.sep + "TESS_noise_S{}.csv".format(sector)) if (not os.path.exists(fullpath) ) or force_redownload or utils.GLOBAL_FORCE_REDOWNLOAD: # queries the target list url = utils.get_sector_pointings(sector_num) if verbose or utils.GLOBAL_VERBOSE: print("Getting sector {0} observed targets from {1}.".format( sector_num, url)) req = requests.get(url) if not req.ok: raise requests.exceptions.HTTPError( "Data from sector {} is not available.".format(sector_num)) observations = pd.read_csv(BytesIO(req.content), comment='#')[[ 'TICID', 'Camera', 'CCD' ]] # MAST has Tmag, RA, Dec at higher precision observed_ticids = observations['TICID'].values # queries MAST for stellar data if verbose or utils.GLOBAL_VERBOSE: print("Querying MAST for sector {0} observed targets.".format( sector_num)) with warnings.catch_warnings(): warnings.simplefilter("ignore") tic_data = Catalogs.query_criteria(catalog='Tic', ID=observed_ticids).to_pandas() tic_data = tic_data.astype({"ID": int}) merged_data = tic_data.merge(observations, left_on='ID', right_on='TICID') if os.path.exists(noises_path): merged_data = merged_data.merge(pd.read_csv(noises_path, index_col=0, comment='#'), on="ID") else: print( "Noise values not found on path: change file location or download using get_tess_photometric_noise.py." ) merged_data = merged_data.rename({"ID": "ticid"}) merged_data.to_csv(fullpath) if verbose or utils.GLOBAL_VERBOSE: print("Saved TIC data from TESS sector {0} to path {1}.".format( sector_num, fullpath)) return merged_data else: stellar_sector_data = pd.read_csv(fullpath, index_col=0) if "noise" not in stellar_sector_data.index and os.path.exists( noises_path): stellar_sector_data = stellar_sector_data.merge(pd.read_csv( noises_path, index_col=0, comment='#'), on="ID") stellar_sector_data.to_csv(fullpath) if verbose or utils.GLOBAL_VERBOSE: print( "Added photometric noise values to TIC data from TESS sector {0} to path {1}." .format(sector_num, fullpath)) return stellar_sector_data
def ticid2radec(entry): if debug: print( "<p>DEBUGGING: trying to call astropy.mast.Catalogs.query_criteria()</p>" ) #from .coordconvert import ra2decimal, dec2decimal #from cgi import escape import warnings, datetime if "GATEWAY_INTERFACE" in os.environ: import __main__ homedir = os.path.abspath( os.path.join(os.path.dirname(__main__.__file__), '../tmp/')) ## # To make astropy work from w/in Apache? XDG variables don't work. os.environ.update({'HOME': homedir}) if not (os.path.isdir(homedir) or os.path.islink(homedir)): if debug: print("<p>Trying to make homedir {}</p>".format(homedir)) try: os.mkdir(homedir) except Exception as e: print( "<p><font color=red>ERROR: Failed to make homedir with exception {}</font></e>" .format(e)) return None homedir = os.environ["HOME"] if debug: print("<p>Homedir is {} with contents:".format(homedir)) print(os.listdir(homedir)) if os.path.isdir("{}/.astropy".format(homedir)): print(os.listdir("{}/.astropy".format(homedir))) print("</p>\n") if debug: print("<p>DEBUGGING: environ is {}</p>".format(os.environ)) key = 'HTTP_HOST' if key in os.environ: if 'heasarcdev' not in os.environ[key]: if debug: print( "<p>DEBUGGING: {} is {}; trying to reset the HTTP proxies to 128.183.17.248:443</p>" .format(key, os.environ[key])) os.environ.update({ "HTTPS_PROXY": "128.183.17.248:443", "HTTP_PROXY": "128.183.17.248:443" }) else: if debug: print( "<p>DEBUGGING: {} is {}; NOT trying to reset the HTTP proxies</p>" .format(key, os.environ[key])) sys.stdout.flush() if debug: print("<p>DEBUG: trying to import astroquery.mast.Catalogs</p>") print("<p>{} DEBUG: HOME dir is currently {}</p>".format( datetime.datetime.now(), os.environ['HOME'])) print("<p>{} DEBUG: HTTP_HOST is currently {}</p>".format( datetime.datetime.now(), os.environ['HTTP_HOST'])) sys.stdout.flush() try: from astroquery.mast import Catalogs except Exception as e: print( "<p>{} ERROR: failed to import astroquery.mast.Catalogs(): {}</p>" .format(datetime.datetime.now(), e)) sys.stdout.flush() raise if debug: print( "<p>{} DEBUG: Successfully imported astroquery.mast.Catalogs.</p>" .format(datetime.datetime.now())) if debug: import inspect, astroquery print("<p>DEBUG: my astroquery is version {} at {}</p>".format( astroquery.__version__, inspect.getfile(astroquery))) sys.stdout.flush() if debug: print("<p>DEBUGGING: Calling query_criteria</p>") sys.stdout.flush() try: catalogData = Catalogs.query_criteria(catalog="Tic", ID=entry) except Exception as e: #print("<p>ERROR: astroquery.mast.Catalogs() error {} for string {}</p>".format(e,escape(entry,quote=True))) print( "<p>ERROR: astroquery.mast.Catalogs() error {} for string {}</p>". format(e, entry)) raise if debug: print("<p>DEBUGGING: this Tic ID gives ra,dec={},{}</p>".format( catalogData['ra'][0], catalogData['dec'][0])) sys.stdout.flush() return entry, catalogData['ra'][0], catalogData['dec'][0]
from astropy.io import ascii import matplotlib.pyplot as plt import pdb from astroquery.mast import Catalogs # take the output of sample.py and collate information required to run isoclassify spoc = ascii.read('tess_spoc_candidates.csv') ids = [''] * len(spoc) band = ['kmag'] * len(spoc) dust = ['allsky'] * len(spoc) for i in range(0, len(spoc)): ids[i] = 'TOI' + str(spoc['Full TOI ID'][i]).split('.')[0] catalogData = Catalogs.query_criteria(catalog="Tic", ID=spoc['TIC']) spoc = spoc[np.argsort(spoc['TIC'])] catalogData = catalogData[np.argsort(np.asarray(catalogData['ID'], dtype='int'))] ascii.write([ ids, catalogData['ra'], catalogData['dec'], catalogData['gaiabp'], catalogData['e_gaiabp'], catalogData['gaiarp'], catalogData['e_gaiarp'], 1. / catalogData['d'], catalogData['e_d'] / catalogData['d']**2, catalogData['Kmag'], catalogData['e_Kmag'], band, dust, spoc['TIC'] ], 'tess_spoc_candidates_isocl.csv', delimiter=',', names=[ 'id_starname', 'ra', 'dec', 'bpmag', 'bpmag_err', 'rpmag',
plt.subplot(5, 5, nplot) prf = getPrfAtColRowFits(col + col_add, row + row_add, ccd, camera, sector, path) plt.imshow(prf, **kwargs) plt.annotate("%.1f, %.1f" % (col_add, row_add), (8, 11), color='w') _ = kwargs.pop('vmax') #unset vmax from astroquery.mast import Tesscut from astroquery.mast import Catalogs ticid = 307214209 target = "TIC %u" % ticid size = 13 catalogData = Catalogs.query_criteria(catalog="Tic", ID=ticid) ra = catalogData['ra'] dec = catalogData['dec'] coord = "%f, %f" % (ra, dec) hdulist = Tesscut.get_cutouts(coord, size=size) n = 1 # There is more than one sector, we chose the second one # Pull out the location of the middle of the CCD from the Physics WCS in the header. image_head = hdulist[n][1].header prime_head = hdulist[n][0].header ap_head = hdulist[n][2].header col_center = image_head['1CRV4P'] row_center = image_head['2CRV4P'] print("Header col,row: %f, %f" % (col_center, row_center))