| 1 |
<!-- A template for a DaCHS SSAP (spectral search) service. |
| 2 |
Since spectra usually come in crazy formats, this already |
| 3 |
contains a datalink service so you'll usually serve proper SDM VOTables. |
| 4 |
|
| 5 |
To fill it out, search and replace %.*% |
| 6 |
|
| 7 |
Note that this doesn't expose all features of DaCHS. For advanced |
| 8 |
projects, you'll still have to read documentation... |
| 9 |
\tpldesc{Spectra via SSAP and TAP, going through datalink} |
| 10 |
--> |
| 11 |
|
| 12 |
<resource schema="\resdir" resdir="."> |
| 13 |
<meta name="creationDate">\now</meta> |
| 14 |
|
| 15 |
\commonmeta |
| 16 |
|
| 17 |
<meta name="ssap.dataSource">%one of survey, pointed, theory, custom, artificial)%</meta> |
| 18 |
<meta name="ssap.creationType">%one of archival, cutout, filtered, mosaic, projection, spectralExtraction, catalogExtraction%</meta> |
| 19 |
<!-- in case you serve anything but a spectrum, see |
| 20 |
http://www.ivoa.net/rdf/product-type |
| 21 |
for what terms you can use here; you can have more than one productType --> |
| 22 |
<meta name="productType">spectrum</meta> |
| 23 |
<meta name="ssap.testQuery">MAXREC=1</meta> |
| 24 |
|
| 25 |
<table id="raw_data" onDisk="True" adql="hidden" |
| 26 |
namePath="//ssap#instance"> |
| 27 |
<!-- the table with your custom metadata; it is transformed |
| 28 |
to something palatable for SSA using the view below --> |
| 29 |
|
| 30 |
<!-- for an explanation of what columns will be defined in the |
| 31 |
final view, see http://docs.g-vo.org/DaCHS/ref.html#the-ssap-view-mixin. |
| 32 |
|
| 33 |
Don't mention anything constant here; fill it in in the view |
| 34 |
definition. |
| 35 |
--> |
| 36 |
<LOOP listItems="%adapt this list to what metadata actually varies among your data sets.% |
| 37 |
ssa_dateObs ssa_dstitle ssa_targname ssa_length |
| 38 |
ssa_specres ssa_timeExt"> |
| 39 |
<events> |
| 40 |
<column original="\\item"/> |
| 41 |
</events> |
| 42 |
</LOOP> |
| 43 |
|
| 44 |
<mixin>//products#table</mixin> |
| 45 |
<!-- remove this if your data doesn't have (usable) positions --> |
| 46 |
<mixin>//ssap#plainlocation</mixin> |
| 47 |
<!-- remove this if you don't have plainlocation or there is no |
| 48 |
aperture --> |
| 49 |
<mixin>//ssap#simpleCoverage</mixin> |
| 50 |
<!-- the following adds a q3c index so obscore queries over s_ra |
| 51 |
and s_dec are fast; again, remove this if you don't have useful |
| 52 |
positions --> |
| 53 |
<FEED source="//scs#splitPosIndex" |
| 54 |
columns="ssa_location" |
| 55 |
long="degrees(long(ssa_location))" |
| 56 |
lat="degrees(lat(ssa_location))"/> |
| 57 |
|
| 58 |
<!-- the datalink column is mainly useful if you have a form-based |
| 59 |
service. You can dump this (and the mapping rule filling it below) |
| 60 |
if you're not planning on web or don't care about giving them datalink |
| 61 |
access. --> |
| 62 |
<column name="datalink" type="text" |
| 63 |
ucd="meta.ref.url" |
| 64 |
tablehead="Datalink" |
| 65 |
description="A link to a datalink document for this spectrum." |
| 66 |
verbLevel="15" displayHint="type=url"> |
| 67 |
<property name="targetType" |
| 68 |
>application/x-votable+xml;content=datalink</property> |
| 69 |
<property name="targetTitle">Datalink</property> |
| 70 |
</column> |
| 71 |
|
| 72 |
%add further custom columns if necessary here% |
| 73 |
</table> |
| 74 |
|
| 75 |
<!-- if you have data that is continually added to, consider using |
| 76 |
updating="True" and an ignorePattern here; see also howDoI.html, |
| 77 |
incremental updating. --> |
| 78 |
<data id="import"> |
| 79 |
<!-- uncomment later <recreateAfter>make_view</recreateAfter> --> |
| 80 |
<property key="previewDir">previews</property> |
| 81 |
<sources recurse="True" |
| 82 |
pattern="%resdir-relative pattern, like data/*.fits%"/> |
| 83 |
|
| 84 |
<!-- The following (and the datalink stuff) assumes you have |
| 85 |
IRAF-style 1D arrays; if you have something even more flamboyant, |
| 86 |
you'll have to change things here as well as in build_sdm_data; |
| 87 |
you'll want to keep the products#define rowmaker, though. --> |
| 88 |
<fitsProdGrammar qnd="True"> |
| 89 |
<rowfilter procDef="//products#define"> |
| 90 |
<bind key="table">"\\schema.raw_data"</bind> |
| 91 |
<!-- make the following a macro expansion once you have |
| 92 |
commented in the sdl service below --> |
| 93 |
<bind key="path">"fullDLURL{sdl}"</bind> |
| 94 |
<!-- the next item should be estimated (the stuff will |
| 95 |
be generated on the fly). Make it something like |
| 96 |
10000+20*number of data points or so. --> |
| 97 |
<bind key="fsize">%typical size of an SDM VOTable in bytes%</bind> |
| 98 |
<bind key="mime">"application/x-votable+xml"</bind> |
| 99 |
<bind key="preview">\\standardPreviewPath</bind> |
| 100 |
<bind key="preview_mime">"image/png"</bind> |
| 101 |
</rowfilter> |
| 102 |
</fitsProdGrammar> |
| 103 |
|
| 104 |
<make table="raw_data"> |
| 105 |
<rowmaker idmaps="*"> |
| 106 |
<!-- put vars here to pre-process FITS keys that you need to |
| 107 |
re-format in non-trivial ways. --> |
| 108 |
|
| 109 |
<var key="specAx">%use getWCSAxis(@header_, 1) for IRAF FITSes (delete otherwise)%</var> |
| 110 |
|
| 111 |
<apply procDef="//ssap#fill-plainlocation"> |
| 112 |
<bind key="ra">%where to get the RA from%</bind> |
| 113 |
<bind key="dec">%where to get the Dec from%</bind> |
| 114 |
<bind key="aperture">%the aperture (a constant estimate may just do it)%</bind> |
| 115 |
</apply> |
| 116 |
|
| 117 |
<!-- the following maps assume the column list in the LOOP |
| 118 |
above. If you changed things there, you'll have to adapt |
| 119 |
things here, too --> |
| 120 |
<map key="ssa_dateObs">dateTimeToMJD(parseTimestamp(@%key for dateObs%, |
| 121 |
"%Y-%m-%d %H:%M:%S"))</map> |
| 122 |
<map key="ssa_dstitle">"{} {}".format(%make a string halfway human-readable and halfway unique for each data set%)</map> |
| 123 |
<map key="ssa_targname">%which header to get the target name from%</map> |
| 124 |
<map key="ssa_specstart">%typically, @specAx.pixToPhys(1)*1e-10%</map> |
| 125 |
<map key="ssa_specend" |
| 126 |
>%typically, @specAx.pixToPhys(@specAx.axisLength)*1e-10%</map> |
| 127 |
<map key="ssa_length">%typically, @specAx.axisLength%</map> |
| 128 |
<map key="ssa_timeExt">%where to get an exposure time from%</map> |
| 129 |
<map key="ssa_specres">%expression to compute the typical spectral FWHM *in meters*%</map> |
| 130 |
|
| 131 |
<!-- uncomment later <map key="datalink">\\dlMetaURI{sdl}</map> --> |
| 132 |
|
| 133 |
<!-- add mappings for your own custom columns here. --> |
| 134 |
</rowmaker> |
| 135 |
</make> |
| 136 |
</data> |
| 137 |
|
| 138 |
|
| 139 |
<macDef raw="True" name="todo"><![CDATA[ |
| 140 |
|
| 141 |
<table id="data" onDisk="True" adql="True"> |
| 142 |
<!-- the SSA table (on which the service is based) --> |
| 143 |
|
| 144 |
<!-- <meta name="_associatedDatalinkService"> |
| 145 |
<meta name="serviceId">sdl</meta> |
| 146 |
<meta name="idColumn">ssa_pubDID</meta> |
| 147 |
</meta> --> |
| 148 |
|
| 149 |
<!-- again, the full list of things you can pass to the mixin |
| 150 |
is at http://docs.g-vo.org/DaCHS/ref.html#the-ssap-view-mixin. |
| 151 |
|
| 152 |
Things you already defined in raw_data are ignored here; you |
| 153 |
can also (almost always) leave them out altogether here. |
| 154 |
Defaulted attributes (the doc has "defaults to" for them) you |
| 155 |
can remove. |
| 156 |
|
| 157 |
The values for the ssa_ attributes below are SQL expressions – that |
| 158 |
is, you need to put strings in single quotes. |
| 159 |
--> |
| 160 |
<mixin |
| 161 |
sourcetable="raw_data" |
| 162 |
copiedcolumns="*" |
| 163 |
ssa_aperture="1/3600." |
| 164 |
ssa_fluxunit="'%Flux unit in the spectrum instance. Use'' for uncalibrated data.%'" |
| 165 |
ssa_spectralunit="'%Unit used in the spectrum itself ('Angstrom' or so)%'" |
| 166 |
ssa_bandpass="'%something like Optical or K; don't sweat it%'" |
| 167 |
ssa_collection="'%a very terse designation for your dataset%'" |
| 168 |
ssa_fluxcalib="'%ABSOLUTE|CALIBRATED|RELATIVE|NORMALIZED|UNCALIBRATED%'" |
| 169 |
ssa_fluxucd="%'phot.flux.density;em.wl', quite likely%" |
| 170 |
ssa_speccalib="'%ABSOLUTE|CALIBRATED|RELATIVE|NORMALIZED|UNCALIBRATED%'" |
| 171 |
ssa_spectralucd="'%em.wl;obs.atmos or similar for optical spectra%'" |
| 172 |
ssa_targclass="'%e.g., star; use Simbad object types%'" |
| 173 |
>//ssap#view</mixin> |
| 174 |
|
| 175 |
<mixin |
| 176 |
calibLevel="%likely one of 1 for uncalibrated or 2 for calibrated data%" |
| 177 |
coverage="%ssa_region -- or remove this if you have no ssa_region%" |
| 178 |
sResolution="ssa_spaceres" |
| 179 |
oUCD="ssa_fluxucd" |
| 180 |
emUCD="ssa_spectralucd" |
| 181 |
>//obscore#publishSSAPMIXC</mixin> |
| 182 |
</table> |
| 183 |
|
| 184 |
<data id="make_view" auto="False"> |
| 185 |
<make table="data"/> |
| 186 |
</data> |
| 187 |
|
| 188 |
<coverage> |
| 189 |
<updater sourceTable="data"/> |
| 190 |
</coverage> |
| 191 |
|
| 192 |
<!-- This is the table definition *for a single spectrum* as used |
| 193 |
by datalink. If you have per-bin errors or whatever else, just |
| 194 |
add columns as above. --> |
| 195 |
<table id="instance" onDisk="False"> |
| 196 |
<mixin ssaTable="data" |
| 197 |
spectralDescription="%something like 'Wavelength' or so%" |
| 198 |
fluxDescription="%something like 'Flux density' or so%" |
| 199 |
>//ssap#sdm-instance</mixin> |
| 200 |
<meta name="description">%a few words what a spectrum represents%</meta> |
| 201 |
</table> |
| 202 |
|
| 203 |
|
| 204 |
<!-- this data item build spectrum *instances* (for datalink) --> |
| 205 |
<data id="build_spectrum" auto="False"> |
| 206 |
<embeddedGrammar> |
| 207 |
<iterator> |
| 208 |
<setup imports="gavo.protocols.products,gavo.utils.pyfits"/> |
| 209 |
<code> |
| 210 |
# we receive a pubDID in self.sourceToken["ssa_pubDID"]; |
| 211 |
# the physical accref is behind its "?", potentially URL-encoded. |
| 212 |
|
| 213 |
sourcePath = os.path.join( |
| 214 |
base.getConfig("inputsDir"), |
| 215 |
urllib.parse.unquote( |
| 216 |
self.sourceToken["ssa_pubDID"].split('?', 1)[-1])) |
| 217 |
|
| 218 |
% add code returning rowdicts from sourcePath % |
| 219 |
# In the common case of 1D FITS images repurposed a a spectrum |
| 220 |
# this could be something like |
| 221 |
# fitsPath = products.RAccref.fromString( |
| 222 |
# self.sourceToken["accref"]).localpath |
| 223 |
# hdus = pyfits.open(fitsPath) |
| 224 |
# ax = utils.getWCSAxis(hdus[0].header, 1) |
| 225 |
|
| 226 |
# for spec, flux in enumerate(hdus[0].data): |
| 227 |
# yield {"spectral": ax.pix0ToPhys(spec), "flux": flux} |
| 228 |
# hdus.close() |
| 229 |
</code> |
| 230 |
</iterator> |
| 231 |
</embeddedGrammar> |
| 232 |
<make table="instance"> |
| 233 |
<parmaker> |
| 234 |
<apply procDef="//ssap#feedSSAToSDM"/> |
| 235 |
</parmaker> |
| 236 |
</make> |
| 237 |
</data> |
| 238 |
|
| 239 |
<!-- the datalink service spitting out SDM spectra (and other formats |
| 240 |
on request) --> |
| 241 |
<service id="sdl" allowed="dlget,dlmeta"> |
| 242 |
<meta name="title">\\schema Datalink Service</meta> |
| 243 |
<datalinkCore> |
| 244 |
<descriptorGenerator procDef="//soda#sdm_genDesc"> |
| 245 |
<bind key="ssaTD">"\\rdId#data"</bind> |
| 246 |
</descriptorGenerator> |
| 247 |
<dataFunction procDef="//soda#sdm_genData"> |
| 248 |
<bind key="builder">"\\rdId#build_spectrum"</bind> |
| 249 |
</dataFunction> |
| 250 |
<FEED source="//soda#sdm_plainfluxcalib"/> |
| 251 |
<FEED source="//soda#sdm_cutout"/> |
| 252 |
<FEED source="//soda#sdm_format"/> |
| 253 |
|
| 254 |
<!-- give people an option to retrieve the ugly FITS, too; |
| 255 |
again, adapt or drop if you have something else --> |
| 256 |
<metaMaker semantics="#progenitor"> |
| 257 |
<code> |
| 258 |
if descriptor.pubDID is None: |
| 259 |
return |
| 260 |
# this assumes normal accref computation: the original file |
| 261 |
# then is just inputsDir/accref |
| 262 |
yield descriptor.makeLinkFromFile( |
| 263 |
base.getConfig("inputsDir") / descriptor.accref, |
| 264 |
description="Spectrum as the original 1D array") |
| 265 |
</code> |
| 266 |
</metaMaker> |
| 267 |
|
| 268 |
</datalinkCore> |
| 269 |
</service> |
| 270 |
|
| 271 |
<!-- a form-based service – this is made totally separate from the |
| 272 |
SSA part because grinding down SSA to something human-consumable and |
| 273 |
still working as SSA is non-trivial --> |
| 274 |
<service id="web" defaultRenderer="form"> |
| 275 |
<meta name="shortName">\\schema Web</meta> |
| 276 |
|
| 277 |
<dbCore queriedTable="data"> |
| 278 |
<condDesc buildFrom="ssa_location"/> |
| 279 |
<condDesc buildFrom="ssa_dateObs"/> |
| 280 |
<!-- add further condDescs in this pattern; if you have useful target |
| 281 |
names, you'll probably want to index them and say: |
| 282 |
|
| 283 |
<condDesc> |
| 284 |
<inputKey original="data.ssa_targname" tablehead="Standard Stars"> |
| 285 |
<values fromdb="ssa_targname from \\schema.data |
| 286 |
order by ssa_targname"/> |
| 287 |
</inputKey> |
| 288 |
</condDesc> --> |
| 289 |
</dbCore> |
| 290 |
|
| 291 |
<outputTable> |
| 292 |
<autoCols>accref, mime, ssa_targname, |
| 293 |
ssa_aperture, ssa_dateObs, datalink</autoCols> |
| 294 |
<FEED source="//ssap#atomicCoords"/> |
| 295 |
<outputField original="ssa_specstart" displayHint="spectralUnit=Angstrom"/> |
| 296 |
<outputField original="ssa_specend" displayHint="spectralUnit=Angstrom"/> |
| 297 |
</outputTable> |
| 298 |
</service> |
| 299 |
|
| 300 |
<service id="ssa" allowed="form,ssap.xml"> |
| 301 |
<meta name="shortName">\\schema SSAP</meta> |
| 302 |
<meta name="ssap.complianceLevel">full</meta> |
| 303 |
|
| 304 |
<publish render="ssap.xml" sets="ivo_managed"/> |
| 305 |
<publish render="form" sets="ivo_managed,local" service="web"/> |
| 306 |
|
| 307 |
<ssapCore queriedTable="data"> |
| 308 |
<property key="previews">auto%delete this line if you have no previews; else delete just this.%</property> |
| 309 |
<FEED source="//ssap#hcd_condDescs"/> |
| 310 |
</ssapCore> |
| 311 |
</service> |
| 312 |
|
| 313 |
<regSuite title="\resdir regression"> |
| 314 |
<!-- see http://docs.g-vo.org/DaCHS/ref.html#regression-testing |
| 315 |
for more info on these. --> |
| 316 |
|
| 317 |
<regTest title="\resdir SSAP serves some data"> |
| 318 |
<url REQUEST="queryData" PUBDID="%a value you have in ssa_pubDID%" |
| 319 |
>ssa/ssap.xml</url> |
| 320 |
<code> |
| 321 |
<!-- to figure out some good strings to use here, run |
| 322 |
dachs test -k SSAP -D tmp.xml q |
| 323 |
and look at tmp.xml --> |
| 324 |
self.assertHasStrings( |
| 325 |
"%some characteristic string returned by the query%", |
| 326 |
"%another characteristic string returned by the query%") |
| 327 |
</code> |
| 328 |
</regTest> |
| 329 |
|
| 330 |
<regTest title="\resdir Datalink metadata looks about right."> |
| 331 |
<url ID="%a value you have in ssa_pubDID%" |
| 332 |
>sdl/dlmeta</url> |
| 333 |
<code> |
| 334 |
<!-- to figure out good items to test here, you probably want to |
| 335 |
dachs test -k datalink q |
| 336 |
and pprint the by_sem dict --> |
| 337 |
by_sem = self.datalinkBySemantics() |
| 338 |
print(by_sem) |
| 339 |
self.fail("Fill this in") |
| 340 |
</code> |
| 341 |
</regTest> |
| 342 |
|
| 343 |
<regTest title="\resdir delivers some data."> |
| 344 |
<url ID="%a value you have in ssa_pubDID%" |
| 345 |
>sdl/dlget</url> |
| 346 |
<code> |
| 347 |
<!-- to figure out some good strings to use here, run |
| 348 |
dachs test -k "delivers data" -D tmp.xml q |
| 349 |
and look at tmp.xml --> |
| 350 |
self.assertHasStrings( |
| 351 |
"%some characteristic string in the datalink meta%") |
| 352 |
</code> |
| 353 |
</regTest> |
| 354 |
|
| 355 |
<!-- add more tests: form-based service renders custom widgets, etc. --> |
| 356 |
</regSuite> |
| 357 |
]]></macDef> |
| 358 |
</resource> |