<resource schema="usnob">
	<meta name="creationDate">2009-01-02T09:54:00Z</meta>
	<meta name="schema-rank">1000</meta>

	<meta name="subject">surveys</meta>
	<meta name="subject">observatories</meta>
	<meta name="subject">wide-field-telescopes</meta>

	<meta name="title">Plate data for the USNO-B 1.0 Catalogue.</meta>
	<meta name="source">2003AJ....125..984M</meta>
	<meta name="description">
		This table contains the metadata for the plates that went into USNO-B 1.0
		as best as we can reconstruct it (i.e., largely those that also make
		up the Digital Sky Survey DSS).  Most of the source files were obtained
		from http://www.nofs.navy.mil/data/fchpix/, some additional contributions
		came from Dave Monet.
	</meta>

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

	<table id="plates" onDisk="True" adql="True" mixin="//scs#q3cindex">
		<mixin>//scs#pgs-pos-index</mixin>
		<meta name="description">Plate data for the source plates of
			USNO-B</meta>
		<meta name="_longdoc" format="rst">
This table contains the
metadata for the plates that went into USNO-B 1.0 as best as
we can reconstruct it.  Most of the source files were obtained
from http://www.nofs.navy.mil/data/fchpix/, some additional
contributions came from Dave Monet.

Note that, in Dave's words in 2003AJ....125..984M, “some confusion
persists” in plate numbering and assignment.  We found this to be
true.

Here is the assignment we have figured out so far:

============================  ====  ==
Survey name                   USNO  We
============================  ====  ==
POSS-I O                      0     A
POSS-I E                      1     B
POSS-II J                     2     C
POSS-II F                     3     D
SERC-J                        4     E
SERC-EJ                       4     E
ESO-R                         5     F
SERC-ER                       5     F
AAO-R                         6     G
POSS-II-N                     7     H
SERC-I, non-POSS              8     I
SERC-I, POSS-II-N             9     ?    -- does not exist in USNO data
POSS-II, marked with UJ       ?     X
============================  ====  ==

</meta>
		<publish/>

		<index columns="survey"/>

		<column name="field" type="smallint" required="True"
			description="Field number in survey" ucd="meta.id;obs.field"
			tablehead="Field#"/>
		<column name="plate" type="text"
			description="Plate number in USNO-B" tablehead="Plate#"
			ucd="meta.id;obs.field;meta.main"/>
		<column name="survey" type="char" required="True"
			description="Survey identifier, see long docs"
			tablehead="Survey ID" ucd="meta.id">
			<values fromdb="survey from \schema.plates order by survey"/>
		</column>
		<column name="epoch" type="timestamp"
			description="Plate epoch" unit="yr" ucd="time.epoch"
			tablehead="Epoch"/>
		<column name="emulsion" type="text" description="Emulsion"
			ucd="instr.plate.emulsion"
			tablehead="Emulsion"/>
		<column name="filter" type="text" description="Filter"
			tablehead="Filter" ucd="meta.id;instr.filter">
			<values nullLiteral="None"/>
		</column>
		<column name="exposure" description="Length of exposure" unit="s"
			tablehead="Exposure"
			ucd="time.duration;obs.exposure"/>
		<column name="usnocode" type="text"
			description="2-char plate code given in the plate catalogue"
			tablehead="USNO code" ucd="meta.id;obs.field"/>
		<column name="alpha1950" unit="deg"
			description="Field center alpha for B1950" ucd="pos.eq.ra"
			tablehead="Ctr. RA B1950"/>
		<column name="delta1950" unit="deg"
			description="Field center decl for B1950" ucd="pos.eq.dec"
			tablehead="Ctr. Dec B1950"/>
		<column name="alpha2000" unit="deg"
			description="Field center alpha for J2000" ucd="pos.eq.ra;meta.main"
			tablehead="Ctr. RA J2000"/>
		<column name="delta2000" unit="deg"
			description="Field center decl for J2000" ucd="pos.eq.dec;meta.main"
			tablehead="Ctr. Dec J2000"/>
		<column name="src" type="text"
			tablehead="Source" description="Source file for this record"
			ucd="meta.ref;meta.file"/>
		<LOOP>
			<csvItems>
				name, head, ucd
				alphaMin1950, "min. RA B1950", "pos.eq.ra;stat.min"
				alphaMax1950, "max. RA B1950", "pos.eq.ra;stat.max"
				deltaMin1950, "min. Dec B1950", "pos.eq.dec;stat.min"
				deltaMax1950, "max. Dec B1950", "pos.eq.dec;stat.max"
			</csvItems>
			<events>
				<column name="\name" unit="deg" tablehead="\head" ucd="\ucd"/>
			</events>
		</LOOP>
	</table>

	<coverage>
		<spectral>2.257e-19 5.369e-19</spectral>
		<temporal>33239.1 36670</temporal>
		<temporal>38262 38945</temporal>
		<temporal>42130 52590.4</temporal>
		<spatial>0/0-11</spatial>
	</coverage>
	
	<rowmaker id="make_plates" idmaps="*">
		<var name="src">\srcstem</var>
		<map dest="epoch">parseDate(@date, "!!julianEp"
			)+parseTime(@time, "!!decimalHours")</map>
		<map dest="alpha1950">float(@alpha1950)*180/math.pi</map>
		<map dest="delta1950">float(@delta1950)*180/math.pi</map>
		<map dest="alpha2000">float(@alpha2000)*180/math.pi</map>
		<map dest="delta2000">float(@delta2000)*180/math.pi</map>
		<map dest="alphaMin1950" nullExcs="ValueError"
			>float(@alphaMin1950)*180/math.pi</map>
		<map dest="alphaMax1950" nullExcs="ValueError"
			>float(@alphaMax1950)*180/math.pi</map>
		<map dest="deltaMin1950" nullExcs="ValueError"
			>float(@deltaMin1950)*180/math.pi</map>
		<map dest="deltaMax1950" nullExcs="ValueError"
			>float(@deltaMax1950)*180/math.pi</map>
		<map dest="exposure">float(@exposure)*60</map>
		<idmaps>emulsion,field,plate,filter,usnocode,src,survey</idmaps>

