Skip to content

Add _unitrep attr of SphericalRepresentation - #3757

Merged
astrofrog merged 14 commits into
astropy:masterfrom
Cadair:unitrep
Oct 5, 2015
Merged

astrofrog merged 14 commits into
astropy:masterfrom
Cadair:unitrep

Conversation

@Cadair

@Cadair Cadair commented May 6, 2015

Copy link
Copy Markdown
Member

_unitrep allows subclasses of SphericalRepresntation to define their
UnitSphericalRepresentation equivalent.

The copy argument to relalize_frame allows in place changes to the data
attached to the frame. This provides a way to create a frame and change
the data at high speed.

@eteq eteq added this to the v1.1.0 milestone May 6, 2015
@eteq

eteq commented May 6, 2015

Copy link
Copy Markdown
Member

This may require some discussion because it includes a subtle but significant change: adding the copy=False option means we're providing a way to break the guarantee of immutability for coordinate objects. @taldcroft @adrn @astrofrog

The _unitrep stuff is essentially independent of that, right @Cadair?

The background for this is that @Cadair was working with @ejeschke to try to speed up Ginga, and there's a need to quickly (in a GUI context) "re-populate" coordinate objects with new data, avoiding the object creation overhead.

Also, btw, @Cadair, this needs a changelog entry.

@adrn

adrn commented May 7, 2015

Copy link
Copy Markdown
Member

Yea, the copy kwarg could require some thought. I don't have a strong opinion about maintaining immutability or not, but it would be a significant change. I worry slightly that it could be tricky to protect against things that would break if we open up that door...

@taldcroft

Copy link
Copy Markdown
Member

Was there a specific need to swap the order of UnitSphericalRepresentatation and SphericalRepresentatation? This just makes some irrelevant diffs, or else obscures real diffs.

@Cadair

Cadair commented May 7, 2015

Copy link
Copy Markdown
Member Author

If I moved the _unitrep stuff out of this, would people be willing to put it into a bug fix release seeing how it's not API breaking? (Just asking because it really breaks solar coords in Ginga).

On the topic of copy kwarg. It is by far the easiest way to speed up the realize frame call (which really needs to happen for Ginga) the other option is going mad on the BaseFrame__init__.

I personally think that it should be ok, people (like me) will hack around it anyway.

@Cadair

Cadair commented May 7, 2015

Copy link
Copy Markdown
Member Author

@taldcroft I swapped them because otherwise the unitrep was not defined when creating the class attr.

Comment thread astropy/coordinates/baseframe.py Outdated

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.

Do you need self._rep_cache = dict() first to clear the cache from any other reprs that might be there?

@taldcroft

Copy link
Copy Markdown
Member

I think it would be better to leave realize_frame alone and have a new method like update_representation_data. That way it is more obvious that an in-place update is being done. We could also have a really big user-beware warning in that method that says there might be subtle issues from doing this and so it should be used with caution.

In general I think we need to open this box to support use cases like this where the current performance is not acceptable.

@eteq

eteq commented May 7, 2015

Copy link
Copy Markdown
Member

👍 to @taldcroft's suggestion here of a different name with a prominent .. warning:: section in its docs.

@Cadair - I also like your suggestion of splitting out the _unitrep stuff - at the very least that makes it easier to review which changes are for what.

@Cadair
Cadair force-pushed the unitrep branch 3 times, most recently from 143d3af to a64d8f3 Compare May 26, 2015 15:21
@Cadair Cadair changed the title Add _unitrep attr of SphericalRepresentation and copy in realize_frame. Add _unitrep attr of SphericalRepresentation May 26, 2015
@Cadair

Cadair commented May 26, 2015

Copy link
Copy Markdown
Member Author

This is now just the ._unitrep stuff.

@Cadair
Cadair force-pushed the unitrep branch 2 times, most recently from 3402691 to 13eb563 Compare May 26, 2015 15:31
Comment thread astropy/coordinates/representation.py Outdated

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This line is the only actual change in here.

Comment thread CHANGES.rst Outdated

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.

Should this really go here if it's describing an attribute for internal-only use, or is this something authors of SphericalRepresentation subclasses need to be aware of?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I did not know where best to put it in the change log, the way I have written this PR does assume that all SphericalRepresentation classes will have a _unitrep attribute now, so any authors will need to update.

Should I add a catch in the BaseCoordinateFrame.__init__ for non-updated subclasses, or are the SunPy ones the only subclasses in existence?!

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.

I would move this to the "API changes" section then, if nothing else, since it's more of an internal API feature.

Also some nitpicks--use double-backticks insgead of singe-backticks, and add a reference to the PR # :)

@taldcroft

Copy link
Copy Markdown
Member

