From 16dc71eccc704b29e8ce513ce084d0cc1d4a66de Mon Sep 17 00:00:00 2001 From: John ZuHone Date: Thu, 8 Jul 2021 22:03:57 -0400 Subject: [PATCH 1/2] Fix combining FITS images--more than one of the images was being marked as the PrimaryHDU --- yt/visualization/fits_image.py | 4 ++-- yt/visualization/tests/test_fits_image.py | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/yt/visualization/fits_image.py b/yt/visualization/fits_image.py index 4bb52158b4..6c89569464 100644 --- a/yt/visualization/fits_image.py +++ b/yt/visualization/fits_image.py @@ -735,12 +735,12 @@ def from_images(cls, image_list): w = first_image.wcs img_shape = first_image.shape data = [] - for is_first, _is_last, fid in mark_ends(image_list): + for fid in image_list: assert_same_wcs(w, fid.wcs) if img_shape != fid.shape: raise RuntimeError("Images do not have the same shape!") for hdu in fid.hdulist: - if is_first: + if len(data) == 0: data.append(_astropy.pyfits.PrimaryHDU(hdu.data, header=hdu.header)) else: data.append(_astropy.pyfits.ImageHDU(hdu.data, header=hdu.header)) diff --git a/yt/visualization/tests/test_fits_image.py b/yt/visualization/tests/test_fits_image.py index 3db5e39da1..bb5ee0a44f 100644 --- a/yt/visualization/tests/test_fits_image.py +++ b/yt/visualization/tests/test_fits_image.py @@ -101,6 +101,9 @@ def test_fits_image(): assert_equal(combined_fid.velocity_unit, dens_img.velocity_unit) assert_equal(combined_fid.magnetic_unit, dens_img.magnetic_unit) assert_equal(combined_fid.current_time, dens_img.current_time) + # Writing the FITS file ensures that we have assembled the images + # together correctly + combined_fid.writeto("combined.fits", overwrite=True) cut = ds.cutting([0.1, 0.2, -0.9], [0.5, 0.42, 0.6]) cut_frb = cut.to_frb((0.5, "unitary"), 128) From 45b2e6339f19bd2b71627e7fce1a48aa90d69404 Mon Sep 17 00:00:00 2001 From: John ZuHone Date: Tue, 27 Jul 2021 22:49:13 -0400 Subject: [PATCH 2/2] make sure we actually test something --- yt/visualization/tests/test_fits_image.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/yt/visualization/tests/test_fits_image.py b/yt/visualization/tests/test_fits_image.py index bb5ee0a44f..db5dfc6fc4 100644 --- a/yt/visualization/tests/test_fits_image.py +++ b/yt/visualization/tests/test_fits_image.py @@ -101,9 +101,13 @@ def test_fits_image(): assert_equal(combined_fid.velocity_unit, dens_img.velocity_unit) assert_equal(combined_fid.magnetic_unit, dens_img.magnetic_unit) assert_equal(combined_fid.current_time, dens_img.current_time) + + # Make sure that we can combine FITSImageData instances with more + # than one image each + combined_fid2 = FITSImageData.from_images([combined_fid, combined_fid]) # Writing the FITS file ensures that we have assembled the images # together correctly - combined_fid.writeto("combined.fits", overwrite=True) + combined_fid2.writeto("combined.fits", overwrite=True) cut = ds.cutting([0.1, 0.2, -0.9], [0.5, 0.42, 0.6]) cut_frb = cut.to_frb((0.5, "unitary"), 128)