Skip to content

Fix broadcasting by using vector SkyCoords internally [WIP] - #285

Merged
bmorris3 merged 17 commits into
astropy:masterfrom
StuartLittlefair:no_target_lists
Feb 23, 2017
Merged

bmorris3 merged 17 commits into
astropy:masterfrom
StuartLittlefair:no_target_lists

Conversation

@StuartLittlefair

@StuartLittlefair StuartLittlefair commented Feb 2, 2017 •

Copy link
Copy Markdown
Contributor

As described in #215, I think there's an argument for all internal calculations converting their arguments to Time and SkyCoord objects, which may be vector. This PR builds on the utility function in #215 and implements this functionality. It's a large change in the observer codebase, but outward facing functionality should be compatible with how it was before. However, there are so many unassociated test failures from other issues with astropy 1.3 it's hard to know, hence the WIP designation.

Once complete, this PR could fix remaining broadcasting issues with astropy 1.3 (e.g #282, #263, #272).

Some notes:

  • This PR requires astropy 1.3 as a minimum version.
  • Although behaviour for scalar times and targets is unchanged, there is an improvement (IMO) in functionality for multiple times and targets. I briefly describe that here.

This PR should give identical behaviour to the existing astroplan code, though the internals of the observer module have changed quite a lot. Please disregard the code samples below - I've left them in the comment for historical purposes

First - for scalar objects:

In [2]:  apo = Observer.at_site("APO")
In [3]:  times = Time(2457786.9048868627, format='jd')
In [4]:  m31 = coord.SkyCoord.from_name('M31')
In [5]:  apo.altaz(times, m31)
Out[5]: 
<SkyCoord (AltAz: obstime=2017-02-02 09:43:02.224949, location=(-1463969.3018517173, -5166673.342234327, 3434985.7120456537) m, pressure=0.0 hPa, temperature=0.0 deg_C, relative_humidity=0, obswl=1.0 micron): (az, alt) in deg
    ( 346.02166236, -13.98494769)>

However, if the times and targets are 1D and broadcastable, altaz and similar calcs will broadcast automatically:

In [6]: ippeg = coord.SkyCoord.from_name('IP Peg')
In [7]: deneb = coord.SkyCoord.from_name('Deneb')
In [8]: times = times + np.linspace(-0.3, 0.3, 3)*u.d
In [9]: apo.altaz(times, [m31, ippeg, deneb])
Out[9]: 
<SkyCoord (AltAz: obstime=[datetime.datetime(2017, 2, 2, 2, 31, 2, 224949)
 datetime.datetime(2017, 2, 2, 9, 43, 2, 224949)
 datetime.datetime(2017, 2, 2, 16, 55, 2, 224949)], location=(-1463969.3018517173, -5166673.342234327, 3434985.7120456537) m, pressure=0.0 hPa, temperature=0.0 deg_C, relative_humidity=0, obswl=1.0 micron): (az, alt) in deg
    [( 297.48755926,  47.14479827), (   2.09385352, -38.68372101),
     (  52.36092567,  64.09699143)]>

also works with lists of FixedTargets

In [11]: apo.altaz(times, [FixedTarget(targ) for targ in [m31, ippeg, deneb]])
Out[11]: 
<SkyCoord (AltAz: obstime=[datetime.datetime(2017, 2, 2, 2, 31, 2, 224949)
 datetime.datetime(2017, 2, 2, 9, 43, 2, 224949)
 datetime.datetime(2017, 2, 2, 16, 55, 2, 224949)], location=(-1463969.3018517173, -5166673.342234327, 3434985.7120456537) m, pressure=0.0 hPa, temperature=0.0 deg_C, relative_humidity=0, obswl=1.0 micron): (az, alt) in deg
    [( 297.48755926,  47.14479827), (   2.09385352, -38.68372101),
     (  52.36092567,  64.09699143)]>

So far the same. But using vector skycoords internally adds functionality, since the horizon argument to the observer routines can be non-scalar and it will work as long as you can broadcast the horizon and altaz results:

In [12]: apo.target_is_up(times, [m31, ippeg, deneb], horizon=u.Quantity([50*u.deg, 0*u.deg, 20*u.deg]))
Out[12]: array([False, False,  True], dtype=bool)
In [13]: apo.target_is_up(times, [m31, ippeg, deneb])
Out[13]: array([ True, False,  True], dtype=bool)

Also, by manipulating the shape of the times and targets object you can create a grid of altaz at all times and targets, rather than broadcasting, e.g:

In [19]: apo.altaz(times[:, np.newaxis], [m31, ippeg, deneb])
Out[19]: 
<SkyCoord (AltAz: obstime=[[datetime.datetime(2017, 2, 2, 2, 31, 2, 224949)
  datetime.datetime(2017, 2, 2, 2, 31, 2, 224949)
  datetime.datetime(2017, 2, 2, 2, 31, 2, 224949)]
 [datetime.datetime(2017, 2, 2, 9, 43, 2, 224949)
  datetime.datetime(2017, 2, 2, 9, 43, 2, 224949)
  datetime.datetime(2017, 2, 2, 9, 43, 2, 224949)]
 [datetime.datetime(2017, 2, 2, 16, 55, 2, 224949)
  datetime.datetime(2017, 2, 2, 16, 55, 2, 224949)
  datetime.datetime(2017, 2, 2, 16, 55, 2, 224949)]], location=(-1463969.3018517173, -5166673.342234327, 3434985.7120456537) m, pressure=0.0 hPa, temperature=0.0 deg_C, relative_humidity=0, obswl=1.0 micron): (az, alt) in deg
    [[( 297.48755926,  47.14479827), ( 277.5507293 ,  23.53321076),
      ( 319.5051457 ,   8.36398593)],
     [( 346.02166236, -13.98494769), (   2.09385352, -38.68372101),
      (  28.22799217,  -3.00973326)],
     [(  53.52265937,  21.03003458), (  84.15855299,  26.41118594),
      (  52.36092567,  64.09699143)]]>

Although I haven't timed the performance I suspect it will be faster than the old, non-vectorised code as well.

There are still some issues with using vector Times or SkyCoords with higher dimensionality - see TODO note in _horiz_cross.

@StuartLittlefair

Copy link
Copy Markdown
Contributor Author

@bsipocz Can you take a look at this PR? I've so many other issues with my local build (the remote test issues etc) that I can't test it properly, but it may address the broadcasting issues. Is there an easy way to make a local copy of a branch with all the prior fixes so I can test thoroughly? I'm a bit git-challenged!

@bmorris3 - this is a really big change to the code, so you probably want to take a look as well.

@bsipocz

bsipocz commented Feb 2, 2017

Copy link
Copy Markdown
Member

@StuartLittlefair - Sure, I've merged this into the testing branch, test are running here: https://travis-ci.org/bsipocz/astroplan/builds/197593459
There were quite a few conflicts, but hopefully I got them resolved properly.

@bsipocz

bsipocz commented Feb 2, 2017

Copy link
Copy Markdown
Member

@bsipocz

bsipocz commented Feb 2, 2017

Copy link
Copy Markdown
Member

Ohh, and I forgot to answer the question: usually for testing multiple PRs, I usually open a new separate test branch and merge in the PRs there. If you have travis turned on your fork, this would do the tests there.

@StuartLittlefair

Copy link
Copy Markdown
Contributor Author

I think the failures are real.

There's something that needs discussion here - in previous versions of astroplan if you called altaz with M targets and N times (M /= N), you would get an (M, N) array back. Also, if you called altaz with a list of times and single target you'd get a (1, N) array.

My PR has changed that behaviour, which has caused some failures in the constraints and scheduling code. I could re-instate it so that altaz worked as before but I would argue the way it works in this PR is an improvement, and it's better the fix the scheduling and constraints code to work with the new behaviour.

This does cause the issue that some existing user code might break, but there is still a healthy API warning on the astroplan main page...

This is not the current default behaviour

Comment thread astroplan/tests/test_target.py Outdated

coo = get_skycoord(m31)
assert coo.is_equivalent_frame(ICRS())
assert_raises(TypeError, len, coo)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please use pytest.raises instead? We don't have nose as a mandatory requirement but pytest, and this currently fails with ImportError: Need nose >= 1.0.0 for tests - see http://somethingaboutorange.com/mrl/projects/nose

@bsipocz

bsipocz commented Feb 2, 2017

Copy link
Copy Markdown
Member

OK, I see. For that discussion I think we need @bmorris3 and @eteq, as I'm not aware of the details for any decision behind the original API.

@StuartLittlefair

Copy link
Copy Markdown
Contributor Author

@bsipocz given the currently broken state of astroplan with astropy 1.3, what do you think about making this PR keep the original behaviour, and submit another PR later for the API change?

@bsipocz

bsipocz commented Feb 2, 2017

Copy link
Copy Markdown
Member

Sounds like a good approach to me.

@StuartLittlefair

Copy link
Copy Markdown
Contributor Author

OK - so the version pushed now restores the original behaviour of astroplan, at least as far as it comes to passing the tests. There may be some cases I've not reverted properly - e.g sun_rise_time called with N times returns an NxN grid.

A local test branch with #281, #279, #273 and this PR applied seem to pass tests, with the exception of one failure in scheduler which is (I think) unrelated.

@bsipocz

bsipocz commented Feb 2, 2017

Copy link
Copy Markdown
Member

@bsipocz

bsipocz commented Feb 2, 2017

Copy link
Copy Markdown
Member

There are still failures, one is the usage of nose (see inline comment), the other one is unrelated and I can fix in another PR.

@StuartLittlefair

Copy link
Copy Markdown
Contributor Author

thanks @bsipocz - fixed the nose issue.

@bsipocz

bsipocz commented Feb 2, 2017

Copy link
Copy Markdown
Member

@StuartLittlefair - Thanks a lot, quite good to see that everything is back to normal.

pinging @olebole and @ViviCoder as they may want to use this to patch the debian version

@bmorris3

bmorris3 commented Feb 2, 2017

Copy link
Copy Markdown
Contributor

@StuartLittlefair Unfortunately there's a little rebase that needs to occur after an update to some Observer docstrings. Still seem to be some build failures, too.

@StuartLittlefair

Copy link
Copy Markdown
Contributor Author

@bmorris3 I've just rebased. I don't think this has any chance of passing until #281, #279, #273 are also merged...

@StuartLittlefair

Copy link
Copy Markdown
Contributor Author

@bmorris3 It might be nice to make astroplan work with the latest version of astropy. I've got two PRs which do that in principle, this and #286. Both only work with astropy v1.3, but #286 could break some user-facing code.

#286 is nearly passing tests - just some docstring issues I can't work out.

OTOH, this PR doesn't include the PRs mentioned in the thread above, so will never pass tests. Those PRs also can't be merged, since they don't pass tests! I'd appreciate some advice on the next step. Is it a good idea to merge in the changes in #281, #279, #273 and get this PR passing?

@bsipocz

bsipocz commented Feb 9, 2017

Copy link
Copy Markdown
Member

@StuartLittlefair @bmorris3 - I think we are already at a point when we need to merge all the bugfix PRs without any of the individual ones passing all the tests. There were already a few tests branches that included all those PRs, if you like I can rerun the tests on the latest one to see whether there are any new divergences compared to astropy dev.

@StuartLittlefair

Copy link
Copy Markdown
Contributor Author

@bsipocz - I think that would be really helpful.

@bsipocz

bsipocz commented Feb 10, 2017

Copy link
Copy Markdown
Member

OK, so I've rebased the test branch, and merge this on in, tests are here:
https://travis-ci.org/bsipocz/astroplan/builds/200202721

We have the a TargetAlwaysUpWarning, and a real failure with numpy dev, and a few sphinx warnings left.

@StuartLittlefair

Copy link
Copy Markdown
Contributor Author

@bsipocz so I've worked out how to make a test branch on my own repository :)

With the latest commits I think I've got all the failures except some of the sphinx warnings. In particular I'm not sure what to do about the OldEarthOrientationWarning . I'm also not sure if the latex-related warnings in the sphinx build are important, but they are part of astropy helpers.

Can you merge my latest commits to my test branch and see if you agree with the summary above. Also, any idea what to do about the OldEarthOrientationWarnings?

@bsipocz

bsipocz commented Feb 10, 2017

Copy link
Copy Markdown
Member

@StuartLittlefair - Latest commits from here or from #286? We had the OldEarth... before, but only had some workarounds for it never a proper solution.
There is an astropy-helpers update PR, too, the latex warnings should go away with that.

@StuartLittlefair

Copy link
Copy Markdown
Contributor Author

@bsipocz from here.

I'm tracking fixes in this PR over there. My hope is that this (or a branch with these commits) can be merged, and I can rebase #286 so the changes are clearer.

@bsipocz

bsipocz commented Feb 11, 2017

Copy link
Copy Markdown
Member

Done. Tests are here: https://travis-ci.org/bsipocz/astroplan/builds/200726025

@StuartLittlefair

Copy link
Copy Markdown
Contributor Author

@bsipocz do my eyes deceive me or is this a passing branch?

What's the next step? Presumably one PR based on all the commits that make up your test branch?

@bsipocz

bsipocz commented Feb 11, 2017

Copy link
Copy Markdown
Member

Wow, I haven't noticed, copied the link here while it was still running.
Actually I would prefer the individual PRs being merged as a big joint PR will mess up any future bug hunts, etc.
Next step is to get the attention of someone with commit rights, and if they want a big joint PR, I can open it straight away from that passing branch ;)

