<!-- please note: to build the data, this uses the movepm function
from the ancient postgastro module.  If you ever wanted to re-build
the data, you'd have to port this to pgsphere's epoch_prop -->

<resource resdir="amlensing" schema="plc" allProfiles="defaults">

  <meta name="creationDate">2008-02-15T13:10:00Z</meta>
  <meta name="schema-rank">100</meta>

  <meta name="subject">catalogs</meta>
  <meta name="subject">astrometric-microlensing-effect</meta>

  <meta name="description" format="plain">A catalogue of candidate stars
    for observing astrometric microlensing using Gaia. </meta>
  <meta name="title">Candidates for astrometric microlensing</meta>
  <meta name="creator">Demleitner, M.; Proft, S.</meta>
  <meta name="coverage.waveband">Optical</meta>
  <meta name="source">2011A&amp;A...536A..50P</meta>

  <meta name="_intro" format="rst">
	  To obtain the complete list of microlensing candidates, including
	  lenses with correct, spurious, and unverified proper motion, click
	  on the Go button. Otherwise, select your preferred candidates and
	  their ordering. If you are only interested in the microlensing
	  candidates with verified proper motion, select "Confirmed?".
	  More information on the idea behind this catalog and the
	  description of all properties can be found in the
	  `service info &lt;/amlensing/q/q/info#id7&gt;`_.
	
  </meta>
  <meta name="_longdoc" format="rst"><![CDATA[
The Idea behind this Catalog
----------------------------

We constructed the candidate list to identify stars with large proper motions
(>0.15 arcsec/year) that are potential candidates for the astrometric
microlensing effect during the Gaia mission [PDW]_. With the Gaia mission it will be
possible to measure this effect with the required accuracy at best 30
micro-arcsec for a single measurement. The satellite, which is observing since July 2014, surveys the
whole sky and has an expected lifetime of five years. It is doing astrometry, photometry
and spectroscopy of approximately one billion stars in our galaxy brighter than
~20 mag in visual band [GAIA]_.

The astrometric microlensing effect allows a precise measurement of the mass of
a star that is acting as a lens [PAC]_. Ideally, the microlensing event is
observed both astrometrically and photometrically. When the unaffected source
position is not known or the lens is not visible both measurements are
necessary. Photometric microlensing events (with small angular distances of
lens and source) are about ten times shorter than the corresponding astrometric
event. Hence Gaia will do no or only few photometric measurements. Therefore,
an accompanying ground based photometric observations of the
events would be advantageous. For this purpose it is very helpful to predict
microlensing events.

To predict microlensing events it is essential to have positions and proper
motions with a high accuracy (maximal 100 mas in position and 10
mas/year in proper motion). Hence it is important to choose suitable
catalogs for the lenses and sources. For the sources, we chose
PPMXL [PPMXL]_, for the lenses the LSPM-NORTH [LSPM]_ on the northern sky and
PPMX [PPMX]_ and UCAC3 [UCAC3]_.

Problems
--------

After manual inspection of about one hundred lens proper motions we found out
that the majority of the high proper motions in PPMX an UCAC3 are erroneous.
While nearly all proper motions from LSPM are correct, only a small
fraction of high proper motions (<1%) from PPMX and UCAC3 are physical.
This means that a high number of
the predicted events from our candidate list is wrong.

Confirmed Microlensing Candidates (2012-2019)
-------------------------------------------------

In our previous work the assembled microlensing catalog comprised
910 candidates for the years 2012 to 2017. Their proper motion analysis yielded
that 96% of the (high) proper motions of the lensing stars were erroneous.
We were thus left with only 43 confirmed microlensing candidates. Due to an
improvement of the search width around potential lensing stars, we can predict
50 additional astrometric microlensing events with correct proper motion
now between 2014 and 2019. All confirmed astrometric microlensing
candidates are marked with true in the "Confirmed?"-column.

References
----------

.. [PDW] Proft, S., Demleitner, M. and Wambsganss, J. (2011). Prediction of astrometric microlensing events during the Gaia mission. `2011A%26A...536A..50P <http://ads.ari.uni-heidelberg.de/abs/2011A%26A...536A..50P>`_
.. [GAIA] Science Performance of the Gaia Satellite. `www.cosmos.esa.int/web/gaia/science-performance <http://www.cosmos.esa.int/web/gaia/science-performance>`_
.. [LSPM] Lepine, S. and Shara, M. M. (2005). A Catalog of Northern Stars With Annual Proper Motions Larger Than 0.15 Seconds of Arc (LSPM catalog - North). `2005AJ....129.1483L <http://ads.ari.uni-heidelberg.de/abs/2005AJ....129.1483L>`_
.. [PAC] Paczynski, B. (1995). The Masses of Nearby Dwarfs can be Determined with Gravitational Microlensing. `1995AcA....45..345P <http://ads.ari.uni-heidelberg.de/abs/1995AcA....45..345P>`_
.. [PPMXL] Roeser, S., Demleitner, M. and Schilbach, E. (2010). The PPMXL catalog of positions and proper motions on the ICRS. Combining USNOB1.0 and 2MASS. `2010AJ....139.2440R <http://ads.ari.uni-heidelberg.de/abs/2010AJ....139.2440R>`_
.. [PPMX] Roeser, S. et al. (2008). PPM Extended (PPMX) - a catalogue of positions and proper motions. `2008A&A...488..401R <http://ads.ari.uni-heidelberg.de/abs/2008A%26A...488..401R>`_
.. [UCAC3] Zacharias, N. et al. (2010). The Third US Naval Observatory CCD Astrograph Catalog (UCAC3). `2010AJ....139.2184Z <http://ads.ari.uni-heidelberg.de/abs/2010AJ....139.2184Z>`_
  ]]></meta>

  <table id="highpm" onDisk="True" mixin="//scs#q3cindex"
      namePath="ppmx/res/ppmx#data">
    <mixin>//scs#pgs-pos-index</mixin>
    <meta name="description">The "input table" containing stars with
      relatively high proper motion.  Currently, these are generated
      PPMX, UCAC3, LSPM-North, and a catalogue of brown dwarfs.</meta>

    <column name="source" type="text"/>
    <column name="sourceId" type="text"/>
    <column name="alpha" type="double precision" unit="deg"
      ucd="pos.eq.ra;meta.main"/>
    <column name="delta" type="double precision" unit="deg"
      ucd="pos.eq.dec;meta.main"/>
    <column name="pma" unit="deg/yr"
      description="Proper motion in alpha, cos(delta) applied"/>
    <column name="pmd" unit="deg/yr"/>
    <column name="alphaErr" unit="deg"/>
    <column name="deltaErr" unit="deg"/>
    <column name="pmaErr" unit="deg/yr"
      description="Error in PM(alpha), cos(delta) applied"/>
    <column name="pmdErr" unit="deg/yr"/>
    <column name="mag" unit="mag"
      description="Some, source dependent, magnitude"/>
    <column name="pmTotal" unit="deg/yr"
      description="Total proper motion"/>
    <column name="pmPA" unit="deg"
      description="Position angle of proper motion"/>
    <column name="roi" type="double precision[]"
      description="Region potentially swept over, as alpha, delta points"/>
    <column original="Rmag"/>
    <column original="Bmag"/>
    <column original="Vmag"/>
    <column original="Jmag"/>
    <column original="Hmag"/>
    <column original="Kmag"/>
  </table>


  <table id="rawcands" original="highpm" namePath="ppmxl/q#main"
      onDisk="True">
    <meta name="description">The table of candidate stars.  These
      are objects from highpm that have a PPMXL object within their
      regions of interest.</meta>

    <!-- this table has all the columns from plc.highpm plus the following:
    -->
    <column original="ipix" name="lensedid" required="True"/>
    <column original="raj2000" name="lensedra" ucd="pos.eq.ra"/>
    <column original="dej2000" name="lensedde" ucd="pos.eq.dec"/>
    <column original="e_raepRA" name="e_lensedra"/>
    <column original="e_deepDE" name="e_lensedde"/>
    <column original="pmRA" name="lensedpmra"/>
    <column original="pmDE" name="lensedpmde"/>
    <column original="e_pmRA" name="e_lensedpmra"/>
    <column original="e_pmDE" name="e_lensedpmde"/>
    <column original="epRA" name="lensedepra"/>
    <column original="epDE" name="lensedepde"/>
    <column original="Jmag" name="lensedjmag"/>
    <column original="Hmag" name="lensedhmag"/>
    <column original="Kmag" name="lensedkmag"/>
    <column original="b1mag" name="lensedBmag"/>
    <column original="r2mag" name="lensedRmag"/>
    <column original="imag" name="lensedImag"/>
  </table>


  <table id="data" onDisk="True" mixin="//scs#q3cindex" adql="True">
    <mixin>//scs#pgs-pos-index</mixin>
    <meta name="description">The final candidate table with estimates
      of minimal distances, epochs, etc.</meta>

    <stc>
      Position ICRS BARYCENTER Epoch J2000.0 "lensalpha" "lensdelta"
        Error "lensalphaErr" "lensdeltaErr"
      Velocity "lenspmalpha" "lenspmdelta"
        Error "lenspmalphaErr" "lenspmdeltaErr"
    </stc>

    <stc>
      Position ICRS "obalpha" "obdelta"
        Error "obalphaErr" "obdeltaErr"
      Velocity "obpmalpha" "obpmdelta"
        Error "obpmalphaErr" "obpmdeltaErr"
    </stc>

    <column name="source" ucd="meta.code" type="text"
      tablehead="Lens src." description="Source of the data of the lens"
      verbLevel="10"/>
    <column name="srcId" ucd="meta.id;meta.main" type="text"
      tablehead="Lensing ob." description="Id of lensing object"
      verbLevel="5"/>
    <column name="lensalpha" tablehead="Lensing alpha"
      description="J2000 PPMX alpha of lens" type="double precision"
      ucd="pos.eq.ra;meta.main" displayHint="type=hms,sf=3"
      unit="deg" verbLevel="1"/>
    <column name="lensdelta" tablehead="Lensing delta"
      description="J2000 PPMX delta of lens" type="double precision"
      ucd="pos.eq.dec;meta.main" displayHint="type=dms"
      unit="deg" verbLevel="1"/>
    <column name="lensalphaErr" tablehead="Err(L.alpha)"
      description="Error of lens alpha" unit="deg"
      ucd="stat.error;pos.eq.ra;meta.main"
      verbLevel="15"/>
    <column name="lensdeltaErr" tablehead="Err(L.delta)"
      description="Error of lens delta" unit="deg"
      ucd="stat.error;pos.eq.dec;meta.main"
      verbLevel="15"/>

    <column name="lenspmalpha" tablehead="L. PM alpha"
      description="Lens PM in alpha, cos(delta) applied" unit="deg/yr"
      displayHint="displayUnit=mas/yr"/>
    <column name="lenspmdelta" tablehead="L. PM delta"
      description="Lens PM in delta" unit="deg/yr"
      displayHint="displayUnit=mas/yr"/>
    <column name="lenspmalphaErr" tablehead="Err(L. PM alpha)"
      description="Error of Lens PM in alpha" unit="deg/yr"
      displayHint="displayUnit=mas/yr"/>
    <column name="lenspmdeltaErr" tablehead="Err(L. PM delta)"
      description="Error of Lens PM in delta" unit="deg/yr"
      displayHint="displayUnit=mas/yr"/>

    <column name="lensmag" tablehead="Lens mag" unit="mag"
      description="PPMX catalogue magnitude of lens"/>
    <LOOP listItems="R B V J H K">
      <events>
        <column name="lens\item\+mag" tablehead="Lens \item mag"
          description="Lens \item mag as in PPMX" unit="mag"/>
      </events>
    </LOOP>
    <column name="lensRmag" tablehead="Lens R" unit="mag"
      description="PPMX Ru mag of lens"/>

    <column name="obalpha" tablehead="Object alpha"
      description="J2000 USNO alpha of lensed object" unit="deg"
      type="double precision" displayHint="type=hms,sf=3"
      />
    <column name="obdelta" tablehead="Object delta"
      description="J2000 USNO delta of lensed object" unit="deg"
      type="double precision" displayHint="type=dms"
      />
    <column name="obalphaErr" tablehead="Err(O. alpha)" unit="deg"
      description="Positional error of lensed object in alpha"
      displayHint="displayUnit=arcsec"
      />
    <column name="obdeltaErr" tablehead="Err(O. delta)" unit="deg"
      description="Positional error of lensed object in delta"
      displayHint="displayUnit=arcsec"
      />

    <column name="obpmalpha" tablehead="O. PM alpha"
      description="Object PM in alpha" unit="deg/yr"
      displayHint="displayUnit=mas/yr"
      />
    <column name="obpmdelta" tablehead="O. PM delta"
      description="Object PM in delta" unit="deg/yr"
      displayHint="displayUnit=mas/yr"
      />
    <column name="obpmalphaErr" tablehead="Err(O. PM alpha)"
      description="Error of Object PM in alpha" unit="deg/yr"
      displayHint="displayUnit=mas/yr"
      />
    <column name="obpmdeltaErr" tablehead="Err(O. PM delta)"
      description="Error of Object PM in delta" unit="deg/yr"
      displayHint="displayUnit=mas/yr"
      />

    <column name="obB" tablehead="Object B mag"
      description="USNO-B B mag magnitude of lensed"
      />
    <column name="obR" tablehead="Object R mag"
      description="USNO-B R mag magnitude of lensed"
      />
    <column name="obI" tablehead="Object I mag"
      description="USNO-B I mag magnitude of lensed"
      />

    <column name="obJ" tablehead="Object J mag"
      description="2MASS J mag magnitude of lensed"
      />
    <column name="obH" tablehead="Object H mag"
      description="2MASS H mag magnitude of lensed"
      />
    <column name="obK" tablehead="Object K mag"
      description="2MASS K mag magnitude of lensed"
      />

    <column name="minDate" tablehead="T(min)" type="real"
      description="Estimated time of closest approach (julian year)"
      unit="yr"
      />
    <column name="minDateErr" tablehead="Err. T(min)" type="real"
      description="Error in estimation of time of closest approach"
      unit="yr"
      />
    <column name="minDist" tablehead="D(min)" unit="deg"
      description="Estimated minimal distance"
      displayHint="displayUnit=arcsec"
      />
    <column name="minDistErr" tablehead="Err. D(min)" type="real"
      description="Error in estimation of minimal distance"
      unit="deg" displayHint="displayUnit=arcsec"
      />

    <column name="confirmed" type="boolean" tablehead="Confirmed?"
      description="1 if lensing event confirmed" required="True"/>
  </table>

  <data id="import_highpm">
    <make table="highpm">
      <script type="preIndex" lang="SQL" name="from ppmx">
          INSERT INTO plc.highpm (
            SELECT 'PPMX' as source, localid as sourceId,
              alphaFloat as alpha, deltaFloat as delta,
              pmra/3600. as pma, pmDE/3600. as pmd,
              RAErr/1000/3600 as alphaErr, DecErr/1000/3600 as deltaErr,
              PMRAErr/3600 as pmaErr, PMDEErr/3600 as pmdErr,
              Cmag as mag, pm_total as pmTotal, angle_pm as pmPA,
              ARRAY[
                startpos[0]+w*sin(a), startpos[1]-w*cos(a),
                endpos[0]+w*sin(a), endpos[1]-w*cos(a),
                endpos[0]-w*sin(a), endpos[1]+w*cos(a),
                startpos[0]-w*sin(a), startpos[1]+w*cos(a)] AS roi,
              Rmag, Bmag, Vmag, Jmag, Hmag, Kmag
            FROM (
              SELECT *, angle_pm/180*3.14159 as a,
                    CASE WHEN Vmag&lt;11 THEN 7/3600. ELSE 2/3600. END as w,
                    movePm(alphaFloat, deltaFloat, pmra/3600., pmDE/3600.,
                      '2000-01-01T00:00:00', '2008-01-01T00:00:00') as startpos,
                    movePm(alphaFloat, deltaFloat, pmra/3600., pmDE/3600.,
                      '2000-01-01T00:00:00', '2020-01-01T00:00:00') as endpos
                  FROM ppmx.data
                  WHERE pm_total>0.15) as withmove)
      </script>

        <script type="preIndex" lang="SQL" name="Import from LSPM">
          INSERT INTO plc.highpm (
            SELECT 'LSPM' as source, id as sourceId,
              raj2000 as alpha, dej2000 as delta,
              pmRA as pma, pmDE as pmd,
              2.8e-5 as alphaErr,
              2.8e-5 as deltaErr, -- levine gives 100 mas position err
              2.2e-6/cos(radians(dej2000)) as pmaErr,
              2.2e-6 as pmdErr, -- and 8 mas/yr as PM err
              vmag_e as mag, pm as pmTotal, pmPA,
              ARRAY[
                startpos[0]+w*sin(a), startpos[1]-w*cos(a),
                endpos[0]+w*sin(a), endpos[1]-w*cos(a),
                endpos[0]-w*sin(a), endpos[1]+w*cos(a),
                startpos[0]-w*sin(a), startpos[1]+w*cos(a)] AS roi,
              rfmag, bjmag, vmag, jmag, hmag, kmag
            FROM (
              SELECT *, pmPA/180*3.14159 as a,
                 CASE WHEN Vmag_e&lt;11 THEN 7/3600. ELSE 2/3600. END as w,
                 movePm(raj2000, dej2000, pmRA, pmDE,
                   '2000-01-01T00:00:00', '2008-01-01T00:00:00') as startpos,
                 movePm(raj2000, dej2000, pmRA, pmDE,
                   '2000-01-01T00:00:00', '2020-01-01T00:00:00') as endpos
              FROM (
                SELECT *, degrees(atan2(radians(pmRA),radians(pmDE))) as pmPA
                FROM lspm.main) as withmove) as q)
      </script>

      <!-- UCAC3 proper motions are only good south of -30 deg.  Take
      those larger than 0.18", which is a nice complement to LSPM north -->
      <script type="preIndex" lang="SQL" name="Import from UCAC3 south">
        <![CDATA[
          INSERT INTO plc.highpm (
            SELECT 'UCAC3' as source,
              to_char(raj2000, '000.99999')||to_char(dej2000, 'S000.99999') as sourceId,
              raj2000 as alpha, dej2000 as delta,
              pmRA as pma, pmDE as pmd,
              sigra as alphaErr,
              sigdc as deltaErr,
              sigpmra/cos(radians(dej2000)) as pmaErr,
              sigpmde as pmdErr,
              mmag as mag, sqrt(pmra^2+pmde^2) as pmTotal, pmPA,
              ARRAY[
                startpos[0]+w*sin(a), startpos[1]-w*cos(a),
                endpos[0]+w*sin(a), endpos[1]-w*cos(a),
                endpos[0]-w*sin(a), endpos[1]+w*cos(a),
                startpos[0]-w*sin(a), startpos[1]+w*cos(a)] AS roi,
              NULL, NULL, NULL, NULL, NULL, NULL
            FROM (
              SELECT *, pmPA/180*3.14159 as a,
                 CASE WHEN mmag<11 THEN 7/3600. ELSE 2/3600. END as w,
                 movePm(raj2000, dej2000, pmRA, pmDE,
                   '2000-01-01T00:00:00', '2008-01-01T00:00:00') as startpos,
                 movePm(raj2000, dej2000, pmRA, pmDE,
                   '2000-01-01T00:00:00', '2020-01-01T00:00:00') as endpos
              FROM (
                SELECT *, degrees(atan2(radians(pmRA),radians(pmDE))) as pmPA
                FROM ucac3.main where
                  dej2000<-30 and sqrt(pmra^2+pmde^2)>5e-5) as withmove) as q)
      ]]></script>
      </make>
  </data>

  <data id="match">
    <make table="rawcands">
      <!-- The select list below must exactly match the table definition
      in rawcands above.  Sorry 'bout that.

      Also, there's a spurious limit in the innermost subquery here
      which is needed to fix postgres' query planner. -->

      <!-- Warning: if you have more than 10e6 rawcands, you need to raise the
      limit here. -->
      <script type="preIndex" lang="SQL" name="Match highpm with ppmxl">
        INSERT INTO plc.rawcands (
          SELECT * FROM (
            SELECT
              lens.*,
              lensed.ipix, lensed.raj2000, lensed.dej2000,
              lensed.e_raepRA, lensed.e_deepDE,
              lensed.pmRA, lensed.pmDE,
              lensed.e_pmRA, lensed.e_pmDE,
              lensed.epRA, lensed.epDE,
              lensed.Jmag, lensed.Hmag, lensed.Kmag,
              CASE WHEN lensed.b1mag IS NULL
                THEN lensed.b2mag
                ELSE lensed.b1mag
              END,
              CASE WHEN lensed.r1mag IS NULL
                THEN lensed.r2mag
                ELSE lensed.r1mag
              END,
              lensed.imag
            FROM
              ppmxl.main AS lensed,
              (SELECT * FROM plc.highpm LIMIT 1000000) AS lens
            WHERE q3c_join(lens.alpha, lens.delta,
              lensed.raj2000, lensed.dej2000, 0.01)
            ) AS q
          WHERE
            q3c_poly_query(raj2000, dej2000, roi)
            AND NOT q3c_radial_query(alpha, delta,
              raj2000, dej2000, 0.5/3600));
      </script>

    </make>
  </data>


  <data id="compute">
    <sources items="database input"/>
    <customGrammar module="res/makecands_svea"/>
    <make table="data">
      <!-- There's a VOTable with lens positions/PMs corrected from PPMXL
      by Svea; somewhat sleazily, we hack that stuff into the rawcands
      table. -->
      <script type="preImport" lang="python" name="Add Svea's corrections">
        from gavo import votable
        data, metadata = votable.load(
          table.tableDef.rd.openRes("data/sveasCorrections.vot"))
        for row in metadata.iterDicts(data):
          c = table.conn.execute("UPDATE plc.rawcands SET "
            "alpha=%(raj2000)s, delta=%(dej2000)s, "
            "alphaErr=%(e_raj2000)s, deltaErr=%(e_raj2000)s, "
            "pma=%(pmra)s, pmd=%(pmde)s, "
            "pmaErr=%(e_pmra)s, pmdErr=%(e_pmde)s "
            "WHERE source||' '||sourceId=%(srcId)s", row)
      </script>
    </make>
  </data>

  <scsCore id="qcore" queriedTable="data">
    <condDesc original="//scs#humanInput"/>
    <condDesc original="//scs#protoInput"/>
    <condDesc buildFrom="lensmag"/>
    <condDesc buildFrom="obB"/>
    <condDesc buildFrom="minDate"/>
    <condDesc>
      <inputKey original="minDist" inputUnit="arcsec"/>
    </condDesc>
    <condDesc>
      <inputKey original="source">
        <values fromdb="source from plc.data"/>
      </inputKey>
    </condDesc>
    <condDesc>
      <inputKey original="confirmed"
        description="Only show candidates for which the encounter
          is confirmed (i.e., proper motions are right)"/>
      <phraseMaker> <!-- only contribute when field is checked -->
        <code>
          if inPars.get(inputKeys[0].name, False):
            yield "confirmed"
        </code>
      </phraseMaker>
    </condDesc>
  </scsCore>

  <service id="q" core="qcore" allowed="form,scs.xml">
	<property key="defaultSort">minDate</property>
    <publish render="form" sets="local,ivo_managed"/>
    <publish render="scs.xml" sets="ivo_managed"/>
    <meta name="shortName">am lensing cands</meta>
    <meta name="testQuery">
      <meta name="ra">314.7149425</meta>
      <meta name="dec">36.1983766667</meta>
      <meta name="sr">0.01</meta>
    </meta>

    <outputTable namePath="data">
      <LOOP listItems="_r source srcId confirmed lensalpha
          lensdelta lensmag obalpha obdelta
          obB minDate minDist">
        <events>
          <outputField original="\item"/>
        </events>
      </LOOP>
      <LOOP listItems="10 13 16 19">
        <events>
          <outputField name="dist20\item"
            select="degrees(epoch_prop_pos(
              spoint(radians(lensalpha), radians(lensdelta)), 0,
              radians(lenspmalpha), radians(lenspmdelta), 0, \item)
            &lt;-> epoch_prop_pos(
              spoint(radians(obalpha), radians(obdelta)), 0,
              radians(obpmalpha), radians(obpmdelta), 0, \item))"
            tablehead="Dist 20\item" unit="deg"
            displayHint="displayUnit=arcsec"/>
        </events>
      </LOOP>
      <outputField name="simbad" type="raw"
        tablehead="In Simbad" select="array[lensalpha,lensdelta]"
        description="Cone search around given position in Simbad"
        displayHint="type=simbadlink,coneMins=0.1,noxml=true"/>
      <outputField name="aladin" verbLevel="19" type="text"
          select="array[lensalpha, lensdelta, obalpha, obdelta, lenspmalpha, lenspmdelta, obpmalpha, obpmdelta, lenspmalphaErr, lenspmdeltaErr ]"
          tablehead="Aladin" description="A script to paste into Aladin
            that visualises the situation."
          displayHint="noxml=true">
        <formatter>
          def RA(f):
            return utils.degToHms(f, ":")
          def DEC(f):
            return utils.degToDms(f, ":")

          def getLensBorder(alpha, delta, pma, pmd, pmaErr, pmdErr,
              years, width):
            cosD = math.cos(delta/180*math.pi)
            # factor for pm for total offset arcsec vector
            destA = alpha+(pma*years)/cosD
            destD = delta+pmd*years
            pmNorm = 1/math.sqrt(pma**2+pmd**2)*(width/2.)/3600.
            oal, odl = pmd*pmNorm, pma*pmNorm
            return ((RA(alpha+oal/cosD), DEC(delta-odl),
                RA(destA+oal/cosD), DEC(destD-odl)),
              (RA(alpha-oal/cosD), DEC(delta+odl),
                RA(destA-oal/cosD), DEC(destD+odl)))

          def getLenseeMark(alpha, delta, pma, pmd, span):
            if pma**2+pmd**2&lt;(1/3600./20)**2:
              return "draw tag(%s, %s)"%(RA(alpha), DEC(delta))
            return  "draw line(%s,%s,%s,%s);"%(
              RA(alpha), DEC(delta),
              RA(alpha+pma*span), DEC(delta+pmd*span))

          if data is None:
            return ""
          span = 25;
          lA, lD = data[0], data[1]
          oA, oD = data[2], data[3]
          lpma, lpmd = data[4], data[5]
          opma, opmd = data[6], data[7]
          lpmaErr, lpmdErr = data[8], data[9]
          upper, lower = getLensBorder(lA, lD, lpma, lpmd, lpmaErr,
              lpmdErr, span, 1)
          script = ";\\n".join([
            "get aladin() %s %s"%(utils.degToHms(lA), utils.degToDms(lD)),
            "sync",
            "draw mode(radec)",
            "draw line(%s,%s,%s,%s)"%upper,
            "draw line(%s,%s,%s,%s)"%lower,
            getLenseeMark(oA, oD, opma, opmd, span),
          ])+";"
          return T.pre(style="width:8em;height:6em;overflow:scroll")[
            script]
        </formatter>
      </outputField>
    </outputTable>
  </service>

  <regSuite title="amlensing regression">
    <regTest title="amlensing web interface yields plausible values.">
      <url parSet="form"
        confirmed="True" hscs_pos="21 35 09.499	+54 28 27.17"
        hscs_sr="600.0">/amlensing/q/q/form</url>
      <code>
        self.assertHasStrings(
          "Matched: 3",
          "LSPM J2135+5428",
          "2018.6788",
          "sim-coo?Coord=323.78958d%2B54.47421d&amp;amp;Radius=0.100000",
          "16735", # dist of 2nd object to search center
          "get aladin() 21 30 19.261 +48 42 06.98;\\nsync;\\ndraw mode(radec);"
        )
      </code>
    </regTest>

    <regTest title="amlensing SCS seems to work">
      <url RA="314.7149425" DEC="36.1983766667" SR="0.01"
      >q/scs.xml</url>
      <code>
        rows = self.getVOTableRows()
        self.assertEqual(len(rows), 1)
        self.assertEqual(rows[0]["confirmed"], False)
        self.assertAlmostEqual(rows[0]["minDate"], 2009.2423095703125)
        self.assertFalse("aladin" in rows[0])
      </code>
    </regTest>

  </regSuite>
</resource>
<!-- vi:et:sta:sw=2
-->
