<resource resdir="brownDwarfs">
	<schema>browndwarfs</schema>

	<macDef name="magCols">
		band, bandU, valR,		errR
		j,		J,		 140-145, 151-155
		h,		H,		 161-166, 172-176
		k,		K,		 182-187, 193-197
	</macDef>

	<meta name="title">DwarfArchives.org – Photometry, spectroscopy, and
	astrometry of  L, T, and Y dwarfs</meta>
	<meta name="creationDate">2008-04-07T10:34:00Z</meta>

	<meta name="subject">brown-dwarfs</meta>
	<meta name="subject">catalogs</meta>

	<meta name="description" format="rst">A catalogue of brown dwarfs produced by
		Gelino et al.	The database reflects the state of
		http://www.dwarfArchives.org on 2015-09-29.</meta>
	<meta name="creator">Gelino, C.; Kirkpatrick, D.;
		Burgasser, A.</meta>
	<meta name="referenceURL">http://www.dwarfArchives.org</meta>
	<meta name="source">http://www.dwarfArchives.org</meta>
	<meta name="copyright">If this table has been useful to you, please
	acknowledge: This research has benefitted from the M, L, and T dwarf
	compendium housed at DwarfArchives.org and maintained by Chris Gelino, Davy
	Kirkpatrick, and Adam Burgasser.</meta>


	<meta name="_news" date="2010-06-18" author="MD">Updated to a new upstream
		version.</meta>
	<meta name="_news" date="2015-09-29" author="MD">Updated to a new upstream
		version.</meta>
	<meta name="_news" date="2016-02-15" author="MD">Complete makeover to
		now include all upstream fields, include proper links, etc..</meta>

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

	<table id="cat" onDisk="True" mixin="//scs#q3cindex">
		<mixin>//scs#pgs-pos-index</mixin>
		<publish sets="dci"/>
		<adql>True</adql>
		<index columns="spectral_opt"/>
		<stc>
			Position ICRS SPHER3 "raj2000" "dej2000" "parallax"
		</stc>

		<column name="designation" tablehead="Name" type="text"
			description="Designation, typically from 2MASS"
			ucd="meta.id;meta.main"/>
		<column name="raj2000" tablehead="RA" unit="deg"
			ucd="pos.eq.ra;meta.main" description="RA J2000.0"/>
		<column name="dej2000" tablehead="Dec" unit="deg"
			ucd="pos.eq.dec;meta.main" description="Dec J2000.0"/>

		<column name="jmag" tablehead="Mag(J)"
			unit="mag" ucd="phot.mag;em.IR.J"
			description="Magnitude in the J band">
			<values min="11.51" max="23.57"/>
		</column>
		<column name="errjmag" tablehead="Err. Mag(J)"
			unit="mag" ucd="stat.error;phot.mag;em.IR.J"
			description="Error in magnitude in the J band"/>
		<column name="hmag" tablehead="Mag(H)"
			unit="mag" ucd="phot.mag;em.IR.H"
			description="Magnitude in the H band">
		</column>
		<column name="errhmag" tablehead="Err. Mag(H)"
			unit="mag" ucd="stat.error;phot.mag;em.IR.H"
			description="Error in magnitude in the H band"/>
		<column name="kmag" tablehead="Mag(K)"
			unit="mag" ucd="phot.mag;em.IR.K"
			description="Magnitude in the K band">
		</column>
		<column name="errkmag" tablehead="Err. Mag(K)"
			unit="mag" ucd="stat.error;phot.mag;em.IR.K"
			description="Error in magnitude in the K band"/>

		<column name="parallax"
			unit="deg" ucd="pos.parallax"
			tablehead="Par."
			description="Parallax as reported by parallax_paper."
			verbLevel="15" displayHint="displayUnit=mas"/>
		<column name="parallax_error"
			unit="deg" ucd="stat.error;pos.parallax"
			tablehead="Par. Error"
			description="Error in parallax as reported by parallax_paper."
			verbLevel="15" displayHint="displayUnit=mas"/>
		<column name="parallax_paper" type="text"
			ucd="meta.bib;pos.parallax"
			tablehead="Par. Src."
			description="Reference to the paper the parallax was taken from"
			verbLevel="15" displayHint="type=bibcode"/>

		<column name="pm_tot" unit="deg/yr" tablehead="PM"
			description="Total proper motion" ucd="pos.pm"
			displayHint="displayUnit=mas/yr"
			verbLevel="15">
			<values min="2.77778e-06" max="0.00130665"/>
		</column>
		<column name="pm_tot_err" unit="deg/yr"
			tablehead="Err(PM)" ucd="stat.error;pos.pm"
			description="Error in total proper motion."
			verbLevel="25" displayHint="displayUnit=mas/yr"/>
		<column name="pm_pa" unit="deg"
			tablehead="PA of PM" ucd="pos.posAng;pos.pm"
			description="Position angle of proper motion"
			verbLevel="15"/>
		<column name="pm_pa_error"
			unit="deg" ucd="stat.error;pos.posAng;pos.pm"
			tablehead="Err. PA"
			description="Error in the position angle of the proper motion."
			verbLevel="25"/>
		<column name="pm_paper" type="text"
			ucd="meta.bib;pos.pm"
			tablehead="PM Src."
			description="Paper the proper motion was taken from."
			verbLevel="15" displayHint="type=bibcode"/>

		<column name="spectral_opt" type="text" tablehead="Spectral (Optical)"
			description="Spectral type inferred from observation in visible light"
			ucd="src.spType;em.opt"
			verbLevel="15"/>
		<column name="st_opt_paper" type="text"
			ucd="meta.bib;src.spType"
			tablehead="Sp. Opt. Src."
			description="Reference to the paper the optical spectral type was taken
				from"
			verbLevel="15" displayHint="type=bibcode"/>

		<column name="spectral_ir" type="text" tablehead="Spectral (IR)"
			ucd="src.spType;em.IR"
			description="Spectral type inferred from observation in infrared"
			verbLevel="15"/>
		<column name="st_ir_paper" type="text"
			ucd="meta.bib;src.spType"
			tablehead="Sp. IR Src."
			description="Reference to the paper the infrared spectral type was taken
				from"
			verbLevel="15" displayHint="type=bibcode"/>

		<column name="discovered_as" type="text"
			ucd="meta.id"
			tablehead="Disc. Name"
			description="Name the object was discovered as."
			verbLevel="15"/>
		<column name="discovered_by" type="text"
			ucd="meta.bib"
			tablehead="Disc. Ref."
			description="Reference to the paper in which the object was discovered."
			verbLevel="15"
			displayHint="type=bibcode"/>
	</table>

	<coverage>
		<updater sourceTable="cat" mocOrder="4"/>
		<spatial>3/11,67,73,81,88,92,95,97,100,103,112,115,129-131,133,136-137,144,147,150,167,175,341,405,409-410,414,422,425,432,436-437,495,569,572 4/0,4,12-14,20,23,27-29,31,34,36,39,42,48,53-54,56,63,110,127,130,140-141,143,147,152,154,156,158,162,165,174,195,212,215,246-247,253,256-257,260-261,263-266,272,275,278,280,282-283,286-287,289-291,296,298-299,301,304,307-309,311-314,316-317,320-321,331-332,335-338,342,346-348,351,357,365,367,377,379,385,387,393,395,405,407-409,422-424,437,439,443,447,455,457,459,464-465,468-470,472-474,480,484,486,488,499,506-507,513,515,529-531,537,539,542-543,553-554,556-557,562-564,566-567,570-571,573,580,582,585-586,592,594-595,597-599,607,611,613,619-620,622-625,628-629,631-633,637-640,642-643,647,649,652,654-655,657,659,664-666,673,675-676,683,685,687,692-693,696-698,705,709,711-712,714-716,719,723-726,730,732,738-742,744,746,752,773,776,779,782-783,786-787,797,809,820,833,839-840,846,854,865,867,880,928-929,932,935,940,942-943,946,978,985,995,998,1001,1003,1005,1010,1014,1018,1021,1023,1027,1034-1035,1038-1039,1042,1048-1050,1053-1054,1056,1061-1062,1067-1069,1072,1077,1081-1083,1089,1093,1095,1099,1101,1103,1105,1108,1110-1111,1113-1114,1120,1124,1126-1127,1129-1131,1133-1137,1142-1143,1148,1150,1162,1165,1167,1169,1171,1173-1175,1177-1179,1187,1189-1191,1193-1196,1201-1202,1209-1210,1213,1224-1225,1227,1231-1232,1234-1235,1238,1241,1244,1246,1248-1250,1258,1265,1267,1269-1270,1273,1275,1277,1281,1286,1288,1293,1297,1306,1312,1318-1319,1322-1323,1325,1331-1332,1335-1336,1341,1358,1363,1375,1385-1386,1393,1399,1407,1412,1417,1422,1425,1428,1433,1438-1439,1441,1444,1446,1449-1452,1454,1459,1466,1468,1470-1471,1506,1535-1537,1539,1543,1557,1563,1565,1567-1568,1570-1571,1576,1579-1580,1582,1589-1590,1594,1596-1597,1599,1613,1615,1625-1628,1630-1631,1635,1647,1649-1651,1653-1654,1660-1661,1672,1674,1678,1685-1686,1692-1693,1695,1705,1710-1713,1716,1718-1721,1724,1726-1727,1733-1734,1737,1739,1741,1752-1753,1757,1762,1767,1769,1771,1773-1774,1776,1778-1779,1781-1783,1787-1788,1813,1831,1874,1878,1921-1922,1929-1930,1932,1934,1938-1939,1941,1946,1954-1958,1963-1964,1966-1968,1970-1971,1974-1975,1978,1984,1991,2017,2021,2023,2026,2028,2031,2034-2036,2040,2042,2044,2057,2060,2064,2072,2076,2078,2081,2085-2087,2089,2092,2097,2100-2101,2104,2109-2110,2130-2131,2137-2138,2144,2150-2152,2164-2166,2173,2175-2177,2179-2180,2188,2191,2200,2207,2210-2211,2213,2218-2219,2221,2223,2226,2241,2243-2244,2246,2250,2254,2263-2266,2285,2287,2296,2298-2299,2301-2302,2307,2315,2336-2337,2343-2344,2347,2377,2385-2386,2388,2395-2397,2404,2417,2423-2425,2430,2432,2440,2444,2449-2450,2465-2467,2472,2480,2487,2489,2501,2511,2514,2520,2523-2524,2530,2535,2541,2546,2555-2556,2559,2562,2570-2571,2579,2597,2624,2641,2664,2669-2671,2680,2685-2686,2691,2713,2717,2719,2722,2741-2742,2747-2748,2750,2757-2758,2767,2771-2772,2776,2780,2791,2800,2808-2809,2815,2819-2820,2823,2827,2829-2830,2833,2841,2847,2859,2879-2880,2883,2887-2888,2895,2898-2899,2902,2912,2916,2926-2927,2930,2932,2935,2938-2939,2949,2955,2959,2977,2994,2996,3007,3010,3018,3025,3028,3037,3045,3047,3051,3055-3056,3059,3061,3063,3067,3071</spatial>
	</coverage>

	<procDef id="get_bibcode" type="apply">
		<setup>
			<par key="src_key"/>
			<par key="dest_key_override">None</par>
		</setup>
		<code>
			dest_key = src_key if dest_key_override is None else dest_key_override
			mat = re.search("href='([^']*)'", vars[src_key])
			if not mat:
				result[dest_key] = None
			else:
				src = urllib.parse.unquote(mat.group(1))
				if "bibcode=" in src:
					result[dest_key] = src.split("bibcode=")[-1]
				else:
					result[dest_key] = src.split("/")[-1]
		</code>
	</procDef>

	<data id="import">
		<sources pattern="data/src.html"/>
		<freeREGrammar ignoreJunk="True">
			<rowProduction><![CDATA[(?s)<tr[^>]*>\s*<td>.*?</tr>]]></rowProduction>
			<parseRE><![CDATA[(?xsm)
				<tr[^>]*>\s*
				<td>(?P<discovered_as>.*?)</td>\s*
				<td>(?P<discovered_by>.*?)</td>\s*
				<td>(?P<designation>.*?)</td>\s*
				<td>(?P<ra>.*?)</td>\s*
				<td>(?P<decl>.*?)</td>\s*
				<td>(?P<jmag>.*?)</td>\s*
				<td>(?P<jmag_error>.*?)</td>\s*
				<td>(?P<hmag>.*?)</td>\s*
				<td>(?P<hmag_error>.*?)</td>\s*
				<td>(?P<kmag>.*?)</td>\s*
				<td>(?P<kmag_error>.*?)</td>\s*
				<td>(?P<parallax>.*?)</td>\s*
				<td>(?P<parallax_error>.*?)</td>\s*
				<td>(?P<parallax_paper>.*?)</td>\s*
				<td>(?P<prop_motion>.*?)</td>\s*
				<td>(?P<prop_motion_error>.*?)</td>\s*
				<td>(?P<pm_pa>.*?)</td>\s*
				<td>(?P<pm_pa_error>.*?)</td>\s*
				<td>(?P<pm_paper>.*?)</td>\s*
				<td>(?P<spectral_opt>.*?)</td>\s*
				<td>(?P<st_opt_paper>.*?)</td>\s*
				<td>(?P<spectral_ir>.*?)</td>\s*
				<td>(?P<st_ir_paper>.*?)</td>\s*
				<td>(?P<note>.*?)</td>\s*</tr>
			]]></parseRE>
			<ignoreOn>
				<keyIs key="pm_pa" value="degree"/>
			</ignoreOn>
		</freeREGrammar>
		<make table="cat">
			<rowmaker>
				<map dest="spectral_opt"
					>parseWithNull(@spectral_opt, str, "&amp;nbsp;")</map>
				<map dest="spectral_ir"
					>parseWithNull(@spectral_ir, str, "&amp;nbsp;")</map>

				<map dest="raj2000">parseAngle(@ra, "fracHour")</map>
				<map dest="dej2000">float(@decl)</map>

				<map dest="designation"
					>re.sub("&lt;[^>]*>", "", @designation).strip()</map>
				<map dest="discovered_as"
					>re.sub("&lt;[^>]*>", "", @discovered_as).strip()</map>

				<map dest="parallax" nullExcs="ValueError"
					>float(@parallax)*DEG_MAS</map>
				<map dest="parallax_error" nullExcs="ValueError"
					>float(@parallax_error)*DEG_MAS</map>
				<map dest="pm_pa" nullExcs="ValueError">float(@pm_pa)</map>
				<map dest="pm_pa_error" nullExcs="ValueError"
					>float(@pm_pa_error)</map>

				<apply procDef="get_bibcode">
					<bind key="src_key">"parallax_paper"</bind>
				</apply>
				<apply procDef="get_bibcode">
					<bind key="src_key">"pm_paper"</bind>
				</apply>
				<apply procDef="get_bibcode">
					<bind key="src_key">"st_opt_paper"</bind>
				</apply>
				<apply procDef="get_bibcode">
					<bind key="src_key">"st_ir_paper"</bind>
				</apply>
				<apply procDef="get_bibcode">
					<bind key="src_key">"discovered_by"</bind>
				</apply>

				<map dest="pm_tot" nullExcs="ValueError"
					>float(@prop_motion)*DEG_ARCSEC</map>
				<map dest="pm_tot_err" nullExcs="ValueError"
					>float(@prop_motion_error)*DEG_ARCSEC</map>

				<LOOP csvItems="\magCols">
					<events>
						<map dest="\band\+mag">parseWithNull(@\band\+mag, float, 'null')</map>
						<map dest="err\band\+mag">
							parseWithNull(@\band\+mag_error, float, 'null')</map>
					</events>
				</LOOP>
			</rowmaker>
		</make>
	</data>

	<service id="cone" allowed="form,scs.xml,external">
		<meta name="shortName">Gelino+ cone</meta>
		<publish render="scs.xml" sets="ivo_managed"/>
		<publish render="external" sets="local,ivo_managed">
			<meta name="accessURL">http://www.dwarfArchives.org</meta>
		</publish>

		<meta>
			testQuery.ra: 6.26525
			testQuery.dec: 47.9887
			testQuery.sr: 0.01
		</meta>

		<scsCore queriedTable="cat">
			<FEED source="//scs#coreDescs"/>
			<condDesc>
				<inputKey original="spectral_opt" showItems="10">
					<values
						fromdb="spectral_opt from \schema.cat order by spectral_opt"/>
				</inputKey>
			</condDesc>
			<condDesc buildFrom="jmag"/>
			<condDesc buildFrom="pm_tot"/>
		</scsCore>
	</service>

	<regSuite id="defaultSortTest">
		<regTest title="default sort key is honored">
			<url parSet="form" hscs_pos="137.8 74.01" hscs_sr="700">cone/form</url>
			<code>
				self.assertXpath("//h:thead/h:tr/h:th[1]", {None: "Dist."})
				self.assertXpath("//h:tr[@class='data'][1]/h:td[1]",
					{None: "32.34"})
				self.assertXpath("//h:tr[@class='data even'][1]/h:td[1]",
					{None: "24537.65"})
				self.assertXpath("//h:select[@id='genForm-_DBOPTIONS_ORDER']/"
					"h:option[@selected='selected']", {"value": "_r"})
			</code>
		</regTest>

		<regTest title="default sort key can be overridden" id="cur">
			<url parSet="form" hscs_pos="137.8 74.01" hscs_sr="700"
				_DBOPTIONS_ORDER="jmag" _DBOPTIONS_DIR="DESC">cone/form</url>
			<code>
				self.assertXpath("//h:tr[@class='data'][1]/h:td[5]",
					{None: "16.823"})
				self.assertXpath(r"//h:tr[@class='data'][2]/h:td[5]",
					{None: EqualingRE(r"16.554\\d*")})
			</code>
		</regTest>
	</regSuite>
</resource>
