<resource schema="gdr2dist">
	<meta name="creationDate">2018-08-28T12:21:37Z</meta>
	<meta name="schema-rank">1000</meta>

	<meta name="title">Estimated distances to 1.33 billion stars
		in Gaia DR2</meta>
	<meta name="description" format="rst">
		This catalogue provides distances estimates (and uncertainties therein)
		for 1.33 billion stars over the whole sky brighter than about G=20.7.
		These have been estimated using the parallaxes (and their uncertainties)
		from Gaia DR2. A Bayesian procedure was used involving a prior
		with a single parameter L(l,b), which varies smoothly with Galactic
		longitude and latitude according to a Galaxy model. The posterior is
		summarized with a point estimate (usually the mode) and a confidence
		interval (usually the 68% highest density interval).  The estimation
		procedure is described in detail in the `accompanying paper`_,
		which also analyses the catalogue content.

		.. _accompanying paper: http://www.mpia.de/homes/calj/gdr2_distances.html
	</meta>

	<meta name="subject">milky-way-galaxy</meta>
	<meta name="subject">stellar-distance</meta>
	<meta name="subject">surveys</meta>
	<meta name="subject">stars</meta>

	<meta name="creator">Bailer-Jones, C.A.L.;  Rybizki, J.; Fouesneau, M.;
		Mantelet, G.;  Andrae, R.</meta>
	<meta name="instrument">Gaia</meta>

	<meta name="source">2018AJ....156...58B</meta>
	<meta name="contentLevel">Research</meta>
	<meta name="type">Catalog</meta>  <!-- or Archive, Survey, Simulation -->

	<table id="main" onDisk="True" adql="True">
		<primary>source_id</primary>
		<index columns="r_est"/>

		<column original="gaia/q2#dr2light.source_id"/>
		<column name="r_est"
			unit="pc" ucd="pos.distance"
			tablehead="Dist"
			description="Estimated distance"
			verbLevel="1"/>
		<column name="r_lo"
			unit="pc" ucd="pos.distance;stat.min"
			tablehead="Min. Dist."
			description="Lower bound on the 1 σ confidence interval"
			verbLevel="5"/>
		<column name="r_hi"
			unit="pc" ucd="pos.distance;stat.max"
			tablehead="Max. Dist."
			description="Upper bound on the 1 σ confidence interval"
			verbLevel="5"/>
		<column name="r_len"
			unit="pc" ucd="stat.fit.param;pos.distance"
			tablehead="Prior scale"
			description="Length scale used in the prior for the distance estimation."
			verbLevel="15"/>
		<column name="result_flag" type="smallint" required="True"
			ucd="meta.code.qual"
			tablehead="Res. Code"
			description="Type of result." 			
			verbLevel="15"
			note="rc"/>
		<column name="modality_flag" type="smallint" required="True"
			ucd="meta.code"
			tablehead="#modes"
			description="Result regime flag: number of modes in
			the posterior (1 or 2)."
			verbLevel="25"/>

		<meta name="note" tag="rc">
			result_flag has three possible values:
				
				:0:
					failed estimate (r_est, r_lo, r_hi are all NaN)
				:1:
					_est is the mode (highest if the posterior is bimodal); r_lo/r_hi
					define the lower/upper limits of the highest density interval (HDI)
					containing 68% of the posterior probability
				:2:
					r_est is the median; r_lo/r_hi define the lower/upper limits of the
					equal-tailed interval (ETI), containing 68% of the posterior
					probability."
				
			99.9% of the rows have result_code=1.
		</meta>
	</table>

	<coverage>
		<spatial>0/0-11</spatial>
	</coverage>

	<data id="import">
		<sources pattern="data/data.txt.gz"/>
		<directGrammar id="booster" cBooster="res/boosterfunc.c"
			type="split" autoNull="\N" preFilter="zcat" splitChar="\t"/>
		<make table="main"/>
	</data>

	<table id="distpos" onDisk="True">
		<LOOP listItems="source_id r_est r_lo r_hi r_len result_flag
				modality_flag">
			<events>
				<column original="main.\item"/>
			</events>
		</LOOP>
		<LOOP listItems="ra dec">
			<events>
				<column original="gaia/q2#dr2light.\item"/>
			</events>
		</LOOP>

		<FEED source="//procs#declare-indexes-from"
			sourceTables="main gaia/q2#dr2light"/>
		<viewStatement>
			CREATE VIEW \curtable AS (SELECT \colNames FROM
				\schema.main
				JOIN gaia.dr2light USING (source_id))
		</viewStatement>
	</table>

	<data id="make_view">
		<make table="distpos"/>
	</data>

	<service id="cone" allowed="form,scs.xml">
		<meta name="shortName">gdr2dist scs</meta>
		<meta name="testQuery">
			<meta name="ra">314.128371381898</meta>
			<meta name="dec">7.33858542846851</meta>
			<meta name="sr">0.0001</meta>
		</meta>

		<publish render="scs.xml" sets="ivo_managed"/>
		<publish render="form" sets="local,ivo_managed"/>

		<scsCore queriedTable="distpos">
			<FEED source="//scs#coreDescs"/>
		</scsCore>
	</service>

	<regSuite title="gdr2dist regression">
		<regTest title="gdr2dist SCS serves some data">
			<url RA="314.118"
					DEC="7.334" SR="0.003"
				>cone/scs.xml</url>
			<code>
				self.assertHasStrings(
					"a 25-bit plus 7 bit sequence",
					"Lower bound on the 1 σ")
				row = self.getFirstVOTableRow()
				self.assertAlmostEqual(row["r_est"], 1261.07604980)
				self.assertEqual(row["source_id"], '1737527443345452544')
			</code>
		</regTest>
	</regSuite>
</resource>
