diff --git a/src/dysh/coordinates/core.py b/src/dysh/coordinates/core.py index e71b6a49..6c13c470 100644 --- a/src/dysh/coordinates/core.py +++ b/src/dysh/coordinates/core.py @@ -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 @@ -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 @@ -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) diff --git a/src/dysh/fits/gbtfitsload.py b/src/dysh/fits/gbtfitsload.py index 57696e81..c996510c 100644 --- a/src/dysh/fits/gbtfitsload.py +++ b/src/dysh/fits/gbtfitsload.py @@ -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): """ @@ -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