Beispiel #1
0
def query_for_spectral_type(identifier,
                            only_first_two_characters=True,
                            default_sptype='G0'):
    """
    Search SIMBAD for the spectral type of a star.

    If no spectral type is found, the default return value is ``"G0"``.

    Parameters
    ----------
    identifier : str
        Name of target
    only_first_two_characters : bool
        Return only first two characters of spectral type?
    default_sptype : str
        Spectral type returned when none is found on SIMBAD

    Returns
    -------
    sptype : str
        Spectral type of the star.
    """
    customSimbad = Simbad()
    customSimbad.SIMBAD_URL = 'http://simbad.harvard.edu/simbad/sim-script'
    customSimbad.add_votable_fields('sptype')
    result = customSimbad.query_object(identifier)

    if len(result['SP_TYPE']) > 0:

        if only_first_two_characters:
            return result['SP_TYPE'][0][:2].strip().decode()
        else:
            return result['SP_TYPE'][0].decode()
    else:
        return default_sptype.decode()
Beispiel #2
0
def query_for_spectral_type(identifier, only_first_two_characters=True,
                            default_sptype='G0'):
    """
    Search SIMBAD for the spectral type of a star.

    If no spectral type is found, the default return value is ``"G0"``.

    Parameters
    ----------
    identifier : str
        Name of target
    only_first_two_characters : bool
        Return only first two characters of spectral type?
    default_sptype : str
        Spectral type returned when none is found on SIMBAD

    Returns
    -------
    sptype : str
        Spectral type of the star.
    """
    customSimbad = Simbad()
    customSimbad.SIMBAD_URL = 'http://simbad.harvard.edu/simbad/sim-script'
    customSimbad.add_votable_fields('sptype')
    result = customSimbad.query_object(identifier)

    if len(result['SP_TYPE']) > 0:

        if only_first_two_characters:
            return result['SP_TYPE'][0][:2].strip().decode()
        else:
            return result['SP_TYPE'][0].decode()
    else:
        return default_sptype.decode()
Beispiel #3
0
def do_simbad_novae(catalog):
	task_str = catalog.get_current_task_str()	
	simbad_mirrors = ['http://simbad.harvard.edu/simbad/sim-script',
					'http://simbad.u-strasbg.fr/simbad/sim-script']

	customSimbad = Simbad()
	customSimbad.ROW_LIMIT = -1
	customSimbad.TIMEOUT = 120

	for mirror in simbad_mirrors:
		customSimbad.SIMBAD_URL = mirror
		try:
			table = customSimbad.query_criteria('maintype=No* | maintype="No?"')
		except:
			continue
		else:
			break

	if not table:
		catalog.log.warning('SIMBAD unable to load, probably offline.')

	
	
	for name in pbar(catalog.entries, task_str):
		try:
			nova_name = "V* " + get_nova_name(name)
			aliases = customSimbad.query_objectids(nova_name)
		except:
			#THROW WARNING HERE
			tprint("Could not find " + nova_name)
			continue
		
		table = customSimbad.query_object(nova_name)
		
		name = catalog.add_entry(name)
		
		bibcode = table[0]['COO_BIBCODE'].decode()
		ra = str(table[0]['RA'])
		dec = str(table[0]['DEC'])
		
		source = catalog.entries[name].add_source(name='SIMBAD astronomical database',
													bibcode=bibcode,
													url="http://simbad.u-strasbg.fr/",
                              						secondary=True)
		catalog.entries[name].add_quantity(NOVA.RA, ra, source)
		catalog.entries[name].add_quantity(NOVA.DEC, dec, source)

		for i in range(len(aliases)):
			try: alias = aliases[i][0].decode()
			except:	alias = str(aliases[i][0])
						
			catalog.entries[name].add_quantity(NOVA.ALIAS, alias, source)
		
		catalog.journal_entries()
