A table mixin for simple support of SIAP.
The columns added into the tables include
- (certain) FITS WCS headers
- imageTitle (interpolateString should come in handy for these)
- instId -- some id for the instrument used
- dateObs -- MJD of the "characteristic" observation time
- the bandpass* values. You're on your own with them...
- the values of the product mixin.
- mimetype -- the mime type of the product.
- the coverage, centerAlpha and centerDelta, nAxes,
pixelSize, pixelScale, wcs* fields calculated by the
computePGS macro.
(their definition is in the siap system RD)
Tables mixing in pgs can be used for SIAP querying and
automatically mix in the products table mixin.
To feed these tables, use the //siap#computePGS and
//siap#setMeta procs. Since you are dealing with products,
you will also need the //products#define rowgen in your grammar.
Polygon ICRS [coverage] Position "centerAlpha" "centerDelta"
SpectralInterval "bandpassLo" "bandpassHi" Spectral "bandpassRefval"
unit m
(votable:Coords) {
time: {
frame: {
timescale: TT
refPosition: UNKNOWN
time0: MJD-origin
}
location: @dateObs
}
}
Computes WCS information for SIA tables from FITS WCS keys.
It takes no arguments but expects WCS-like keywords in rowdict, i.e.,
CRVAL1, CRVAL2 (interpreted as float deg), CRPIX1, CRPIX2 (pixel
corresponding to CRVAL1, CRVAL2), CUNIT1, CUNIT2 (pixel scale unit,
we bail out if it isn't deg and assume deg when it's not present),
CDn_n (the transformation matrix; substitutable by CDELTn), NAXISn
(the image size).
Records without or with insufficient wcs keys are furnished with
all-NULL wcs info if the missingIsError setup parameter is False,
else they bomb out with a DataError (the default).
True"1,2"
from gavo.protocols import siap
wcskeys = ["centerAlpha", "centerDelta",
"nAxes", "pixelSize", "pixelScale", "wcs_projection",
"wcs_refPixel", "wcs_refValues", "wcs_cdmatrix", "wcs_equinox"]
naxis = [int(v) for v in naxis.split(",")]
class PixelGauge(object):
"""is a container for information about pixel sizes.
It is constructed with an wcs.WCS instance and an (x, y)
pair of pixel coordinates that should be close to the center
of the frame.
"""
def __init__(self, wcs, centerPix):
self.centerPos = coords.pix2sky(wcs, centerPix)
self.pixelScale = coords.getPixelSizeDeg(wcs)
offCenterPos = coords.pix2sky(wcs,
(centerPix[0]+1, centerPix[1]+1))
def copyFromWCS(vars, wcs, result):
"""adds the "simple" WCS keys from the wcstools instance wcs to
the record result.
"""
result["mime"] = "application/fits"
result["centerAlpha"], result["centerDelta"
] = coords.getCenterFromWCSFields(wcs)
result["nAxes"] = int(vars["NAXIS"])
axeInds = range(1, result["nAxes"]+1)
dims = list(int(vars["NAXIS%d"%i])
for i in axeInds)
pixelGauge = PixelGauge(wcs, (dims[0]/2., dims[1]/2.))
result["pixelSize"] = dims
result["pixelScale"] = list(pixelGauge.pixelScale)
result["wcs_projection"] = vars.get("CTYPE1")
if result["wcs_projection"]:
result["wcs_projection"] = result["wcs_projection"][5:8]
result["wcs_refPixel"] = list(wcs.wcs.crpix)
result["wcs_refValues"] = list(wcs.wcs.crval)
result["wcs_cdmatrix"] = list(
(wcs.wcs.get_pc()*wcs.wcs.get_cdelt()).ravel())
result["wcs_equinox"] = vars.get("EQUINOX", None)
def nullOutWCS(result, additionalKeys):
"""clears all wcs fields, plus the ones in additonalKeys.
"""
for key in wcskeys+additionalKeys:
result[key] = None
def addWCS(vars, result, additionalKeys, addCoverage):
wcs = coords.getWCS(vars, naxis=naxis)
if wcs is None:
if missingIsError:
raise base.DataError("No WCS information")
else:
nullOutWCS(result, additionalKeys)
else:
copyFromWCS(vars, wcs, result)
addCoverage(vars, wcs, result)
additionalKeys = ["coverage"]
def addCoverage(vars, wcs, result):
result["coverage"] = coords.getSpolyFromWCSFields(wcs)
try:
addWCS(vars, result, additionalKeys, addCoverage)
except KeyError:
# presumably some basic FITS keyword missing
if missingIsError:
raise
sets siap meta *and* product table fields.
These fields are common to all SIAP implementations.
If you define the bandpasses yourself, do *not* change
bandpassUnit and give all values in Meters. If you do change
it, at least obscore would break, but probably more.
For optical images, we recommend to fill out bandpassId and then
let the //siap#getBandFromFilter apply compute the actual
limits. If your band is not known, please supply the
necessary information to the authors.
Do *not* use ``idmaps="*"`` when using this procDef; it writes
directly into result, and you would be clobbering what it does.
Nonestr(rd.getMeta("instrument"))NoneNone"m"NoneNoneNone'ICRS'None
if bandpassUnit!="m":
base.ui.NotifyWarning("//siap#setMeta has bandpassUnit!=m."
" That's going to be trouble at the very least.")
result["dateObs"] = toMJD(dateObs)
result["imageTitle"] = title
result["instId"] = instrument
result["bandpassId"] = bandpassId
result["bandpassUnit"] = bandpassUnit
result["bandpassRefval"] = bandpassRefval
result["bandpassHi"] = bandpassHi
result["bandpassLo"] = bandpassLo
result["refFrame"] = refFrame
result["pixflags"] = pixflags
sets the bandpassId, bandpassUnit, bandpassRefval, bandpassHi,
and bandpassLo from a set of standard band Ids.
The bandpass ids known are contained in a file supplied by
DaCHS that you should consult for supported values by running
``dachs admin dumpDF data/filters.txt``.
If you pass in an unknown filter name, no keys will be generated,
but no diagnostics will be emitted either. Make sure to dachs info
on the imported table if you expect no NULLs in the bandpass
columns.
All values filled in here are in meters.
If this is used, it must run after //siap#setMeta since
setMeta clobbers our result fields.
None
_filterMap, _aliases = base.getFilterMap()
def setBandpass(result, filterId):
if not _filterMap:
parseFilterMap()
try:
short, mid, long = _filterMap[_aliases.get(filterId, filterId)]
except KeyError: # nothing known, do nothing
return
result["bandpassId"] = filterId
result["bandpassUnit"] = "m"
result["bandpassRefval"] = mid
result["bandpassLo"] = short
result["bandpassHi"] = long
if sourceCol is None:
val = result['bandpassId']
else:
val = vars[sourceCol]
setBandpass(result, val)
from gavo import rscdef
from gavo.protocols import siap
def interpretFormat(inPars, sqlPars):
# Interprets a SIA FORMAT parameter. METADATA is caught by the
# SIAP renderer, which of the magic values leaves ALL and
# GRAPHIC to us.
fmt = inPars.get("FORMAT")
if fmt=="image/fits":
fmt = "application/fits"
if fmt is None or fmt=="ALL":
return ""
elif fmt=="GRAPHIC":
return "mime IN %%(%s)s"%base.getSQLKey("format",
base.getConfig("web", "graphicMimes"), sqlPars)
else:
return "mime=%%(%s)s"%base.getSQLKey(
"format", fmt, sqlPars)
def getQueriedTable(inputKeys):
"""tries to infer the table queried from the inputKeys passed to
the condDesc.
This will return None if it cannot find this parent table.
"""
try:
res = inputKeys[0].parent.parent.queriedTable
except (AttributeError, IndexError):
traceback.print_exc()
return None
if not isinstance(res, rscdef.TableDef):
return None
return res
siap.xmlsiap.xmlOVERLAPSsiap.xmlGRAPHICsiap.xml
yield siap.getQuery(getQueriedTable(inputKeys), inPars, outPars)
yield interpretFormat(inPars, outPars)
siap.xmlsiap.xmlsiap.xmlGRAPHICsiap.xml
pos = inPars["hPOS"]
try:
ra, dec = base.parseCooPair(pos)
except ValueError:
data = base.caches.getSesame("web").query(pos)
if not data:
raise base.ValidationError("%r is neither a RA,DEC pair nor"
" a simbad resolvable object"%inPars.get("hPOS", "Not given"),
"hPOS")
ra, dec = float(data["RA"]), float(data["dec"])
inPars = {
"POS": "%f, %f"%(ra, dec), "SIZE": inPars["hSIZE"],
"INTERSECT": inPars["hINTERSECT"], "FORMAT": inPars.get("hFORMAT")}
yield siap.getQuery(getQueriedTable(inputKeys), inPars, outPars)
yield interpretFormat(inPars, outPars)