<resource schema="hesspub" resdir=".">
	<meta name="creationDate">2022-12-12T10:25:17Z</meta>
	<meta name="schema-rank">100</meta>

	<meta name="title">HESS Public Test Release 1</meta>
	<meta name="description" format="rst">
		High Energy Stereoscopic System (H.E.S.S.) is a system of imaging
		atmospheric Cherenkov telescopes (IACTs) for the investigation of cosmic
		gamma rays in the photon energy range of 80 GeV to 100 TeV.  The data
		published here is a list of estimated parameters of gamma-ray candidates,
		i.e. particles for which it was determined with a high likelihood that they
		are not cosmic-ray background, but gamma rays.

		The provided parameters are:
		
		* incoming direction as position in the sky
		* energy
		* likelihood of being a gamma ray
		* run number

		The data are taken in runs of 28 minutes. For each run, the data of all
		auxiliary systems are recorded and links to air shower simulations and
		lookup tables corresponsing to the environment and state of the instrument
		are provided.
	</meta>
	<meta name="subject">high-energy-astrophysics</meta>
	<meta name="subject">gamma-ray-astronomy</meta>
	<meta name="subject">particle-astrophysics</meta>

	<meta name="creator">HESS collaboration</meta>
	<meta name="instrument">H.E.S.S.</meta>
	<meta name="facility">HESS Site, Khomas Region, Namibia (23°16′17″S 16°30′00″E)</meta>

	<meta name="source">2006A&amp;A...457..899A</meta>
	<meta name="contentLevel">Research</meta>
	<meta name="type">Archive</meta>

	<meta name="coverage.waveband">Gamma-ray</meta>

	<meta name="_longdoc">
		Full documentation on the dataset published here is available at
		https://hess.science/hess_dl3_dr1_v0.6.pdf.
	</meta>

	<meta name="copyright">
		The data and documentation is publicly released by the H.E.S.S.
		collaboration as a contribution to the ongoing efforts to define a common
		open format for data level 3 of imaging atmospheric Cherenkov telescopes
		(IACTs) and IACT open-source science tool development, to enlarge the
		community involved in IACT data analysis.

		No scientific publications may be derived from the data. Using the data for
		new claims about the astrophysical sources is not permitted.

		When using this data, please include the following attribution:

			This work made use of data from the H.E.S.S. DL3 public test
			data release 1 (HESS DL3 DR1, H.E.S.S. collaboration, 2018).
	</meta>

	<table id="obs" onDisk="True" adql="Hidden">
		<meta name="description">H.E.S.S. observes in bunches of 18 minutes,
			and each bunch is characterised by some metadata.  This metadata
			is kept in this table and accessible through the obs_id column.</meta>
		<primary>obs_id</primary>

		<column name="obs_id" type="text"
			ucd="meta.id;obs"
			description="Observation identifier.  This can be joined with
				that observation's metadata in the hessobs.obs table."
			verbLevel="1"/>
		<column name="time_start" type="double precision"
			unit="d" ucd="time.start"
			description="Start of observation of this bunch"
			verbLevel="1"/>
		<column name="time_stop" type="double precision"
			unit="d" ucd="time.end"
			description="End of observation of this bunch"
			verbLevel="1"/>
		<column name="livetime"
			unit="s" ucd="time.duration"
			description="Total live time of run"
			verbLevel="15"/>
		<column name="target_name" type="text"
			ucd="meta.id;src"
			description="Observed object"
			verbLevel="15"/>

		<column name="energ_lo" type="real[]"
			unit="TeV" ucd="TODO"
			description="TODO"
			verbLevel="15"/>
		<column name="energ_hi" type="real[]"
			unit="TeV" ucd="TODO"
			description="TODO"
			verbLevel="15"/>
		<column name="theta_lo" type="real[]"
			unit="deg" ucd="TODO"
			description="TODO"
			verbLevel="15"/>
		<column name="theta_hi" type="real[]"
			unit="deg" ucd="TODO"
			description="TODO"
			verbLevel="15"/>
		<column name="rad_lo" type="real[]"
			unit="deg" ucd="TODO"
			description="TODO"
			verbLevel="15"/>
		<column name="rad_hi" type="real[]"
			unit="deg" ucd="TODO"
			description="TODO"
			verbLevel="15"/>
		<column name="psf" type="real[32][6][]"
			unit="sr**-1" ucd="instr.det.psf"
			description="TODO"
			verbLevel="15"/>

		<!-- TODO: Effarea? etrue_lo etrue_hi?  migra_hi/lo?  nochmal theta?
		matrix? rpsf dimensions?-->
	</table>

	<data id="import_meta">
		<sources id="allbunches" pattern="data/hess_dl3_*.fits.gz"/>

		<fitsProdGrammar qnd="False" hdusField="hdus">
		</fitsProdGrammar>

		<make table="obs">
			<rowmaker>
				<apply name="fetch_psf">
					<code>
						psfSrc = @hdus["PSF"].data
						result["psf"] = psfSrc["RPSF"]
						result["energ_lo"] = psfSrc["ENERG_LO"][0]
						result["energ_hi"] = psfSrc["ENERG_HI"][0]
						result["theta_lo"] = psfSrc["THETA_LO"][0]
						result["theta_hi"] = psfSrc["THETA_HI"][0]
						result["rad_lo"] = psfSrc["RAD_LO"][0]
						result["rad_hi"] = psfSrc["RAD_HI"][0]
					</code>
				</apply>
				<map key="obs_id">\srcstem.split("_")[-1]</map>
				<map key="livetime">@hdus[1].header["LIVETIME"]</map>
				<map key="target_name">@hdus[1].header["OBJECT"]</map>
				<map key="time_start">dateTimeToMJD(
					datetime.datetime.utcfromtimestamp(
						@hdus["GTI"].header["TSTART"]))</map>
				<map key="time_stop">dateTimeToMJD(
					datetime.datetime.utcfromtimestamp(
						@hdus["GTI"].header["TSTOP"]))</map>
			</rowmaker>
		</make>
	</data>

	<table id="main" onDisk="True" mixin="//scs#q3cindex" adql="Hidden">
		<meta name="description">Suspected gamma photons detected by
			H.E.S.S.</meta>
		<!-- <primary>event_id</primary> -->
		<foreignKey source="obs_id" inTable="obs" metaOnly="True"/>

		<stc>
			Position ICRS "ra" "dec"
		</stc>

		<column name="event_id" type="bigint" required="True"
			ucd="meta.id;meta.main"
			description="Unique event id computed as BUNCH_ID &lt;&lt; 32 | HESS_ID."
			verbLevel="1"/>
		<column name="ra" type="double precision"
			unit="deg" ucd="pos.eq.ra;meta.main"
			tablehead="RA"
			description="ICRS right ascension of the event."
			verbLevel="1"
			displayHint="sf=5"/>
		<column name="dec" type="double precision"
			unit="deg" ucd="pos.eq.dec;meta.main"
			tablehead="Dec"
			description="ICRS declination of the event."
			verbLevel="1"
			displayHint="sf=5"/>
		<column name="event_mjd" type="double precision"
			unit="d" ucd="time.epoch;obs"
			description="Epoch of the event"
			verbLevel="1"
			displayHint="sf=3"/>
		<column name="energy" type="real"
			unit="TeV"
			description="Reconstructed event energy"
			verbLevel="1"
			displayHint="sf=3"/>
		<column name="detx" type="real"
			ucd="pos.cartesian.x;instr" unit="deg"
			description="Reconstructed field of view X"
			verbLevel="15"
			displayHint="sf=1"/>
		<column name="dety" type="real"
			ucd="pos.cartesian.x;instr" unit="deg"
			description="Reconstructed field of view Y"
			verbLevel="15"
			displayHint="sf=1"/>
		<column original="obs.obs_id"/>
	</table>

	<coverage>
		<updater spaceTable="main" timeTable="main"/>
		<spectral>2.4E-8 3.7e-5</spectral>
	</coverage>

	<data id="import">
		<sources original="allbunches"/>

		<fitsTableGrammar lowerKeys="True"/>

		<make table="main">
			<rowmaker idmaps="*">
				<map key="event_mjd">dateTimeToMJD(
					datetime.datetime.utcfromtimestamp(@time))</map>
				<map key="obs_id">\srcstem.split("_")[-1]</map>
			</rowmaker>
		</make>
	</data>

	<service id="cone" allowed="form,scs.xml">
		<meta name="shortName">HESS scs</meta>
		<meta name="testQuery">
			<meta name="ra">204.1106414794922</meta>
			<meta name="dec">-27.04576301574707</meta>
			<meta name="sr">0.0001</meta>
		</meta>

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

		<scsCore queriedTable="main">
			<FEED source="//scs#coreDescs"/>
			<condDesc buildFrom="event_mjd"/>
			<condDesc buildFrom="energy"/>
		</scsCore>

		<outputTable autoCols="*">
			<outputField original="obs_id">
				<formatter>
					return T.a(href=f"/\rdId/obsmeta/qp/{data}")[
						"Observation Metadata"]
				</formatter>
			</outputField>
		</outputTable>
	</service>

	<service id="obsmeta" allowed="qp,form">
		<meta name="title">HESS observation metadata</meta>
		<property name="queryField">obs_id</property>
		<dbCore queriedTable="obs">
			<condDesc buildFrom="obs_id"/>
		</dbCore>
	</service>

	
	<regSuite title="hesspub regression">
		<regTest title="hesspub SCS serves some data">
			<url RA="204.1"
					DEC="-27" SR="0.1"
					event_mjd="41767.141521 41767.141522"
				>cone/scs.xml</url>
			<code>
				row = self.getFirstVOTableRow()
				self.assertAlmostEqual(row["ra"], 204.11064147)
				self.assertEqual(row["obs_id"], '020136')
			</code>
		</regTest>
	</regSuite>
</resource>
