| 1 |
<?xml version="1.0" encoding="utf-8"?> |
| 2 |
<!-- definition of the position-related interfaces (and later SCS fragments) --> |
| 3 |
|
| 4 |
<resource resdir="__system" schema="dc"> |
| 5 |
<STREAM id="splitPosIndex"> |
| 6 |
<doc> |
| 7 |
Adds an index over the separate long and lat columns. |
| 8 |
This is currently implemented using q3c; DaCHS will move |
| 9 |
to pgsphere entirely at some point. RDs using this will not |
| 10 |
need an update then. This will by default cluster according |
| 11 |
to the index. In the rare cases when you don't want this, |
| 12 |
add a cluster="False" in the FEED element. |
| 13 |
|
| 14 |
Since long and lat may be expressions, this will not automatically |
| 15 |
declare index/columns. You should therefore pass in a |
| 16 |
comma-separated list of column names in the columns attribute |
| 17 |
in order to inform clients of the index. |
| 18 |
|
| 19 |
Examples:: |
| 20 |
|
| 21 |
<FEED source="//scs#splitPosIndex" long="ra" lat="dec" |
| 22 |
columns="ra,dec"/> |
| 23 |
|
| 24 |
<FEED source="//scs#splitPosIndex" |
| 25 |
long="long(ssa_location)" lat="lat(ssa_location)" |
| 26 |
columns="ssa_location"/> |
| 27 |
</doc> |
| 28 |
<DEFAULTS cluster="True" columns=""/> |
| 29 |
<index name="splitpos_\\tablename" cluster="\cluster"> |
| 30 |
<columns>\columns</columns> |
| 31 |
q3c_ang2ipix(\long,\lat) |
| 32 |
</index> |
| 33 |
</STREAM> |
| 34 |
|
| 35 |
<STREAM id="q3cIndexDef"> |
| 36 |
<doc> |
| 37 |
Definition of a q3c index over the main position of a table. |
| 38 |
</doc> |
| 39 |
<index name="q3c_\\tablename" cluster="True" kind="q3c"> |
| 40 |
<columns>\\nameForUCDs{pos.eq.ra;meta.main|POS_EQ_RA_MAIN}, \\nameForUCDs{pos.eq.dec;meta.main|POS_EQ_DEC_MAIN}</columns> |
| 41 |
q3c_ang2ipix(\\nameForUCDs{pos.eq.ra;meta.main|POS_EQ_RA_MAIN}, \\nameForUCDs{pos.eq.dec;meta.main|POS_EQ_DEC_MAIN}) |
| 42 |
</index> |
| 43 |
</STREAM> |
| 44 |
|
| 45 |
<mixinDef id="q3cindex"> |
| 46 |
<doc> |
| 47 |
A mixin adding an index to the main equatorial positions. |
| 48 |
|
| 49 |
In new RDs, use pgs-pos-index instead; we'd like to stop q3c support |
| 50 |
at some point. |
| 51 |
|
| 52 |
This is what you usually want if your input data already has |
| 53 |
"sane" (i.e., ICRS or at least J2000) positions or you convert |
| 54 |
the positions manually. |
| 55 |
|
| 56 |
You have to designate exactly one column with the ucds pos.eq.ra;meta.main |
| 57 |
pos.eq.dec;meta.main, respectively. These columns receive the |
| 58 |
positional index. |
| 59 |
|
| 60 |
This will fail without the q3c extension to postgres. |
| 61 |
</doc> |
| 62 |
<lateEvents> |
| 63 |
<FEED source="//scs#q3cIndexDef"/> |
| 64 |
</lateEvents> |
| 65 |
</mixinDef> |
| 66 |
|
| 67 |
<STREAM id="spoint-index-def"> |
| 68 |
<doc> |
| 69 |
Definition of an index over spoint(ra, dec); give this |
| 70 |
parameters long and lat naming the corresponding columns (in degrees). |
| 71 |
|
| 72 |
Or use the spoint-index mixin. |
| 73 |
|
| 74 |
This will by default cluster according to the index. In the rare cases |
| 75 |
when you don't want this, add a cluster="False" in the FEED element. |
| 76 |
|
| 77 |
This needs to be replayed within a table (or something that |
| 78 |
defines a tablename macro). |
| 79 |
</doc> |
| 80 |
<DEFAULTS cluster="True" columns=""/> |
| 81 |
<index name="spoint_\\tablename" cluster="\cluster" kind="spoint" |
| 82 |
method="GIST"> |
| 83 |
<columns>\ra,\dec</columns> |
| 84 |
spoint(radians(\ra),radians(\dec)) |
| 85 |
</index> |
| 86 |
</STREAM> |
| 87 |
|
| 88 |
<mixinDef id="pgs-pos-index"> |
| 89 |
<doc> |
| 90 |
A mixin adding a pgsphere index to the main spherical position for |
| 91 |
tables with separate RA and Dec columns. |
| 92 |
|
| 93 |
You have to designate exactly one column with the ucds pos.eq.ra;meta.main |
| 94 |
pos.eq.dec;meta.main, respectively. These columns receive the |
| 95 |
positional index. |
| 96 |
|
| 97 |
This should be used instead of q3cindex on new tables; it's |
| 98 |
a bit slower than q3c, but it's less funky, too. |
| 99 |
|
| 100 |
If you'd like an index on other sorts of long/lat pairs, see the |
| 101 |
//scs#spoint-index-def STREAM. |
| 102 |
</doc> |
| 103 |
<lateEvents> |
| 104 |
<FEED source="spoint-index-def" |
| 105 |
ra="\nameForUCDs{pos.eq.ra;meta.main}" |
| 106 |
dec="\nameForUCDs{pos.eq.dec;meta.main}"/> |
| 107 |
</lateEvents> |
| 108 |
</mixinDef> |
| 109 |
|
| 110 |
<outputTable id="instance"> |
| 111 |
<!-- this is the prototype from which SCSCore makes its distance |
| 112 |
columns --> |
| 113 |
<outputField id="distCol" |
| 114 |
name="_r" type="double precision" |
| 115 |
unit="deg" ucd="pos.angDistance" |
| 116 |
tablehead="Dist." |
| 117 |
description="Distance to cone center" |
| 118 |
select="'NaN'::REAL" |
| 119 |
verbLevel="10" |
| 120 |
displayHint="displayUnit=arcsec"/> |
| 121 |
</outputTable> |
| 122 |
|
| 123 |
<condDesc> |
| 124 |
<!-- common setup for the SCS-related condDescs --> |
| 125 |
<phraseMaker id="scsUtils"> |
| 126 |
<setup id="scsSetup"> |
| 127 |
<par key="raColName" description="Name of the column containing |
| 128 |
the longitude (default is to determine by UCD)">None</par> |
| 129 |
<par key="decColName" description="Name of the column containing |
| 130 |
the latitude (default is to determine by UCD)">None</par> |
| 131 |
<code> |
| 132 |
from gavo.protocols import scs |
| 133 |
|
| 134 |
def getRADec(inPars, sqlPars): |
| 135 |
"""tries to guess coordinates from inPars. |
| 136 |
|
| 137 |
(for human SCS condition). |
| 138 |
""" |
| 139 |
pos = inPars["hscs_pos"] |
| 140 |
try: |
| 141 |
return base.parseCooPair(pos) |
| 142 |
except ValueError: |
| 143 |
data = base.caches.getSesame("web").query(pos) |
| 144 |
if not data: |
| 145 |
raise base.ValidationError("%s is neither a RA,DEC" |
| 146 |
" pair nor a simbad resolvable object"% |
| 147 |
inPars["hscs_pos"], "hscs_pos") |
| 148 |
return float(data["RA"]), float(data["dec"]) |
| 149 |
|
| 150 |
def genQuery(td, inPars, outPars): |
| 151 |
"""returns the query fragment for this cone search. |
| 152 |
""" |
| 153 |
return scs.getRadialCondition(td, |
| 154 |
"%%(%s)s"%base.getSQLKey("RA", inPars["RA"], outPars), |
| 155 |
"%%(%s)s"%base.getSQLKey("DEC", inPars["DEC"], outPars), |
| 156 |
"%%(%s)s"%base.getSQLKey("SR", inPars["SR"], outPars), |
| 157 |
raColName, decColName) |
| 158 |
</code> |
| 159 |
</setup> |
| 160 |
</phraseMaker> |
| 161 |
</condDesc> |
| 162 |
|
| 163 |
<condDesc id="protoInput" required="True"> |
| 164 |
<inputKey name="RA" type="double precision" unit="deg" ucd="pos.eq.ra" |
| 165 |
description="Right Ascension (ICRS decimal)" tablehead="Alpha (ICRS)" |
| 166 |
multiplicity="single" |
| 167 |
std="True"> |
| 168 |
<property name="onlyForRenderer">scs.xml</property> |
| 169 |
</inputKey> |
| 170 |
<inputKey name="DEC" type="double precision" unit="deg" ucd="pos.eq.dec" |
| 171 |
description="Declination (ICRS decimal)" tablehead="Delta (ICRS)" |
| 172 |
multiplicity="single" |
| 173 |
std="True"> |
| 174 |
<property name="onlyForRenderer">scs.xml</property> |
| 175 |
</inputKey> |
| 176 |
<inputKey name="SR" type="real" unit="deg" description="Search radius" |
| 177 |
multiplicity="single" |
| 178 |
tablehead="Search Radius" std="True"> |
| 179 |
<property name="onlyForRenderer">scs.xml</property> |
| 180 |
</inputKey> |
| 181 |
<phraseMaker id="scsPhrase" name="scsSQL"> |
| 182 |
<setup original="scsSetup"/> |
| 183 |
<code> |
| 184 |
yield genQuery(core.queriedTable, inPars, outPars) |
| 185 |
</code> |
| 186 |
</phraseMaker> |
| 187 |
</condDesc> |
| 188 |
|
| 189 |
<condDesc id="humanInput" combining="True" joiner="AND"> |
| 190 |
<inputKey id="hscs_pos" |
| 191 |
name="hscs_pos" type="text" |
| 192 |
multiplicity="single" |
| 193 |
description= "Coordinates (as h m s, d m s or decimal degrees), or SIMBAD-resolvable object" tablehead="Position/Name"> |
| 194 |
<property name="notForRenderer">scs.xml</property> |
| 195 |
</inputKey> |
| 196 |
<inputKey id="hscs_sr" |
| 197 |
name="hscs_sr" description="Search radius in arcminutes" |
| 198 |
multiplicity="single" |
| 199 |
tablehead="Search radius"> |
| 200 |
<property name="notForRenderer">scs.xml</property> |
| 201 |
</inputKey> |
| 202 |
<phraseMaker original="scsUtils" id="humanSCSPhrase" name="humanSCSSQL"> |
| 203 |
<code> |
| 204 |
if inPars["hscs_pos"] is None: |
| 205 |
return |
| 206 |
if inPars["hscs_sr"] is None: |
| 207 |
raise base.ValidationError("If you query for a position," |
| 208 |
" you must give a search radius", "hscs_sr") |
| 209 |
|
| 210 |
ra, dec = getRADec(inPars, outPars) |
| 211 |
try: |
| 212 |
sr = float(inPars["hscs_sr"])/60. |
| 213 |
except ValueError: # in case we're not running behind forms |
| 214 |
raise gavo.ValidationError("Not a valid float", "hscs_sr") |
| 215 |
inPars = {"RA": ra, "DEC": dec, "SR": sr} |
| 216 |
yield genQuery(core.queriedTable, inPars, outPars) |
| 217 |
</code> |
| 218 |
</phraseMaker> |
| 219 |
</condDesc> |
| 220 |
|
| 221 |
<STREAM id="makeSpointCD"> |
| 222 |
<doc><![CDATA[ |
| 223 |
This builds a cone search condDesc for Web forms for an spoint column. |
| 224 |
|
| 225 |
To define it, say something like:: |
| 226 |
|
| 227 |
<FEED source="//scs#makeSpointCD" |
| 228 |
tablehead="Position observed" |
| 229 |
matchColumn="ssa_location"/> |
| 230 |
|
| 231 |
This is also used in ``<condDesc buildFrom="(some spoint col)"/>`` |
| 232 |
]]></doc> |
| 233 |
|
| 234 |
<!-- this should be forbidden in untrusted RDs since it's easy to |
| 235 |
do python code or SQL injection using this. To mitigate it, |
| 236 |
we'd need some input validation for (specific) macro arguments |
| 237 |
or a notion of "unsafe" streams. Well, right before untrusted |
| 238 |
DaCHS RDs actually start to get swapped, I'll do either of these. --> |
| 239 |
|
| 240 |
<condDesc> |
| 241 |
<inputKey name="pos_\matchColumn" type="text" |
| 242 |
multiplicity="single" |
| 243 |
description= "Coordinates (as h m s, d m s or decimal degrees), |
| 244 |
or SIMBAD-resolvable object" tablehead="\tablehead"> |
| 245 |
</inputKey> |
| 246 |
<inputKey name="sr_\matchColumn" |
| 247 |
multiplicity="single" |
| 248 |
description="Search radius in arcminutes" |
| 249 |
unit="arcmin" |
| 250 |
tablehead="Search radius for \tablehead"> |
| 251 |
</inputKey> |
| 252 |
<phraseMaker> |
| 253 |
<setup> |
| 254 |
<code> |
| 255 |
from gavo.protocols import scs |
| 256 |
</code> |
| 257 |
</setup> |
| 258 |
<code><![CDATA[ |
| 259 |
ra, dec = scs.parseHumanSpoint(inPars["pos_\matchColumn"], |
| 260 |
"pos_\matchColumn") |
| 261 |
try: |
| 262 |
sr = float(inPars["sr_\matchColumn"])/60. |
| 263 |
except ValueError: # in case we're not running behind forms |
| 264 |
raise gavo.ValidationError("Not a valid float", "sr_\matchColumn") |
| 265 |
yield "%s <@ scircle(%%(%s)s, %%(%s)s)"%("\matchColumn", |
| 266 |
base.getSQLKey("pos", |
| 267 |
pgsphere.SPoint.fromDegrees(ra, dec), outPars), |
| 268 |
base.getSQLKey("sr", sr/180*math.pi, outPars)) |
| 269 |
]]></code> |
| 270 |
</phraseMaker> |
| 271 |
</condDesc> |
| 272 |
</STREAM> |
| 273 |
|
| 274 |
<STREAM id="coreDescs"> |
| 275 |
<doc><![CDATA[ |
| 276 |
This stream inserts three condDescs for SCS services on tables with |
| 277 |
pos.eq.(ra|dec).main columns; one producing the standard SCS RA, |
| 278 |
DEC, and SR parameters, another creating input fields for human |
| 279 |
consumption, and finally MAXREC. |
| 280 |
]]></doc> |
| 281 |
<condDesc original="//scs#humanInput"/> |
| 282 |
<condDesc original="//scs#protoInput"/> |
| 283 |
</STREAM> |
| 284 |
|
| 285 |
</resource> |