<resource schema="xpparams" resdir=".">
	<meta name="creationDate">2023-06-12T11:51:04Z</meta>
	<meta name="schema-rank">20</meta>

	<meta name="title">Parameters of 220 million stars from Gaia BP/RP (XP) spectra</meta>
	<meta name="description">
		We present astrophysical parameters of
		220 million stars, based on Gaia XP spectra and
		near-infrared photometry from 2MASS and WISE. Instead of using ab initio
		stellar models, we develop a data-driven model of Gaia XP spectra as a
		function of the stellar parameters, with a few straightforward built-in
		physical assumptions. This resource is a VO re-publication of the resulting
		catalog of stellar parameters.  For bulk downloads, the covariances, the
		trained model, and more, see https://zenodo.org/record/7811871.
	</meta>
	<meta name="subject">stellar-properties</meta>
	<meta name="subject">milky-way-galaxy</meta>
	<meta name="subject">sky-surveys</meta>

	<meta name="creator">Zhang, Xiangyu</meta>
	<meta name="creator">Green, G.M.</meta>
	<meta name="creator">Rix, Hans-Walter</meta>

	<meta name="instrument">Gaia RP/BP Spectrometer</meta>
	<meta name="facility">Gaia</meta>

	<meta name="source">2023MNRAS.524.1855Z</meta>
	<meta name="contentLevel">Research</meta>
	<meta name="type">Catalog</meta>

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

	<meta name="isPreviousVersionOf" ivoId="ivo://org.gavo.dc/xpparams2/q/cone"
		>Unveiling the Milky Way dust extinction curve in 3D</meta>

	<meta name="_longdoc" format="rst"> <![CDATA[
		Example: A Dust Map
		-------------------
		As an example of what one can do with this data, consider the following
		ADQL query to generate an all-sky extinction map for stars at
		a distance between 400 pc and 600 pc::

			select source_id/140737488355328 as hpx, avg(ext) as meanext
			from xpparams.main
			where
			mod_parallax between 1.67 and 2.5
				and quality_flags < 8
				and mod_parallax/err_mod_parallax > 5
				and err_ext < 0.2
			group by hpx

		This exploits the fact that Gaia source ids can be `converted to
		HEALPixes`_ to produce a map and shows how to do useful quality cuts
		that allow relatively careless use of the data.

		If you use TOPCAT to execute this on the GAVO DC TAP service (select
		Asynchronous mode and make sure you set Max Rows to something more than
		50000, because that is how many pixels our map will have), you can
		do a sphere plot, then add a Healpix control.  In it, select the table
		resulting from this query, manually set the HEALPix level to 6 and
		configure the Axis to Aitoff projection in the Galactic system to
		arrive at a plot like this:

		.. _converted to HEALPixes: https://dc.g-vo.org/gedr3dist/q/cone/info#note-id
		.. image:: /static/img/xpparams-dustmap.png

		Example: Metallicity of a Globular Cluster
		------------------------------------------

		Try the following query yielding data on Omega Cen and illustrating how
		to match with the local Gaia DR3 catalogue in order to constrain proper
		motions::

			SELECT
				xpp.*,
				g.pmra, g.pmdec, g.phot_g_mean_mag, g.phot_bp_mean_mag,
				g.phot_rp_mean_mag
			FROM xpparams.main as xpp JOIN gaia.edr3lite as g USING (source_id)
			WHERE
				distance(xpp.ra, xpp.dec, 201.697, -47.479472)<0.5
				AND distance(g.pmra, g.pmdec, -3.24, -6.73)<1.25
				AND xpp.quality_flags < 8
				AND xpp.mod_parallax/xpp.err_mod_parallax > 5.
				AND xpp.feh_confidence > 0.5
				AND xpp.err_fe_h < 0.2

		Again in TOPCAT, try a 3d plot of RA, Dec and 1/mod_parallax. You will want
		to manually cut the parallax axis a bit to get rid of (presumably spurious)
		background stars.  Make fe_h the aux axis in the “Form“ tab.  If you look
		“from above“, you will see that the quality cuts have punched a hole into
		the cluster.  If you look from the side, you can see that the cluster stars
		are (by and large) rather metal-poor compared to foreground stars:


		.. image:: /static/img/xpparams-omegacen.png
	]]></meta>

	<table id="main" onDisk="True" mixin="//scs#q3cindex" adql="True">
		<primary>source_id</primary>
		<index columns="teff"/>
		<index columns="fe_h"/>
		<index columns="logg"/>

		 <column name="source_id" type="bigint" required="True"
			ucd="meta.id;meta.main"
			tablehead="Source Id"
			description="Gaia DR3 unique source identifier.  You can match this
				against gaia.dr3lite on this TAP service."
			verbLevel="1">
			<property name="statisticsTarget">10000</property>
		</column>

		<column name="ra" type="double precision"
			unit="deg" ucd="pos.eq.ra;meta.main"
			tablehead="RA"
			description="Gaia ICRS right ascension for this object."
			verbLevel="1" displayHint="sf=7"/>
		<column name="dec" type="double precision"
			unit="deg" ucd="pos.eq.dec;meta.main"
			tablehead="Dec"
			description="Gaia ICRS declination for this object."
			verbLevel="1" displayHint="sf=7"/>

		<column name="teff"
			unit="K" ucd="phys.temperature.effective"
			tablehead="Teff"
			description="Estimated effective Temperature.  Note that
				the raw HDF5 files released by Zhang et al. (2023) give
				Teff in a different unit (Kilokelvin)."
			verbLevel="5"/>
		<column name="fe_h"
			ucd="phys.abund.Fe"
			tablehead="[Fe/H]"
			description="Log of Fe/H in solar units"
			verbLevel="5"/>
		<column name="logg"
			ucd="phys.gravity"
			tablehead="log(g)"
			description="Log of surface gravity in solar units"
			verbLevel="5"/>
		<column name="ext"
			unit="mag" ucd="phys.absorption"
			tablehead="Ext."
			description="Estimated extinction parameter.  To convert to the extension
				at a particular wavelength, multiply this by that wavelength's
				value in the extinction curve, available at
				https://zenodo.org/record/7811871/files/extinction_curve.txt?download=1
				and in the footnote."
			verbLevel="5"
			note="R"/>
		<column name="mod_parallax"
			unit="mas" ucd="pos.parallax"
			tablehead="Est. Par."
			description="Parallax estimated from the model."
			verbLevel="5"/>

		<column name="err_teff"
			unit="K" ucd="stat.error;phys.temperature.effective"
			tablehead="Err. Teff"
			description="Error in estimated effective temperature.  Note that
			the raw HDF5 files released by Zhang et al. (2023) give the error in
			Teff in a different unit (Kilokelvin)."
			verbLevel="15"/>
		<column name="err_fe_h"
			ucd="stat.error;phys.abund.Fe"
			tablehead="Err. [Fe/H]"
			description="Error in fe_h"
			verbLevel="15"/>
		<column name="err_logg"
			ucd="stat.error;phys.gravity"
			tablehead="Err. log(g)"
			description="Error in log_g"
			verbLevel="15"/>
		<column name="err_ext"
			unit="mag" ucd="stat.error;phys.absorption"
			tablehead="Err. Ext."
			description="Error in ext"
			verbLevel="15"/>
		<column name="err_mod_parallax"
			unit="mas" ucd="stat.error;pos.parallax"
			tablehead="Err. Par."
			description="Error in the parallax estimated from the model."
			verbLevel="15"/>

		<column name="chi2_opt"
			ucd="stat.fit.chi2"
			tablehead="χ²"
			description="χ² of the best-fit solution.
				Divide by 61 to obtain χ² per degree of freedom."
			verbLevel="15"/>
		<column name="ln_prior"
			ucd="stat.fit.goodness"
			tablehead="ln(prior)"
			description="Natural log of the GMM prior on stellar type, at the
				location of the optimal solution."
			verbLevel="15"/>

		<column name="teff_confidence"
			ucd="stat.fit.goodness"
			tablehead="Conf. T"
			description="A neural-network-based estimate of the confidence in the
				effective temperature estimate, on a scale of 0 (no confidence) to 1
				(high confidence)."
			verbLevel="15"/>
		<column name="feh_confidence"
			ucd="stat.fit.goodness"
			tablehead="Conf. [Fe/H]"
			description="A neural-network-based estimate of the confidence in the
				[Fe/H] estimate, on a scale of 0 (no confidence) to 1
				(high confidence)."
			verbLevel="15"/>
		<column name="logg_confidence"
			ucd="stat.fit.goodness"
			tablehead="Conf. logg"
			description="A neural-network-based estimate of the confidence in the
				log(g) estimate, on a scale of 0 (no confidence) to 1
				(high confidence)."
			verbLevel="15"/>
		<column name="quality_flags" type="smallint" required="True"
			ucd="meta.code.qual"
			tablehead="Quality Flags"
			description='The three least significant bits represent whether the
				confidence in effective temperature, [Fe/H] and log(g) is less than
				0.5, respectively. The 4th bit is set if chi2_opt/61 > 2. The 5th bit
				is set if ln_prior &lt; -7.43. The 6th bit is set if our parallax
				estimate is more than 10 sigma from the GDR3 measurement (using
				reported parallax uncertainties from GDR3). The two most significant
				bits are always unset.  We recommend a cut of quality_flags &lt; 8 (the
				"basic reliability cut"), although a stricter cut of quality_flags == 0
				ensures higher reliability at the cost of lower completeness.'
			verbLevel="5"/>

		<meta name="note" tag="R">
