Skip to content

Commit

Permalink
fix: add support for AzEl observations
Browse files Browse the repository at this point in the history
Adds check for empty radesys and functionality to handle AltAz (AzEl) coordinate frame
  • Loading branch information
astrofle committed May 30, 2024
1 parent f0925e3 commit 3c40e62
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/dysh/coordinates/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from astropy.coordinates.spectral_coordinate import (
DEFAULT_DISTANCE as _DEFAULT_DISTANCE,
)
from astropy.time import Time

_PMZERO = 0.0 * u.mas / u.yr
_PMZERORAD = 0.0 * u.rad / u.s
Expand Down Expand Up @@ -302,6 +303,21 @@ def sanitize_skycoord(target):
pm_b=pm_lat,
radial_velocity=_rv,
)
elif hasattr(target, "az"): # AzEl or AltAz
lon = target.az
lat = target.alt
pm_lon = target.pm_az_cosalt
pm_lat = target.pm_alt
_target = coord.SkyCoord(
lon,
lat,
frame=target.frame,
distance=newdistance,
pm_az_cosalt=pm_lon,
pm_alt=pm_lat,
radial_velocity=_rv,
)

else:
warnings.warn(f"Can't sanitize {target}")
return target
Expand Down Expand Up @@ -479,6 +495,8 @@ def make_target(header):
frame=header["RADESYS"].lower(),
radial_velocity=header["VELOCITY"] * _MPS,
distance=_DEFAULT_DISTANCE, # need this or PMs get units m rad /s !
obstime=Time(header["DATE-OBS"]),
location=gbt_location(),
)
# print(f"{t1},{t1.pm_ra_cosdec},{t1.pm_dec},{t1.distance},{t1.radial_velocity}")
target = sanitize_skycoord(t1)
Expand Down
12 changes: 12 additions & 0 deletions src/dysh/fits/gbtfitsload.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ def __init__(self, fileobj, source=None, hdu=None, **kwargs):
if lsdf > 1:
warnings.warn(f"Found {lsdf} FITS files") # or maybe just print()

self._update_radesys()

@property
def selection(self):
"""
Expand Down Expand Up @@ -1633,3 +1635,13 @@ def write_scans(self, fileobj, scans, output_verify="exception", overwrite=False
# write it out!
outhdu.update_extend() # possibly unneeded
outhdu.writeto(fileobj, output_verify=output_verify, overwrite=overwrite, checksum=checksum)

def _update_radesys(self):
""" """

mask = self._index["RADESYS"] == ""
if mask.sum() > 0:
warnings.warn("No RADESYS specified.")
azel_mask = (self._index["CTYPE2"] == "AZ") & (self._index["CTYPE3"] == "EL")
azel_radesys = "AltAz"
self._index.loc[azel_mask, "RADESYS"] = azel_radesys

0 comments on commit 3c40e62

Please sign in to comment.