<?xml version="1.0" encoding="utf-8"?>


<!-- Fields description adapted from Vizier -->

<resource resdir="2mass" schema="twomass">

	<meta name="creationDate">2008-01-15T15:23:00Z</meta>
	<meta name="schema-rank">50</meta>
	<meta name="title">The 2MASS point source catalog</meta>
	<meta name="description">The 2MASS Point Source Catalogue,
		short a couple of exotic fields.
		We provide this data mainly for matching with other catalogs
		within our TAP service.
	</meta>

	<meta name="subject">stars</meta>
	<meta name="subject">surveys</meta>
	<meta name="subject">astrometry</meta>

	<meta name="content.type">Catalog</meta>

	<meta name="coverage">
		<meta name="waveband">Infrared</meta>
	</meta>

	<coverage>
		<spatial>0/0-11</spatial>
		<spectral>8.33e-20 1.863e-19</spectral>
		<temporal>1997-06-07 2001-02-16</temporal>
	</coverage>

	<table id="data" onDisk="true" adql="True" primary="mainid"
		mixin="//scs#q3cindex">
		<mixin>//scs#pgs-pos-index</mixin>
		<index columns="Hmag"/>
		<index columns="Jmag"/>
		<index columns="Kmag"/>
		<index columns="pts_key"/>

		<stc>
			Position ICRS Epoch J2000.0 "RAJ2000" "DEJ2000"
		</stc>

		<publish sets="dci,ivo_managed,local"/>
			<column name="RAJ2000" unit="deg" tablehead="RA (J2000)"
				description="Right ascension (J2000)"
				ucd="pos.eq.ra;meta.main" type="double precision" verbLevel="1"/>
			<column name="DEJ2000" unit="deg" description="Declination (J2000)"
				ucd="pos.eq.dec;meta.main" type="double precision"
				tablehead="DEC (J2000)" verbLevel="1"/>
			<column name="errMaj" unit="deg" tablehead="Err(pos)_major"
				description="Major axis of position error ellipse"
				ucd="stat.error;pos.eq" verbLevel="15"/>
			<column name="errMin" unit="deg" tablehead="Err(pos)_minor"
				description="Minor axis of position error ellipse"
				ucd="stat.error;pos.eq" verbLevel="15"/>
			<column name="errPA" unit="deg" tablehead="PA(err. ellipse)"
				description="Position angle of error ellipse major axis (E of N)"
				ucd="stat.error;pos.eq" verbLevel="15"/>
			<column name="mainid" tablehead="Cat. Id"
				description="Source designation" ucd="meta.id;meta.main"
				type="text" verbLevel="1"/>
			<column name="Jmag" unit="mag" tablehead="m_J"
				description="2MASS J magnitude" ucd="phot.mag;em.IR.J"
				verbLevel="15">
				<property name="statisticsTarget">10000</property>
			</column>
			<column name="Jcmsig" unit="mag"
				description="J default magnitude uncertainty"
				tablehead="Err'(m_J)"
				ucd="stat.error;phot.mag;em.IR.J"/>
			<column name="e_Jmag" unit="mag"
				tablehead="Err(m_J)"
				description="2MASS J total magnitude uncertainty"
				ucd="stat.error;phot.mag;em.IR.J" verbLevel="20"/>
			<column name="Jsnr" description="J Signal-to-noise ratio"
				ucd="stat.snr;phot.mag;em.IR.J" tablehead="SNR(J)"/>
			<column name="Hmag" unit="mag" tablehead="m_H"
				description="2MASS H magnitude" ucd="phot.mag;em.IR.H"
				verbLevel="15">
				<property name="statisticsTarget">10000</property>
			</column>
			<column name="Hcmsig" unit="mag" tablehead="Err'(m_H)"
				description="H default magnitude uncertainty"
				ucd="stat.error;phot.mag;em.IR.H"/>
			<column name="e_Hmag" unit="mag"  tablehead="Err(m_H)"
				description="2MASS H total magnitude uncertainty"
				ucd="stat.error;phot.mag;em.IR.H" verbLevel="25"/>
			<column name="Hsnr"
				description="H Signal-to-noise ratio" tablehead="SNR(H)"
					ucd="stat.snr;phot.mag;em.IR.H"/>
			<column name="Kmag" unit="mag" tablehead="m_K"
				description="2MASS K_s magnitude" ucd="phot.mag;em.IR.K"
				verbLevel="15">
				<property name="statisticsTarget">10000</property>
			</column>
			<column name="Kcmsig" unit="mag" tablehead="Err'(m_K)"
				description="magnitude uncertainty"
				ucd="stat.error;phot.mag;em.IR.K"/>
			<column name="e_Kmag" unit="mag" tablehead="Err(m_K)"
				description="2MASS K_s total magnitude uncertainty"
				ucd="stat.error;phot.mag;em.IR.K" verbLevel="25"/>
			<column name="Ksnr" description="K Signal-to-noise ratio"
				ucd="stat.snr;phot.mag;em.IR.K" tablehead="SNR(K)"/>
			<column name="Qflg" type="char(3)"
				ucd="meta.code.qual;phot"
				tablehead="Phot. quality"
				description="JHK photometric quality flag"
				verbLevel="25" note="q"/>
			<column name="Rflg" type="char(3)"
				ucd="meta.ref"
				tablehead="Qual. source"
				description="JHK default magnitude read flag"
				verbLevel="25" note="r"/>
			<column name="Bflg" type="char(3)"
				ucd="meta.code"
				tablehead="blend flag"
				description="JHK blend flag"
				verbLevel="25" note="b"/>
			<column name="Cflg" type="char(3)"
				ucd="meta.code"
				tablehead="confusion contamination"
				description="Contamination and confusion flag"
				verbLevel="25" note="c"/>
