<resource schema="carmenes" resdir=".">
	<meta name="creationDate">2025-07-08T11:57:48Z</meta>

	<meta name="title">Carmenes DR1 Radial Velocity Time Series</meta>
	<meta name="description">
		The CARMENES instrument, installed at the 3.5 m telescope of the Calar Alto
		Observatory in Almería, Spain, was conceived to deliver high-accuracy
		radial velocity (RV) measurements with long-term stability to search for
		temperate rocky planets around a sample of nearby cool stars.

		The service publishes the radial velocities derived from the
		CARMENES guaranteed time observations (GTO),
		spanning from 2016 to 2020.  This results in 362 individual
		time series mapping time to radial velocities.
	</meta>
	<meta name="subject">exoplanets</meta>
	<meta name="subject">habitable-planets</meta>
	<meta name="subject">high-resolution-spectroscopy</meta>
	<meta name="subject">radial-velocity</meta>

	<meta name="creator">Ribas, I.; Reiners, A.; Zechmeister, M.; A. Caballero,
		J.; C. Morales, J.; Sabotta, S.; Baroch, D.; J. Amado, P.; Quirrenbach, A.;
		Abril, M.; Aceituno, J.; Anglada-Escudé, G.; Azzaro, M.; Barrado, D.; J. S.
		Béjar, V.; Benítez de Haro, D.; Bergond, G.; Bluhm, P.; Calvo Ortega, R.;
		Cardona Guillén, C.; Chaturvedi, P.; Cifuentes, C.; Colomé, J.; Cont, D.;
		Cortés-Contreras, M.; Czesla, S.; Díez-Alonso, E.; Dreizler, S.;
		Duque-Arribas, C.; Espinoza, N.; Fernández, M.; Fuhrmeister, B.;
		Galadí-Enríquez, D.; García-López, A.; González-Álvarez, E.; I. González
		Hernández, J.; W. Guenther, E.; de Guindos, E.; P. Hatzes, A.; Henning, Th.;
		Herrero, E.; Hintz, D.; L. Huelmo, Á.; V. Jeffers, S.; N. Johnson, E.; de
		Juan, E.; Kaminski, A.; Kemmer, J.; Khaimova, J.; Khalafinejad, S.;
		Kossakowski, D.; Kürster, M.; Labarga, F.; Lafarga, M.; Lalitha, S.; Lampón,
		M.; Lillo-Box, J.; Lodieu, N.; J. López González, M.; López-Puertas, M.;
		Luque, R.; Magán, H.; Mancini, L.; Marfil, E.; L. Martín, E.; Martín-Ruiz,
		S.; Molaverdikhani, K.; Montes, D.; Nagel, E.; Nortmann, L.; Nowak, G.;
		Pallé, E.; M. Passegger, V.; Pavlov, A.; Pedraz, S.; Perdelwitz, V.; Perger,
		M.; Ramón-Ballesta, A.; Reffert, S.; Revilla, D.; Rodríguez, E.;
		Rodríguez-López, C.; Sadegi, S.; Á. Sánchez Carrasco, M.; Sánchez-López, A.;
		Sanz-Forcada, J.; Schäfer, S.; Schlecker, M.; H. M. M. Schmitt, J.; Schöfer,
		P.; Schweitzer, A.; Seifert, W.; Shan, Y.; L. Skrzypinski, S.; Solano, E.;
		Stahl, O.; Stangret, M.; Stock, S.; Stürmer, J.; M. Tabernero, H.; Tal-Or,
		L.; Trifonov, T.; Vanaverbeke, S.; Yan, F.; Zapatero Osorio, M. R.</meta>
	<meta name="instrument">CARMENES</meta>
	<meta name="facility">Calar Alto</meta>

	<meta name="source">2023A&amp;A...670A.139R</meta>
	<meta name="contentLevel">Research</meta>
	<meta name="type">Archive</meta>

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

	<meta name="ssap.dataSource">pointed</meta>
	<meta name="ssap.creationType">archival</meta>
	<meta name="productType">spectrum</meta>
	<meta name="ssap.testQuery">MAXREC=1</meta>


	<table id="objects" onDisk="True" adql="True"
			primary="carmenes_id" dupePolicy="drop">
		<meta name="description">Properties of CARMENES DR1 target objects.

			This is derived from ivo://cds.vizier/J/A+A/670/A139.
		</meta>
		<column name="carmenes_id" type="text"
			ucd="meta.id;meta.main"
			description="CARMENES target designation"
			verbLevel="1"/>
		<column name="name" type="text"
			ucd="meta.id"
			description="SIMBAD-resolvable star name"
			verbLevel="1"/>
		<column name="nobs" type="smallint"
			ucd="meta.number;obs"
			description="Number of nightly zero point corrected radial velocity
				measurements for this object"
			verbLevel="25">
			<values nullLiteral="0"/>
		</column>
		<column name="nspect" type="smallint" required="True"
			ucd="meta.number"
			description="Number of spectra for this object in DR1"
			verbLevel="25"/>
		<FEED source="//procs#witherror" name="mass" type="double precision"
			unit="solMass" ucd="phys.mass"
			description="Mass of the star from Carmencita"
			verbLevel="15"/>
		<FEED source="//procs#witherror" name="radius" type="double precision"
			unit="solRad" ucd="phys.size.radius"
			description="Radius of the star from Carmencita"
			verbLevel="15"/>
		<FEED source="//procs#witherror" name="teff"
			unit="K" ucd="phys.temperature.effective"
			description="Effective temperature of the star from carmencita"
			verbLevel="15"/>
		<column name="p_rot" type="double precision"
			unit="d" ucd="time.period"
			description="Rotation period of the star (see p_rot_source for
				the provenance of this value)"
			verbLevel="15"/>
		<column name="p_rot_source" type="text"
			ucd="meta.bib"
			description="Source of the value in p_rot (see 2023A&amp;A...670A.139R
				for the meaning of the abbreviations)"
			verbLevel="25"/>
		<column name="survey" type="text"
			ucd="meta.code"
			description="Flag identifying stars that are part of the blind radial
				velocity survey (GTO) or the program to determine the mass of
				transiting planets (TESS). An asterisk marks stars already tabulated in
				Reiners et al., 2018A&amp;A...612A..49R"
			verbLevel="15"/>
		<column name="remarks" type="text"
			ucd="meta.note"
			description="Comment identifying spectroscopic multiple systems:
			Double-line spectroscopic binaries (SB2), triple-line spectroscopic
			binaries (ST3), and visual binaries (Visual).
			Multiplicity references: Bar18 – 2018A&amp;A...619A..32B;
			Bar21 – 2021A&amp;A...653A..49B; Gaia – 2016A&amp;A...595A...1G;
			Mor09 – 2009ApJ...691.1400M"
			verbLevel="15"/>
		<column name="ra" type="double precision"
			unit="deg" ucd="pos.eq.ra;meta.main"
			description="Right Ascension (J2000) from SIMBAD"
			verbLevel="1"/>
		<column name="dec" type="double precision"
			unit="deg" ucd="pos.eq.dec;meta.main"
			description="Declination (J2000) from SIMBAD"
			verbLevel="1"/>
	</table>

	<data id="import-names">
		<sources pattern="data/carmenes-targets.vot"/>
		<voTableGrammar/>
		<make table="objects">
			<rowmaker>
				<simplemaps>
					mass: Mass,
					nobs: NAVC,
					nspect: NRVC,
					name: Name,
					p_rot: Prot,
					radius: Rad,
					survey: Survey,
					teff: Teff,
					err_mass: e_Mass,
					err_radius: e_Rad,
					err_teff: e_Teff,
					ra: _RA,
					dec: _DE
				</simplemaps>
				<map key="remarks">@Comm.strip() or None</map>
				<map key="p_rot_source">@Ref.strip() or None</map>
				<map key="carmenes_id">@Karmn.strip() or None</map>
			</rowmaker>
		</make>
	</data>

	<table id="rvs" onDisk="True" adql="True">
		<meta name="description">All RV estimates from CARMENES DR1, for
			all objects.  To obtain single time series, it is probably
			simpler to use the SSA service or pull them from obscore.</meta>
		<column name="object" type="text"
			ucd="meta.id;meta.main"
			tablehead="Object"
			description="Carmenes identifier of the target object"
			verbLevel="1"/>
		<column name="bjd" type="double precision"
			unit="d" ucd="time.epoch"
			tablehead="Epoch"
			description="JD of the observation at the solar system barycenter
				(probably in TDB)."
			verbLevel="1"/>
		<FEED source="//procs#witherror"
			name="rv" type="double precision"
			unit="km/s" ucd="spect.dopplerVeloc"
			tablehead="RV_S"
			description="Radial velocity derived by the Serval pipeline"
			verbLevel="1"/>
		<FEED source="//procs#witherror"
			name="a_rv" type="double precision"
			unit="km/s" ucd="spect.dopplerVeloc"
			tablehead="ARV_S"
			description="Radial velocity derived by the Serval pipeline, corrected
				for the CARMENES' nightly zero point (NZP), which ought to
				repair most of the instruments' drift."
			verbLevel="1"/>

		<FEED source="//procs#witherror"
			name="dlw"
			unit="m**2/s**2" ucd="spect.line.width;arith.diff"
			tablehead="DLW"
			description="Differential line width derived by the Serval pipeline;
				this is a marker for stellar activity."
			verbLevel="25"/>
		<FEED source="//procs#witherror"
			name="ccf_rv" type="double precision"
			unit="km/s" ucd="spect.dopplerVeloc"
			tablehead="RV_ccf"
			description="BERV-, secular acceleration- and drift-corrected
				radial velocity derived by the Racoon pipeline
				(see 2020A&amp;A...636A..36L)."
			verbLevel="1"/>
		<FEED source="//procs#witherror"
			name="ccf_fwhm" type="double precision"
			unit="km/s" ucd="spect.dopplerVeloc;stat.fwhm"
			tablehead="FWHM_ccf"
			description="Full Width Half Maximum derived by the Racoon pipeline."
			verbLevel="15"/>
		<FEED source="//procs#witherror"
			name="ccf_contrast"
			unit="%" ucd="phot.flux;arith.ratio"
			tablehead="Contrast"
			description="Contrast derived by the Racoon Pipeline (see
				2020A&amp;A...636A..36L)."
			verbLevel="15"/>
		<FEED source="//procs#witherror"
			name="ccf_bis"
			unit="km/s" ucd=""
			tablehead="B.I.S."
			description="Bisector inverse slope derived by the Racoon pipeline
				 (see 2020A&amp;A...636A..36L)."
			verbLevel="25"/>

		<FEED source="//procs#witherror"
			name="halpha"
			ucd="spect.index"
			tablehead="Hα index"
			description="Hα (λ=6562.81 Angstrom) index; this is an indicator
				for stellar activity (cf. 2018A&amp;A...609A..12Z)."/>
		<FEED source="//procs#witherror"
			name="hacen"
			unit="count" ucd="phot.flux;em.line.Halpha"
			tablehead="Hα flux"
			description="Flat-normalised Hα mean flux"/>
		<FEED source="//procs#witherror"
			name="haleft"
			unit="count" ucd="phot.flux;em.line.Halpha"
			tablehead="Hα left"
			description="Flat-normalised flux in the left Hα reference region,
				i.e., (-300, -100) km/s; this is an indicator
				for stellar activity (cf. 2018A&amp;A...609A..12Z)." />
		<FEED source="//procs#witherror"
			name="haright"
			unit="count" ucd="phot.flux;em.line.Halpha"
			tablehead="Hα right"
			description="Flat-normalised flux in the right Hα reference region,
				i.e., (100, 300) km/s; this is an indicator
				for stellar activity (cf. 2018A&amp;A...609A..12Z)."/>

		<FEED source="//procs#witherror"
			name="cai"
			ucd="spect.index"
			tablehead="Ca I index"
			description="Ca I λ=6572.80 Angstrom index (-15,15) km/s; this is an indicator
				for stellar activity (cf. 2018A&amp;A...609A..12Z)."/>

		<FEED source="//procs#witherror"
			name="cai_8498"
			ucd="spect.index"
			tablehead="Ca II 8498 index"
			description="Ca II λ=8498.02 index (-15,15) km/s; this is an indicator
				for stellar activity (cf. 2018A&amp;A...609A..12Z)."/>
		<FEED source="//procs#witherror"
			name="cai_8542"
			ucd="spect.index"
			tablehead="Ca II 8542 index"
			description="Ca II λ=8542.09 index (-15,15) km/s; this is an indicator
				for stellar activity (cf. 2018A&amp;A...609A..12Z)."/>
		<FEED source="//procs#witherror"
			name="cai_8698"
			ucd="spect.index"
			tablehead="Ca II 8698 index"
			description="Ca II λ=8662.14 index (-15,15) km/s; this is an indicator
				for stellar activity (cf. 2018A&amp;A...609A..12Z)."/>

		<FEED source="//procs#witherror"
			name="nad1"
			ucd="spect.index"
			tablehead="Na D1 index"
			description="Na I D1 λ=5889.95 Angstrom index (-15,15) km/s; this is
				an indicator for stellar activity (cf. 2018A&amp;A...609A..12Z)."/>
		<FEED source="//procs#witherror"
			name="nad2"
			ucd="spect.index"
			tablehead="Na D2 index"
			description="Na I D2 λ=5895.92 Angstrom index (-15,15) km/s; this is
				an indicator for stellar activity (cf. 2018A&amp;A...609A..12Z)."/>

		<column name="spec_flag" type="smallint" required="True"
			ucd="meta.code.qual"
			tablehead="Flags"
			description="Bit mask for spectral problems: bit 5 S/N too low,
				bit 6 S/N too high, bit 7 not within nautical twilight,
				bit 8 too close to the moon, bit 9 LED on during observation"
			verbLevel="15"/>

		<FEED source="//procs#witherror" name="drift"
			unit="m/s" ucd="instr.calib"
			tablehead="Drift"
			description="Drift measure derived by the caracal pipeline."
			verbLevel="25"/>
		<column name="berv" type="double precision"
			unit="m/s" ucd="phys.veloc"
			tablehead="BE RV"
			description="Barycentric RV of the Earth"
			verbLevel="25"/>
		<column name="sadrift"
			unit="m/s" ucd="instr.calib"
			tablehead="Drift"
			description="Drift due to secular acceleration"
			verbLevel="25"/>
		<column name="spec_accref" type="text"
			unit="" ucd="meta.id;meta.file"
			tablehead="spec"
			description="The access reference of the source spectrum."
			verbLevel="1"/>
		<FEED source="//procs#witherror"
			name="rvmean" type="double precision"
			unit="km/s" ucd="spect.dopplerVeloc;stat.mean"
			tablehead="RV"
			description="Undrifted mean radial velocity"
			verbLevel="1"/>
		<FEED source="//procs#witherror"
			name="rvmed" type="double precision"
			unit="km/s" ucd="spect.dopplerVeloc;stat.median"
			tablehead="RV med."
			description="Undrifted median radial velocity"
			verbLevel="1"/>

		<column name="rv_orders_serval" type="real[61]"
			unit="km/s" ucd="spect.dopplerVeloc"
			description="Per-order radial velocity estimates from serval, starting
				with order 118, ending at order 58"
			verbLevel="30"/>
		<column name="err_rv_orders_serval" type="real[61]"
			unit="km/s" ucd="stat.error;spect.dopplerVeloc"
			description="Errors for rv_orders_serval"
			verbLevel="30"/>

		<column name="dlw_orders_serval" type="real[61]"
			unit="m**2/s**2" ucd="spect.line.width;arith.diff"
			description="Per-order differential line width from serval, starting
				with order 118, ending at order 58"
			verbLevel="30"/>
		<column name="err_dlw_orders_serval" type="real[61]"
			unit="km/s" ucd="stat.error;spect.line.width;arith.diff"
			description="Errors for dlw_orders_serval"
			verbLevel="30"/>

		<column name="rv_orders_racoon" type="real[61]"
			unit="km/s" ucd="spect.dopplerVeloc"
			description="Per-order radial velocity estimates from racoon, starting
				with order 118, ending at order 58"
			verbLevel="30"/>
		<column name="err_rv_orders_racoon" type="real[61]"
			unit="km/s" ucd="stat.error;spect.dopplerVeloc"
			description="Errors for rv_orders_racoon"
			verbLevel="30"/>

		<column name="fwhm_orders_racoon" type="real[61]"
			description="Per-order FWHM estimates from racoon, starting
				with order 118, ending at order 58"
			verbLevel="30"/>
		<column name="err_fwhm_orders_racoon" type="real[61]"
			description="Errors for fwhm_orders_racoon"
			verbLevel="30"/>

		<column name="contrast_orders_racoon" type="real[61]"
			description="Per-order FWHM estimates from racoon, starting
				with order 118, ending at order 58"
			verbLevel="30"/>
		<column name="err_contrast_orders_racoon" type="real[61]"
			description="Errors for contrast_orders_racoon"
			verbLevel="30"/>

		<column name="bis_orders_racoon" type="real[61]"
			description="Per-order BIS estimates from racoon, starting
				with order 118, ending at order 58"
			verbLevel="30"/>
		<column name="err_bis_orders_racoon" type="real[61]"
			description="Errors for bis_orders_racoon"
			verbLevel="30"/>
	</table>

	<data id="import-ts">
		<sources pattern="data/serval_racoon/*.csv"/>
		<csvGrammar/>
		<make table="rvs">
			<rowmaker idmaps="*">
				<var key="object">\srcstem.split("_")[0]</var>
				<!-- no idea why my file names have an extra _A -->
				<var key="spec_accref">"carmenes/data/{}/{}".format(
					@object, @TIMEID.replace(".fits", "_A.fits"))</var>

<!-- unmapped: CRX':  'E_CRX'
'SNREF': '134.96', 'EXPTIME': '800.1', 'FLAG': '0', 'AIRMASS': '1.1042'
-->
				<simplemaps>
					object: object,
					bjd: BJD,
					rv: RVC,
					err_rv: E_RVC,
					a_rv: AVC,
					err_a_rv: E_AVC,
					dlw: DLW,
					err_dlw: E_DLW,
					ccf_rv: CCF_RV,
					err_ccf_rv: CCF_E_RV,
					ccf_fwhm: CCF_FWHM,
					err_ccf_fwhm: CCF_E_FWHM,
					ccf_contrast: CCF_CONTRAST,
					err_ccf_contrast: CCF_E_CONTRAST,
					ccf_bis: CCF_BIS,
					err_ccf_bis: CCF_E_BIS,
					halpha: HALPHA,
					err_halpha: E_HALPHA,
					hacen: HACEN,
					err_hacen: E_HACEN,
					haleft: HALEFT,
					err_haleft: E_HALEFT,
					haright: HARIGH,
					err_haright: E_HARIGH,
					cai: CAI,
					err_cai: E_CAI,
					cai_8498: CAIRT1,
					err_cai_8498: E_CAIRT1,
					cai_8542: CAIRT2,
					err_cai_8542: E_CAIRT1,
					cai_8698: CAIRT3,
					err_cai_8698: E_CAIRT3,
					nad1: NAD1,
					err_nad1: E_NAD1,
					nad2: NAD2,
					err_nad2: E_NAD2,
					spec_flag: FLAG,
					drift: DRIFT,
					err_drift: E_DRIFT,
					berv: BERV,
					sadrift: SADRIFT,
					rvmean: RV,
					err_rvmean: E_RV,
					rvmed: RVMED,
					err_rvmed: E_RVMED
				</simplemaps>
			
				<LOOP>
					<csvItems>
					destcol,                   srcstem
					rv_orders_serval,          RVO
					err_rv_orders_serval,      E_RVO
					dlw_orders_serval,         DLW
					err_dlw_orders_serval,     E_DLW
					rv_orders_racoon,          CCF.RVO
					err_rv_orders_racoon,      CCF.E_RVO
					fwhm_orders_racoon,        CCF.FWHMO
					err_fwhm_orders_racoon,    CCF.E_FWHMO
					contrast_orders_racoon,    CCF.CONTRASTO
					err_contrast_orders_racoon,CCF.E_CONTRASTO
					bis_orders_racoon,         CCF.BISO
					err_bis_orders_racoon,     CCF.E_BISO
					</csvItems>
					<events>
						<map key="\destcol">[parseFloat(vars["\srcstem\+_{:03d}".format(o)])
								for o in range(118, 57, -1)]</map>
					</events>
				</LOOP>
			</rowmaker>
		</make>
	</data>


	<table id="raw_ts" onDisk="True" adql="hidden"
			namePath="//ssap#instance">
		<LOOP listItems="ssa_dstitle ssa_targname ssa_length ssa_timeExt">
			<events>
				<column original="\item"/>
			</events>
		</LOOP>
		<column original="//obscore#ObsCore.t_min"/>
		<column original="//obscore#ObsCore.t_max"/>

		<mixin>//products#table</mixin>
		<mixin>//ssap#plainlocation</mixin>
		<mixin>//ssap#simpleCoverage</mixin>

		<column name="datalink" type="text"
			ucd="meta.ref.url"
			tablehead="Datalink"
			description="A link to a datalink document for this spectrum."
			verbLevel="15" displayHint="type=url">
			<property name="targetType"
			 >application/x-votable+xml;content=datalink</property>
			<property name="targetTitle">Datalink</property>
		</column>

		<viewStatement>
			CREATE MATERIALIZED VIEW \qName AS (SELECT \colNames FROM (
				(SELECT
				'CARMENES DR1 ' || carmenes_id || ' RVs' AS ssa_dstitle,
				'CARMENES ' || carmenes_id AS ssa_targname,
				ssa_length,
				ssa_timeExt,
				t_min,
				t_max,
				spoint(radians(ra), radians(dec)) AS ssa_location,
				NULL::spoly AS ssa_region,
				'carmenes/t/' || carmenes_id AS accref,
				'application/x-votable+xml' AS mime,
				50000 AS accsize,
				NULL::DATE as embargo,
				NULL as owner,
				NULL as datalink
				FROM (SELECT
					object,
					COUNT(*) as ssa_length,
					(MAX(bjd)-MIN(bjd))*86400 AS ssa_timeExt,
					MIN(bjd)-2400000.5 as t_min,
					MAX(bjd)-2400000.5 as t_max
					FROM \schema.rvs
					GROUP BY object) as q
				LEFT OUTER JOIN \schema.objects
				ON (carmenes_id=object)
				WHERE carmenes_id IS NOT NULL)) AS q)
		</viewStatement> <!-- J02362+068 has no carmenes_id -->
	</table>

	<data id="create-raw-view">
		<recreateAfter>make-ssa-view</recreateAfter>
		<property key="previewDir">tspreviews</property>
		<make table="raw_ts">
			<script type="preImport" lang="SQL">
				DELETE FROM dc.products WHERE sourcetable='carmenes.raw_ts'
			</script>
			<script type="postCreation" lang="SQL" name="add to product table">
				INSERT INTO dc.products (SELECT
					accref,
					owner,
					NULL AS embargo,
					mime,
					\sqlquote{\internallink{/carmenes/t/sdl/dlget?ID=}} ||
						gavo_urlescape(accref) as accesspath,
					'carmenes.raw_ts' as sourcetable,
					'carmenes/tspreviews/' || accref || '.png' as preview,
					NULL as datalink,
					'image/png' as preview_mime
				FROM carmenes.raw_ts);
			</script>
		</make>
	</data>


	<table id="ts_ssa" onDisk="True" adql="True">
		<meta name="_associatedDatalinkService">
			<meta name="serviceId">sdl</meta>
			<meta name="idColumn">ssa_pubDID</meta>
		</meta>

		<mixin
			sourcetable="raw_ts"
			copiedcolumns="*"
			ssa_aperture="1/3600."
			ssa_bandpass="'Optical'"
			ssa_collection="'CARMENES DR1 timeseries'"
			ssa_dstype="'timeseries'"
			ssa_fluxcalib="NULL"
			ssa_fluxucd="NULL"
			ssa_pubDID="\sql_standardPubDID"
			ssa_spectralucd="NULL"
			ssa_spectralunit="NULL"
			ssa_targclass="'star'"
			ssa_specext="NULL"
			ssa_specmid="NULL"
		>//ssap#view</mixin>

		<mixin
			calibLevel="3"
			coverage="ssa_region"
			oUCD="'spect.dopplerVeloc'"
			>//obscore#publishSSAPMIXC</mixin>
	</table>

	<data id="make-ssa-view" auto="False">
		<make table="ts_ssa"/>
	</data>

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

	<table id="instance" onDisk="False">
		<!-- we use a template for description here; it will be filled
			out by the datalink service below -->
 		<meta name="description">The \metaString{source} radial velocity
 			time series for {ssa_targname} from CARMENES DR1.</meta>

		<dm>
				(votable:Coords) {
					time: (votable:TimeCoordinate) {
						frame:
							(votable:TimeFrame) {
								timescale: TDB
								refPosition: BARYCENTER
								time0: 0 }
						location: @bjd
					}
					space:
						(votable:SphericalCoordinate) {
							frame: (votable:SpaceFrame) {
								orientation: ICRS
							}
							location: @ssa_location
						}
				}
			</dm>

			<dm>
				(ndcube:Cube) {
					independent_axes: @bjd
					dependent_axes: [@rvmean @spec_accref]
				}
			</dm>

		<param original="ts_ssa.t_min"/>
		<param original="ts_ssa.t_max"/>
		<param original="ts_ssa.ssa_location"/>

		<column original="rvs.bjd"/>
		<column original="rvs.rvmean"/>
		<column original="rvs.err_rvmean"/>
		<column original="rvs.spec_accref"/>
	</table>

	<data id="build-ts" auto="False">
		<embeddedGrammar>
			<iterator>
				<code>
					object = self.sourceToken.accref.split("/")[-1]
					with base.getTableConn() as conn:
						yield from conn.queryToDicts(
							"SELECT bjd, rvmean, err_rvmean,"
								"  \sqlquote{\internallink{/getproduct/}}"
								"    || gavo_urlescape(spec_accref) as spec_accref"
								"  FROM \schema.rvs"
								"  WHERE object=%(object)s",
								locals())
				</code>
			</iterator>
			<pargetter>
				<code>
					return self.sourceToken.ssa_row
				</code>
			</pargetter>
		</embeddedGrammar>

		<make table="instance">
			<rowmaker idmaps="*" id="make-ts"/>
			<parmaker id="make-ts-par" idmaps="t_min, t_max, ssa_location">
			</parmaker>
		</make>
	</data>

	<service id="sdl" allowed="dlget,dlmeta,static">
		<property name="staticData">data/periodograms</property>
		<meta name="title">\schema Datalink Service</meta>
		<datalinkCore>
			<descriptorGenerator>
				<code>
					if "?" in pubDID:
						accref = urllib.parse.unquote_plus(pubDID.split("?")[-1])
					else:
						# it already is an accref rather than a full pubDID
						accref = pubDID

					descriptor = ProductDescriptor.fromAccref(pubDID, accref)
					with base.getTableConn() as conn:
						descriptor.ssa_row = next(conn.queryToDicts(
							"SELECT * FROM \schema.ts_ssa"
							" WHERE accref=%(accref)s",
							{"accref": accref}))
					return descriptor
				</code>
			</descriptorGenerator>

			<metaMaker name="add_provenance" semantics="#progenitor">
				<code>
					with base.getTableConn() as conn:
						for row in conn.query("SELECT spec_accref FROM"
								" \schema.rvs WHERE object=%(object)s",
								{"object": descriptor.accref.split("/")[-1]}):
							yield descriptor.makeLink(
								makeProductLink(row[0]),
								contentType="application/x-votable+xml",
								contentLength=4000000)
				</code>
			</metaMaker>

			<metaMaker name="add_periodogram" semantics="#derivation">
				<code>
					objname = descriptor.accref.split("/")[-1]
					yield descriptor.makeLinkFromFile(
						rd.getAbsPath(f"data/periodograms/{objname}_periodograms.pdf"),
						description="Periodograms derivied from this time series")
				</code>
			</metaMaker>

			<dataFunction>
				<setup imports="gavo.rsc"/>
				<code>
					descriptor.data = rsc.makeData(
						rd.getById("build-ts"),
						forceSource=descriptor)

					tab = descriptor.data.getPrimaryTable()
					tab.setMeta("description",
						base.getMetaText(tab, "description").format(**descriptor.ssa_row))
				</code>
			</dataFunction>

			<metaMaker>
				<code>
					yield MS(InputKey, type="double precision[2]",
						xtype="interval",
						name="TIME", multiplicity="forced-single",
						unit="d", ucd="time.epoch",
						description="Time interval to cut out",
						values=MS(Values,
							min=descriptor.ssa_row["t_min"],
							max=descriptor.ssa_row["t_max"]))
				</code>
			</metaMaker>

			<dataFunction>
				<code><![CDATA[
					if args["TIME"] is None:
						return
					tmin, tmax = args["TIME"]

					ts_table = descriptor.data.getPrimaryTable()
					new_rows = [row for row in
						ts_table.rows
						if tmin<=row["bjd"]-JD_MJD<=tmax]
					
					ts_table.rows = new_rows
				]]></code>
			</dataFunction>

			<dataFormatter>
				<setup imports="gavo.formats.votablewrite"/>
				<code>
					return ("application/x-votable+xml;version=1.5",
						votablewrite.getAsVOTable(descriptor.data, version=(1,5)))
				</code>
			</dataFormatter>
		</datalinkCore>
	</service>


	<!-- a form-based service – this is made totally separate from the
	SSA part because grinding down SSA to something human-consumable and
	still working as SSA is non-trivial -->
	<service id="web" defaultRenderer="form">
		<meta name="shortName">\schema Web</meta>
		<meta name="title">Carmenes DR1 Radial Velocity Time Series Browser
		Service</meta>

		<dbCore queriedTable="ts_ssa">
			<condDesc buildFrom="ssa_location"/>
			<condDesc buildFrom="t_max"/>
			<!-- add further condDescs in this pattern; if you have useful target
			names, you'll probably want to index them and say:

			<condDesc>
				<inputKey original="data.ssa_targname" tablehead="Target Object">
					<values fromdb="ssa_targname from \schema.data
						order by ssa_targname"/>
				</inputKey>
			</condDesc> -->
		</dbCore>

		<outputTable>
			<autoCols>accref, ssa_targname, t_min, t_max, ssa_bandpass,
				datalink</autoCols>
			<FEED source="//ssap#atomicCoords"/>
		</outputTable>
	</service>

	<service id="ssa" allowed="form,ssap.xml">
		<meta name="shortName">\schema TS SSAP</meta>
		<meta name="ssap.complianceLevel">full</meta>

		<publish render="ssap.xml" sets="ivo_managed"/>
		<publish render="form" sets="ivo_managed,local" service="web"/>

		<ssapCore queriedTable="ts_ssa">
			<property key="previews">auto</property>
			<FEED source="//ssap#hcd_condDescs"/>
		</ssapCore>
	</service>

	<regSuite title="carmenes time series regression">
		<regTest title="carmenes times series SSAP serves some data">
			<url REQUEST="queryData"
				PUBDID="ivo://org.gavo.dc/~?carmenes/t/J00051%2B457"
				>ssa/ssap.xml</url>
			<code>
				row = self.getFirstVOTableRow()
				self.assertAlmostEqual(row["location_dec"], 45.78657)
				self.assertEqual(row["ssa_dstitle"], "CARMENES DR1 J00051+457 RVs")
				self.assertAlmostEqual(row["t_min"], 57399.78514925111)
			</code>
		</regTest>

		<regTest title="carmenes time series Datalink metadata looks about right.">
			<url ID="ivo://org.gavo.dc/~?carmenes/t/J00051%2B457"
				>sdl/dlmeta</url>
			<code>
					by_sem = self.datalinkBySemantics()
					self.assertEqual(set(by_sem),
						{"#this", "#derivation", "#progenitor", "#preview", "#proc"})
					self.assertEqual(len(by_sem["#progenitor"]), 53)
					self.assertEqual(
						self.getUnique(by_sem["#derivation"])["access_url"][-49:],
						'carmenes/t/sdl/static/J00051+457_periodograms.pdf')
			</code>
		</regTest>

		<regTest title="carmenes delivers some data.">
			<url ID="ivo://org.gavo.dc/~?carmenes/t/J00051%2B457"
				>sdl/dlget</url>
			<code><![CDATA[
				rows = self.getVOTableRows()
				self.assertEqual(len(rows), 53)
				self.assertAlmostEqual(rows[-1]["bjd"], 2458093.501628257)
				self.assertAlmostEqual(rows[-1]["rvmean"], 32.42744087336881)
				self.assertHasStrings(
					"J00051+457 from CARMENES DR1",
					"ON>Undrifted mean radial velocity</DES",
					# ssa_location
					'value="1.29537')
			]]></code>
		</regTest>
	</regSuite>
</resource>