<!-- the following proc app is supposed to compute the survey id used in
usno b.  This is totally messy, but that's the way the data is. -->
		
		<apply id="computeSurveyId">
			<code><![CDATA[
				src, emulsion = vars["src"], vars["emulsion"]
				plate, usnocode = vars["plate"], vars["usnocode"]
				try:
					if src=="POSSI":
						if emulsion=="103aE":
							val = "B" # POSS-I-E
						elif emulsion=="103aO":
							val = "A" # POSS-I-0
						else:
							fail
					elif src=="POSSII":
						if plate[:2]=="UJ":
							val = "X"
						elif emulsion=="IIIaJ":
							val = "C"  # POSS-II-J
						elif emulsion=="IIIaF":
							val = "D"  # POSS-II-F
						elif emulsion=="IVN":
							val = "H"  # POSS-II-N
						else:
							fail
					elif src=="aaor":
						val = "G"    # AAO-R
					elif src=="SERC-I":
						if usnocode=="xn":
							val = "H"    # SERC-I, POSS
						else:
							val = "I"    # SERC-I, non-POSS
					elif src=="South":
						# OMG.  I base this on the record count.  Sigh.
						val = {
							0: "E",  # SERC-J or SERC-EJ
							1: "F",  # ESO-R or SERC-ER
						}[vars["parser_"].recNo%2]
					else:
						fail
				except NameError:
					raise base.Error("No survey char discernible: %s"%vars)
				vars["survey"] = val
			]]></code>
		</apply>
	</rowmaker>

	<data id="import">
		<sources patterns="platedata/*.table"/>
		<columnGrammar topIgnoredLines="6">
			<col key="field">1-4</col>
			<col key="plate">7-13</col>
			<col key="date">15-23</col>
			<col key="time">25-29</col>
			<col key="alpha1950">31-38</col>
			<col key="delta1950">40-48</col>
			<col key="alpha2000">50-57</col>
			<col key="delta2000">59-67</col>
			<col key="emulsion">69-73</col>
			<col key="filter">75-80</col>
			<col key="exposure">83-85</col>
			<col key="alphaMin1950">94-101</col>
			<col key="alphaMax1950">103-110</col>
			<col key="deltaMin1950">112-120</col>
			<col key="deltaMax1950">122-130</col>
			<col key="usnocode">132-133</col>
		</columnGrammar>
		<make table="plates" rowmaker="make_plates"/>
	</data>

	<dbCore queriedTable="plates" id="pqcore">
		<condDesc original="//scs#humanInput"/>
		<condDesc original="//scs#protoInput"/>
		<condDesc buildFrom="survey"/>
		<condDesc buildFrom="field"/>
		<condDesc buildFrom="emulsion"/>
	</dbCore>

	<service id="pq" core="pqcore">
		<meta name="shortName">usnob_plates</meta>
		<meta name="title">USNO-B1 plates</meta>
		<publish render="form" sets="ivo_managed,local"/>
		<outputTable namePath="plates">
			<outputField original="epoch" unit="yr" displayHint="sf=2"/>
			<LOOP listItems="field survey alpha2000 delta2000 emulsion filter src
					alphaMin1950 alphaMax1950 deltaMin1950 deltaMax1950">
				<events>
					<outputField original="\item"/>
				</events>
			</LOOP>
		</outputTable>
	</service>

	<regSuite title="USNO plates service">
		<regTest title="USNO plates service works">
			<url parSet="form" field="340" survey="B"
				>/usnob/res/plates/pq/form</url>
			<code><![CDATA[
				self.assertHasStrings(
					"<title>USNO-B1",
					"<td>1951.66516",
					"<td>306.8376",
					"td>RP2444",
					"<td>310.766")
			]]></code>
		</regTest>
	</regSuite>
</resource>
