def test_calculate_solar_rotate_shift(aia171_test_mapcube, known_displacements_layer_index0, known_displacements_layer_index1): # Test that the default works test_output = calculate_solar_rotate_shift(aia171_test_mapcube) assert_allclose(test_output['x'].to('arcsec').value, known_displacements_layer_index0['x'], rtol=5e-2, atol=1e-5) assert_allclose(test_output['y'].to('arcsec').value, known_displacements_layer_index0['y'], rtol=5e-2, atol=1e-5) # Test that the rotation relative to a nonzero layer_index works test_output = calculate_solar_rotate_shift(aia171_test_mapcube, layer_index=1) assert_allclose(test_output['x'].to('arcsec').value, known_displacements_layer_index1['x'], rtol=5e-2, atol=1e-5) assert_allclose(test_output['y'].to('arcsec').value, known_displacements_layer_index1['y'], rtol=5e-2, atol=1e-5)
def test_calculate_solar_rotate_shift(aia171_test_mapcube, known_displacements_layer_index0, known_displacements_layer_index1): # Test that the default works test_output = calculate_solar_rotate_shift(aia171_test_mapcube) assert_allclose(test_output['x'].to('arcsec').value, known_displacements_layer_index0['x'], rtol=5e-2, atol=0) assert_allclose(test_output['y'].to('arcsec').value, known_displacements_layer_index0['y'], rtol=5e-2, atol=0) # Test that the rotation relative to a nonzero layer_index works test_output = calculate_solar_rotate_shift(aia171_test_mapcube, layer_index=1) assert_allclose(test_output['x'].to('arcsec').value, known_displacements_layer_index1['x'], rtol=5e-2, atol=0) assert_allclose(test_output['y'].to('arcsec').value, known_displacements_layer_index1['y'], rtol=5e-2, atol=0)
def test_mapcube_solar_derotate(aia171_test_mapcube, aia171_test_submap): # Test that a mapcube is returned when the clipping is False tmc = mapcube_solar_derotate(aia171_test_mapcube, clip=False) assert(isinstance(tmc, map.MapCube)) # Test that all entries have the same shape - nothing clipped for m in tmc: assert(m.data.shape == aia171_test_submap.data.shape) # Test that the returned reference pixels are correctly displaced. tmc = mapcube_solar_derotate(aia171_test_mapcube, clip=True) tshift = calculate_solar_rotate_shift(aia171_test_mapcube, layer_index=1) for im, m in enumerate(tmc): for i_s, s in enumerate(['x', 'y']): assert_allclose(m.reference_pixel[i_s], aia171_test_submap.reference_pixel[i_s] + tshift[s][im] / m.scale[i_s] - tshift[s][0] / m.scale[i_s], rtol=5e-2, atol=0) # Test that a mapcube is returned on default clipping (clipping is True) tmc = mapcube_solar_derotate(aia171_test_mapcube) assert(isinstance(tmc, map.MapCube)) # Test that the shape of data is correct when clipped clipped_shape = (25, 19) for m in tmc: assert(m.data.shape == clipped_shape)
def test_mapsequence_solar_derotate(aia171_test_mapsequence, aia171_test_submap): # Test that a mapsequence is returned when the clipping is False. tmc = mapsequence_solar_derotate(aia171_test_mapsequence, clip=False) assert(isinstance(tmc, sunpy.map.MapSequence)) # Test that all entries have the same shape when clipping is False for m in tmc: assert(m.data.shape == aia171_test_submap.data.shape) # Test that a mapsequence is returned on default clipping (clipping is True) tmc = mapsequence_solar_derotate(aia171_test_mapsequence) assert(isinstance(tmc, sunpy.map.MapSequence)) # Test that the shape of data is correct when clipped clipped_shape = (25, 18) for m in tmc: assert(m.data.shape == clipped_shape) # Test that the returned reference pixels are correctly displaced. layer_index = 0 derotated = mapsequence_solar_derotate(aia171_test_mapsequence, clip=True, layer_index=layer_index) tshift = calculate_solar_rotate_shift(aia171_test_mapsequence, layer_index=layer_index) derotated_reference_pixel_at_layer_index = derotated[layer_index].reference_pixel for i, m_derotated in enumerate(derotated): for i_s, s in enumerate(['x', 'y']): diff_in_rotated_reference_pixel = derotated[i].reference_pixel[i_s] - derotated_reference_pixel_at_layer_index[i_s] diff_arcsec = tshift[s][i] - tshift[s][layer_index] diff_pixel = diff_arcsec / m.scale[0] assert_quantity_allclose(diff_in_rotated_reference_pixel, diff_pixel, rtol=5e-2)
def test_mapcube_solar_derotate(aia171_test_mapcube, aia171_test_submap): # Test that a mapcube is returned when the clipping is False. tmc = mapcube_solar_derotate(aia171_test_mapcube, clip=False) assert(isinstance(tmc, sunpy.map.MapCube)) # Test that all entries have the same shape when clipping is False for m in tmc: assert(m.data.shape == aia171_test_submap.data.shape) # Test that a mapcube is returned on default clipping (clipping is True) tmc = mapcube_solar_derotate(aia171_test_mapcube) assert(isinstance(tmc, sunpy.map.MapCube)) # Test that the shape of data is correct when clipped clipped_shape = (24, 19) for m in tmc: assert(m.data.shape == clipped_shape) # Test that the returned reference pixels are correctly displaced. layer_index = 0 derotated = mapcube_solar_derotate(aia171_test_mapcube, clip=True, layer_index=layer_index) tshift = calculate_solar_rotate_shift(aia171_test_mapcube, layer_index=layer_index) derotated_reference_pixel_at_layer_index = derotated[layer_index].reference_pixel for i, m_derotated in enumerate(derotated): for i_s, s in enumerate(['x', 'y']): diff_in_rotated_reference_pixel = derotated[i].reference_pixel[i_s] - derotated_reference_pixel_at_layer_index[i_s] diff_arcsec = tshift[s][i] - tshift[s][layer_index] diff_pixel = diff_arcsec / m.scale[0] assert_quantity_allclose(diff_in_rotated_reference_pixel, diff_pixel, rtol=5e-2)
# Select the middle image, to derotate around mid_file = np.int(np.floor(nf / 2)) # make mapcube containing first and last maps & calculate derotation shifts # if not centered at 0deg long, shift amount wont be enough -- # maybe only calculate latitude, use other method for longitude trim mc_shifts = [] mapI = Map(flist[0]) mapF = Map(flist[-1]) mc_shifts.append(mapI) mc_shifts.append(mapF) #new_mapcube1 = Map(mc_shifts, cube=True) new_mapcube1 = Map(mc_shifts, sequence=True) shifts = calculate_solar_rotate_shift(new_mapcube1, layer_index=0) # compute longitude / latitude shift over timespan diffLon = np.abs(np.floor((np.floor(shifts['x'][1].value) / 2.))) # calculate rotation amount in pixels diffLonPix = diffLon / (mapI.scale)[0].value # calculate total latitude shift in pixels, x2 since underestimated? diffLatPix = int((np.abs((shifts['y'][1].value)) / (mapI.scale)[1].value) * 2.) #print(diffLon, diffLonPix) #print(diffLatPix*mapI.scale[1].value, diffLatPix) if diffLatPix == 0: diffLatPix = 5 # value of zero messes with next steps