<?xml version="1.0" encoding="iso-8859-1"?>

<resource schema="obscode">
	<meta name="title">Observatory Codes</meta>
	<meta name="creationDate">2010-03-03T10:10:00Z</meta>
	<meta name="schema-rank">500</meta>
	<meta name="description" format="plain">
		List of Observatory Codes assigned by
		the Minor Planet Center (MPC). The codes are used in cataloguing
		astrometric observations of small bodies in the solar system. A code is
		unique for a certain location and consists of three digits or one letter
		and two digits.

		In this representation, we give the observatory code, the geocentric
		coordinates, and the observatory designation.
	</meta>

	<meta name="_longdoc" format="rst"><![CDATA[
		In addition to the values given in the
		`original MPC list <http://www.cfa.harvard.edu/iau/lists/ObsCodesF.html>`_,
		we give the geocentric and geodetic latitudes and the height
		(more or less above sea level) computed from the parallax
		constants given in the source.  The data in MPC's list
		is given to three to six decimal places, so the accuracy of
		these values is usually not better than a couple of dozen meters
		(and can be substantially worse at times).
	]]></meta>

	<meta name="creator">Minor Planet Center</meta>

	<meta name="subject">catalogs</meta>
	<meta name="subject">observatories</meta>

	<meta name="source">1983MPC..7759......</meta>
	<meta name="_related" title="Source">http://www.cfa.harvard.edu/iau/lists/ObsCodes.html</meta>

	<macDef name="osmBase">http://www.openstreetmap.org?zoom=17</macDef>

	<execute every="2592000" title="Update ObsData" id="runupdate">
		<job>
			<code>
				execDef.spawn(["dachs", "imp", "obscode/q", "update_from_upstream"])
			</code>
		</job>
	</execute>

	<table onDisk="True" id="data" adql="True">
		<column name="code" type="text" tablehead="Code"
			description="Observatory Code assigned by the Minor Planet Center"
			ucd="meta.id" />
		<column name="long" tablehead="Long."
			description="Longitude of the observatory"
			ucd="pos.earth.lon" unit="deg"/>
		<column name="cosphip" tablehead="rho cos(phi')"
			description="Parallax constant, cosine"/>
		<column name="sinphip" tablehead="rho sin(phi')"
			description="Parallax constant, sine"/>
		<column name="gclat" tablehead="GC Lat."
			description="Geocentric latitude of the observatory"
			ucd="pos.earth.lat;pos.geocentric" unit="deg"/>
		<column name="gdlat" tablehead="GD Lat."
			description="Geodetic latitude of the observatory WGS84"
			ucd="pos.earth.lat;pos.geocentric" unit="deg"/>
		<column name="height" tablehead="Alt."
			description="Altitude of the observatory"
			ucd="pos.earth.altitude" unit="m"
			displayHint="sf=0"/>
		<column name="name" tablehead="Name"
			description="Operator-chosen designation of the Observatory"
			ucd="meta.id;meta.main" type="text"/>
	</table>

	<data id="import">
		<sources pattern="data/ObsCodes.dat"/>
		<columnGrammar topIgnoredLines="2">
			<col key="code">1-4</col>
			<col key="long">5-13</col>
			<col key="cosphip">14-21</col>
			<col key="sinphip">22-30</col>
			<col key="name">31-</col>

			<ignoreOn>
				<keyIs key="sinphip" value=""/>
				<keyIs key="sinphip" value="0.000000"/>
			</ignoreOn>
	</columnGrammar>

		<rowmaker id="build_data" idmaps="*">
			<var name="gclat">math.atan2(float(@sinphip), float(@cosphip))/utils.DEG
				</var>
			<var name="rho">math.sqrt(float(@sinphip)**2+float(@cosphip)**2)</var>
			<apply name="trafo">
				<setup>
					<code>
						from gavo.stc import geo
					</code>
				</setup>
				<code>
					long, lat, height = geo.geocToGeod(
						float(vars["long"]), vars["gclat"], vars["rho"])
					vars["height"] = height
					vars["gdlat"] = lat
				</code>
			</apply>
		</rowmaker>

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

	<data id="update_from_upstream" auto="false">
		<recreateAfter>import</recreateAfter>
		<make>
			<table id="ignored" onDisk="True" temporary="True"/>
			<script lang="python" type="postCreation">
				inF = urllib.request.urlopen(
					"https://www.minorplanetcenter.net/iau/lists/ObsCodes.html")
				with open(table.tableDef.rd.getAbsPath(
					"data/ObsCodes.dat"), "wb") as outF:
					outF.write(inF.read())
				inF.close()
			</script>
		</make>
	</data>


	<dbCore id="placore" queriedTable="data">
		<condDesc buildFrom="code"/>
		<condDesc buildFrom="long"/>
		<condDesc buildFrom="gdlat"/>
		<condDesc buildFrom="height"/>
		<condDesc buildFrom="name"/>
		<outputTable>
			<outputField original="name"/>
			<outputField original="code"/>
			<outputField original="long"/>
			<outputField original="gclat"/>
			<outputField original="gdlat"/>
			<outputField original="height"/>
			<outputField name="map" type="text"
				tablehead="Map"
				select="'\osmBase'||'&amp;lon='||long||'&amp;lat='||gdlat"
				description="Link to an OpenStreetMap of this place"
				displayHint="type=url">
				<formatter>
					return T.a(href=data)["[OSM]"]
				</formatter>
			</outputField>
		</outputTable>
	</dbCore>

	<service id="query" core="placore">
		<meta name="shortName">obscode_web</meta>
		<publish render="form" sets="local,ivo_managed"/>
	</service>

</resource>
