<resource schema="gdr2mock">
	<meta name="title">A Gaia DR2 mock stellar catalog</meta>
	<meta name="description">
		This catalogue is a simulation of the
		Gaia DR2 stellar content using Galaxia (a tool to sample stars from a
		Besancon-like Milky Way model), 3d dust extinction maps and the latest
		PARSEC Isochrones. It is mimicking the Gaia DR2 data model
		and an apparent magnitude limit of g=20,7.  Extinctions and photometry
		in different bands have also been included in a supplementary table as
		well as uncertainty estimates using a scaled nominal error model.
	</meta>
	<meta name="creationDate">2018-03-13T13:08:00</meta>
	<meta name="schema-rank">1000</meta>
	<meta name="doi">10.21938/SYx.JVejuu66uzDiLcfRlA</meta>
	<meta name="referenceURL">\internallink{/tableinfo/gdr2mock.main}</meta>

	<meta name="subject">astrostatistics-techniques</meta>
	<meta name="subject">milky-way-galaxy</meta>
	<meta name="subject">astronomical-simulations</meta>

	<meta name="creator">Rybizki, J.; Demleitner, M.; Fouesneau, M.;
		Bailer-Jones, C.; Rix, H.-W.; Andrae, R.</meta>
	
	<FEED source="//procs#license-cc0" what="the Gaia DR2 mock catalogue"/>

	<meta name="_news" author="MD" date="2018-07-24" format="rst">
		Added a column phot_rvs_mean_mag based on the approximations
		given in  :bibcode:`2018A&amp;A...616A...1G`.  This is going to be severely off
		outside of 0.1&lt;BP-G&lt;1.7; the column is also not included
		in the dumps.
	</meta>

	<meta name="_news" author="MD" date="2018-05-17">
		Two of the dump files were truncated due to overflows; also, some
		stars beyond DR1's top source_id were missing in the dump.  If
		you have downloaded the dump before today, please re-download
		dump-059114520-059124586.fits, dump-058933326-058943392.fits, and
		dump-100507267-100663295.fits.
	</meta>

	<meta name="_news" author="JR" date="2018-04-25" format="rst"
		>The catalog was revised and several spurious previsously unextincted
		OB and TP-AGB stars were removed (see the arXiv manuscript for details).
		In consequence, the number of sources has decreased by about 0.5%.

		The uncertainties in BP flux were truncated for uncertainties higher
		than 100 mag in BP (they are replaced by NULL. These
		high values come from the nominal error model for single-transits
		and are probably too pessimistic.  In short: Do not use bp fluxes
		if the errors are NULL.
		
		Also, made available a dump of the (non-null) rows of gdr2mock.main.
	</meta>

	<meta name="source">2018PASP..130g4101R</meta>
	<meta name="contentLevel">Research</meta>
	<meta name="type">Simulation</meta>

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

	<STREAM id="apsispars">
		<doc>An internal stream to build the three-parameter sets for the
			priam/FLAME-determined stuff.</doc>
		<column name="\name\+_val"
			unit="\unit" ucd="\ucd"
			tablehead="\tablehead"
			description="Estimate of \description from Apsis-\prog"/>
		<column name="\name\+_percentile_lower"
			unit="\unit" ucd="\ucd;stat.min"
			tablehead="\tablehead low"
			description="Lower uncertainty bound of \description estimate
				from Apsis-\prog.  This is the 16th percentile of its PDF."/>
		<column name="\name\+_percentile_upper"
			unit="\unit" ucd="\ucd;stat.max"
			tablehead="\tablehead high"
			description="Upper uncertainty bound of \description estimate
				from Apsis-\prog.  This is the 84th percentile of its PDF."/>
	</STREAM>


	<STREAM id="extcols">
		<column name="index_parsec" type="integer" required="True"
			ucd="meta.id;meta.main"
			tablehead="Bin"
			description="The parsec bin has the format
				AABBCCCDDD, where AA denotes the metallicity bin, BB the
				luminosity bin, CCC the T_eff bin, and DDD the extinction bin."/>

		<LOOP>
			<csvItems>
				bandName, bandLabel, descLabel, ucd
				BP,       bp, Gaia BP,      opt.B
				RP,       rp, Gaia RP,      opt.R
				U,        ju, Johnson U,    opt.U
				B,        jb, Johnson B,    opt.B
				V,        jv, Johnson V,    opt.V
				R,        jr, Johnson R,    opt.R
				I,        ji, Johnson I,    opt.I
				J,        jj, Johnson J,    ir.J
				H,        jh, Johnson H,    ir.H
				K,        jk, Johnson K,    ir.K
				u,        su, SDSS u,       opt.U
				g,        sg, SDSS g,       opt.V
				r,        sr, SDSS r,       opt.R
				i,        si, SDSS i,       opt.I
				z,        sz, SDSS z,       opt.I
			</csvItems>
			<events>
				<column name="a_\bandLabel"
					unit="mag" ucd="phys.absorption;em.\ucd"
					tablehead="A_\bandName"
					description="Extinction in the \descLabel band"/>
			</events>
		</LOOP>
	</STREAM>

	<table id="raw_exts" onDisk="True" adql="Hidden" primary="index_parsec">
		<meta name="description">
			Extinctions for Gaia DR2 mock photometry.  This is joined into
			the parsec_phot view.
		</meta>
		<column name="index_noext" type="integer" required="True"
			ucd="meta.ref"
			tablehead="Phot. Ref."
			description="A reference to dereddened photometry.  This is
				built like index_parsec, except that DDD is always zero.  It is
				used to reference the raw_phot table and should not be user-visible."/>	
		<FEED source="extcols"/>
	</table>

	<data id="import_raw_exts" recreateAfter="make_photometry_view">
		<sources pattern="data/parsec_extinctions_lookup.fits"/>
		<directGrammar id="extbooster" cBooster="res/extbooster.c" type="fits">
			<mapKeys>
					a_bp: A_BP,
					a_rp: A_RP,
					a_ju: A_U,
					a_jb: A_B,
					a_jv: A_V,
					a_jr: A_R,
					a_ji: A_I,
					a_jj: A_J,
					a_jh: A_H,
					a_jk: A_K,
					a_su: A_u,
					a_sg: A_g,
					a_sr: A_r,
					a_si: A_i,
					a_sz: A_z,
					index_parsec: index_parsec
			</mapKeys>
			<!-- edit the generated source to add

				MAKE_INT(fi_index_noext, index_parsec-index_parsec%1000);-->
		</directGrammar>
		<make table="raw_exts"/>
	</data>


	<STREAM id="photcols">
		<LOOP>
			<csvItems>
				bandName, bandLabel, descLabel, ucd
				G,        gaia_g,    Gaia G,    opt.V
				U,        ubv_u,     Johnson U, opt.U
				B,        ubv_b,     Johnson B, opt.B
				V,        ubv_v,     Johnson V, opt.V
				R,        ubv_r,     Johnson R, opt.R
				I,        ubv_i,     Johnson I, opt.I
				J,        ubv_j,     Johnson J, ir.J
				H,        ubv_h,     Johnson H, ir.H
				K,        ubv_k,     Johnson K, ir.K
				u,        sdss_u,    SDSS u, opt.U
				g,        sdss_g,    SDSS g, opt.V
				r,        sdss_r,    SDSS r, opt.R
				i,        sdss_i,    SDSS i, opt.I
				z,        sdss_z,    SDSS z, opt.I
				J,        2mass_j,   2MASS J, ir.J
				H,        2mass_h,   2MASS H, ir.H
				K',       2mass_ks,  2MASS K', ir.K
				W1,       wise_w1,   WISE W1, ir.3-4um
				W2,       wise_w2,   WISE W2, ir.4-8um
				W3,       wise_w3,   WISE W3, ir.8-15um
				W4,       wise_w4,   WISE W4, ir.15-30um
			</csvItems>
			<events>
				<column name="mag_\bandLabel"
					unit="mag" ucd="phot.mag;em.\ucd"
					tablehead="Mag. \bandName"
					description="Simulated absolute magnitude in the \descLabel band (note that
						no extinction is applied)."/>
			</events>
		</LOOP>
	</STREAM>


	<table id="raw_phot" onDisk="True" adql="Hidden" primary="index_noext">
		<meta name="description">
			Absolute magnitude for Gaia DR2 mock in various photometric bands.
			This is joined with the raw_extinctions to give the gdr2mock.photometry.
		</meta>
		<column name="index_noext" type="bigint" required="True"
			ucd="meta.id;meta.main"
			tablehead="Bin"
			description="The index of the model bin; this has the format
				AABBCCC000, where AA gives the metallicity bin, BB gives the
				luminosity bin, and CCC the T_eff bin This is referenced from
				index_noext in raw_exts."/>
		<FEED source="photcols"/>
	</table>

	<data id="import_phot" recreateAfter="make_photometry_view">
		<sources pattern="data/parsec_photometry_lookup.fits"/>
		<fitsTableGrammar/>
		<make table="raw_phot">
			<rowmaker>
				<simplemaps>
					mag_gaia_g: gaia_g,
					mag_ubv_u: ubv_u,
					mag_ubv_b: ubv_b,
					mag_ubv_v: ubv_v,
					mag_ubv_r: ubv_r,
					mag_ubv_i: ubv_i,
					mag_ubv_j: ubv_j,
					mag_ubv_h: ubv_h,
					mag_ubv_k: ubv_g,
					mag_sdss_u: sdss_u,
					mag_sdss_g: sdss_g,
					mag_sdss_r: sdss_r,
					mag_sdss_i: sdss_i,
					mag_sdss_z: sdss_z,
					mag_2mass_j: 2mass_j,
					mag_2mass_h: 2mass_h,
					mag_2mass_ks: 2mass_ks,
					mag_wise_w1: wise_w1,
					mag_wise_w2: wise_w2,
					mag_wise_w3: wise_w3,
					mag_wise_w4: wise_w4,
					index_noext: index_parsec
				</simplemaps>
			</rowmaker>
		</make>
	</data>

	<table id="photometry" onDisk="True" adql="True">
		<meta name="title">Photometry for the Gaia DR2 mock catalog</meta>
		<meta name="description">This table contains simulated
			absolute magnitudes to about 0.1 mag precision for all the stars,
			as well as extinctions in several bands; To use it, join it USING (parsec_index) with the
			\schema.main table.
			</meta>
		<FEED source="photcols"/>
		<FEED source="extcols"/>

		<viewStatement>
			CREATE VIEW \curtable AS
				(SELECT \colNames FROM
					\schema.raw_exts JOIN \schema.raw_phot USING (index_noext))
		</viewStatement>
	</table>

	<table onDisk="True" id="generated_data" adql="hidden" mixin="//scs#q3cindex"
			primary="source_id">
		<meta name="description">This contains the data actually generated.
			Users probably want to use the gdr2mock.main table that
			(fairly well) follows the Gaia DR2 data model.
		</meta>
		<LOOP>
			<csvItems>
				name, type, unit, description, tablehead
				teff, real, K, effective Temperature, Teff
				feh, real, , log of metallicity in solar units ('dex'), [Fe/H]
				a0, real, mag, monochramatic Extinction at lambda=547.7nm, A_0
				lum, real, solLum, Stellar luminosity, Luminosity
				glon, double precision, deg, Galactic longitude, l
				glat, double precision, deg, Galactic latitude, b
				mass, real, solMass, initial mass in solar masses, Mass
				age, real, Gyr, Age of the star, Age
				logg,   real, log(cm/(s**2)), Surface gravity of star, log(g)
				gaia_g,    real, mag, apparent G mag including extinction, G
				gaia_g_bp, real, mag, apparent BP mag including extinction, BP
				gaia_g_rp, real, mag, apparent RP mag including extinction, RP
				sig_g,     real, mag, error in G, error_G
				sig_bp,    real, mag, error in BP, error_BP
				sig_rp,    real, mag, error in RP, error_RP
				A_G,       real, mag, Extinction in G, A_G
				parallax,  real, mas, parallax in mas, parallax
				radial_velocity, real, km/s, Radial velocity in km/s, V_rad
				pm_ra, 	   real, mas/yr, Proper motion in projection of right ascension, pm_alpha
				pm_dec,    real, mas/yr, Proper motion in declination, pm_delta
				ebp_rp,    real, mag, reddening in BP-RP, E(BP-RP)
				parallax_error, real, mas, parallax uncertainty in mas, error_parallax
			</csvItems>
			<events>
				<column name="\name" type="\type"
				unit="\unit"
				tablehead="\tablehead"
					description="\description"/>
			</events>
		</LOOP>
		<index columns="gaia_g_bp"/>
		<index columns="gaia_g_rp"/>
		<index columns="gaia_g"/>
		<index columns="pm_ra"/>
		<index columns="pm_dec"/>
		<index columns="random_index"/>
		<index columns="parallax"/>
		<index name="q3c_gdr2mock_galacitc">
			<columns>glon, glat</columns>
			q3c_ang2ipix(glon, glat)
		</index>

		<column name="source_id" type="bigint" required="True"
			ucd="meta.id;meta.main"
			tablehead="ID"
			description="Healpix number using Nside = 4096 with the nested scheme
				on equatorial coordinates times 2^35. The last digits
				of the source_id are reserved for a running number that serves as a
				unique identifier per HEALPix cell. This is formed in accordance with
				Gaia's source_id definition, but of course mock objects have no
				relation to any Gaia objects that may have an identical source_id."/>
		<column name="ra" type="double precision"
			unit="deg" ucd="pos.eq.ra;meta.main"
			tablehead="RA (ICRS)"			
			description="Barycentric Right Ascension in ICRS at ref_epoch "/>
		<column name="dec" type="double precision"
			unit="deg" ucd="pos.eq.dec;meta.main"
			tablehead="Dec (ICRS)"			
			description="Barycentric Declination in ICRS at ref_epoch "/>
		<column name="index_parsec" type="integer" required="True"
			tablehead="Phot." ucd="meta.id.cross"
			description="Foreign key into the photometry/extinction table."/>
		<column name="random_index" type="integer" required="True"
			tablehead="Random"			
			description="Random index that can be used to deterministically select subsets "/>
		<column name="beta_index" type="smallint" required="True"
			tablehead="beta"
			description="Index by |sin(beta)| in order to apply astrometric performance table"/>
	</table>

	<data id="import_raw" recreateAfter="import">
		<sources pattern="data/mwG*.fits"/>
		<directGrammar type="fits" id="booster" cBooster="res/boosterfunc.c">
			<mapKeys>
				ebp_rp: EBP-RP
			</mapKeys>
		</directGrammar>
		<make table="generated_data"/>
	</data>

	<table id="main" onDisk="True" adql="True">
		<meta name="description">A synthetic Milky Way catalog mimicking
			GDR2 in stellar content and data model.</meta>

		<meta name="_longdoc" format="rst"><![CDATA[
			Query Validator
			'''''''''''''''
			
			A web form for validating queries against the Gaia DR2 data model
			without actually submitting them is available at
			http://gaia.ari.uni-heidelberg.de/adql-validator.html
			Note, however, that this machine supports many valuable ADQL 1.1
			extensions that that validator does not know about.

			Associate Photometry
			''''''''''''''''''''

			To add simulated multi-band photometry, join \schema.main with
			\RSTtable{\schema.photometry} ``USING (index_parsec)``.

			Nominal error model
			'''''''''''''''''''

			The nominal error model for the astrometry is way too optimistic for
			stars with an apparent G magnitude smaller than 12. For stars in this
			range a factor of approximately five needs to be added to the reported
			values. For details refer to https://doi.org/10.1051/0004-6361/201832727.
			For the photometry the nominal error model seems to be too conservative
			and the GDR2 photometry seems to be more precise
			(cf. https://doi.org/10.1051/0004-6361/201832756).

			Coping with the table size
			''''''''''''''''''''''''''

			\schema.main is a large table.  A sequential scan of it will take
			about an hour on a machine not otherwise loaded.  Therefore, only
			do queries on the whole table with tested queries that actually yield
			what you expect them to yield.  For development, please restrict
			yourself to reasonably sized-subsets.  The recommended pattern is to
			use common table expressions (CTEs) like this::

				WITH sample AS (
					SELECT * FROM gdr2mock.main
					WHERE distance(ra, dec, 66.73, 75.87)<2)
				SELECT ra, dec, 1/parallax
				FROM sample
				WHERE age BETWEEN 0.2 and 0.3
			
			When extending this kind of query to the whole sky (or other regions),
			all you need to do is edit the statement after WITH.

			Note that CTEs are not yet available on all TAP services.  On services
			that do not have them, you can substitute them with
			`subqueries <http://docs.g-vo.org/adql/html/page014.html>`_ in many
			situations.

			Preferred form of spatial constraints
			'''''''''''''''''''''''''''''''''''''

			Please note that the standard (and fast) pattern for spatial
			selections is cone-like; you can equivalently write::

				WHERE distance(ra, dec, 66.73, 75.87)<2

			or::

				WHERE 1=CONTAINS(
					POINT(ra, dec),
					CIRCLE(66.73, 75.87, 2))

			Both assume ADQL 2.1; in ADQL 2.0 (which still runs on the major Gaia
			services in early 2018; this form also runs on ADQL 2.1), it's::

				WHERE 1=CONTAINS(
					POINT('', ra, dec),
					CIRCLE('', 66.73, 75.87, 2))


			*Do not* use “rectangular” selection ("ra between 1 and 2" or "ra<=2 and
			ra>=1") – this will be slow and may introduce all kinds of weird effects
			depending on the coordinate frame.

			Chunking the catalog
			''''''''''''''''''''

			In some situations, you want to exhaustively partition the catalog.
			To do that, use the ``source_id`` column, which has a healpix number in
			the upper 29 bits.  The following partition will yield chunks of no more
			than 10 million objects and was used to produce the `dump of the
			catalog`_::

				limits = [0, 164291313590476000L, 191269676664280480L,
					207871746248160160L, 248685167308531040L, 271513012986365600L,
					345530573214495872L, 411247098650686208L, 431307932731207552L,
					458978048704340352L, 474888365388891648L, 510167763254636032L,
					523311068341874048L, 539913137925753728L, 674113200395447936L,
					936287549240881152L, 1060803071119978752L, 1276629975710414592L,
					1473087799119657216L, 1738720912461732096L, 1791985885710012928L,
					1810663213991877376L, 1820347754582473984L, 1823806519079115520L,
					1826573530676428800L, 1832107553871055360L, 1843175600260308480L,
					1860469422743516416L, 1869462210434784768L, 1920651924985080320L,
					1961465346045451264L, 1974608651132689408L, 1990518967817240832L,
					2005737531602463744L, 2017497330891045120L, 2020956095387686656L,
					2023723106985000192L, 2025798365682984960L, 2029948883078955008L,
					2032024141776939776L, 2034099400474924800L, 2038249917870894848L,
					2045859199763506432L, 2050701470058804480L, 2059002504850744320L,
					2064536528045370880L, 2072145809937982464L, 2075604574434624000L,
					2083905609226563840L, 2103966443307085056L, 2152389146260067584L,
					2168991215843947264L, 2177984003535215360L, 2185593285427826944L,
					2199428343414393344L, 2207729378206333184L, 2222256189092227840L,
					2270678892045210368L, 2544613040179225088L, 2768049226662272512L,
					2918851358715846656L, 2931994663803084288L, 2948596733386963968L,
					3006703976930543104L, 3035757598702332416L, 3052359668286212096L,
					3099398865440538112L, 3112542170527775744L, 3128452487212327424L,
					3165115390876728320L, 3316609275829630464L, 3331827839614853632L,
					3354655685292687872L, 3383017554165149184L, 3422447469426863104L,
					3442508303507384832L, 3472945431077830656L, 3672862018983715328L,
					4026347750540486656L, 4036032291131083264L, 4036724044030411776L,
					4037415796929739776L, 4038107549829068288L, 4038799302728396288L,
					4039491055627724800L, 4040182808527053312L, 4040874561426381312L,
					4041566314325709824L, 4042258067225037824L, 4042949820124366336L,
					4043641573023694848L, 4044333325923022848L, 4045025078822351360L,
					4045716831721679872L, 4046408584621007872L, 4047792090419664896L,
					4048483843318992896L, 4049175596218321408L, 4049867349117649408L,
					4050559102016977920L, 4051250854916306432L, 4051942607815634432L,
					4052634360714962944L, 4053326113614290944L, 4055401372312275968L,
					4056093125211604480L, 4057476631010260992L, 4058860136808918016L,
					4059551889708246016L, 4060935395506902528L, 4061627148406231040L,
					4062318901305559552L, 4063010654204887552L, 4063702407104216064L,
					4064394160003544064L, 4065085912902872576L, 4066469418701529088L,
					4067852924500186112L, 4068544677399514112L, 4070619936097499136L,
					4072695194795484160L, 4075462206392797184L, 4076153959292125696L,
					4076845712191454208L, 4077537465090782208L, 4079612723788767232L,
					4084454994084065792L, 4087913758580707328L, 4089297264379363840L,
					4089989017278692352L, 4090680770178020352L, 4092064275976677376L,
					4093447781775333888L, 4095523040473318912L, 4096906546271975424L,
					4098981804969960448L, 4101057063667945472L, 4103132322365930496L,
					4103824075265258496L, 4105207581063915008L, 4106591086862572032L,
					4107282839761900032L, 4108666345560556544L, 4110049851359213568L,
					4112125110057198592L, 4115583874553840128L, 4116275627453168128L,
					4116967380352496640L, 4118350886151153152L, 4119734391949809664L,
					4122501403547123200L, 4124576662245108224L, 4130802438339062784L,
					4137719967332346368L, 4143945743426300928L, 4146021002124285952L,
					4149479766620927488L, 4153630284016897536L, 4157089048513539072L,
					4161239565909509120L, 4170924106500105728L, 4181300399990030336L,
					4193751952177939968L, 4200669481171223552L, 4202744739869208576L,
					4204819998567193088L, 4210354021761819648L, 4221422068151072768L,
					4241482902231593984L, 4251167442822190592L, 4251859195721519104L,
					4253242701520175616L, 4254626207318832128L, 4257393218916145664L,
					4260851983412787200L, 4262927242110772224L, 4265002500808757248L,
					4267769512406070272L, 4273995288500025344L, 4280912817493308416L,
					4286446840687934976L, 4291289110983233536L, 4294056122580546560L,
					4298206639976516608L, 4303740663171143168L, 4309274686365769728L,
					4312733450862411264L, 4314808709560396288L, 4317575721157709312L,
					4321034485654350848L, 4338328308137559040L, 4369457188607333376L,
					4394360292983153152L, 4468377853211283456L, 4478062393801879552L,
					4487746934392476160L, 4504349003976355840L, 4509883027170982400L,
					4514033544566952448L, 4518875814862250496L, 4531327367050160128L,
					4567298517815233024L, 4631631537452766208L, 4828089360862009344L,
					5188492621412064256L, 5227922536673778688L, 5235531818566389760L,
					5238298830163703808L, 5241065841761016832L, 5248675123653627904L,
					5252133888150269952L, 5254209146848254976L, 5256284405546240000L,
					5271502969331463168L, 5299864838203923456L, 5305398861398550528L,
					5308857625895191552L, 5310932884593176576L, 5317158660687131648L,
					5323384436781086720L, 5330993718673697792L, 5335144236069667840L,
					5338603000566309888L, 5342061765062950912L, 5349671046955563008L,
					5355896823049518080L, 5367656622338099200L, 5403627773103171584L,
					5413312313693768704L, 5435448406472274944L, 5504623696405106688L,
					5518458754391672832L, 5525376283384955904L, 5533677318176896000L,
					5540594847170179072L, 5559272175452044288L, 5589017550123161600L,
					5597318584915101696L, 5604927866807712768L, 5613228901599652864L,
					5620838183492263936L, 5645049534968755200L, 5699006261116364800L,
					5725984624190169088L, 5786167126431732736L, 5799310431518970880L,
					5815220748203522048L, 5823521782995462144L, 5826980547492103168L,
					5831131064888073216L, 5833206323586058240L, 5834589829384715264L,
					5835281582284043264L, 5837356840982028288L, 5844966122874640384L,
					5849116640270609408L, 5851191898968594432L, 5852575404767251456L,
					5856034169263893504L, 5857417675062549504L, 5858801180861206528L,
					5860184686659863552L, 5862259945357847552L, 5865718709854489600L,
					5869869227250459648L, 5872636238847772672L, 5874711497545757696L,
					5876095003344414720L, 5880245520740384768L, 5882320779438369792L,
					5886471296834338816L, 5888546555532323840L, 5891313567129637888L,
					5894772331626278912L, 5899614601921576960L, 5904456872216876032L,
					5914141412807472128L, 5920367188901427200L, 5924517706297397248L,
					5927284717894710272L, 5929359976592695296L, 5930743482391351296L,
					5931435235290680320L, 5932126988190008320L, 5932818741089336320L,
					5934202246887993344L, 5936277505585978368L, 5937661011384634368L,
					5939736270082619392L, 5942503281679933440L, 5945962046176574464L,
					5949420810673216512L, 5951496069371201536L, 5953571328069186560L,
					5956338339666499584L, 5957721845465156608L, 5959105351263812608L,
					5960488857062469632L, 5962564115760454656L, 5965331127357767680L,
					5968098138955080704L, 5970173397653065728L, 5972248656351050752L,
					5975707420847692800L, 5977782679545677824L, 5979166185344333824L,
					5980549691142990848L, 5984700208538960896L, 5987467220136273920L,
					5990925984632915968L, 5995076502028884992L, 6001302278122840064L,
					6010986818713437184L, 6019287853505376256L, 6024821876700003328L,
					6027588888297316352L, 6028972394095973376L, 6031047652793958400L,
					6034506417290599424L, 6044190957881196544L, 6053183745572464640L,
					6057334262968434688L, 6061484780364403712L, 6067018803559030784L,
					6075319838350970880L, 6090538402136194048L, 6107140471720073216L,
					6137577599290519552L, 6199143607330740224L, 6233731252297155584L,
					6264168379867601920L, 6363089044471552000L, 6439873616296994816L,
					6581682960659300352L, 6648091238994819072L, 6664693308578699264L,
					6702047965142428672L, 6709657247035039744L, 6720033540524964864L,
					6724184057920934912L, 6726951069518247936L, 6730409834014889984L,
					6733868598511531008L, 6736635610108844032L, 6754621185491381248L,
					6762230467383992320L, 6774682019571902464L, 6863226390685927424L,
					6906806823343610880L, 6917183116833535999L]

			Please don't use it to dump the catalog yourself; it might still come
			in handy if you filter out a large part of the objects but still have
			more than 10 million matches.  Just regularly remove separation points.

			The way to use it in python would be to say::
				
				# make svc a TapService object with the right access URL, and then:
				for low, high in zip(limits[:-1], limits[1:]):
					partial = svc.run_sync("WITH sample AS ("
						" SELECT * FROM \schema.main"
						" WHERE source_id BETWEEN {} AND {})"
						" <your query against sample here>".format(low, high-1))

			RVS magnitudes
			''''''''''''''

			In particular to aid in designing studies involving radial velocities,
			we give a column phot_rvs_mean_mag based on the approximations
			given in :bibcode:`2018A&A...616A...1G`.  This is going to be severely off
			outside of 0.1<BP-G<1.7 (which only affects less than 50 ppm of
			the objects).

			Dump of the catalog
			'''''''''''''''''''

			While we strongly recommend that you try to structure your
			problem so as to make it work through ADQL, for the benefit
			of those who want to mirror the table or use it in services of their
			own, we provide a dump of the data in the form of FITS binary tables
			files; warning: pulling it transfers about 300 gigabytes, and
			dealing with this data volume is nontrivial.
			
			Having said that: The dump files are available from
			\internallink{gdr2mock/q/download/static/}.
		]]></meta>

		<index columns="source_id, ra, dec, l, b, phot_bp_mean_mag,
			phot_rp_mean_mag, phot_g_mean_mag, pmra, pmdec,
			random_index"/>

		<foreignKey source="index_parsec" inTable="photometry"
			metaOnly="True"/>

		<FEED source="gaia/q2#dr2lightcolumns"/>

		<column name="l" type="double precision"
			ucd="pos.galactic.lon" unit="deg"
			tablehead="l"
			description="Galactic longitude (converted from ra, dec)"/>
		<column name="b" type="double precision"
			ucd="pos.galactic.lat" unit="deg"
			tablehead="b"
			description="Galactic latitude (converted from ra, dec)"  />

		<column name="phot_g_n_obs" type="smallint"
			tablehead="#Obs G" ucd="meta.number"
			description="Number of observations contributing to G photometry">
			<values nullLiteral="-1" />
		</column>
		<column name="phot_variable_flag" type="text"
			ucd="meta.code;src.var"
			tablehead="Var?"
			description="Photometric variability flag"
			note="var"/>

		<LOOP>
			<csvItems>
				band, ucd
				rp,   R
				bp,   B
			</csvItems>
			<events>
				<column name="phot_\band\+_n_obs" type="smallint" required="True"
					ucd="meta.number;obs;phot.mag;em.opt.\ucd"
					tablehead="#\upper{\band}"
					description="Number of observations (CCD transits) that contributed
						to the integrated \upper{\band} mean flux and mean flux error."/>
			</events>
		</LOOP>

		<LOOP>
			<csvItems>
				name, label, bands
				bp_rp, BP-RP, em.opt.B;em.opt.R
				bp_g,  BP-G,  em.opt.B;em.opt.V
				g_rp,  G-RP,  em.opt.V;em.opt.R
			</csvItems>
			<events>
				<column name="\name"
					unit="mag" ucd="phot.color;\bands"
					tablehead="\label"
					description="\label color"/>
			</events>
		</LOOP>

		<column name="phot_rvs_mean_mag"
			unit="mag" ucd="phot.color;em.opt.I"
			tablehead="RVS"
			description="Approximate estimate for the RVS magnitude.  This
				uses formulae (2) and (3) from  2018A&amp;A...616A...1G.  Outside
				of the range 0.1&lt;BP-G&lt;1.7 we use Eq. 3 (which means the
				value is probably fairly bogus)."/>

		<column name="rv_nb_transits" type="smallint" required="True"
			ucd="meta.number;obs;spect.dopplerVeloc"
			tablehead="#RV"
			description="Number of transits (epochs) used to compute radial
				velocity."/>

		<column name="ref_epoch" type="double precision"
			ucd="meta.ref;time.epoch" unit="yr"
			tablehead="Epoch"
			description="Reference epoch to which the astrometic source parameters
				are referred, expressed as a Julian Year in TCB."/>
		<column name="astrometric_delta_q"
			ucd="stat.value"
			tablehead="δq(HIP)"
			description="Hipparcos/Gaia data discrepancy (Hipparcos subset of
				TGAS only)"
			note="dq"/>
		<column name="astrometric_excess_noise"
			ucd="stat.value" unit="mas"
			tablehead="Ex. Noise"
			description="Excess noise of the source"
			note="en"/>
		<column name="astrometric_excess_noise_sig"
			ucd="stat.value"
			tablehead="Sig. Noise"
			description="Significance of excess noise"
			note="en"/>

		<column name="astrometric_n_obs_ac" type="smallint" required="True"
			ucd="meta.number"
			tablehead="#Obs AC"
			description="Total number of observations AC"
			note="n"/>
		<column name="astrometric_n_obs_al" type="smallint" required="True"
			ucd="meta.number"
			tablehead="#Obs AL"
			description="Total number of observations AL"
			note="n"/>
		<column name="astrometric_n_bad_obs_ac" type="smallint" required="True"
			ucd="meta.number"
			tablehead="#Bad AC"
			description="Number of bad observations AC"
			note="nb"/>
		<column name="astrometric_n_bad_obs_al" type="smallint" required="True"
			ucd="meta.number"
			tablehead="#Bad AL"
			description="Number of bad observations AL"
			note="nb"/>
		<column name="astrometric_n_good_obs_ac" type="smallint" required="True"
			ucd="meta.number"
			tablehead="#Good AC"
			description="Number of good observations AC"
			note="ng"/>
		<column name="astrometric_n_good_obs_al" type="smallint" required="True"
			ucd="meta.number"
			tablehead="#Good AL"
			description="Number of good observations AL"
			note="ng"/>
		<column name="astrometric_chi2_al"
			ucd="stat.fit.chi2"
			tablehead="χ² AL"
			description="Astrometric goodness-of-fit (χ²) in the AL direction;
				χ² values were computed for the ‘good’ AL observations of the
				source, without taking into account the astrometric excess noise
				(if any) of the source. They do, however, take into account the
				attitude excess noise (if any) of each observation."/>

		<column name="astrometric_primary_flag" type="smallint" required="True"
			ucd="meta.code"
			tablehead="Primary?"
			description="Only primary sources (for which this flag is True)
				contribute to the estimation of attitude, calibration, and global
				parameters.  The estimation of source parameters is not affected
				by primariness."/>
		<column name="astrometric_pseudo_colour"
			unit="um**-1"
			tablehead="Astr. Col."
			description="Colour of the source assumed in the final astrometric
				processing, given as he effective wavenumber of the photon flux
				distribution in the astrometric (G) band.  The value given in this
				field was astrometrically determined in a preliminary solution, using
				the chromatic displacement of image centroids calibrated by means of
				the effective wavenumbers (ν_eff) of primary sources calculated from
				BP and RP magnitudes. The field is empty when no such determination
				was possible, in which case a default value of 1.6 1/µm was assumed."/>
		<column name="mean_varpi_factor_al"
			ucd="stat.fit.param"
			tablehead="Par. Fact."
			description="Mean parallax factor in the AL direction, computed from all
				the good observations of the source processed in the astrometry.
				The value given in this field is typically in the range [−0.23, +0.32]
				(1st and 99th percentiles). A value outside this range indicates a
				distribution of observations that is unfavourable for the determination
				of the parallax, and the calculated parallax could then be more
				vulnerable to errors, e.g. from the calibration model, not reflected in
				the formal uncertainties."/>
		<column name="visiblilty_periods_used" type="smallint" required="True"
			ucd="meta.number;obs"
			tablehead="#Obs"
			description="Number of visibility periods used in Astrometric solution. A
				visibility period is a group of observations separated from other groups
				by a gap of at least 4 days."/>
		<column name="astrometric_sigma5d_max"
			unit="mas" ucd="stat.error;obs;stat.max"
			tablehead="Max σ"
			description="The longest principal axis in the 5-dimensional error
				ellipsoid.  This is useful for filtering out cases where one of the five
				parameters, or some linear combination of several parameters, is
				particularly ill-determined. It is measured in mas and computed as the
				square root of the largest singular value of the scaled 5 × 5 covariance
				matrix of the astrometric parameters."/>

		<column name="matched_observations" type="smallint" required="True"
			ucd="meta.number"
			tablehead="Matched_observations"
			description="The number of observations (detection transits) that have
				been matched to a given source during the last internal crossmatch
				revision."/>
		<column name="astrometric_priors_used" type="smallint"
			tablehead="Prior"
			description="Type of prior used in in the astrometric solution"
			note="pri">
			<values nullLiteral="-1" />
		</column>
		<column name="astrometric_relegation_factor"
			ucd="arith.factor"
			tablehead="Releg. fct."
			description="Relegation factor of the source calculated as per Eq. (118)
				in 2012A&amp;A...538A..78L used for the primary selection process." />
		<column name="astrometric_weight_ac"
			ucd="stat.weight;stat.mean" unit="mas**-2"
			tablehead="Weight AC"
			description="Mean astrometric weight of the source"
			note="maw"/>
		<column
			name="astrometric_weight_al"
			ucd="stat.weight;stat.mean" unit="mas**-2"
			description="Mean astrometric weight of the source"
			tablehead="Weight AL"
			note="maw"/>
		<column name="duplicated_source" type="smallint" required="True"
			tablehead="Dup?"
			description="During data processing, this source happened to have been
			duplicated and one source only has been kept."
			note="dup"/>

		<column name="ra_dec_corr"
			ucd="stat.correlation"
			tablehead="RA-Dec-Corr"
			description="Correlation between right ascension and declination"
			note="cr"/>
		<column name="ra_pmra_corr"
			ucd="stat.correlation"
			tablehead="RA-PM(RA) Corr."
			description="Correlation between right ascension and proper motion in
				right ascension"
				note="cr"/>
		<column name="ra_pmdec_corr"
			ucd="stat.correlation"
			tablehead="RA-PM(Dec) Corr."
			description="Correlation between right ascension and proper motion in
				declination"
				note="cr"/>
		<column name="dec_pmra_corr" ucd="stat.correlation"
			tablehead="Dec-PM(RA) Corr."
			description="Correlation between declination and proper motion in
				right ascension"
				note="cr"/>
		<column name="dec_pmdec_corr"
			ucd="stat.correlation"
			tablehead="Dec-PM(Dec) Corr."
			description="Correlation between declination and proper motion in
				declination"
				note="cr"/>
		<column name="pmra_pmdec_corr"
			ucd="stat.correlation"
			tablehead="PM(RA)-RM(Dec)-RA"
			description="Correlation between proper motion in right ascension and
				proper motion in declination"
				note="cr"/>
		<column name="ra_parallax_corr"
			ucd="stat.correlation"
			tablehead="RA-π Corr."
			description="Correlation between right ascension and parallax"
			note="cr"/>
		<column name="dec_parallax_corr"
			ucd="stat.correlation"
			tablehead="RA-Dec Corr."
			description="Correlation between declination and parallax"
			note="cr"/>
		<column name="parallax_pmra_corr"
			ucd="stat.correlation"
			tablehead="π-PM(RA) Corr."
			description="Correlation between parallax and proper motion in right
				ascension"
			note="cr"/>
		<column name="parallax_pmdec_corr"
			ucd="stat.correlation"
			tablehead="π-PM(Dec) Corr."
			description="Correlation between parallax and proper motion in
				declination"
			note="cr"/>

		<LOOP listItems="k1 k2 k3 k4">
			<events>
				<column name="scan_direction_mean_\item"
					tablehead="Scan dir. \item" unit="deg"
					description="Mean position angle of scan directions across
						the source"
					note="sk"/>
				<column name="scan_direction_strength_\item"
					tablehead="Scan conc. \item"
					description="Degree of concentration of scan directions across
						the source"
					note="sk"/>
			</events>
		</LOOP>

		<column name="priam_flags" type="bigint"
			ucd="meta.code"
			tablehead="Priam?"
			description="Flags describing the status of the astrophysical
				parameters Teff, A G and E[BP-RP] (i.e., those determined by
				Apsis-Priam). See the release documentation.">
			<values nullLiteral="-1"/>
		</column>
		<column name="flame_flags" type="bigint"
			ucd="meta.code"
			tablehead="FLAME?"
			description="Flags describing the status of the astrophysical
				parameters radius and luminosity (i.e., those determined by
				Apsis-FLAME). See the release documentation.">
			<values nullLiteral="-1"/>
		</column>

		<FEED source="apsispars"
			name="teff"
			unit="K"
			ucd="phys.temperature"
			tablehead="T_eff"
			description="the effective temperature"
			prog="Priam"/>
		<FEED source="apsispars"
			name="a_g"
			unit="mag"
			ucd="phys.absorption"
			tablehead="A_G"
			description="the line-of-sight extinction in the G-band"
			prog="Priam"/>
		<FEED source="apsispars"
			name="e_bp_min_rp"
			unit="mag"
			ucd="phys.absorption"
			tablehead="E(BP-RP)"
			description="the line-of-sight reddening E(BP-RP)"
			prog="Priam"/>
		<FEED source="apsispars"
			name="radius"
			unit="solRad"
			ucd="phys.size.radius"
			tablehead="R"
			description="the radius"
			prog="FLAME"/>
		<FEED source="apsispars"
			name="lum"
			unit="solLum"
			ucd="phys.luminosity"
			tablehead="solLum"
			description="the luminosity"
			prog="FLAME"/>

		<meta name="note" tag="id">
			For the contents of Gaia DR1 (and hence TGAS), which does not include
			Solar System objects, the source ID consists of a 64-bit integer, least
			significant bit = 1 and most significant bit = 64, comprising:

			* a HEALPix index number (sky pixel) in bits 36 - 63; by definition the
				smallest HEALPix index number is zero.
			* a 2-bit Data Processing Centre code in bits 34 - 35; for example
				MOD(source_id / 4294967296, 8) can be used to distinguish between
				sources initialised via the Initial Gaia Source List by the Torino DPC
				(code = 0) and sources otherwise detected and assigned by Gaia
				observations (code &gt; 0)
			* a 25-bit plus 7 bit sequence number within the HEALPix pixel in bits 1
				to 32 split into:

				* a 25 bit running number in bits 8 x 32; the running numbers are
					defined to be positive, i.e. never zero (except in the case of forced
					empty windows)
				* a 7-bit component number in bits 1 x 7 one spare bit in bit 33

			This means that the HEALpix index level 12 of a given source is contained
			in the most significant bits. HEALpix index of 12 and lower levels can
			thus be retrieved as follows:

			* HEALpix level 12 = source_id / 34359738368
			* HEALpix level 11 = source_id / 137438953472
			* HEALpix level 10 = source_id / 549755813888
			* HEALpix level n = source_id / 2^35 * 4^(12 - level).
		</meta>

		<meta name="note" tag="dq">
			In the TGAS solution astrometric_delta_q (ΔQ)
			indicates the discrepancy between the Hipparcos proper motion and the
			TGAS proper motion. A large value of ΔQ could indicate non-linear motion
			(e.g. in a binary).

			For more details, see the paper referenced in the source metadata.
		</meta>

		<meta name="note" tag="en">
			This is the excess noise ϵ\ :sub:`i` of the source. It measures the
			disagreement, expressed as an angle, between the observations of a source
			and the best-fitting standard astrometric model (using five astrometric
			parameters). The assumed observational noise in each observation is
			quadratically increased by ϵ\ :sub:`i`.  in order to statistically match
			the residuals in the astrometric solution. A value of 0 signifies that
			the source is astrometrically well-behaved, i.e.  that the residuals of
			the fit statistically agree with the assumed observational noise. A
			positive value signifies that the residuals are statistically larger than
			expected.

			The significance of ϵ\ :sub:`i` is given by astrometric_excess_noise_sig.
			If this is larger than 2, then ϵ\ :sub:`i` is probably not significant,
			and the source may be astrometrically well-behaved even if ϵ\ :sub:`i`
			is large.

			The excess noise may absorb all kinds of modelling errors that are not
			accounted for by the observational noise (image centroiding error) or the
			excess attitude noise. Such modelling errors include LSF and PSF
			calibration errors, geometric instrument calibration errors, and part of
			the high-frequency attitude noise. These modelling errors are
			particularly important in the early data releases, but should decrease as
			the astrometric modelling of the instrument and attitude improves over
			the years.

			Additionally, sources that deviate from the standard five-parameter
			astrometric model (e.g. unresolved binaries, exoplanet systems, etc.) may
			have positive excess noise.  . Given the many other possible
			contributions to the excess noise, the user must study the empirical
			distributions of ϵ\ :sub:`i` and astrometric_excess_noise_sig.
			to make sensible cutoffs before filtering out sources for their
			particular application.

			In Gaia DR1, the excess source noise has the same interpretation as
			described above for both the primary (TGAS) and secondary data sets. It
			measures the disagreement between the five-parameter model and the
			observations, augmented by the different priors used. Thus, in TGAS the
			excess noise may be increased if the proper motion seen during the 14
			months of Gaia observations are not in agreement with the proper motion
			inferred from the Tycho-2/Gaia comparison. In the secondary solution the
			excess noise may be increased if the Gaia observations indicate a proper
			motion or parallax several times larger than the prior uncertainty.
		</meta>

		<meta name="note" tag="nb">
			Number of AC or AL observations (= CCD transits) that were strongly
			downweighted in the astrometric solution of the source, and therefore
			contributed little to the determination of the astrometric parameters. An
			observation is considered to be strongly downweighted if its
			downweighting factor w &lt; 0.2, which means that the absolute value of
			the astrometric residual exceeds 4.83 times the total uncertainty of the
			observation, calculated as the quadratic sum of the centroiding
			uncertainty, excess source noise, and excess attitude noise.
		</meta>

		<meta name="note" tag="ng">
			Number of AC/AL observations (= CCD transits) that were not strongly
			downweighted in the astrometric solution of the source. Strongly
			downweighted observations (with downweighting factor w&lt;0.2,
			are instead counted in astrometric_n_bad_obs_ac/_al. The sum of
			astrometric_n_good_obs_ac/_al and astrometric_n_bad_obs_ac/_al equals
			astrometric_n_obs_ac/_al, the total number of AC/AL observations used in
			the astrometric solution of the source.
		</meta>

		<meta name="note" tag="n">
			Total number of AC/AL observations (= CCD transits) used in the
			astrometric solution of the source, independent of their weight. Note
			that some observations may be strongly downweighted (see
			astrometric_n_bad_obs_ac/_al).
			
			Nearly all sources having G&lt;13 will have AC observations from
			2d windows, while fainter than that limit only ∼ 1% of stars (the
			so–called “calibration faint stars”) are assigned 2d windows
			resulting in AC observations (this does not apply to AL).
		</meta>

		<meta name="note" tag="pri">
			Type of prior used in the astrometric solution:

			0:
				No prior used
			1:
				Galaxy Bayesian Prior for parallax and proper motion
			2:
				Galaxy Bayesian Prior for parallax and proper motion relaxed by factor
				10
			3:
				Hipparcos prior for position
			4:
				Hipparcos prior for position and proper motion
			5:
				Tycho2 prior for position
			6:
				Quasar prior for proper motion

			The Galaxy Bayesian Prior is defined in :bibcode:`2015A&amp;A...583A..68M`,
			where it is denoted σ\ :sub:`ϖ,F90` (for the parallax) and
			σ\ :sub:`μ,F90` (for proper motion).

			For Gaia DR1 the only types of priors used are 2 (for the secondary data
			set), 3 (for the Hipparcos subset of the primary data set), or 5 (for the
			non-Hipparcos subset of the primary data set). Type 6 was used for
			internal calibration purposes and alignment of the reference frame, but
			the corresponding astrometric results are in general not published.
		</meta>

		<meta name="note" tag="maw">
			Mean astrometric weight of the source in AC or AL direction.
			The mean astrometric weight of the source is calculated as per Eq. (119)
			in :bibcode:`2012A&amp;A...538A..78L`\ .
		</meta>

		<meta name="note" tag="cr">
			All off-diagonal members entries of the covariance matrix
			(ra_dec_corr, ra_pmra_corr, ra_pmdec_corr, dec_pmra_corr, dec_pmdec_corr,
			pmra_pmdec_corr, ra_parallax_corr, dec_parallax_corr, parallax_pmra_corr,
			parallax_pmdec_corr) are dimensionless values normalised to
			between -1 and 1.
		</meta>

		<meta name="note" tag="dup">
			This may indicate observational, cross-matching or processing problems,
			or stellar multiplicity, and probable astrometric or photometric problems
			in all cases. In DR1, for close doubles with separations below some 2
			arcsec, truncated windows have not been processed, neither in astrometry
			and photometry. The transmitted window is centred on the brighter part of
			the acquired window, so the brighter component has a better chance to be
			selected, even when processing the fainter transit. If more than two
			images are contained in a window, the result of the image parameter
			determination is un-predictable in the sense that it might refer to
			either (or neither) image, and no consistency is assured.
		</meta>

		<meta name="note" tag="var">
			Flag indicating if variability was identified in the photometric G band:

			* NULL: source not processed and/or exported to catalogue
			* "CONSTANT": Source not identified as variable (not in this release)
			* "VARIABLE": source identified and processed as variable;
				see ivo://esavo/gaia/tap for more information on these objects.

			Note that for this data release only a small subset of (variable) sources
			was processed and/or exported, so for many (known) variable sources this
			flag is set to NULL.
		</meta>

		<meta name="note" tag="sk">
			The scan_direction_strength and scan_direction_mean quantify
			the distribution of AL scan directions across the source.
			scan_direction_mean_kK (K=1..4) is 1/K times the argument of the
			trigonometric moments m\ :sub:`k` = exp(ikθ), where
			θ is the position angle of the scan and the mean value is taken over the
			nObs[0] AL observations contributing to the astrometric parameters of the
			source.

			θ is defined in the usual astronomical sense:
			θ = 0 when the FoV is moving towards local North, and θ = 90°
			towards local East.

			scan_direction_mean_kK is an angle between
			-180°/K and 180°/K, giving the mean position angle of the scans
			at order K.  The different orders K
			are statistics of the scan directions modulo 360°/K.
			
			For example, at first order (K=1), θ = 10° and θ = 190°
			count as different directions, but at second order (K = 2)
			they are the same. Thus, scan_direction_mean_k1 is the mean
			direction when the sense of direction is taken into account, while
			scan_direction_mean_k2 is the mean direction without regard to the sense
			of the direction.
			
			For example, scan_direction_mean_k1 = 0 means that the scans
			preferentially go towards North, while scan_direction_mean_k2 = 0 means
			that they preferentially go in the North-South direction, and
			scan_direction_mean_k4 = 0 that they preferentially go either in the
			North-South or in the East-West direction.

			The scan_direction_strength is a number between 0 and 1, where 0 means
			that the scan directions are well spread out in different directions,
			while 1 mean sthat they are concentrated in a single direction (given by
			scan_angle_mean).
		</meta>

		<column name="source_id" original="generated_data.source_id"/>
		<column name="feh"
			unit="" ucd="phys.abund.Fe"
			tablehead="[Fe/H]"
			description="Fe/H as log10 of solar ratio ('dex')"/>
		<column name="a0"
			unit="mag" ucd="phys.absorption"
			tablehead="a_0"
			description="Monochromatic extinction at lambda = 547.7nm"/>
		<column name="mass"
			unit="solMass" ucd="phys.mass"
			tablehead="Mass"
			description="Initial mass of the star"/>
		<column name="age"
			unit="Gyr" ucd="time.age"
			tablehead="Age"
			description="Age of the star"/>
		<column name="logg"
			unit="log(cm/(s**2))" ucd="phys.gravity"
			tablehead="log(g)"
			description="Logarithm of surface gravity."/>
		<column name="teff_val"
			unit="K" ucd="phys.temperature"
			tablehead="T_eff"
			description="Effective temperature of the star"/>
		<column name="lum_val"
			unit="solLum" ucd="phys.luminosity"
			tablehead="lum"
			description="Stellar luminosity in solar luminosities."/>
		<column name="e_bp_min_rp_val"
			unit="mag" ucd="phys.absorption"
			tablehead="E(BP-RP)"
			description="Line-of-sight reddening E(BP-RP)"/>
		<column name="a_g_val"
			unit="mag" ucd="phys.absorption"
			tablehead="A_G"
			description="Line-of-sight extinction in the G band, A_G"/>
		<column name="radius_val"
			unit="solRad" ucd="phys.size.radius"
			tablehead="Radius"
			description="Stellar radius in solar radii"/>
		<column name="nobs" type="integer" required="True"
			unit="" ucd="meta.number;obs"
			tablehead="N_obs"
			description="Nominal number of observations, scaled to the shorter time base of 			GDR2
				(a function with ecliptic latitude)."/>
		<column name="index_parsec" type="integer" required="True"
			tablehead="Phot." ucd="meta.id.cross"
			description="Foreign key into the photometry/extinction table."/>

		<viewStatement><![CDATA[
			CREATE VIEW \curtable AS (
				SELECT \colNames FROM (
					SELECT
						source_id,
						ra,
						dec,
						a.parallax_error * c.alpha_ratio * 1.644 AS ra_error,
						a.parallax_error * c.delta_ratio * 1.644 AS dec_error,
						glon as l,
						glat as b,
						pm_ra as pmra,
						pm_dec as pmdec,
						a.parallax_error * c.pmra_ratio * 1.644 AS pmra_error,
						a.parallax_error * c.pmdec_ratio * 1.644 AS pmdec_error,
						parallax,
						a.parallax_error * c.parallax_ratio * 1.644 AS parallax_error,
						parallax / parallax_error AS parallax_over_error,
						ROUND(0.37 * b.n_obs)::INTEGER AS nobs,
						gaia_g AS phot_g_mean_mag,
						gaia_g_rp AS phot_rp_mean_mag,
						gaia_g_bp AS phot_bp_mean_mag,
						CASE WHEN gaia_g-gaia_g_rp<1.4
							THEN gaia_g_rp + 0.042319
								- 0.65124 * (gaia_g-gaia_g_rp)
								+ 1.0215 * POWER(gaia_g-gaia_g_rp,2)
								- 1.3947 * POWER(gaia_g-gaia_g_rp,3)
								+ 0.53768 * POWER(gaia_g-gaia_g_rp,4)
							ELSE gaia_g_rp + 132.32
								- 377.28 * (gaia_g-gaia_g_rp)
								+ 402.32 * POWER(gaia_g-gaia_g_rp,2)
								- 190.97 * POWER(gaia_g-gaia_g_rp,3)
								+ 34.026 * POWER(gaia_g-gaia_g_rp,4)
						END AS phot_rvs_mean_mag,
						power(10, 0.4 * (25.6884 - gaia_g)) AS phot_g_mean_flux,
						power(10, 0.4 * (25.3514 - gaia_g_bp)) AS phot_bp_mean_flux,
						power(10, 0.4 * (24.7619 - gaia_g_rp)) AS phot_rp_mean_flux,
						-1 * (power(10, 0.4 * (25.6884 - (gaia_g + (sig_g / sqrt(0.37 * b.n_obs))))) - power(10, 0.4 * (25.6884 - gaia_g))) AS phot_g_mean_flux_error,
						-1 * (power(10, 0.4 * (25.3514 - (gaia_g_bp + (sig_bp / sqrt(0.37 * b.n_obs))))) - power(10, 0.4 * (25.3514 - gaia_g_bp))) AS phot_bp_mean_flux_error,
						-1 * (power(10, 0.4 * (24.7619 - (gaia_g_rp + (sig_rp / sqrt(0.37 * b.n_obs))))) - power(10, 0.4 * (24.7619 - gaia_g_rp))) AS phot_rp_mean_flux_error,
						power(10, 0.4 * (25.6884 - gaia_g)) / (-1 * (power(10, 0.4 * (25.6884 - (gaia_g + (sig_g / sqrt(0.37 * b.n_obs))))) - power(10, 0.4 * (25.6884 - gaia_g)))) AS phot_g_mean_flux_over_error,
						power(10, 0.4 * (25.3514 - gaia_g_bp)) / (-1 * (power(10, 0.4 * (25.3514 - (gaia_g_bp + (sig_bp / sqrt(0.37 * b.n_obs))))) - power(10, 0.4 * (25.3514 - gaia_g_bp)))) AS phot_bp_mean_flux_over_error,
						power(10, 0.4 * (24.7619 - gaia_g_rp)) / (-1 * (power(10, 0.4 * (24.7619 - (gaia_g_rp + (sig_rp / sqrt(0.37 * b.n_obs))))) - power(10, 0.4 * (24.7619 - gaia_g_rp)))) AS phot_rp_mean_flux_over_error,
						gaia_g_bp - gaia_g_rp AS bp_rp,
						gaia_g_rp - gaia_g AS bp_g,
						gaia_g - gaia_g_rp AS g_rp,
						radial_velocity,
						ebp_rp AS e_bp_min_rp_val,
						lum AS lum_val,
						feh,
						teff AS teff_val,
						A_G as a_g_val,
						mass,
						age,
						logg,
						a0,
						(sqrt((lum * 3.839e+26)/(4 * 3.141592653589793 * 5.67037321 * 1e-8)) / (teff * teff)) / 6.955e8 AS radius_val,
						index_parsec,
						random_index,
						NULL::REAL AS radial_velocity_error,
						NULL::SMALLINT AS phot_rp_n_obs,
						NULL::SMALLINT AS phot_g_n_obs,
						NULL::SMALLINT AS phot_bp_n_obs,
						NULL::SMALLINT AS visiblilty_periods_used,
						NULL::REAL AS ref_epoch,
						NULL::REAL AS astrometric_chi2_al,
						NULL::REAL AS astrometric_delta_q,
						NULL::REAL AS astrometric_excess_noise,
						NULL::REAL AS astrometric_excess_noise_sig,
						NULL::REAL AS astrometric_gof_al,
						NULL::SMALLINT AS astrometric_n_bad_obs_ac,
						NULL::SMALLINT AS astrometric_n_bad_obs_al,
						NULL::SMALLINT AS astrometric_n_good_obs_ac,
						NULL::SMALLINT AS astrometric_n_good_obs_al,
						NULL::SMALLINT AS astrometric_n_obs_ac,
						NULL::SMALLINT AS astrometric_n_obs_al,
						NULL::SMALLINT AS astrometric_params_solved,
						NULL::SMALLINT AS astrometric_primary_flag,
						NULL::SMALLINT AS astrometric_priors_used,
						NULL::REAL AS astrometric_pseudo_colour,
						NULL::REAL AS astrometric_relegation_factor,
						NULL::REAL AS astrometric_sigma5d_max,
						NULL::REAL AS astrometric_weight_ac,
						NULL::REAL AS astrometric_weight_al,
						NULL::REAL AS dec_parallax_corr,
						NULL::REAL AS dec_pmdec_corr,
						NULL::REAL AS dec_pmra_corr,
						NULL::SMALLINT AS duplicated_source,
						NULL::SMALLINT AS matched_observations,
						NULL::REAL AS mean_varpi_factor_al,
						NULL::REAL AS parallax_pmdec_corr,
						NULL::REAL AS parallax_pmra_corr,
						NULL::REAL::REAL AS phot_bp_rp_excess_factor,
						NULL::TEXT AS phot_variable_flag,
						NULL::REAL AS pmra_pmdec_corr,
						NULL::REAL AS ra_dec_corr,
						NULL::REAL AS ra_parallax_corr,
						NULL::REAL AS ra_pmdec_corr,
						NULL::REAL AS ra_pmra_corr,
						NULL::SMALLINT AS rv_nb_transits,
						NULL::SMALLINT AS priam_flags,
						NULL::SMALLINT AS flame_flags,
						NULL::REAL AS teff_percentile_lower,
						NULL::REAL AS teff_percentile_upper,
						NULL::REAL AS a_g_percentile_lower,
						NULL::REAL AS a_g_percentile_upper,
						NULL::REAL AS e_bp_min_rp_percentile_lower,
						NULL::REAL AS e_bp_min_rp_percentile_upper,
						NULL::REAL AS radius_percentile_lower,
						NULL::REAL AS radius_percentile_upper,
						NULL::REAL AS lum_percentile_lower,
						NULL::REAL AS lum_percentile_upper,
						NULL::REAL AS scan_direction_mean_k1,
						NULL::REAL AS scan_direction_mean_k2,
						NULL::REAL AS scan_direction_mean_k3,
						NULL::REAL AS scan_direction_mean_k4,
						NULL::REAL AS scan_direction_strength_k1,
						NULL::REAL AS scan_direction_strength_k2,
						NULL::REAL AS scan_direction_strength_k3,
						NULL::REAL AS scan_direction_strength_k4

					FROM \schema.generated_data AS a
					JOIN \schema.astrometric_performance6 AS c
						ON (c.lat_index=a.beta_index)					
					JOIN \schema.astrometric_performance2 AS b
						ON (b.lat_index=a.beta_index)
					) vals )
		]]></viewStatement>
	</table>

	<data id="import">
		<make table="main"/>
	</data>


	<data id="make_photometry_view">
		<make table="photometry"/>
	</data>

	<table id="astrometric_performance6" onDisk="true" adql="hidden"
			primary="lat_index">
		<meta name="title">Gaia Astrometric Performance, Table 6</meta>
		<meta name="description">This table gives numerical factors
			to be applied to the sky-averaged astrometric errors for the different
			astrometric parameters as function of ecliptic latitude β, including the
			effect of the variation of the number of transits over the sky.
			Source: https://www.cosmos.esa.int/web/gaia/table-6
		</meta>

		<column name="lat_index" type="smallint" required="True"
			ucd="meta.id;meta.main"
			tablehead="Index"
			description="Bin index, starting at 1"/>
		<column name="sinbetbin"
			tablehead="|sin(β)|"
			description="Bin in absolute ecliptic latitude"/>
		<column name="alpha_ratio"
			ucd="stat.error;arith.ratio"
			tablehead="ra error factor"
			description="The error factor (including nobs) to be multiplied
				with the nominal parallax error to derive the eom ra error
				for a specific ecliptic latitude bin"/>
		<column name="delta_ratio"
			ucd="stat.error;arith.ratio"
			tablehead="dec error factor"
			description="The error factor (including nobs) to be multiplied
				with the nominal parallax error to derive the eom dec error for
				a specific ecliptic latitude bin"/>
		<column name="parallax_ratio"
			ucd="stat.error;arith.ratio"
			tablehead="parallax error factor"
			description="The error factor (including nobs) to be multiplied
				with the nominal parallax error to derive the eom parallax error
				for a specific ecliptic latitude bin"/>
		<column name="pmra_ratio"
			ucd="stat.error;arith.ratio"
			tablehead="pmra error factor"
			description="The error factor (including nobs) to be multiplied
				with the nominal parallax error to derive the eom pmra error
				for a specific ecliptic latitude bin"/>
		<column name="pmdec_ratio"
			ucd="stat.error;arith.ratio"
			tablehead="pmdec error factor"
			description="The error factor (including nobs) to be multiplied
				with the nominal parallax error to derive the eom pmdec error
				for a specific ecliptic latitude bin"/>
	</table>

	<data id="make_astperf6">
		<sources>
			<item>
|sin(beta)|     alpha*     delta     pi     mu-alpha*     mu-delta
0.025           1.026     0.756    1.180     0.725        0.542
0.075           1.021     0.757    1.180     0.722        0.542
0.125           1.002     0.751    1.169     0.710        0.537
0.175           0.993     0.752    1.167     0.703        0.539
0.225           0.973     0.751    1.158     0.689        0.538
0.275           0.952     0.742    1.143     0.673        0.533
0.325           0.934     0.740    1.136     0.662        0.533
0.375           0.901     0.730    1.146     0.640        0.525
0.425           0.861     0.718    1.098     0.614        0.515
0.475           0.819     0.705    1.072     0.584        0.506
0.525           0.765     0.691    1.043     0.548        0.493
0.575           0.701     0.673    1.009     0.500        0.477
0.625           0.631     0.650    0.970     0.451        0.461
0.675           0.535     0.621    0.922     0.381        0.437
0.725           0.469     0.607    0.850     0.327        0.423
0.775           0.554     0.636    0.808     0.386        0.443
0.825           0.603     0.654    0.779     0.422        0.456
0.875           0.641     0.669    0.755     0.447        0.467
0.925           0.668     0.680    0.731     0.466        0.473
0.975           0.688     0.706    0.713     0.481        0.490
			</item>
		</sources>
		<embeddedGrammar>
			<iterator>
				<code>
					names = ("lat_index sinbetbin alpha_ratio delta_ratio"
						" parallax_ratio pmra_ratio pmdec_ratio").split()
					for ind, items in enumerate(self.sourceToken.split("\n")[2:]):
						yield dict(zip(names,
							[ind]+[float(item) for item in items.split()]))
				</code>
			</iterator>
		</embeddedGrammar>
		<make table="astrometric_performance6">
			<rowmaker idmaps="*"/>
		</make>
	</data>

	<table id="astrometric_performance2" onDisk="true" adql="hidden"
			primary="lat_index">
		<meta name="title">Gaia Astrometric Performance, Table 2</meta>
		<meta name="description">This table gives numerical factors
			to be applied to the sky-averaged astrometric errors for the different
			astrometric parameters as function of ecliptic latitude β, including the
			effect of the variation of the number of transits over the sky.
			Source: https://www.cosmos.esa.int/web/gaia/table-2
		</meta>
		<column name="lat_index" type="smallint" required="True"
			ucd="meta.id;meta.main"
			tablehead="Index"
			description="Bin index, starting at 0"/>
		<column name="n_obs" type="integer" required="True"
			ucd="meta.number;obs"
			tablehead="N_obs"
			description="The sky averaged number of observations at eom for
				a specific bin in ecliptic latitude"/>

		<column name="alpha_ratio"
			ucd="stat.error;arith.ratio"
			tablehead="ra error factor"
			description="The error factor to be multiplied with the nominal
				parallax error to derive ra error for a specific ecliptic
				latitude bin"/>
		<column name="delta_ratio"
			ucd="stat.error;arith.ratio"
			tablehead="dec error factor"
			description="The error factor to be multiplied with the nominal
				parallax error to derive dec error for a specific ecliptic
				latitude bin"/>
		<column name="parallax_ratio"
			ucd="stat.error;arith.ratio"
			tablehead="parallax error factor"
			description="The error factor to be multiplied with the nominal
				parallax error to derive parallax error for a specific ecliptic
				latitude bin"/>
		<column name="pmra_ratio"
			ucd="stat.error;arith.ratio"
			tablehead="pmra error factor"
			description="The error factor to be multiplied with the nominal
				parallax error to derive pmra error for a specific ecliptic
				latitude bin"/>
		<column name="pmdec_ratio"
			ucd="stat.error;arith.ratio"
			tablehead="pmdec error factor"
			description="The error factor to be multiplied with the nominal
				parallax error to derive pmdec error for a specific ecliptic
				latitude bin"/>
	</table>

	<data id="make_astperf2">
		<sources>
			<item>
|sin(beta)|     beta_min [deg]     beta_max [deg]     N_obs     alpha*     delta     pi     mu-alpha*     mu-delta
0.025                0.0                 2.9           61       0.920     0.666    1.045     0.651        0.478
0.075                2.9                 5.7           61       0.916     0.667    1.044     0.648        0.478
0.125                5.7                 8.6           62       0.907     0.667    1.043     0.642        0.478
0.175                8.6                11.5           62       0.898     0.668    1.041     0.636        0.479
0.225               11.5                14.5           63       0.887     0.672    1.042     0.628        0.482
0.275               14.5                17.5           65       0.881     0.675    1.044     0.624        0.485
0.325               17.5                20.5           66       0.871     0.678    1.046     0.618        0.488
0.375               20.5                23.6           68       0.853     0.679    1.046     0.607        0.489
0.425               23.6                26.7           71       0.833     0.682    1.048     0.594        0.490
0.475               26.7                30.0           75       0.814     0.689    1.053     0.581        0.495
0.525               30.0                33.4           80       0.786     0.697    1.058     0.563        0.498
0.575               33.4                36.9           87       0.751     0.708    1.067     0.536        0.502
0.625               36.9                40.5           98       0.717     0.725    1.088     0.513        0.515
0.675               40.5                44.4          122       0.679     0.774    1.154     0.484        0.545
0.725               44.4                48.6          144       0.646     0.822    1.156     0.451        0.573
0.775               48.6                53.1          106       0.656     0.738    0.943     0.457        0.515
0.825               53.1                58.2           93       0.668     0.711    0.852     0.467        0.496
0.875               58.2                64.2           85       0.679     0.695    0.789     0.473        0.486
0.925               64.2                71.8           80       0.686     0.686    0.741     0.479        0.478
0.975               71.8                90.0           75       0.684     0.690    0.700     0.479        0.479
			</item>
		</sources>
		<embeddedGrammar>
			<iterator>
				<code>
					names = ("lat_index sinbetabs beta_min beta_max n_obs alpha_ratio delta_ratio"
						" parallax_ratio pmra_ratio pmdec_ratio").split()
					for ind, items in enumerate(self.sourceToken.split("\n")[2:]):
						if items.strip():
							yield dict(zip(names,
								[ind]+[float(item) for item in items.split()]))
				</code>
			</iterator>
		</embeddedGrammar>
		<make table="astrometric_performance2">
			<rowmaker idmaps="*"/>
		</make>
	</data>

	<service id="download" allowed="static">
		<meta name="title">Gaia DR2 Mock Bulk Download</meta>
		<meta name="description" format="rst">
			A facility to download the raw FITS tables
			containing the generated data for the Gaia DR2 mock tables.  Almost
			all users will want to use the ingested and processed table
			gdr2mock.main on the TAP service at http://dc.g-vo.org/tap instead.

			Rough metadata for the FITS binary tables is available from
			\RSTtable{gdr2mock.generated_data}.
			To download the files, visit \RSTservicelink{\rdId/download/static}.
		</meta>
		<nullCore/>
		<property name="staticData">data</property>
	</service>

	<data id="pub" auto="False">
		<make table="main"/>
		<make table="photometry"/>
		<publish sets="local,ivo_managed"/>
	</data>

	<regSuite title="GDR2mock regression">
		<regTest title="GDR2mock main view looks plausible.">
			<url parSet="TAP"
				QUERY="select * from gdr2mock.main where random_index=1326633"
				>/tap/sync</url>
			<code>
				row = self.getFirstVOTableRow()
				self.assertEqual(row["source_id"], 1473352350088298497)
				self.assertAlmostEqual(row["ra_error"], 0.0390325976461172)
				self.assertEqual(row["nobs"], 32)
			</code>
		</regTest>
	</regSuite>
</resource>
