<resource schema="gedr3mock">
	<meta name="title">Gaia early DR3 Mock Catalogue (gedr3mock)</meta>
	<meta name="description">
		This catalogue is a simulation of the
		Gaia EDR3 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 scaled GDR2 errors.
		Additional magnitude limit per HEALpix maps are provided, based on the mode
		in the magnitude distribution of Gaia DR2 data.
	</meta>
	<meta name="creationDate">2019-12-01T13:08:00</meta>
	<meta name="schema-rank">20</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.;  Bailer-Jones, C.; Tio, P. D.;
		Cantat-Gaudin, T.;  Fouesneau, M.; Chen, Y.;  Andrae, R.;
		Girardi, L.;  Sharma, S.
	</meta>

	<meta name="source">2020PASP..132g4501R</meta>
	<meta name="doi">10.21938/dBrplG8I1KR7RyfkMXTyYA</meta>
	<meta name="contentLevel">Research</meta>
	<meta name="type">Simulation</meta>

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

	<meta name="referenceURL">\internallink{/tableinfo/gedr3mock.main}</meta>

	<FEED source="//procs#license-cc0" what="the Gaia eDR3 mock catalogue"/>

	<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="[Null] 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="[Null] Upper uncertainty bound of \description estimate
				from Apsis-\prog.  This is the 84th percentile of its PDF."/>
	</STREAM>


	<table id="parsec_props" onDisk="True" adql="True">
		<meta name="title">Parsec-based photometry and extinction
			for GeDR3 Mock</meta>
		<meta name="description">
			This table is intended to augment the Gaia photometry of GeDR3 Mock stars
			with other bands and extinctions (Sloan, Johnson and 2MASS). The
			grid was generated by binning all isochrones in logg, teff, and feh and
			taking the median values of all isochrone models that fall within one
			bin. We also report the median values of some astrophysical parameters so
			that one can check how far the actual star abundances deviate from the
			bin's median. For the extinction we report the extinction for the specific
			isochrone bin in a specific photometric band for 6 different values of
			monochromatic extinction, A_0, i.e. 1,2,3,5,10,20 mag.

			Sometimes stars in GeDR3 Mock depart from the isochrone grid, because,
			e.g., the feh value is outside of the grid or values have been
			interpolated by Galaxia in the catalog generation from the Parsec
			isochrones. Then the index_parsec is assigned to the nearest neighbour
			in log_lum and log_teff.
		</meta>

		<index columns="index_parsec"/>

		<column name="index_parsec" type="integer" required="True"
			ucd="meta.ref"
			tablehead="Phot. Ref."
			description="The primary key of the photometry table, useful
			for joining with index_parsec in gedr3mock.main.  This has the
			format LLLTTTFFF indexing bins in log_lum, log_teff, feh in the parsec
			isochrones.  To find the actual bin centers, see the log_lum, log_teff,
			and meh_ini columns."/>	

		<column name="meh_ini"
			ucd="phys.abund.z"
			tablehead="[Fe/H]_0"
			description="Log of initial model metalicity at the center of this bin."
			verbLevel="5"/>
		<column name="log_age"
			unit="log(yr)" ucd="time.age"
			tablehead="log(Age)"
			description="Median log of model star age at the parsec bin."
			verbLevel="5"/>
		<column name="m_ini"
			unit="solMass" ucd="phys.mass"
			tablehead="Mass_initial"
			description="Median of the initial (zero age) mass of all model stars in the parsec bin."
			verbLevel="5"/>
		<column name="m_act"
			unit="solMass" ucd="phys.mass"
			tablehead="Mass_current"
			description="Median of the current (at log_age) mass of all model star in the parsec bin."
			verbLevel="5"/>
		<column name="log_lum"
			unit="log(solLum)" ucd="phys.luminosity"
			tablehead="Lum"
			description="Median Log of luminosity of all model stars in the
				parsec bin."
			verbLevel="5"/>
		<column name="log_teff"
			unit="log(K)" ucd="phys.temperature.effective"
			tablehead="T_eff"
			description="Median Log of the effective temperature of all model stars in the parsec bin."
			verbLevel="5"/>
		<column name="log_grav"
			unit="log(m/s**2)" ucd="phys.gravity"
			tablehead="log(g)"
			description="Median Log of the surface gravity of all model stars in the parsec bin."
			verbLevel="5"/>

		<LOOP>
			<csvItems>
				bandName, bandLabel, descLabel, ucd
				G,        gaia_g,    Gaia G,    opt.V
				BP_bright,gaia_bpbr, Gaia BP,   opt.B
				BP_faint, gaia_bpft, Gaia BP,   opt.B
				RP,       gaia_rp,   Gaia RP,   opt.R
				RVS,      gaia_rvs,  Gaia RVS,  opt.R
				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
				L,        ubv_l,     Johnson L, ir.3-4um
				M,        ubv_m,     Johnson M, ir.4-8um
				u,        sloan_u,    SDSS u, opt.U
				g,        sloan_g,    SDSS g, opt.V
				r,        sloan_r,    SDSS r, opt.R
				i,        sloan_i,    SDSS i, opt.I
				z,        sloan_z,    SDSS z, opt.I
				J,        tmass_j,   2MASS J, ir.J
				H,        tmass_h,   2MASS H, ir.H
				K',       tmass_ks,  2MASS K', ir.K
			</csvItems>
			<events>
				<column name="\bandLabel"
					unit="mag" ucd="phot.mag;em.\ucd"
					tablehead="Mag. \bandName"
					description="Median absolute magnitude in the \descLabel band
						(note that no extinction is applied) in the respective
						isochrone bin."/>
			</events>
		</LOOP>
		<LOOP listItems="1 2 3 5 10 20" reexpand="True">
			<events>
				<LOOP>
					<csvItems>
						bandName, bandLabel, descLabel, ucd
						G,        gaia_g,  Gaia G,       opt.V
						BP_bright,gaia_bpbr, Gaia BP,      opt.B
						BP_faint, gaia_bpft, Gaia BP,      opt.B
						RP,       gaia_rp, Gaia RP,      opt.R
						RVS,      gaia_rvs, Gaia RVS,    opt.R
						u,        sloan_u, SDSS u,       opt.U
						g,        sloan_g, SDSS g,       opt.V
						r,        sloan_r, SDSS r,       opt.R
						i,        sloan_i, SDSS i,       opt.I
						z,        sloan_z, SDSS z,       opt.I
						J,        tmass_j, 2MASS J,      ir.J
						H,        tmass_h, 2MASS H,      ir.H
						Ks,       tmass_ks,2MASS Ks,     ir.K
						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
						JJ,       ubv_j, Johnson J,    ir.J
						JH,       ubv_h, Johnson H,    ir.H
						JK,       ubv_k, Johnson K,    ir.K
						JL,       ubv_j, Johnson L,    ir.3-4um
						JM,       ubv_m, Johnson M,    ir.4-8um
					</csvItems>
					<events>
						<column name="A0_\\item\\+_\bandLabel"
							unit="mag" ucd="phys.absorption;em.\ucd"
							tablehead="A_0(\bandName)"
							description="Median extinction in the \descLabel band for
								monochromatic extinction (A_0) of \\item mag
								for the respective isochrone bin"/>
					</events>
				</LOOP>
			</events>
		</LOOP>
	</table>

	<data id="import_parsec">
		<sources pattern="data/*_lookup.fits"/>
		<fitsTableGrammar/>
		<make table="parsec_props">
			<rowmaker idmaps="*">
				<map key="index_parsec">@parsec_index</map>
			</rowmaker>
		</make>
	</data>

	<table onDisk="True" id="generated_data" adql="True" 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
				l, double precision, deg, Galactic longitude, l
				b, double precision, deg, Galactic latitude, b
				smass, real, solMass, initial mass in solar masses, Mass_initial
				age, real, Gyr, Age of the star, Age
				logg,   real, log(cm/(s**2)), Surface gravity of star, log(g)
				phot_g_mean_mag,    real, mag, apparent G mag including extinction, G
				phot_bp_mean_mag, real, mag, apparent BP mag including extinction, BP
				phot_rp_mean_mag, real, mag, apparent RP mag including extinction, RP
				phot_rvs_mean_mag, real, mag, apparent RVS mag including extinction, RVS
				popid, smallint, , Population ID according to the Besancon model. Including SMC/LMC = 10 and stellar clusters = 11, PopID
				mact, real, solMass, actual (present) mass in solar masses, Mass_actual
				phot_g_mean_mag_error,     real, mag, error in G, error_G				
				a_g,       real, mag, Extinction in G, A_G
				a_bp,       real, mag, Extinction in BP, A_BP
				a_rp,       real, mag, Extinction in RP, A_RP
				a_rvs,       real, mag, Extinction in RVS, A_RVS
				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
				parallax_error, real, mas, parallax uncertainty in mas, error_parallax
				radial_velocity_error, real, km/s, Radial velocity uncertainty in km/s, error_rvs
				phot_g_n_obs, smallint, , Number of photometric observations (trained from DR2 scaled to DR3 time), Nobs
				visibility_periods_used, smallint, , Number of observations effectively used for the astrometric solutions (trained from DR2 scaled to DR3), VPU

			</csvItems>
			<events>
				<column name="\name" type="\type" required="True"
				unit="\unit"
				tablehead="\tablehead"
					description="\description"/>
			</events>
		</LOOP>
		<index columns="phot_g_mean_mag"/>
		<index columns="phot_bp_mean_mag"/>
		<index columns="phot_rp_mean_mag"/>
		<index columns="parallax"/>
		<index columns="index_parsec"/>
		<index columns="random_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="[GeDR3mock only] 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="d11y" type="smallint" required="True"
			ucd="stat.likelihood;obs"
			tablehead="Det%"
			description="[GeDR3mock only] Probability that this source can be
				detected by Gaia, estimated according to interpolated Table 1 in
				2019A&amp;A...621A..86B, in percent (this is below 100 for
				fainter sources of close pairs)."/>
	</table>

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

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

		<meta name="_longdoc" format="rst"><![CDATA[

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

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

			Uncertainty model
			'''''''''''''''''
			
			parallax_error, phot_g_mean_mag_error, radial_velocity error were
			trained on GDR2 data and predicted for the GeDR3mock using G, BP-RP and
			number of observations (which were trained on GDR2 data using the
			sky position). Then those uncertainties were scaled to the longer baseline
			of Gaia EDR3 data, i.e. 34 month. The other photometry and astrometry
			uncertainties are just linear relations to the ones predicted here.
			Again GDR2 data was used to best fit those simple relations. This
			is mainly done due to space limitations.
			
			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 gedr3mock.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 2019; 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::

				limits = [
					0,  161000525582565376,  190241590646669312,
					205827580287254528,  238741701382897664,  260424586078715904,
					281214461174349824,  376312424451538944,  419212653748027392,
					434001497458475008,  459290814653136896,  473006912971997184,
					506257553345216512,  518036827572011008,  530296897617788928,
					561471797476720640,  759627535381168128,  944006495668797440,
					1040369721951649792, 1255394304688390144, 1474976775439122432,
					1741324705534574592, 1790290699963334656, 1808727482736574464,
					1819886048289751040, 1822801609529229312, 1825109106478809088,
					1827664749458882560, 1832812559820914688, 1838462125442334720,
					1857229242740244480, 1864013813599174656, 1871967199678169088,
					1929099026448252928, 1960210463870418944, 1971591440010051584,
					1980320050506104832, 1997472672417579008, 2006800825988415488,
					2016674749643489280, 2020634984368308224, 2023410014277861376,
					2026188170923606016, 2029748561373036544, 2031976584247771136,
					2034011161795493888, 2037941537907671040, 2045798957237403648,
					2052181725315858432, 2059282715005419520, 2063545693384998912,
					2073126425392578560, 2080238410198417408, 2092100903711539200,
					2128972270234763264, 2163964193428996096, 2171955100342288384,
					2179776957342810112, 2191148037877792768, 2202326978755821568,
					2211928292246683648, 2231575809120796672, 2286857948095315968,
					2639650169561284608, 2844586217717104640, 2928305335158439936,
					2947826648713527296, 3014250448249946112, 3033455136815972352,
					3047843655214694400, 3059447729135550464, 3101322766918352896,
					3113168321080459264, 3128946862694858752, 3154598675129303040,
					3242442335564333056, 3328470908460335104, 3351027045906776064,
					3370789496105730048, 3398130467638083584, 3428571374765998080,
					3445687163037941760, 3480352737437155328, 3733830299813937152,
					4035615867629731840, 4036828663314907136, 4037599867642576896,
					4038530810393919488, 4039095306535567360, 4039591701675769856,
					4040246907526709248, 4040707156222148608, 4041261550600716288,
					4041667820147179520, 4042098966144221184, 4042414835219038208,
					4042752179130335232, 4043060523422449664, 4043363473235640320,
					4043724868963794944, 4044015036954312704, 4044364131896131584,
					4045435915215044608, 4045963199760039936, 4046800684023021568,
					4048057700691476480, 4048868040761147392, 4049171128013291520,
					4049506513419501568, 4049809463232692224, 4050069944409260032,
					4050254799801679872, 4050418042918666240, 4050637910884483072,
					4050833967551610880, 4051108433141694464, 4051576584576958464,
					4052155511808720896, 4052449425010720768, 4052746739826819072,
					4053179122774441984, 4054090617913868288, 4056095405568425984,
					4056328948710113280, 4056576201387409408, 4058360193363214336,
					4059134971103674368, 4059773409402290176, 4060841035192860672,
					4061834065991434240, 4062363893157068800, 4062492261139611648,
					4062658802791481344, 4062844929494220800, 4063012433218764800,
					4063230067801587712, 4063918843116912640, 4064646857253453824,
					4064985884791930880, 4065414763046240256, 4066361579996708864,
					4067952504602624000, 4068619805081468928, 4069903038230298624,
					4071285845900918784, 4073456488012578816, 4076157988082024448,
					4077170191614607360, 4077951291546927104, 4079694739031457792,
					4084865329900027904, 4088450768598728704, 4089692289025179648,
					4090370584620302336, 4091069564777922560, 4092166636864274432,
					4093254363101790208, 4094818177874132992, 4096497029050531840,
					4097917357555449856, 4099795632653336576, 4101931537069506560,
					4103357569290993664, 4104180175787261952, 4105068890420150272,
					4106540724172881920, 4107362780913336320, 4108191091126173696,
					4109639525897076736, 4110886028485591040, 4112922083502063616,
					4116166123840339968, 4117045630063345664, 4118075357062496256,
					4119249051365408768, 4120552178802753536, 4123114934248669184,
					4125097937829101568, 4132304137037545472, 4138499163505557504,
					4144234456674205696, 4145768687711813632, 4148283751840874496,
					4151153339750416384, 4154588729471664128, 4156720235841323008,
					4160109549153419264, 4164476053424701440, 4173161748607533056,
					4183065084198649856, 4194740488936357888, 4201030485721219072,
					4203246001651187712, 4204504083471532032, 4207748673565622272,
					4214137351519076352, 4236123701424160768, 4249140888304877568,
					4252016626607587328, 4252794771602407424, 4253810170590658560,
					4254961050027294720, 4256649796808343552, 4259413384925020160,
					4261775445139128320, 4263664062518263808, 4265313123801497600,
					4267381442612297728, 4269142035606274048, 4274763254443540480,
					4280098668977061888, 4285079628449579008, 4288820063928057856,
					4292441202394923008, 4294774812745662464, 4297876672486572032,
					4302944081060823040, 4307653873478139904, 4311003638731374592,
					4313171051027628032, 4315005620538310656, 4317185780297498624,
					4319582887444742144, 4322968180667449344, 4346606340634836992,
					4372445757240770560, 4414351272111505408, 4471222102308945920,
					4479473318600114176, 4490903429165613056, 4505091733368864768,
					4508939336871313408, 4513839894556049408, 4517168391131234304,
					4523225497609437184, 4537650746568474624, 4587791466092298240,
					4651041147358019584, 4651929999429861376, 4654742378375020544,
					4657309325709017088, 4658131141931302912, 4659220586155737088,
					4685905458483953664, 4752009334496428032, 5048627575618797568,
					5219424715445108736, 5233961496114888704, 5237655511586832384,
					5241283796879278080, 5247578260430127104, 5253317539328425984,
					5255512336336158720, 5259769920236814336, 5297659812484481024,
					5305849353045278720, 5309762411849318400, 5313139321295863808,
					5323313445985058816, 5331000028695625728, 5335160855573037056,
					5337642556396142592, 5340266987572428800, 5343656403963740160,
					5350462621457842176, 5354722576180445184, 5359458413279444992,
					5372887470343979008, 5404963145103966208, 5410571788276989952,
					5424220988185247744, 5442675225705578496, 5508257452170149888,
					5521906755157622784, 5529933739796201472, 5540320791784062976,
					5546108208675815424, 5583112135069663232, 5595949689238192128,
					5601613136193912832, 5614335276001263616, 5621941697442217984,
					5640128856716214272, 5671690544149954560, 5700966140751118336,
					5716945240158371840, 5766837504414056448, 5792882426615169024,
					5802883584381419520, 5818014616726274048, 5824544513204420608,
					5827317722047840256, 5831197726783569920, 5833472822499868672,
					5834633528821678080, 5835820554703077376, 5836584268607782912,
					5844699317255798784, 5848652851831635968, 5850924511574097920,
					5852524266632773632, 5854022419945095168, 5857492066325495808,
					5858927272597127168, 5860855678553292800, 5862852907065409536,
					5865046604561514496, 5869000963771072512, 5871370892365266944,
					5874081463405641728, 5875585801470869504, 5876931225746145280,
					5879421001107767296, 5881995988620541952, 5884080800105758720,
					5887131841793622016, 5888770698234560512, 5890363031589748736,
					5893058312546549760, 5895628043019354112, 5900250699140169728,
					5904354901168750592, 5913874541561511936, 5919725420890030080,
					5924441569858945024, 5926972130230009856, 5929102227850395648,
					5930678309049335808, 5931684087310843904, 5932349738522247168,
					5933174578401509376, 5934095969145585664, 5935796020280557568,
					5937111070547116032, 5938525764054941696, 5940292851039469568,
					5942406318546485248, 5944115818609508352, 5947882333129408512,
					5950513670613106688, 5952165721193578496, 5953570931413614592,
					5956003807048499200, 5957924550783008768, 5959238638976892928,
					5960370448758734848, 5961583038285479936, 5963056933622513664,
					5965315330505965568, 5968019063958405120, 5969643214431322112,
					5971116078976204800, 5972674464909885440, 5976388340310605824,
					5978043002231193600, 5979719860542767104, 5980600672435830784,
					5983573786237075456, 5986047549960617984, 5988772071054770176,
					5991739515499184128, 5995044510013325312, 6000602713090424832,
					6009501438651138048, 6018305022096310272, 6022181968815325184,
					6026558643569164288, 6028494643027509248, 6029656311421992960,
					6032022529164443648, 6035830893845676032, 6046287902260854784,
					6054119551786811392, 6057337650522619904, 6060242697682157568,
					6064027697741299712, 6070987949942505472, 6076648098363342848,
					6090704048854401024, 6105062502482051072, 6131616773444730880,
					6189459537561387008, 6225770977788166144, 6260198885877088256,
					6362808609516027904, 6442940742070435840, 6618300339755941888,
					6652038613536079872, 6679890273859796992, 6706241753646628864,
					6716109767426703360, 6722991267107569664, 6726135492405886976,
					6728692372336541696, 6733950168221089792, 6736718979017998336,
					6755124150831939584, 6762744900283793408, 6780826540801261568,
					6866936202679812096, 8931576916874782720]

			Please don't use it to dump the catalog yourself (see `Dump of the
			catalog`_ for that); it might still come
			in handy if you filter out a large part of the objects but still have
			more than 20 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
			''''''''''''''

			These were calculated from the stellar spectra using the nominal RVS
			passband. As it is uncertain whether this column will be provided in Gaia EDR3
			it might still be useful for selection of RVS sample which can be done to the
			real catalogs by equation 2 and 3 of :bibcode:`2018A&A...616A...1G`.
			This is going to be severely off outside of 0.1<BP-G<1.7 (which only affects
			a negligible amount 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 400 gigabytes, and
			dealing with this data volume is nontrivial.
			
			Having said that: The dump files are available from
			\internallink{gedr3mock/q/download}.

			If you would like to split the dump into more manageable chunks, use
			something like::

				zcat dump.gz | split -a4 -l 5000 -d - part
		]]></meta>

		<foreignKey source="index_parsec" inTable="parsec_props"
			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="[GeDR3mock only] apparent magnitude of the RVS band."/>

		<column name="phot_g_mean_mag_error"
			unit="mag" ucd="phot.color;em.opt.V"
			tablehead="G error"
			description="[GeDR3mock only] G mag error approximated by the symmetrised flux error."/>

		<column name="phot_bp_mean_mag_error"
			unit="mag" ucd="phot.color;em.opt.B"
			tablehead="BP error"
			description="[GeDR3mock only] BP mag error (generated by scaling the G mag error with
				an empirical factor of 19.854 derived from GDR2)."/>
		<column name="phot_rp_mean_mag_error"
			unit="mag" ucd="phot.color;em.opt.R"
			tablehead="RP error"
			description="[GeDR3mock only] RP mag error (generated by scaling the G mag error with
				an empirical factor of 9.1205 derived from GDR2)."/>
		<column name="phot_rvs_mean_mag_error"
			unit="mag" ucd="phot.color;em.opt.R"
			tablehead="RVS error"
			description="[GeDR3mock only] RVS mag error (generated by scaling the G mag error with
				with 30; this is essentially a wild guess which is probably too low
				if RVS magnitudes are provided at all)."/>

		<column name="rv_nb_transits" type="smallint" required="True"
			ucd="meta.number;obs;spect.dopplerVeloc"
			tablehead="#RV"
			description="[NULL] 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="[NULL] 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="[NULL] 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="[NULL] Excess noise of the source"
			note="en"/>
		<column name="astrometric_excess_noise_sig"
			ucd="stat.value"
			tablehead="Sig. Noise"
			description="[NULL] Significance of excess noise"
			note="en"/>

		<column name="astrometric_n_obs_ac" type="smallint" required="True"
			ucd="meta.number"
			tablehead="#Obs AC"
			description="[NULL ]Total number of observations AC"
			note="n"/>
		<column name="astrometric_n_obs_al" type="smallint" required="True"
			ucd="meta.number"
			tablehead="#Obs AL"
			description="[NULL] 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="[NULL] 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="[NULL] 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="[NULL] 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="[NULL] Number of good observations AL"
			note="ng"/>
		<column name="astrometric_chi2_al"
			ucd="stat.fit.chi2"
			tablehead="χ² AL"
			description="[NULL] 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="[NULL] 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="[NULL] 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="[NULL] 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="visibility_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="[NULL] 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="[NULL] 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="[NULL] 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="[NULL] 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="[NULL] Mean astrometric weight of the source"
			note="maw"/>
		<column
			name="astrometric_weight_al"
			ucd="stat.weight;stat.mean" unit="mas**-2"
			description="[NULL] Mean astrometric weight of the source"
			tablehead="Weight AL"
			note="maw"/>
		<column name="duplicated_source" type="smallint" required="True"
			tablehead="Dup?"
			description="[NULL] During data processing, this source happened to have been
			duplicated and one source only has been kept."
			note="dup"/>
		<column original="d11y"/>

		<column name="ra_dec_corr"
			ucd="stat.correlation"
			tablehead="RA-Dec-Corr"
			description="[NULL] Correlation between right ascension and declination"
			note="cr"/>
		<column name="ra_pmra_corr"
			ucd="stat.correlation"
			tablehead="RA-PM(RA) Corr."
			description="[NULL] 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="[NULL] 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="[NULL] 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="[NULL] 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="[NULL] 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="[NULL] Correlation between right ascension and parallax"
			note="cr"/>
		<column name="dec_parallax_corr"
			ucd="stat.correlation"
			tablehead="RA-Dec Corr."
			description="[NULL] Correlation between declination and parallax"
			note="cr"/>
		<column name="parallax_pmra_corr"
			ucd="stat.correlation"
			tablehead="π-PM(RA) Corr."
			description="[NULL] Correlation between parallax and proper motion in right
				ascension"
			note="cr"/>
		<column name="parallax_pmdec_corr"
			ucd="stat.correlation"
			tablehead="π-PM(Dec) Corr."
			description="[NULL] 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="[NULL] Mean position angle of scan directions across
						the source"
					note="sk"/>
				<column name="scan_direction_strength_\item"
					tablehead="Scan conc. \item"
					description="[NULL] 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="[NULL] 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="[NULL] 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="a_bp"
			unit="mag"
			ucd="phys.absorption"
			tablehead="A_BP"
			description="the line-of-sight extinction in the BP-band"
			prog="Priam"/>
		<FEED source="apsispars"
			name="a_rp"
			unit="mag"
			ucd="phys.absorption"
			tablehead="A_RP"
			description="the line-of-sight extinction in the RP-band"
			prog="Priam"/>
		<FEED source="apsispars"
			name="a_rvs"
			unit="mag"
			ucd="phys.absorption"
			tablehead="A_RVS"
			description="the line-of-sight extinction in the RVS-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="[GeDR3mock only] Fe/H as log10 of solar ratio ('dex')"/>
		<column name="a0"
			unit="mag" ucd="phys.absorption"
			tablehead="a_0"
			description="[GeDR3mock only] Monochromatic extinction at lambda = 547.7nm"/>
		<column name="initial_mass"
			unit="solMass" ucd="phys.mass"
			tablehead="Mass"
			description="[GeDR3mock only] Initial mass of the star"/>
		<column name="current_mass"
			unit="solMass" ucd="phys.mass"
			tablehead="current Mass"
			description="[GeDR3mock only] Current mass of the star"/>
		<column name="age"
			unit="Gyr" ucd="time.age"
			tablehead="Age"
			description="[GeDR3mock only] Age of the star"/>
		<column name="logg"
			unit="log(cm/(s**2))" ucd="phys.gravity"
			tablehead="log(g)"
			description="[GeDR3mock only] 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="popid" type="smallint" required="True"
			ucd="src.class"
			tablehead="Pop (Besc)"
			description="[GeDR3mock only] Population ID according to the Besancon model.
				10=SMC/LMC, 11=stellar clusters"/>
		<column name="pm_total"	
			unit="mas/yr" ucd="pos.pm"
			tablehead="Total proper motion"
			description="[GeDR3mock only] Total proper motion of the star, i.e.,
				sqrt(pmra^2+pmdec^2)."/>
		<column name="index_parsec" type="integer" required="True"
			tablehead="Phot." ucd="meta.id.cross"
			description="[GeDR3mock only] Foreign key into the photometry/extinction table."/>

		<FEED source="//procs#declare-indexes-from"
			sourceTables="generated_data"/>

		<viewStatement><![CDATA[
			CREATE VIEW \curtable AS (
				SELECT \colNames FROM (
					SELECT
						source_id,
						ra,
						dec,
						l,
						b,
						pm_ra as pmra,
						pm_dec as pmdec,
						parallax,
						phot_g_mean_mag,
						phot_rp_mean_mag,
						phot_bp_mean_mag,
						phot_rvs_mean_mag,
                    	phot_g_mean_mag_error,
                    	phot_g_mean_mag_error*19.854 AS phot_bp_mean_mag_error,
                    	phot_g_mean_mag_error*9.1205 AS phot_rp_mean_mag_error,
                    	phot_g_mean_mag_error*30 AS phot_rvs_mean_mag_error,
                    	visibility_periods_used,
                    	phot_g_n_obs,
                    	parallax_error,
                    	0.647 * parallax_error * 1.5206 AS pmdec_error,
                    	0.647 * parallax_error * 1.7099 AS pmra_error,
                    	parallax_error * 0.8114 AS ra_error,
                    	parallax_error * 0.7503 AS dec_error,
                    	radial_velocity_error,					
						power(10, 0.4 * (25.6884 - phot_g_mean_mag)) AS phot_g_mean_flux,
						power(10, 0.4 * (25.3514 - phot_bp_mean_mag)) AS phot_bp_mean_flux,
						power(10, 0.4 * (24.7619 - phot_rp_mean_mag)) AS phot_rp_mean_flux,
						-1 * (power(10, 0.4 * (25.6884 - (phot_g_mean_mag + phot_g_mean_mag_error))) - power(10, 0.4 * (25.6884 - phot_g_mean_mag))) AS phot_g_mean_flux_error,
						-1 * (power(10, 0.4 * (25.3514 - (phot_bp_mean_mag + phot_g_mean_mag_error*19.854))) - power(10, 0.4 * (25.3514 - phot_bp_mean_mag))) AS phot_bp_mean_flux_error,
						-1 * (power(10, 0.4 * (24.7619 - (phot_rp_mean_mag + phot_g_mean_mag_error*9.1205))) - power(10, 0.4 * (24.7619 - phot_rp_mean_mag))) AS phot_rp_mean_flux_error,
						power(10, 0.4 * (25.6884 - phot_g_mean_mag)) / (-1 * (power(10, 0.4 * (25.6884 - (phot_g_mean_mag + (phot_g_mean_mag_error)))) - power(10, 0.4 * (25.6884 - phot_g_mean_mag)))) AS phot_g_mean_flux_over_error,
						power(10, 0.4 * (25.3514 - phot_bp_mean_mag)) / (-1 * (power(10, 0.4 * (25.3514 - (phot_bp_mean_mag + (phot_g_mean_mag_error*19.854)))) - power(10, 0.4 * (25.3514 - phot_bp_mean_mag)))) AS phot_bp_mean_flux_over_error,
						power(10, 0.4 * (24.7619 - phot_rp_mean_mag)) / (-1 * (power(10, 0.4 * (24.7619 - (phot_rp_mean_mag + (phot_g_mean_mag_error*9.1205)))) - power(10, 0.4 * (24.7619 - phot_rp_mean_mag)))) AS phot_rp_mean_flux_over_error,
						phot_bp_mean_mag - phot_rp_mean_mag AS bp_rp,
						phot_bp_mean_mag - phot_g_mean_mag AS bp_g,
						phot_g_mean_mag - phot_rp_mean_mag AS g_rp,
						radial_velocity,
						a_bp - a_rp AS e_bp_min_rp_val,
						lum AS lum_val,
						feh,
						teff AS teff_val,
						a_g as a_g_val,
						a_bp as a_bp_val,
						a_rp as a_rp_val,
						a_rvs as a_rvs_val,	
						smass as initial_mass,
						mact as current_mass,
						popid,
						age/1e9 AS age,
						logg,
						a0,
						sqrt(pm_ra*pm_ra+pm_dec*pm_dec) AS pm_total,
						(sqrt((power(10, lum) * 3.839e+26)/(4 * 3.141592653589793 * 5.67037321 * 1e-8)) / (teff * teff)) / 6.955e8 AS radius_val,
						index_parsec as index_parsec,
						random_index,
						ROUND(phot_g_n_obs * 0.09618)::INTEGER AS phot_rp_n_obs,
						ROUND(phot_g_n_obs * 0.09219)::INTEGER AS phot_bp_n_obs,
						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,
						COALESCE(d11y, 100) AS d11y,
						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 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 a_bp_percentile_lower,
						NULL::real AS a_bp_percentile_upper,
						NULL::real AS a_rp_percentile_lower,
						NULL::real AS a_rp_percentile_upper,
						NULL::real AS a_rvs_percentile_lower,
						NULL::real AS a_rvs_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
				) vals)
		]]></viewStatement>
	</table>

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

	<table id="detectabilities" onDisk="True" temporary="True">
		<meta name="description">A temporary table used to insert
			detectability information into generated_data.  Not used
			in operations.</meta>
		<column original="generated_data.source_id"/>
		<column name="d11y" type="smallint">
			<values nullLiteral="100"/>
		</column>
	</table>

	<data id="insert_d11y" auto="False">
		<sources pattern="data/det*.csv"/>
		<csvGrammar topIgnoredLines="1" names="source_id,d11y"/>
		<make table="detectabilities">
			<script type="postCreation" lang="SQL">
				UPDATE \schema.generated_data AS t
				SET d11y=a.d11y
				FROM detectabilities as a
				WHERE t.source_id=a.source_id
			</script>
		</make>
	</data>

	<STREAM id="maglim-per-band">
		<column name="maglim_\band"
			unit="mag" ucd="instr.sensitivity"
			tablehead="Mode \upper{\band}"
			description="The mode of the \upper{\band} magnitude distribution
				in the respective HEALPix"/>
		<column name="starcount_\band" type="integer" required="True"
			ucd="meta.number"
			tablehead="#Stars"
			description="The number of stars in the respective HEALPix bin with
				G&lt;20.7"/>
		<column name="maglim_\band\+_density_threshold"
			unit="mag" ucd="instr.sensitivity"
			tablehead="Mode \upper{\band} HD"
			description="The mode of the \upper{\band} magnitude distribution in the
				respective HEALPix. In HEALPixes with less than 1e5 stars per square
				degree the limit is set to 20.7 mag. This should reduce the noise
				of the mode estimator due to Poisson noise in low density areas."/>

		<column name="maglim_\band\+_parallax"
			unit="mag" ucd="instr.sensitivity"
			tablehead="Mode \upper{\band}"
			description="The mode of the \upper{\band} magnitude distribution
				in the respective HEALPix when also requiring a parallax measurement"/>
		<column name="starcount_\band\+_parallax" type="integer" required="True"
			ucd="meta.number"
			tablehead="#Stars"
			description="The number of stars in the respective HEALPix bin with
				G&lt;20.7 and parallax measurement"/>
		<column name="maglim_\band\+_parallax_density_threshold"
			unit="mag" ucd="instr.sensitivity"
			tablehead="Mode \upper{\band} HD"
			description="The mode of the \upper{\band} magnitude distribution in the
				respective HEALPix when also requiring a parallax measurement. In HEALPixes with less than 1e5 stars per square
				degree the limit is set to 20.7 mag. This should reduce the noise
				of the mode estimator due to Poisson noise in low density areas."/>

		<column name="maglim_\band\+_color"
			unit="mag" ucd="instr.sensitivity"
			tablehead="Mode \upper{\band}"
			description="The mode of the \upper{\band} magnitude distribution
				in the respective HEALPix when also requiring a BP and RP measurement"/>
		<column name="starcount_\band\+_color" type="integer" required="True"
			ucd="meta.number"
			tablehead="#Stars"
			description="The number of stars in the respective HEALPix bin with
				G&lt;20.7 and BP and RP measurement"/>
		<column name="maglim_\band\+_color_density_threshold"
			unit="mag" ucd="instr.sensitivity"
			tablehead="Mode \upper{\band} HD"
			description="The mode of the \upper{\band} magnitude distribution in the
				respective HEALPix when also requiring a BP and RP measurement. In HEALPixes with less than 1e5 stars per square
				degree the limit is set to 20.7 mag. This should reduce the noise
				of the mode estimator due to Poisson noise in low density areas."/>

		<column name="maglim_\band\+_parallax_color"
			unit="mag" ucd="instr.sensitivity"
			tablehead="Mode \upper{\band}"
			description="The mode of the \upper{\band} magnitude distribution
				in the respective HEALPix when also requiring a parallax and BP and RP measurement"/>
		<column name="starcount_\band\+_parallax_color" type="integer" required="True"
			ucd="meta.number"
			tablehead="#Stars"
			description="The number of stars in the respective HEALPix bin with
				G&lt;20.7 and parallax and BP and RP measurement"/>
		<column name="maglim_\band\+_parallax_color_density_threshold"
			unit="mag" ucd="instr.sensitivity"
			tablehead="Mode \upper{\band} HD"
			description="The mode of the \upper{\band} magnitude distribution in the
				respective HEALPix when also requiring a parallax and BP and RP measurement. In HEALPixes with less than 1e5 stars per square
				degree the limit is set to 20.7 mag. This should reduce the noise
				of the mode estimator due to Poisson noise in low density areas."/>
	</STREAM>

	<STREAM id="maglim-for-level">
		<table id="maglim_\level" onDisk="True" adql="True">
			<meta name="description" format="rst">
				This table gives empirical magnitude limits for
				G and BP bands derived from Gaia DR2 with G &lt; 20.7 mag for HEALPixels
				of \level (scale roughly ~\resolution degrees). For each band
				we have 4 different variants:
				
				(1) no additional condition,
				(2) parallax available,
				(3) BP-RP available,
				(4) parallax and BP-RP available.
				
				For BP mag limits we also require that BP is available. The magnitude
				limits are approximated by the mode of the magnitude distribution in a
				specific HEALpix. Since this mode estimator is prone to Poisson noise
				in low density areas we report the magnitude limits in two flavours:

				(a) directly the mode estimator
				(b) the same as the mode estimator,

				except that in healpixel with a stellar density below 1e5 sources per
				square degree the limit is arbitrarily set to 20.7 mag. These magnitude
				limits were created using the `gdr2_completeness package`_ and users
				are encouraged to create custom-made magnitude limits with specific
				conditions, e.g. RVS sample with good parallaxes.

				.. _gdr2_completeness package: https://github.com/jan-rybizki/gdr2_completeness
			</meta>

			<index columns="hpx"/>
			<column name="hpx" type="integer" required="True"
				ucd="pos.healpix"
				tablehead="HEALPix"
				description="Level \level HEALPix for which the magnitude
					limit applies."/>

			<FEED source="maglim-per-band" band="g"/>
			<FEED source="maglim-per-band" band="bp"/>
		</table>

		<data id="import_maglim_\level" auto="False">
			<sources pattern="data/maglim_level_\level.fits"/>
			<fitsTableGrammar/>
			<make table="maglim_\level"/>
		</data>
	</STREAM>

	<FEED source="maglim-for-level" level="5" resolution="2"/>
	<FEED source="maglim-for-level" level="6" resolution="1"/>
	<FEED source="maglim-for-level" level="7" resolution="0.5"/>

	<STREAM id="rvs_sample_template">
		<table id="rvs_sample_\bias" onDisk="True" primary="source_id"
				adql="hidden">
			<meta name="description" format="rst">
				This table lists source_ids of gedr3mock objects that
				are drawn at random using to the selection function found in
				Gaia DR2 for stars with a full six-parameter solution as derived
				in bibcode`TODO`. It is intended to be used to test selection
				effects in observables on underlying stellar population parameter
				distributions.

				The completeness function was applied in spatial bins of HEALPix level
				5, and bins of one each in GRVS magnitude and G-GRP color, yielding
				7.2e6 sources.

				\otherblurb
			</meta>

			<foreignKey inTable="generated_data" source="source_id"
				metaOnly="True"/>
			<column original="generated_data.source_id"
				description="Identifier of a star within the unbiased RVS sample."/>
		</table>

		<data id="import-rvs-\bias">
			<sources>rvsdata/source_ids_gedr3mock_rvs_sample\srctag.csv</sources>
			<csvGrammar topIgnoredLines="1" names="source_id"/>
			<make table="rvs_sample_\bias"/>
		</data>
	</STREAM>

	<FEED source="rvs_sample_template"
		bias="unbiased"
		srctag=""
		otherblurb="This table gives an unbiased selection. The
			gedr3mock.rvs_sample_pi_rvs table reflects a sample biased to match the
			mean parallax of the RVS sample in each bin, and the
			gedr3mock.rvs_sample_pi_all reflects a sample biased to match the mean
			parallax of the entire Gaia DR2 in each bin."/>

	<FEED source="rvs_sample_template"
		bias="pi_rvs"
		srctag="_biased_rvs_parallax"
		otherblurb="This table gives a selection biased so as to match its
			mean parallax to the the mean parallax of the RVS sample in Gaia DR2
			in each bin. The gedr3mock.rvs_sample_pi_random table reflects an
			unbiased sample, and gedr3mock.rvs_sample_pi_all reflects a sample biased
			to match the mean parallax of the entire Gaia DR2 in each bin."/>

	<FEED source="rvs_sample_template"
		bias="pi_all"
		srctag="_biased_all_parallax"
		otherblurb="This table gives a selection biased so as to match its
			mean parallax to the the mean parallax of Gaia DR2 in each bin. The
			gedr3mock.rvs_sample_pi_random table reflects an unbiased sample,
			and gedr3mock.rvs_sample_pi_rvs reflects a sample biased to match
			the mean parallax of the RVS sample in Gaia DR2 in each bin."/>


	<service id="download" allowed="form,static"
			defaultRenderer="form">
		<meta name="title">Gaia early DR3 Mock Bulk Download</meta>
		<template key="form">res/downloadguard.html</template>
		<pythonCore>
			<inputTable>
				<inputKey type="text" name="input" multiplicity="single"
					tablehead="I read the warning"
					description="Type in 'yes' here to pull the data"/>
			</inputTable>
			<outputTable/>
			<coreProc>
				<code>
					from gavo import svcs

					if inputTable.getParam("input")=="yes":
						raise svcs.WebRedirect(
							"http://vo.ari.uni-heidelberg.de/gedr3mock/dump.gz?")
					else:
						raise base.ValidationError("This must be 'yes' (without any"
							" quotes)", "input")
				</code>
			</coreProc>
		</pythonCore>

		<property name="staticData">data</property>
	</service>

	<data id="pub" auto="False">
		<make table="main"/>
		<make table="parsec_props"/>
		<make table="maglim_5"/>
		<make table="maglim_6"/>
		<make table="maglim_7"/>
		<make table="rvs_sample_pi_rvs"/>
		<make table="rvs_sample_pi_all"/>
		<make table="rvs_sample_unbiased"/>
		<publish sets="local,ivo_managed"/>
	</data>

	<regSuite title="GeDR3mock regression">
		<regTest title="GeDR3mock main+parsec join looks plausible.">
			<url parSet="TAP"
				QUERY="select * from gedr3mock.main
					join gedr3mock.parsec_props
					using (index_parsec)
					where source_id=4258885035228135485"
				>/tap/sync</url>
			<code>
				row = self.getFirstVOTableRow()
				self.assertAlmostEqual(row["ra"], 283.319953674879)
				self.assertAlmostEqual(row["phot_bp_mean_flux_error"], 1.0847477)
				self.assertEqual(row["random_index"], 1372887323)
				self.assertEqual(row["phot_g_n_obs"], 181)
				self.assertAlmostEqual(row["a_g_val"], 0.191156)
				self.assertAlmostEqual(row["A0_2_sloan_u"], 3.1199998855)
				self.assertEqual(row["d11y"], 100)
			</code>
		</regTest>

		<regTest title="GeDR3mock detectabilties applied.">
			<url parSet="TAP"
				QUERY="SELECT source_id, d11y FROM gedr3mock.main WHERE
					source_id between 4256653300000000000 and 4256653400000000000
					and d11y&lt;100">/tap/sync</url>
			<code>
				rows = self.getVOTableRows()
				self.assertTrue(
					{u'source_id': 4256653301501657248, u'd11y': 0}
					in rows)
			</code>
		</regTest>

		<regTest title="Dump service redirects to apache.">
			<url parSet="form" input="yes">/gedr3mock/q/download</url>
			<code>
				self.assertHTTPStatus(301)
				self.assertHeader("location",
					"http://vo.ari.uni-heidelberg.de/gedr3mock/dump.gz?")
			</code>
		</regTest>

		<regTest title="RVS sample is present">
			<url parSet="TAP" QUERY="SELECT source_id FROM
				gedr3mock.generated_data
				NATURAL JOIN gedr3mock.rvs_sample_unbiased
				WHERE DISTANCE(ra, dec, 280.50, -4.77)&lt;0.01
					AND teff BETWEEN 4000 and 4300"
				>/tap/sync</url>
			<code>
				ids = [r["source_id"] for r in self.getVOTableRows()]
				self.assertEqual(ids, [4256687661240025127])
			</code>
		</regTest>
	</regSuite>
</resource>
