astropy / pyvo

An Astropy affiliated package providing access to remote data and services of the Virtual Observatory (VO) using Python.
https://pyvo.readthedocs.io/en/latest
BSD 3-Clause "New" or "Revised" License
74 stars 50 forks source link

DatalinkRecord should have a backlink to the originating record #542

Open msdemlei opened 2 months ago

msdemlei commented 2 months ago

When using datalink, one sometimes wants to go back to the table row the datalink originally came from. As an example, assume you want to make Hα maps from spectral cubes; you will need the redshift of the source object for that, and that you can presumably only get from the original record.

Here's some code illustrating the problem:

import pyvo

l0 = 6.5625e-7

svc = pyvo.dal.TAPService("http://dc.g-vo.org/tap")
results = svc.run_sync("select top 5 * from califa.cubes
  natural join califa.objects")

for dl in results.iter_datalinks():
  redshift = *** dl.original["redshift"] ***
  lobs = l0*(1+redshift)
  map = next(dl.bysemantics("#this")).processed(band=(lobs, lobs))

The trouble: This doesn't work at the moment, because there's no "original" attribute on DatalinkRecord-s. To work around this, people would have to figure out the key used by the datalink machinery (which, incidentally, is not pretty in pyVO either, but that's perhaps not a real problem) and then go back to the original table with the datalink.id. That's really not nice.

What I'd suggest instead is that we add an attribute ("original" is perhaps not the best name) or a function ("get_originating_row()") that makes it easy to pull out the record in the original table corresponding to datalink.id.

Opinions? I'd donate an implementation (which shouldn't be hard anyway), but I'd first like to make sure I'm not missing anything -- and whether anyone has ideas for how to make this a pretty and obvious API.