<!--	<column name="Ndet"
				description="Number of aperture measurements (jjhhkk)"
				ucd="meta.number" type="char(6)" tablehead="#measurements"/>
			<column name="prox" unit="deg"
				description="Distance between source and nearest neighbour"
				ucd="pos.angDistance"/>
			<column name="pxPA" unit="deg" description="
				Position angle of vector from source to nearest neighbour (E of N)"
				ucd="pos.posAng"/>
			<column name="pxCntr"
				description="Sequence number of nearest neighbour"
				ucd="meta.number" type="bigint"/>
-->
			<column name="Xflg" description="Extended source contamination"
				ucd="meta.code" type="char" tablehead="ext. src contamination">
				<values nullLiteral=" "/>
			</column>
			<column name="Aflg" description="Association with asteroid or comet"
				ucd="meta.code" type="char" tablehead="solar system flag">
				<values nullLiteral=" "/>
			</column>
		<column name="pts_key" type="bigint" required="True"
			ucd="meta.id;meta.table"
			tablehead="key"
			description="Unique source identifier in catalogue" note="p"/>

<!--	<column name="Hemis" description="Hemisphere of observation"
				ucd="obs.param;obs" type=char"/>
-->
			<column name="quoted/date" unit="yr" description="Observation date"
				ucd="time.epoch;obs" type="date" tablehead="Obs. date"/>
			<column name="Scan" description="Scan number (within date)"
				required="True"
				ucd="meta.id;obs.field" type="smallint" tablehead="Scan number"/>
<!--	<column name="GLON" unit="deg" description="Galactic longitude"
				ucd="pos.galactic.lon" type="double precision"/>
			<column name="GLAT" unit="deg" description="Galactic latitude"
				ucd="pos.galactic.lat" type="double precision"/>
-->
			<column name="Xscan" unit="deg" tablehead="d(plate center)"
				description="Distance of source from focal plane centerline"
				ucd="pos.distance;pos.cartesian;instr.det"/>
			<column name="JD" unit="d" type="timestamp"
				description="Julian date of detection" ucd="time.epoch"
				tablehead="JD" verbLevel="1"/>
<!--	<column name="Jpsfchi"
				description="J band reduced chi2 value of fit"
				ucd="stat.fit.chi2;stat.value"/>
			<column name="Hpsfchi"
				description="H band reduced chi2 value of fit"
				ucd="stat.fit.chi2;stat.value"/>
			<column name="Kpsfchi" description="K band reduced chi2 value of fit"
				ucd="stat.fit.chi2;stat.value"/>
			<column name="Jstdap" unit="mag"
				description="J standard aperture magnitude" ucd="phot.mag;em.IR.J"/>
			<column name="e_Jstdap" unit="mag" description="error on Jstdap
				ucd="stat.error"/>
			<column name="Hstdap" unit="mag"
				description="H standard aperture magnitude" ucd="phot.mag;em.IR.H"/>
			<column name="e_Hstdap" unit="mag" description="error on Hstdap"
				ucd="stat.error"/>
			<column name="Kstdap" unit="mag"
				description="K standard aperture magnitude" ucd="phot.mag;em.IR.K"/>
			<column name="e_Kstdap" unit="mag"
				description="error on Kstdap" ucd="stat.error"/>
-->
			<column name="edgeNS" unit="deg" description=
				"Distance from the source to the nearest North or South scan edge"
				ucd="pos;arith.diff" tablehead="d(NS edge)"/>
			<column name="edgeEW" unit="deg" description=
				"Distance from the source to the nearest East or West scan edge"
				ucd="pos;arith.diff" tablehead="d(EW edge)"/>
			<column name="edge" description=
				"flag indicating to which edges the edgeNS and edgeEW values refer"
				ucd="meta.code;pos.cartesian;instr.det" type="char(2)" tablehead="Edge flag"/>
			<column name="dup" description="Flag indicating duplicate source"
				ucd="meta.code" type="char" tablehead="Duplicity">
				<values nullLiteral=" "/>
			</column>
			<column name="use_src" description="Use source flag" ucd="meta.code"
				type="char" tablehead="Use" verbLevel="25">
				<values nullLiteral=" "/>
			</column>
<!--	<column name="opt" description="Associated optical source"
				ucd="meta.id;meta.dataset" type="char"/>
			<column name="Dopt" unit="deg"
				description="Distance to associated optical source"
				ucd="pos.angDistance"/>
			<column name="PAopt" unit="deg" description=
				"position angle from optical source to the 2MASS source position"
				ucd="pos.posAng"/>
			<column name="Bmag" unit="mag"
				description="Blue magnitude of associated optical source"
				ucd="phot.mag;em.opt.B"/>
			<column name="Rmag" unit="mag"
			description="Visual or red mag of associated optical source"
			ucd="phot.mag;em.opt.R"/>
			<column name="Nopt"
				description="Number of optical sources within 5arcsec"
				ucd="meta.number" type="smallint"/>
			<column name="extKey"
				description="Record Identifier in XSC" ucd="meta.id.cross"
				type="int"/>
			<column name="scanKey"
				description="Record Identifier in the Scan Information Table"
				ucd="meta.id" type="int"/>
			<column name="coaddKey"
				description="Record Identifier in the Atlas Image Data Table"
				ucd="meta.id;meta.dataset" type="int"/>
			<column name="coadd"
				description="Sequence number of the Atlas Image" ucd="meta.number"
				type="int"/>