Beispiel #4
0
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']
    simbadbadnamebib = ['2004AJ....127.2809W', '2005MNRAS.364.1419Z',
                        '2015A&A...574A.112D', '2011MNRAS.417..916G',
                        '2002ApJ...566..880G']
    simbadbannedcats = ['[TBV2008]', 'OGLE-MBR']
    customSimbad = Simbad()
    customSimbad.ROW_LIMIT = -1
    customSimbad.TIMEOUT = 120
    customSimbad.add_votable_fields('otype', 'sptype', 'sp_bibcode', 'id')
    table = []
    for mirror in simbadmirrors:
        customSimbad.SIMBAD_URL = mirror
        try:
            table = customSimbad.query_criteria('maintype=No* | maintype="No?"')
        except:
            continue
        else:
            break

    if not table:
        catalog.log.warning('SIMBAD unable to load, probably offline.')

    # 2000A&AS..143....9W
    for brow in pbar(table, task_str):
        row = {x: re.sub(r'b\'(.*)\'', r'\1',
                         str(brow[x])) for x in brow.colnames}
        # Skip items with no bibliographic info aside from SIMBAD, too
        # error-prone
        if row['OTYPE'] == 'Candidate_No*' and not row['SP_TYPE']:
            continue
        if (not row['COO_BIBCODE'] and not row['SP_BIBCODE'] and
                not row['SP_BIBCODE_2']):
            continue
        if any([x in row['MAIN_ID'] for x in simbadbannedcats]):
            continue
        if row['COO_BIBCODE'] and row['COO_BIBCODE'] in simbadbadnamebib:
            continue
        name = single_spaces(re.sub(r'\[[^)]*\]', '', row['MAIN_ID']).strip())
        if name == 'SN':
            continue
        if is_number(name):
            continue
        name = catalog.add_entry(name)
        source = (catalog.entries[name]
                  .add_source(name='SIMBAD astronomical database',
                              bibcode="2000A&AS..143....9W",
                              url="http://simbad.u-strasbg.fr/",
                              secondary=True))
        aliases = row['ID'].split(',')
        for alias in aliases:
            if any([x in alias for x in simbadbannedcats]):
                continue
            ali = single_spaces(re.sub(r'\[[^)]*\]', '', alias).strip())
            if is_number(ali):
                continue
            ali = name_clean(ali)
            catalog.entries[name].add_quantity(NOVA.ALIAS,
                                               ali, source)
        if row['COO_BIBCODE'] and row['COO_BIBCODE'] not in simbadbadcoordbib:
            csources = ','.join(
                [source, catalog.entries[name].add_source(
                    bibcode=row['COO_BIBCODE'])])
            catalog.entries[name].add_quantity(NOVA.RA,
                                               row['RA'], csources)
            catalog.entries[name].add_quantity(NOVA.DEC,
                                               row['DEC'], csources)
        if row['SP_BIBCODE']:
            ssources = uniq_cdl([source,
                                 catalog.entries[name]
                                 .add_source(bibcode=row['SP_BIBCODE'])] +
                                ([catalog.entries[name]
                                  .add_source(bibcode=row['SP_BIBCODE_2'])] if
                                 row['SP_BIBCODE_2'] else []))
            catalog.entries[name].add_quantity(
                NOVA.CLAIMED_TYPE,
                (row['SP_TYPE']
                 .replace('SN.', '')
                 .replace('SN', '')
                 .replace('(~)', '')
                 .strip(': ')), ssources)
    catalog.journal_entries()
    return
