<?xml version="1.0"?>

<resource schema="mcextinct">
	<meta name="title">Reddening and Extinction maps of the Magellanic Clouds</meta>
	<meta name="creationDate">2009-06-02T08:42:00Z</meta>
	<meta name="schema-rank">200</meta>
	<meta name="description" format="plain">
A catalogue of E(V-I) extinction values is presented for 3174 (LMC) and 693
(SMC) fields within the Magellanic Clouds. The extinction values were
computed by determining the (V-I) colour difference of the red clump from
Optical Gravitational Microlensing Experiment (OGLE III) observations in the
V and I bands and theoretical values for unreddend red clump colours.
	</meta>

	<meta name="doi">10.21938/AvlnaD4AvIeK9nIscpF.YA</meta>

	<meta name="_longdoc" format="rst"><![CDATA[
The Optical Gravitational Microlensing Experiment (OGLE III) has monitored
both Magellanic Clouds in the V and I band. Using the public stellar
photometry database of OGLE III in order to derive spatially resolved
reddening maps, we subdivide the OGLE III observations of the Large
Magellanic Cloud (LMC) in 3174 subfields. The size of the fields varies from
4.5 x 4.5 square arcmin to 36 x 36 square arcmin in order to ensure that each
field contains at least 300 stars and no more than 4800 stars. I.e., in dense
regions our reddening resolution is higher.

In each of these subfields the mean (V-I) colour of the red clump is
determined. A theoretical colour of (V-I):sub:0 = 0.92 mag is adopted for the LMC
and subtracted from the measured value. The difference is defined as
reddening E(V-I). To provide you directly useable data we calculated the
reddening for different filters by adopting Schlegels list of conversion
factors (Table 6 in Schlegel et al. 1998, AJ, 500, 525). To use this table
the extinction has to be recalculated from E(B-V) to E(V-I). For this purpose
we adopted E(V-I) = 1.38 × E(B-V)
(Tammann et al. 2003, A&A, 404, 423).

For the Small Magellanic Cloud (SMC) the same procedure is used. The OGLE III
data are subdivided into 693 contiguous subfields. The reddening of each
subfield is determined adopting a theoretical colour of
|(V-I)_0| = 0.89 mag.

The following table (containing values taken from
`1998ApJ...500..525S <http://adsabs.harvard.edu/abs/1998ApJ...500..525S>`_)
shows the laws adopted to compute extinction values in
the various bands:

==========    ====    =======   ======   ========   ========
Filter        name    |λ_eff|   A/A(V)   A/E(B-V)   A/E(V-I)
==========    ====    =======   ======   ========   ========
Landolt       U       3372      1.66     5.43       3.94
Landolt       B       4404      1.32     4.32       3.13
Landolt       V       5428      1.02     3.32       2.4
Landolt       R       6509      0.82     2.67       1.94
Landolt       I       8090      0.59     1.94       1.41
Gunn          g       5244      1.07     3.48       2.52
Gunn          r       6707      0.79     2.59       1.88
Gunn          i       7985      0.61     1.99       1.44
Gunn          z       9055      0.47     1.54       1.12
Stromgren     u       3502      1.6      5.23       3.79
Stromgren     b       4676      1.24     4.05       2.93
Stromgren     v       4127      1.39     4.55       3.3
Stromgren     beta    4861      1.18     3.86       2.8
Stromgren     y       5479      1        3.28       2.37
Sloan         u'      3546      1.58     5.16       3.74
Sloan         g'      4925      1.16     3.79       2.75
Sloan         r'      6335      0.84     2.75       1.99
Sloan         i'      7799      0.64     2.09       1.51
Sloan         z'      9294      0.45     1.48       1.07
==========    ====    =======   ======   ========   ========


Crossmatching with your tables
------------------------------

If you want to add extinctions to your own tables, use TAP.  Our TAP
server has the ivo-id ivo://org.gavo.dc/__system__/tap/run.  You will need
a TAP client to do this.  Recent versions of
`TOPCAT <http://www.star.bris.ac.uk/~mbt/topcat/>`_, for example, allow you
use TAP.  To add a column with the reddening,  load the table into TOPCAT
and note its id (that's the number in front of the colon in the Table List in
TOPCAT's main window; if you've just started TOPCAT, that's 1).

Then, select TAP from the TOPCAT's VO menu, at the bottom ("TAP URL") enter
``http://dc.g-vo.org/tap`` and click "Enter Query".

In the resulting dialog, enter::

	SELECT ev_i, mine.* FROM
		mcextinct.exts AS exts
		JOIN tap_upload.t1 AS mine
		ON (1=CONTAINS(POINT('ICRS', mine.raj2000, mine.dej2000),exts.bbox))

If your table has id 15, say, change ``tap_upload.t1`` to
``tap_upload.t15``.  You will also need to fix the column names for RA
and Dec (written as raj2000 and dej2000 here).

To compute extinctions in specific bands, use the factors given in the A/E(V-I)
column in the table above above.  To, e.g., add the extinctions in Sloan u' and
Sloan z', say::

	SELECT ev_i*3.74 as A_sloan_u, ev_i*1.07 as A_sloan_z, mine.* FROM
		mcextinct.exts AS exts
		JOIN tap_upload.t1 AS mine
		ON (1=CONTAINS(POINT('ICRS', mine.raj2000, mine.dej2000),exts.bbox))

For batch processing, similar operations can be done with
`STILTS <http://www.star.bristol.ac.uk/~mbt/stilts/>`_ or GAVO's
`tapsh <http://soft.g-vo.org/tapsh>`_.  For the latter,
you could use a shell script like the following to add an ev_i column
to the file named in the first command line argument argument
(note the backup); again, you'll need to fix the column names for RA and Dec::

	#!/bin/sh
	cp $1 $1.bak
	tapsh <<EOF
	server ivo://org.gavo.dc/__system__/tap/run
	SELECT ev_i, mine.* FROM \
		mcextinct.exts AS exts\
		JOIN tap_upload.mytable AS mine \
		ON (1=CONTAINS(POINT('ICRS', mine.raj2000, mine.dej2000),exts.bbox))
	upload "$1" as mytable
	run
	save "$1"
	EOF

.. |λ_eff| replace:: λ\ :sub:`eff`
.. |(V-I)_0| replace:: (V-I)\ :sub:`0`
	]]></meta>


	<meta name="copyright" format="rst"><![CDATA[
	If you use this data, please cite
	Haschke, R., Grebel, E., Duffau, S., 2011: "New Optical Reddening
	Maps of the Large and Small Magellanic Clouds", AJ 141, 158,
	`2011AJ....141..158H <http://adsabs.harvard.edu/abs/2011AJ....141..158H>`_

	The photometric data of the red clump is provided by the OGLE collaboration.

	Part of this research was supported by SFB 881 "The Milky Way System".
	]]></meta>
	<meta>
		creator.name:Haschke, R.
		creator:
		creator.name: Grebel, E.K.
		creator.name.altIdentifier: orcid:0000-0002-1891-3794
		creator:
		creator.name: Duffau, S.
	</meta>

	<meta name="subject">large-magellanic-cloud</meta>
	<meta name="subject">interstellar-extinction</meta>
	<meta name="subject">interstellar-dust</meta>
	
	<meta name="coverage">
		<meta name="waveband">Optical</meta>
		<meta name="waveband">Infrared</meta>
		<meta name="regionOfRegard">0.02</meta>
	</meta>

	<meta name="source">2011AJ....141..158H</meta>

	<macDef name="filterdefs">
		label, name, factor, verb
		Landolt U, a_U, 3.94, 10
		Landolt B, a_B, 3.13, 10
		Landolt V, a_V, 2.4, 10
		Landolt R, a_R, 1.94, 10
		Landolt I, a_I, 1.41, 10
		Gunn g, a_gg, 2.52, 21
		Gunn r, a_gr, 1.88, 21
		Gunn i, a_gi, 1.44, 21
		Gunn z, a_gz, 1.12, 21
		Stromgren u, a_su, 3.79, 25
		Stromgren b, a_sb, 2.93, 25
		Stromgren v, a_sv, 3.3, 25
		Stromgren beta, a_sbeta, 2.8, 25
		Stromgren y, a_sy, 2.37, 25
		Sloan u', a_slu, 3.74, 15
		Sloan g', a_slg, 2.75, 15
		Sloan r', a_slr, 1.99, 15
		Sloan i', a_sli, 1.51, 15
		Sloan z', a_slz, 1.07, 15
	</macDef>

	<table id="exts" onDisk="True" adql="True" mixin="//scs#q3cindex">
		<mixin>//scs#pgs-pos-index</mixin>
		<meta name="description">
			Extinction values within certain areas in the Magellanic clouds.
		</meta>
		<stc>PositionInterval ICRS [bbox]</stc>
		<stc>Position ICRS "centerAlpha" "centerDelta"</stc>
		<column name="bbox" type="sbox" tablehead="Bounding Box"
			description="Bounding box for the extinction data" verbLevel="10"
			ucd="pos.outline;obs.field"/>
		<column name="centerAlpha" unit="deg" tablehead="RA"
			description="Area center RA ICRS" ucd="pos.eq.ra;meta.main"
			verbLevel="1"/>
		<column name="centerDelta" unit="deg" tablehead="Dec"
			description="Area center Declination ICRS" ucd="pos.eq.dec;meta.main"
			verbLevel="1"/>
		<column name="ev_i" unit="mag" tablehead="E(V-I)"
			ucd="phot.color.excess;em.opt.V;em.opt.I"
			description="Reddening (color difference between observation
				and theory, V-I)"
			verbLevel="1"/>
		<column name="sig_ev_i" unit="mag" tablehead="σ(E(V-I))"
			ucd="stat.stdev;phot.color.excess"
			description="Differential reddening calculated as FWHM of
				the red clump star distribution"/>
	</table>

	<coverage>
		<updater sourceTable="exts"/>
		<spatial>4/2068 5/8263,8268-8269,8271,8280,8323,8326,8329,9376,9378 6/33045-33047,33049,33051,33069,33080-33081,33083,33104-33106,33112,33124-33126,33128-33130,33287,33289,33291,33297-33299,33313,33315,33323-33326,33328-33330,37416,37418,37536</spatial>
		<spectral>1.986e-19 6.02e-19</spectral>
	</coverage>

	<data id="import">
		<sources pattern="data/*.txt"/>
		<reGrammar topIgnoredLines="1">
			<names>raMin, raMax, decMin, decMax, ev_i, sig_ev_i</names>
		</reGrammar>

		<rowmaker id="build_exts" idmaps="*">
			<var name="raMin">float(@raMin)</var>
			<var name="raMax">float(@raMax)</var>
			<var name="decMin">float(@decMin)</var>
			<var name="decMax">float(@decMax)</var>

			<map dest="centerAlpha">(@raMin+@raMax)/2.</map>
			<map dest="centerDelta">(@decMin+@decMax)/2.</map>
			<map dest="bbox">pgsphere.SBox(pgsphere.SPoint(@raMin*DEG, @decMin*DEG),
						pgsphere.SPoint(@raMax*DEG, @decMax*DEG))</map>
		</rowmaker>
		
		<make table="exts" rowmaker="build_exts"/>
	</data>

	<table id="uploadedPos" onDisk="True" temporary="True">
		<!-- user-uploaded data, only temporary -->
		<column name="ra" type="double precision" unit="deg" tablehead="RA"
			ucd="pos.eq.ra;meta.main" description="Uploaded RA"/>
		<column name="dec" type="double precision" unit="deg" tablehead="Dec"
			ucd="pos.eq.dec;meta.main" description="Uploaded Dec"/>
	</table>

	<data id="upload" auto="False">
		<reGrammar names="ra,dec"/>
		<rowmaker id="build_upload" idmaps="*"/>
		<make table="uploadedPos" rowmaker="build_upload"/>
	</data>
	
	<customCore id="crosscore" module="bin/crosscore">
		<property name="joinQuery">SELECT u.ra, u.dec, e.ev_i,
			FROM uploadedPos AS u
			JOIN mcextinct.exts AS e ON (spoint(u.ra, u.dec) @ e.bbox)</property>
		<outputTable namePath="exts">
			<column original="uploadedPos.ra"/>
			<column original="uploadedPos.dec"/>
			<column original="ev_i"/>
		</outputTable>
		<inputTable>
			<inputKey name="inPos" tablehead="Input Positions"
				description="Decimal ICRS RA and Dec, one pair per line"
				widgetFactory="widgetFactory(TextArea, rows=15, cols=30)"/>
		</inputTable>
	</customCore>

	<service id="cross" core="crosscore">
		<meta name="title">MC Exinctions by Positions</meta>
		<meta name="_intro" format="rst">
			**Do not use this service.**  We will soon completely shut it down,
			since it is no longer necessary and actually far more cumbersome
			than the TAP-based procedure for doing what this service did.
			See the \RSTservicelink{mcextinct/q/info}{Service Info} for how
			to add extinction columns to your tables.
		
			Enter positions within the LMC to
			obtain the
			extinction values.  Note that no values will be returned for
			positions we do not have extinction values for.

			If you have VOTable data, the
			\RSTservicelink{/cross/q/match/form}{crossmatch service} with a
			sufficiently large search radius might work better for you.
		</meta>
	</service>

	<dbCore id="conequery" queriedTable="exts">
		<condDesc original="//scs#humanInput">
			<phraseMaker original="//scs#humanSCSPhrase">
				<setup original="//scs#scsSetup" id="proxQuery">
					<code><![CDATA[
						def genQuery(_, inPars, outPars):
							return ("scircle '<(%%(%s)sd, %%(%s)sd), %%(%s)sd>'"
								" && bbox")%(
									base.getSQLKey("RA", inPars["RA"], outPars),
									base.getSQLKey("DEC", inPars["DEC"], outPars),
									base.getSQLKey("SR", inPars["SR"], outPars))
					]]></code>
				</setup>
			</phraseMaker>
		</condDesc>
	 	<condDesc original="//scs#protoInput">
			<phraseMaker original="//scs#scsPhrase">
				<setup original="proxQuery"/>
			</phraseMaker>
		</condDesc>
		<condDesc buildFrom="ev_i"/>
		<outputTable id="fullOut">
			<outputField name="row_id"
				ucd="meta.id;meta.main"
				tablehead="ID"
				description="Artificial key for this row"
				select="format('%%s-%%s',
					((long(ne(bbox)))*1000)::INTEGER,
					((1.5+lat(ne(bbox)))*1000)::INTEGER)"
				verbLevel="1"/>
			<outputField original="centerAlpha"/>
			<outputField original="centerDelta"/>
			<outputField original="ev_i"/>
			<outputField original="sig_ev_i"/>
			<outputField original="bbox"/>
			<LOOP csvItems="\filterdefs">
				<events>
					<outputField name="\name" tablehead="\label"
						description="Extinction in \label, computed as described in
							the reference URL"
						ucd="phys.absorption;em.opt"
						select="ev_i*\factor" unit="mag"
						displayHint="sf=2" verbLevel="\verb"/>
				</events>
			</LOOP>
		</outputTable>
	</dbCore>

	<service id="cone" core="conequery" allowed="form,scs.xml">
		<property name="noAdditionals">True</property>
		<meta name="_intro" format="rst"><![CDATA[
			Enter a position within the
			Magellanic Clouds
			and/or select bands for which you require extinctions.
			The extinction values provided here are based on red clump stars
			as described in `Haschke, R., et al (2011, AJ, 141, 158)
			<http://adsabs.harvard.edu/abs/2011AJ....141..158H>`_.

			To find out how the extinctions for the various bands are computed,
			please refer to the `service info </mcextinct/q/cone/info>`_ .

			If you want to compute extinctions for your object lists, see the
			service info's `crossmatching with your tables`_ chapter.

			.. _crossmatching with your tables: /mcextinct/q/cone/info#crossmatching-with-your-tables
		]]></meta>
		<meta name="testQuery">
			<meta name="ra">93.5257</meta>
			<meta name="dec">-72.8005</meta>
		</meta>
		<publish render="form" sets="local,ivo_managed"/>
		<publish render="scs.xml" sets="ivo_managed"/>
		<meta name="shortName">MC extinctions</meta>
		<meta name="title">Magellanic Clouds Extinction Values</meta>
		<meta name="_noresultwarning">Sorry, your coordinates are outside of the area of the Clouds covered by OGLE-III</meta>

		<inputKey name="_ADDITEM" tablehead="Extinctions for band(s)"
			description="Check bands you want extinctions for"
			type="text" showItems="-1" multiplicity="multiple">
			<values>
				<LOOP csvItems="\filterdefs">
					<events>
						<option title="\label">\name</option>
					</events>
				</LOOP>
			</values>
		</inputKey>

		<outputTable namePath="fullOut">
			<outputField original="row_id"/>
			<outputField original="centerAlpha"/>
			<outputField original="centerDelta"/>
			<outputField original="ev_i"/>
			<outputField original="sig_ev_i"/>
			<outputField original="bbox"/>
		</outputTable>
	</service>

	<regSuite id="dachsregression">
		<regTest title="mcextinct VOSI availability looks plausible">
			<url>cone/availability</url>
			<code><![CDATA[
				self.assertHasStrings("available>true", "upSince>20")
			]]></code>
		</regTest>

		<regTest title="VOSI availability response validates">
			<url>cone/availability</url>
			<code>
				self.assertValidatesXSD()
			</code>
		</regTest>

		<regTest title="mcextinct VOSI capabilities looks plausible">
			<url>cone/capabilities</url>
			<code><![CDATA[
				self.assertHasStrings("capability", "ConeSearch", "Type>GET</query")
			]]></code>
		</regTest>

		<regTest title="VOSI capabilities response validates">
			<url>cone/capabilities</url>
			<code>
				self.assertValidatesXSD()
			</code>
		</regTest>

		<regTest title="VOSI tableMetadata response looks plausible" id="cur">
			<url>cone/tableMetadata</url>
			<code><![CDATA[
				self.assertHasStrings(
					"name>mcextinct</name", "ame>centeralpha</name")
			]]></code>
		</regTest>

		<regTest title="VOSI tableMetadata response validates for dbCore">
			<url>cone/tableMetadata</url>
			<code>
				self.assertValidatesXSD()
			</code>
		</regTest>
	</regSuite>

	<regSuite id="svcs">
			<regTest title="MC Extinctions form gives expected data">
				<url parSet="form" _ADDITEM="a_gg" hscs_sr="10.0"
					hscs_pos="84.6583, -69.0949">cone/form</url>
				<code>
					self.assertHasStrings("Matched: 12", "0.43", "Gunn g",
						# part of bounding box serialisation for 1487-297:
						# last and first digits
						"06 -69.2")
				</code>
			</regTest>

		<regTest title="MC Extinctions SCS gives expected data">
			<url SR="0.1" DEC="-69.0949" RA="84.6583"
				RESPONSEFORMAT="votabletd">cone/scs.xml</url>
			<code><![CDATA[
				self.assertHasStrings('><TD>0.17',
					'</TD><TD>84.62618', ' -69.24887')
			]]></code>
		</regTest>

		<regTest title="VOTable casts work on magellanic cloud extinction values.">
				<url SR="0.1" DEC="-72.8005" RA="93.5257"
					>cone/scs.xml</url>
			<code>
				self.assertXpath("//v:FIELD[@ID='centerAlpha']", {
					"datatype": "double",
					"ucd": "POS_EQ_RA_MAIN"})
				self.assertXpath("//v:FIELD[@ucd='ID_MAIN']", {
					"datatype": "char",
					"arraysize": "*"})

			</code>
		</regTest>
	</regSuite>
</resource>
