Repository navigation
Conversation
|
Cleanest may be to always return a |
|
I think |
|
+1 |
|
My suggestion was a bit more complicated, allowing one to ask for either masked or regular array, but always returning a masked array and raising an exception if fully outside is probably easier and thus better. |
|
This turns out to be trickier than I thought, but I'm working on it. |
Check if arrays overlap before constructing slices. Add several tests.
|
OK, I pushed code. I suspect that this will not make it into 1.0 and thus I have not written anything into the CHANGES.rst yet. |
|
travis-ci failed because of this Sphinx issue: I'm not convinced this change is the right approach. Maybe it would be better to have functions that compute nd slices and then the user can decide what to do (e.g. change in place, or copy with or without padding) ... maybe using other helper functions. I don't have a concrete suggestion at the moment, but my suggestion would be to think about this and discuss some more, unless most people think it's important to make this change before the 1.0 release. @adonath You're using |
|
@cdeil The function to compute ndslices is |
|
I should point out that in the course of this PR, I found that the current implementation no only returns arrays or different sizes (which I consider a bug, but others may consider that a feature) it also gives clearly wrong results when called with invalid (negative) inputs (examples with current master, are fixed with the modified implementation in this PR): The problem is independent of the number of dimensions, so I chose 1d arrays in these example, but it is a problem for 2 d arrays, too: |
|
Ah, OK ... I didn't know overlap_slices was part of the public API. Still ... aren't there use cases where one does want to get smaller cutouts at the edged (and not have those padded or masked)? I think that's what we need in gammapy/gammapy#234 . Would it be bad to add an option to let the user control the behaviour at the large array edges where the small array doesn't completely fit? |
|
When you use the current version of (Note that the example above does not include the correct rounding for even/odd array sizes and that in practice 5, 0.5 and 2.2 would be variable names.) Does that not look a little more confusing than it should be? I'm not opposed to offering a keyword to switch that behaviour (that's what I suggested at the top of this thread) but I've been convinced that it would be easier to support one and only one way to do it. |
|
@cdeil For gammapy/gammapy#234 it doesn't make a difference because the boundary handling is done outside the @hamogu Sorry for not commenting earlier. I'm not in favor of returning a I would keep the default behaviour as it is. That leaves is to the user, what to do with those 'incomplete' extracted arrays, because it think there are surely cases were you just don't care and discard them, as it was done in the photutils psf photometry prototype . But I would add an optional boundary parameter for convenience. It could even be the same options as in |
There was a problem hiding this comment.
why the addition of np.floor? For positive numbers it does the same as int, while I'd think that negative positions would need special treatment.
There was a problem hiding this comment.
This is required to avoid errors with negative positions.
If we want to allow extraction of partially overlapping arrays with a central position to the left of the larger array (such as extract an array of size 5 with a center at -1, which still overlaps for two positions such as shown below)
----0123456789
sssss
The extracted array s would be ---01.
There was a problem hiding this comment.
Subject to the same caveat as my other comments: I thought "pos" would be the "position of the center" not the "index of the center". If that is indeed meant to be the index, then negative indices can be disallowed and there is no need for np.floor.
|
Regarding the discussion re: maskedarray one can also return an array with NaN values outside the boundary. That could actually be a keyword argument if needed. |
|
@hamogu - on the negative indices: yes, this is indeed inconsistent. In principle, there is no reason not to be able to give a negative offset -- meaning, as usual, counting from the far end of the array -- but the addition of the size should not be allowed to become positive. Still, the effort would likely not be worth the pain, so it may be easiest to just disallow negative indices. |
|
What does a negative position mean? I interpreted that as the position in a geometical sense (The array as indexes 0,1,2,3, ... ,so "-1" would be on to the left of "0"), but I now realize that this can also be interpreted as the "index of the position" (negative numbers simply mean it's counted from the right of the array.) Which one was the intention of the original authors of this code? If they intended the meaning "array indices" then I take everything back that I said and close this PR. In that case, I just suggest the simple addition of "Index of the Position of the small array's center, with respect to the large array." to the docstring. |
|
@hamogu - for what it is worth, I think your interpretation is much more logical than mine: let's treat @adonath's point about keeping the array type the same is well-taken (especially since |
|
I'd second @astrofrog's suggestion that the fill value be a keyword parameter (e.g. with default= |
|
@hamogu My intention was |
|
Just to underline my comment above: I don't think |
|
Just thinking out loud here, but perhaps a better approach would be to make this a class (e.g. |
|
I see this more as a low-level function that could be used to build a classes like @larrybradley suggested on top of it. If we are talking e.g. about an image, that class could also handle changes to the WCS etc. |
|
The Travis failure us just a few sphinx warnings which I will fix when I add the changelog in the end. |
|
@larrybradley: For odd arrays we use the middle element as the center already, which, I believe, is exactly what you suggest. (I looked at both the scipy documentation and the scipy source code and it is not clear to me what happens for even sized arrays). |
|
@astrofrog : If you want to know exactly what the coordinates of the input position are in terms of your new array, use
However, I understand that this is not necessarily sufficient. A user will want an option that returns the coordinates of position in the new array for even and odd shaped arrays and for any mode. Unfortunately, this is somewhat non-trivial in the presence of edges (and precisely this is the reason why I originally implemented the mode that we now call "partial", where it's easy). I think I will have to redesign I'm sorry that now it's me to hold this up. I know that by now there are at least two other PRs that wait for this. Please bear with me. |
|
@hamogu Yes, that's right. I was just trying to clarify that the generic filter BTW, for even-sized arrays, |
|
Travis is still running, but this is a heads up that I added a keyword to return the position in the coordinate system of the new array. Please review. |
There was a problem hiding this comment.
Please move to the nddata section
There was a problem hiding this comment.
This isn't actually restricted to integers, right? How about just tuple or number here, along with the minor edit a few lines down?
There was a problem hiding this comment.
The shape of an array is restricted to an int. (No array has float dimensions), but he position is not. I changed this.
|
@hamogu -- only a couple minor comments, thanks for adding the option to return position! If you don't have time to make these changes please speak up. They are not critical to merging this. @astrofrog -- position is now returned, haven't tried it extensively myself, but the test suite is pretty thorough. Unless you have concerns beyond my line comments, this looks good to merge; those line comments are not critical, can be fixed later. |
also fix a couple of line breaks to make lines < 80 characters [skip CI]
|
Any more comments on my longest ever running PR? |
|
But it was created only in this year! |
|
This might not get merged until the python in astronomy workshop is done. Perhaps we could open a PR for a new unit? |
|
I get a merge conflict in every single of 19 commits. That's why I don't like PR's that are open this long (and if I remember right, this is about the forth time that I rebase). |
See extensive discussion in astropy#3333
|
@mwcraig @wkerzendorf : Please see #3727 which is this PR, with copy & paste of the changes into a new branch based of the current master. |
Something about that doesn't sound right. In the future I could probably try rebasing for you. |
See extensive discussion in astropy#3333
It would be useful for me if we had either:
This was originally astropy/imageutils#21 but got not resolved before merging with astropy, so I open it here again to raise visibility.
My use specific use case is PSF photometry (astropy/photutils#159) where I would like to extract sub-arrays or a large image and perform the PSF photometry on those subarrays. Unfortunately, with the current behaviour, I cannot easily relate the pixel coordinates of the large array and the subarray. The
extract_arrayroutine has all the code to check if I am extracting something in the middle of an array or on the edges (that's how it decides how large the return array is), but there is no way to propagate this information back to the caller.I think this is a problem in almost any application of
extract_array, my PSF photometry is just one concrete example.CC: @astrofrog @larrybradley