Beispiel #5
0
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
            break

    if not table:
        catalog.log.warning('SIMBAD unable to load, probably offline.')

    # 2000A&AS..143....9W
    for brow in pbar(table, task_str):
        row = {x: re.sub(r'b\'(.*)\'', r'\1',
                         str(brow[x])) for x in brow.colnames}
        # Skip items with no bibliographic info aside from SIMBAD, too
        # error-prone
        if row['OTYPE'] == 'Candidate_SN*' and not row['SP_TYPE']:
            continue
        if (not row['COO_BIBCODE'] and not row['SP_BIBCODE'] and
                not row['SP_BIBCODE_2']):
            continue
        if any([x in row['MAIN_ID'] for x in simbadbannedcats]):
            continue
        if row['COO_BIBCODE'] and row['COO_BIBCODE'] in simbadbadnamebib:
            continue
        name = single_spaces(re.sub(r'\[[^)]*\]', '', row['MAIN_ID']).strip())
        if name in simbadbannednames:
            continue
        if is_number(name.replace(' ', '')):
            continue
        name = catalog.add_entry(name)
        source = (catalog.entries[name]
                  .add_source(name='SIMBAD astronomical database',
                              bibcode="2000A&AS..143....9W",
                              url="http://simbad.u-strasbg.fr/",
                              secondary=True))
        aliases = row['ID'].split(',')
        for alias in aliases:
            if any([x in alias for x in simbadbannedcats]):
                continue
            ali = single_spaces(re.sub(r'\[[^)]*\]', '', alias).strip())
            if is_number(ali.replace(' ', '')):
                continue
            if ali in simbadbannednames:
                continue
            ali = name_clean(ali)
            catalog.entries[name].add_quantity(SUPERNOVA.ALIAS,
                                               ali, source)
        if row['COO_BIBCODE'] and row['COO_BIBCODE'] not in simbadbadcoordbib:
            csources = ','.join(
                [source, catalog.entries[name].add_source(
                    bibcode=row['COO_BIBCODE'])])
            catalog.entries[name].add_quantity(SUPERNOVA.RA,
                                               row['RA'], csources)
            catalog.entries[name].add_quantity(SUPERNOVA.DEC,
                                               row['DEC'], csources)
        if row['SP_BIBCODE'] and row['SP_BIBCODE'] not in simbadbadtypebib:
            ssources = uniq_cdl([source,
                                 catalog.entries[name]
                                 .add_source(bibcode=row['SP_BIBCODE'])] +
                                ([catalog.entries[name]
                                  .add_source(bibcode=row['SP_BIBCODE_2'])] if
                                 row['SP_BIBCODE_2'] else []))
            catalog.entries[name].add_quantity(
                SUPERNOVA.CLAIMED_TYPE,
                (row['SP_TYPE']
                 .replace('SN.', '')
                 .replace('SN', '')
                 .replace('(~)', '')
                 .strip(': ')), ssources)
    catalog.journal_entries()
    return