@StuartLittlefair

Copy link
Copy Markdown
Contributor Author

@bmorris3 @eteq

Thanks to the hard work of @bsipocz we now have a collection of PRs (this one included) which in combination give a passing test suite!

Note that contrary to what is said in the initial message with this PR, it does not change the API.

The question is whether you would like multiple small PRs to be merged, or to review on huge PR. In the latter case @bsipocz can create that from her passing branch (see test results above).

@StuartLittlefair

Copy link
Copy Markdown
Contributor Author

@eteq @bsipocz one issue remaining building the docs which seems to be that astropy=1.3 is not available for numpy 1.12 on conda. is it ok to change travis.yml to use numpy 1.11 for that build or should this be fixed elsewhere?

@bsipocz

bsipocz commented Feb 18, 2017 via email

Copy link
Copy Markdown
Member

@bsipocz

bsipocz commented Feb 19, 2017

Copy link
Copy Markdown
Member

OK, so the problem there is that there is no wcsaxes build for np 1.12.
For the sake of this PR, yes please change NUMPY_VERSION for the docs build to 1.11.

In the meantime I'll open another PR that changes to use wcsaxes from astropy when possible rather than the standalone version.
But as wcsaxes is already been merged into astropy and s astroplan already requires astropy 1.3, I'm opening a new PR that does the switch.

@bsipocz

bsipocz commented Feb 19, 2017

Copy link
Copy Markdown
Member

At the end wcsaxes isn't directly used so it made sense to open a PR against this one.

@StuartLittlefair

Copy link
Copy Markdown
Contributor Author

Thanks for the PR @bsipocz In the end it hasn't helped - we now have a similar problem with astro query.

@bsipocz

bsipocz commented Feb 20, 2017

Copy link
Copy Markdown
Member

@StuartLittlefair - this is indeed an annoying issue. To have a quick and dirty fix, I suggest to add conda-forge to the CONDA_CHANNELS variable. For the long term we will come up with something in ci-helpers

this is a temporary fudge until astropy-helpers can be updated
@StuartLittlefair

Copy link
Copy Markdown
Contributor Author

@bmorris3 @eteq @bsipocz OK - we have a passing PR!

@bmorris3

Copy link
Copy Markdown
Contributor

@StuartLittlefair Thanks for all of your hard work on this one!

@bmorris3
bmorris3 merged commit 3fca943 into astropy:master Feb 23, 2017
@StuartLittlefair
StuartLittlefair deleted the no_target_lists branch August 18, 2023 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants