<resource schema="onebigb">
	<meta name="title">1BIGB: First Brazil-ICRANet Gamma-Ray Blazar
		Catalogue</meta>
	<meta name="creationDate">2018-04-23T17:05:03</meta>
	<meta name="schema-rank">1000</meta>
	<meta name="description" format="rst">
	This catalog presents the 1-100 GeV spectral energy distribution (SED)
	for a population of 148 high-synchrotron-peaked blazars (HSPs) recently
	detected with Fermi-LAT as part of the
	First Brazil-ICRANet Gamma-ray Blazar catalogue (1BIGB).
	A series of two works describe details on the broadband analysis:
	:bibcode:`2017A&amp;A...598A.134A`, and the calculation of the
	gamma-ray SEDs :bibcode:`2018MNRAS.480.2165A`.

	The 1BIGB sample was originally selected from an excess signal in the
	0.3-500 GeV band The flux estimates presented here are derived considering
	PASS8 data, integrating over more than 9 years of Fermi-LAT observations. The
	full broadband fit between 0.3-500 GeV presented in paper 1 for all sources
	was reevaluated in paper 2, updating the power-law parameters with currently
	</meta>
	<meta name="creator">Arsioli, B.; de Almeida, U.B.</meta>

	<meta name="subject">catalogs</meta>
	<meta name="subject">gamma-ray-sources</meta>
	<meta name="subject">high-energy-astrophysics</meta>
	<meta name="subject">blazars</meta>

	<meta name="ssap.creationType">archival</meta>

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

	<meta name="source">
	 	2018MNRAS.480.2165A
	</meta>
	<meta name="facility">Fermi FGST</meta>
	<meta name="instrument">Fermi LAT</meta>

	<table id="measurements" onDisk="True" adql="True">
		<meta name="description">A table of raw measurement points.
			See the seds table for combined SEDs.</meta>

		<column name="id" type="integer"
			ucd="meta.id;meta.main"
			tablehead="ID" verbLevel="20"
			description="Datapoint ID"
			required="True"/>

		<column name="iauid" type="text"
			ucd="meta.id"
			tablehead="Obj. Id"
			description="IAU-compliant identifier of the Blazar"/>

		<column name="ra" type="double precision"
			unit="deg" ucd="pos.eq.ra;meta.main"
			tablehead="R.A." verbLevel="1"
			description="Right Ascension"/>

		<column name="dec" type="double precision"
			unit="deg" ucd="pos.eq.dec;meta.main"
			tablehead="Dec." verbLevel="1"
			description="Declination"/>

		<column name="frequency" type="real"
			unit="Hz" ucd="em.freq"
			tablehead="Frequency" verbLevel="1"
			description="Flux measurement frequency"
			required="True"/>

		<column name="nufnu" type="real"
			unit="erg.cm**-2.s**-1" ucd="phot.flux"
			tablehead="Flux" verbLevel="1"
			description="nuFnu Flux"
			required="True"/>

		<column name="nufnu_error" type="real"
			unit="erg.cm**-2.s**-1" ucd="stat.error;phot.flux"
			tablehead="Flux error" verbLevel="1"
			description="nuFnu Flux error"
			required="True"/>

		<column name="upper_limit" type="text"
			ucd="meta.code"
			tablehead="upper-limit" verbLevel="1"
			description="Flux upper limit"
			required="False">
			<values nullLiteral=""/>
		</column>
	</table>

	<data id="import">
		<sources>data/1bigb.csv</sources>
		<csvGrammar/>
		<make table="measurements">
			<rowmaker simplemaps="nufnu:flux,nufnu_error:flux_err"
					idmaps="id,ra,dec,frequency,upper_limit">
				<map key="iauid">makeIAUId('1BIGBJ',
					float(@ra), float(@dec), 1, 0)</map>
			</rowmaker>
		</make>
		<recreateAfter>build_seds</recreateAfter>
	</data>

	<table id="seds" namePath="//ssap#instance" mixin="//products#table"
			onDisk="True" adql="hidden">
		<meta name="description">SEDs constructed from the measurements
			table by grouping by object</meta>

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

		<column original="measurements.iauid"/>
		<column name="ra" type="double precision"
			unit="deg" ucd="pos.eq.ra;meta.main"
			tablehead="R.A."
			description="ICRS Right Ascension of the Blazar"/>

		<column name="dec" type="double precision"
			unit="deg" ucd="pos.eq.dec;meta.main"
			tablehead="Dec."
			description="ICRS Declination of the Blazar"/>

		<column original="ssa_specstart"/>
		<column original="ssa_specend"/>

		<column name="err_max"
			unit="erg.cm**-2.s**-1" ucd="stat.error;phot.flux"
			tablehead="Flux err."
			description="Maximal statistical flux error in the dataset"/>

		<column original="measurements.frequency" type="real[]"/>
		<column original="measurements.nufnu" type="real[]"/>
		<column original="measurements.nufnu_error" type="real[]"
			description="Error in nuFnu; a zero here indicates an upper limit"/>
	</table>

	<data id="build_seds" auto="False">
		<property key="previewDir">previews</property>
		<recreateAfter>build_ssa</recreateAfter>

		<sources item="database query"/>

		<embeddedGrammar>
			<rowfilter name="fix_source_token">
				<code>
					rowIter.sourceToken = "\schema/"+@iauid
					yield row
				</code>
			</rowfilter>
			
			<rowfilter procDef="//products#define">
				<bind key="path">\fullDLURL{sdl}</bind>
				<bind key="accref">rowIter.sourceToken</bind>
				<bind key="mime">"application/x-votable+xml"</bind>
				<bind key="fsize">4000</bind>
				<bind key="table">"\schema.seds"</bind>
				<bind key="preview_mime">"image/png"</bind>
				<bind key="preview">\standardPreviewPath</bind>
			</rowfilter>
			<iterator><code>
				with base.getTableConn() as conn:
					return conn.queryToDicts(
						"""
						SELECT iauid as iauid,
							ra, dec,
							max(nufnu_error) as err_max,
							array_agg(frequency) as frequency,
							array_agg(nufnu) as nufnu,
							array_agg(nufnu_error) as nufnu_error
						FROM \schema.measurements
						GROUP BY ra, dec, iauid""")
			</code></iterator>
		</embeddedGrammar>

		<make table="seds">
			<rowmaker idmaps="*">
				<map key="ssa_specstart">LIGHT_C/max(@frequency)</map>
				<map key="ssa_specend">LIGHT_C/min(@frequency)</map>
				<apply procDef="//ssap#fill-plainlocation">
					<bind key="aperture">0.45</bind>
					<bind key="ra">@ra</bind>
					<bind key="dec">@dec</bind>
				</apply>
			</rowmaker>
		</make>
	</data>

	<table id="ssa" onDisk="True" adql="True">
		<meta name="description">SSA-compliant table of SEDs constructed
			within 1BIGB.</meta>
		<index columns="ssa_location" method="GIST"/>
		<index columns="ssa_pubdid"/>

		<!-- on ssa_dateObs and friends: The observations in effect cover
			2008-08 through 2017-08 as per paper II.  The midpoint of that
			is about MJD 56380.  And timeExt is about 3300 days. -->
		<mixin
			accref="'\schema/' || iauid"
			accsize="4000"
			copiedcolumns="frequency,nufnu,nufnu_error"
			sourcetable="seds"
			ssa_aperture="0.45"
			ssa_bandpass="'Gamma-ray'"
			ssa_binSize="1e-15"
			ssa_collection="'1BIGB'"
			ssa_creator="'Arsioli et al'"
			ssa_datasource="'pointed'"
			ssa_dateObs="56380.0"
			ssa_dstitle="'1BIGB GeV SED for ' || iauid"
			ssa_fluxStatError="err_max"
			ssa_fluxcalib="'ABSOLUTE'"
			ssa_fluxucd="'phot.flux'"
			ssa_fluxunit="'erg.cm**-2.s**-1'"
			ssa_length="\+array_length(frequency, 1)"
			ssa_location="ssa_location"
			ssa_region="ssa_region"
			ssa_speccalib="'ABSOLUTE'"
			ssa_specres="5e-16"
			ssa_spectralucd="'em.freq'"
			ssa_spectralunit="'Hz'"
			ssa_targclass="'Blazar'"
			ssa_targname="iauid"
			ssa_timeExt="2.87e8"
			>//ssap#view</mixin>
		<mixin
			calibLevel="3"
			coverage="ssa_region"
			t_resolution="3e8"
			facility_name="'Fermi'"
			>//obscore#publishSSAPMIXC</mixin>
		
	</table>

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

	<data id="build_ssa" auto="False">
		<make table="ssa"/>
	</data>

 <table id="spectrum">
		<mixin ssaTable="ssa"
			fluxDescription="Calibrated Flux ν F_ν"
			spectralDescription="Frequency"
			>//ssap#sdm-instance</mixin>
		<column name="flux_error"
			unit="erg.cm**-2.s**-1" ucd="stat.error;phot.flux"
			tablehead="Flux error"
			description="Flux error; a 0 here means an upper limit"/>
	</table>

	<data id="build_sdm_data" auto="False">
		<embeddedGrammar>
			<iterator>
				<code>
					with base.getTableConn() as conn:
						res = list(conn.query(
							"select frequency, nufnu, nufnu_error from \schema.seds"
							"  where accref=%(accref)s",
							{"accref": self.sourceToken["accref"]}))[0]

					for nu, nufnu, errNufnu in zip(*res):
						yield {"spectral": nu, "flux": nufnu, "flux_error": errNufnu}
				</code>
			</iterator>
		</embeddedGrammar>
		<make table="spectrum">
			<parmaker>
				<apply procDef="//ssap#feedSSAToSDM"/>
			</parmaker>
		</make>
	</data>

	<service id="sdl" allowed="dlget,dlmeta">
		<meta name="title">1BIGB Datalink Service</meta>

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

		<datalinkCore>
			<descriptorGenerator procDef="//soda#sdm_genDesc">
				<bind name="ssaTD">"\rdId#ssa"</bind>
			</descriptorGenerator>
			<dataFunction procDef="//soda#sdm_genData">
				<bind name="builder">"\rdId#build_sdm_data"</bind>
			</dataFunction>
			<FEED source="//soda#sdm_plainfluxcalib"/>
			<FEED source="//soda#sdm_format"/>
		</datalinkCore>
	</service>

	<service id="web" defaultRenderer="form">
		<meta name="shortName">1BIGB Web</meta>
		<meta name="title">1BIGB Spectra Web Interface</meta>

		<dbCore queriedTable="ssa">
			<condDesc buildFrom="ssa_location"/>
		</dbCore>

		<outputTable>
			<autoCols>
				ssa_targname, accref, ssa_reference,
				ssa_timeExt, ssa_instrument, ssa_length
			</autoCols>
			<FEED source="//ssap#atomicCoords"/>
			<outputField original="ssa_specend"
				tablehead="Lower Energy"
				displayHint="spectralUnit=GeV,sf=0"/>
			<outputField original="ssa_specstart"
				tablehead="Upper Energy"
				displayHint="spectralUnit=GeV,sf=0"/>
		</outputTable>
	</service>

	<service id="ssap" allowed="ssap.xml">
		<meta name="shortName">1BIGB SSAP</meta>
		<meta name="ssap.dataSource">pointed</meta>
		<meta name="ssap.creationType">archival</meta>
		<meta name="ssap.testQuery">MAXREC=1</meta>

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

		<ssapCore queriedTable="ssa">
			<FEED source="//ssap#hcd_condDescs"/>
		</ssapCore>

	</service>

	<regSuite title="1BIGB regression">
		<regTest title="1BIGB data available">
			<url POS="54.63,-57.08" SIZE="0.3" REQUEST="queryData">ssap/ssap.xml</url>
			<code>
				row = self.getFirstVOTableRow()
				self.assertAlmostEqual(row["ssa_specext"], 1.2264238E-15)
				self.assertEqual(row["ssa_targclass"], "Blazar")
				self.assertTrue(row["accref"].endswith(
					"getproduct/onebigb/1BIGBJ033831.9-570447"))
			</code>
		</regTest>

		<regTest title="1BIGB data delivery">
			<url httpHonorRedirects="True"
				>/getproduct/onebigb/1BIGBJ033831.9-570447</url>
			<code>
				row = self.getFirstVOTableRow(rejectExtras=False)
				self.assertAlmostEqual(row["spectral"]/2.42e+23, 1)
				self.assertAlmostEqual(row["flux"]/2.04e-13, 1)
				self.assertAlmostEqual(row["flux_error"], 0.)
				self.assertHasStrings("Calibrated Flux ν F_ν")
			</code>
		</regTest>

		<regTest title="1BIGB previews avaiable">
			<url>/getproduct/onebigb/1BIGBJ010250.8-200158?preview=True</url>
			<code>
				self.assertHasStrings("PNG", "RLX")
			</code>
		</regTest>
	</regSuite>
</resource>

