<?xml version="1.0"?>
<resource schema="danish">
	<meta name="title">MiNDSTEP Danish Observatory Lens Images</meta>
	<meta name="creationDate">2008-06-10T12:14:00Z</meta>
	<meta name="schema-rank">1000</meta>
	<meta name="description">TBD</meta>

	<meta name="subject">quasars</meta>
	<meta name="subject">observational-cosmology</meta>
	<meta name="subject">strong-gravitational-lensing</meta>
	
	<meta name="_related" title="Lens Image Collection">
		http://vo.uni-hd.de/lensdemo/view/q/form</meta>
  <meta name="coverage.waveband">Optical</meta>

	<meta name="facility">ESO La Silla</meta>

	<meta name="_news" author="MD" date="2009-03-04">Cleaned up headers; there
		are no invalid header cards any more, and the spurious bzero coming
		in from upstream is gone, too.</meta>
	<meta name="_news" author="MD" date="2009-10-01">New data from 2009
	  campaign.  Slight changes in all file names.</meta>
	<meta name="_news" author="MD" date="2011-01-11">New data from 2010
	  campaign.  Now there are 2469 frames in the DB.</meta>

	<table id="data" onDisk="True" mixin="//siap#pgs">
		<register services="lensunion/q#im"/>

		<index columns="bandpassLo"/>
		<index columns="bandpassHi"/>

		<mixin
			calibLevel="2"
			collectionName="'MiNDSTEp'"
			targetName="object"
			targetClass="'GravLens'"
			expTime="exptime"
			createDIDIndex="True"
		>//obscore#publishSIAP</mixin>

		<column type="text"
			description="Observatory the exposure was prepared at"
			name="observat" tablehead="Observatory"/>
		<column type="text" name="instrume"
			tablehead="Instrument"
			ucd="meta.id;instr"/>
		<column type="text" name="detname"
			tablehead="Detector"/>
		<column type="text" description="Name given at La Silla"
			name="origname"
			tablehead="Orig. Name" ucd="meta.id;meta.file"/>
		<column type="text" description="Object observed" name="object"
			tablehead="Object" ucd="meta.id;meta.main"
			required="True"/>
		<column type="real" description="Exposure time" name="exptime"
			ucd="time.duration;obs.exposure" unit="s"/>
		<column type="timestamp" description="UT start time" name="tm_start"
			ucd="time.epoch;obs.exposure"/>
		<column type="timestamp" description="UT end time" name="tm_end"
			ucd="time.epoch;obs.exposure"/>
		<column type="text" description="Filter used on wheel A" name="filter_a"
				ucd="meta.id;instr.filter"/>
		<column type="text" description="Filter used on wheel B" name="filter_b"
				ucd="meta.id;instr.filter"/>
		<column type="text" description="Filter used" name="filter"
			ucd="meta.id;instr.filter;meta.main"
			tablehead="Filter"/>
		<column type="real" description="Sidereal time at start" name="st"
			tablehead="Sid. time" unit="s"/>
		<column type="real" description="Right ascension at start"
			name="ra" ucd="pos.eq.ra;meta.main" unit="deg"
			tablehead="RA"/>
		<column type="real" description="Declination at start" name="dec"
			ucd="pos.eq.dec;meta.main" unit="deg" tablehead="Dec"/>
		<column type="real" description="Hour Angle at start" name="ha"
			tablehead="H.A."/>
		<column type="real" description="Zenith distance at start" name="zdist"
			ucd="pos.az.zd" unit="deg"/>
	</table>

	<coverage>
		<updater sourceTable="data" mocOrder="5"/>
		<temporal>54622.4 55435.4</temporal>
		<spatial>5/4186-4187,4208-4209,4371,4376-4377,4379-4380,4440-4441,4443,4718,4801,4804-4806,4938-4939,4960-4961,5639,5645,5650,5656,5658,11514,11845,11847,11856</spatial>
		<spectral>2.25732e-19 4.09576e-19</spectral>
	</coverage>

	<rowmaker id="build_data">
		<var name="dateOfObs">datetime.datetime.combine(
			parseTimestamp(@DATE_OBS).date(), datetime.time(0,0,0))</var>

		<apply procDef="//procs#mapValue" name="mapFilterA">
			<bind key="sourceName">"danish/res/filtermap.txt"</bind>
			<bind key="destination">"filter_a"</bind>
			<bind key="value">vars["FILTER_A"]</bind>
		</apply>

		<apply procDef="//procs#mapValue" name="mapFilterB">
			<bind key="sourceName">"danish/res/filtermap.txt"</bind>
			<bind key="destination">"filter_b"</bind>
			<bind key="value">vars["FILTER_B"]</bind>
		</apply>

