| 1 |
<!-- A template for a DaCHS Timeseries data collection served through |
| 2 |
SSAP and obscore. |
| 3 |
|
| 4 |
Since time series usually come in crazy formats, this already |
| 5 |
contains a datalink service. This will produce data hopefully |
| 6 |
conforming to http://ivoa.net/documents/Notes/LightCurveTimeSeries/ |
| 7 |
at this point. |
| 8 |
|
| 9 |
To fill it out, minimally search and replace %.*% |
| 10 |
|
| 11 |
Note that this doesn't expose all features of DaCHS. For advanced |
| 12 |
projects, you'll still have to read documentation... |
| 13 |
\tpldesc{Time series via Obscore and SSAP formatted with datalink} |
| 14 |
--> |
| 15 |
|
| 16 |
<resource schema="\resdir" resdir="."> |
| 17 |
<meta name="creationDate">\now</meta> |
| 18 |
|
| 19 |
\commonmeta |
| 20 |
|
| 21 |
<meta name="ssap.dataSource">%one of survey, pointed, theory, custom, artificial)%</meta> |
| 22 |
<meta name="ssap.creationType">%one of archival, cutout, filtered, mosaic, projection, spectralExtraction, catalogExtraction%</meta> |
| 23 |
<meta name="productType">timeseries</meta> |
| 24 |
<meta name="ssap.testQuery">MAXREC=1</meta> |
| 25 |
|
| 26 |
<table id="raw_data" onDisk="True" adql="hidden" |
| 27 |
namePath="//ssap#instance"> |
| 28 |
<!-- the table with your custom metadata; it is transformed |
| 29 |
to something palatable for SSA and Obscore using the view below --> |
| 30 |
|
| 31 |
<!-- for an explanation of what columns will be defined in the |
| 32 |
final view, see http://docs.g-vo.org/DaCHS/ref.html#the-ssap-view-mixin. |
| 33 |
|
| 34 |
Don't mention anything constant here; fill it in in the view |
| 35 |
definition. |
| 36 |
--> |
| 37 |
<LOOP listItems="%adapt this list to what metadata actually varies among your data sets.% |
| 38 |
ssa_dstitle ssa_targname ssa_length ssa_timeExt |
| 39 |
ssa_bandpass ssa_specstart ssa_specend"> |
| 40 |
<events> |
| 41 |
<column original="\\item"/> |
| 42 |
</events> |
| 43 |
</LOOP> |
| 44 |
<column original="//obscore#ObsCore.t_min"/> |
| 45 |
<column original="//obscore#ObsCore.t_max"/> |
| 46 |
|
| 47 |
<mixin>//products#table</mixin> |
| 48 |
<!-- remove this if your data doesn't have (usable) positions --> |
| 49 |
<mixin>//ssap#plainlocation</mixin> |
| 50 |
<!-- remove this if you don't have plainlocation or there is no |
| 51 |
aperture --> |
| 52 |
<mixin>//ssap#simpleCoverage</mixin> |
| 53 |
<!-- the following adds a q3c index so obscore queries over s_ra |
| 54 |
and s_dec are fast; again, remove this if you don't have useful |
| 55 |
positions --> |
| 56 |
<FEED source="//scs#splitPosIndex" |
| 57 |
columns="ssa_location" |
| 58 |
long="degrees(long(ssa_location))" |
| 59 |
lat="degrees(lat(ssa_location))"/> |
| 60 |
|
| 61 |
<!-- the datalink column is mainly useful if you have a form-based |
| 62 |
service. You can dump this (and the mapping rule filling it below) |
| 63 |
if you're not planning on web or don't care about giving them datalink |
| 64 |
access. --> |
| 65 |
<column name="datalink" type="text" |
| 66 |
ucd="meta.ref.url" |
| 67 |
tablehead="Datalink" |
| 68 |
description="A link to a datalink document for this spectrum." |
| 69 |
verbLevel="15" displayHint="type=url"> |
| 70 |
<property name="targetType" |
| 71 |
>application/x-votable+xml;content=datalink</property> |
| 72 |
<property name="targetTitle">Datalink</property> |
| 73 |
</column> |
| 74 |
|
| 75 |
%add further custom columns if necessary here% |
| 76 |
</table> |
| 77 |
|
| 78 |
<!-- if you have data that is continually added to, consider using |
| 79 |
updating="True" and an ignorePattern here; see also howDoI.html, |
| 80 |
incremental updating. --> |
| 81 |
<data id="import"> |
| 82 |
<!-- uncomment when make_view becomes visible |
| 83 |
<recreateAfter>make_view</recreateAfter> --> |
| 84 |
<property key="previewDir">previews</property> |
| 85 |
<sources recurse="True" |
| 86 |
pattern="%resdir-relative pattern, like data/*.fits%"/> |
| 87 |
|
| 88 |
<!-- It's quite likely that you will need to be creative with a |
| 89 |
custom row filter or even an embedded grammar to annotate your |
| 90 |
time series. Sorry about that; we need a standard format for |
| 91 |
these things badly. The important thing is the rowfilter |
| 92 |
munging single input files to datalinks. If you have multiple |
| 93 |
time series per file, it's likely that you want to manipulate |
| 94 |
self.sourceToken in a rowfilter in front of products#define. --> |
| 95 |
<fitsProdGrammar qnd="True"> |
| 96 |
<rowfilter procDef="//products#define"> |
| 97 |
<bind key="table">"\\schema.raw_data"</bind> |
| 98 |
<bind key="path">"fullDLURL{sdl}"</bind> |
| 99 |
<!-- the next item should be estimated (the stuff will |
| 100 |
be generated on the fly). Make it something like |
| 101 |
10000+20*number of data points or so. --> |
| 102 |
<bind key="fsize">%typical size of an SDM VOTable in bytes%</bind> |
| 103 |
<bind key="mime">"application/x-votable+xml"</bind> |
| 104 |
<bind key="preview">\\standardPreviewPath</bind> |
| 105 |
<bind key="preview_mime">"image/png"</bind> |
| 106 |
</rowfilter> |
| 107 |
</fitsProdGrammar> |
| 108 |
|
| 109 |
<make table="raw_data"> |
| 110 |
<rowmaker idmaps="*"> |
| 111 |
<!-- put vars here to pre-process FITS keys that you need to |
| 112 |
re-format in non-trivial ways. --> |
| 113 |
|
| 114 |
<apply procDef="//ssap#fill-plainlocation"> |
| 115 |
<bind key="ra">%where to get the RA from%</bind> |
| 116 |
<bind key="dec">%where to get the Dec from%</bind> |
| 117 |
<bind key="aperture">%the aperture (a constant estimate may just do it)%</bind> |
| 118 |
</apply> |
| 119 |
|
| 120 |
<!-- the following maps assume the column list in the LOOP |
| 121 |
above. If you changed things there, you'll have to adapt |
| 122 |
things here, too --> |
| 123 |
<map key="ssa_dateObs">dateTimeToMJD(parseTimestamp(@%key for dateObs%, |
| 124 |
"%Y-%m-%d %H:%M:%S"))</map> |
| 125 |
<map key="ssa_dstitle">"{} {}".format(%make a string halfway human-readable and halfway unique for each data set%)</map> |
| 126 |
<map key="ssa_targname">%which header to get the target name from%</map> |
| 127 |
<map key="ssa_specstart">%the min wavelength [m] in your passband</map> |
| 128 |
<map key="ssa_specend">%the max wavelength [m] in your passband%</map> |
| 129 |
<map key="ssa_length">%the number of points in the time series%</map> |
| 130 |
<map key="ssa_timeExt">%t_max-t_min at this point%</map> |
| 131 |
<map key="t_min">%earliest time stamp, mjd%</map> |
| 132 |
<map key="t_max">%latest time stamp, mjd%</map> |
| 133 |
|
| 134 |
<!-- uncomment later <map key="datalink">\\dlMetaURI{sdl}</map> --> |
| 135 |
|
| 136 |
<!-- add mappings for your own custom columns here. --> |
| 137 |
</rowmaker> |
| 138 |
</make> |
| 139 |
</data> |
| 140 |
|
| 141 |
<macDef raw="True" name="todo"><![CDATA[ |
| 142 |
|
| 143 |
<table id="data" onDisk="True" adql="True"> |
| 144 |
<!-- the SSA table (on which the service is based) --> |
| 145 |
|
| 146 |
<!-- uncomment later <meta name="_associatedDatalinkService"> |
| 147 |
<meta name="serviceId">sdl</meta> |
| 148 |
<meta name="idColumn">ssa_pubDID</meta> |
| 149 |
</meta> --> |
| 150 |
|
| 151 |
<!-- again, the full list of things you can pass to the mixin |
| 152 |
is at http://docs.g-vo.org/DaCHS/ref.html#the-ssap-view-mixin. |
| 153 |
|
| 154 |
Things you already defined in raw_data are ignored here; you |
| 155 |
can also (almost always) leave them out altogether here. |
| 156 |
Defaulted attributes (the doc has "defaults to" for them) you |
| 157 |
can remove. |
| 158 |
|
| 159 |
The values for the ssa_ attributes below are SQL expressions – that |
| 160 |
is, you need to put strings in single quotes. |
| 161 |
--> |
| 162 |
<mixin |
| 163 |
sourcetable="raw_data" |
| 164 |
copiedcolumns="*" |
| 165 |
ssa_aperture="1/3600." |
| 166 |
ssa_fluxunit="'%Flux unit in the spectrum instance. Use'' for uncalibrated data.%'" |
| 167 |
ssa_spectralunit="'%Unit used in the spectrum itself ('Angstrom' or so)%'" |
| 168 |
ssa_bandpass="'%something like Optical or K; don't sweat it%'" |
| 169 |
ssa_collection="'%a very terse designation for your dataset%'" |
| 170 |
ssa_fluxcalib="'%ABSOLUTE|CALIBRATED|RELATIVE|NORMALIZED|UNCALIBRATED%'" |
| 171 |
ssa_fluxucd="%'phot.mag', perhaps; consider adding band info%" |
| 172 |
ssa_spectralucd="'%em.wl;obs.atmos or similar for optical spectra%'" |
| 173 |
ssa_targclass="'%e.g., star; use Simbad object types%'" |
| 174 |
>//ssap#view</mixin> |
| 175 |
|
| 176 |
<mixin |
| 177 |
calibLevel="%likely one of 1 for uncalibrated or 2 for calibrated data%" |
| 178 |
coverage="%ssa_region -- or remove this if you have no ssa_region%" |
| 179 |
oUCD="ssa_fluxucd" |
| 180 |
>//obscore#publishSSAPMIXC</mixin> |
| 181 |
</table> |
| 182 |
|
| 183 |
<data id="make_view" auto="False"> |
| 184 |
<make table="data"/> |
| 185 |
</data> |
| 186 |
|
| 187 |
<coverage> |
| 188 |
<updater sourceTable="data"/> |
| 189 |
</coverage> |
| 190 |
|
| 191 |
<!-- This is the table definition *for a single time series* as used |
| 192 |
by datalink. If you have per-bin errors or whatever else, just |
| 193 |
add columns as above. --> |
| 194 |
<table id="instance" onDisk="False"> |
| 195 |
<!-- we use a template for description here; it will be filled |
| 196 |
out by the datalink service below --> |
| 197 |
<meta name="description">The \\metaString{source} light curve |
| 198 |
for {ssa_targname} in the {ssa_bandpass} filter.</meta> |
| 199 |
<mixin |
| 200 |
effectiveWavelength="@ssa_specmid" |
| 201 |
filterIdentifier="@ssa_bandpass" |
| 202 |
magnitudeSystem="%Vega or AB, perhaps%" |
| 203 |
phot_description="%make it something like 'Gaia-calibrated magnitude'%" |
| 204 |
phot_ucd="%phot.mag?%" |
| 205 |
phot_unit="%mag%" |
| 206 |
refposition="%pick from http://ivoa.net/rdf/refposition%" |
| 207 |
refframe="%pick from http://ivoa.net/rdf/refframe%" |
| 208 |
time0="%JD of your time's zero point, 2400000.5 for MJD%" |
| 209 |
timescale="%pick from http://ivoa.net/rdf/timescale%" |
| 210 |
>//timeseries#phot-0</mixin> |
| 211 |
<param original="data.ssa_bandpass"/> |
| 212 |
<param original="data.ssa_specstart"/> |
| 213 |
<param original="data.ssa_specmid"/> |
| 214 |
<param original="data.ssa_specend"/> |
| 215 |
<param original="data.ssa_location"/> |
| 216 |
<!-- %add columns for other dependent values (errors and the like) --> |
| 217 |
</table> |
| 218 |
|
| 219 |
<data id="build-ts" auto="False"> |
| 220 |
<!-- The source token is the datalink descriptor from the sdl |
| 221 |
datalink service, which also has the metadata in ssa_row. |
| 222 |
This is what our pargetter returns. If you have sane source |
| 223 |
material, you don't need that and you can in principle use |
| 224 |
proper grammars, too. --> |
| 225 |
<embeddedGrammar> |
| 226 |
<iterator> |
| 227 |
<code> |
| 228 |
# Example: three-column lines (you could use an reGrammar |
| 229 |
# here, but we need a custom pargetter) |
| 230 |
with open(self.sourceToken.src_name) as f: |
| 231 |
for ln in f: |
| 232 |
parts = ln.split() |
| 233 |
yield { |
| 234 |
'obs_time': float(parts[0]), |
| 235 |
'phot': float(parts[1]), |
| 236 |
'err_phot': float(parts[2]),} |
| 237 |
</code> |
| 238 |
</iterator> |
| 239 |
<pargetter> |
| 240 |
<code> |
| 241 |
return self.sourceToken.ssa_row |
| 242 |
</code> |
| 243 |
</pargetter> |
| 244 |
</embeddedGrammar> |
| 245 |
|
| 246 |
<make table="instance"> |
| 247 |
<rowmaker idmaps="*" id="make-ts"/> |
| 248 |
<!-- you need explicit idmaps rather than * here because |
| 249 |
#phot-0 has "hidden" params that you don't want to fill --> |
| 250 |
<parmaker id="make-ts-par" idmaps="ssa_bandpass, ssa_specstart, |
| 251 |
ssa_specend, ssa_location, ssa_specmid"> |
| 252 |
</parmaker> |
| 253 |
</make> |
| 254 |
</data> |
| 255 |
|
| 256 |
<!-- the datalink service spitting out quasi-standard time series --> |
| 257 |
<service id="sdl" allowed="dlget,dlmeta"> |
| 258 |
<meta name="title">\\schema Datalink Service</meta> |
| 259 |
<datalinkCore> |
| 260 |
<descriptorGenerator> |
| 261 |
<code> |
| 262 |
descriptor = ProductDescriptor.fromAccref( |
| 263 |
pubDID, pubDID.split("?")[-1]) |
| 264 |
with base.getTableConn() as conn: |
| 265 |
descriptor.ssa_row = next(conn.queryToDicts( |
| 266 |
"SELECT * FROM \\schema.data" |
| 267 |
" WHERE ssa_pubdid=%(pubDID)s", |
| 268 |
{"pubDID": pubDID})) |
| 269 |
return descriptor |
| 270 |
</code> |
| 271 |
</descriptorGenerator> |
| 272 |
<dataFunction> |
| 273 |
<setup imports="gavo.rsc"/> |
| 274 |
<code> |
| 275 |
descriptor.data = rsc.makeData( |
| 276 |
rd.getById("build-ts"), |
| 277 |
forceSource=descriptor) |
| 278 |
|
| 279 |
# sample code for how to change various pieces of metadata of |
| 280 |
# the generated table. The tableDef you see is a copy, |
| 281 |
# so edit with impunity. |
| 282 |
tab = descriptor.data.getPrimaryTable() |
| 283 |
tab.setMeta("description", |
| 284 |
base.getMetaText(tab, "description").format(**descriptor.ssa_row)) |
| 285 |
|
| 286 |
mag_ucd = "phot.mag;em.opt.V" |
| 287 |
if descriptor.ssa_row["ssa_bandpass"]=="Bessell R": |
| 288 |
mag_ucd = "phot.mag;em.opt.R" |
| 289 |
tab.tableDef.getColumnByName("phot").ucd = mag_ucd |
| 290 |
tab.tableDef.getColumnByName("err_phot").ucd = "stat.error;"+mag_ucd |
| 291 |
</code> |
| 292 |
</dataFunction> |
| 293 |
|
| 294 |
<dataFormatter> |
| 295 |
<setup imports="gavo.formats.votablewrite"/> |
| 296 |
<code> |
| 297 |
return ("application/x-votable+xml;version=1.5", |
| 298 |
votablewrite.getAsVOTable(descriptor.data, version=(1,5))) |
| 299 |
</code> |
| 300 |
</dataFormatter> |
| 301 |
</datalinkCore> |
| 302 |
</service> |
| 303 |
|
| 304 |
|
| 305 |
<!-- a form-based service – this is made totally separate from the |
| 306 |
SSA part because grinding down SSA to something human-consumable and |
| 307 |
still working as SSA is non-trivial --> |
| 308 |
<service id="web" defaultRenderer="form"> |
| 309 |
<meta name="shortName">\\schema Web</meta> |
| 310 |
|
| 311 |
<dbCore queriedTable="data"> |
| 312 |
<condDesc buildFrom="ssa_location"/> |
| 313 |
<condDesc buildFrom="t_max"/> |
| 314 |
<!-- add further condDescs in this pattern; if you have useful target |
| 315 |
names, you'll probably want to index them and say: |
| 316 |
|
| 317 |
<condDesc> |
| 318 |
<inputKey original="data.ssa_targname" tablehead="Target Object"> |
| 319 |
<values fromdb="ssa_targname from \\schema.data |
| 320 |
order by ssa_targname"/> |
| 321 |
</inputKey> |
| 322 |
</condDesc> --> |
| 323 |
</dbCore> |
| 324 |
|
| 325 |
<outputTable> |
| 326 |
<autoCols>accref, ssa_targname, t_min, t_max, ssa_bandpass, |
| 327 |
datalink</autoCols> |
| 328 |
<FEED source="//ssap#atomicCoords"/> |
| 329 |
</outputTable> |
| 330 |
</service> |
| 331 |
|
| 332 |
<service id="ssa" allowed="form,ssap.xml"> |
| 333 |
<meta name="shortName">\\schema SSAP</meta> |
| 334 |
<meta name="ssap.complianceLevel">full</meta> |
| 335 |
|
| 336 |
<publish render="ssap.xml" sets="ivo_managed"/> |
| 337 |
<publish render="form" sets="ivo_managed,local" service="web"/> |
| 338 |
|
| 339 |
<ssapCore queriedTable="data"> |
| 340 |
<property key="previews">auto%delete this line if you have no previews; else delete just this.%</property> |
| 341 |
<FEED source="//ssap#hcd_condDescs"/> |
| 342 |
</ssapCore> |
| 343 |
</service> |
| 344 |
|
| 345 |
<regSuite title="\resdir regression"> |
| 346 |
<!-- see http://docs.g-vo.org/DaCHS/ref.html#regression-testing |
| 347 |
for more info on these. --> |
| 348 |
|
| 349 |
<regTest title="\resdir SSAP serves some data"> |
| 350 |
<url REQUEST="queryData" PUBDID="%a value you have in ssa_pubDID%" |
| 351 |
>ssa/ssap.xml</url> |
| 352 |
<code> |
| 353 |
<!-- to figure out some good strings to use here, run |
| 354 |
dachs test -k SSAP -D tmp.xml q |
| 355 |
and look at tmp.xml --> |
| 356 |
self.assertHasStrings( |
| 357 |
"%some characteristic string returned by the query%", |
| 358 |
"%another characteristic string returned by the query%") |
| 359 |
</code> |
| 360 |
</regTest> |
| 361 |
|
| 362 |
<regTest title="\resdir Datalink metadata looks about right."> |
| 363 |
<url ID="%a value you have in ssa_pubDID%" |
| 364 |
>sdl/dlmeta</url> |
| 365 |
<code> |
| 366 |
<!-- to figure out good items to test here, you probably want to |
| 367 |
dachs test -k datalink q |
| 368 |
and pprint the by_sem dict --> |
| 369 |
by_sem = self.datalinkBySemantics() |
| 370 |
print(by_sem) |
| 371 |
self.fail("Fill this in") |
| 372 |
</code> |
| 373 |
</regTest> |
| 374 |
|
| 375 |
<regTest title="\resdir delivers some data."> |
| 376 |
<url ID="%a value you have in ssa_pubDID%" |
| 377 |
>sdl/dlget</url> |
| 378 |
<code> |
| 379 |
<!-- to figure out some good strings to use here, run |
| 380 |
dachs test -k "delivers data" -D tmp.xml q |
| 381 |
and look at tmp.xml --> |
| 382 |
self.assertHasStrings( |
| 383 |
"%some characteristic string in the datalink meta%") |
| 384 |
</code> |
| 385 |
</regTest> |
| 386 |
|
| 387 |
<!-- add more tests: form-based service renders custom widgets, etc. --> |
| 388 |
</regSuite> |
| 389 |
|
| 390 |
</macDef> |
| 391 |
</resource> |