Skip to content

Commit 642b595

Browse files
committed
add jmmc-simbad:resolve-identifiers()
1 parent 675de13 commit 642b595

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

content/jmmc-simbad.xql

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ xquery version "3.0";
1414
:)
1515
module namespace jmmc-simbad="http://exist.jmmc.fr/jmmc-resources/simbad";
1616

17+
import module namespace jmmc-tap="http://exist.jmmc.fr/jmmc-resources/tap" at "jmmc-tap.xql";
18+
19+
1720
declare namespace votable="http://www.ivoa.net/xml/VOTable/v1.3";
1821
declare namespace http="http://expath.org/ns/http-client";
1922

@@ -97,6 +100,61 @@ declare %private function jmmc-simbad:escape($str as xs:string) as xs:string {
97100
replace($str, "'", "''")
98101
};
99102

103+
(:~
104+
: Try to identify somes targets from the given identifiers on CDS Simbad.
105+
:
106+
: @param $identifiers the target names
107+
: @return a votable with one row per identifier and simbad info (name, ra, dec, pmra, pmdec, id) if found.
108+
:)
109+
declare function jmmc-simbad:votable4identifiers($identifiers as xs:string*){
110+
let $table :=
111+
<table>
112+
<tr><th>identifier</th></tr>
113+
{
114+
for $identifier in $identifiers
115+
return <tr><td>{$identifier}</td></tr>
116+
}
117+
</table>
118+
let $name := "whynot"
119+
let $votable := jmmc-tap:table2votable($table, $name)
120+
121+
let $query := "SELECT whynot.*, main_id AS name, ra, dec, pmra, pmdec, oid AS id " ||
122+
"FROM basic JOIN ident ON oidref=oid RIGHT JOIN TAP_UPLOAD.whynot as whynot ON id=my_identifier"
123+
return
124+
jmmc-tap:tap-adql-query($jmmc-simbad:TAP-SYNC, $query, $votable, count($identifiers), "votable/td")
125+
};
126+
127+
(:~
128+
: Try to identify somes targets from the given identifiers on CDS Simbad.
129+
:
130+
: @param $identifiers the target names
131+
: @return a map of identifiers / targets (same format as resolve-by-name) value is empty if identifier is unknown on Simbad.
132+
:)
133+
declare function jmmc-simbad:resolve-by-names($identifiers as xs:string*) as item()* {
134+
let $votable := jmmc-simbad:votable4identifiers($identifiers)
135+
let $map := map:merge(
136+
for $tr in $votable//*:TR
137+
let $my_identifier := data($tr/*:TD[1])
138+
let $id := data($tr/*:TD[7])
139+
let $target := if (exists($id)) then
140+
<target>
141+
{
142+
element {"name"} {data($tr/*:TD[2])}
143+
,element {"ra"} {data($tr/*:TD[3])}
144+
,element {"dec"} {data($tr/*:TD[4])}
145+
,element {"pmra"} {data($tr/*:TD[5])}
146+
,element {"pmdec"} {data($tr/*:TD[6])}
147+
,element {"id"} {data($tr/*:TD[7])}
148+
}
149+
</target>
150+
else
151+
()
152+
return map:entry($my_identifier, $target)
153+
)
154+
return $map
155+
};
156+
157+
100158
(:~
101159
: Try to identify a target from its name with Simbad.
102160
:
@@ -118,7 +176,7 @@ declare function jmmc-simbad:resolve-by-name($identifier as xs:string) as item()
118176
declare function jmmc-simbad:resolve-by-name($identifier as xs:string, $ra as xs:double?, $dec as xs:double?) as item()* {
119177
let $do-dist := ($ra and $dec)
120178
let $query :=
121-
"SELECT oid AS id, ra, dec, main_id AS name, pmra, pmdec " || (if($do-dist) then ", DISTANCE(POINT('ICRS', ra, dec), POINT('ICRS', " || $ra || ", " || $dec || ")) AS dist " else " ") ||
179+
"SELECT main_id AS name, ra, dec, pmra, pmdec, oid AS id " || (if($do-dist) then ", DISTANCE(POINT('ICRS', ra, dec), POINT('ICRS', " || $ra || ", " || $dec || ")) AS dist " else " ") ||
122180
"FROM basic JOIN ident ON oidref=oid " ||
123181
"WHERE id = '" || jmmc-simbad:escape($identifier) || "' " ||
124182
(if($do-dist) then "ORDER BY dist" else "")
@@ -136,7 +194,7 @@ declare function jmmc-simbad:resolve-by-name($identifier as xs:string, $ra as xs
136194
:)
137195
declare function jmmc-simbad:resolve-by-coords($ra as xs:double, $dec as xs:double, $radius as xs:double) as item()* {
138196
jmmc-simbad:resolve(
139-
"SELECT oid AS id, ra, dec, main_id AS name, DISTANCE(POINT('ICRS', ra, dec), POINT('ICRS', " || $ra || ", " || $dec || ")) AS dist , pmra, pmdec " ||
197+
"SELECT main_id AS name, ra, dec, pmra, pmdec, oid AS id, DISTANCE(POINT('ICRS', ra, dec), POINT('ICRS', " || $ra || ", " || $dec || ")) AS dist " ||
140198
"FROM basic " ||
141199
"WHERE CONTAINS(POINT('ICRS', ra, dec), CIRCLE('ICRS', " || $ra || ", " || $dec || ", " || $radius || " )) = 1 " ||
142200
"ORDER BY dist")

repo.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<ul xmlns="">
1616
<li>jmmc-tap : tap-adql-query() support optional votable-name for tap-upload.</li>
1717
<li>jmmc-tap : add table2votable() as helper for tap-upload.</li>
18+
<li>jmmc-simbad : add resolve-by-names() to scale-up name resolution (few seconds for one thousand of identifiers).</li>
1819
</ul>
1920
</change>
2021
<change version="0.45.0">

0 commit comments

Comments
 (0)