| 1 |
""" |
| 2 |
Tests for time series serialisation, discovery, and the like. |
| 3 |
""" |
| 4 |
|
| 5 |
#c Copyright 2008-2025, the GAVO project <[email protected]> |
| 6 |
#c |
| 7 |
#c This program is free software, covered by the GNU GPL. See the |
| 8 |
#c COPYING file in the source distribution. |
| 9 |
|
| 10 |
|
| 11 |
from gavo.helpers import testhelpers |
| 12 |
|
| 13 |
from gavo import api |
| 14 |
|
| 15 |
|
| 16 |
class _FullPhoto0TS(testhelpers.TestResource): |
| 17 |
"""A time series using the timeseries#photo0 mixin with all pars filled |
| 18 |
out and a few extra columns. |
| 19 |
""" |
| 20 |
def make(self, deps): |
| 21 |
rd = api.parseFromString(api.RD, """<resource schema="test"> |
| 22 |
<table id="instance"> |
| 23 |
<mixin |
| 24 |
timescale="UTC" |
| 25 |
refposition="TOPOCENTER" |
| 26 |
time0="2400000.5" |
| 27 |
|
| 28 |
refframe="ICRS" |
| 29 |
pos_epoch="J2020.56" |
| 30 |
longitude="@ra" |
| 31 |
latitude="@dec" |
| 32 |
|
| 33 |
independent_axes="[@obs_time @obs_time_reduced]" |
| 34 |
dependent_axes="[@phot @mag @xray]" |
| 35 |
|
| 36 |
filterIdentifier="@ssa_bandpass" |
| 37 |
zeroPointFlux="2000" |
| 38 |
magnitudeSystem="Vega" |
| 39 |
effectiveWavelength="5e-7" |
| 40 |
|
| 41 |
time_description="Detection time" |
| 42 |
phot_description="Reduced V-band flux" |
| 43 |
phot_unit="Jy" |
| 44 |
phot_ucd="phot.flux;em.opt.V" |
| 45 |
>//timeseries#phot-0</mixin> |
| 46 |
|
| 47 |
<dm> |
| 48 |
(phot:PhotCal) { |
| 49 |
filterIdentifier: "Johnson/V" |
| 50 |
magnitudeSystem: Vega |
| 51 |
zeroPointFlux: 2000 |
| 52 |
effectiveWavelength: 5e-7 |
| 53 |
value: @mag |
| 54 |
} |
| 55 |
</dm> |
| 56 |
|
| 57 |
<dm> |
| 58 |
(phot:PhotCal) { |
| 59 |
filterIdentifier: "XMM/Hardrock" |
| 60 |
effectiveWavelength: 1e-10 |
| 61 |
value: @xray |
| 62 |
} |
| 63 |
</dm> |
| 64 |
|
| 65 |
<dm> |
| 66 |
(ivoa:Measurement) { |
| 67 |
value: @phot |
| 68 |
statError: @phot_error |
| 69 |
} |
| 70 |
</dm> |
| 71 |
|
| 72 |
<dm> |
| 73 |
(votable:Coords) { |
| 74 |
time: (votable:TimeCoordinate) { |
| 75 |
frame: |
| 76 |
(votable:TimeFrame) { |
| 77 |
timescale: TCB |
| 78 |
refPosition: BARYCENTER |
| 79 |
time0: 0 } |
| 80 |
location: @obs_time_reduced |
| 81 |
} |
| 82 |
space: |
| 83 |
(votable:SphericalCoordinate) { |
| 84 |
frame: (votable:SpaceFrame) { |
| 85 |
orientation: ICRS |
| 86 |
epoch: J2020.56 } |
| 87 |
longitude: @ra |
| 88 |
latitude: @dec |
| 89 |
} |
| 90 |
} |
| 91 |
</dm> |
| 92 |
|
| 93 |
<param name="ra" ucd="pos.eq.ra">299.59031591</param> |
| 94 |
<param name="dec" ucd="pos.eq.dec">35.20160625</param> |
| 95 |
<param name="ssa_bandpass" type="text">Johnson V</param> |
| 96 |
|
| 97 |
<column name="obs_time_reduced" ucd="time.epoch"/> |
| 98 |
<column name="mag" ucd="phot.mag;em.opt.V" unit="mag"/> |
| 99 |
<column name="xray" ucd="phot.flux;em.xray.hard" unit="Jy"/> |
| 100 |
<column name="phot_error" ucd="stat.error;phot.flux;em.opt.V" |
| 101 |
unit="Jy"/> |
| 102 |
</table> |
| 103 |
</resource>""") |
| 104 |
table = api.TableForDef(rd.getById("instance"), |
| 105 |
rows=[dict(obs_time=56321, obs_time_reduced=2456320.996, |
| 106 |
phot=125, phot_error=0.23, mag=6.5, xray=10.3)]) |
| 107 |
return testhelpers.getXMLTree( |
| 108 |
api.getFormatted("vodml", table), debug=False) |
| 109 |
|
| 110 |
|
| 111 |
class FullPhoto0Test(testhelpers.VerboseTest): |
| 112 |
resources = [("tree", _FullPhoto0TS())] |
| 113 |
|
| 114 |
def testDataproductType(self): |
| 115 |
dpPar = self.tree.uniqueXpath( |
| 116 |
"RESOURCE/TABLE/PARAM[@name='dataproduct_type']") |
| 117 |
self.assertEqual(dpPar.get("value"), "timeseries") |
| 118 |
self.assertEqual(dpPar.get("ucd"), "meta.code.class") |
| 119 |
self.assertEqual(dpPar.get("utype"), "obscore:ObsDataset.dataProductType") |
| 120 |
|
| 121 |
def testDataproductSubtype(self): |
| 122 |
dpPar = self.tree.uniqueXpath( |
| 123 |
"RESOURCE/TABLE/PARAM[@name='dataproduct_subtype']") |
| 124 |
self.assertEqual(dpPar.get("value"), "lightcurve") |
| 125 |
self.assertEqual(dpPar.get("ucd"), "meta.code.class") |
| 126 |
self.assertEqual( |
| 127 |
dpPar.get("utype"), "obscore:ObsDataset.dataProductSubtype") |
| 128 |
|
| 129 |
def testCoosys(self): |
| 130 |
coosysID = self.tree.uniqueXpath("//PARAM[@name='ra']").get("ref") |
| 131 |
cs = self.tree.getByID(coosysID) |
| 132 |
self.assertEqual(cs.get("epoch"), "J2020.56") |
| 133 |
self.assertEqual(cs.get("system"), "ICRS") |
| 134 |
|
| 135 |
def testTimesys1(self): |
| 136 |
ts = self.tree.getByID( |
| 137 |
self.tree.uniqueXpath("//FIELD[@name='obs_time']").get("ref")) |
| 138 |
self.assertEqual(ts.get("refposition"), "TOPOCENTER") |
| 139 |
self.assertEqual(ts.get("timeorigin"), "2400000.5") |
| 140 |
self.assertEqual(ts.get("timescale"), "UTC") |
| 141 |
|
| 142 |
def testTimesys2(self): |
| 143 |
ts = self.tree.getByID( |
| 144 |
self.tree.uniqueXpath("//FIELD[@name='obs_time_reduced']").get("ref")) |
| 145 |
self.assertEqual(ts.get("refposition"), "BARYCENTER") |
| 146 |
self.assertEqual(ts.get("timeorigin"), "0") |
| 147 |
self.assertEqual(ts.get("timescale"), "TCB") |
| 148 |
|
| 149 |
def testCubeIndepAxes(self): |
| 150 |
self.assertEqual( |
| 151 |
self.tree.xpath("//INSTANCE[@dmtype='ndcube:Cube']/" |
| 152 |
"ATTRIBUTE[@dmrole='independent_axes']/COLLECTION/ATTRIBUTE/@ref"), |
| 153 |
["obs_time", "obs_time_reduced"]) |
| 154 |
|
| 155 |
def testCubeDepAxes(self): |
| 156 |
self.assertEqual( |
| 157 |
self.tree.xpath("//INSTANCE[@dmtype='ndcube:Cube']/" |
| 158 |
"ATTRIBUTE[@dmrole='dependent_axes']/COLLECTION/ATTRIBUTE/@ref"), |
| 159 |
["phot", "mag", "xray"]) |
| 160 |
|
| 161 |
def testDefaultPhotcal(self): |
| 162 |
pg = self.tree.getByID( |
| 163 |
self.tree.getByID("phot").get("ref")) |
| 164 |
self.assertEqual("2000", |
| 165 |
pg.xpath("PARAM[@name='zeroPointFlux']")[0].get("value")) |
| 166 |
self.assertEqual("Vega", |
| 167 |
pg.xpath("PARAM[@name='magnitudeSystem']")[0].get("value")) |
| 168 |
self.assertEqual("5e-7", |
| 169 |
pg.xpath("PARAM[@name='effectiveWavelength']")[0].get("value")) |
| 170 |
|
| 171 |
def testParametersReferencing(self): |
| 172 |
pg = self.tree.getByID( |
| 173 |
self.tree.getByID("phot").get("ref")) |
| 174 |
paramId = pg.xpath("PARAMref[@utype='photDM:PhotometryFilter.identifier']" |
| 175 |
)[0].get("ref") |
| 176 |
self.assertEqual(self.tree.getByID(paramId).get("value"), "Johnson V") |
| 177 |
|
| 178 |
def testXrayPhotcal(self): |
| 179 |
pg = self.tree.getByID( |
| 180 |
self.tree.getByID("xray").get("ref")) |
| 181 |
self.assertEqual("XMM/Hardrock", |
| 182 |
pg.xpath("PARAM[@name='filterIdentifier']")[0].get("value")) |
| 183 |
self.assertEqual("1e-10", |
| 184 |
pg.xpath("PARAM[@name='effectiveWavelength']")[0].get("value")) |
| 185 |
self.assertEqual([], |
| 186 |
pg.xpath("PARAM[@name='zeroPointFlux']")) |
| 187 |
self.assertEqual([], |
| 188 |
pg.xpath("PARAM[@name='magnitudeSystem']")) |
| 189 |
|
| 190 |
def testPhotMetadata(self): |
| 191 |
f = self.tree.uniqueXpath("//FIELD[@name='phot']") |
| 192 |
self.assertEqual(f.get("unit"), "Jy") |
| 193 |
self.assertEqual(f.get("ucd"), "phot.flux;em.opt.V") |
| 194 |
self.assertEqual( |
| 195 |
f.xpath("DESCRIPTION")[0].text, |
| 196 |
"Reduced V-band flux") |
| 197 |
|
| 198 |
def testTimeMetadata(self): |
| 199 |
f = self.tree.uniqueXpath("//FIELD[@name='obs_time']") |
| 200 |
self.assertEqual(f.get("unit"), "d") |
| 201 |
self.assertEqual(f.get("ucd"), "time.epoch") |
| 202 |
self.assertEqual( |
| 203 |
f.xpath("DESCRIPTION")[0].text, |
| 204 |
"Detection time") |
| 205 |
|
| 206 |
def testForwardReferences(self): |
| 207 |
self.assertEqual( |
| 208 |
self.tree.xpath("//*[@utype='adhoc:location']/@ref"), |
| 209 |
["phot", "mag", "xray"]) |
| 210 |
|
| 211 |
|
| 212 |
class _MinimalPhoto0TS(testhelpers.TestResource): |
| 213 |
"""A time series using the timeseries#photo0 mixin with only the |
| 214 |
mandatory pars filled out and obs_time overridden. |
| 215 |
""" |
| 216 |
def make(self, deps): |
| 217 |
rd = api.parseFromString(api.RD, """<resource schema="test"> |
| 218 |
<table id="instance"> |
| 219 |
<mixin |
| 220 |
timescale="UTC" |
| 221 |
refposition="TOPOCENTER" |
| 222 |
time0="2440587.5" |
| 223 |
|
| 224 |
filterIdentifier='"Johnson/V"' |
| 225 |
effectiveWavelength="5e-7" |
| 226 |
|
| 227 |
phot_unit="Jy" |
| 228 |
phot_ucd="phot.flux;em.opt.V" |
| 229 |
>//timeseries#phot-0</mixin> |
| 230 |
<column original="obs_time" unit="s"/> |
| 231 |
</table> |
| 232 |
</resource>""") |
| 233 |
table = api.TableForDef(rd.getById("instance"), |
| 234 |
rows=[dict(obs_time=1.45e9, phot=125,)]) |
| 235 |
return testhelpers.getXMLTree( |
| 236 |
api.getFormatted("vodml", table), debug=False) |
| 237 |
|
| 238 |
|
| 239 |
class MinimalPhot0Test(testhelpers.VerboseTest): |
| 240 |
resources = [("tree", _MinimalPhoto0TS())] |
| 241 |
|
| 242 |
def testDataproductType(self): |
| 243 |
dpPar = self.tree.uniqueXpath( |
| 244 |
"RESOURCE/TABLE/PARAM[@name='dataproduct_type']") |
| 245 |
self.assertEqual(dpPar.get("value"), "timeseries") |
| 246 |
self.assertEqual(dpPar.get("ucd"), "meta.code.class") |
| 247 |
self.assertEqual(dpPar.get("utype"), "obscore:ObsDataset.dataProductType") |
| 248 |
|
| 249 |
def testTimeMetaOverridden(self): |
| 250 |
f = self.tree.uniqueXpath("//FIELD[@name='obs_time']") |
| 251 |
self.assertEqual(f.get("unit"), "s") |
| 252 |
|
| 253 |
def testNoParamJunk(self): |
| 254 |
self.assertEqual( |
| 255 |
self.tree.xpath("//PARAM[@name='effectiveWavelength']/@value"), |
| 256 |
['5e-7']) |
| 257 |
|
| 258 |
self.assertEqual( |
| 259 |
self.tree.xpath("//PARAM[@name='zeroPointFlux']"), |
| 260 |
[]) |
| 261 |
|
| 262 |
if __name__=="__main__": |
| 263 |
testhelpers.main(FullPhoto0Test) |