This table is originally at
https://zenodo.org/record/7811871/files/extinction_curve.txt?download=1.

==========  ======================
wavelength  extinction_curve
392.0       4.004029750823975
402.0       3.932934284210205
412.0       3.8616459369659424
422.0       3.790104627609253
432.0       3.66058611869812
442.0       3.6425302028656006
452.0       3.5208635330200195
462.0       3.42183256149292
472.0       3.3702077865600586
482.0       3.31054949760437
492.0       3.2349464893341064
502.0       3.103348970413208
512.0       3.028446674346924
522.0       2.913299798965454
532.0       2.8309452533721924
542.0       2.766111135482788
552.0       2.658158779144287
562.0       2.5784859657287598
572.0       2.5361363887786865
582.0       2.4805185794830322
592.0       2.412776470184326
602.0       2.356668472290039
612.0       2.313209056854248
622.0       2.272326707839966
632.0       2.2307708263397217
642.0       2.1915647983551025
652.0       2.156630516052246
662.0       2.1017379760742188
672.0       2.040684938430786
682.0       2.0002477169036865
692.0       1.9592469930648804
702.0       1.9099318981170654
712.0       1.8628478050231934
722.0       1.8250858783721924
732.0       1.7893791198730469
742.0       1.7572511434555054
752.0       1.7151219844818115
762.0       1.7081632614135742
772.0       1.6803325414657593
782.0       1.6145453453063965
792.0       1.566452145576477
802.0       1.5282924175262451
812.0       1.4971987009048462
822.0       1.4678758382797241
832.0       1.4417716264724731
842.0       1.4134937524795532
852.0       1.3825805187225342
862.0       1.3539363145828247
872.0       1.3050405979156494
882.0       1.2772356271743774
892.0       1.2389837503433228
902.0       1.2139592170715332
912.0       1.193802833557129
922.0       1.155206322669983
932.0       1.143110990524292
942.0       1.113704800605774
952.0       1.075573444366455
962.0       1.0743821859359741
972.0       1.0339452028274536
982.0       0.9810613989830017
992.0       1.0053104162216187
1235.0      0.6821472644805908
1662.0      0.4082775115966797
2159.0      0.2695426046848297
3352.6      0.13694290816783905
4602.8      0.09808244556188583
==========  ======================
		</meta>
	</table>

	<coverage>
		<updater sourceTable="main"/>
	</coverage>

	<data id="import">
		<sources pattern="data/stellar_params*.h5"/>

		<directGrammar id="boost" type="hdf5rootarrs"
				cBooster="res/boosterfunc.c">
			<property name="dataset">/</property>
		</directGrammar>
		
		<make table="main">
			<rowmaker idmaps="*">
			</rowmaker>
		</make>
	</data>

	<service id="cone" allowed="form,scs.xml">
		<meta name="shortName">XP ap-pars</meta>
		<meta name="testQuery">
			<meta name="ra">81.1106109</meta>
			<meta name="dec">2.77958655</meta>
			<meta name="sr">0.001</meta>
		</meta>

		<publish render="form" sets="ivo_managed, local"/>
		<publish render="scs.xml" sets="ivo_managed"/>
		<scsCore queriedTable="main">
			<FEED source="//scs#coreDescs"/>
			<condDesc inputOptional="True" buildFrom="quality_flags">
				<phraseMaker>
					<code>
						if inPars[inputKeys[0].name] is None:
							if inputKeys[0].xtype=="interval":
								inPars["quality_flags"] = [0, 8]
							else:
								inPars["quality_flags"] = "&lt; 8"
						yield base.getSQLForField(inputKeys[0], inPars, outPars)
					</code>
				</phraseMaker>
			</condDesc>
		</scsCore>
	</service>

	<regSuite title="xpparams regression">
		<regTest title="xpparams SCS honours quality flags">
			<url RA="81.43474578"
					DEC="3.1562118530" SR="0.03333"
				>cone/scs.xml</url>
			<code>
				rows = self.getVOTableRows()
				# the following assertion is for the default quality cut to be
				# active (without it, it's 17 rows)
				self.assertEqual(len(rows), 16)
				self.assertAlmostEqual(rows[0]["teff"]-4593.015, 0, 3)
				self.assertAlmostEqual(rows[1]["logg"], 4.4473667, 6)
				self.assertEqual(rows[2]["source_id"], "3235947833912912896")
			</code>
		</regTest>

		<regTest title="xpparams cone form honours quality flags">
			<url parSet="form"
				hscs_pos="81.43474578 3.1562118530" hscs_sr="2" quality_flags="&lt; 8"
				>cone/form</url>
			<code>
				self.assertHasStrings(
					# the following assertion is for quality_flags &lt; 8 being evaluated
					"Matched: 16",
					"4593.015", # Teff of 0
					"81.4371948", # RA of 1
					"32.41", # dist of 2
				)
			</code>
		</regTest>

	</regSuite>
</resource>