-->

		<meta name="note" tag="p">
			pts_key is called cntr in the IRSA/GATOR version of 2MASS. This
			sequential number was defined when source records from final data
			processing were loaded into the Point Source Working Database.
			
			Pts_key is incremented in order (or reverse order depending on
			the scan direction) of declination within a scan. For
			this reason, on average sources with close pts_key values are
			close to each other on the sky, except at Tile boundaries.
			
			Pts_key ordering thus provides a useful mapping of the 2MASS
			release on storage media. PSC sources are cross-referenced in the
			XSC, Known Asteroid Detection List, Known Comet Detection List,
			and Planet and Planetary Satellite Detection
			List via the value of pts_key.
		</meta>

		<meta name="note" tag="q"><![CDATA[
			qflag is the photometric quality flag (upstream ph_qual). Three character
			flag, one character per band [JHKs], that provides a summary of the net
			quality of the default photometry in each band, as derived from the Read
			Flag (rflg), measurement uncertainties ([jhk]_cmsig), scan
			signal-to-noise ratios ([jhk]_snr), frame-detection statistics (ndet),
			and profile-fit reduced chi-squared values ([jhk]_psfchi). The value for
			qflag is set for a band according to the precedence of the table below.
			For example, a source that is tested and meets the conditions for
			category "X" is not tested for subsequent qualities.

			"X"
				There is a detection at this location, but no valid brightness estimate
				can be extracted using any algorithm. rflg="9" and default magnitude
				is null.
			"U"
				Upper limit on magnitude. Source is not detected in this band
				(rflg="0"), or it is detected, but not resolved in a consistent
				fashion with other bands (rflg="6"). A value of qflag="U" does not
				necessarily mean that there is no flux detected in this band at the
				location. Whether or not flux has been detected can be determined from
				the value of rflg. When rflag="0", no flux has been detected. When
				rflg="6", flux has been detected at the location where the images
				were not deblended consistently in all three bands (JHKs).
			"F"
				This category includes rflg="1" or rflag="3" sources where a
				reliable estimate of the photometric error, [jhk]_cmsig, could not be
				determined. The uncertainties reported for these sources in [jhk]_cmsig
				and [jhk]_msigcom are flags and have numeric values >8.0.
			"E"
				This category includes detections where the goodness-of-fit quality of
				the profile-fit photometry was very poor (rflg=2 and
				[jhk]psf_chi>10.0), or detections where psf fit photometry did not
				converge and an aperture magnitude is reported (rflg=4), or
				detections where the number of frames was too small in relation to the
				number of frames in which a detection was geometrically possible
				(rflg="1" or rflag="2").
			"A"
				Detections in any brightness regime where valid measurements were made
				(rflg="1","2" or "3") with [jhk]\\_snr>10 AND [jhk]\\_cmsig<0.10857.
			"B"
				Detections in any brightness regime where valid measurements were made
				(rflg="1","2" or "3") with [jhk]\\_snr>7 AND [jhk]\\_cmsig<0.15510.
			"C"
				Detections in any brightness regime where valid measurements were made
				(rflg="1","2" or "3") with [jhk]_snr>5 AND [jhk]_cmsig<0.21714.
			"D"
				Detections in any brightness regime where valid measurements were made
				(rflg="1","2" or "3") with no [jhk]_snr or [jhk]_cmsig requirement.
		]]></meta>

		<meta name="note" tag="r"><![CDATA[
			rflg is upstream's Read flag (rd_flg). It is a three character flag,
			one character per band [JHKs], that indicates the origin of the default
			magnitudes and uncertainties in each band (j_m,h_m,k_m, j_cmsig, h_cmsig,
			k_cmsig). rflg values of "1", "2" or "3" generally indicate the best
			quality detections, photometry and astrometry (although other quality
			flags must be considered). Values of "0", "4", "6" and "9" in a band
			indicate either non-detections, or generally poor quality photometry and
			positions. The definitions of the rflg values are:

			"0"
				Source is not detected in this band. The default magnitude is the 95%
				confidence upper limit derived from a 4" radius aperture measurement
				taken at the position of the source on the Atlas Image. The sky
				background is estimated in an annular region with inner radius of 14"
				and outer radius of 20".
			"1"
				The default magnitude is derived from aperture photometry measurements
				on the 51 ms "Read_1" exposures. The aperture radius is 4", with the
				sky background measured in an annulus with an inner radius of 14" and
				an outer radius of 20". Used for sources that saturate one or more of
				the 1.3s "Read_2" exposures, but are not saturated on at least one of
				the 51 ms "Read_1" frames.
			"2"
				The default magnitude is derived from a profile-fitting measurement
				made on the 1.3 sec "Read_2" exposures. The profile-fit magnitudes are
				normalized to curve-of-growth-corrected aperture magnitudes. This is
				the most common type in the PSC, and is used for sources that have no
				saturated pixels in any of the 1.3 sec exposures.
			"3"
				The default magnitude is derived from a 1-d radial profile fitting
				measurement made on the 51 ms "Read_1" exposures. Used for very bright
				sources that saturate all of the 51 ms "Read 1" exposures.
			"4"
				The default magnitude is derived from curve-of-growth-corrected 4"
				radius aperture photometry measurements on the 1.3 s "Read_2"
				exposures. This is used for sources that are not saturated in any of
				the Read_2 frames, but where the profile-fitting measurements fail to
				converge to a solution. These magnitudes are the same as the standard
				aperture magnitudes (j_m_stdap, h_m_stdap, k_m_stdap), but when they
				are the default magnitudes, it generally implies that they are low
				quality measurements.
			"6"
				The default magnitude is the 95% confidence upper limit derived from a
				4" radius aperture measurement taken at the position of the source on
				the Atlas Image. The sky background is estimated in an annular region
				with inner radius of 14" and outer radius of 20". This is used for
				pairs of sources which are detected and resolved in another band, but
				are detected and not resolved in this band. This differs from a
				rflg="0" because in this case there is a detection of the source in
				this band, but it is not consistently resolved across all bands.
			"9"
				The default magnitude is the 95% confidence upper limit derived from a
				4" radius aperture measurement taken at the position of the source on
				the Atlas Image. The sky background is estimated in an annular region
				with inner radius of 14" and outer radius of 20". This is used for
				sources that were nominally detected in this band, but which could not
				have a useful brightness measurement from either profile fitting or
				aperture photometry. This often occurs in highly confused regions, or
				very near Tile edges where a significant fraction of the measurement
				aperture of sky annulus falls off the focal plane.
		]]></meta>

		<meta name="note" tag="b"><![CDATA[
			Blend flag (upstream's bl_flg). This is a three character flag, one
			character per band [JHKs], that indicates the number of components that
			were fit simultaneously when estimating the brightness of a source:

			"0"
				Source is not detected, or is inconsistently deblended in that band.
			"1"
				One component was fit to the source in R_2 profile-fitting photometry
				(rd_flg="2"), or default magnitudes are from aperture photometry
				(rd_flg="1" or "4") or saturated star 1-d radial profile-fitting
				(rd_flg="3").
			">1"
				More than one component was fit simultaneously during R2 profile-fit
				photometry, where the value of the field is the number of components
				simultaneously fit. The maximum number of components is 7 in any band
				for the PSC, so this bflg is always a three character flag.
				Multi-component fitting occurs only for profile-fitting, and only when
				more than one detection is found within ~5". Single detections that are
				not well-fit by a single PSF are not split.
		]]></meta>

		<meta name="note" tag="c"><![CDATA[
			Contamination and confusion flag (upstream: cc_flg). This is a three
			character flag, one character per band [JHKs], that indicates that the
			photometry and/or position measurements of a source may be contaminated
			or biased due to proximity to an image artifact or nearby source of equal
			or greater brightness. The cflg in each band is set in hierarchical
			order according to the following table, in the event a source is affected
			by more than one artifact or condition:

			"p"
				Persistence. Source may be contaminated by a latent image left by a
				nearby bright star.
			"c"
				Photometric Confusion. Source photometry is biased by a nearby star
				that has contaminated the background estimation. This is very common in
				high source density regions.
			"d"
				Diffraction spike confusion. Source may be contaminated by a
				diffraction spike from a nearby star.
			"s"
				Electronic stripe. Source measurement may be contaminated by a stripe
				from a nearby bright star.
			"b"
				Bandmerge confusion. In the process of merging detections in the
				different bands for this source, there was more than one possible match
				between the different band components. This occurs in regions of very
				high source density, or when multiple sources were split in one band
				but not another.
			"0"
				Source is unaffected by known artifacts, or is not detected in the band.

			Non-zero values the cflg in any band is an indicator that the measurements of that source may be contaminated.
		]]></meta>
	</table>

	<data id="import" auto="false">
		<sources pattern="data/psc*.gz"/>
		<directGrammar cBooster="res/boosterfunc.c" gzippedInput="True"
			autoNull="\N"/>
		<make table="data"/>
	</data>

	<scsCore queriedTable="data" id="baseQuery" namePath="data">
		<condDesc original="//scs#humanInput"/>
		<condDesc original="//scs#protoInput"/>
		<condDesc buildFrom="Jmag"/>
		<condDesc buildFrom="Hmag"/>
		<condDesc buildFrom="Kmag"/>
	</scsCore>

	<service id="q" core="baseQuery" allowed="form,scs.xml">
		<meta name="shortName">twomass_q</meta>
		<meta name="title">2Mass Query</meta>
		<publish render="scs.xml" sets="ivo_managed"/>

		<meta name="testQuery">
			<meta name="ra">127.567785</meta>
			<meta name="dec">1.526871</meta>
			<meta name="sr">0.001</meta>
		</meta>

		<outputTable namePath="data">
			<column original="_r"/>
			<column original="mainid"/>
			<column original="RAJ2000" displayHint="type=hms"/>
			<column original="DEJ2000" displayHint="type=dms"/>
			<column original="Jmag"/>
			<column original="Hmag"/>
			<column original="Kmag"/>
		</outputTable>
	</service>
</resource>
