<resource schema="kapteyn">
	<meta name="creationDate">2012-07-23T16:00:00</meta>
	<meta name="schema-rank">1000</meta>
	<meta name="title">Potsdam Kapteyn Series Plates</meta>
	<meta name="creator">Tsvetkov, M; Tsvetkova, K.; Demleitner, M.</meta>

	<meta name="subject">history-of-astronomy</meta>
	<meta name="subject">astrophotography</meta>
	<meta name="subject">kapteyn-selected-areas</meta>

	<meta name="description" format="rst">
		In the context of Kapteyn's plan to obtain a photometric standard, in
		Potsdam more than 400 photographic plates of several Selected Areas,
		Special Areas, and Kapteyn-Pritchard areas were obtained between 1910 and
		1933, both as direct images and with an object prism.  This service
		provides FITS images of the science area of the plates as well as images of
		the entire plates, including previous markings.
	</meta>

	<meta name="source">1963ASPL....9...89L</meta>
	<meta name="facility">Astrophysikalisches Observatorium Potsdam (42)</meta>
	<meta name="instrument">80cm Great Refractor</meta>
	<meta name="instrument">Zeiss Triplet 15 cm Potsdam-Telegrafenberg</meta>
	<meta name="coverage">
		<meta name="waveband">Optical</meta>
	</meta>

	<meta name="_related" title="hppunion VO service">/hppunion/q/im/info</meta>

	<FEED source="//procs#license-cc-by" what="Kapteyn series plate scans"/>

	<meta name="!copyright" format="rst">
		\RSTccby{Kapteyn series plate scans}

		Support for scanning the plates and obtaining metadata was
		provided by DFG grant STE 710-6-1.  We gratefully acknowledge
		support  by Leibniz-Institut für Astrophysik Potsdam and
		the Bulgarian Academy of Sciences.</meta>

	<table id="plates" onDisk="True" mixin="//siap#pgs" adql="True">
		<index columns="bandpassHi"/>
		<index columns="bandpassLo"/>

		<mixin
			calibLevel="1"
			collectionName="'Potsdam Kapteyn Series'"
			expTime="exposure"
			mime="'application/x-votable+xml;content=datalink'"
			accessURL="'\internallink{\rdId/dl/dlmeta}?ID='||gavo_urlescape(pub_did)"
			size="10"
			facilityName="'AO Potsdam'"
			targetName="object"
			targetClass="'Region'">//obscore#publishSIAP</mixin>

		<meta name="_associatedDatalinkService">
			<meta name="serviceId">dl</meta>
			<meta name="idColumn">pub_did</meta>
		</meta>

		<publish sets="ivo_managed" services="//tap#run,hppunion/q#im"/>

		<column original="accref">
		</column>

		<column name="exposure"
			tablehead="Exp. time" unit="s" ucd="time.duration;obs.exposure"
			description="Effective exposure time." verbLevel="15"/>
		<column name="airmass"
			tablehead="Airmass" ucd="obs.airMass"
			description="Airmass at mean epoch." verbLevel="21"/>
		<column name="object"  type="text"
			tablehead="Targ. Obj." ucd="meta.id"
			description="Special object on plate." verbLevel="15"/>
		<column name="observer"  type="text"
			tablehead="Observer" verbLevel="21" ucd="obs.observer"
			description="Observer."/>
		<column name="start_time"  type="timestamp"
			tablehead="Start" unit="d" ucd="time.start;obs"
			description="UT at start of exposure." verbLevel="15"
			displayHint="type=humanDate"/>
		<column name="end_time"  type="timestamp"
			tablehead="End" unit="d" ucd="time.end;obs"
			description="UT at end of exposure." verbLevel="15"
			displayHint="type=humanDate"/>
		<column name="wfpdb_id" type="text"
			ucd="meta.id"
			tablehead="WFPDB"
			description="Plate identifier as in the WFPDB."
			verbLevel="15"/>
		<column name="pub_did" type="text"
			ucd="meta.ref.url"
			tablehead="Pub. DID"
			description="Dataset identifier assigned by the publisher."
			verbLevel="5"/>
		<column name="platephoto" type="text"
			ucd="meta.ref.url"
			tablehead="Photo"
			description="Image of the plate including border and other
				markings."
			displayHint="type=url"
			verbLevel="15"/>
	</table>

	<coverage>
		<updater sourceTable="plates" mocOrder="4"/>
		<spectral>3.82009e-19 5.22749e-19</spectral>
		<temporal>18867 27155</temporal>
		<spatial>2/0,75,103,119,124 3/4-6,8-9,65-68,72,129,131-132,136-137,194-195,197-198,200-202,224-225,283,286-287,305,307-310,312-313,343,347,350-351,364-365,367,369,371-373,376-377,423,429,431,433-436,440,467,471,473,475,491,494-495,500-502,504 4/40-42,44,48,64,128,258-259,276-278,280-282,292-294,296-298,521-523,532-534,536-538,552-554,556,770,773-775,785-786,812,814,816,832,904-905,907-910,914,1111,1131,1141-1143,1191,1226-1227,1244,1256-1258,1260,1264,1367,1387,1397-1399,1435,1438,1465-1467,1473,1482-1483,1496-1498,1512-1514,1516,1627,1630,1689-1691,1713,1721-1723,1731,1748-1750,1752-1754,1764-1766,1769-1770,1867,1879,1882,1889,1891,1897,1899,1959,1963,1973-1975,2020-2022,2024-2026,2032</spatial>
	</coverage>

	<data id="process_incoming" auto="False">
		<!-- this data item is just for the processors of the incoming files,
		see README -->
		<sources pattern="data/incoming/*.fits" recurse="True"/>
		<nullGrammar/>
		<make><table/></make>
	</data>

	<data id="import" recreateAfter="hppunion/q#import">
		<sources pattern="data/fits/*.fits"/>
		<fitsProdGrammar>
			<rowfilter procDef="//products#define">
				<bind key="table">"\schema.plates"</bind>
				<bind key="preview"
					>"\internallink{\schema/q/dl/static/jpegs/thumb_%s.jpg}"%(
						@WFPDB_ID.replace(" ", "_"))</bind>
				<bind key="preview_mime">"image/jpeg"</bind>
			</rowfilter>
		</fitsProdGrammar>

		<make table="plates">
			<rowmaker>
				<apply procDef="//siap#computePGS">
					<bind key="missingIsError">False</bind>
				</apply>

				<apply procDef="//siap#setMeta" name="setMeta">
					<bind key="dateObs">vars.get("DATE_AVG", @DATE_OBS)</bind>
					<bind key="instrument">@TELESCOP</bind>
					<bind key="title">"Potsdam Kapteyn Series %s for %s"%(
						@PLATENUM, @OBJECT)</bind>
					<bind key="bandpassId">"Pg"</bind>
					<bind key="bandpassLo">3.8e-7</bind>
					<bind key="bandpassHi">5.2e-7</bind>
					<bind key="bandpassRefval">4.5e-7</bind>
					<bind key="bandpassUnit">'m'</bind>
				</apply>

				<simplemaps>
					airmass: AIRMASS,
					object: OBJECT,
					observer: OBSERVER,
					wfpdb_id: WFPDB_ID
				</simplemaps>

				<map key="exposure" source="EXPTIME" nullExcs="KeyError"/>
				<map key="start_time">parseISODT(@DATE_OBS)</map>
				<map key="end_time" nullExcs="KeyError"
					>parseISODT(@DATE_END)</map>
				<map key="platephoto"
					>"\internallink{\rdId/dl/static/jpegs/%s.jpg}"%(
						@WFPDB_ID.replace(" ", "_"))</map>
				<map key="pub_did">\standardPubDID</map>
			</rowmaker>
		</make>
	</data>

	<service id="dl" allowed="dlget,dlmeta,static">
		<meta name="title">Potsdam Kapteyn series datalink service</meta>
		<property name="staticData">data/static</property>

		<datalinkCore>
			<descriptorGenerator procDef="//soda#fits_genDesc">
				<bind name="accrefPrefix">"kapteyn"</bind>
			</descriptorGenerator>
			<FEED source="//soda#fits_standardDLFuncs"
				stcs='PositionInterval ICRS "RA_MIN" "DEC_MIN" "RA_MAX" "DEC_MAX"'/>
			<metaMaker semantics="#preview-image">
				<code>
					svc = rd.getById("dl")
					basename = descriptor.accref.split("/")[-1].split(".")[0]

					yield descriptor.makeLink(
						svc.getURL("static")+"/jpegs/"+basename+".jpg",
						description="Low-res photo with plate borders.",
						contentType="image/jpeg",
						contentLength=os.path.getsize(rd.getAbsPath("data/static"
							"/jpegs/"+basename+".jpg")),
						contentQualifier="#image")
					yield descriptor.makeLink(
						svc.getURL("static")+"/wedges/"+basename+"w.fits",
						description="Greyscale wedge scanned with the data.",
						semantics="#calibration",
						contentType="application/fits",
						contentLength=os.path.getsize(rd.getAbsPath("data/static"
							"/wedges/"+basename+"w.fits")))
				</code>
			</metaMaker>
		</datalinkCore>
	</service>

	<service id="web" allowed="form">
		<meta name="title">Potsdam Kapteyn Plates Web Service</meta>
		<meta name="shortName">Kayteyn Web</meta>

		<publish render="form" sets="local"/>

		<dbCore queriedTable="plates">
			<condDesc original="//siap#humanInput"/>
			<condDesc buildFrom="dateObs"/>
			<condDesc>
				<inputKey original="object" multiplicity="multiple" showItems="5">
					<values fromdb="object from \schema.plates"/>
				</inputKey>
			</condDesc>
			<condDesc combining="True">
				<phraseMaker>
					<code>
						if "_ra" in outPars:
							outPars["X_search_center"] = pgsphere.SPoint.fromDegrees(
								outPars["_ra"], outPars["_dec"])
						else:
							outPars["X_search_center"] = None
						if False:
							yield
					</code>
				</phraseMaker>
			</condDesc>

			<outputTable original="plates">
				<outputField name="_r"
					unit="deg" ucd="pos.distance"
					tablehead="Dist."
					description="Distance to the search center"
					select="degrees(spoint(radians(centerAlpha), radians(centerDelta))
						&lt;-> %(X_search_center)s)"
					displayHint="displayUnit=arcmin,sf=0"/>
			</outputTable>
		</dbCore>

		<outputTable>
			<outputField original="_r"/>
			<outputField original="accref"/>
			<outputField original="accsize"/>
			<outputField name="datalink" type="text"
				select="pub_did"
				ucd="meta.ref.url"
				tablehead="DL"
				description="URL of a datalink document for this dataset."
				verbLevel="1">
				<formatter><![CDATA[
					if data:
						return T.a(href="/\rdId/dl/dlmeta?ID="+
							urllib.parse.quote(data))["[Access]"]
					else:
						return ""
				]]></formatter>		
				<property name="targetType"
					>application/x-votable+xml;content=datalink</property>
				<property name="targetTitle">Datalink</property>
			</outputField>


			<outputField original="accref" name="acc4"
				tablehead="Scaled 1/4"
				description="Original plate scaled to 25%."
				select="accref">
				<formatter><![CDATA[
					if data:
						return T.a(href=makeProductLink(data+"?scale=4"))[
							"[Scaled 25%]"]
					else:
						return ""
				]]></formatter>
			</outputField>

			<LOOP listItems="dateObs centerAlpha centerDelta
				object wfpdb_id imageTitle instId exposure platephoto">
				<events>
					<outputField original="\item"/>
				</events>
			</LOOP>
		</outputTable>
	</service>

	<regSuite>
		<regTest title="Kapteyn datalink has additional metadata">
			<url ID="ivo://org.gavo.dc/~?kapteyn/data/fits/POT015_000317.fits"
				>dl/dlmeta</url>
			<code><![CDATA[
				self.assertHasStrings(
					"<TD>Low-res photo with plate borders.</TD>",
					"kapteyn/q/dl/static/jpegs/POT015_000317.jpg</TD>",
					"<TD>Greyscale wedge scanned with the data.</TD>",
					"kapteyn/q/dl/static/wedges/POT015_000317w.fits</TD>",
					"#proc")
			]]></code>
		</regTest>

		<regTest title="Kapteyn web service somewhat works">
			<url parSet="form" dateObs='1910-08-02T22:36:01 +/- 0.002'
				hPOS="287.05 15.0">web/form</url>
			<code><![CDATA[
				self.assertHasStrings(
					'getproduct/kapteyn/data/fits/POT015_000317.fits?scale=4">',
					'kapteyn/q/dl/dlmeta?ID=ivo%3A//org.gavo.dc/~%3Fkapteyn/data/fits/POT015_000317.fits"',
					'kapteyn/q/dl/static/jpegs/POT015_000317.jpg">',
					'<td>SA 87</td>',
					'>Dist.<')
				# regrettably, the regression test dataset is off of the real one,
				# so we have two distances (in arcmins)
				self.assertTrue(re.search(b"<td>(3|110)</td>", self.data),
					"Can't find either version of the distance from the center")
			]]></code>
		</regTest>

		<regTest title="Kapteyn photos present and delivered">
			<url>dl/static/jpegs/POT015_000317.jpg</url>
			<code>
				self.assertHasStrings("JFIF")
			</code>
		</regTest>

		<regTest title="Kapteyn SODA delivers data">
			<url ID="ivo://org.gavo.dc/~?kapteyn/data/fits/POT015_000317.fits"
				CIRCLE="287.05 15.05 0.001"
				>dl/dlget</url>
			<code>
				self.assertHasStrings(b"NAXIS1  =                    5",
					b"OBJECT  = 'SA 87   '",
					b"\\x46\\xfc\\xbe\\x00\\x46\\xfa\\xfc\\x00")
			</code>
		</regTest>
	</regSuite>
</resource>
