DKISTDC / dkist

A Python library for obtaining, processing and interacting with calibrated DKIST data.
https://docs.dkist.nso.edu/projects/python-tools/
BSD 3-Clause "New" or "Revised" License
26 stars 13 forks source link

Convert the "Bounding Box" column in a Fido search result to a SkyCoord column #341

Open Cadair opened 8 months ago

Cadair commented 8 months ago

I got this far:

In [105]: res
Out[105]: 
<dkist.net.client.DKISTQueryResponseTable object at 0x7f3db14d3910>
       Start Time               End Time        Instrument               Wavelength                                     Bounding Box                      ... Has Temporal Axis Average Spectral Sampling Average Spatial Sampling Average Temporal Sampling
                                                                             nm                                        arcsec,arcsec                      ...                               nm                     arcsec                      s            
----------------------- ----------------------- ---------- -------------------------------------- ------------------------------------------------------- ... ----------------- ------------------------- ------------------------ -------------------------
2023-10-16T22:02:47.512 2023-10-16T22:03:21.326       VISP 853.7002737559743 .. 854.6361356847904    -69.97999999998137,102.6 .. -141.62999999988824,53.6 ...              True      0.000999852488051306      0.03647318432948004        16.906828252790408

In [105]: coords = np.array(list(map(literal_eval, res["Bounding Box"])))

In [106]: observer = EarthLocation.of_site("DKIST").get_itrs(res["Start Time"])

In [107]: observer = observer.transform_to(sunpy.coordinates.HeliographicStonyhurst(obstime=res["Start Time"]))

In [108]: res["Bounding Box"] = SkyCoord(coords[..., 0], coords[..., 1], unit=u.arcsec, frame="helioprojective", obstime=res["Start Time"][:, None], observer=observer[:, None])
Cadair commented 8 months ago

Note: The dataset API uses top_right, lower_left ordering and sunpy uses lower_left, top_right everywhere so we might want to flip them around to match the sunpy convention.

Cadair commented 8 months ago

Here's a complete implementation of a function which transforms the BoundingBox coord:

def dkist_fido_convert_bb(res):
    res = res.copy()
    coords = np.array(list(map(literal_eval, res["Bounding Box"])))
    observer = EarthLocation.of_site("DKIST").get_itrs(res["Start Time"])
    observer = observer.transform_to(sunpy.coordinates.HeliographicStonyhurst(obstime=res["Start Time"]))
    res["Bounding Box"] = SkyCoord(coords[..., 0][:, ::-1], coords[..., 1][:, ::-1], unit=u.arcsec, frame="helioprojective", obstime=res["Start Time"][:, None], observer=observer[:, None])
    return res