Repository navigation
Use numpy broadcasting for altaz and constraints - #286
Conversation
|
OK, I was going to ping people when this was passing tests, but I can't understand some of the failures - in particular I'm not sure what to do about the sphinx failures. The older version of numpy also seem to fail because Time has no So, for discussion, @eteq, @bmorris3, @bsipocz you might want to take a look at this PR sometime. |
a52920d to
48ee0d0
Compare
|
I have now rebased this so it is easier to see what has changed. I've also profiled the changes here against the current master which also uses This PR is faster, but not dramatically so (with the exception of the The results (in s) are shown below:
|
|
@StuartLittlefair It looks like this PR is good to go! I just want to check before I click the green button that this one is ready to merge? |
|
I'm happy with it. I'd be happier if @eteq took a look at it because it's a big change. Also, does it need a change log entry? |
|
Ok, then I'm going to do an intermediate release first, so that we can get v0.2.1 on pypi ASAP. |
|
Good plan! |
|
Hi @bmorris3. I'm thinking of finishing up this PR, but I can't make my mind up about the default behaviour. In the past astroplan has always done calculations for a grid of times and targets and as you know, this PR changes this default. It doesn't have to; we could make gridding the default again, and allow non gridding as an option. Edit: my own opinion is that the intuitive behaviour is the one in this PR; if I supply three times and three targets to I'm going to finish up editing the docs and adding a changelog over the next week, but before I do that I wanted to check that you are happy with this decision? EDIT: this PR is now ready to go as far as I'm concerned. It just really needs package maintainers to agree on the API breaking change. |
…argets' in constraints
4a47f60 to
2c539f3
Compare
|
p.s, this PR fixes #296 |
273d0a6 to
8c47a4d
Compare
|
@StuartLittlefair sorry for the long delay there! I just finished my candidacy exam and can take a look now. Reviewing! |
| To see the (target x time) array for the non-boolean score:: | ||
| By default, calling a constraint will try to broadcast the time and target arrays | ||
| against each other, and raise a `ValueError` if this is not possible. To see the | ||
| (target x time) array for the constraint, there is an optional "grid_times_targets" |
There was a problem hiding this comment.
Small correction – would you please make "grid_times_targets" -> `grid_times_targets`? That way it will be rendered nicely in the docs.
| @@ -3,6 +3,13 @@ | |||
|
|
|||
| - No changes yet | |||
There was a problem hiding this comment.
We can remove this line with your addition below.
|
@bmorris3 congratulations! I've made the minor changes requested |
|
Closed and re-opened to start tests, which failed due to random lookup failure for APO site. |
|
Thanks for all of your hard work @StuartLittlefair! |
As discussed in #285 I think there is an advantage to relying on the broadcasting of times and targets in astropy, now that those objects are shape aware. This PR is basically to show how that would work, so the code maintainers can discuss if it's a good idea or not.
This PR passes all tests locally (some of which have been tweaked to accommodate changed behaviour - see below). To do this I have included changes in #281, #279, #273 as well.
The three potential gains are cleaner code, faster performance and greater flexibility. The downsides are that it requires astropy v1.3, and that it's a change which will probably break user code - see discussion below.
Cleaner Code
The philosophy is to always convert target arguments to
SkyCoordobjects. As a result, we no longer have to have two paths through the code for vector and non-vector targets. We can also get rid of constructions like:which becomes
Faster performance
Performance is similar for single targets and single or a few times. However, when calculating the altaz or evaluating constraints over many targets and times it is much faster. For example evaluating the built-in constraints for 100 times and 2 targets has improved from 15s to 1.5s. Scheduling currently does every combination of target/time one-by-one so doesn't see any speed-up but the code could be adapted in a future PR.
Greater flexibility
This is also where the code-breaking behaviour arises. Previously, evaluating a constraint or calculating altaz for N targets and M times would always return an NxM array. This is no longer true. If N and M are equal, for example, the result will be a 1D array of size M.
I'd argue this is an improvement - one doesn't always want to calculate every target at every time. To minimise the transition pain, both altaz and the constraint call function have a
gridargument, which restores the previous behaviour.