Repository navigation
Conversation
There was a problem hiding this comment.
What does this do? Should it be here or in update_representation_data?
There was a problem hiding this comment.
I think it should be in update_representation_data. The purpose here is to cache other representations of the data that are requested, while always maintaining self._data as the original representation. If self._data gets updated in place then this cache gets invalidated and should be cleared.
|
ping @eteq @taldcroft |
|
@Cadair - to use this do you create a new representation object each time or modify an existing one in place (using private attributes, e.g. |
There was a problem hiding this comment.
The third sentence this method ... is a bit ambiguous as which method this refers to. I would suggest:
This is a low-level in-place operation on this frame that is provided for
applications where speed is required. No validity or consistency checks are performed.
A safer method of changing the data of a frame is ...,
which returns a copy of the frame with the new data.
|
@Cadair - this could use a test that does: Basic test:
More in-depth test:
|
|
@Cadair - sorry for the delay... I've finished my review. Definitely 👍 on the concept. |
|
@eteq - currently you can update a coordinate in place via |
|
Any progress on this? |
|
@Cadair - do you think you can try to squeeze in the "basic tests" @taldcroft mentioned a while back here? And to answer the question I never answered from 11 months ago... As far as I'm aware |
|
@Cadair - any thought that you might want this in time for the Astropy v1.3 feature freeze (this Friday)? Alternatively, do you expect you'll get to this at any point, or should we consider closing it? |
The update_representation_data method 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.
81e2885 to
4d6db62
Compare
|
@eteq I think I addressed all the comments |
|
Sorry to come late to this discussion, but having implemented the shape-changing stuff, I've become more aware of how coordinates work. Because of that, two comments, one on the implementation, the other on the name: On the implementation, and specifically the lack of checks: There are really two ways one could screw up one's object: either its shape is inconsistent with the frame attributes, in which case the instance can no longer be transformed, etc., or the data is for a wrong type of frame and hence the coordinates now are wrong. I think we cannot easily protect against the latter type of error, but since The above means it wouldn't be quite as fast to replace data with other data with a different shape, but I think that is OK. Now on the name: I feel introducing |
|
p.s. I do wonder if it wouldn't be easier to just ensure we can make a copy of a frame much more rapidly, i.e., can we really not speed up |
|
@mhvk How does the Representation objects store shape? Does each lat lon etc have a shape, which is also stored in the frame? I would be ok with a setter for data, but I think it would be harder to expose the "this may eat your cat" warning to users with a setter over a dedicated method? |
|
@Cadair - the representation object has a On the "this may eat your cat" -- my feeling is that if we check that something is a representation and that is has an OK shape, we have done everything the initialiser would do, so a large warning no longer is necessary. But as said, I do wonder if we cannot speed up |
|
@mhvk - just to check, do you mean you can look into this more before the feature freeze deadline? |
|
@mhvk - The purpose of this function is basically to be as fast as possible, primarily for use cases where it's a small (often scalar) coordinate object. In that case, it's hard to see any way I think it may indeed make sense to do the shape-checking, though, as that's still a cheap operation. But I still think it's important to keep the "this may eat your cat" warning, because we just haven't thoroughly checked all of this. I also really don't want people to think this is a "standard" way of doing this. I don't think we want to encourage mutability, as there are other things that we aren't necessarily invalidating properly (e.g. the KD-tree from the searching functions), and the point of the immutibility was to make it so we don't have to. So I think it's important that this be treated as a tool to be used only in niche cases where you really definitely need the speed and know you aren't going to screw something up. |
|
Put another, more succinct way: I do not think we want to make a Oh, and my comment above answered @taldcroft's question about mutability: the kd-tree used by the matching stuff. But that's not even implemented in |
|
I agree with @eteq on the data setter front, I don't think it's such a good idea. |
|
Let me just toss out a plan B for this that occurred to me in looking at this today. It seems actually possible to set the representation data in place using "public" methods (apart from cache clearing). By using numpy broadcasting then there is no chance of getting the shape wrong, hence no need to additional validation. Hopefully @mhvk won't point out some subtlety in this which breaks everything. 😄 Now here's the idea:
|
|
I like this approach, I am also very 👍 on making the cache clear public. I feel that maybe having this PR for a complete representation swap might still be useful, but I am not sure of a performance based use case for it as @taldcroft's suggestion fixes the intended use for this PR very well. |
|
BTW, I would naively expect the following to work as well, but it doesn't. There is probably a good reason (that I've forgotten), but it looks like accessing the |
|
That must be happening at the Representation level right? |
|
@taldcroft - for why your second example doesn't work, see #4903, i.e., my question whether it was possible to revert the decision to present ra, dec always in degrees to the users -- which (sadly) implies that On the more general PR question: I like the approach of pointing out how one can update the values in-place, and what else needs to be done to reinitialize. Note that, effectively, this means you keep the shape of the skycoord, but that seems by far the most common case, so is fine. |
The representation knows nothing about So Upshot is that the reliable way is accessing the representation data object directly and manipulating the repr attributes (lon, lat) not frame attributes (ra, dec). This is one more layer of difficulty that advanced developers will be able to master. |
|
@mhvk - re: revisiting decision. That is going to be a very hard sell since it will break code. So anybody who uses |
|
As for how to make clearing the representation cache public: in |
|
@taldcroft - yes, I know it is a hard sell... Anyway, if I'll think of another good counterargument, I'll add it to #4903. |
|
p.s. As for the cache, like for |
|
my only concern with having the cache in an attribute is it would make it more complex to have it clear multiple caches. While at the moment we just have the representation cache I know @eteq wanted to make the clear method a place to wipe out all data cache. |
|
@Cadair - since it is a cache, it should always be fine to just wipe it completely. We do the same in |
|
I changed labels, as I think the consensus would seem to be that we expose the cache and write documentation, which would be a different PR. |
|
@mhvk I am not sure I understand, my point was if we cache more than just |
|
Now I'm confused: if we cache everything in a |
|
Ok that makes sense. So we have a |
|
Yes, that would be the idea. With that, we can, if we ever wish, add one that has Note the implementation using |
|
Ok I will open up a new PR with these suggestions, probably tonight, but maybe tomorrow in the hope of sqeezing it into 1.3 |
|
👍 to the new idea from me... @Cadair, maybe this is just what you mean, but the idea would be that the |
The update_representation_data method 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.
This is a splinter of #3757 containing just the in-place modification stuff.