2011-03-25T10:23:00
observational-astronomy
Definition and support code for the ObsCore
data model and table.
5
try:
with base.getTableConn() as conn:
# don't try this if there is no obscore table
if not base.UnmanagedQuerier(conn).getTableType("ivoa.obscore"):
return
res = conn.query("select vals from dc.discrete_string_values"
" where tablename='ivoa.ObsCore'"
" and column_name='dataproduct_type'")
dptypes = next(res)[0]
def addDptypes(rd, context):
for dptype in dptypes:
rd.addMeta("productTypeServed", dptype)
context.addExitFunc(addDptypes)
except Exception as msg:
base.ui.notifyInfo("Cannot publish product types served in"
f" obscore ({msg});"
" you can probably fix this by running dachs limits //obscore")
if False:
yield
The columns of a (standard) obscore table. This can be used
to define a "native" obscore table (as opposed to the more usual
mixins below that expose standard products via obscore.
Even if you are sure you want to do this, better ask again...
Polygon ICRS [s_region]
1enumerate1
The calib_level flag takes the following values:
=== ===========================================================
0 Raw Instrumental data requiring instrument-specific tools
1 Instrumental data processable with standard tools
2 Calibrated, science-ready data without instrument signature
3 Enhanced data products (e.g., mosaics)
=== ===========================================================
1enumerate111111111enumerate111111111111111enumerate1enumerate1111111
if not base.getConfig("ivoa", "materialiseObscore"):
yield {"materialise": "no"}
TrueObscore-1.1ivo://ivoa.net/std/obscore#core-1.1True
ivo://ivoa.net/std/obscore#table-1.1
\getConfig{web}{sitename} Obscore Table
\metaString{authority.shortName} Obscore
//obscore#dl
obs_publisher_did
The IVOA-defined obscore table, containing
generic metadata for datasets within this data centre.
if base.getConfig("ivoa", "materialiseObscore"):
yield {"materialise": "materialise"}
create view \qName (\colNames) as (select * from (VALUES(
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL)) as q WHERE 0=1);
This table contains the SQL fragments that make up this installation's
ivoa.obscore view. Whenever a participating table is re-made, the
view definition is renewed with a statement made up of a union of
all sqlFragments present in this table.
Manipulate this table through gavo imp on tables that have an obscore
mixin, or by dropping RDs or purging tables that are part of obscore.
This stream has the code to turn ivoa._obscoresources into a
view definition. This is always a preImport script on ivoa.obscore
and overrides its built-in trivial view creation. For a non-materialised
obscore view, this is also a postCreation script on anything that
contributes to ivoa.obscore.
These scripts must be included in any table that eventually
ends up as a part of ivoa.obscore.
if not base.getConfig("ivoa", "materialiseObscore"):
yield {"materialise": "no"}
Material for all mixins contributing to ivoa.obscore.
At its centre, this gives a table an obscoreClause property.
The stuff around it is just means to feed it; see the obscoreClause
for what macros anything embedding this will have to define.
'\qName'FalseTrue
\getConfig{web}{siteName} Obscore
CAST(\dataproduct_type AS text) AS dataproduct_type,
CAST(\dataproduct_subtype AS text) AS dataproduct_subtype,
CAST(\calib_level AS smallint) AS calib_level,
CAST(\obs_collection AS text) AS obs_collection,
CAST(\obs_id AS text) AS obs_id,
CAST(\obs_title AS text) AS obs_title,
CAST(\obs_publisher_did AS text) AS obs_publisher_did,
CAST(\obs_creator_did AS text) AS obs_creator_did,
CAST(\access_url AS text) AS access_url,
CAST(\access_format AS text) AS access_format,
CAST(\access_estsize AS bigint) AS access_estsize,
CAST(\target_name AS text) AS target_name,
CAST(\target_class AS text) AS target_class,
CAST(\s_ra AS double precision) AS s_ra,
CAST(\s_dec AS double precision) AS s_dec,
CAST(\s_fov AS real) AS s_fov,
CAST(\s_region AS spoly) AS s_region,
CAST(\s_resolution AS real) AS s_resolution,
CAST(\t_min AS double precision) AS t_min,
CAST(\t_max AS double precision) AS t_max,
CAST(\t_exptime AS double precision) AS t_exptime,
CAST(\t_resolution AS double precision) AS t_resolution,
CAST(\em_min AS real) AS em_min,
CAST(\em_max AS real) AS em_max,
CAST(\em_res_power AS real) AS em_res_power,
CAST(\o_ucd AS text) AS o_ucd,
CAST(\pol_states AS text) AS pol_states,
CAST(\facility_name AS text) AS facility_name,
CAST(\instrument_name AS text) AS instrument_name,
CAST(\s_xel1 AS integer) AS s_xel1,
CAST(\s_xel2 AS integer) AS s_xel2,
CAST(\t_xel AS integer) AS t_xel,
CAST(\em_xel AS integer) AS em_xel,
CAST(\pol_xel AS integer) AS pol_xel,
CAST(\s_pixel_scale AS real) AS s_pixel_scale,
CAST(\em_ucd AS text) AS em_ucd,
CAST(\preview AS text) AS preview,
CAST(\source_table AS text) AS source_table
Minor housekeeping chores for obscore tables.
Common elements for (almost all) ObsTAP publication mixins.
NULL2'unnamed'NULLNULLNULLNULLNULLNULLNULLNULLNULLNULLNULLNULLNULLNULLNULL
publish mixin parameters deriving from products#table interface
fields.
accref__COMPUTE__accrefmimeaccsize/1024accref || '?preview=True'
Publish this table to ObsTAP.
This means mapping or giving quite a bit of data from the present
table to ObsCore rows. Internally, this information is converted
to an SQL select statement used within a create view statement.
In consequence, you must give *SQL* expressions in the parameter
values; just naked column names from your input table are ok,
of course. Most parameters are set to NULL or appropriate
defaults for tables mixing in //products#table.
Since the mixin generates script elements, it cannot be used
in untrusted RDs. The fact that you can enter raw SQL also
means you will get ugly error messages if you give invalid
parameters.
Some items are filled from product interface fields automatically.
You must change these if you obscore-publish tables not mixin
in products.
Note: you must say ``dachs imp //obscore`` before anything
obscore-related will work.
NULLNULLNULLNULLNULLNULLNULLNULLNULLNULLNULLNULLNULL
Publish a PGS SIAP table to ObsTAP.
This works like //obscore#publish except some defaults apply
that copy fields that work analogously in SIAP and in ObsTAP.
For special situations, you can, of course, override any
of the parameters, but most of them should already be all right.
To find out what the parameters described as "preset for SIAP"
mean, refer to //obscore#publish.
Note: you must say ``dachs imp //obscore`` before anything
obscore-related will work.
'image'imageTitlecenterAlphacenterDeltapixelScale[1]*pixelSize[1]coveragedateObsdateObsbandpassLobandpassHi'em.opt'pixelScale[1]*3600instIdNULLpixelSize[1]pixelSize[2]pixelScale[1]*3600\sqlquote{\metaSeq{facility}{NULL}}
Publish a table mixing in //ssap#hcd to ObsTAP. Since //ssap#hcd
is deprecated, this should not be used in new RDs, either. For
//ssap#mixc tables, use publishSSAPMIXC.
This works like `the //obscore#publish mixin`_ except some defaults apply
that copy fields that work analogously in SSAP and in ObsTAP.
The columns already set in SSAP are marked as UNDOCUMENTED in the
parameter list below. For special situations, you can, of course,
override any of the parameters. To find out what they actually mean,
mean, refer to `the //obscore#publish mixin`_.
Note that this mixin does *not* set coverage (obscore: s_region).
This is because although we could make a circle from ssa_location
and ssa_aperture, circles are not allowed in DaCHS' s_region (which
has a fixed type of spoly). The recommended solution to still
have s_region is to add (and index) a custom field in the ssa table
and compute some sort of spolys for the coverage.
Note: you must say ``dachs imp //obscore`` before anything
obscore-related will work.
NULL\sqlquote{\getParam{ssa_collection}{NULL}}ssa_creatorDIDdegrees(lat(ssa_location))degrees(long(ssa_location))ssa_specendssa_specstartssa_timeExtssa_aperture\sqlquote{\getParam{ssa_instrument}{NULL}}\sqlquote{\getParam{ssa_fluxucd}}'spectrum'\getParam{ssa_spaceRes}{NULL}/3600.ssa_dateObs+ssa_timeExt/43200.ssa_dateObs-ssa_timeExt/43200.ssa_targnamessa_targclassssa_dstitle\sqlquote{\getParam{ssa_spectralucd}}ssa_pubDIDssa_length
Publish a table mixing in //ssap#view (or the deprecated //ssap#mixc)
to ObsTAP.
This works like `the //obscore#publish mixin`_ except some defaults apply
that copy fields that work analogously in SSAP and in ObsTAP.
The columns already set in SSAP are marked as UNDOCUMENTED in the
parameter list below. For special situations, you can, of course,
override any of the parameters. To find out what they actually mean,
mean, refer to `the //obscore#publish mixin`_.
Note that this mixin does *not* set coverage (obscore: s_region).
This is because although we could make a circle from ssa_location
and ssa_aperture, circles are not allowed in DaCHS' s_region (which
has a fixed type of spoly). The recommended solution to still
have s_region is to add (and index) a custom field; the
//ssap#simpleCoverage will do this.
Note: you must say ``dachs imp //obscore`` before anything
obscore-related will work.
NULLssa_collectionssa_creatorDIDdegrees(lat(ssa_location))degrees(long(ssa_location))ssa_specendssa_specstartssa_lengthssa_timeExtssa_aperturessa_instrument\sqlquote{\metaSeq{facility}{NULL}}\sqlquote{\getParam{ssa_fluxucd}}ssa_dstype\getParam{ssa_spaceRes}{NULL}/3600.ssa_dateObs+ssa_timeExt/43200.ssa_dateObs-ssa_timeExt/43200.ssa_targnamessa_targclassssa_dstitle\sqlquote{\getParam{ssa_spectralucd}}\sqlquote{\getParam{ssa_fluxucd}}ssa_specstart/ssa_specresssa_pubDID11
Publish a table that already has large parts of the obscore schema.
This has parameters called like the corresponding obscore columns
that also default to taking their data columns named like them.
Use this when you already have, by and large, and obscore structure
in your source table.
Note that this will *not* do the right thing with product#table
instances by default. For these, you will have to manually
map access_url, access_format, and access_estsize.
for column in context.getById("ObsCore").columns:
yield {'name': column.name, 'description': column.description}
\name
An empty table having all columns of the
obscore table. Useful internally, and sometimes for tricky queries.
publishhidden
if base.getConfig("ivoa", "materialiseObscore"):
yield {"createObscoreType": "preImport"}
else:
yield {"createObscoreType": "postCreation"}
create
\getConfig{web}{sitename} Obscore Datalink
A datalink service accompanying obscore. This will redirect to data
collection-specific datalink services if they exist or return extremely
basic datalinks otherwise.
from gavo import svcs
from gavo.protocols import products
class ObscoreDescriptor(ProductDescriptor):
def __init__(self,
pubDID, accessURL, accessSize,
mime, preview, sourceTable):
ProductDescriptor.__init__(self, pubDID, None,
accessURL, mime,
sourceTable=sourceTable, preview=preview)
self.accessSize = accessSize
self.suppressAutoLinks = True
currentHost = base.getCurrentServerURL()
with base.getTableConn() as conn:
res = list(conn.queryToDicts(
"SELECT"
" access_url, access_format, access_estsize,"
" preview, source_table"
" FROM ivoa.obscore"
" WHERE obs_publisher_did=%(pubdid)s",
{"pubdid": pubDID}))
if not res:
return DatalinkFault.NotFoundFault(pubDID,
"No data set with pubDID %s known here"%pubDID)
ocrow = res[0]
td = base.getTableDefForTable(conn, ocrow["source_table"])
dlid = base.getMetaText(td,
"_associatedDatalinkService.serviceId", default=None)
if dlid:
dlsvc = td.rd.getById(dlid)
dlurl = dlsvc.getURL("dlmeta")
raise svcs.Found(dlurl+"?ID="+urllib.parse.quote(pubDID))
return ObscoreDescriptor(
pubDID,
products.formatProductLink(ocrow["access_url"], currentHost),
ocrow["access_estsize"]*1024,
ocrow["access_format"],
products.formatProductLink(ocrow["preview"], currentHost),
ocrow["source_table"])
yield descriptor.makeLink(
descriptor.accessPath,
description="The main data product",
semantics="#this",
contentType=descriptor.mime,
contentLength=descriptor.accessSize)
if descriptor.preview:
yield descriptor.makeLink(
descriptor.preview,
description="A preview or thumbnail of the data",
semantics="#preview")