next up previous contents
Next: About this document ... Up: The SX Online Manual Previous: Lists of Proximity Queries

Subsections

Example Queries

The following are queries that several people within the SDSS community wanted to run, and they are posted as examples of real queries. Each example is listed here in a way that you can directly cut and paste into the sxQT and run it, since comments are now accepted in queries (any text after // or # or - on a line is ignored).

Some general hints

Note: The time it typically takes to run each query and the # of objects found (in runs 752/756) is indicated in the comments below the query. The estimated time according to the query analysis (cost prediction) is also indicated in parentheses. The actual time will depend on a number of factors such as the system load and the number and type of SELECT fields in the query.

Some 'real' Query Examples

Query 1: Cataclysmic variables

// Paula Szkody <szkody@alicar.astro.washington.edu>
// Search for Cataclysmic Variables and pre-CVs with White Dwarfs and
// very late secondaries:
// u-g < 0.4
// g-r < 0.7
// r-i > 0.4
// i-z > 0.4
SELECT  obj.field.segment.run,               
        obj.field.segment.camCol,
	obj.field.segment.rerun,
	obj.field.field,
	obj.objID,
	u,g,r,i,z,
	obj.ra, obj.dec
FROM sxPrimary
WHERE (
    u - g < 0.4 &&
    g - r < 0.7 &&
    r - i > 0.4 &&
    i - z > 0.4
)
// Simple enough, but note that we run it on sxPrimary, a subclass of sxTag
// that includes sxGalaxy, sxStar, sxSky and sxUnknown. This excludes the
// sxBad and sxSecondary classes which need not be searched. Object
// members are extracted using the "obj" association-link in the tag class.
// Runs in 1438s (est 1566) and finds 83969 objs.

Query 2: Velocities and errors

// (Robert H. Lupton <rhl@astro.princeton.edu>)
SELECT  field.segment.run,
	field.segment.camCol,
	field.field,
	objID,
	objRowc,objColc,rowv,colv,rowvErr,colvErr,
	objFlags,flags,psfCounts,psfCountsErr
FROM sxPhotoPrimary
WHERE (
    ((rowv * rowv) / (rowvErr * rowvErr) + 
     (colv * colv) / (colvErr * colvErr) > 4)
)
// Runs in 977s (est. 132) and finds 298882 objs.

Query 3: Coordinate cut

// (Robert H. Lupton <rhl@astro.princeton.edu>)
// coordinate cut --> cut in ra --> 40:100
SELECT tag.g, tag.r
FROM sxPhotoObj
WHERE (
    ((-0.642788 * tag.cx + 0.766044 * tag.cy>=0) AND 
     (-0.984808 * tag.cx - 0.173648 * tag.cy<0))
)

// This query currently returns an empty query execution tree, i.e.
// no nodes are found to satisfy this cut.
// Another coordinate cut:
SELECT  psfCounts, rowv, colv, id, field.field,
	field.segment.run,field.segment.camCol
FROM sxPhotoObj
WHERE (
    ((-0.707107 * tag.cx -0.707107 * tag.cy>=0) AND 
     (-0.694658 * tag.cx -0.71934  * tag.cy<0))
)
// This one runs in 162s (est 90) but finds 0 objs.

Query 4: Searching objects and fields by ID

// (Robert H. Lupton <rhl@astro.princeton.edu>)
// Searching for a particular object in a particular field.
SELECT  objID,
	field.field, ra, dec
FROM sxPhotoObj
WHERE (
     objID = 14 && field.field = 11
)
// Runs in s (est ).

Query 5: Galaxies with bluer centers

// Michael Strauss <strauss@astro.princeton.edu>
// For all galaxies with r_Petro < 18, not saturated, not bright, not
// edge, give me those whose centers are appreciably bluer than their
// outer parts. That is, define the center color as: u_psf - g_psf And
// define the outer color as: u_model - g_model Give me all objects
// which have (u_model - g_model) - (u_psf - g_psf) < -0.4

SELECT u,g,photoobj.objID       // or whatever you want from each object
FROM sxGalaxy
WHERE (
  (flag1 & (OBJECT1_SATUR | OBJECT1_BRIGHT | OBJECT1_EDGE) == 0) &&
  (photoobj.petroRad[2] < 18) &&
  (((photoobj.modelCounts[0] - photoobj.modelCounts[1]) -
        (photoobj.psfCounts[0] - photoobj.psfCounts[1])) < -0.4)
)
// Notes: r_Petro -> petroRad[2] (3rd element of ugriz array) u_psf,
// g_psf -> psfCounts[0], psfCounts[1] u_model, g_model ->
// modelCounts[0], modelCounts[1] ** these are the same as ugriz, so
// if you can use (u-g) instead of (modelCounts[0] - modelCounts[1])
// it runs twice as fast!  The search is performed on the sxGalaxy
// subclass of sxTag, so only galaxy objects are searched and you dont
// need the "if galaxy..."  The petroRad, modelCounts and psfCounts
// are members of the sxPhotoObj class, which is accessed via the
// "photoobj" association link in the tag class.  Since the query is
// done on tag objects, you need the "photoobj."  prepended to each
// photoobj member in the SELECT list.  A combination of flags is used
// to filter out saturated, bright and edge objects.
//
// Runs in 598s (est. 643) and finds 23737 objs (using u-g).

Query 6: PSF colors of stars

// Michael Strauss <strauss@astro.princeton.edu>
// Give me the PSF colors of all stars brighter than 20th (rejecting on
// various flags) that have PSP_STATUS = 2
//
// This query can be formulated in at least 2 ways, but the second
// being much faster than the first:
// Method 1:
SELECT  photoobj.psfCounts,         // or whatever you want from each object
	field.segment.run,
	field.segment.camCol,
	field.segment.rerun,
	field.field
FROM sxStar
WHERE (
    obj.psfCounts[1] < 20 && (field.pspStatus = 2)
)
// The search is performed on the sxStar subclass of sxTag, so only
// star objects are searched.
// PSP_STATUS -> field.pspStatus
// Runs in 727s (est. 918) but finds 0 objs. [ART]
// Finds tons of objects if pspStatus check is left out.
// Method 2 (this is an example of an association query):

SELECT  field.segment.run,
	field.segment.camCol,
	field.segment.rerun,
	field.field,
	objID,ra,dec
FROM (
     SELECT obj FROM field WHERE pspStatus = 2
     )
WHERE (
     objType = AR_OBJECT_TYPE_STAR && psfCounts[2] < 20          
)
// The second query uses the knowledge that there are far fewer fields than
// objects, and so drastically narrows the number of objects found by using
// an association query on the field class. We first get all objects
// belonging to fields with pspStatus = 2, then apply the star test and
// psfCounts predicate to all such objects.
// Runs in < 2s (est 10) and finds 0 objs (FAST!).

Query 7: Cluster finding

// (James Annis <annis@fnal.gov>)
// if {AR_DFLAG_BINNED1 || AR_DFLAG_BINNED2 || AR_DFLAG_BINNED4} {
//    if {! ( AR_DFLAG_BLENDED && !( AR_DFLAG_NODEBLEND || AR_DFLAG_CHILD))} {
//       if { galaxy } { ;# not star, asteroid, or bright
//           if { primary_object} {
//             if {petrocounts{i} < 23 } { accept }
//           }
//       }
//    }
// }
SELECT  obj.field.segment.run,          // or whatever you want
        obj.field.segment.camCol,
        obj.field.segment.rerun,
        obj.field.field,
        obj.objID, obj.ra, obj.dec
FROM galaxy                             // select galaxy and primary only
WHERE (
   flag1 & (AR_DFLAG1_BINNED1 | AR_DFLAG1_BINNED2 | AR_DFLAG1_BINNED4) > 0 
&&
   flag1 & (AR_DFLAG1_BLENDED | AR_DFLAG1_NODEBLEND | AR_DFLAG1_CHILD) !=
                            AR_DFLAG1_BLENDED 
&& 
   obj.petroCounts[3] < 23
)
// Notes: AR_DFLAG -> AR_DFLAG1 or OBJECT1
// petrocounts -> petroCounts[3] (i is 4th in array[0:4] of u,g,r,i,z)
// Selecting sxGalaxy (or galaxy) class already ensures it is a primary
// object because sxGalaxy is a subclass of sxPrimary.
// The petroCounts is a member of the sxPhotoObj class, which is accessed
// via the "photoobj" (alias "obj") association link in the tag class.
// 
// Takes almost an hour to run and finds almost all of the 1.9M galaxies!

Query 8: Diameter-limited sample of galaxies

// (James Annis <annis@fnal.gov>)
// if {AR_DFLAG_BINNED1 || AR_DFLAG_BINNED2 || AR_DFLAG_BINNED4} {
//   if {! ( AR_DFLAG_BLENDED && !( AR_DFLAG_NODEBLEND || AR_DFLAG_CHILD)} {
//      if { galaxy } { ;# not star, asteroid, or bright
//         if (!AR_DFLAG_NOPETRO) {
//           if { petrorad > 15 } { accept }
//         } else {
//           if { petror50 > 7.5 } { accept }
//         }
//         if (AR_DFLAG_TOO_LARGE && petrorad > 2.5 ) { accept }
//         if ( AR_DFLAG_SATUR && petrorad < 17.5) { don't accept }
//      }
//    }
//  }
SELECT obj.field.segment.run,
       obj.field.segment.camCol,
       obj.field.segment.rerun,
       obj.field.field,
       obj.objID, obj.ra, obj.dec
FROM galaxy
WHERE (
   flag1 & (AR_DFLAG1_BINNED1 | AR_DFLAG1_BINNED2 | AR_DFLAG1_BINNED4) > 0 
&&
   flag1 & (AR_DFLAG1_BLENDED | AR_DFLAG1_NODEBLEND | AR_DFLAG1_CHILD) !=
		      AR_DFLAG1_BLENDED 
&&
    ( ( flag1 & AR_DFLAG1_NOPETRO == 0 && obj.petroRad[3] > 15 ) ||
      ( flag1 & AR_DFLAG1_NOPETRO > 0 && obj.petroR50[3] > 7.5 ) ) 
||
      ( flag1 & AR_DFLAG1_TOO_LARGE >0 && obj.petroRad[3] > 2.5 ) 
&&
      ( flag1 & AR_DFLAG1_SATUR == 0 || obj.petroRad[3] >= 17.5 )
)
// Notes: AR_DFLAG -> AR_DFLAG1 or OBJECT1
// petrorad -> petroRad[3] (i is 4th in array[0:4] of u,g,r,i,z)
// petror50 -> petroR50[3] similarly
// The search is performed on the sxGalaxy (alias "galaxy") subclass of
// sxTag, so only galaxy objects are searched.
// The petrorad and petroR50 are members of the sxPhotoObj class, which
// is accessed via the "photoobj" (alias "obj") association link in
// the tag class.
// Runs in 790s (est 643) and returns 11065 objs. Jim thinks that this is too
// many objects, and we are investigating whether we formulated the query
// as he intended it or not. Same is the case for the next two queries.

Query 9: Extremely red galaxies:

// (James Annis <annis@fnal.gov>)
// if {AR_DFLAG_BINNED1 || AR_DFLAG_BINNED2 || AR_DFLAG_BINNED4} {
//    if {! ( AR_DFLAG_BLENDED && !( AR_DFLAG_NODEBLEND || AR_DFLAG_CHILD)} {
//        if { galaxy } { ;# not star, asteroid, or bright
//           if { primary_object} {
//               if {!AR_DFLAG_CR && !R_DFLAG_INTERP}
//                   if { frame_seeing < 1.5" } {
//                       if { counts_model<i>-counts_model<z> - 
//                              (reddening<i> - reddening<z>) > 1.0 } {
//                          accept
//                       }
//                   }
//               }
//           }
//        }
//     }
// }
SELECT field.segment.run,
       field.segment.camCol,
       field.segment.rerun,
       field.field,
       obj.objID, obj.ra, obj.dec
FROM galaxy
WHERE (
   flag1 & (AR_DFLAG1_BINNED1 | AR_DFLAG1_BINNED2 | AR_DFLAG1_BINNED4) > 0 
&&
   flag1 & (AR_DFLAG1_BLENDED | AR_DFLAG1_NODEBLEND | AR_DFLAG1_CHILD) !=
		      AR_DFLAG1_BLENDED 
&&
   flag1 & (AR_DFLAG1_CR | AR_DFLAG1_INTERP) == 0 
&&
   field.psfWidth[2] < 1.5 
&& 
   (i - z - (obj.reddening[3] - obj.reddening[4]) > 1.0 )
)
// i - z used inst. of modelCounts<i> - modelCounts<z>
// Runs in 1043s (est 643), finds 29648 objects.

Query 10: The BRG sample

{
// (James Annis <annis@fnal.gov>)
// if {AR_DFLAG_BINNED1 || AR_DFLAG_BINNED2 || AR_DFLAG_BINNED4} {
//    if {! ( AR_DFLAG_BLENDED && !( AR_DFLAG_NODEBLEND || AR_DFLAG_CHILD)} {
//       if {!AR_DFLAG_EDGE & !AR_DFLAG_SATUR} {
//          if { galaxy} { ;# not star, asteroid, or bright
//            if { primary_object} {
//               if {! (petrocounts<2> < 15.5 && petror50<2> < 2) } {
//                 if {petrocounts<r> > 0 && counts_model<g> > 0 &&
//                       counts_model<r> > 0 && counts_model<i> > 0 } {
//                     petSB = deRed_r + 2.5*log10(2*3.1415*petror50<r>^2)
//                     deRed_g = petrocounts<g> - reddening<g>
//                     deRed_r = petrocounts<r> - reddening<r>
//                     deRed_i = petrocounts<i> - reddening<i>
//                     deRed_gr = deRed_g - deRed_r
//                     deRed_ri = deRed_r - deRed_i
//                     cperp = deRed_ri - deRed_gr/4.0 - 0.18
//                     cpar = 0.7*deRed_gr + 1.2*(deRed_ri -0.18)
//                     if {(deRed_r < 19.2 && deRed_r < 13.1 + cpar/0.3 &&
//                          abs(cperp) < 0.2 && petSB < 24.2 ) ||
//                          (deRed_r < 19.5 && cperp > 0.45 - deRed_gr/0.25 &&
//                           deRed_gr > 1.35 + deRed_ri*0.25 && petSB < 23.3) {
//                          accept ;# whew!!!
//                      }
//                   }
//                }
//             }
//           }
//        }
//     }
//  }
//
SELECT
field.segment.run,
field.segment.camCol,
field.segment.rerun,
field.field,
obj.objID,
obj.ra,
obj.dec
FROM galaxy WHERE (

flag1 & (AR_DFLAG1_BINNED1 | AR_DFLAG1_BINNED2 | AR_DFLAG1_BINNED4) > 0 &&
flag1 & (AR_DFLAG1_BLENDED | AR_DFLAG1_NODEBLEND | AR_DFLAG1_CHILD) != 
    AR_DFLAG1_BLENDED  &&

flag1 & (AR_DFLAG1_EDGE | AR_DFLAG1_SATUR) == 0 && 
obj.petroCounts[3] > 17.65 &&

(obj.petroCounts[2] > 15.5 || obj.petroR50[2] > 2 ) &&
(obj.petroCounts[2] > 0 && g > 0 && r > 0 && i > 0 ) &&

(

(obj.petroCounts[2] - obj.reddening[2] < 19.2) &&
(obj.petroCounts[2] - obj.reddening[2] < 13.1 +     // deRed_r < 13.1 +
  (7/3)*( g - obj.reddening[1] -   // 0.7 / 0.3 * deRed_gr
	  r + obj.reddening[2] ) + 
     4 *( r - obj.reddening[2] -    // 1.2 / 0.3 * deRed_ri
	  i + obj.reddening[3] )
    -4 * 0.18 ) &&
( ( r - obj.reddening[2] - 
    i + obj.reddening[3] -
   (g - obj.reddening[1] - 
    r + obj.reddening[2])/4 - 0.18 ) < 0.2 ) &&
( ( r - obj.reddening[2] - 
    i + obj.reddening[3] -
   (g - obj.reddening[1] - 
    r + obj.reddening[2])/4 - 0.18 ) > -0.2 ) &&

// petSB - deRed_r + 2.5 log10(2Pi*petroR50^2)
( (obj.petroCounts[2] - obj.reddening[2]) +         
   2.5 * LOG( 2 * 3.1415 * obj.petroR50[2] * obj.petroR50[2] ) < 24.2 ) 

)  ||
(

(obj.petroCounts[2] - obj.reddening[2] < 19.5) &&
( ( r - obj.reddening[2] -             // cperp = deRed_ri
    i + obj.reddening[3] -             // - deRed_gr/4 - 0.18
   (g - obj.reddening[1] - 
    r + obj.reddening[2])/4 - 0.18 ) > 
  0.45 - 4*( g - obj.reddening[1] -   // 0.45 - deRed_gr/0.25
	     r + obj.reddening[2] ) ) &&
  
( g - obj.reddening[1] - 
  r + obj.reddening[2]  >  
  1.35 + 0.25 *( r - obj.reddening[2] - 
                 i + obj.reddening[3] ) ) &&

// petSB - deRed_r + 2.5 log10(2Pi*petroR50^2)
( (obj.petroCounts[2] - obj.reddening[2]) +          
   2.5 * LOG( 2 * 3.1415 * obj.petroR50[2] * obj.petroR50[2] ) < 23.3 ) 

)

) 
// query runs in 2035 seconds, returning 19942 objects.  
// after having added the obj.petrocounts[3] > 17.65, there are 
// still 16944 objects.

Query 11: Low-z QSO candidates

// Gordon Richards <richards@oddjob.uchicago.edu>
// Low-z QSO candidates using the following cuts:
//
// -0.27 <= u-g < 0.71
// -0.24 <= g-r < 0.35
// -0.27 <= r-i < 0.57
// -0.35 <= i-z < 0.70
// g <= 22
// objc_type == 3
SELECT g,obj.objID    // or whatever you want returned
FROM sxGalaxy         // takes care of objc_type == 3
WHERE (
  (g <= 22) &&
  (u-g >= -0.27) && (u-g < 0.71) &&
  (g-r >= -0.24) && (g-r < 0.35) &&
  (r-i >= -0.27) && (r-i < 0.57) &&
  (i-z >= -0.35) && (i-z < 0.70)
)
//
// Runs in 323s (est. 643) and finds 12054 objs.
// OR, do it using the BETWEEN operator:

SELECT field.segment.run,
       field.segment.camCol,
       field.segment.rerun,
       field.field,
       obj.objID,
       obj.ra,
       obj.dec
FROM sxGalaxy
WHERE
  g <= 22 &&
  (u-g) BETWEEN -0.27 AND 0.71 &&
  (g-r) BETWEEN -0.24 AND 0.35 &&
  (r-i) BETWEEN -0.27 AND 0.57 &&
  (i-z) BETWEEN -0.35 AND 0.70
// This runs in 11:41 minutes and returns 12054 objects. The longer
// time is due to the additional association links it has to follow up
// in the SELECT statement. The more member fields you want to extract
// and the more indirection is involved (i.e. association of
// association of ...), the longer it will take to get the results
// back. As for the second part of this query: Then I look to see if
// any of the output objects are within 10" of each other to see if
// they might be gravitational lens candidates. For output, I spit out
// run, rerun, camcol, field, id, g', the 4 colors, and the FIRST peak
// flux.

Comment: This would have to be done with an analysis engine. There is no way to do this with the SX currently (although you can do a proximity query on a single object at a time).

Query 12: Errors on moving objects

// Gordon Richards <richards@oddjob.uchicago.edu>
// Another useful query is to see if the errors on moving (or apparently
// moving objects) are correct. For example it used to be that some
// known QSOs were being flagged as moving objects. One way to look for
// such objects is to compare the velocity to the error in velocity and
// see if the "OBJECT1_MOVED" or "OBJECT2_BAD_MOVING_FIT" is set. So
// return objects with
//
// objc_type == 3
// sqrt(rowv*rowv + colv*colv) >= sqrt(rowvErr*rowvErr + colvErr*colvErr)
//
// then output, the velocity, velocity errors, i' magnitude, and the
// relevant "MOVING" object flags.

SELECT obj.rowv,
       obj.colv,
       obj.rowvErr,
       obj.colvErr,
       i,
       flag1 & OBJECT1_OBJECT_MOVED,
       flag2 & OBJECT2_BAD_MOVING_FIT
FROM sxGalaxy
WHERE (
 (flag1 & OBJECT1_OBJECT_MOVED) > 0 || (flag2 & OBJECT2_BAD_MOVING_FIT) > 0 &&
  (obj.rowv * obj.rowv + obj.colv * obj.colv) >= (obj.rowvErr * obj.rowvErr
                                                + obj.colvErr * obj.colvErr)
)
// Runs in 1615s (est. 643) and finds 72987 objs with flags.

Query 13: A random sample of the data

// Karl Glazebrook <kgb@pha.jhu.edu>
// So as a newcomer I might want to do somethink like 'give me the colours
// of 100,000 random objects from all fields which are survey quality' so
// then I could plot up colour-colour diagrams and play around with
// more sophisticated cuts. How would I do that?
//
// COMMENT:
// Unfortunately, it is not possible to get a random sample using the SX (yet).
// One thing you might do is get all the objects in a given database file
// in the federation. There are currently ~ 200 DBs in the SX, and getting
// all the objects in one DB wd give you several thousand objects, though
// all in a given region of the sky. To have a sample you might also just
// select a certain run and camcol and investigate only the galaxies from
// there:
SELECT * FROM (
    SELECT obj FROM field WHERE segment.run = 752 && segment.camcol = 2
) WHERE objType = 3

Query 14: tsObj data for a list of objects

// (Dan VandenBerk <danvb@fnal.gov>)
// We have a list of objects -- RA and DEC -- for which we would like
// matches and all of the tsObj data. Can I send you the list?

This can be run using the ProxList server to process the datafile one by one. See section on proxlist for details.

Query 15: Find quasars

// (Xiaohui Fan et.al. <fan@astro.princeton.edu>) 
// quasar finding query

SELECT obj.field.segment.run,
        obj.field.segment.camCol,
        obj.field.segment.rerun,
        obj.field.field,
        obj.objID,
        u,g,r,i,z,
        obj.ra,
        obj.dec
FROM sxStar       // or sxGalaxy 
WHERE ( 
( u - g > 2.0 || u > 22.3 ) && 
( i < 19 ) && ( i > 0 ) && 
( g - r > 1.0 ) && 
( r - i < 0.08 + 0.42 * (g - r - 0.96) || g - r > 2.26 ) && 
( i - z < 0.25 ) 
 )


next up previous contents
Next: About this document ... Up: The SX Online Manual Previous: Lists of Proximity Queries



© The Johns Hopkins University 2000
Generated by Ani Thakar at 2001-05-31