def test_reproject_roundtrip(file_format): # Test the reprojection with solar data, which ensures that the masking of # pixels based on round-tripping works correctly. Using asdf is not just # about testing a different format but making sure that GWCS works. # The observer handling changed in 2.1. pytest.importorskip('sunpy', minversion='2.1.0') from sunpy.map import Map from sunpy.coordinates.ephemeris import get_body_heliographic_stonyhurst if file_format == 'fits': map_aia = Map(get_pkg_data_filename('data/aia_171_level1.fits', package='reproject.tests')) data = map_aia.data wcs = map_aia.wcs date = map_aia.date target_wcs = wcs.deepcopy() elif file_format == 'asdf': pytest.importorskip('astropy', minversion='4.0') pytest.importorskip('gwcs', minversion='0.12') asdf = pytest.importorskip('asdf') aia = asdf.open( get_pkg_data_filename('data/aia_171_level1.asdf', package='reproject.tests')) data = aia['data'][...] wcs = aia['wcs'] date = wcs.output_frame.reference_frame.obstime target_wcs = Map( get_pkg_data_filename('data/aia_171_level1.fits', package='reproject.tests')).wcs.deepcopy() else: raise ValueError('file_format should be fits or asdf') # Reproject to an observer on Venus target_wcs.wcs.cdelt = ([24, 24]*u.arcsec).to(u.deg) target_wcs.wcs.crpix = [64, 64] venus = get_body_heliographic_stonyhurst('venus', date) target_wcs.wcs.aux.hgln_obs = venus.lon.to_value(u.deg) target_wcs.wcs.aux.hglt_obs = venus.lat.to_value(u.deg) target_wcs.wcs.aux.dsun_obs = venus.radius.to_value(u.m) output, footprint = reproject_interp((data, wcs), target_wcs, (128, 128)) header_out = target_wcs.to_header() # ASTROPY_LT_40: astropy v4.0 introduced new default header keywords, # once we support only astropy 4.0 and later we can update the reference # data files and remove this section. for key in ('CRLN_OBS', 'CRLT_OBS', 'DSUN_OBS', 'HGLN_OBS', 'HGLT_OBS', 'MJDREFF', 'MJDREFI', 'MJDREF', 'MJD-OBS', 'RSUN_REF'): header_out.pop(key, None) header_out['DATE-OBS'] = header_out['DATE-OBS'].replace('T', ' ') return array_footprint_to_hdulist(output, footprint, header_out)
def test_reproject_roundtrip(file_format): # Test the reprojection with solar data, which ensures that the masking of # pixels based on round-tripping works correctly. Using asdf is not just # about testing a different format but making sure that GWCS works. pytest.importorskip('sunpy', minversion='1.0.4') from sunpy.map import Map from sunpy.coordinates.ephemeris import get_body_heliographic_stonyhurst if file_format == 'fits': map_aia = Map(os.path.join(DATA, 'aia_171_level1.fits')) data = map_aia.data wcs = map_aia.wcs date = map_aia.date target_wcs = wcs.deepcopy() elif file_format == 'asdf': pytest.importorskip('astropy', minversion='4.0') pytest.importorskip('gwcs', minversion='0.12') asdf = pytest.importorskip('asdf') aia = asdf.open(os.path.join(DATA, 'aia_171_level1.asdf')) data = aia['data'][...] wcs = aia['wcs'] date = wcs.output_frame.reference_frame.obstime target_wcs = Map(os.path.join(DATA, 'aia_171_level1.fits')).wcs.deepcopy() else: raise ValueError('file_format should be fits or asdf') # Reproject to an observer on Venus target_wcs.wcs.cdelt = ([24, 24] * u.arcsec).to(u.deg) target_wcs.wcs.crpix = [64, 64] venus = get_body_heliographic_stonyhurst('venus', date) target_wcs.heliographic_observer = venus output, footprint = reproject_interp((data, wcs), target_wcs, (128, 128)) return array_footprint_to_hdulist(output, footprint, target_wcs.to_header())