Make it so we can use broadcasting even if input WCS is same dimension as data#539
Make it so we can use broadcasting even if input WCS is same dimension as data#539astrofrog wants to merge 11 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #539 +/- ##
==========================================
+ Coverage 88.13% 88.24% +0.10%
==========================================
Files 51 51
Lines 2074 2110 +36
==========================================
+ Hits 1828 1862 +34
- Misses 246 248 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ddcca20 to
37561e9
Compare
|
Ok so we need to add proper support for non_reprojected_dims to |
|
|
||
| # Determine how many extra broadcasted dimensions are present | ||
| n_broadcasted = len(shape_out) - wcs_in.low_level_wcs.pixel_n_dim | ||
| n_broadcasted = len(shape_out) - wcs_out.low_level_wcs.pixel_n_dim |
37561e9 to
0c503ea
Compare
73354f3 to
0521578
Compare
0521578 to
dd525c7
Compare
9114b9d to
b050a04
Compare
|
Ok so this is now tidied up and should be functional and #611 contains the part of extending this to co-addition. I'll do another self-review and then mark this ready for review. |
|
@svank - tagged you for review in case you want to take a look, this is an extension of the work you started in #332 - here we can now specify explicitly which dimensions to ignore - for now only leading dimensions can be ignored, but I plan to generalize this. The idea here was to efficiently be able to reproject say a solar time+spatial cube where the spatial coordinates drift over time, so one can't actually use a simple 2D WCS for both input and output WCS - the slicing has to be different for each slice. For now I've not added narrative docs because this work is split up over multiple PRs and I want to wait until this is in good shape and stress-tested before documenting it. |
This is very much a WIP and not ready for usage but just opening this to not lose my progress.
I think we need to write down the rules for block sizes, and broadcasted reprojection, and I think it's ok to not cover all arbitrary cases. I'm now using the terminology 'reprojected dimensions' and 'non-reprojected dimensions', where the latter are essentially dimensions where we assume the mapping is 1-to-1 between input and output.
Proposed rules:
ndim.wcs_inhas fewer pixel dimensions thanndim, then we assume that the input WCS applies to the lastwcs_in.pixel_n_dimdimensions of the input data, and that leading dimensions are the non-reprojected ones. The same applies towcs_out.shape_outshould either havendimelements, or match the number of reprojected dimensions. If the latter, then any missing elements for non-reprojected dimensions should be set to be the same as the input.block_size, if specified, should also either havendimelements, or match the number of reprojected dimensions. If the latter, then any missing elements for non-reprojected dimensions should be either set to1ifblock_sizeequalsshape_outfor reprojected dimensions, or-1otherwiseblock_sizeshould either matchshape_outfor reprojected or for non-reprojected dimensions (that is, we either chunk over non-reprojected dimensions only, or over reprojected dimensions only). If it matchesshape_outfor reprojected dimensions, then the remaining block_size should be 1 so that only a single slice is reprojected at a time (yes there may be cases where someone wants to process slices in e.g. time or spectral slices, but this is going to introduce more complexity when the input WCS has dimensionndimso we punt on this for now).non_reprojected_dimsshould for now be only leading dimensions starting from0, so e.g.(0,),(0, 1)and so on.(1,2)is not allowed for now. This could be relaxed in future potentially at the cost of more complexity.non_reprojected_dimsoption could take a list of tuples where each tuple gives the(input_dim, output_dim)correspondence.non_reprojected_dimsis specified, then ifwcs_inorwcs_outhave fewer dimensions thanndim, the difference in the number of dimensions should match the length ofnon_reprojected_dims.For cases where the third axis is completely decoupled from the spatial axes in cubes,
non_reprojected_dimsisn't strictly needed because the WCSes could be easily sliced down to 2D. However, we do need that option for cases where the input WCS is 3D in the sense that each spatial slice might be different (for example due to drift at different times) but where each time still corresponds cleanly to one 2D slice and there is no dependence of e.g. time position on spatial position.Complex examples that should work:
non_reprojected_dims=(0,), it should work and basically only care about the spatial to spatial conversion. This example doesn't make a huge amount of sense, but another more realistic example is that if one wants to align two spectral cubes spatially without touching the spectral axis,non_reprojected_dims=(0,)could do this.