The following is a selection of actual queries submitted by SDSS users, and some are in response to scientific questions posed by users. The queries are listed in increasing order of difficulty/complexity. Where applicable, query execution times for the latest SDSS data releases are noted. NOTE: Please also read the Optimizing Queries and Bookmark Lookup Bug sections of the SQL Intro page to learn how to run faster queries, and the Query Limits page to see the timeouts and row limits on queries. Click on the name of the query from the list below to go directly to that sample query. The queries are roughly in order of increasing complexity. You can cut and paste queries from here into your favorite search tool.
Basic SELECT-FROM-WHERE Top
Galaxies with two criteria Top
Unclassified spectra Top
Galaxies with multiple criteria Top
Spatial unit vectors Top
Cataclysmic variables (CVs) using colors Top
Data subsample Top
Low-z QSOs using colors Top
Object velocities and errors Top
Using BETWEEN Top
Moving Asteroids Top
Quasars in imaging Top
Object counting and logic Top
Galaxies blended with stars Top
Stars in specific fields Top
Using three tables Top
Selected neighbors in run Top
QSOs in spectroscopy Top
Objects close pairs Top
Errors using flags Top
Elliptical galaxies based on model fits Top
|
-- Galaxies with bluer centers, by Michael Strauss. For all galaxies with r_Petro < 18, -- not saturated, not bright, and not edge, give me those with centers appreciably bluer -- than their outer parts, i.e., define the center color as: u_psf - g_psf and define -- the outer color as: u_model - g_model; give me all objs which have -- (u_model - g_model) - (u_psf - g_psf) < -0.4 -- -- Another flags-based query. -- NOTE: This query takes a long time to run without the "TOP 1000". | |
SELECT TOP 1000 | |
| |
FROM Galaxy | |
WHERE | |
| |
| |
| |
| |
| |
|
-- Diameter-limited sample of galaxies from James Annis. -- Another query showing the use of flags, now using the bitwise '|' (or). | |
SELECT | |
| |
| |
| |
| |
| |
| |
| |
FROM Galaxy | |
WHERE ( flags & (dbo.fPhotoFlags('BINNED1') | |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
-- Extremely red galaxies (from James Annis). -- Similar to the previous query. | |
SELECT | |
| |
| |
| |
| |
| |
| |
FROM Field f | |
| |
WHERE | |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
-- A version of the LRG sample, by James Annis. -- Another query with many conditions and flag tests. | |
SELECT | |
| |
| |
| |
| |
| |
| |
| |
FROM Galaxy | |
WHERE ( ( flags & (dbo.fPhotoFlags('BINNED1') | |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
-- The query below was originally written by Andy Connolly to find the brightness of -- the closest source within 0.5arcmin. It involves a 3-way join of the PhotoObjAll table -- with itself and the Neighbors table. This is a huge join because the PhotoObjAll table -- is the largest table in the DB, and the Neighbors table has over a billion entries -- (although it is a thin table). The two versions of the query shown below illustrate -- how we can speed up the query a lot by using the (much thinner) PhotoTag table -- instead of the PhotoObjAll table. See also the Optimizing Queries section of the -- SQL Intro page for more on using the PhotoTag table. The query also illustrates the -- LEFT JOIN construct and the use of nested joins. -- The first (original) version of the query uses the PhotoObjAll table twice in the 3-way -- join because we need some of the columns that are only in the PhotoObjall table. -- Since this version literally takes days to run on the entire DR2 database, a TOP 100 -- has been inserted into the SELECT to prevent the query from being submitted as is. SELECT TOP 100 o.ra,o.dec,o.flags, o.type,o.objid, FROM PhotoObjAll as o WHERE -- The second version of this query demonstrates the advantage of using the PhotoTag -- table over the PhotoObjAll table. One of the PhotoObjAll joins in the main 3-way -- join is replaced with PhotoTag, and the nested PhotoObjAll join with Neighbors is -- also replaced with PhotoTag. This version runs in about 2-3 hours on the DR2 DB. -- Note that when you replace PhotoObjAll or its views by PhotoTag, you have to also -- replace any references to the shorthand (simplified) magnitudes (u,g,r,i,z) and errors -- by their full names (modelMag_u and modelMagErr_u etc.). SELECT o.ra,o.dec,o.flags, o.type,o.objid, FROM PhotoObjAll as o WHERE | |
-- Two versions of a query to find galaxies with particular spectral lines. -- Version 1: Find galaxies with spectra that have an equivalent width in -- H_alpha > 40 Angstroms. We want object ID's from the photometry (Galaxy) -- but constraints from spectroscopy. The line widths and IDs are stored in -- SpecLine. This is a simple query, but now we are using three tables. The -- spectroscopy tables of measured lines are arranged non-intuitively, and we -- urge users to read about them on the DAS help pages. -- IMPORTANT NOTE: -- Each spectroscopic object now has a match to at least two photometric -- objects, one in Target and one in Best. Therefore, when performing a join -- between spectroscopic photometric objects, you must specify either -- PhotoObj.ObjID=SpecObj.bestObjID OR PhotoObj.ObjID = SpecObj.targetObjID. -- Normally, the default photometric database is BEST, so you will want to use -- SpecObj.bestObjID | |
SELECT G.objId | -- we want the photometric objID |
FROM Galaxy as G | |
JOIN SpecObj as S ON G.objId=S.bestObjId | -- this galaxy has a spectrum, and |
JOIN SpecLine as L ON S.specObjId=L.specObjId | -- line L is detected in spectrum |
WHERE | |
-- you could add a constraint that the spectral type is galaxy | |
L.LineId = 6565 | -- and line L is the H alpha line |
and L.ew > 40 | -- and is > 40 angstrom wide |
-- Second version of this query finds galaxies with more specific spectra. -- This version also requires weak Hbeta line (Halpha/Hbeta > 20.) | |
SELECT G.ObjID | -- return qualifying galaxies |
FROM Galaxy as G | -- G is the galaxy |
JOIN SpecObj as S ON G.ObjID = S.BestObjID | -- S is the spectra of galaxy G |
JOIN SpecLine as L1 ON S.SpecObjID = L1.SpecObjID | -- L1 is a line of S |
JOIN SpecLine as L2 ON S.SpecObjID = L2.SpecObjID | -- L2 is a second line of S |
JOIN SpecLineNames as LN1 ON L1.LineId = LN1. value | -- the names of the lines (Halpha) |
JOIN SpecLineNames as LN2 ON L2.LineId = LN2.value | -- the names of the lines (Hbeta) |
WHERE LN1.name = 'Ha_6565' | -- L1 is H-alpha |
| -- L2 is H-beta |
| -- BIG Halpha |
| -- significant Hbeta emission line |
| -- Hbeta is comparatively small |
|
-- This query demonstrates the use of the photometry flags to select clean -- photometry for star and galaxy objects. Note that using these flag combinations -- may invoke the bookmark lookup bug if your query is searching a large fraction -- of the database. In that case, use the prescribed workaround for it as described on -- the SQL intro page. -- For queries on star objects, when you use PSF mags, use only PRIMARY objects -- and the flag combinations indicated below. If you use the Star view as below, you -- will get only primary objects, otherwise you will need to add a "mode=1" constraint. -- NOTE: The symbolic flag values are purposely replaced in the following examples by -- the hex values for the flag masks. This is for efficiency (see the Using dbo -- functions section of the SQL Intro page). -- For example, if you are interested in r-band magnitudes of objects, perform the -- following checks (add analogous checks with AND for other bands if you are -- interested in multiple magnitudes or colors): | |||
SELECT TOP 10 u,g,r,i,z,ra,dec, flags_r FROM Star WHERE -- For galaxies (i.e. not using PSF mags): Again use only PRIMARY objects. Other -- cuts are nearly the same, but remove the cut on EDGE. Possibly also remove -- the cut on INTERP flags. SELECT TOP 10 u,g,r,i,z,ra,dec, flags_r FROM Galaxy WHERE | |
-- Find binary stars with specific colors. -- At least one of them should have the colors of a white dwarf. | |
SELECT TOP 100 s1.objID as s1, s2.objID as s2 | |
FROM Star AS S1 | -- S1 is the white dwarf |
JOIN Neighbors AS N ON S1.objID = N.objID | -- N is the precomputed neighbors lists |
JOIN Star AS S2 ON S2.objID = N.NeighborObjID | -- S2 is the second star |
WHERE | |
| -- and S2 is a star |
| -- the 3 arcsecond test |
| -- and S1 meets Paul Szkodys color cut for |
| -- white dwarfs. |
| |
| |
|
-- Find quasars with a broad absorption line and a nearby galaxy within 10arcsec. -- Return both the quasars and the galaxies. | |
SELECT Q.BestObjID as Quasar_candidate_ID , | |
| |
FROM SpecObj as Q | -- Q is the specObj of the quasar candidate |
JOIN Neighbors as N ON Q.BestObjID = N.ObjID | -- N is the Neighbors list of Q |
JOIN Galaxy as G ON G.ObjID = N.NeighborObjID | -- G is the nearby galaxy |
JOIN SpecClass as SC ON Q.SpecClass =SC.value | -- Spec Class |
JOIN SpecLine as L ON Q.SpecObjID = L.SpecObjID | -- the broad line we are looking for |
JOIN SpecLineNames as LN ON L.LineID = LN.value | -- Line Name |
WHERE | |
| -- Spectrum says "QSO" |
| -- and isn't not identified |
| -- but its a prominent absorption line |
| -- and it is within 10 arcseconds of the Q. |
|
-- Find galaxies without saturated pixels within 1' of a given point (ra=185.0, dec=-0.5). -- This query uses a function fGetNearbyObjEq,which takes 3 arguments (ra,dec, -- distance in arcmin); this function uses the Neighbors table. The Neighbors and Galaxy -- tables have in common the objID, so we have to select objects from both where the -- objIDs are the same. The output of the function is a table with the Galaxy Object ID -- and distance in arcmin from the input. This query introduces the use of a JOIN to -- combine table contents. We also use the 'ORDER BY' syntax, which sorts the output. | ||||
SELECT TOP 100 G.objID, GN.distance | ||||
FROM Galaxy as G | ||||
JOIN dbo.fGetNearbyObjEq(185.,-0.5, 1) AS GN -- this function outputs a table, so we have to do a join | ||||
WHERE (G.flags & dbo.fPhotoFlags('saturated')) = 0 -- and the object is not saturated. f.PhotoFlags is a function that interprets the flag bits.
| ORDER BY distance -- sort these by distance
| | |
-- Find all elliptical galaxies with spectra that have an anomalous emission line. -- This query introduces the SQL syntax DISTINCT, which will return only one instance -- of the requested parameter (ObjID, in this case), because our query may return the -- same object more than once. This is also the first nested query, where we use one -- SELECT (the inner one) to get a group of objects we are not interested in. The outer -- SELECT includes the new syntax 'not in', which is used to perform the exclusion. | |
SELECT DISTINCT G.ObjID | |
FROM | |
JOIN Galaxy as G | |
JOIN SpecObj as S ON G.ObjID = S.bestObjID | -- the galaxy has a spectrum |
JOIN SpecLine as L ON S.SpecObjID = L.SpecObjID | -- L is a spectral line |
JOIN XCRedshift as XC ON S.SpecObjID = XC.SpecObjID | -- cross-correlation redshift |
WHERE | |
| -- template used is "elliptical" |
| -- any line type is found |
| -- and the line is prominent by some |
-- definition; in this case, equivalent | |
-- width is over 10 Angstroms | |
| -- insist that there are no other lines |
| -- This is the chosen line. |
| -- L1 is another line |
| -- for this object |
| -- at nearly the same wavelength |
| -- but with unknown line type |
| |
|
-- What's the SQL to get the broadest line of each spectrum, together with its -- identification (or more generally, all the columns for the spectral line with the -- highest/lowest something)? (Sebastian Jester) -- Note: The previous version of this query was corrected by Gordon Richards. | |
SELECT top 100 | |
| |
| |
| |
-- get the spectroscopic object ID, the line ID, and the max width (in velocity) | |
FROM SpecLine AS sl | |
JOIN (SELECT | |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
WHERE | |
| |
-- Just as with the specObjID, each specLineID appears many times in specLine | |
-- This final WHERE clause makes sure we get the one specLineID from SpecObj | |
-- which matches the unique combination of specObjID and lineID in sMax. | |
|
-- Gridded galaxy counts and masks. Actually consists of TWO queries: -- 1) Create a gridded count of galaxies with u-g > 1 and r < 21.5 over -1 < dec < 1, -- and 179 < R.A. < 181, on a grid, and create a map of masks over the same grid. -- Scan the table for galaxies and group them in cells 2 arc-minuteson a side. Provide -- predicates for the color restrictions on u-g and r and to limit the search to the -- portion of the sky defined by the right ascension and declination conditions. Return -- the count of qualifying galaxies in each cell. -- 2) Run another query with the same grouping, but with a predicate to include only -- objects such as satellites, planets, and airplanes that obscure the cell. The second -- query returns a list of cell coordinates that serve as a mask for the first query. --- First find the gridded galaxy count (with the color cut) --- In local tangent plane, ra/cos(dec) is a linear degree. | |||||||||||||||||||||||||||
SELECT cast((ra/cos(cast(dec*30 as int)/30.0))*30 as int)/30.0 as raCosDec, | |||||||||||||||||||||||||||
| FROM Galaxy as G
| | | WHERE ra between 179 and 181
| | | | GROUP BY cast((ra/cos(cast(dec*30 as int)/30.0))*30 as int)/30.0,
| |
| -- now build mask grid. -- This is a separate query if no temp tables can be made SELECT cast((ra/cos(cast(dec*30 as int)/30.0))*30 as int)/30.0 as raCosDec,
| | | FROM PhotoObj as PO
| | | | WHERE
| | | | GROUP BY cast((ra/cos(cast(dec*30 as int)/30.0))*30 as int)/30.0,
| | | |
-- Create a count of galaxies for each of the HTM triangles. Galaxies should satisfy a -- certain color cut, like 0.7u-0.5g-0.2i<1.25 && r<21.75, output it in a form adequate -- for visualization. | |||||||||
SELECT (htmID / power(2,24)) as htm_8 , | |||||||||
| | | FROM Galaxy -- only look at galaxies
| WHERE (0.7*u - 0.5*g - 0.2*i) < 1.25 -- meeting this color cut
| | group by (htmID /power(2,24)) -- group into 8-deep HTM buckets.
| | |
-- Find stars with multiple measurements with magnitude variations > 0.1. Note that -- this runs very slowly without the "TOP 100", so please see the Optimizing queries -- section of the SQL help page to learn how to speed up this query. | |
SELECT TOP 100 | |
| -- select object IDs of star and its pair |
FROM Neighbors as N | -- the neighbor record |
| -- the primary star |
| -- the second observation of the star |
| |
| |
WHERE | |
| -- distance is 0.5 arc second or less |
| -- observations are two different runs |
| -- S2 is indeed a star |
| -- S1 magnitudes are reasonable |
| |
| |
| |
| |
| -- S2 magnitudes are reasonable. |
| |
| |
| |
| |
| -- and one of the colors is different. |
| |
| |
| |
| |
| |
| |
|
-- Select white dwarf candidates, returning the necessary photometric parameters, -- proper motion, spectroscopic information, and the distance to the nearest neighbor -- brighter than g=21. (From Jeff Munn) | |
SELECT
FROM ( ) AS o LEFT OUTER JOIN ( ) AS nbor ON o.objID = nbor.objID |
-- Here is a query to get object IDs and field MJDs (Modified Julian Dates) for quasars with secondary -- matches. (From Jordan Raddick) SELECT top 100 FROM PhotoTag AS p WHERE ORDER BY p.modelmag_g |
-- Some more useful quasar queries (from Sebastian Jester). -- Getting magnitudes for spectroscopic quasars - retrieves BEST photometry. -- This query introduces the SpecPhoto view of the SpecPhotoAll table, which is a pre-computed join -- of the important fields in the SpecObjAll and PhotoObjAll tables. It is very convenient and much -- faster to use this when you can instead of doing the join yourself. SELECT ra,dec,psfmag_i-extinction_i AS mag_i,psfmag_r-extinction_r AS mag_r,z FROM SpecPhoto WHERE zconf > 0.35 -- Getting TARGET photometry for spectra SELECT sp.ra,sp.dec,sp.z, FROM specphoto AS sp INNER JOIN TARGDR2..photoprimary AS p ON sp.targetobjid = p.objid WHERE sp.zconf > 0.35 -- Getting FIRST data for spectroscopic quasars - returns only those quasars that match SELECT sp.ra,sp.dec,sp.z, FROM SpecPhoto AS sp WHERE sp.zconf > 0.35 -- Surface density of quasar targets and FIRST matches to them on a field-by-field basis -- restricted to some part of the sky. SELECT f.run,f.rerun,f.camcol,f.field,ra_avg,dec_avg, FROM ( ) AS f INNER JOIN ( ) AS p ON f.fieldid = p.fieldid ORDER BY ra_avg,dec_avg |
-- This query from Sebastian Jester demonstrates the use of the LEFT OUTER JOIN -- construct in order to include even rows that do not meet the JOIN condition. The -- query also gets the sky brighness and turns it into a flux, which illustrates the use of -- the POWER() function and CAST to change the string representation into floating -- point. The First table contains matches between SDSS and FIRST survey objects. select fld.run, fld.avg_sky_muJy, fld.runarea as area, isnull(fp.nfirstmatch,0) from ( --first part: for each run, get total area and average sky brightness ) as fld left outer join ( -- second part: for each run,get total number of FIRST matches. To get the run number -- for each FIRST match, need to join FIRST with PHOTOPRIMARY. Some runs may have -- 0 FIRST matches, so these runs will not appear in the result set of this subquery. -- But we want to keep all runs from the first query in the final result, hence -- we need a LEFT OUTER JOIN between the first and the second query. -- The LEFT OUTER JOIN returns all the rows from the first subquery and matches -- with the corresponding rows from the second query. Where the second query -- has no corresponding row, a NULL is returned. The ISNULL() function in the -- SELECT above converts this NULL into a 0 to say "0 FIRST matches in this run". ) as fp on fld.run=fp.run order by fld.run |
-- This query from Gordon Richards demonstrates the use of multiple OUTER JOINs -- It does take a few hours to run, hence the TOP 10 is added if you want to try it. SELECT TOP 10 FROM BESTDR3..SpecObjAll AS p WITH (index(0)) WHERE ( |
-- A query from Tomo Goto that looks for several spec lines at once. | |
SELECT TOP 100 | |
FROM SpecPhoto AS S | -- S is the spectra of galaxy G |
-- L is a line of S | |
-- L2 is a line of S | |
-- L_OII is a line of S | |
-- L_Hd is a line of S | |
WHERE | |
-- L is the H alpha line | |
-- L2 is the H beta line | |
-- L_OII is the O-II line | |
-- L_Hd is the H delta line | |
-- A query from Jon Loveday to count galaxies in the North.
-- Galaxy number counts for northern Galactic hemisphere, ie. stripe < 50. -- -- 262158 is the sum of the SATURATED, BLENDED, BRIGHT and EDGE flags, -- obtained with the query: -- -- SELECT top 1 (dbo.fPhotoFlags('SATURATED') -- + dbo.fPhotoFlags('BLENDED') -- + dbo.fPhotoFlags('BRIGHT') -- + dbo.fPhotoFlags('EDGE')) from PhotoTag SELECT cast(2*(g.petroMag_r - g.extinction_r + 0.25) as int)/2.0 as r, 2*count(*) as N FROM galaxy g WHERE GROUP BY cast(2*(g.petroMag_r - g.extinction_r + 0.25) as int)/2.0 ORDER BY cast(2*(g.petroMag_r - g.extinction_r + 0.25) as int)/2.0 |
-- List the number of each type of object observed by each -- special program. SELECT plate.programname, dbo.fSpecClassN(specClass) AS Class, FROM SpecObjAll WHERE plate.programtype > 0 GROUP BY plate.programname, specClass ORDER BY plate.programname, specClass |
-- A query to list the primary and special plates that have objects in common -- Returns the pairs of special and primary plates, the total number of nights -- on which the objects they have in common have been observed, the progam to -- which the special plate belongs, and the number of objects the plates -- have in common. SELECT first.plate, other.plate, FROM SpecObjAll first WHERE first.scienceprimary = 1 AND other.scienceprimary = 0 GROUP BY first.plate, other.plate, otherPlate.programname ORDER BY nightsObserved DESC, otherPlate.programname, |
-- A query to list the spec IDs and classifications of the primary -- targets of a special program, in this case fstar51. -- -- Note that the flag may be different for other special programs SELECT specObjId, dbo.fSpecClassN(specClass) AS Class FROM SpecObjAll WHERE plate.programName LIKE 'fstar51' AND |
-- Find redshifts and types of all galaxies -- in the lowz special program with z < 0.01 SELECT specObjID, z, zErr, zConf, dbo.fSpecClassN(specClass) FROM SpecObjAll WHERE plate.programName LIKE 'lowz%' AND specClass = 2 AND z < 0.01 |
-- Compare different redshift measurements of the same object for objects
-- with high redshift SELECT prim.bestObjId, prim.mjd AS PrimMJD, prim.plate AS PrimPlate, FROM SpecObjAll prim WHERE other.bestObjId > 0 ORDER BY prim.bestObjId |
-- There are several built-in functions available to CAS users that make spatial
-- queries, i.e., those with coordinate cuts, much more efficient than simply -- including the coordinate constraints in the WHERE clause. Some examples: -- 1) Rectangular search using straight coordinate constraints: SELECT objID, ra, dec FROM PhotoObj AS WHERE (ra between 179.5 and 182.3) and (dec between -1.0 and 1.8) -- This query can be rewritten as follows to use the HTM function that returns a -- rectangular search area: SELECT p.objID, p.ra, p.dec FROM SpecObjAll p, dbo.fGetObjFromRectEq(179.5, -1.0, 182.3, 1.8) r WHERE p.objID = r.objID -- 2) Radial search for objects near a given position (cone search): SELECT objid, ra, dec FROM PhotoTag p, dbo.fGetNearbyObjEq(179.5, -0.5, 2.0) n WHERE p.objID = n.objID |
-- Determine area of sky targeted by v3_1_0 or later of the target selection algorithm -- Note that the "min" just happens to work, it is not robust to changes in the min value. -- (from Gordon Richards). This query also contains examples of setting the output -- precision of columns with STR. select sum(area) FROM Region where regionid in ( ) -- Extract all quasars and quasar candidates from that area SELECT FROM Target AS t WHERE ( ) ORDER by p.ra |
-- A query to search for merging galaxy pairs, as per the prescription in
-- Allam et al. 2004. -- (from Jordan Raddick and Ani Thakar). -- Note: this query takes more than an hour to run without a top <n> or count(*). select count(*) /* g1.objid as g1_id, g1.ra as g1_ra, g1.dec as g1_dec, g1.modelmag_u as g1_u, g1.modelmag_g as g1_g, g1.modelmag_r as g1_r, g1.modelmag_i as g1_i, g1.modelmag_z as g1_z, g2.objid as g2_id, g2.ra as g2_ra, g2.dec as g2_dec, g2.modelmag_u as g2_u, g2.modelmag_g as g2_g, g2.modelmag_r as g2_r, g2.modelmag_i as g2_i, g2.modelmag_z as g2_z, g1.petroR50_r as g1_radius, g2.petroR50_r as g2_radius, n.distance as separation */ FROM Galaxyg1 JOIN Neighbors n on g1.objID = N.objID JOIN Galaxy g2 on g2.objID = N.NeighborObjID where g1.objId < g2.ObjID and N.NeighborType = 3 and g1.petrorad_u > 0 and g2.petrorad_u > 0 and g1.petrorad_g > 0 and g2.petrorad_g > 0 and g1.petrorad_r > 0 and g2.petrorad_r > 0 and g1.petrorad_i > 0 and g2.petrorad_i > 0 and g1.petrorad_z > 0 and g2.petrorad_z > 0 and g1.petroradErr_g > 0 and g2.petroradErr_g > 0 and g1.petroMag_g BETWEEN 16 and 21 and g2.petroMag_g BETWEEN 16 and 21 and g1.modelmag_u > -9999 and g1.modelmag_g > -9999 and g1.modelmag_r > -9999 and g1.modelmag_i > -9999 and g1.modelmag_z > -9999 and g2.modelmag_u > -9999 and g2.modelmag_g > -9999 and g2.modelmag_r > -9999 and g2.modelmag_i > -9999 and g2.modelmag_z > -9999 and abs(g1.modelmag_g - g2.modelmag_g) > 3 and (g1.petroR50_r BETWEEN 0.25*g2.petroR50_r AND 4.0*g2.petroR50_r) and (g2.petroR50_r BETWEEN 0.25*g1.petroR50_r AND 4.0*g1.petroR50_r) and (n.distance <= (g1.petroR50_r + g2.petroR50_r)) |
-- Verify that ubercalibration was done on photometric data -- and obtain standard and ubercalibrated r band model magnitudes. select top 10 u.modelMag_r as urmag,p.modelMag_r as prmag from SpecObjAll p where p.objID=u.objID AND |
-- Select red stars (spectral type K) that are bright (g0 < 17), with -- large CaII triplet eq widths, with low errors on the CaII triplet eq -- widths. select sp.plate,sp.mjd,sp.fiberid,sp.g0,sp.gmr0, FROM sppLines AS sl where |
-- Select low metallicity stars ([Fe/H] < -3.5) which have relatively -- small error bars on the abundance (err < 0.5 dex) and which are brighter -- than 19th mag (dereddened) and where more than three different measures -- of feh are ok and are averaged. select sp.plate,sp.mjd,sp.fiberid,sp.g0,sp.gmr0, FROM sppLines AS sl where |
-- The following query can be used to find the completeness (in percent) of the -- spectroscopic survey by region. | |
SELECT | |
FROM Target AS t | |
WHERE | |
GROUP BY r.regionid | |
-- This query uses the new SQL Server 2005 CROSS APPLY and OUTER APPLY -- constructs to apply a table-valued function to the results of a query. -- In this example, we use the fFootPrintEq function which returns a list -- of SDSS regions that intersect the area specified by the RA, dec and -- radius, or NULL if the area is outside the SDSS footprint. -- For each point in the input list, in this case the result of a query -- on PhotoObj, return "yes" or "no" depending on whether the point is in -- the SDSS footprint or not, along with any other needed columns. SELECT top 100 objID, ra, dec, FROM PhotoObj AS p WHERE (ra BETWEEN 179.5 AND 182.3) AND (dec BETWEEN -1.0 AND 1.8) |
-- The flag fields in the SpecObjAll table are 64-bit, but some analysis tools -- (and FITS format) only accept 32-bit integers. Here is a way to split them -- up, using bitmasks to extract the higher and lower 32 bits, and dividing by -- a power of 2 to shift bits to the right (since there is no bit shift operator -- in SQL. The hexadecimal version can be used for debugging to make sure -- you are splitting them up right. | ||
SELECT TOP 10 objid,ra,dec, | ||
-- output the whole bigint as a check | ||
-- get the lower 32 bits with a mask | ||
FROM SpecObjAll | ||
-- Hexadecimal version of above query - use for debugging. | ||
SELECT TOP 10 objid,ra,dec, | ||
FROM SpecObjAll | ||
-- Several sample queries on searching for variable objects with the Match tables.
-- (from Robert Lupton and Zeljko Ivezic). Zeljko put together a number of queries about variable objects. I've implemented them in SQL and appended my solutions to this message; I could do all except three; one (query8) because I couldn't think of a solution, and two because some of the fields in the matchHead tables are not set. I do NOT guarantee that these are optimal; in fact I don't quite guarantee that they are even correct. They are significantly complicated by three problems: 0. SQL doesn't include any operators to calculate order statistics such as medians 1. The match tables only give the matches. This means that they include all except one of the observations of a given object. I have a workaround in the queries, but maybe we should add the self-match rows too? I've flagged them as distance == -1" 2. The matchHead tables do not guarantee that the objId of the head is a PRIMARY. This is a problem when using some of the the functions that return matches, as some (but not all) only return primaries. For example, fGetNearbyObjEq() does but fGetObjFromRect() doesn't, I think that the best solution would be to make all such dbo.functions return all objects -- it's easy to say e.g. (select objId from dbo.fGetObjFromRect(ra1, ra2, dec1, dec2) where mode = @primaryMode) as N 3. The issues with matchHead.missCount; but this is a separate issue (which is why I said three problems, not four). R -- N.b. This is designed to be used with my emacs interface; other users -- may have to evaluate the set statements for @variables, and -- substitute them by hand. /* The crucial table for variability is the MATCH table: PhotoObj pairs from different runs (times) that probably are the same object. SDSS primary and secondary objects of type STAR, GALAXY, and UNKNOWN within 1 arcsec of one another and from different runs (so two different observations) Table also holds type, mode and distance information. See also MatchHead Table. name |unit |description --------------------------------------------------------------------------- objID1 | | The unique objId of the center object mode1 | | is object primary,secondary,family | | outside type1 | | Object type of the start object objID2 | | The objId of the matching object mode2 | | is neighbor primary,secondary,family or | | outside type2 | | Object type of the matching object distance | arcmin | Distance between center and neighbor --------------------------------------------------------------------------- */ -- Note: the following variable declarations can be used in CasJobs or -- the emacs interface, but not in SkyServer. If you are running the -- queries in SkyServer, you will need to replace the variables with -- their actual values. declare @r numeric set @r = select 1/60.0 -- search radius, arcmin declare @ra numeric set @ra = 217.924624 -- a QSO declare @dec numeric set @dec = -1.2251894 declare @box numeric set @box = 0.1 declare @ra1 numeric set @ra1 = select @ra - @box/2.0 declare @dec1 numeric set @dec1 = select @dec - @box/2.0 declare @ra2 numeric set @ra2 = select @ra + @box/2.0 declare @dec2 numeric set @dec2 = select @dec + @box/2.0 declare @bad_flags bigint set @bad_flags = (dbo.fPhotoFlags('SATURATED') | dbo.fPhotoFlags('BRIGHT') | dbo.fPhotoFlags('EDGE') | dbo.fPhotoFlags('PSF_FLUX_INTERP')) declare @star int set @star = dbo.fPhotoType('star') declare @galaxy int set @galaxy = dbo.fPhotoType('galaxy') declare @primaryMode int set @primaryMode = dbo.fPhotoMode('primary') -- query1 -- 1) Return all detections within R arcsec from a position given -- by (RA,Dec). Motivation: light curve for a given object -- -- I assume that R is small enough to lie within the match table radius, -- so I can first find the object, then use the match table to get the -- light curve -- select dbo.fSDSS(obj.objId) as ID, ltrim(str(60*distance, 12, 2)) as distance, -- arcsec ltrim(str(mjd_r,20,2)) as MJD, modelMag_g, modelMagErr_g, modelMag_r, modelMagErr_r, modelMag_i, modelMagErr_i from ( select objId1, objId2, -1/60. as distance FROM match union all select objId1, objId2, distance FROM match ) as M JOIN PhotoObj as Obj on (obj.objId = M.objId2) JOIN Field as F on F.fieldId = obj.fieldId where M.ObjId1 = dbo.fGetNearestObjIdEq(@ra, @dec, @r) /* Notes: The basic query is: select dbo.fSDSS(obj.objId) as ID from match as M join PhotoObj as Obj on (obj.objId = M.objId2) where M.objId1 = dbo.fGetNearestObjIdEq(@ra, @dec, @r) This is simple enough; find the object nearest to @ra, @dec, look it up in the match table, and then show us all of its matches. There's a problem with this approach, namely that it doesn't include the matched object itself, only its matches. The solution to this is to use not MATCH but a home-brewed temporary table (what's the proper word for these?) that includes an entry with the objid2 equal to the objID. We should probably fix the database to do this for us. With this change, the query becomes: select dbo.fSDSS(obj.objId) as ID from ( select objId1, objId2, -1/60. as distance FROM match union all select objId1, objId2, distance FROM match ) as M join PhotoObj as Obj on (obj.objId = M.objId2) where M.objId1 = dbo.fGetNearestObjIdEq(@ra, @dec, @r) and the query given above is merely an elaboration of this approach. */ -------------------------------------------------------------------------- -- query2 -- 2) Return all detections within a rectangle specified by equatorial -- or galactic coordinates; index all unique sources, provide the -- total number of detections for each source, index detections -- according to time (run number). Motivation: doing light curves -- for a large number of sources -- -- I assume that R is small enough to lie within the match table radius, -- so I can first find the object, then use the match table to get the -- light curve -- -- query2a select dbo.fSDSS(M.objId1) as UID, -- These are the unique object IDs dbo.fSDSS(obj.objId) as ID, ltrim(str(60*distance, 12, 2)) as distance, -- arcsec ltrim(str(mjd_r,20,2)) as MJD, psfMag_r, psfMagErr_r, dbo.fPhotoTypeN(type) as type from ( select objId1, objId2, -1/60. as distance FROM match union all select objId1, objId2, distance FROM match ) as M JOIN PhotoObj as Obj on (obj.objId = M.objId2) join (select objId from dbo.fGetObjFromRect(@ra1,@ra2,@dec1,@dec2) where mode = @primaryMode) as N on (M.objId1 = N.objId1) JOIN Field as F on (F.fieldId = obj.fieldId) where 0 = (flags & @bad_flags) order by M.objId1 /* Without the selection on PRIMARY mode we'd double count matches */ -- query2b /* Here's another way to do the same thing, using the matchHead table. Here the UID is the entry in the matchHead, and is in not in general a primary. This approach won't work using table-valued functions that only return primaries, such as fGetNearbyObjEq(), as not all the entries in matchHead are primaries */ select dbo.fSDSS(MH.objId1) as UID, -- These are the unique object IDs dbo.fSDSS(obj.objId) as ID, ltrim(str(60*distance, 12, 2)) as distance, -- arcsec ltrim(str(mjd_r,20,2)) as MJD, psfMag_r, psfMagErr_r, dbo.fPhotoTypeN(obj.type) as type from matchHead as MH join ( select objId1, objId2, -1/60. as distance FROM match union all select objId1, objId2, distance FROM match ) as M on (M.objId1 = MH.objID1) JOIN PhotoObj as Obj on (obj.objId = M.objId2) JOIN Field as F on (F.fieldId = obj.fieldId) where MH.objId1 in (select objId from dbo.fGetObjFromRect(@ra1,@ra2,@dec1,@dec2)) and 0 = (flags & @bad_flags) order by MH.objId1 -- query3 -- query3a -- 3) Return all objects with difference between the brightest and -- faintest state (in a given band, or any band), or between -- one of the extreme states and the mean/median value, larger/smaller -- than X mag. Motivation: objects with impeccable photometry, -- eclipsing binaries, outbursts, etc. -- -- I'll ask for the min value to differ from the mean by more than 0.1, -- and add another constraint that the mean magnitude be brighter than -- some limit. Only search a small region, and only consider stars -- The extra "select * from" is there so that I can use the calculated -- quantities in a "where" clause. select * from ( select dbo.fSDSS(min(M.objId1)) as UID, -- These are the unique object IDs count(*) as n, min(obj.psfMag_r) as psfMagMin_r, avg(obj.psfMag_u) as psfMag_u, avg(obj.psfMag_g) as psfMag_g, avg(obj.psfMag_r) as psfMag_r, avg(obj.psfMag_i) as psfMag_i, avg(obj.psfMag_z) as psfMag_z, avg(obj.psfMagErr_r)/sqrt(count(*)) as psfMagErr_r, avg(obj.psfMag_r) - min(obj.psfMag_r) as psfDelta_r from ( select objId1, type1, objId2, -1/60. as distance FROM match union all select objId1, type1, objId2, distance FROM match ) as M join PhotoObj as Obj on (obj.objId = M.objId2) where M.objId1 in (select objId from dbo.fGetObjFromRect(@ra1,@ra2,@dec1,@dec2) where mode = @primaryMode) and 0 = (flags & @bad_flags) and psfMagErr_r >= 0 and M.type = @star group by M.objId1 ) as RESULT where psfMag_r < 20 and psfMag_r - psfMagMin_r > 0.05 order by psfMag_r - psfMagMin_r desc -- query3b /* * And here's the same query using a median. As Jim Gray says, * "The median SHOULD be in SQL but it isn't"; this causes real pain. * * The pain is made worse as correlated subqueries are only allowed with * a scalar value, and the natural way to write the median query uses a * table value; I circumvent this by generating an table with medians, * and joining it back. */ select * from ( select dbo.fSDSS(M.objId1) as UID, -- These are the unique object IDs count(*) as n, min(obj.psfMag_r) as psfMagMin_r, avg(obj.psfMag_r) as psfMag_r, avg(obj.psfMagErr_r)/sqrt(count(*)) as psfMagErr_r, min(psfMagMed_r) as psfMagMed_r, min(psfMagMed_r) - min(obj.psfMag_r) as psfDelta_r ,dbo.fGetUrlNavId(M.objId) as URL from ( select objId1, type1, objId2, -1/60. as distance FROM match union all select objId1, type1, objId2, distance FROM match ) as M join PhotoObj as Obj on (obj.objId = M.objId2) join ( select M50.objId1, (select cast(min(psfMag_r) as float) -- the median, assuming n is odd from ( select top 50 percent psfMag_r FROM PhotoObj AS iobj where iobj.objId in (select M50.objId1 union select objId2 FROM match AS MM where M50.objId1=MM.objId1) and 0 = (iobj.flags & @bad_flags) order by psfMag_r desc ) as top50 ) as psfMagMed_r from match as M50 ) as med on med.objId1 = M.objId1 where M.objId1 in (select objId from dbo.fGetObjFromRect(@ra1,@ra2,@dec1,@dec2) where mode = @primaryMode) and 0 = (flags & @bad_flags) and M.type = @star group by M.objId1 ) as RESULT -- /* where psfMagMed_r < 20 and psfMagMed_r - psfMagMin_r > 0.05 -- */ order by psfMag_r - psfMagMin_r desc -- query4 -- 4) Return all objects with rms in a given band greater/smaller -- than X mag. Motivation: a part of classic variability search -- -- I'll ask for the rms to be less than 0.02, and only -- search a small region. -- select * from ( select dbo.fSDSS(M.objId1) as UID, -- These are the unique object IDs count(*) as n, avg(psfMag_r) as psfMag_r, stdevp(psfMag_r) as rms_r, -- Not in ANSI SQL 92 avg(psfMagErr_r) as psfMagErr_r from ( select objId1, objId2, -1/60. as distance FROM match union all select objId1, objId2, distance FROM match ) as M join PhotoObj as Obj on (obj.objId = M.objId2) where M.objId1 in (select objId from dbo.fGetObjFromRect(@ra1,@ra2,@dec1,@dec2) where mode = @primaryMode) and 0 = (flags & @bad_flags) and psfMag_r < 20 group by M.objId1 ) as RESULT where rms_r > 0.05 -- n.b. psfMagErr^2 isn't subtracted order by rms_r desc -- query5 -- query5a -- 5) Return all objects with chi2 in a given band greater/smaller -- than Y. Motivation: a part of classic variability search -- -- I'll only search a small region. -- select * from ( select dbo.fSDSS(UID) as UID, avg(ra) as ra, avg(dec) as dec, avg(mean.psfMag_r) as psfMag_r, count(*) as n, sum(square((obj.psfMag_r - mean.psfMag_r)/obj.psfMagErr_r))/count(*) as rchi2_psfMag_r from ( select iM.objId1 as UID, -- These are the unique object IDs avg(psfMag_r) as psfMag_r from ( select objId1, type1, objId2, -1/60. as distance FROM match union all select objId1, type1, objId2, distance FROM match ) as iM join PhotoObj as iobj on (iobj.objId = iM.objId2) where iM.objId1 in (select objId from dbo.fGetObjFromRect(@ra1,@ra2,@dec1,@dec2) where mode = @primaryMode) and iM.type1 = @star and 0 = (iobj.flags & @bad_flags) group by iM.objId ) as mean join ( select objId1, objId2, -1/60. as distance FROM matchwhere mode1 = @primaryMode union select objId1, objid2, distance FROM matchwhere mode1 = @primaryMode ) as M on mean.UID = M.objId1 join PhotoObj as Obj on (obj.objId = M.objId2) where 0 = (flags & @bad_flags) group by UID ) as RESULT where psfMag_r < 20 and n > 1 and rchi2_psfMag_r > 2 -- query5b -- -- This query doesn't work: -- Cannot perform an aggregate function on an expression containing an -- aggregate or a subquery -- select dbo.fSDSS(min(M.objId1)) as UID, count(*) as n, sum(square((obj.psfMag_r - avg(psfMag_r))/obj.psfMagErr_r))/count(*) as rchi2_psfMag_r from ( select distinct objId1, objId2, -1/60. as distance FROM match union select objId1, objid2, distance FROM match ) as M join PhotoObj as Obj on (obj.objId = M.objid2) where M.objId1 in (select objId from dbo.fGetObjFromRect(@ra1,@ra2,@dec1,@dec2)) and 0 = (flags & @bad_flags) group by M.objId1 -- query6 -- 6) Return all objects with (max-min) in a given band greater/smaller -- than k*rms. Motivation: another way to look for variables (using -- a different light curve statistic) -- -- I'll only search a small region. -- select * from ( select dbo.fSDSS(M.objID1) as UID, avg(ra) as ra, avg(dec) as dec, avg(psfMag_r) as psfMagMean_r, min(psfMag_r) as psfMagMin_r, max(psfMag_r) as psfMagMax_r, -- Two alternative estimates of "RMS"; from the data, or -- from the quoted errors. -- stdevp(psfMag_r) as psfMagRMS_r, -- Not in ANSI SQL 92 sqrt(sum(power(psfMagErr_r, 2))/count(*)) as psfMagRMS_r, count(*) as n from ( select objId1, type1, objId2, -1/60. as distance FROM match union all select objId1, type1, objId2, distance FROM match ) as M join PhotoObj as Obj on (obj.objId = M.objId2) where M.objId1 in (select objId from dbo.fGetObjFromRect(@ra1,@ra2,@dec1,@dec2) where mode = @primaryMode) and M.type1 = @star and 0 = (flags & @bad_flags) group by M.objId1 ) as RESULT where (psfMagMax_r - psfMagMin_r) > 2.5*psfMagRMS_r and psfMagMean_r < 22 order by psfMagMean_r -- query7 -- 7) Return all objects with (q75-q50) in a given band greater/smaller -- than k*(q50-q25), where qN are quartiles. Motivation: another -- way to look for variables (using a different light curve statistic) -- N.b. match.objId are not unique, so without both "select distinct" -- and "union" (not "union all") while looking for percentiles we'll -- get double counting. select * from ( select dbo.fSDSS(M.objId1) as UID, -- These are the unique object IDs count(*) as n, min(obj.psfMag_r) as psfMagMin_r, avg(obj.psfMag_r) as psfMag_r, avg(obj.psfMagErr_r)/sqrt(count(*)) as psfMagErr_r, min(psfMagQ25_r) as psfMagQ25_r, min(psfMagQ50_r) as psfMagQ50_r, min(psfMagQ75_r) as psfMagQ75_r, min(psfMagQ75_r) - min(psfMagQ25_r) as psfIQR_r -- ,dbo.fGetUrlNavId(M.objId) as URL from ( select objId1, type1, objId2, -1/60. as distance FROM match union all select objId1, type1, objId2, distance FROM match ) as M join PhotoObj as Obj on (obj.objId = M.objId2) join ( select distinct M25.objId1, ( select cast(min(psfMag_r) as float) -- Q75 from ( select top 75 percent -- not 25% psfMag_r FROM PhotoObj AS iobj where iobj.objId in (select M25.objId1 union select objId2 FROM match AS MM where M25.objId1=MM.objId1) and 0 = (iobj.flags & @bad_flags) order by psfMag_r desc -- magnitudes! ) as top25 ) as psfMagQ25_r from match as M25 ) as Q25 on Q25.objId1 = M.objId1 join ( select distinct M50.objId1, ( select cast(min(psfMag_r) as float) -- Q50 from ( select top 50 percent psfMag_r FROM PhotoObj AS iobj where iobj.objId in (select M50.objId union select matchObjId FROM match AS MM where M50.objId=MM.objId) and 0 = (iobj.flags & @bad_flags) order by psfMag_r desc -- magnitudes! ) as top50 ) as psfMagQ50_r from match as M50 ) as Q50 on Q50.objId1 = M.objId1 join ( select distinct M75.objId1, ( select cast(min(psfMag_r) as float) -- Q25 from ( select top 25 percent -- not 75% psfMag_r FROM PhotoObj as iobj where iobj.objId in (select M75.objId1 union select objId2 FROM match AS MM where M75.objId1=MM.objId2) and 0 = (iobj.flags & @bad_flags) order by psfMag_r desc -- magnitudes! ) as top75 ) as psfMagQ75_r from match as M75 ) as Q75 on Q75.objId = M.objId where M.objId1 in (select objId from dbo.fGetObjFromRect(@ra1,@ra2,@dec1,@dec2) where mode = @primaryMode) and 0 = (flags & @bad_flags) and M.type = @star group by M.objId1 ) as RESULT -- /* where psfMagQ50_r < 21 and (psfMagQ75_r - psfMagQ50_r) > 0.0*(psfMagQ50_r - psfMagQ25_r) -- */ order by psfMag_r - psfMagMin_r desc -- query8 -- 8) Return all objects with at least one brightness derivative -- (m2-m1)/(t2-t1) in a given band greater than X mag. Motivation: -- another way to look for variables (e.g. Mira variables have huge -- light curve amplitudes, but never a large time derivatives; RR Lyrae -- on the other hand have much smaller light curve amplitudes, but much -- larger time derivatives). -- -- RHL can't think of a way to do this one. Ideas anyone? -- -- query9 -- 9) Return all objects that at least once were not detected (that is, -- their position was observed at least twice, and at least once -- there was no detection). Motivation: photo problems, eclipsing -- binaries -- -- We can't do this (yet) as matchHead.missCount isn't set; -- well, not without understanding the HTM. The outline of -- a possible query is given below. -- -- Even then we won't do a great job with the current schema; I think -- that we'd do better to include some sort of place-holder for these -- missing objects in the match tables. -- select dbo.fSDSS(MH.objId1) as UID, -- These are the unique object IDs dbo.fSDSS(obj.objId) as ID, ltrim(str(60*distance, 12, 2)) as distance, -- arcsec ltrim(str(mjd_r,20,2)) as MJD, psfMag_r, psfMagErr_r, dbo.fPhotoTypeN(obj.type) as type from matchHead as MH join ( select objId1, objId2, -1/60. as distance FROM match union all select objId1, objId2, distance FROM match ) as M on (M.objId1 = MH.objID) JOIN PhotoObj as Obj on (obj.objId = M.objId2) JOIN Field as F on (F.fieldId = obj.fieldId) where MH.objId1 in (select objId from dbo.fGetObjFromRect(@ra1,@ra2,@dec1,@dec2)) and MH.missCount > 0 and 0 = (flags & @bad_flags) and psfMag_r < 20 order by MH.objId1 -- query10 -- 10) Return all objects that were detected only m times (or only within -- T1 days), while their position was observed at least N times -- (m < N ), or longer than T2 days (T1 < T2). -- Motivation: afterglows, microlensing, SNe -- -- Need matchHead.missCount. -- -- query11 -- 11) Like 10, but object must be an unresolved child, and must have -- at least one resolved sibling. Motivation: SNe in nearby galaxies -- -- Need matchHead.missCount -- -- query12 -- 12) Return all resolved objects whose rms for model magnitude in -- a given band is smaller than X mag, while rms for psf magnitude -- is larger than Y mag. Motivation: finding nearby galaxies with AGN -- by nuclear variability -- -- This won't work, as the psf mag of an extended object depends -- on the seeing. But the query can be written. -- -- I'll only search a small region, and correct the RMS errors for -- the measured errors -- select * from ( select dbo.fSDSS(M.objID1) as UID, --avg(ra) as ra, avg(dec) as dec, count(*) as n, -- avg(psfMag_r) as psfMagMean_r, stdevp(psfMag_r) as psfMagRMS_r, -- Not in ANSI SQL 92 sqrt(sum(power(psfMagErr_r, 2))/count(*)) as psfMagErr_r, -- avg(modelMag_r) as modelMagMean_r, stdevp(modelMag_r) as modelMagRMS_r, -- Not in ANSI SQL 92 sqrt(sum(power(modelMagErr_r, 2))/count(*)) as modelMagErr_r from ( select objId1, type1, objId2, -1/60. as distance FROM match union all select objId1, type1, objId2, distance FROM match ) as M JOIN PhotoObj as Obj on (obj.objId = M.objId2) where M.objId1 in (select objId from dbo.fGetObjFromRect(@ra1,@ra2,@dec1,@dec2) where mode = @primaryMode) and M.type = @galaxy and 0 = (flags & @bad_flags) group by M.objId1 ) as RESULT where modelMagMean_r < 22 and (square(modelMagRMS_r) - square(modelMagErr_r)) < square(0.02) and (square(psfMagRMS_r) - square(psfMagErr_r)) > square(0.2) order by modelMagMean_r |