# Cross-matching SDSS and Gaia Data

**URL:** <https://www.rubin.community/t/cross-matching-sdss-and-gaia-data/7411>\
**Category:** Support\
**Tags:** dp0\
**Created:** [February 14, 2023, 12:06am UTC](https://www.rubin.community/t/cross-matching-sdss-and-gaia-data/7411 "2023-02-14T00:06:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![babel](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/babel/32/2085_2.png) [@babel](https://www.rubin.community/u/babel)\
**Post date:** [February 14, 2023, 12:06am UTC](https://www.rubin.community/t/cross-matching-sdss-and-gaia-data/7411/1 "2023-02-14T00:06:38Z")

</div>

I want to cross-match SDSS SEGUE stars with the Gaia DR3 data set to create photometric parallax models for DP0.2. I’m just starting to look at the Gaia tutorials, but I think the NOIR Astrolab has what I want. I’d appreciate any suggestions.

---

<div class="post-metadata">

**Author:** ![babel](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/babel/32/2085_2.png) [@babel](https://www.rubin.community/u/babel)\
**Post date:** [February 14, 2023, 12:08am UTC](https://www.rubin.community/t/cross-matching-sdss-and-gaia-data/7411/2 "2023-02-14T00:08:52Z")

</div>

From Mark Taylor:  
I’m no SDSS expert but it looks like this match has already been done between SDSS DR17 and Gaia DR3; the following ADQL query to the Noirlab TAP service seems to do the job (as long as your distance constraint is less than 1.5 arcsec):  
select \*  
from sdss\_dr17.x1p5\_\_specobj\_\_gaia\_dr3\_\_gaia\_source as j  
join sdss\_dr17.specobj as specobj on j.id1 = specobj.specobjid  
join gaia\_dr3.gaia\_source as gaia on j.id2 = gaia.source\_id  
where j.“distance”\<0.3  
The resulting table is rather wide, so specifying only the columns you want rather than SELECT \* would be a good idea. The ESA Gaia TAP service has a similar match table between Gaia DR3 and SDSS DR13. You can do this using TOPCAT’s tap client, as noted at [https://datalab.noirlab.edu/splus/access.php;](https://datalab.noirlab.edu/splus/access.php;) maybe also using the interfaces on the datalab web pages.

---

<div class="post-metadata">

**Author:** ![babel](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/babel/32/2085_2.png) [@babel](https://www.rubin.community/u/babel)\
**Post date:** [February 14, 2023, 12:09am UTC](https://www.rubin.community/t/cross-matching-sdss-and-gaia-data/7411/3 "2023-02-14T00:09:20Z")

</div>

Thank you Mark, I’ll try it!

---

<div class="post-metadata">

**Author:** ![babel](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/babel/32/2085_2.png) [@babel](https://www.rubin.community/u/babel)\
**Post date:** [March 6, 2023, 6:22pm UTC](https://www.rubin.community/t/cross-matching-sdss-and-gaia-data/7411/4 "2023-03-06T18:22:58Z")

</div>

Thank you again, Mark (and Robert Nikutta). I needed to join three tables instead of two, and with help from the two of you, the following query now works on the NOIR Astro DataLab. This community is so supportive!

query = “”"  
SELECT s.bestobjid, s.specobjid, s.ra, s.dec, s.glon, s.glat, s.class, s.elodieteff,   
s.elodiefeh, s.elodielogg,   
g.source\_id, g.designation, g.ra, g.dec, g.l, g.b, g.parallax, g.teff\_gspphot,   
g.mh\_gspphot, g.logg\_gspphot, g.rv\_template\_teff, g.rv\_template\_fe\_h,  
g.rv\_template\_logg,   
p.objid, p.ra, p.dec, p.l, p.b, p.clean, p.score, p.type, p.type\_u, p.type\_g,   
p.type\_r, p.type\_i, p.type\_z, p.psfmag\_u, p.psfmag\_g, p.psfmag\_r, p.psfmag\_i,   
p.psfmagerr\_i, p.psfmagerr\_z, p.probpsf, p.probpsf\_u, p.probpsf\_g, p.probpsf\_r,   
p.probpsf\_i, p.probpsf\_z, p.lnlstar\_u, p.lnlstar\_g, p.lnlstar\_r, p.lnlstar\_i,   
p.lnlstar\_z   
FROM sdss\_dr17.x1p5\_\_specobj\_\_gaia\_dr3\_\_gaia\_source as j   
JOIN sdss\_dr17.specobj as s ON j.id1 = s.specobjid   
JOIN gaia\_dr3.gaia\_source as g ON j.id2 = g.source\_id   
JOIN sdss\_dr17.photoplate as p ON s.bestobjid = p.objid   
WHERE p.clean= 1 AND p.type=6 AND g.teff\_gspphot \>2000. AND   
s.elodieteff\>2000.   
LIMIT 10"""  
result = qc.query(sql=query, fmt=‘pandas’)  
result
