How to use the astroquery.simbad.Simbad function in astroquery

To help you get started, we’ve selected a few astroquery examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Stargrazer82301 / CAAPR / CAAPR / CAAPR_AstroMagic / PTS / pts / magic / tools / catalogs.py View on Github external
def get_ngc_name(galaxy_name, delimiter=" "):

    """
    This function ...
    :param galaxy_name:
    :param delimiter:
    :return:
    """

    # The Simbad querying object
    simbad = Simbad()
    simbad.ROW_LIMIT = -1

    result = simbad.query_objectids(galaxy_name)
    for name in result["ID"]:

        if "NGC" in name:

            splitted = name.split("NGC")
            if splitted[0] == "":
                number = int(splitted[1])
                return "NGC" + delimiter + str(number)

    # If nothing is found, return None
    return None
github alexteachey / MoonPy / moonpy.py View on Github external
except:
						pass


			elif (self.telescope.lower() == 'tess'):
				try:
					simbad_query = Simbad.query_object(self.target)[0] ### this will look for any object!
					target_name = self.target
					self.RA = simbad_query['RA']
					self.Dec = simbad_query['DEC']
					target_in_simbad = 'y'

				except:
					if self.target_type.lower() == 'toi':
						try:
							simbad_query = Simbad.query_object('TOI-'+self.target)[0]
							target_name = 'TOI-'+str(self.target) ### only update if this worked!
							self.RA = simbad_query['RA']
							self.Dec = simbad_query['DEC']
							target_in_simbad = 'y'
						except:
							target_in_simbad = 'n'
							try:
								self.RA = np.array(exofop_data['RA'][self.exofop_rowidx])[0]
								self.Dec = np.array(exofop_data['Dec'][self.exofop_rowidx])[0]
							except:
								pass

					elif self.target_type.lower() == 'tic':
						try:
							simbad_query = Simbad.query_object('TIC '+self.target)[0] 
							target_name = 'TIC '+str(self.target) ### only update if this worked!
github astropy / astroquery / docs / gallery-examples / example2_simbad.py View on Github external
from astroquery.simbad import Simbad

s = Simbad()
# bibcodelist(date1-date2) lists the number of bibliography
# items referring to each object over that date range
s.add_votable_fields('bibcodelist(2003-2013)')
r = s.query_object('m31')
r.pprint()

"""
MAIN_ID      RA          DEC      RA_PREC DEC_PREC COO_ERR_MAJA COO_ERR_MINA COO_ERR_ANGLE COO_QUAL COO_WAVELENGTH     COO_BIBCODE     BIBLIST_2003_2013
------- ------------ ------------ ------- -------- ------------ ------------ ------------- -------- -------------- ------------------- -----------------
  M  31 00 42 44.330 +41 16 07.50       7        7          nan          nan             0        B              I 2006AJ....131.1163S              3758
"""
github alexteachey / MoonPy / mp_lcfind.py View on Github external
def kplr_coord_download(ra, dec, coord_format='degrees', quarters='all', search_radius=5, lc_format='pdc', sc=False):
	### find the object in Simbad using it's coordinates, and call kplr_target_download

	### try to interpret the coordinate_format 
	if 'h' in ra or ':' in ra:
		coord_format == 'sexagesimal'
		ra = ra.replace(' ', '') ### remove the spaces
		dec = dec.replace(' ', '') ### remove the spaces

	if coord_format=='degrees':
		nearby_objects = Simbad.query_region(coord.SkyCoord(ra, dec, unit=(u.deg, u.deg), frame='icrs'), radius='0d0m5s')
	elif coord_format=='sexagesimal':
		nearby_objects = Simbad.query_region(coord.SkyCoord(str(ra)+' '+str(dec), frame='icrs'), radius='0d0m'+str(search_radius)+'s')

	print(nearby_objects)
	best_hit = nearby_objects[0][0].decode('UTF-8')
	print("best_hit = ", best_hit)

	if (best_hit.startswith('KOI') == False) and (best_hit.startswith('Kepler') == False) and (best_hit.startswith("KIC") == False):
		### look for aliases
		alias_query = Simbad.query_objectids(str(best_hit))['ID']
		search_idx = 0
		while search_idx < 10: ### maximum tries
			try:
				alias = alias_query[search_idx]
				if alias.startswith('KOI') or alias.statswith('Kepler') or alias.startswith("KIC"):
					best_hit = alias
github astropy / astroquery / docs / gallery-examples / example4_simbad.py View on Github external
from astropy import coordinates
from astroquery.simbad import Simbad

customSimbad = Simbad()

# We've seen errors where ra_prec was NAN, but it's an int: that's a problem
# this is a workaround we adapted
customSimbad.add_votable_fields('ra(d)', 'dec(d)')
customSimbad.remove_votable_fields('coordinates')

C = coordinates.SkyCoord(0, 0, unit=('deg', 'deg'), frame='icrs')

result = customSimbad.query_region(C, radius='2 degrees')

result[:5].pprint()
"""
    MAIN_ID        RA_d       DEC_d
 ------------- ----------- ------------
 ALFALFA 5-186  0.00000000   0.00000000
 ALFALFA 5-188  0.00000000   0.00000000
github afeinstein20 / eleanor / eleanor / mast.py View on Github external
def coords_from_name(name):
    """ Finds the RA, Dec for a given target name."""
    from astroquery.simbad import Simbad
    result_table = Simbad.query_object(name)
    coords = SkyCoord(Angle(result_table['RA'][0] + ' hours'),
                      Angle(result_table['DEC'][0] + ' degrees'))
    return (coords.ra.deg, coords.dec.deg)
github astrolabsoftware / fink-broker / fink_broker / classification.py View on Github external
List of object ID (custom)
    distmaxarcsec: int
        Radius used for searching match. extcatalog sources lying within
        radius of the center (ra, dec) will be considered as matches.

    Returns
    ----------
    data_filt_new: pd.DataFrame
        Formatted decoded data returned by the astroquery module
    """

    # Reset the fields to a minimal number
    Simbad.reset_votable_fields()
    # Add new fields to the query
    Simbad.add_votable_fields('otype')
    Simbad.add_votable_fields('ra(d)')
    Simbad.add_votable_fields('dec(d)')

    list_keys = ['MAIN_ID', 'RA_d', 'DEC_d', 'OTYPE']
    list_old_keys = ['main_id', 'ra', 'dec', 'main_type']
    dictionary_simbad_to_new = dict(zip(list_keys, list_old_keys))

    # create a mask with the entries of the query
    nans = [np.nan] * len(ra)
    mask = pd.DataFrame(zip(nans, ra, dec, nans, id))
    mask.columns = list_old_keys + ['objectId']

    # Send requests in vector form and obtain a table as a result
    units = tuple([u.deg, u.deg])
    query_new = (
        Simbad.query_region(
            coord.SkyCoord(
github skyportal / skyportal / tools / ztf_upload_avro.py View on Github external
Instrument, Group, GroupUser, Photometry, Role,
                              Source, Spectrum, Telescope, Thumbnail, User,
                              Token)

from avro.datafile import DataFileReader, DataFileWriter
from avro.io import DatumReader, DatumWriter
import fastavro
import astropy.units as u
from astropy.io import fits
from astropy.time import Time
from astropy.coordinates import SkyCoord
from astroquery.simbad import Simbad
from astroquery.vizier import Vizier

Simbad.TIMEOUT = 5
customSimbad = Simbad()
customSimbad.add_votable_fields('otype', 'sp', 'pm', "v*")
customGaia = Vizier(columns=["*", "+_r"], catalog="I/345/gaia2")

class ZTFAvro():

    def __init__(self, fname, ztfpack, only_pure=True, verbose=True,
                 clobber=True):

        self.fname = fname
        self.ztfpack = ztfpack
        self.verbose = verbose
        self.only_pure = only_pure
        self.clobber = clobber

        if not os.path.exists(self.fname):
            print(f"Cannot find file {fname}")
github astrocatalogs / supernovae / tasks / simbad.py View on Github external
def do_simbad(catalog):
    # Simbad.list_votable_fields()
    # Some coordinates that SIMBAD claims belong to the SNe actually belong to
    # the host.
    task_str = catalog.get_current_task_str()
    simbadmirrors = ['http://simbad.harvard.edu/simbad/sim-script',
                     'http://simbad.u-strasbg.fr/simbad/sim-script']
    simbadbadcoordbib = ['2013ApJ...770..107C']
    simbadbadtypebib = ['2014ApJ...796...87I', '2015MNRAS.448.1206M',
                        '2015ApJ...807L..18N']
    simbadbadnamebib = ['2004AJ....127.2809W', '2005MNRAS.364.1419Z',
                        '2015A&A...574A.112D', '2011MNRAS.417..916G',
                        '2002ApJ...566..880G']
    simbadbannedcats = ['[TBV2008]', 'OGLE-MBR']
    simbadbannednames = ['SN']
    customSimbad = Simbad()
    customSimbad.ROW_LIMIT = -1
    customSimbad.TIMEOUT = 120
    customSimbad.add_votable_fields('otype', 'sptype', 'sp_bibcode', 'id')
    table = []
    print(customSimbad.SIMBAD_URL)
    for mirror in simbadmirrors:
        customSimbad.SIMBAD_URL = mirror
        try:
            table = customSimbad.query_criteria('maintype=SN | maintype="SN?"')
        except Exception:
            continue
        else:
            if not table:
                continue
            else:
                break
github alexteachey / MoonPy / moonpy.py View on Github external
def find_aliases(self):
		target_aliases = []
		alias_search_results = Simbad.query_objectids(self.target)
		for alidx in np.arange(0,np.array(alias_search_results).shape[0],1):
			target_alias = alias_search_results[alidx][0]
			target_aliases.append(target_alias)
		self.aliases = np.array(target_aliases)