@Cadair - are there any diffs in SphericalRepresentation or UnitSphericalRepresentation apart from the _unitrep class attribute? Difficult to tell because of the order swap of class definitions.

Also kindof a nit, but the coordinates package tends to use more verbose names, so _unit_representation might be more consistent. Since it only gets used in one place the verbosity shouldn't be a problem.

@Cadair

Cadair commented May 28, 2015

Copy link
Copy Markdown
Member Author

@taldcroft I have changed _unitrep to _unit_representation.

The only change in representation.py is the addition of the attribute to the SphericalRepresentation class, and the order swap.

@embray I have moved the changelog entry, I think it is ok now.

@embray

embray commented May 28, 2015

Copy link
Copy Markdown
Member

👍

@Cadair

Cadair commented Jun 9, 2015

Copy link
Copy Markdown
Member Author

Any more comments on this?

@taldcroft

Copy link
Copy Markdown
Member

@Cadair - if I do the following there are a lot of matches in the coordinates code:

find astropy/coordinates -name '*.py' | xargs grep UnitSphericalRepresentation

So my question is whether some of these need to be generalized to use the new class attribute so that subclasses actually behave as expected. One obvious case is in the __repr__ method of baseframe.py. This does:

                if (issubclass(self.representation, SphericalRepresentation) and
                        isinstance(self.data, UnitSphericalRepresentation)):
                    data = self.represent_as(self.data.__class__,
                                             in_frame_units=True)
                else:
                    data = self.represent_as(self.representation,
                                             in_frame_units=True)

If it is the intent (or requirement) that custom _unit_representation classes be a subclass of UnitSphericalRepresentation then this is OK, otherwise not. Apart from that I haven't gone through and looked at each instance of UnitSphericalRepresentation in the code, but maybe you need to, or at least have justification for why no generalizations are needed.

This is leading into adding some tests of having a custom _unit_representation and putting that object through the paces.

@Cadair

Cadair commented Jun 30, 2015

Copy link
Copy Markdown
Member Author

@taldcroft I was working on the assumption that a class in the _unit_representation attribute would be required to be a subclass of UnitSphericalRepresentation are you ok with this? I will document it somewhere.

I will try and find some time to work more on this, but I am rather busy.

@taldcroft

Copy link
Copy Markdown
Member

OK, if the _unit_representation needs to be a subclass then part of my question is answered. But I still suspect there are many cases where UnitSphericalRepresentation has been hardwired and assumed to be the only possible UnitSphericalRepresentation class. E.g.:

if self.data.__class__ == UnitSphericalRepresentation:
...

And in representation.py:

...
elif other_class is UnitSphericalRepresentation:
...
return UnitSphericalRepresentation(lon=self.lon, lat=self.lat)

No worries on time. This is your feature request after all!

@embray

embray commented Jul 7, 2015

Copy link
Copy Markdown
Member

Is this ready to merge, then?

Comment thread astropy/coordinates/representation.py Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

represent_as is in fact defined a bit further down, so remove this comment? (Or clarify it and move it further down).

@mhvk

mhvk commented Oct 5, 2015

Copy link
Copy Markdown
Contributor

See minor cleanup comments; they can be a [skip ci] commit to speed this up.

Comment thread CHANGES.rst Outdated

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.

Add [#3757] at the end here.

@eteq

eteq commented Oct 5, 2015

Copy link
Copy Markdown
Member

Two minor comments above, and one other thing best described via comment: Can you add just a bit in the representations.rst file mentioning this attribute's existence?

Thanks @Cadair !

@Cadair

Cadair commented Oct 5, 2015

Copy link
Copy Markdown
Member Author

I will get to this asap.

Cadair and others added 13 commits October 5, 2015 17:47
_unitrep allows subclasses of SphericalRepresntation to define their
UnitSphericalRepresentation equivalent.
This mainly makes code check for subclasses as well as the base class.
[ci skip]
They now respect subclasses of the three SphericalRepresentation
classes.
…sentation classes, and that custom transform is removed from transform graph after tests
@Cadair

Cadair commented Oct 5, 2015

Copy link
Copy Markdown
Member Author

@mhvk @astrofrog @eteq I think this is ready!

@eteq

eteq commented Oct 5, 2015

Copy link
Copy Markdown
Member

Alright, I think we can merge this once/if the tests pass!

@astrofrog

Copy link
Copy Markdown
Member

👍

astrofrog added a commit that referenced this pull request Oct 5, 2015
Add _unitrep attr of SphericalRepresentation
@astrofrog
astrofrog merged commit 34f4c29 into astropy:master Oct 5, 2015
@Cadair

Cadair commented Oct 5, 2015

Copy link
Copy Markdown
Member Author

Thanks everyone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants