<resource resdir="emi" schema="emi">
	<meta name="title">VLBI images of Lockman Hole radio sources</meta>
	<meta name="description" format="plain">
		These are 1.4GHz Very Long Baseline Interferometry images of 532 radio
		sources with a flux density exceeding 100uJy as determined by Ibar et al.
		(2009, MNRAS, 397, 281), obtained between 2010-06-03 and 2010-09-03.
		
		For all fields, we give frames processed using natural weighting to
		preserve maximal sensitivity.  For the 65 detected sources, we additionally
		give frames processed using uniform weighting to suppress sidelobes (see
		Middelberg et al. 2013, A&amp;A 551, 97 for details) in flux density
		measurements. Some sources have larger images to cover a larger area
		because the initial coordinates were not sufficiently accurate.
	</meta>

	<meta name="creator">
		<meta name="name">Middelberg, E.</meta>
	</meta>
	<meta name="creator">
		<meta name="name">Deller, A.</meta>
	</meta>
	<meta name="creator">
		<meta name="name">Norris, R.</meta>
	</meta>
	<meta name="creator">
		<meta name="name">Fotopuoulou, S.</meta>
	</meta>
	<meta name="creator">
		<meta name="name">Salvato, M.</meta>
	</meta>
	<meta name="creator">
		<meta name="name">Morgan, J.</meta>
	</meta>
	<meta name="creator">
		<meta name="name">Brisken, W.</meta>
	</meta>
	<meta name="creator">
		<meta name="name">Lutz, D.</meta>
	</meta>
	<meta name="creator">
		<meta name="name">Rovilos, E.</meta>
	</meta>

	<meta name="content">
		<meta name="type">Survey</meta>
	</meta>
	<meta name="source">2013A&amp;A...551A..97M</meta>

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

	<meta name="creationDate">2013-04-09T12:57:26Z</meta>
	<meta name="schema-rank">100</meta>

	<meta name="subject">radio-interferometry</meta>
	<meta name="subject">galaxy-evolution</meta>
	<meta name="subject">active-galaxies</meta>

	<meta name="facility"> Very Long Baseline Array, operated by The National
		Radio Astronomy Observatory</meta>

	<table id="main" onDisk="True">
		<mixin>//siap2#pgs</mixin>
		<mixin preview="NULL">//obscore#publishObscoreLike</mixin>
		<mixin
			s_resolution_min="s_resolution_min"
			s_resolution_max="s_resolution_max"
			>//obs-radio#publish</mixin>

		<column name="target_name" original="target_name"
			description="Source name as in
				2009MNRAS.397..281I (VizieR J/MNRAS/397/281)"/>
		<column name="obsra"
			ucd="pos.eq.ra" unit="deg"
			description="Antenna pointing, RA"
			verbLevel="18"/>
		<column name="obsdec"
			ucd="pos.eq.dec" unit="deg"
			description="Antenna pointing, Dec"
			verbLevel="18"/>
		<column name="weighting" type="text"
			ucd="meta.code"
			description="Natural or uniform, according to weighting method."
			verbLevel="18">
			<values><option>natural</option><option>uniform</option></values>
		</column>
		<column original="//obs-radio#obs_radio.s_resolution_min"/>
		<column original="//obs-radio#obs_radio.s_resolution_max"/>
	</table>

	<coverage>
		<updater spaceTable="main" timeTable="main"/>
		<spectral>8.712e-25 9.596e-25</spectral>
		<temporal>55381 55381</temporal>
		<spatial>5/1517 6/6047,6090,6112</spatial>
	</coverage>

	<data id="import_main">
		<sources recurse="True">
			<pattern>*.fits</pattern>
		</sources>
		<fitsProdGrammar qnd="True">
			<maxHeaderBlocks>80</maxHeaderBlocks>
			<mapKeys>
				<map key="object">OBJECT</map>
				<map key="obsdec">OBSDEC</map>
				<map key="obsra">OBSRA</map>
			</mapKeys>
			<rowfilter procDef="__system__/products#define">
				<bind key="table">"emi.main"</bind>
			</rowfilter>
		</fitsProdGrammar>

		<make table="main" >
			<rowmaker id="gen_rmk" idmaps="obsra, obsdec, s_resolution*">
				<apply name="fixObjectName">
					<setup imports="csv">
						<code>
							with open(rd.getAbsPath("res/namemap.csv")) as f:
								nameMap = dict(csv.reader(f))
						</code>
					</setup>
					<code>
						@target_name = nameMap[@object]
					</code>
				</apply>

				<apply name="extract_resolution">
					<!-- the beam size is in AIPS HISTORY cards, which we'll ad-hoc
					parse here -->
					<code>
						for card in @header_["HISTORY"]:
							if "CLEAN BMAJ" in card:
								@s_resolution_max = float(
									re.search("BMAJ= *([0-9.E-]+)", card).group(1))
								@s_resolution_min = float(
									re.search("BMIN= *([0-9.E-]+)", card).group(1))
								break
					</code>
				</apply>

				<apply procDef="//siap2#computePGS"/>
				<apply procDef="//siap2#setMeta">
					<bind name="em_min">0.207</bind>
					<bind name="em_max">0.228</bind>
					<!-- since the images are fairly complex mosaics, there's no way we
					can have sensible dates; this one here "plays a special role
					in the calibration" (Middelberg) -->
					<bind name="t_min"
						>dateTimeToMJD(datetime.datetime(2010, 7, 4))</bind>
					<bind name="t_max"
						>dateTimeToMJD(datetime.datetime(2010, 7, 4))</bind>
					<bind name="obs_title">"VLBA 1.4 GHz "+@target_name</bind>
					<bind name="calib_level">3</bind>
					<bind name="obs_collection">"VLBA LH sources"</bind>
					<bind name="o_ucd">"phot.flux.density;em:radio.750-1500MHz;phys.polarisation.Stokes.I"</bind>
					<bind name="pol_states">"/I/"</bind>
					<bind name="pol_xel">1</bind>
					<bind name="target_name">@target_name</bind>
					<bind name="t_resolution">5000000</bind>
					<bind name="target_class">"agn"</bind>
					<bind name="instrument_name">"VLBA"</bind>
				</apply>
				
				<map key="weighting">\inputRelativePath.split("_")[-1][:-5]</map>
			</rowmaker>
		</make>
	</data>

	<service id="browse" allowed="form">
		<meta name="shortName">VLBI-Lockman web</meta>
		<meta name="title">Browser interface to VLBI images of Lockman
			Hole radio sources</meta>
		<dbCore queriedTable="main">
			<condDesc original="//siap2#humanInput"/>
			<condDesc>
				<inputKey original="target_name" showItems="10" multiplicity="multiple">
					<values fromdb="target_name from emi.main order by target_name"/>
				</inputKey>
			</condDesc>
			<condDesc buildFrom="weighting"/>
			<outputTable autoCols="target_name, access_estsize">
				<column original="access_url"/>
				<column original="s_ra" displayHint="type=hms"/>
				<column original="s_dec" displayHint="type=dms"/>
			</outputTable>
		</dbCore>
	</service>

	<service id="s" allowed="form,siap2.xml">
		<meta name="shortName">VLBI-Lockman</meta>
		<meta name="sia.type">Pointed</meta>
		<meta name="testQuery.pos.ra">163.3</meta>
		<meta name="testQuery.pos.dec">57.8</meta>
		<meta name="testQuery.size.ra">0.1</meta>
		<meta name="testQuery.size.dec">0.1</meta>

		<publish render="siap2.xml" sets="ivo_managed"/>
		<publish render="form" sets="ivo_managed,local" service="browse"/>

		<dbCore queriedTable="main">
			<FEED source="//siap2#parameters"/>
			<condDesc buildFrom="weighting"/>
		</dbCore>
	</service>

	<regSuite title="emi regression">
		<regTest title="emi siap2 looks plausible">
			<url POS="CIRCLE 162.24 57.15 0.02" weighting="uniform">
				s/siap2.xml
			</url>
			<code>
				res = self.getVOTableRows()
				self.assertEqual(len(res), 1)
				self.assertEqual(res[0]["access_url"], EqualingRE(
					"https?://.*/getproduct/emi/data/L0009_uniform.fits"))
				self.assertEqual(res[0]["access_estsize"], 16448)
				self.assertEqual(res[0]["weighting"], "uniform")
			</code>
		</regTest>

		<regTest title="emi form interface looks plausible">
			<url parSet="form" hPOS="162.24,+57.15" hSIZE="0.02"
				>browse/form</url>
			<code>
				self.assertHasStrings(
					'onmouseover="insertPreview(this, null)"', # image shown
					"LH1.4GHzJ104858.3+570925", # title given
					"Source name as in 2009MNRAS.397..281I") # source combo box
			</code>
		</regTest>

		<regTest title="Parameter values with pluses are passed through">
			<url parSet="form"
				target_name="LH1.4GHzJ104858.3+570925">browse/form</url>
			<code>
				self.assertHasStrings(
					"getproduct/emi/data/L0009_uniform.fits", # at least a match, so
						           # the + isn't butchered by the input layer either.
				)
			</code>
		</regTest>

		<regTest title="obs_radio table is there and works">
			<url parSet="TAP"><QUERY>
				SELECT * FROM
				ivoa.obscore NATURAL JOIN ivoa.obs_radio
				WHERE obs_collection='VLBA LH sources'
					AND distance(s_ra, s_dec, 162.24295, 57.15716)&lt;0.001
					AND em_min between 0.2 and 0.3
					AND t_min=55381
					AND s_resolution_max between 2.0823e-06 and 2.0825e-06
				</QUERY>/tap/sync</url>
			<code>
				row = self.getFirstVOTableRow()
				self.assertEqual(row["target_class"], "agn") # from obscore
				self.assertEqual(row["uv_distance_min"], None) # defaulted obs_radio
				self.assertAlmostEqual(row["s_resolution_min"],
					1.4388999716175022e-06) # non-defaulted obs_radio
			</code>
		</regTest>
	</regSuite>
</resource>
