Package gavo :: Package rscdef :: Module coverage
[frames] | no frames]

Source Code for Module gavo.rscdef.coverage

  1  """ 
  2  The coverage RD element. 
  3   
  4  Most code to obtain coverage information from actual resources is in  
  5  gavo.user.info. 
  6  """ 
  7   
  8  #c Copyright 2008-2019, the GAVO project 
  9  #c 
 10  #c This program is free software, covered by the GNU GPL.  See the 
 11  #c COPYING file in the source distribution. 
 12   
 13   
 14  from gavo import base 
 15  from gavo import stc 
 16  from gavo import utils 
 17  from gavo.utils import pgsphere 
 18   
19 -class FloatInterval(base.AtomicAttribute):
20 """An attribute keeping a floating-point attribute. 21 22 The literal of these is as in VOTable: a whitespace-separated pair 23 for decimal floating-point literals. 24 """ 25 typeDesc_ = "A float interval (i.e., a space-separated pair of floats)" 26
27 - def parse(self, value):
28 try: 29 lower, upper = [float(f) for f in value.split()] 30 if lower>upper: 31 raise base.LiteralParseError(self.name_, value, 32 hint="In intervals, the lower value must be smaller or equal" 33 " to the upper one.") 34 return lower, upper 35 except (ValueError, TypeError): 36 raise base.LiteralParseError(self.name_, value, 37 hint="Intervals are represented as two floating-point literals" 38 " separated by whitespace.")
39
40 - def unparse(self, value):
41 return "%.10g %.10g"%value
42 43
44 -class FloatOrDateInterval(FloatInterval):
45 """An attribute keeping a temporal interval as MJD. 46 47 On literal input, we also allow ISO-like timestamps. You cannot 48 mix MJD and ISO, though. 49 """ 50 typeDesc_ = "A float or ISO timestamp interval (values separated by space)"
51 - def parse(self, value):
52 try: 53 return FloatInterval.parse(self, value) 54 except base.LiteralParseError: 55 try: 56 lower, upper = [stc.dateTimeToMJD(utils.parseISODT(f)) 57 for f in value.split()] 58 if lower>upper: 59 raise base.LiteralParseError(self.name_, value, 60 hint="In intervals, the lower value must be smaller or equal" 61 " to the upper one.") 62 return lower, upper 63 except (ValueError, TypeError): 64 raise base.LiteralParseError(self.name_, value, 65 hint="Time intervals are represented as two floating-point or" 66 " ISO timestamp literals separated by whitespace.")
67 68
69 -class Ranges(base.ListOfAtomsAttribute):
70 """An attribute definition for a list of intervals. 71 """ 72 typeDesc_ = "A sequence of intervals (a space-separated pair of floats" 73
74 - def __init__(self, name, intervalAttr, default=[], **kwargs):
75 base.ListOfAtomsAttribute.__init__( 76 self, name, default, intervalAttr, **kwargs)
77 78
79 -class Updater(base.Structure):
80 """Information on where and how to update a piece of coverage information. 81 """ 82 name_ = "updater" 83 84 # this stuff is interpreted by user.rdmanipulator.iterCoverageItems 85 _sourceTable = base.ReferenceAttribute("sourceTable", 86 default=base.NotGiven, 87 description="A table from which to compute coverage by default.", 88 copyable=True) 89 _spaceTable = base.ReferenceAttribute("spaceTable", 90 default=base.NotGiven, 91 description="A table from which to compute spatial coverage (overrides" 92 " sourceTable).", 93 copyable=True) 94 _timeTable = base.ReferenceAttribute("timeTable", 95 default=base.NotGiven, 96 description="A table from which to compute temporal coverage (overrides" 97 " sourceTable)", 98 copyable=True) 99 _spectralTable = base.ReferenceAttribute("spectralTable", 100 default=base.NotGiven, 101 description="A table from which to compute spectral coverage (overrides" 102 " sourceTable)", 103 copyable=True) 104 _mocOrder = base.IntAttribute("mocOrder", 105 default=6, 106 description="Maximal HEALpix order to use in coverage MOCs (6 is about" 107 " a degree resolution, each additional point doubles resolution).", 108 copyable=True)
109 110
111 -class Coverage(base.Structure):
112 """The coverage of a resource. 113 114 For now, this is attached to the complete resource rather than the table, 115 since this is where it sits in VOResource. DaCHS *could* be a bit 116 more flexible, allowing different coverages per publish element. It 117 is not right now, though. 118 119 Note: Technically, this will introduce or amend the coverage meta 120 element. The information given here will be masked if you define 121 a coverage meta on the service or table level. Just do not do that. 122 """ 123 name_ = "coverage" 124 125 _updater = base.StructAttribute("updater", 126 childFactory=Updater, 127 description="Rules for automatic computation or updating of" 128 " coverage information.", 129 default=base.NotGiven) 130 _spectral = Ranges("spectral", 131 FloatInterval( 132 "spectral", description="A wavelength interval"), 133 description="Interval(s) of spectral coverage, in meters of" 134 " BARYCENTER vacuum wavelength.") 135 _temporal = Ranges("temporal", 136 FloatOrDateInterval( 137 "temporal", description="A time interval"), 138 description="Interval(s) of temporal coverage, in MJD" 139 " (for TT BARYCENTER).") 140 _spatial = base.UnicodeAttribute("spatial", 141 default=base.NotGiven, 142 description="A MOC in ASCII representation giving the ICRS coverage" 143 " of the resource") 144
145 - def completeElement(self, ctx):
146 self._completeElementNext(Coverage, ctx) 147 if self.spatial is base.NotGiven: 148 self.parsedMOC = None 149 else: 150 self.parsedMOC = pgsphere.SMoc.fromASCII(self.spatial)
151
152 - def onParentComplete(self):
153 if self.spatial is not base.NotGiven: 154 self.parent.addMeta("coverage.spatial", self.spatial) 155 156 for interval in self.temporal: 157 self.parent.addMeta("coverage.temporal", 158 self._temporal.itemAttD.unparse(interval)) 159 160 for interval in self.spectral: 161 self.parent.addMeta("coverage.spectral", 162 self._spectral.itemAttD.unparse(interval))
163