Debian Codegraph @

gavo/resources/inputs/__system__/ssap.rd

raw
1 <resource resdir="__system" schema="dc">
2 <meta name="creationDate">2010-10-07T13:00:00</meta>
3 <meta name="description">Table structures and definitions used
4 in building Simple Spectral Access (SSAP) services.</meta>
5 <meta name="subject">virtual-observatories</meta>
6
7 <STREAM id="base_columns">
8 <index columns="ssa_pubDID"/>
9
10 <!-- a table containing columns required for all SSA tables.
11
12 There is only minimal CoordSys metadata here; we assume
13 such information is conveyed via STC groups anyway. If that
14 should turn out to be not sufficient, we'll think again. -->
15
16 <stc>Position ICRS [ssa_location] Size "ssa_aperture" "ssa_aperture"
17 SpectralInterval "ssa_specstart" "ssa_specend"
18 Spectral "ssa_specmid" Size "ssa_specext"</stc>
19
20 <FEED source="//products#tablecols">
21 <EDIT ref="column[accref]" utype="ssa:Access.Reference"
22 ucd="meta.ref.url;meta.dataset"/>
23 <EDIT ref="column[mime]" utype="ssa:Access.Format"/>
24 <EDIT ref="column[accsize]" utype="ssa:Access.Size" ucd=""/>
25 </FEED>
26
27 <column name="ssa_dstitle" type="text" required="True"
28 utype="ssa:DataID.Title" ucd="meta.title;meta.dataset"
29 tablehead="Title" verbLevel="15"
30 description="A compact and descriptive designation of the dataset."/>
31 <column name="ssa_creatorDID" type="text"
32 utype="ssa:DataID.CreatorDID" ucd="meta.id"
33 tablehead="C. DID" verbLevel="15"
34 description="Dataset identifier assigned by the creator"/>
35 <column name="ssa_pubDID" type="text"
36 utype="ssa:Curation.PublisherDID"
37 ucd="meta.ref.ivoid"
38 tablehead="P. DID" verbLevel="15"
39 description="Dataset identifier assigned by the publisher"/>
40 <column name="ssa_cdate" type="timestamp"
41 utype="ssa:DataID.Date" ucd="time;meta.dataset"
42 tablehead="Proc. Date" verbLevel="15"
43 description="Processing/Creation date"
44 xtype="timestamp"/>
45 <column name="ssa_pdate" type="timestamp"
46 utype="ssa:Curation.Date"
47 tablehead="Pub. Date" verbLevel="15"
48 description="Date last published."
49 xtype="timestamp"/>
50 <column name="ssa_bandpass" type="text"
51 utype="ssa:DataID.Bandpass" ucd="instr.bandpass"
52 tablehead="Bandpass" verbLevel="15"
53 description="Bandpass (i.e., rough spectral location) of this dataset;
54 this should be the most appropriate term from the vocabulary
55 http://www.ivoa.net/rdf/messenger."/>
56 <column name="ssa_cversion" type="text"
57 utype="ssa:DataID.Version" ucd="meta.version;meta.dataset"
58 tablehead="C. Version" verbLevel="15"
59 description="Creator assigned version for this dataset (will be
60 incremented when this particular item is changed)."/>
61 <column name="ssa_targname" type="text" required="True"
62 utype="ssa:Target.Name" ucd="meta.id;src"
63 tablehead="Object" verbLevel="15"
64 description="Common name of object observed."/>
65 <column name="ssa_targclass" type="text"
66 utype="ssa:Target.Class" ucd="src.class"
67 tablehead="Ob. cls" verbLevel="15"
68 description="Object class (star, QSO,...; use Simbad object
69 classification http://simbad.u-strasbg.fr/simbad/sim-display?data=otypes
70 if at all possible)"/>
71 <column name="ssa_redshift"
72 utype="ssa:Target.Redshift" ucd="src.redshift"
73 tablehead="z" verbLevel="15"
74 description="Redshift of target object"/>
75 <column name="ssa_targetpos" type="spoint"
76 utype="ssa:Target.pos.spoint" ucd="pos.eq;src"
77 tablehead="Obj. pos" verbLevel="15"
78 description="Equatorial (ICRS) position of the target object."/>
79 <column name="ssa_snr"
80 ucd="stat.snr"
81 utype="ssa:Derived.SNR"
82 tablehead="SNR" verbLevel="15"
83 description="Signal-to-noise ratio estimated for this dataset"/>
84 <column name="ssa_location" type="spoint"
85 ucd="pos.eq"
86 utype="ssa:Char.SpatialAxis.Coverage.Location.Value"
87 verbLevel="5" tablehead="Location"
88 description="ICRS location of aperture center" unit="deg"/>
89 <column name="ssa_aperture"
90 unit="deg" ucd="phys.angSize;instr.fov"
91 utype="ssa:Char.SpatialAxis.Coverage.Bounds.Extent"
92 verbLevel="15" tablehead="Aperture"
93 description="Angular diameter of aperture"/>
94 <column name="ssa_dateObs" type="double precision"
95 unit="d"
96 utype="ssa:Char.TimeAxis.Coverage.Location.Value" ucd="time.epoch"
97 verbLevel="5" tablehead="Date Obs."
98 description="Midpoint of exposure (MJD)"
99 displayHint="type=humanDate"
100 xtype="mjd"/>
101 <column name="ssa_timeExt"
102 unit="s"
103 utype="ssa:Char.TimeAxis.Coverage.Bounds.Extent" ucd="time.duration"
104 verbLevel="5" tablehead="Exp. Time"
105 description="Exposure duration"/>
106 <column name="ssa_specmid"
107 unit="m" ucd="instr.bandpass"
108 utype="ssa:Char.SpectralAxis.Coverage.Location.Value"
109 verbLevel="15" tablehead="Mid. Band"
110 description="Midpoint of region covered in this dataset"/>
111 <column name="ssa_specext"
112 unit="m" ucd="instr.bandwidth"
113 utype="ssa:Char.SpectralAxis.Coverage.Bounds.Extent"
114 verbLevel="15" tablehead="Bandwidth"
115 description="Width of the spectrum"/>
116 <column name="ssa_specstart"
117 unit="m" ucd="em.wl;stat.min"
118 utype="ssa:Char.SpectralAxis.Coverage.Bounds.Start"
119 verbLevel="15" tablehead="Band start"
120 description="Lower value of spectral coordinate"/>
121 <column name="ssa_specend"
122 unit="m" ucd="em.wl;stat.max"
123 utype="ssa:Char.SpectralAxis.Coverage.Bounds.Stop"
124 verbLevel="15" tablehead="Band end"
125 description="Upper value of spectral coordinate"/>
126 </STREAM>
127
128 <!-- The SSA metadata is huge, and many arrangements are conceivable.
129 To come up with some generally useful interface definitions, I'll
130 first define a table for a "homogeneous" data collection, the ssahcd
131 case. There's also a core for this. -->
132
133 <STREAM id="hcd_fields">
134 <!-- the SSA (HCD) fields for an instance table -->
135 <FEED source="//ssap#base_columns"/>
136 <column name="ssa_length" type="integer"
137 utype="ssa:Dataset.Length" tablehead="Length"
138 verbLevel="5"
139 description="Number of points in the spectrum">
140 <values nullLiteral="-1"/>
141 </column>
142 </STREAM>
143
144 <STREAM id="ssa_allpars">
145 <doc>Fixed parameters of all SSA tables</doc>
146 <param name="ssa_model" type="text" required="True"
147 utype="ssa:Dataset.DataModel"
148 tablehead="Model"
149 description="Data model name and version">Spectrum-1.0</param>
150 <param name="ssa_csysName" type="text" required="True"
151 utype="ssa:CoordSys.SpaceFrame.Name"
152 tablehead="Sys" verbLevel="15"
153 description="System RA and Dec are given in"
154 >ICRS</param>
155 <param name="ssa_timeSI" type="text"
156 utype="ssa:Dataset.TimeSI"
157 tablehead="[Time]"
158 description="Time conversion factor in Osuna-Salgado convention."
159 >\timeSI</param>
160
161 <param name="ssa_spectralSI" type="text"
162 utype="ssa:Dataset.SpectralSI"
163 tablehead="[Spectral]"
164 description="Spectral conversion factor in Osuna-Salgado convention"
165 >\spectralSI</param>
166 <param name="ssa_spectralucd" type="text" required="True"
167 utype="ssa:Char.SpectralAxis.Ucd" ucd="meta.ucd"
168 tablehead="UCD(spectral)" verbLevel="15"
169 description="UCD of the spectral column in the spectra served;
170 when you have wavelengths,
171 use em.wl for vacuum wavelengths, em.wl;obs.atmos for
172 air wavelengths.">\spectralUCD</param>
173 <param name="ssa_spectralunit" type="text" required="True"
174 utype="ssa:Char.SpectralAxis.Unit" ucd="meta.unit"
175 tablehead="unit(spectral)" verbLevel="15"
176 description="Unit of the spectral column">\magicEmpty{\spectralUnit}</param>
177
178 <param name="ssa_fluxSI" type="text"
179 utype="ssa:Dataset.FluxSI"
180 tablehead="[Flux]"
181 description="Flux/magnitude conversion factor in Osuna-Salgado convention"
182 >\fluxSI</param>
183 <param name="ssa_fluxucd" type="text" required="True"
184 utype="ssa:Char.FluxAxis.Ucd" ucd="meta.ucd"
185 tablehead="UCD(flux)" verbLevel="15"
186 description="UCD of the flux column">\magicEmpty{\fluxUCD}</param>
187 <param name="ssa_fluxunit" type="text" required="True"
188 utype="ssa:Char.FluxAxis.Unit" ucd="meta.unit"
189 tablehead="unit(flux)" verbLevel="15"
190 description="Unit of the flux column">\magicEmpty{\fluxUnit}</param>
191 </STREAM>
192
193 <STREAM id="hcd_outpars">
194 <doc>The parameters table for an SSA (HCD) result. The definition
195 of the homogeneous in HCD is that all these parameters are
196 constant for all datasets within a table ("collection").
197
198 These params are supposed to be filled using mixin parameters
199 (or stream parameters, but the available parameters are documented
200 in the hcd mixin). Some params are hardcoded to NULL right now;
201 they can easily be added to hcd's parameters if someone needs them.
202
203 ssa_model and ssa_dstype cannot be changed right now. Changing
204 them would probably not make much sense since they reflect
205 what's in this RD.</doc>
206
207 <LFEED source="ssa_allpars"/>
208 <param name="ssa_dstype" type="text"
209 utype="ssa:Dataset.Type"
210 tablehead="Data type"
211 description="Type of data (spectrum, time series, etc)"
212 >Spectrum</param>
213 <param name="ssa_publisher" type="text" required="True"
214 utype="ssa:Curation.Publisher" ucd="meta.curation"
215 tablehead="Publisher" verbLevel="15"
216 description="Publisher of the datasets included here.">\publisher</param>
217 <param name="ssa_creator" type="unicode"
218 utype="ssa:DataID.Creator"
219 tablehead="Creator" verbLevel="15"
220 description="Creator of the datasets included here.">\creator</param>
221 <param name="ssa_collection" type="text"
222 utype="ssa:DataID.Collection"
223 tablehead="Collection" verbLevel="15"
224 description="A short handle naming the collection this spectrum
225 belongs to."
226 >\collection</param>
227 <param name="ssa_instrument" type="text"
228 utype="ssa:DataID.Instrument" ucd="meta.id;instr"
229 tablehead="Instrument" verbLevel="15"
230 description="Instrument or code used to produce these datasets"
231 >\instrument</param>
232 <param name="ssa_datasource" type="text"
233 utype="ssa:DataID.DataSource"
234 tablehead="Src" verbLevel="15"
235 description="Method of generation for the data (one of
236 survey, pointed, theory, custom, artificial)."
237 >\datasource</param>
238 <param name="ssa_creationtype" type="text"
239 utype="ssa:DataID.CreationType"
240 tablehead="Using" verbLevel="15"
241 description="Process used to produce the data (archival, cutout,
242 filtered, mosaic, projection, spectralExtraction, or catalogExtraction)"
243 >\creationType</param>
244 <param name="ssa_reference" type="text"
245 utype="ssa:Curation.Reference" ucd="meta.bib.bibcode"
246 tablehead="Ref." verbLevel="15"
247 description="URL or bibcode of a publication describing this data."
248 >\reference</param>
249 <param name="ssa_fluxStatError"
250 unit="\fluxUnit" utype="ssa:Char.FluxAxis.Accuracy.StatError"
251 ucd="stat.error;phot.flux.density;em"
252 tablehead="Err. flux" verbLevel="15"
253 description="Statistical error in flux"
254 ><values nullLiteral="NaN"/>\statFluxError</param>
255 <param name="ssa_fluxSysError"
256 utype="ssa:Char.FluxAxis.Accuracy.SysError"
257 unit="\fluxUnit" ucd="stat.error.sys;phot.flux.density;em"
258 tablehead="Sys. Err flux" verbLevel="15"
259 description="Systematic error in flux"
260 ><values nullLiteral="NaN"/>\sysFluxError</param>
261 <param name="ssa_fluxcalib" type="text"
262 utype="ssa:Char.FluxAxis.Calibration"
263 tablehead="Calib Flux" verbLevel="15"
264 description="Type of flux calibration (ABSOLUTE, CALIBRATED, RELATIVE,
265 NORMALIZED, or UNCALIBRATED)."
266 >\fluxCalibration<values id="flux_calib_values" caseless="True">
267 <option>ABSOLUTE</option>
268 <option>CALIBRATED</option>
269 <option>RELATIVE</option>
270 <option>NORMALIZED</option>
271 <option>UNCALIBRATED</option>
272 <option>ANY</option>
273 </values></param>
274 <param name="ssa_binSize"
275 unit="m" ucd="em.wl;spect.binSize"
276 utype="ssa:Char.SpectralAxis.Accuracy.BinSize"
277 tablehead="Spect. Bin" verbLevel="15"
278 description="Bin size in wavelength"/>
279 <param name="ssa_spectStatError"
280 unit="m" ucd="stat.error;em"
281 utype="ssa:Char.SpectralAxis.Accuracy.StatError"
282 tablehead="Err. Spect" verbLevel="15"
283 description="Statistical error in wavelength">
284 <values nullLiteral="NaN"/>\statSpectError</param>
285 <param name="ssa_spectSysError"
286 unit="m" ucd="stat.error.sys;em"
287 utype="ssa:Char.SpectralAxis.Accuracy.SysError"
288 tablehead="Sys. Err. Spect" verbLevel="15"
289 description="Systematic error in wavelength">
290 <values nullLiteral="NaN"/>\sysSpectError</param>
291 <param name="ssa_speccalib" type="text"
292 utype="ssa:Char.SpectralAxis.Calibration" ucd="meta.code.qual"
293 tablehead="Calib. Spect." verbLevel="15"
294 description="Type of wavelength calibration">\spectralCalibration</param>
295 <param name="ssa_specres"
296 unit="m" ucd="spect.resolution;em.wl"
297 utype="ssa:Char.SpectralAxis.Resolution"
298 tablehead="Spec. Res." verbLevel="15"
299 description="Resolution (in meters of wavelength) on the spectral axis"
300 ><values nullLiteral="NaN"/>\spectralResolution</param>
301 <param name="ssa_spaceError"
302 unit="deg" ucd="stat.error;pos.eq"
303 utype="ssa:Char.SpatialAxis.Accuracy.StatError"
304 tablehead="Err. Spc" verbLevel="15"
305 description="Statistical error in position"
306 ><values nullLiteral="NaN"/>\statSpaceError</param>
307 <param name="ssa_spaceCalib" type="text"
308 ucd="meta.code.qual"
309 utype="ssa:Char.SpatialAxis.Calibration"
310 tablehead="Calib. Spc" verbLevel="15"
311 description="Type of calibration in spatial coordinates"/>
312 <param name="ssa_spaceRes"
313 unit="deg" ucd="pos.angResolution"
314 utype="ssa:Char.SpatialAxis.Resolution"
315 tablehead="Res. Spc" verbLevel="15"
316 description="Spatial resolution of data"/>
317 </STREAM>
318
319 <STREAM id="mixc_morefields">
320 <doc>
321 The fields that a mixc table needs on top of what hcd has; for
322 simplicity, this is everything that hcd has as a parameter.
323 </doc>
324
325 <LFEED source="ssa_allpars"/>
326 <LOOP>
327 <codeItems>
328 defaults = {"type": "real", "unit": "__NULL__", "ucd": "__NULL__"}
329 for evType, name, pars in context.getById("hcd_outpars").iterEvents():
330 if evType=="start" and name=="param":
331 if (pars["name"].endswith("SI") # those remain params
332 or pars["name"] in ["ssa_csysName", "ssa_model"]):
333 continue
334 if (pars["name"] in ["ssa_spaceRes", "ssa_spaceCalib",
335 "ssa_spaceError"]):
336 # would anyone *ever* miss those?
337 continue
338 if pars["name"].endswith("unit") or pars["name"].endswith("ucd"):
339 # these must be parameters since they end up in the table
340 # metadata
341 continue
342 rec = {}
343 rec.update(defaults)
344 rec.update(pars)
345 rec["verbLevel"] = '15'
346 yield rec
347 </codeItems>
348 <events>
349 <column name="\name" type="\type"
350 utype="\utype" ucd="\ucd" unit="\unit"
351 tablehead="\tablehead"
352 description="\description"
353 verbLevel="\verbLevel"/>
354 </events>
355 </LOOP>
356 </STREAM>
357
358 <STREAM id="atomicCoords">
359 <doc>
360 A stream for form-based service's VOTables to include simple
361 RA and Dec rather than normal ssa_location.
362
363 SSA services get that from the core and don't need this.
364 </doc>
365 <outputField name="location_ra"
366 unit="deg" ucd="pos.eq.ra;meta.main"
367 utype="ssa:Char.SpatialAxis.Coverage.Location.Value.C1"
368 tablehead="RA" verbLevel="15"
369 select="degrees(long(ssa_location))"
370 displayHint="sf=7"/>
371 <outputField name="location_dec"
372 unit="deg" ucd="pos.eq.dec;meta.main"
373 utype="ssa:Char.SpatialAxis.Coverage.Location.Value.C2"
374 tablehead="Dec" verbLevel="15"
375 select="degrees(lat(ssa_location))"
376 displayHint="sf=7"/>
377 </STREAM>
378
379 <STREAM id="coreOutputAdditionals">
380 <!-- Fields added to the queried table def to make the core
381 output table. -->
382 <outputField name="ssa_score"
383 utype="ssa:Query.Score"
384 tablehead="Score" verbLevel="15"
385 select="0">
386 <description>A measure of how closely the record matches your
387 query. Higher numbers mean better matches.</description>
388 </outputField>
389 <FEED source="atomicCoords"/>
390 </STREAM>
391
392 <table id="instance" onDisk="False">
393 <meta name="description">A sample of SSA fields for referencing and such.
394 </meta>
395 <!-- think about whether we can trick refposition and timescale
396 in here -->
397 <FEED source="hcd_fields"/>
398 <FEED source="hcd_outpars" spectralUnit="" fluxUnit=""
399 publisher="junk" creator="junk" collection="" timeSI=""
400 spectralSI="" fluxSI="" instrument="junk" datasource="junk"
401 creationType="junk" reference="junk" fluxUCD="junk"
402 spectralUCD="junk" statFluxError="NaN" sysFluxError="NaN"
403 fluxCalibration="" statSpectError="NaN" sysSpectError="NaN"
404 spectralCalibration="" statSpaceError="NaN"
405 spectralResolution="NaN"/>
406 </table>
407
408 <procDef type="apply" id="setMeta">
409 <doc>
410 Sets metadata for an SSA data collection, including its
411 products definition.
412
413 Since this is only useful with the deprecated hcd and mixc mixins,
414 this should no longer be used.
415
416 The values are left in vars, so you need to do manual copying,
417 e.g., using idmaps="*", or, if you need to be more specific,
418 idmaps="ssa_*".
419 </doc>
420 <setup>
421 <par key="dstitle" late="True" description="a title for the data set
422 (e.g., instrument, filter, target in some short form; must be filled
423 in); ssa:DataID.Title"/>
424 <par key="creatorDID" late="True" description="id given by the
425 creator (leave out if not applicable); ssa:DataID.CreatorDID"
426 >None</par>
427 <par key="pubDID" late="True" description="Id provided by the
428 publisher (i.e., you); this is an opaque string and must be given;
429 ssa:Curation.PublisherDID"/>
430 <par key="cdate" late="True" description="date the file was
431 created (or processed; optional); this must be either a string
432 in ISO format, or you need to parse to a timestamp yourself;
433 ssa:DataID.Date">None</par>
434 <par key="pdate" late="True" description="date the file was
435 last published (in general, the default is fine); ssa:Curation.Date"
436 >datetime.datetime.utcnow()</par>
437 <par key="bandpass" late="True" description="bandpass (i.e., rough
438 spectral location) of this dataset; ssa:DataID.Bandpass"
439 >None</par>
440 <par key="cversion" late="True" description="creator assigned version
441 for this file (should be incremented when it is changed);
442 ssa:DataID.Version">None</par>
443 <par key="targname" late="True" description="common name of
444 the object observed; ssa:Target.Name">None</par>
445 <par key="targclass" late="True" description="object class (star,
446 QSO,...); ssa:Target.Class">None</par>
447 <par key="redshift" late="True" description="source redshift;
448 ssa:Target.Redshift">None</par>
449 <par key="snr" late="True" description="signal-to-noise ratio
450 estimated for this dataset; ssa:Derived.SNR">None</par>
451 <par key="alpha" late="True" description="right ascension of target
452 (ICRS degrees); ssa:Char.SpatialAxis.Coverage.Location.Value.C1"
453 >None</par>
454 <par key="delta" late="True" description="declination of target
455 (ICRS degrees); ssa:Char.SpatialAxis.Coverage.Location.Value.C2"
456 >None</par>
457 <par key="aperture" late="True" description="angular diameter of
458 aperture (expected in degrees);
459 ssa:Char.SpatialAxis.Coverage.Bounds.Extent">None</par>
460 <par key="dateObs" late="True" description="observation midpoint
461 (you can give a datetime, a string in iso format, a jd, or an mjd,
462 the latter two being told apart by comparing against 1e6)">None</par>
463 <par key="timeExt" late="True" description="exposure time
464 (in seconds); ssa:Char.TimeAxis.Coverage.Bounds.Extent">None</par>
465 <par key="specmid" late="True" description="(ignored; only present
466 for compatibility, computed from specstart and specend)"
467 >None</par>
468 <par key="specext" late="True" description="(ignored; only present
469 for compatibility, computed from specstart and specend)"
470 >None</par>
471 <par key="specstart" late="True" description="lower bound of
472 wavelength interval (in meters);
473 ssa:Char.SpectralAxis.Coverage.Bounds.Start">None</par>
474 <par key="specend" late="True" description="upper bound of
475 wavelength interval (in meters);
476 ssa:Char.SpectralAxis.Coverage.Bounds.Stop">None</par>
477 <par key="length" late="True" description="Number of samples
478 in the spectrum; ssa:Dataset.Length">None</par>
479 <code>
480 copiedKWs = ['dstitle', 'creatorDID', 'pubDID', 'cdate',
481 'pdate', 'bandpass', 'cversion', 'targname', 'targclass',
482 'redshift', 'snr', 'aperture', 'timeExt',
483 'specstart', 'specend', 'length']
484 </code>
485 </setup>
486 <code>
487 vars["ssa_dateObs"] = toMJD(dateObs)
488 userPars = locals()
489 for kw in copiedKWs:
490 vars["ssa_"+kw] = userPars[kw]
491 alpha = parseFloat(alpha)
492 delta = parseFloat(delta)
493 specstart = parseFloat(specstart)
494 specend = parseFloat(specend)
495
496 if specstart is not None and specend is not None:
497 vars["ssa_specext"] = specend-specstart
498 vars["ssa_specmid"] = (specend-specstart)/2
499
500 vars["ssa_region"] = vars["ssa_location"] = None
501 if alpha is not None and delta is not None:
502 vars["ssa_location"] = pgsphere.SPoint.fromDegrees(alpha, delta)
503 if aperture:
504 vars["ssa_region"] = pgsphere.SCircle.fromDALI(
505 [alpha, delta, aperture]).asPoly(6)
506 </code>
507 </procDef>
508
509 <procDef type="apply" id="setMixcMeta">
510 <doc>
511 Sets metadata for an SSA data set from mixed sources. This will
512 only work sensibly in cooperation with setMeta
513
514 Since //ssap#mixc is deprecated, there is no reason to use this
515 in new RDs.
516
517 As with setMeta, the values are left in vars; if you did as recommended
518 with setMeta, you'll have this covered as well.
519 </doc>
520 <setup>
521 <par key="dstype" late="True"
522 description="Type of data. The only defined value currently is
523 Spectrum, but you may get away with TimeSeries; ssa:Dataset.Type"
524 >"spectrum"</par>
525 <par key="publisher" late="True"
526 description="Publisher IVO; ssa:Curation.Publisher"
527 >"Take from RD"</par>
528 <par key="creator" late="True" description="Creator/Author"
529 >"Take from RD"</par>
530 <par key="collection" late="True" description="IOVA id of the originating
531 data collection (leave empty if you don't know what this
532 is about)">None</par>
533 <par key="instrument" late="True" description="Instrument or code
534 used to produce this dataset; ssa:DataID.Instrument"
535 >"Take from RD"</par>
536 <par key="datasource" late="True" alias="dataSource"
537 description="Generation type
538 (typically, one survey, pointed, theory, custom, artificial);
539 ssa:DataID.DataSource">None</par>
540 <par key="creationType" late="True" description="Process used to
541 produce the data (zero or more of archival, cutout, filtered,
542 mosaic, projection, spectralExtraction, catalogExtraction, concatenated
543 by commas); ssa:DataID.CreationType">None</par>
544 <par key="reference" late="True" description="URL or bibcode of
545 a publication describing this data.">"Take from RD"</par>
546
547 <par key="binSize" late="True" description="Bin size on the
548 spectral axis in m">None</par>
549 <par key="fluxStatError" late="True" description="Statistical
550 error for flux in units of fluxUnit">None</par>
551 <par key="spectStatError" late="True" description="Statistical
552 error for the spectral coordinate in m">None</par>
553 <par key="fluxSysError" late="True" description="Systematic
554 error for flux in units of fluxUnit">None</par>
555 <par key="spectSysError" late="True" description="Systematic
556 error for the spectral coordinate in m">None</par>
557
558 <par key="fluxCalib" late="True" description="Type of flux calibration
559 (one of ABSOLUTE, RELATIVE, NORMALIZED, or UNCALIBRATED);
560 ssa:Char.FluxAxis.Calibration">None</par>
561 <par key="specCalib" late="True" description="Type of wavelength
562 Calibration (one of ABSOLUTE, RELATIVE, NORMALIZED, or UNCALIBRATED);
563 ssa:Char.SpectralAxis.Calibration">None</par>
564 <par key="specres" late="True" description="Resolution on the
565 spectral axis; you must give this as FWHM wavelength in meters
566 here. This will default to binSize if not given;
567 ssa:Char.SpectralAxis.Resolution">None</par>
568 </setup>
569 <code>
570 inVars = locals()
571 for parName, metaName in [
572 ("publisher", "publisher"),
573 ("reference", "source"),
574 ("instrument", "instrument")]:
575 if inVars[parName]=="Take from RD":
576 vars["ssa_"+parName] = base.getMetaText(
577 rd, metaName, acceptSequence=False)
578 else:
579 vars["ssa_"+parName] = inVars[parName]
580
581 for copiedName in ["dstype", "collection", "datasource",
582 "creationType", "fluxCalib", "specCalib", "specres", "binSize"]:
583 vars["ssa_"+copiedName.lower()] = inVars[copiedName]
584
585 if vars["ssa_specres"] is None:
586 vars["ssa_specres"] = vars["ssa_binsize"]
587 </code>
588 </procDef>
589
590 <STREAM id="commonMixinParams">
591 <mixinPar key="fluxUnit" description="Flux unit used by the
592 spectra and in SSA char metadata. This must be a VOUnit string (use
593 a single blank if your spectrum is not calibrated)."
594 >__EMPTY__</mixinPar>
595 <mixinPar key="spectralUnit" description="Spectral unit used by the
596 spectra (SSA char metadata always is wavelength in meters).
597 This must be a VOUnit string (use a single blank if your
598 spectrum is not calibrated).">__EMPTY__</mixinPar>
599
600 <mixinPar key="timeSI" description="SI conversion factor for times
601 in Osuna-Salgado convention; ssa:DataSet.TimeSI (you probably want
602 to leave this empty)">__NULL__</mixinPar>
603 <mixinPar key="fluxSI" description="SI conversion factor for fluxes
604 in the spectrum instance (not the SSA metadata) in Osuna-Salgado
605 convention; ssa:Dataset.FluxSI (you probably want to leave this
606 empty)">__NULL__</mixinPar>
607 <mixinPar key="spectralSI" description="SI conversion factor of frequency
608 or wavelength in the spectrum instance (not the SSA metadata, they
609 are all in meters); ssa:Dataset.SpectralSI (you probably want to
610 leave this empty)">__NULL__</mixinPar>
611 <mixinPar key="spectralUCD" description="ucd of the spectral column, like
612 em.freq or em.energy; default is wavelength; ssa:Char.SpectralAxis.Ucd"
613 >em.wl</mixinPar>
614 <mixinPar key="fluxUCD" description="ucd of the flux column, like
615 phot.count, phot.flux.density, etc. Default is for flux over
616 wavelength; ssa:Char.FluxAxis.Ucd">phot.flux.density;em.wl</mixinPar>
617
618 <mixinPar key="refposition"
619 description="Reference position for times given in this table.
620 Choose from http://www.ivoa.net/rdf/refposition, leave as UNKNOWN
621 if in doubt.">UNKNOWN</mixinPar>
622 <mixinPar key="timescale"
623 description="Timescale for times given in this table.
624 Choose from http://www.ivoa.net/rdf/timescale. If in doubt,
625 leaving this at TT is probably good enough for discovery."
626 >TT</mixinPar>
627 </STREAM>
628
629 <mixinDef id="hcd">
630 <doc><![CDATA[
631 Deprecated. use `the //ssap#view mixin`_ instead.
632
633 This mixin is for "homogeneous" data collections, where homogeneous
634 means that all values in hcd_outpars are constant for all datasets
635 in the collection. This is usually the case if they all come
636 from one instrument.
637
638 Rowmakers for tables using this mixin should use the `//ssap#setMeta`_
639 proc application.
640
641 Do not forget to call the `//products#define`_ row filter in grammars
642 feeding tables mixing this in. At the very least, you need to
643 say::
644
645 <rowfilter procDef="//products#define">
646 <bind name="table">"mySchema.myTableName"</bind>
647 </rowfilter>
648 ]]></doc>
649
650 <FEED source="commonMixinParams"/>
651
652 <mixinPar key="creator" description="Creator designation;
653 ssa:DataID.Creator">__NULL__</mixinPar>
654 <mixinPar key="publisher" description="Publisher IVO (by default
655 taken from the DC config); ssa:Curation.Publisher"
656 >\metaString{publisherID}{\metaString{publisher}}</mixinPar>
657 <mixinPar key="instrument" description="Instrument or code used to produce
658 these datasets; ssa:DataID.Instrument">__NULL__</mixinPar>
659 <mixinPar key="datasource" alias="dataSource"
660 description="Generation type (typically, one
661 survey, pointed, theory, custom, artificial); ssa:DataID.DataSource"
662 >__NULL__</mixinPar>
663 <mixinPar key="creationType" description="Process used to
664 produce the data (zero or more of archival, cutout, filtered,
665 mosaic, projection, spectralExtraction, catalogExtraction);
666 ssa:DataID.CreationType">__NULL__</mixinPar>
667 <mixinPar key="reference" description="URL or bibcode of a
668 publication describing this data; ssa:Curation.Reference"
669 >__NULL__</mixinPar>
670 <mixinPar key="statFluxError" description="Statistical error in
671 flux; ssa:Char.FluxAxis.Accuracy.StatError"
672 >__NULL__</mixinPar>
673 <mixinPar key="sysFluxError" description="Systematic error in flux;
674 ssa:Char.FluxAxis.Accuracy.SysError"
675 >__NULL__</mixinPar>
676 <mixinPar key="fluxCalibration" description="Type of flux calibration
677 (one of ABSOLUTE, RELATIVE, NORMALIZED, or UNCALIBRATED);
678 ssa:Char.FluxAxis.Calibration"/>
679 <mixinPar key="statSpectError"
680 description="Statistical error in wavelength (units of specralSI);
681 ssa:Char.SpectralAxis.Accuracy.StatError">__NULL__</mixinPar>
682 <mixinPar key="sysSpectError" description="Systematic error in wavelength
683 (in m); ssa:Char.SpectralAxis.Accuracy.SysError"
684 >__NULL__</mixinPar>
685 <mixinPar key="spectralCalibration" description="Type of wavelength
686 Calibration (one of ABSOLUTE, RELATIVE, NORMALIZED, or UNCALIBRATED);
687 ssa:Char.SpectralAxis.Calibration">__NULL__</mixinPar>
688 <mixinPar key="statSpaceError" description="Statistical error in position
689 in degrees;
690 ssa:Char.SpatialAxis.Accuracy.StatError"
691 >__NULL__</mixinPar>
692 <mixinPar key="collection" description="ivo id of the originating
693 collection; ssa:DataID.Collection">__NULL__</mixinPar>
694 <mixinPar key="spectralResolution"
695 description="Resolution on the spectral axis; you must give this
696 as FWHM wavelength in meters here. Approximate as necessary;
697 ssa:Char.SpectralAxis.Resolution">NaN</mixinPar>
698
699 <FEED source="//products#hackProductsData"/>
700 <events>
701 <dm>
702 (votable:Coords) {
703 time: {
704 frame: {
705 timescale: \timescale
706 refPosition: \refposition
707 time0: 2400000.5
708 }
709 location: @ssa_dateObs
710 }
711 }
712 </dm>
713
714 <index columns="ssa_pubDID"/>
715 <index columns="ssa_targname"/>
716 <index columns="ssa_location" method="GIST"/>
717 <FEED source="//products#tableRules"/>
718 <LFEED source="//ssap#hcd_fields"/>
719 <LFEED source="//ssap#hcd_outpars"/>
720 </events>
721
722 <processEarly>
723 <code>
724 # these secret attributes are used by the sdm-instance
725 substrate.from_mixin_spectral_unit = mixinPars["spectralUnit"]
726 substrate.from_mixin_spectral_ucd = mixinPars["spectralUCD"]
727 substrate.from_mixin_flux_unit = mixinPars["fluxUnit"]
728 substrate.from_mixin_flux_ucd = mixinPars["fluxUCD"]
729 </code>
730 </processEarly>
731 </mixinDef>
732
733
734 <mixinDef id="mixc">
735 <doc><![CDATA[
736 Deprecated. use `the //ssap#view mixin`_ instead.
737
738 This mixin provides the columns and params for a common SSA service.
739
740 Rowmakers for tables using this mixin should use the `//ssap#setMeta`_
741 and the `//ssap#setMixcMeta`_ proc applications.
742
743 There are some limitations to the variability; in particular, all
744 spectra must have the same types of axes (i.e., frequency, wavelength,
745 or energy) with identical units. If you don't have that,
746 either leave the respective metadata empty or homogenize it
747 before ingestion.
748
749 Do not forget to call the `//products#define`_ row filter in grammars
750 feeding tables mixing this in. At the very least, you need to
751 say::
752
753 <rowfilter procDef="//products#define">
754 <bind name="table">"schema.table"</bind>
755 </rowfilter>
756 ]]></doc>
757
758 <FEED source="commonMixinParams"/>
759
760 <FEED source="//products#hackProductsData"/>
761 <events>
762 <dm>
763 (votable:Coords) {
764 time: {
765 frame: {
766 timescale: \timescale
767 refPosition: \refposition
768 time0: 2400000.5
769 }
770 location: @ssa_dateObs
771 }
772 }
773 </dm>
774
775 <index columns="ssa_pubDID"/>
776 <index columns="ssa_targname"/>
777 <index columns="ssa_location" method="GIST"/>
778 <FEED source="//products#tableRules"/>
779 <LFEED source="//ssap#hcd_fields"/>
780 <LFEED source="//ssap#mixc_morefields"/>
781 </events>
782
783 <processEarly>
784 <code>
785 # these secret attributes are used by the sdm-instance
786 substrate.from_mixin_spectral_unit = mixinPars["spectralUnit"]
787 substrate.from_mixin_spectral_ucd = mixinPars["spectralUCD"]
788 substrate.from_mixin_flux_unit = mixinPars["fluxUnit"]
789 substrate.from_mixin_flux_ucd = mixinPars["fluxUCD"]
790 </code>
791 </processEarly>
792 </mixinDef>
793
794
795 <mixinDef id="view">
796 <doc><![CDATA[
797 This mixin produces an SSA-ready relation as a view.
798
799 The idea is that you import your spectra into a table suitable for your
800 particular data collection (but mixing in `//products#define`_). You
801 then fill the columns for an SSA response giving in each mixin parameter
802 here either with a column reference (as a simple column name) or with a
803 SQL literals (put strings into single quotes – sourcetable is the
804 exception here). Save typing by having the final column names
805 in the source table and using the ``copiedcolumns`` mixin par.
806
807 If you have positions for your spectra, you probably want to also mix in
808 `the //ssap#plainlocation mixin`_ in the original table in order to have
809 indexed positions in a way suitable for SSA queries.
810
811 In general, you will have to generate indices on the source table;
812 postgres doesn't support indices on views. If you can't use the
813 plainlocation mixin, please not that the the SSA engine expects
814 spoints as the location (and these would be indexed like
815 <index columns="loc_col" method="GIST"/>).
816
817 The mixin will automatically create an index over whatever you
818 give for ssa_pubDID (if you give something).
819 ]]></doc>
820
821 <mixinPar key="sourcetable" description="Reference to the table
822 to build the view upon (i.e., the value of its id attribute).
823 This mixin can only build onto a single table. To make an
824 SSA table based on a join of multiple underlying table, define
825 an intermediate table with a viewStatement of its own and use
826 that as sourcetable."/>
827 <mixinPar key="materialize" description="Set to True to
828 make this a materialized view. For smallish tables, that
829 is a reasonable thing to do that generally simplifies the handling
830 a bit. On the other hand, the view will no longer follow the
831 underlying tables.">False</mixinPar>
832 <mixinPar key="copiedcolumns" description="rowmaker/idmaps-like list of
833 strings with column names or shell patterns to copy from sourcetable.
834 These columns will automatically be taken over in the view.
835 SSA columns taken over in this way *cannot* be overridden in
836 mixin parameters; the mandatory mixin parameters ssa_spectralunit
837 and ssa_fluxcalib have to be given (with ignored values) even
838 if they are in copiedcolumns.">__EMPTY__</mixinPar>
839
840 <mixinPar key="refposition"
841 description="Reference position for times given in this table.
842 Choose from http://www.ivoa.net/rdf/refposition, leave as UNKNOWN
843 if in doubt.">UNKNOWN</mixinPar>
844 <mixinPar key="timescale"
845 description="Timescale for times given in this table.
846 Choose from http://www.ivoa.net/rdf/timescale. If in doubt,
847 leaving this at TT is probably good enough for discovery."
848 >TT</mixinPar>
849
850 <mixinPar key="ssa_region" description="A region covered by the
851 observation for this spectrum; this will be ``ssa_region`` when
852 you mix //ssap#simpleCoverage into the original table. You'll
853 probably want to leave this at the default otherwise."
854 >not given</mixinPar>
855 <mixinPar key="customcode" description="A SQL fragment with extra
856 column definitions to go into the view. This must start with
857 a comma (because it's going to be appended to the select clause)."
858 >__EMPTY__</mixinPar>
859 <mixinPar key="whereclause" description="A SQL fragment that
860 fits after the source table (typically, a WHERE clause). Use
861 this if you only want a subset of the original table to be
862 visible through SSAP.">__EMPTY__</mixinPar>
863 <LOOP>
864 <codeItems>
865 VIEWPAR_DEFAULTS = {
866 # maps view column names to defaults for the mixin
867 "accref": "accref",
868 "owner": "owner",
869 "embargo": "embargo",
870 "mime": "mime",
871 "accsize": "accsize",
872 "ssa_aperture": "NULL",
873 "ssa_bandpass": "NULL",
874 "ssa_collection": "NULL",
875 "ssa_creationtype":
876 "\\sqlquote{\\metaString{ssap.creationType}{unknown}}",
877 "ssa_csysName": "'ICRS'",
878 "ssa_datasource":
879 "\\sqlquote{\\metaString{ssap.dataSource}{unknown}}",
880 "ssa_dateObs": "NULL",
881 "ssa_dstitle": "NULL",
882 "ssa_dstype": "'spectrum'",
883 "ssa_fluxcalib": "",
884 "ssa_fluxucd": "'phot.flux.density;em.wl'",
885 "ssa_instrument": "\\sqlquote{\\metaString{instrument}{unknown}}",
886 "ssa_length": "NULL",
887 "ssa_location": "NULL",
888 "ssa_model": "'Spectrum-1.0'",
889 "ssa_pdate": "\\sqlquote{\\today}",
890 "ssa_publisher": "\\sqlquote{\\metaString{publisher}{unknown}}",
891 "ssa_pubDID": "\\sql_standardPubDID",
892 "ssa_reference": "\\sqlquote{\\metaString{source}{unknown}}",
893 "ssa_specres": "NULL",
894 "ssa_spectralucd": "'em.wl;obs.atmos'",
895 "ssa_spectralunit": "",
896 "ssa_specmid": "(ssa_specend+ssa_specstart)/2",
897 "ssa_specext": "(ssa_specend-ssa_specstart)",
898 }
899
900 DESCRIPTION_OVERRIDES = {
901 "ssa_binSize": "Size of the typical spectral bin in meters"
902 " of wavelength.",
903 "ssa_cdate": "Dataset creation date as a datetime",
904 "ssa_pdate": "Date of (last) publication as a datetime",
905 "ssa_dataObs": "MJD of the midpoint of the exposure",
906 "ssa_fluxSI": "It's safe to ignore this.",
907 "ssa_timeSI": "It's safe to ignore this.",
908 "ssa_spectralSI": "It's safe to ignore this.",
909 "ssa_fluxunit": "Unit of the flux column in the dataset. This"
910 " is also the unit for the ssa_flux*Error columns (and thus"
911 " better had not change between rows).",
912 "ssa_spectralunit": "Unit of the flux column in the dataset"
913 " (e.g., 'Angstrom'). This is also the unit for the"
914 " ssa_spectral*Error columns (and thus better had not"
915 " change between rows).",
916 "ssa_location": "You probably don't want to manually"
917 " handle this. Use `the //ssap#plainlocation mixin`_"
918 " on your metadata table instead and write ssa_location here.",
919 "ssa_region": "You probably don't want to manually"
920 " handle this. Use `the /ssap#simpleCoverage mixin`_"
921 " on your metadata table instead.",
922 "ssa_targetpos": "Position of the intended target of the"
923 " observation. You don't usually need to give this."
924 " if you do, you probably want to write"
925 " pgsphere.SPoint.fromDegrees(targ_ra, targ_dec)",
926 }
927
928 from gavo.protocols import ssap
929 for c in ssap.iterViewColumns(context):
930 yield {"name": c.name,
931 "description": DESCRIPTION_OVERRIDES.get(c.name, c.description),
932 "default": VIEWPAR_DEFAULTS.get(c.name, "NULL")}
933 </codeItems>
934 <events>
935 <mixinPar key="\name" description="\description">\default</mixinPar>
936 </events>
937 </LOOP>
938
939 <processEarly>
940 <setup imports="collections, fnmatch, gavo.adql, gavo.rscdef, weakref,
941 gavo.rscdef.column.makeOptionsFromDist">
942 <code>
943 valueExpression = adql.getRawGrammar()[0]["valueExpression"]
944
945 def getCopiedColumns(copiedColumnsSpec, baseTable):
946 """returns a sequence for columns in baseTable matching
947 copiedColumnsSpec.
948
949 copiedColumnsSpec has comma-separated shell patterns as in
950 rowmaker/@idmaps.
951
952 Refactoring this and rscdef.rmkdef.RowmakerDef._resolveIdmaps
953 is probably not worth it.
954 """
955 baseNames = [c.key for c in baseTable]
956 matchingNames = []
957 for pat in [s.strip() for s in copiedColumnsSpec.split(",")]:
958 matchingNames.extend(fnmatch.filter(baseNames, pat))
959
960 # if a column has matched multiple times, it will
961 # be returned multiple times; since later occurrences
962 # overwrite earlier ones in tables, that shouldn't hurt.
963 return [baseTable.getColumnByName(n)
964 for n in matchingNames]
965
966 # Change product table column utypes; this is always universally
967 # necessary because these columns typically come from sourcetable
968 # and there from //products#tablecols. And where's not necessary
969 # it certainly doesn't hurt either.
970 UTYPE_OVERRIDES = {
971 "accref": ("ssa:Access.Reference", "meta.ref.url;meta.dataset"),
972 "mime": ("ssa:Access.Format", "meta.code.mime"),
973 "accsize": ("ssa:Access.Size", "")}
974
975 def applyOverrides(col):
976 if col.name in UTYPE_OVERRIDES:
977 utype, ucd = UTYPE_OVERRIDES[col.name]
978 return col.change(utype=utype, ucd=ucd)
979 return col
980
981 def nullToEmpty(val):
982 return "" if val.lower()=="null" else val
983
984 def makeOptionsForConstant(sqlLit, col):
985 """sets col's values to sqlLit's string value if it is
986 a string literal.
987
988 This is mainly cosmetics for VOSI tablesets, where we don't
989 want *calib columns to oddly stick out with a lot of
990 irrelevant options.
991 """
992 # better say nothing than bleed out non-expanded
993 # macros
994 if '\\\\' in sqlLit:
995 return
996
997 if col.type=="text" and utils.isSQLTextLiteral(sqlLit):
998 if col.values is None:
999 col.values = base.makeStruct(rscdef.Values, parent_=col)
1000 col.values.options = makeOptionsFromDist({
1001 sqlLit.strip()[1:-1].replace("''", "'"): 1})
1002 col.values.actual = True
1003 </code>
1004 </setup>
1005 <code>
1006 from gavo.protocols import ssap
1007 substrate.viewPieces = collections.OrderedDict()
1008
1009 for c in ssap.iterViewColumns(context):
1010 substrate.feedObject("column", applyOverrides(c))
1011
1012 val = mixinPars[c.name]
1013 if '\\\\' not in val:
1014 # this is *not* a security feature (if you can run this
1015 # mixin, you can run SQL through the viewStatement anyway).
1016 # This is just so you get get perhaps more useful error messages
1017 # in some cases.
1018 try:
1019 _ = valueExpression.parseString(val, parseAll=True)
1020 except base.ParseException:
1021 raise base.StructureError("Mixin par %s=%s does not match SQL"
1022 " valueExpression."%(c.name, val),
1023 hint="ssap#view parameters are in general put literally"
1024 " into a view declaration and hence must be valid SQL."
1025 " What you put in here is not recognised by DaCHS'"
1026 " ADQL parser. If you are sure postgres will swallow"
1027 " it, prefix it with backslash-+ to make DaCHS accept it, too.")
1028 substrate.viewPieces[c.name] = "(%s)::%s AS %s"%(
1029 val, base.sqltypeToPG(c.type), c.name)
1030
1031 makeOptionsForConstant(val, c)
1032
1033 # ssa_region is a local addition (yet) and can't be taken
1034 # from ssap#instance.
1035 if mixinPars["ssa_region"]!="not given":
1036 substrate.feedObject("column",
1037 MS(rscdef.Column, name="ssa_region",
1038 type="spoly", tablehead="Coverage",
1039 description="Rough coverage based on location and aperture",
1040 verbLevel=30))
1041 substrate.viewPieces["ssa_region"] = (
1042 "(%s)::spoly AS ssa_region"%mixinPars["ssa_region"])
1043
1044 # Copy over columns from the source table (these will overwrite
1045 # stuff from ssap#instance)
1046 sourceTable = base.resolveId(
1047 context, mixinPars["sourcetable"], forceType=rscdef.TableDef)
1048 for c in getCopiedColumns(mixinPars["copiedcolumns"], sourceTable):
1049 substrate.feedObject("column", applyOverrides(c))
1050 substrate.viewPieces[c.name] = "(%s)::%s AS %s"%(
1051 c.name, base.sqltypeToPG(c.type), c.name)
1052
1053 # the source table almost always needs an index we can use
1054 # for our pubdids, so just create it.
1055 if mixinPars["ssa_pubDID"]:
1056 sourceTable.feedObject("index",
1057 base.makeStruct(rscdef.DBIndex,
1058 columns=["ssa_pubDID"],
1059 content_="(%s)"%mixinPars["ssa_pubDID"],
1060 name="obscore_%s_did_index"%substrate.id))
1061
1062 # these secret attributes are used by the sdm-instance
1063 substrate.from_mixin_spectral_unit = nullToEmpty(
1064 mixinPars["ssa_spectralunit"]).strip("'")
1065 substrate.from_mixin_spectral_ucd = nullToEmpty(
1066 mixinPars["ssa_spectralucd"]).strip("'")
1067 substrate.from_mixin_flux_unit = nullToEmpty(
1068 mixinPars["ssa_fluxunit"]).strip("'")
1069 substrate.from_mixin_flux_ucd = nullToEmpty(
1070 mixinPars["ssa_fluxucd"]).strip("'")
1071 </code>
1072 </processEarly>
1073
1074 <processLate>
1075 <code>
1076 # Now override view definitions for columns the substrate
1077 # got from the source table.
1078 sourceTable = base.resolveId(
1079 context, mixinPars["sourcetable"])
1080
1081 for col in substrate.columns:
1082 if col.name in sourceTable:
1083 substrate.viewPieces[col.name] = "%s::%s"%(
1084 col.name, base.sqltypeToPG(col.type))
1085
1086 if base.parseBooleanLiteral(mixinPars["materialize"]):
1087 materialization = "MATERIALIZED"
1088 else:
1089 materialization = ""
1090
1091 substrate.viewStatement = substrate.viewStatement.replace(
1092 "__VIEW_DEF_LINES__", ",\n".join(substrate.viewPieces.values())
1093 ).replace(
1094 "__SOURCETABLE_NAME__", sourceTable.getQName()
1095 ).replace(
1096 "__MATERIALIZATION__", materialization
1097 ).replace(
1098 "__COL_NAMES__", ", ".join(c.name for c in substrate))
1099 </code>
1100 </processLate>
1101
1102 <events>
1103 <onDisk>True</onDisk>
1104 <dm>
1105 (votable:Coords) {
1106 time: {
1107 frame: {
1108 timescale: \timescale
1109 refPosition: \refposition
1110 time0: 2400000.5
1111 }
1112 location: @ssa_dateObs
1113 }
1114 }
1115 </dm>
1116
1117 <viewStatement>
1118 CREATE __MATERIALIZATION__ VIEW \\curtable AS (
1119 SELECT __COL_NAMES__ FROM (
1120 SELECT
1121 __VIEW_DEF_LINES__ \customcode
1122 FROM __SOURCETABLE_NAME__
1123 \whereclause) AS internal_ssa_view)
1124 </viewStatement>
1125 </events>
1126
1127 <lateEvents passivate="True">
1128 <FEED
1129 source="//procs#declare-indexes-from"
1130 sourceTables="\sourcetable"/>
1131 </lateEvents>
1132 </mixinDef>
1133
1134 <procDef id="parablePQLPar" type="phraseMaker">
1135 <doc>A procDef for condDescs that may match against table
1136 params *or* table columns, depending on where consCol is found.
1137 </doc>
1138 <setup>
1139 <par name="consCol" description="Name of the database column
1140 constrained by the input value."/>
1141 <par name="parClass" description="Identifier of a PQLPar
1142 (sub)class that is used to parse the incoming value."/>
1143 <code>
1144 from gavo import rscdef
1145 </code>
1146 </setup>
1147 <code>
1148 key = inputKeys[0].name
1149 val = inPars.get(key, None)
1150 if val is None or val.lower()=="any":
1151 return
1152 parsed = parClass.fromLiteral(val, key)
1153
1154 valueSource = core.queriedTable.getByName(consCol)
1155 if isinstance(valueSource, rscdef.Param):
1156 if (valueSource.value is not None
1157 and not parsed.covers(valueSource.value)):
1158 yield '1!=1'
1159 else:
1160 yield parsed.getSQL(consCol, outPars)
1161 </code>
1162 </procDef>
1163
1164 <STREAM id="hcd_condDescs">
1165 <doc>
1166 This stream defines the condDescs for an SSA service based on
1167 one of the mixins defined here.
1168 </doc>
1169 <condDesc id="coneCond" combining="True" joiner="AND">
1170 <!-- condCond is combining to let the client specify SIZE but
1171 not POS (as splat does); pql#coneParameter can handle that. -->
1172 <inputKey name="POS" type="text" description="ICRS position of target
1173 object" unit="deg" std="True" multiplicity="single"
1174 utype="ssa:Char.SpatialAxis.Coverage.Location.Value"/>
1175 <inputKey name="SIZE" description="Size of the region of
1176 interest around POS" std="True" multiplicity="single"
1177 unit="deg"
1178 utype="ssa:Char.SpatialAxis.Coverage.Bounds.Extent"/>
1179 <phraseMaker procDef="//pql#coneParameter">
1180 <bind name="posCol">"ssa_location"</bind>
1181 </phraseMaker>
1182 </condDesc>
1183
1184 <condDesc id="bandCond">
1185 <inputKey name="BAND" type="text" description="Wavelength (range)
1186 of interest (or symbolic bandpass names)" unit="m"
1187 multiplicity="single"
1188 std="True" utype="ssa:DataId.Bandpass"/>
1189 <phraseMaker>
1190 <code>
1191 key = inputKeys[0].name
1192 lit = inPars.get(key, None)
1193 if lit is None:
1194 return
1195 try:
1196 ranges = pql.PQLFloatPar.fromLiteral(lit, key)
1197 if ranges is None: # null string
1198 return
1199 yield ranges.getSQLForInterval(
1200 "ssa_specstart", "ssa_specend", outPars)
1201 except base.LiteralParseError:
1202 # As float ranges, things didn't work out. Try band names ("V")
1203 # and bail out if unsuccessful.
1204 yield pql.PQLPar.fromLiteral(lit, key).getSQL(
1205 "ssa_bandpass", outPars)
1206 </code>
1207 </phraseMaker>
1208 </condDesc>
1209
1210 <condDesc id="timeCond">
1211 <inputKey original="//ssap#instance.ssa_dateObs" name="TIME" unit=""
1212 type="text" std="True" multiplicity="single"/>
1213 <phraseMaker procDef="//pql#dateParameter">
1214 <bind name="consCol">"ssa_dateObs"</bind>
1215 <bind name="consColKind">"mjd"</bind>
1216 </phraseMaker>
1217 </condDesc>
1218
1219 <condDesc id="formatCond">
1220 <inputKey original="//ssap#instance.mime" name="FORMAT" type="text"
1221 std="True" multiplicity="single"/>
1222 <phraseMaker id="makeFormatPhrase">
1223 <setup>
1224 <par name="compliantFormats">frozenset([
1225 "application/x-votable+xml"])</par>
1226 <par name="nativeFormats">frozenset([
1227 "application/fits", "text/csv", "text/plain", "image/fits"])</par>
1228 <par name="consCol">"mime"</par>
1229 </setup>
1230 <code>
1231 val = inPars.get("FORMAT", None)
1232 if val is None:
1233 return
1234 if val=="" or val=="ALL": # no constraint
1235 return
1236
1237 sel = pql.PQLStringPar.fromLiteral(
1238 val.lower(), "FORMAT").getValuesAsSet()
1239
1240 if "all" in sel:
1241 return # No constraints
1242
1243 if "compliant" in sel:
1244 yield "%s IN %%(%s)s"%(consCol, base.getSQLKey(consCol,
1245 compliantFormats, outPars))
1246 sel.remove("compliant")
1247
1248 if "native" in sel:
1249 yield "%s IN %%(%s)s"%(consCol, base.getSQLKey(consCol,
1250 nativeFormats, outPars))
1251 sel.remove("native")
1252
1253 if "graphic" in sel:
1254 yield "%s LIKE 'image/%%'"%(consCol)
1255 sel.remove("graphic")
1256
1257 if "votable" in sel:
1258 yield "%s = 'application/x-votable+xml'"%consCol
1259 sel.remove("votable")
1260
1261 if "fits" in sel:
1262 yield "%s = 'application/fits'"%consCol
1263 sel.remove("fits")
1264
1265 if "xml" in sel:
1266 yield "1=0" # whatever would *that* be?
1267 sel.remove("xml")
1268
1269 if sel:
1270 yield "%s IN %%(%s)s"%(consCol, base.getSQLKey(consCol,
1271 sel, outPars))
1272 </code>
1273 </phraseMaker>
1274 </condDesc>
1275
1276
1277 <!--
1278 The following ssa keys cannot be generically supported since
1279 no SSA model column corresponds to them:
1280 VARAMPL, TIMERES -->
1281 <LOOP>
1282 <csvItems>
1283 keyName, matchCol, procDef
1284 APERTURE, ssa_aperture, //pql#floatParameter
1285 SNR, ssa_snr, //pql#floatParameter
1286 REDSHIFT, ssa_redshift, //pql#floatParameter
1287 TARGETNAME, ssa_targname, //pql#irStringParameter
1288 TARGETCLASS, ssa_targclass, //pql#stringParameter
1289 MTIME, ssa_pdate, //pql#dateParameter
1290 </csvItems>
1291 <events>
1292 <condDesc id="\keyName\+_cond">
1293 <inputKey original="//ssap#instance.\matchCol" name="\keyName"
1294 type="text" xtype="" std="True" multiplicity="single"/>
1295 <phraseMaker procDef="\procDef">
1296 <bind name="consCol">"\matchCol"</bind>
1297 </phraseMaker>
1298 </condDesc>
1299 </events>
1300 </LOOP>
1301
1302 <!-- the following keys may need to be compared against PARAMs,
1303 hence the special handling -->
1304 <LOOP>
1305 <csvItems>
1306 keyName, matchCol, parClass
1307 FLUXCALIB, ssa_fluxcalib, pql.PQLCaselessPar
1308 SPATRES, ssa_spaceRes, pql.PQLFloatPar
1309 WAVECALIB, ssa_speccalib, pql.PQLCaselessPar
1310 COLLECTION, ssa_collection, pql.PQLPar
1311 </csvItems>
1312 <events>
1313 <condDesc id="\keyName\+_cond">
1314 <inputKey original="//ssap#instance.\matchCol" name="\keyName"
1315 type="text" std="True" multiplicity="single"/>
1316 <phraseMaker procDef="//ssap#parablePQLPar">
1317 <bind name="consCol">"\matchCol"</bind>
1318 <bind name="parClass">\parClass</bind>
1319 </phraseMaker>
1320 </condDesc>
1321 </events>
1322 </LOOP>
1323
1324 <!-- SPECRP is an extra madness because it queries against
1325 λ/Δλm which isn't even in the SSA table. Oh, boy. -->
1326
1327 <condDesc id="SPECRP_cond">
1328 <inputKey name="SPECRP" type="real" std="True"
1329 description="Lower limit to spectral resolution power
1330 (λ/Δλ) as a single number."
1331 multiplicity="single"/>
1332 <phraseMaker>
1333 <setup>
1334 <code>
1335 from gavo import rscdef
1336 </code>
1337 </setup>
1338 <code> <![CDATA[
1339 valueSource = core.queriedTable.getByName("ssa_specres")
1340 if isinstance(valueSource, rscdef.Param):
1341 if valueSource.value is None:
1342 raise base.ValidationError("Unknown spectral resolution"
1343 " in %s"%core.queriedTable.getQName(), "SPECRP")
1344 else:
1345 yield '%%(%s)s < ssa_specend/%s'%(
1346 base.getSQLKey("specrp", inPars["SPECRP"], outPars),
1347 valueSource.value)
1348
1349 elif isinstance(valueSource, rscdef.Column):
1350 yield '%%(%s)s < ssa_specend/ssa_specres'%(
1351 base.getSQLKey("specrp", inPars["SPECRP"], outPars))
1352
1353 else:
1354 raise base.ValidationError("Table %s has insufficient"
1355 " information to query against spectral resolution"
1356 " power."%core.queriedTable.getQName(), "SPECRP")
1357 ]]></code>
1358 </phraseMaker>
1359 </condDesc>
1360
1361 <LOOP>
1362 <csvItems>
1363 keyName, matchCol
1364 PUBDID, ssa_pubDID
1365 CREATORDID, ssa_creatorDID
1366 </csvItems>
1367 <events>
1368 <condDesc>
1369 <inputKey original="//ssap#instance.\matchCol" name="\keyName"
1370 std="True" multiplicity="single"/>
1371 <phraseMaker>
1372 <code>
1373 yield "\matchCol=%%(%s)s"%base.getSQLKey("\keyName",
1374 inPars["\keyName"], outPars)
1375 </code>
1376 </phraseMaker>
1377 </condDesc>
1378 </events>
1379 </LOOP>
1380
1381 <!-- WILDTARGET and WILDTARGETCASE are funky special cases. -->
1382 <LOOP>
1383 <csvItems>
1384 keyName, parClass, addDesc
1385 WILDTARGET, PQLNocaseShellPatternPar, (case insensitive)
1386 WILDTARGETCASE, PQLShellPatternPar, (case sensitive)
1387 </csvItems>
1388 <events>
1389 <condDesc id="\keyName\+_cond">
1390 <inputKey name="\keyName" type="text" tablehead="Name Pattern"
1391 description="Shell pattern of target observed \addDesc"
1392 multiplicity="single"/>
1393 <phraseMaker>
1394 <code>
1395 parsed = pql.\parClass.fromLiteral(
1396 inPars.get("\keyName"), "\keyName")
1397 if parsed is not None:
1398 yield parsed.getSQL("\keyName", outPars)
1399 </code>
1400 </phraseMaker>
1401 </condDesc>
1402 </events>
1403 </LOOP>
1404
1405 <condDesc combining="True" joiner="AND">
1406 <!-- meta keys not (directly) entering the query -->
1407 <inputKey name="REQUEST" type="text" tablehead="Request type"
1408 description='This is queryData for the default operation; some
1409 services support getData as well' std="True"
1410 multiplicity="single"
1411 required="True">
1412 <property key="defaultForForm">queryData</property>
1413 </inputKey>
1414 <inputKey name="TOP" type="integer" tablehead="#Best"
1415 multiplicity="single"
1416 description='Only return the TOP "best" records (on this service,
1417 this usually is equivalent to MAXREC, so no ranking is implied).'
1418 std="True"/>
1419 <inputKey name="COMPRESS" type="boolean" tablehead="Compress?"
1420 multiplicity="single"
1421 description="Return compressed results?"
1422 std="True">True</inputKey>
1423 <inputKey name="RUNID" type="text" tablehead="Run id"
1424 multiplicity="single"
1425 description="An identifier for a certain run. Opaque to the service"
1426 std="True"/>
1427 <phraseMaker> <!-- done by the core code for these -->
1428 <code>
1429 if False:
1430 yield
1431 </code>
1432 </phraseMaker>
1433 </condDesc>
1434 </STREAM>
1435
1436 <NXSTREAM id="makeSpecGroup" doc="copies over SSA fields into groups
1437 required by the spectral DM; enter the names of the fields,
1438 whitespace-separated, in the fieldnames parameter">
1439 <group utype="\groupUtype">
1440 <LOOP>
1441 <codeItems>
1442 from gavo.protocols import sdm
1443 srcTable = context.getById("instance")
1444 for name in "\fieldnames".split():
1445 utype = sdm.getSDM1UtypeForSSA(
1446 srcTable.getElementForName(name).utype)
1447 yield {"dest": name, "utype": utype}
1448 </codeItems>
1449 <events>
1450 <paramRef dest="\\dest" utype="\\utype"/>
1451 </events>
1452 </LOOP>
1453 </group>
1454 </NXSTREAM>
1455
1456 <mixinDef id="sdm-instance">
1457 <doc><![CDATA[
1458 This mixin is intended for tables that get serialized into documents
1459 conforming to the Spectral Data Model 1, specifically to VOTables
1460
1461 The input to such tables comes from ssa tables (hcd, in this case).
1462 Their columns (and params) are transformed into params here.
1463
1464 The mixin adds two columns (you could add more if, e.g., you had
1465 errors depending on the spectral or flux value), spectral (wavelength
1466 or the like) and flux. Their metadata is taken from the ssa fields
1467 where available (ssa_fluxucd as flux UCD, ssa_fluxunit etc).
1468
1469 This mixin in action could look like this::
1470
1471 <table id="instance" onDisk="False">
1472 <mixin ssaTable="spectra"
1473 fluxUnit="Jy"
1474 >//ssap#sdm-instance</mixin>
1475 </table>
1476
1477 The mixin thus defines a gazillion of params. This will almost
1478 always be filled using `//ssap#feedSSAToSDM`_ as explained in
1479 `SDM compliant tables`_
1480 ]]></doc>
1481
1482 <!-- technically the sdm-instance defines the (silly) SDM-groups
1483 using the translation of names to utypes as given by the
1484 ssa instance above, whereas the actual params and columns are
1485 taken from the ssaTable. This works if the ssa table actually
1486 mixes in ssap#hcd; otherwise, you're on your own. -->
1487
1488 <mixinPar key="ssaTable" description="The SSAP (HCD) instance table
1489 to take the params from"/>
1490 <mixinPar key="spectralDescription" description="Description for the
1491 spectral column"
1492 >The independent variable of this spectrum (see its ucd to figure out whether it's a wavelength, frequency, or energy)</mixinPar>
1493 <mixinPar key="fluxDescription" description="Description
1494 for the flux column">The dependent variable of this spectrum (see the ucd for its physical meaning)</mixinPar>
1495 <mixinPar key="fluxUnitOverride" description="Force unit of
1496 the spectral column (don't use this; fix your SSA table instead)"
1497 >__EMPTY__</mixinPar>
1498 <mixinPar key="fluxUCDOverride" description="Force UCD of
1499 the spectral column (don't use this; fix your SSA table instead)"
1500 >__EMPTY__</mixinPar>
1501 <mixinPar key="spectralUnitOverride" description="Force unit of
1502 the spectral column (don't use this; fix your SSA table instead)"
1503 >__EMPTY__</mixinPar>
1504 <mixinPar key="spectralUCDOverride" description="Force UCD of the
1505 spectral column (don't use this)">__EMPTY__</mixinPar>
1506
1507 <events>
1508 <FEED source="makeSpecGroup"
1509 groupUtype="spec:Spectrum.Target"
1510 fieldnames="ssa_targname ssa_redshift ssa_targetpos ssa_targclass"/>
1511 <FEED source="makeSpecGroup"
1512 groupUtype="spec:Spectrum.Char"
1513 fieldnames="ssa_location ssa_aperture ssa_dateObs ssa_timeExt
1514 ssa_specmid ssa_specext ssa_specstart ssa_specend ssa_spectralucd
1515 ssa_binSize ssa_fluxSysError ssa_fluxStatError
1516 ssa_spectStatError ssa_spectSysError ssa_speccalib
1517 ssa_specres ssa_spectralunit ssa_fluxunit ssa_fluxucd"/>
1518 <FEED source="makeSpecGroup"
1519 groupUtype="spec:Spectrum.Curation"
1520 fieldnames="ssa_reference ssa_pubDID ssa_pdate ssa_publisher"/>
1521 <FEED source="makeSpecGroup"
1522 groupUtype="spec:Spectrum.DataID"
1523 fieldnames="ssa_dstitle ssa_creatorDID ssa_cdate ssa_bandpass
1524 ssa_cversion ssa_creator ssa_collection ssa_instrument
1525 ssa_datasource ssa_creationtype"/>
1526 <FEED source="makeSpecGroup"
1527 groupUtype="spec:Spectrum.Derived"
1528 fieldnames="ssa_snr"/>
1529 <FEED source="makeSpecGroup"
1530 groupUtype="spec:Spectrum.CoordSys"
1531 fieldnames="ssa_csysName"/>
1532
1533 <!-- UCDs and Units filled in by processEarly -->
1534 <column name="spectral" type="double precision"
1535 utype="spec:spectrum.data.spectralaxis.value"
1536 description="\spectralDescription"/>
1537 <column name="flux" type="double precision"
1538 utype="spec:spectrum.data.fluxaxis.value"
1539 description="\fluxDescription"/>
1540 <group utype="spec:spectrum.data">
1541 <columnRef key="spectral"
1542 utype="spec:spectrum.data.spectralaxis.value"/>
1543 <columnRef key="flux" utype="spec:spectrum.data.fluxaxis.value"/>
1544 </group>
1545 </events>
1546
1547 <processEarly>
1548 <setup>
1549 <code>
1550 from gavo import base
1551 from gavo import rscdef
1552 from gavo.protocols import sdm
1553 </code>
1554 </setup>
1555 <code>
1556 # copy over columns and params from the instance table as
1557 # params for us.
1558 ssapInstance = context.resolveId(mixinPars["ssaTable"])
1559 for col in ssapInstance.columns:
1560 atts = col.getAttributes()
1561 atts["utype"] = sdm.getSDM1UtypeForSSA(atts["utype"])
1562 atts["required"] = False
1563 substrate.feedObject("param",
1564 base.makeStruct(rscdef.Param, parent_=substrate, **atts))
1565 for param in ssapInstance.params:
1566 newUtype = sdm.getSDM1UtypeForSSA(param.utype)
1567 substrate.feedObject("param",
1568 param.change(utype=newUtype))
1569
1570 specUnit = getattr(
1571 ssapInstance,
1572 "from_mixin_spectral_unit",
1573 "\spectralUnitOverride")
1574 if specUnit is None:
1575 raise base.StructureError("Cannot deduce spectral ucd/unit from"
1576 " ssa table; use spectralUCDOverride and spectralUnitOverride")
1577
1578 specCol = substrate.getColumnByName("spectral")
1579 specCol.feed("ucd", r"\spectralUCDOverride" or
1580 ssapInstance.from_mixin_spectral_ucd)
1581 specCol.feed("unit", r"\spectralUnitOverride" or
1582 ssapInstance.from_mixin_spectral_unit)
1583
1584 fluxUnit = getattr(ssapInstance,
1585 "from_mixin_flux_unit",
1586 "\fluxUnitOverride")
1587 if fluxUnit is None:
1588 raise base.StructureError("Cannot deduce flux ucd/unit from"
1589 " ssa table; use fluxUCDOverride and fluxUnitOverride")
1590 if specUnit is None:
1591 raise base.StructureError("Cannot deduce flux ucd/unit from"
1592 " ssa table; use fluxUCDOverride and fluxUnitOverride")
1593
1594 fluxCol = substrate.getColumnByName("flux")
1595 fluxCol.feed("ucd", r"\fluxUCDOverride"
1596 or ssapInstance.from_mixin_flux_ucd)
1597 fluxCol.feed("unit", r"\fluxUnitOverride"
1598 or ssapInstance.from_mixin_flux_unit)
1599
1600 # set the SDM container meta if not already present
1601 if substrate.getMeta("utype", default=None) is None:
1602 substrate.setMeta("utype", "spec:Spectrum")
1603 </code>
1604 </processEarly>
1605 </mixinDef>
1606
1607 <STREAM id="_coverage-contents">
1608 <column name="ssa_region" type="spoly"
1609 ucd="pos.outline;obs.field"
1610 tablehead="Coverage"
1611 description="Rough coverage based on location and aperture."
1612 verbLevel="30"/>
1613 <index columns="ssa_region" method="GIST"/>
1614 </STREAM>
1615
1616 <mixinDef id="simpleCoverage">
1617 <doc>
1618 A mixin furnishes a table with an ssa_region column giving
1619 a polygonal coverage. For SSA itself, that's unnecessary, but it's
1620 highly recommended if you have data with positional and aperture
1621 data and will publish it via obscore, too (which in turn is highly
1622 recommended).
1623
1624 The column will be filled with a hexagon approximating the aperture.
1625 This is done by //ssap#fill-plainlocation (or, historically, by
1626 //ssap#setMeta), so usually you're all set with this mixin. We also
1627 create an index for the ssa_region field.
1628
1629 To make it visible in obscore, you must bind the ``ssa_region`` parameter
1630 of `the //ssap#view mixin`_ to ``ssa_region`` (so the column is in the
1631 SSAP table, and the ``coverage`` mixin par of `the
1632 //obscore#publishSSAPMIXC mixin`_ to ``ssa_region`` (so the value ends up
1633 in obscore's ``s_region``).
1634 </doc>
1635 <events>
1636 <FEED source="_coverage-contents"/>
1637 </events>
1638 </mixinDef>
1639
1640 <mixinDef id="plainlocation">
1641 <doc>
1642 A mixin that adds ssa_location column to a table.
1643
1644 You probably want this in the source tables for //ssap#view tables.
1645 This will also index the column. At least if you later want to
1646 publish the data through obscore, you will also want
1647 `the //ssap#simpleCoverage mixin`_ if you mix this in.
1648
1649 Use the `//ssap#fill-plainlocation`_ apply to feed these.
1650 </doc>
1651
1652 <events>
1653 <column name="ssa_location" type="spoint"
1654 ucd="pos.eq" unit="deg"
1655 utype="ssa:Char.SpatialAxis.Coverage.Location.Value"
1656 tablehead="Location"
1657 description="ICRS location of aperture center"
1658 verbLevel="5"/>
1659 <index columns="ssa_location" method="GIST"/>
1660 </events>
1661 </mixinDef>
1662
1663 <procDef type="apply" id="fill-plainlocation">
1664 <doc>
1665 This mixin fills the columns added by the plainlocation mixin
1666 with values generated from ra, dec, and aperture.
1667 </doc>
1668 <setup>
1669 <par key="ra" late="True" description="ICRS RA of aperture center"/>
1670 <par key="dec" late="True" description="ICRS Dec of aperture center"/>
1671 <par key="aperture" late="True"
1672 description="Size of the aperture in degrees; if you leave this
1673 at None, no ssa_region will be generated.">None</par>
1674 </setup>
1675 <code>
1676 vars["ssa_location"] = vars["ssa_region"] = None
1677 if ra is None or dec is None:
1678 return
1679
1680 vars["ssa_location"] = pgsphere.SPoint.fromDegrees(ra, dec)
1681 if aperture is not None:
1682 vars["ssa_region"] = pgsphere.SCircle.fromDALI(
1683 [ra, dec, aperture/2]).asPoly(6)
1684 </code>
1685 </procDef>
1686
1687 <procDef type="apply" id="feedSSAToSDM">
1688 <doc>
1689 feedSSAToSDM takes the current rowIterator's sourceToken and
1690 feeds it to the params of the current target. sourceTokens must
1691 be an SSA rowdict (as provided by the sdmCore). Further, it takes
1692 the params from the sourceTable argument and feeds them to the
1693 params, too.
1694
1695 All this probably only makes sense in parmakers when making tables
1696 mixing in //ssap#sdm-instance in data children of sdmCores.
1697 </doc>
1698 <code>
1699 srcMeta = vars["parser_"].sourceToken
1700 for param in targetTable.tableDef.params:
1701 newVal = srcMeta.get(param.name)
1702 if newVal is not None:
1703 targetTable.setParam(param.name, newVal)
1704 </code>
1705 </procDef>
1706
1707 <STREAM id="obscore-time-index">
1708 <doc>
1709 Include this stream in an ssa-like table feeding obscore. It will
1710 add an index useful for querying against obscore t_min and t_max.
1711
1712 This uses the dateObs and timeExt attributes which are
1713 preset for what the columns are called in SSA tables. dateObs
1714 must be a column reference because we declare the index to be on
1715 it. timeExt can be an expression, too, and no index will be declared
1716 on it.
1717 </doc>
1718 <DEFAULTS
1719 dateObs="ssa_dateObs"
1720 timeExt="ssa_timeExt"/>
1721 <index name="t_min_index" columns="\dateObs"
1722 >(\dateObs-\timeExt/43200.)</index>
1723 <index name="t_max_index" columns="\dateObs"
1724 >(\dateObs+\timeExt/43200.)</index>
1725 </STREAM>
1726
1727 </resource>