|
3 | 3 | Changing the resolution of an NDCube |
4 | 4 | ===================================== |
5 | 5 |
|
6 | | -This example shows how to change the resolution of an NDCube by reprojecting to a finer grid. |
| 6 | +This example shows how to change the sampling of an NDCube by reprojecting to a different grid. |
| 7 | +
|
| 8 | +Reprojecting is useful when you need a new WCS or a non-integer change in pixel scale. |
| 9 | +
|
| 10 | +.. warning:: |
| 11 | +
|
| 12 | + Reprojecting resamples the data, but it does not make the underlying data intrinsically higher resolution. |
| 13 | + If you only need to combine aligned pixels by an integer factor to reduce resolution, |
| 14 | + `~ndcube.NDCube.rebin` is usually a better choice because it operates directly on contiguous input pixels. |
7 | 15 | """ |
8 | 16 |
|
9 | 17 | import matplotlib.pyplot as plt |
|
18 | 26 |
|
19 | 27 | ############################################################################ |
20 | 28 | # We start by creating an NDCube from sample solar data provided by SunPy. |
21 | | -# Here we use an AIA 171 image, but the same approach can be applied to other datasets, including those with non celestial axes. |
| 29 | +# Here we use an AIA 171 image, but the same approach can be applied to other datasets, including those with non-celestial axes. |
22 | 30 |
|
23 | 31 | image_data = fits.getdata(AIA_171_IMAGE, ext=1) |
24 | 32 | image_header = fits.getheader(AIA_171_IMAGE, ext=1) |
25 | 33 | cube = NDCube(image_data, WCS(image_header)) |
26 | 34 |
|
27 | 35 | ########################################################################### |
28 | | -# Next, we define a new WCS with a finer pixel scale, note that while it is obvious that the CDELT values are changed to reflect the finer scale, |
29 | | -# the CRPIX values also need to be adjusted as the reference pixel position is different on the new pixel scale. |
| 36 | +# Next, we define a new WCS with a finer pixel scale. This changes the sampling of the output array, but it does not make the underlying data intrinsically higher resolution. |
| 37 | +# Note that while it is obvious that the CDELT values are changed to reflect the finer scale, the CRPIX values also need to be adjusted as the reference pixel position is different on the new pixel scale. |
30 | 38 | # You can scale the axes by any amount, including non-integer values, greater or less than 1. |
31 | 39 | # You can also scale each axis independently. |
32 | 40 | # Here we scale both spatial axes by a factor of 1.5. |
|
43 | 51 | reprojected_cube = cube.reproject_to(new_wcs, shape_out=new_shape) |
44 | 52 |
|
45 | 53 | ########################################################################### |
46 | | -# Our new NDCube now has a higher resolution. |
| 54 | +# Our new NDCube now has finer sampling. |
47 | 55 | print(cube.data.shape, reprojected_cube.data.shape) |
48 | 56 |
|
49 | 57 | ########################################################################### |
|
57 | 65 | ax1.set_ylabel('Y [pixel]') |
58 | 66 |
|
59 | 67 | ax2.imshow(reprojected_cube.data, origin='lower', cmap=cm.sdoaia171, vmin=10, vmax=10000) |
60 | | -ax2.set_title('Reprojected (Upscaled)') |
| 68 | +ax2.set_title('Reprojected to New Resolution') |
61 | 69 | ax2.set_xlabel('X [pixel]') |
62 | 70 | ax2.set_ylabel('Y [pixel]') |
63 | 71 | plt.tight_layout() |
|
0 commit comments