<!-- we now map in fixHeaders!
		<apply procDef="//procs#mapValue" name="mapObjects">
			<bind key="sourceName">"danish/res/objectmap.txt"</bind>
			<bind key="destination">"object"</bind>
			<bind key="value">vars["OBJECT"]</bind>
		</apply> -->

		<apply procDef="//siap#setMeta">
			<bind key="title">"%s_%s"%(vars["OBJECT"], vars["DATE_OBS"])</bind>
			<bind key="instrument">vars["TELESCOP"]</bind>
			<bind key="dateObs">vars["DATE_OBS"]</bind>
			<bind key="bandpassId">"+".join([f for f in [vars["filter_a"],
				vars["filter_b"]] if f!="clear"])</bind>
		</apply>

		<apply procDef="//siap#getBandFromFilter"/>

		<apply procDef="//siap#computePGS"/>

		<map dest="filter">result["bandpassId"]</map>
	
		<map dest="tm_start">@dateOfObs+parseTime(
			@TM_START, "!!secondsSinceMidnight")</map>
		<map dest="tm_end">@dateOfObs+parseTime(
			@TM_END, "!!secondsSinceMidnight")</map>

		<simplemaps>observat:OBSERVAT, instrume:INSTRUME, detname:DETNAME,
			origname:FILENAME, exptime:EXPTIME, st:ST, ra:RA, dec:DEC,
			ha:HA, zdist:ZDIST, object:OBJECT</simplemaps>
		<idmaps>object, filter_a, filter_b</idmaps>
	</rowmaker>

	<data id="content" auto="False" recreateAfter="lensunion/q#import">
		<sources pattern="data/*.fits">
			<ignoreSources fromfile="res/badframes.txt"/>
		</sources>

		<fitsProdGrammar qnd="True">
			<rowfilter procDef="//products#define">
				<bind key="embargo">parseTimestamp(row["DATE_OBS"])+datetime.timedelta(
					days=365)</bind>
				<bind key="owner">"danish"</bind>
				<bind key="table">"danish.data"</bind>
			</rowfilter>
		</fitsProdGrammar>

		<make table="data" rowmaker="build_data"/>
	</data>

	<data id="update" original="content" updating="True">
		<sources pattern="data/*.fits">
			<ignoreSources fromdb="select accref from danish.data"
				fromfile="res/badframes.txt"/>
		</sources>
	</data>

	<dbCore id="qcore" queriedTable="data" namePath="data">
		<condDesc>
			<inputKey original="object" showItems="2" type="text" required="True"
				multiplicity="multiple">
				<values fromdb="object FROM danish.data"/>
			</inputKey>
		</condDesc>
		<condDesc buildFrom="dateObs"/>
		<condDesc>
			<inputKey original="filter" showItems="3" multiplicity="multiple">
				<values fromdb="filter FROM danish.data"/>
			</inputKey>
		</condDesc>
	</dbCore>

	<service id="q" core="qcore">
		<publish render="form" sets="local"/>
		<meta name="shortName">dan_object</meta>
		<meta name="title">MiNDSTEp Lens Images</meta>
		<property name="defaultSort">dateObs</property>
		<outputTable namePath="data">
			<column original="dateObs" displayHint="type=humanDate"/>
			<LOOP listItems= "object exptime filter accsize">
				<events>
					<column original="\item"/>
				</events>
			</LOOP>
			<column original="accref" displayHint="type=product,width=100"/>
			<column name="aladin" type="text" select="NULL" wantsRow="true"
					tablehead="Aladin" displayHint="noxml=true">
				<formatter>
					imgURL = makeProductLink(data["accref"])
					aladinPrefix = ("http://aladin.u-strasbg.fr/java/nph-aladin.pl"
						"?frame=launching&amp;script=load%20")
					return T.a(href="%s%s"%(aladinPrefix, urllib.parse.quote(imgURL)))[
						"[Open Applet]"]
				</formatter>
			</column>
		</outputTable>
	</service>

	<regSuite title="danish DaCHS regression">
		<regTest title="Scaled FITS looks plausible and complete">
			<url>/getproduct/danish/data/Q2237_0305_20080828T24210.fits?scale=10</url>
			<code>
				self.assertHasStrings("NAXIS1  =                  214",
				"FULLURL = 'http://",
				b'\\xdcF\\xf3\\xf3\\x1b')
			</code>
		</regTest>
	</regSuite>
</resource>
