astroplan icon indicating copy to clipboard operation
astroplan copied to clipboard

Hour angle constraint

Open mcoughlin opened this issue 2 years ago • 12 comments

This PR adds possibility of an hour angle constraint.

mcoughlin avatar Jun 21 '23 11:06 mcoughlin

Apologies @bmorris3. I fixed the linting issue.

mcoughlin avatar Jun 21 '23 15:06 mcoughlin

@mcoughlin Just a few more:

astroplan/constraints.py:947:69: W291 trailing whitespace
astroplan/constraints.py:948:26: W291 trailing whitespace
astroplan/tests/test_constraints.py:168:34: W291 trailing whitespace

bmorris3 avatar Jun 21 '23 16:06 bmorris3

@bmorris3 I think I got those in the last commit.

mcoughlin avatar Jun 21 '23 16:06 mcoughlin

Hi @mcoughlin,

Thanks for starting this constraint.

In astroplan we try to use full-precision astropy methods wherever possible, so that results from astroplan will agree with doing the calculation "the long way" via astropy. Astroplan already has a method for computing hour angle, so an hour angle constraint should use the result of this method:

https://github.com/astropy/astroplan/blob/67c0c6ba8467fc26ca79a7cef056eb38a066abd2/astroplan/observer.py#L1917-L1944

bmorris3 avatar Jun 23 '23 15:06 bmorris3

@bmorris3 We tried that and found the calculation quite slow for constraints. Maybe it makes sense to just have a warning in the doc string?

mcoughlin avatar Jun 23 '23 15:06 mcoughlin

I wonder why it's so slow. Is it possible that a different combination of arguments in the local_sidereal_time method would be faster? https://docs.astropy.org/en/stable/time/index.html#sidereal-time-and-earth-rotation-angle

bmorris3 avatar Jun 23 '23 16:06 bmorris3

@bmorris3 Not sure. I just fixed the PR to use Astropy by default though.

mcoughlin avatar Jun 23 '23 16:06 mcoughlin

@mhvk We're using astropy.time.Time.local_sidereal_time to compute LST in astroplan:

https://github.com/astropy/astroplan/blob/67c0c6ba8467fc26ca79a7cef056eb38a066abd2/astroplan/observer.py#L1914C29-L1915

Do you know if there are more performant options to give the LST functions, so that we can compute many accurate LSTs quickly (see https://github.com/astropy/astroplan/pull/560#issuecomment-1604482430)?

bmorris3 avatar Jun 26 '23 14:06 bmorris3

If you don't need full precision, you can avoid the correction for the TIO relative to longitude 0. Easiest is picking an old model, "iau1982", which doesn't have it -- this is a factor 4 faster and seems accurate to better than 4e-7 hours.

More accurate (1e-10 hours) and almost as fast is

time.sidereal_time(kind, longitude='tio', model=model) + self.location.lon

For planning purposes, either seems reasonable.

p.s. We probably should have something in our documentation about the speed differences...

mhvk avatar Jun 26 '23 16:06 mhvk

Thanks @mhvk ! @bmorris3 I gave that a whirl.

mcoughlin avatar Jun 26 '23 18:06 mcoughlin

@bmorris3 maybe you can retrigger the tests?

mcoughlin avatar Jul 06 '23 16:07 mcoughlin