Skip to content

Added a utility function to get a non-scalar SkyCoord from a list of targets - #215

Closed
StuartLittlefair wants to merge 2 commits into
astropy:masterfrom
StuartLittlefair:get_skycoord
Closed

StuartLittlefair wants to merge 2 commits into
astropy:masterfrom
StuartLittlefair:get_skycoord

Conversation

@StuartLittlefair

Copy link
Copy Markdown
Contributor

The rationale behind this PR is that it is often faster to make calculations with a non-scalar SkyCoord than with a list of FixedTarget objects or SkyCoord objects. However, making the conversion is non-trivial so a helper function is required.

The utility function described here will return a SkyCoord object when passed either:

  • a single FixedTarget or SkyCoord
  • a list of FixedTargets or SkyCoords.

In the latter case, the returned SkyCoord will be non-scalar.

In the case where all of the supplied target coordinates are in the same frame, no conversion will take place. If there is a mix of frames, all coordinates will be converted to ICRS.

One potentially controversial decision is what to do when there is a mix of coordinates with distances and those without. You cannot create a SkyCoord with a mix like this. It is, IMO, not right to discard the distances from targets that have them, since any transformation into a frame with a different origin will be incorrect. Instead, I assign an arbitrary, large, distance to those targets which lack it.

@StuartLittlefair

Copy link
Copy Markdown
Contributor Author

These tests will currently fail since the tests in get_skycoord to check if the frame is equivalent die on frames with the obsgeoloc property set. This is fixed in astropy/astropy#5207.

@StuartLittlefair

Copy link
Copy Markdown
Contributor Author

I'd like to resurrect this PR in light of the broadcasting issues with astropy 1.3 (#282, #263).

This PR should now pass tests, and moving away from using a list of FixedTarget objects to a vector SkyCoord for internal calculations may be the easiest way to deal with the broadcasting issues, and would probably speed up the code and make it more powerful.

@bsipocz

bsipocz commented Jan 31, 2017

Copy link
Copy Markdown
Member

Thanks @StuartLittlefair. I'll pick this PR into my testing branch, that contain all the fixes with the other issues. It that pass we can have a big merging event :)

@StuartLittlefair

StuartLittlefair commented Jan 31, 2017 •

Copy link
Copy Markdown
Contributor Author

@bsipocz the approach I'm suggesting will probably involve a large amount of re-factoring in the end, but I'm thinking we should always be broadcasting the targets (first axis) against the obstimes, which can be any shape. An example would be that the current observer.altaz function would look like:

        if not isinstance(time, Time):
            time = Time(time)
        if time.isscalar:
            time = Time[np.newaxis]

        altaz_frame = AltAz(location=self.location, obstime=time,
                            pressure=self.pressure, obswl=obswl,
                            temperature=self.temperature,
                            relative_humidity=self.relative_humidity)
        if target is None:
            # Return just the frame
            return altaz_frame
        else:
            # convert target argument to vector SkyCoord
            targets = get_skycoord(target)
            if targets.isscalar:
                targets = targets[np.newaxis]
            # now we broadcast the targets array so that the
            # first index iterates over targets, any remaining indices over times
            while targets.ndim <= altaz_frame.ndim:
                targets = targets[:, np.newaxis]
            return targets.transform_to(altaz_frame)

@bsipocz

bsipocz commented Jan 31, 2017

Copy link
Copy Markdown
Member

@StuartLittlefair - The PR is it's current form is merged into a test branch that includes the other fixes, too, but there are still a few broadcasting failures both in the code and the docs, e.g.
https://travis-ci.org/bsipocz/astroplan/jobs/196944611#L738

Full build:
https://travis-ci.org/bsipocz/astroplan/builds/196944604

While the proposed behaviour changes looks OK to me, I have to state that I don't know the code itself well enough to make any decisions.

@StuartLittlefair

Copy link
Copy Markdown
Contributor Author

Hi @bsipocz

Thanks for including the pr. It won't, by itself fix the broadcasting issues but the helper function it provides might give a way to work with astropy coordinate broadcasting rather than against it.

I've been working on a PR based on the current master to show how this might be done, but it's not a quick fix and due to other time pressures probably won't be available to address #282 in a timely fashion unless someone else picks it up.

@bsipocz

bsipocz commented Jan 31, 2017

Copy link
Copy Markdown
Member

@StuartLittlefair - sure, no worries, I was just mislead by the comment above that this should pass the tests.
@wtgee mentioned in #282 (comment) that he already fixed some of the issues, maybe he can pick this up, too?

@StuartLittlefair

Copy link
Copy Markdown
Contributor Author

Superseded by #285

@StuartLittlefair
StuartLittlefair deleted the get_skycoord branch May 9, 2017 11:40
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.

2 participants