Skip to content

Instantly share code, notes, and snippets.

@davidwhogg
Forked from dfm/README.md
Created November 15, 2012 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidwhogg/4079651 to your computer and use it in GitHub Desktop.
Save davidwhogg/4079651 to your computer and use it in GitHub Desktop.
Get some stars.

First install the Python module:

pip install casjobs

Then set the environment variables:

export CAS_DR9_WSID="1234567890" # get yours here: http://skyserver.sdss3.org/CasJobs/ChangeDetails.aspx
export CAS_DR9_PSWD="your_casjobs_password"

Then run the demo... attached.

This saves a file called "stars.fits" with the table you want in the 1 HDU... I think that you know where to go from there.

import os
import casjobs
table_name = "star_table"
q = """SELECT TOP 128 s.u, s.g, s.r, s.i, s.z, s.ra, s.dec, s.flags_g
INTO {0}
FROM Star s,
dbo.fGetNearbyObjEq(160.9862,58.1255,36.0) n
-- within 36 arcmin of this RA, Dec
WHERE
((s.flags_g & 0x10000000) != 0) -- detected in BINNED1
AND ((s.flags_g & 0x8100000c00a4) = 0)
-- not EDGE, NOPROFILE, PEAKCENTER, NOTCHECKED, PSF_FLUX_INTERP,
-- SATURATED, or BAD_COUNTS_ERROR
AND (((s.flags_g & 0x400000000000) = 0) or (s.psfmagerr_g <= 0.2))
-- not DEBLEND_NOPEAK or small PSF error
AND (((s.flags_g & 0x100000000000) = 0) or (s.flags_g & 0x1000) = 0)
-- not INTERP_CENTER or not COSMIC_RAY SELECT TOP 10
AND s.g < 22
AND s.objID = n.objID
ORDER BY
s.g
""".format(table_name)
# Make sure that these environment variables are set.
wsid = os.environ["CAS_DR9_WSID"]
pswd = os.environ["CAS_DR9_PSWD"]
jobs = casjobs.CasJobs(
userid=wsid,
password=pswd,
base_url="http://skyserver.sdss3.org/CasJobs/services/jobs.asmx"
)
# Clobber the table.
try:
jobs.drop_table(table_name)
except:
pass
job_id = jobs.submit(q)
status = jobs.monitor(job_id)
assert status[0] == 5
jobs.request_and_get_output(table_name, "FITS", "stars.fits")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment