# [AstroPy] Hour Angle from location and alt/az

Josh Walawender jmwalawender at gmail.com
Sat Nov 5 00:37:46 EDT 2016

```Hi John,

I solved a similar problem using the RA, DEC, and time from the header (and knowing the telescopes location) then just using the RA-LST method.  Here’s some (pseudo)code which calculates the HA for the mid point of the exposure (adjust as needed for start time if you like):

# Location of the observation
loc = EarthLocation(lat=cfg_loc['latitude’], lon=cfg_loc['longitude’], height=cfg_loc['elevation’])
# Read the start time and exposure time of the image from the header
# estimate the exposure mid time
midtime = starttime + exptime/2.0
# determine the sidereal time at the mid point of the exposure
sidereal = midtime.sidereal_time('apparent')
# read the position of the field from the header (assumes J2000)
## To calculate HA, we need to precess to the current equinox
## otherwise the RA - LST method will be off.
FK5_Jnow = FK5(equinox=midtime)

This was good enough for my purposes, but did seem a bit cumbersome.

-Josh

> On Nov 4, 2016, at 2:04 PM, John K. Parejko <parejkoj at uw.edu> wrote:
>
> Hello astropythians,
>
> I’m trying to work around a distinct lack of UT1 and LST in some telescope file headers, and was wondering if there’s a straight-forward astropy way to get a source’s Hour Angle from the alt/az, ra/dec, and telescope location. I can build an altaz SkyCoord, but I’m not sure what to do with it from there:
>
> loc = coord.EarthLocation.from_geodetic(long, lat, elevation)
> sky = coord.SkyCoord(az, alt, location=loc, frame='altaz', unit='deg’)
>
> I can’t transform this to ICRS:
>
> ipdb> sky.transform_to(coord.ICRS)
> *** TypeError: unsupported operand type(s) for -: 'NoneType' and ‘float’
>
> and there’s not an “hour_angle” method that I can see in either of those.
>
> Per the internet[1], one should be able to get HA from alt/az and dec directly (modulo refraction corrections):
>
> HA = asin(- sin(az)*cos(alt) / cos(dec))
>
> I can do that, but I was hoping for a nice and tidy astropy method.
>
> Thanks,
> John
>
> 1: http://star-www.st-and.ac.uk/~fv/webnotes/chapter7.htm
>
> --
> *************************
> John Parejko
> parejkoj at uw.edu
> http://staff.washington.edu/parejkoj/
> Department of Physics and Astronomy
> University of Washington
> Seattle, WA
> **************************
>
>
>
>
>
>
>
>
>
>
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> https://mail.scipy.org/mailman/listinfo/astropy

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20161104/8c19257a/attachment.html>
```