Exemplo n.º 1
0
def handling_exception(params, constraints):
    NSIDEmax = params['NSIDE max']
    vec = hp.ang2vec(params["ang"][0], params["ang"][1], lonlat=True)
    pixels = hp.query_disc(NSIDEmax,
                           vec,
                           np.radians(params['r'] / 3600.),
                           inclusive=True)
    subjobs = mastcasjobs.MastCasJobs(context="PanSTARRS_DR2")

    for pixel in pixels:
        ang, r = qr.parameters(NSIDEmax, pixel)
        subquery = sub_query_string(ang[0], ang[1], r)
        accept = True

        while accept:
            try:
                subtab = subjobs.quick(subquery,
                                       task_name="python cone search")
                accept = False
            except Exception:
                from time import sleep
                sleep(60)
                pass

        subtab = qr.fixcolnames(ascii.read(subtab))
        subtab = qr.query_constraints(subtab, constraints)

        if pixel == pixels[0]:
            table = subtab
        else:
            table = vstack([table, subtab])

    return table
Exemplo n.º 2
0
def search_s(ra, dec, search_size):
    query = """select o.raMean, o.decMean
    from fGetNearbyObjEq("""+str(ra)+','+str(dec)+","+str(search_size/2)+""") nb
    JOIN MeanObjectView o on o.ObjID=nb.ObjID
    WHERE o.nDetections>5
    """

    jobs = mastcasjobs.MastCasJobs(context="PanSTARRS_DR2")
    results = jobs.quick(query, task_name="python cone search")
    return(results)
Exemplo n.º 3
0
def vector_match_mast_casjob(tab):
    """
    (currently not working) attempt at getting a proper table join to work on
    the proj1301_xmatch.csv table that I uploaded to
    http://mastweb.stsci.edu/mcasjobs/.

    uses the https://github.com/rlwastro/mastcasjobs wrapper to DFM's casjobs
    wrapper

    (wrappers on wrappers)
    """

    assert NotImplementedError

    import mastcasjobs

    with open('~/.mast_casjob_credentials', 'r') as f:
        lines = f.readlines()

    user = lines[0].rstrip('\n')
    pwd = lines[1].rstrip('\n')  # http://mastweb.stsci.edu/mcasjobs/
    wsid = lines[2].rstrip('\n')  # given in the profile

    jobs = mastcasjobs.MastCasJobs(userid=wsid,
                                   password=pwd,
                                   context="TESS_v7")
    query = "select top 100 * from catalogRecord"
    results = jobs.quick(query, task_name="foobar")
    print(results)

    #FIXME
    # # buest guess so far... but it doesn't work!!!
    # SELECT top 100 tic.Tmag, tic.TWOMASS, upl.tmass_id
    # FROM catalogRecord as tic
    # JOIN MyDB.proj1301_xmatch as upl
    # ON (tic.TWOMASS = CONVERT(nvarchar(max),upl.tmass_id);

    query = ('SELECT top 100 tic.Tmag, tic.TWOMASS, upl.tmass_id '
             'FROM catalogRecord as tic '
             'JOIN MyDB.proj1301_xmatch as upl '
             'ON (tic.TWOMASS = CONVERT(nvarchar(max),upl.tmass_id);')

    jobid = jobs.submit(query, task_name="foobar")

    results = jobs.status(jobid)

    #FIXME

    import IPython
    IPython.embed()
    pass
Exemplo n.º 4
0
def search_ser(ra, dec, search_size):
    query = """select o.raMean, o.decMean, s.*
    from fGetNearbyObjEq("""+str(ra)+','+str(dec)+","+str(search_size/2)+""") nb
    JOIN MeanObjectView o on o.ObjID=nb.ObjID
    JOIN StackObjectAttributes AS soa ON soa.ObjID = nb.ObjID
    JOIN StackModelFitSer s ON (s.gstackDetectID=soa.gstackDetectID AND s.ObjID=nb.ObjId)
    WHERE o.nDetections>5
    AND soa.primaryDetection>0
    AND (o.rmeanpsfmag - o.rmeankronmag > 0.05)
    """

    jobs = mastcasjobs.MastCasJobs(context="PanSTARRS_DR2")
    results = jobs.quick(query, task_name="python cone search")
    return(results)
Exemplo n.º 5
0
def maxnside(user, pwd):

    theta, phi = 0., 0.  #in degree
    nsides = [2**x for x in range(12)][1:]
    nsides = np.flip(nsides)

    for nside in nsides:
        pix = hp.ang2pix(nside, theta=theta, phi=phi, lonlat=True)
        ang, radius = qr.parameters(nside, pix)
        query = qr.query_string(theta, phi, radius)
        jobs = mastcasjobs.MastCasJobs(context="PanSTARRS_DR2")

        try:
            jobs.quick(query, task_name="python cone search")
            pass
        except Exception:
            return nside
Exemplo n.º 6
0
def query_function(params, constraints):
    import exception as exc
    params['ang'], params['r'] = parameters(params["NSIDE"], params['pixel'])
    query = query_string(params['ang'][0], params['ang'][1], params['r'])
    jobs = mastcasjobs.MastCasJobs(context="PanSTARRS_DR2")

    try:
        table = jobs.quick(query, task_name="python cone search")
    except Exception:
        print("Exception. code!=200")
        table = exc.handling_exception(params, constraints)
        print("Extracted {} objects from PS1".format(len(table)))
        return table, jobs

    table = fixcolnames(ascii.read(table))
    table = query_constraints(table, constraints)
    return table, jobs
Exemplo n.º 7
0
def single_repeated_query_mast_casjob(tab):
    """
    the dumb way to get the Tmags once you have the 2mass IDs.
    i really wish TIC 8 existed. and that the interface for doing this was
    better. i guess an alternative is going to the MAST website and clicking
    around? but FALSE. it's not. you can only crossmatch on position LOL.
    """
    outpath = '../data/rms_vs_mag/projid_1301_gaia_2mass_tic_all_matches.csv'
    if os.path.exists(outpath):
        print('skipping single repeated casjob query')
        return

    import mastcasjobs

    with open('~/.mast_casjob_credentials', 'r') as f:
        lines = f.readlines()

    user = lines[0].rstrip('\n')
    pwd = lines[1].rstrip('\n')  # http://mastweb.stsci.edu/mcasjobs/
    wsid = lines[2].rstrip('\n')  # given in the profile

    jobs = mastcasjobs.MastCasJobs(userid=wsid,
                                   password=pwd,
                                   context="TESS_v7")

    tmags = []
    for ix, tmass_id in enumerate(tab['original_ext_source_id']):
        print('{}: {}/{}'.format(datetime.utcnow().isoformat(), ix, len(tab)))

        query = (
            "select top 1 TWOMASS, Tmag from catalogRecord where TWOMASS = \'{}\'"
            .format(tmass_id.decode('utf-8')))

        results = jobs.quick(query, task_name="foobar")
        if len(results.split('\n')) == 3:
            tmags.append(float(results.split('\n')[1].split(',')[-1]))
        else:
            tmags.append(-1)

    tab['tmag'] = tmags
    outdf = tab.to_pandas()
    outdf.to_csv(outpath, index=False)
    print('saved {}'.format(outpath))
Exemplo n.º 8
0
    def submit_query(self, reset=True):
        """
        Submit the query and download the resulting table
        """
        if self.context == 'ps1':
            c = 'PanSTARRS_DR2'

        elif self.context == 'gaia':
            c = 'GAIA_DR2'

        else:
            raise ValueError('Only gaia and ps1 available now.')

        jobs = mastcasjobs.MastCasJobs(context=c)
        if reset:
            jobs.drop_table_if_exists(self.name)
        else:
            try:
                self.table = jobs.get_table(self.name,
                                            format='CSV').to_pandas()
                if self.context == 'ps1':
                    self.table = self.table.replace(-999, np.nan)
                print('loading existing table')
                return
            except:
                pass

        job_id = jobs.submit(self.query)
        status = jobs.monitor(job_id)
        print(status)
        if status[0] != 5:
            raise ValueError('No table created')
        self.table = jobs.get_table(self.name, format='CSV').to_pandas()

        if self.context == 'ps1':
            self.table = self.table.replace(-999, np.nan)

        return
Exemplo n.º 9
0
def get_ps_score(RA, DEC):
	'''Get ps1 star/galaxy score from MAST. Provide RA and DEC in degrees.
	Returns an empty string if no match is found witing 3 arcsec.
	'''
	# get the WSID and password if not already defined
	# get your WSID by going to https://mastweb.stsci.edu/ps1casjobs/changedetails.aspx after you login to Casjobs.

	os.environ['CASJOBS_WSID'] = str(1862226089)
	os.environ['CASJOBS_PW'] = 'tr4nsientsP!z'
	query = """select top 1 p.ps_score
	from pointsource_magnitudes_view as p
	inner join fGetNearbyObjEq(%.5f, %.5f, 0.05) nb on p.objid=nb.objid
	""" %(RA, DEC)

	print(query)

	jobs = mastcasjobs.MastCasJobs(context="HLSP_PS1_PSC")
	results = jobs.quick(query, task_name="python cross-match")

	output = results.split('\n')[1]
	if not output:
		output = None
	
	return output
Exemplo n.º 10
0
s.ypsfMajorFWHM, s.ypsfMinorFWHM, s.ypsfLikelihood,
psc.ps_score, o.qualityFlag, o.objinfoFlag, s.primaryDetection, 
m.gFlags, s.ginfoFlag, s.ginfoFlag2, s.ginfoFlag3,
m.rFlags, s.rinfoFlag, s.rinfoFlag2, s.rinfoFlag3,
m.iFlags, s.iinfoFlag, s.iinfoFlag2, s.iinfoFlag3,
m.zFlags, s.zinfoFlag, s.zinfoFlag2, s.zinfoFlag3,
m.yFlags, s.yinfoFlag, s.yinfoFlag2, s.yinfoFlag3
from fGetNearbyObjEq({},{},{}) nb
join ObjectThin o on o.objid=nb.objid
join MeanObject m on o.objid=m.objid and o.uniquePspsOBid=m.uniquePspsOBid
join StackObjectView s on o.objid=s.objid and s.primaryDetection=1 and o.uniquePspsOBid=s.uniquePspsOBid
join HLSP_PS1_PSC.pointsource_scores psc on psc.objid=o.objid""".format(
    ra, dec, radius)

jobs = mastcasjobs.MastCasJobs(username='******',
                               password='******',
                               context=context)
results = jobs.quick(query, task_name='python cone search')
#tab = PC.fixcolnames(PC.ascii.read(results))

results_tab = Table(results,
                    meta={
                        'clustername': clustername,
                        'ra': ra,
                        'dec': dec,
                        'radius': radius
                    })

# # Convert all -999 entry to -99 for easier table handling in other scripts
# for c in range(len(results_tab.colnames)):
#     colname = results_tab.colnames[c]