Beispiel #6
0
    def from_simbad(cls, simbad_id, *, version=2, target_id=None,
        fits_keywords={}, **columns):
        """

Create an OI_TARGET table from simbad identifiers

Arguments
---------

version (int, optional)
    Version of the OIFITS standard if it cannot be deduced from context
simbad_id (str × NTARGET)
    IDs recognised by SIMBAD
target_id (int × NTARGET, optional, default: 1 .. NTARGET)
    target ID for cross-reference 
category (str × NTARGET, optional)
    target catogory, SCI or CAL
fits_keywords (dict, optional, default: {})
    additional FITS header keywords 

Additional arguments
--------------------

Any additional keyword argument will be appended as a non-standard FITS 
column with its name prefixed with NS_ 

        """
        from astroquery.simbad import Simbad 

        deg = np.deg2rad(1)
        mas = deg / 3_600_000

        simbad = Simbad()
        
        # at CDS is not working
        simbad.SIMBAD_URL = 'https://simbad.harvard.edu/simbad/sim-script' 

        simbad.remove_votable_fields(*simbad.get_votable_fields()[1:])
        # OIFITS standard imposes equinox = epoch for the frame which
        # de facto excludes ICRS, we use FK5.
        simbad.add_votable_fields(
            'ra(d;A;FK5;J2000;2000)', 'dec(d;D;FK5;J2000;2000)',
            'coo_err_angle', 'coo_err_maja', 'coo_err_mina',
            'plx', 'plx_error',
            'rvz_radvel', 'rvz_wavelength',
            'pmra', 'pmdec', 'pm_err_angle', 'pm_err_maja', 'pm_err_mina',
            'sp',
        )
        tab = simbad.query_objects(simbad_id)

        # target ID must be ascii, if not, pick simbad
        main_id = tab['MAIN_ID']
        target = [s if ascii(s)[1:-1] == s else decode(m)
                            for s, m in zip(simbad_id, main_id)]

        def tolist(x, deflt=np.nan):
            x = [decode(e) for e in x.tolist()]
            x = np.array([deflt if e in ['', None] else e for e in x])
            return x

        def ellipse_to_xy_err(a, b, theta):
            a2, b2 = a**2, b**2
            cos2, sin2 = np.cos(theta) ** 2, np.sin(theta) ** 2
            x = np.sqrt(a2 * cos2 + b2 * sin2)
            y = np.sqrt(a2 * sin2 + b2 * cos2)
            return x,y 

        # coordinates and parallaxes
        ra = tolist(tab['RA_d_A_FK5_J2000_2000'])
        dec = tolist(tab['DEC_d_D_FK5_J2000_2000'])
        a = mas / deg * tolist(tab['COO_ERR_MAJA'])
        b = mas  / deg * tolist(tab['COO_ERR_MINA'])
        theta = deg * tolist(tab['COO_ERR_ANGLE'])
        ra_err, dec_err  = ellipse_to_xy_err(a, b, theta)
        equinox = 2000.
 
        parallax = mas / deg * tolist(tab['PLX_VALUE'])
        para_err = mas / deg * tolist(tab['PLX_ERROR'])
        
        # velocity and proper motion
        sysvel = 1e3 * tolist(tab['RVZ_RADVEL'])
        veldef = tolist(tab['RVZ_WAVELENGTH'], 'OPTICAL')
        veltyp = 'BARYCENTRIC'
        
        pmra = mas / deg * tolist(tab['PMRA'])
        pmdec = mas / deg * tolist(tab['PMDEC'])
        a = mas / deg * tolist(tab['PM_ERR_MAJA'])
        b = mas / deg * tolist(tab['PM_ERR_MINA'])
        theta = deg * tolist(tab['PM_ERR_ANGLE'])
        pmra_err, pmdec_err = ellipse_to_xy_err(a, b, theta)
       
        # spectral type
        spectyp = tolist(tab['SP_TYPE'], 'UNKNOWN') 

        return cls.from_data(version=version, target_id=target_id,
                target=target, ra=ra, dec=dec, equinox=equinox,
                ra_err=ra_err, dec_err=dec_err,
                sysvel=sysvel, veltyp=veltyp, veldef=veldef,
                pmra=pmra, pmdec=pmdec, pmra_err=pmra_err, pmdec_err=pmdec_err,
                parallax=parallax, para_err=para_err, spectyp=spectyp,
                **columns)
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',
        'url:CBAT',
        'url:GPSA',
    ]
    badurlbibname = ['url:TNS', 'url:ASASSN', 'url:Lasair', 'url:AAVSO']
    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(
                'maintypes=CV* | maintypes="CV?" | maintypes=No* | maintypes="No?"'
            )
        except Exception:
            continue
        else:
            if not table:
                continue
            break

    if not table:
        catalog.log.warning('SIMBAD unable to load, probably offline.')

    # 2000A&AS..143....9W
    for brow in pbar(table, task_str):
        row = {
            x: re.sub(r'b\'(.*)\'', r'\1', str(brow[x]))
            for x in brow.colnames
        }
        # Skip items with no bibliographic info aside from SIMBAD, too
        # error-prone
        #        print(row)
        if (not row['COO_BIBCODE'] and not row['SP_BIBCODE']
                and not row['SP_BIBCODE_2'] and not row['OTYPE'] == 'Nova'
                and not row['OTYPE'] == 'DwarfNova'):
            continue
        if any([x in row['MAIN_ID'] for x in simbadbannedcats]):
            continue
        if row['COO_BIBCODE'] and row['COO_BIBCODE'] in simbadbadnamebib:
            continue
        name = single_spaces(re.sub(r'\[[^)]*\]', '',
                                    row['MAIN_ID']).strip()).replace('*', '_')
        if name in simbadbannednames:
            continue
        if is_number(name.replace(' ', '')):
            continue
        name = catalog.add_entry(name)
        source = (catalog.entries[name].add_source(
            name='SIMBAD astronomical database',
            bibcode="2000A&AS..143....9W",
            url="http://simbad.u-strasbg.fr/",
            secondary=True)).replace('*', '_')
        if row['COO_BIBCODE'] == 'url:TNS':
            source = ','.join([
                source, catalog.entries[name].add_source(
                    name='Transient Name Server',
                    url='https://wis-tns.weizmann.ac.il/')
            ])
        if row['COO_BIBCODE'] == 'url:ASASSN':
            source = ','.join([
                source, catalog.entries[name].add_source(
                    name='ASAS-CV Transients',
                    bibcode="2014ApJ...788...48S",
                    url=
                    'http://www.astronomy.ohio-state.edu/~assassin/transients.html'
                )
            ])
        if row['COO_BIBCODE'] == 'url:Lasair':
            source = ','.join([
                source, catalog.entries[name].add_source(
                    name='lASAIR Transients and Variables',
                    bibcode="2019RNAAS...3...26S",
                    url='https://lasair.roe.ac.uk/')
            ])

        aliases = row['ID'].split(',')
        for alias in aliases:
            if any([x in alias for x in simbadbannedcats]):
                continue
            ali = single_spaces(re.sub(r'\[[^)]*\]', '',
                                       alias).strip()).replace('*', '_')
            if is_number(ali.replace(' ', '')):
                continue
            if ali in simbadbannednames:
                continue
            ali = name_clean(ali)
            catalog.entries[name].add_quantity(CATACLYSMIC.ALIAS, ali, source)
            catalog.entries[name].add_quantity(
                CATACLYSMIC.CLAIMED_TYPE,
                (row['OTYPE'].replace('CV.', 'CV').replace('CV', 'CV').replace(
                    '(~)', '').replace('CV?', 'Candidate').replace(
                        '*', '').replace('No?', 'Candidate Nova').strip(': ')),
                source)
        if row['COO_BIBCODE'] and row['COO_BIBCODE'] not in simbadbadcoordbib:
            csources = source
            if row['COO_BIBCODE'] not in badurlbibname:
                csources = ','.join([
                    source, catalog.entries[name].add_source(
                        bibcode=row['COO_BIBCODE'])
                ])
            catalog.entries[name].add_quantity(CATACLYSMIC.RA, row['RA'],
                                               csources)
            catalog.entries[name].add_quantity(CATACLYSMIC.DEC, row['DEC'],
                                               csources)
            catalog.entries[name].add_quantity(
                CATACLYSMIC.CLAIMED_TYPE,
                (row['OTYPE'].replace('CV.', 'CV').replace('CV', 'CV').replace(
                    '(~)', '').replace('CV?', 'Candidate').replace(
                        '*', '').replace('No?', 'Candidate Nova').strip(': ')),
                csources)
        if row['SP_BIBCODE'] and row['SP_BIBCODE'] not in simbadbadtypebib:
            ssources = source
            if row['SP_BIBCODE'] and row['SP_BIBCODE_2'] not in badurlbibname:
                ssources = uniq_cdl([
                    source, catalog.entries[name].add_source(
                        bibcode=row['SP_BIBCODE'])
                ] + ([
                    catalog.entries[name].add_source(
                        bibcode=row['SP_BIBCODE_2'])
                ] if row['SP_BIBCODE_2'] else []))
            catalog.entries[name].add_quantity(
                CATACLYSMIC.CLAIMED_TYPE,
                (row['OTYPE'].replace('CV.', 'CV').replace('CV', 'CV').replace(
                    '(~)', '').replace('CV?', 'Candidate').replace(
                        '*', '').replace('No?', 'Candidate Nova').strip(': ')),
                ssources)
        if row['OTYPE'] == 'Nova' and row['SP_BIBCODE'] == '' and row[
                'COO_BIBCODE'] == '':
            catalog.entries[name].add_quantity(CATACLYSMIC.RA, row['RA'],
                                               source)
            catalog.entries[name].add_quantity(CATACLYSMIC.DEC, row['DEC'],
                                               source)
            catalog.entries[name].add_quantity(CATACLYSMIC.CLAIMED_TYPE,
                                               (row['OTYPE']), source)
        if row['OTYPE'] == 'DwarfNova' and row['SP_BIBCODE'] == '' and row[
                'COO_BIBCODE'] == '':
            catalog.entries[name].add_quantity(CATACLYSMIC.RA, row['RA'],
                                               source)
            catalog.entries[name].add_quantity(CATACLYSMIC.DEC, row['DEC'],
                                               source)
            catalog.entries[name].add_quantity(CATACLYSMIC.CLAIMED_TYPE,
                                               (row['OTYPE']), source)
    catalog.journal_entries()
    return