def test_calculate_match_template_shift(aia171_test_mc, aia171_mc_arcsec_displacements, aia171_test_map, aia171_test_map_layer, aia171_test_map_layer_shape): # Define these local variables to make the code more readable ny = aia171_test_map_layer_shape[0] nx = aia171_test_map_layer_shape[1] # Test to see if the code can recover the displacements. test_displacements = calculate_match_template_shift(aia171_test_mc) assert_allclose(test_displacements['x'], aia171_mc_arcsec_displacements['x'], rtol=5e-2, atol=0) assert_allclose(test_displacements['y'], aia171_mc_arcsec_displacements['y'], rtol=5e-2, atol=0 ) # Test setting the template as a ndarray template_ndarray = aia171_test_map_layer[ny // 4: 3 * ny // 4, nx // 4: 3 * nx // 4] test_displacements = calculate_match_template_shift(aia171_test_mc, template=template_ndarray) assert_allclose(test_displacements['x'], aia171_mc_arcsec_displacements['x'], rtol=5e-2, atol=0) assert_allclose(test_displacements['y'], aia171_mc_arcsec_displacements['y'], rtol=5e-2, atol=0) # Test setting the template as GenericMap submap = aia171_test_map.submap([nx / 4, ny / 4]*u.pix, [3 * nx / 4, 3 * ny / 4]*u.pix) test_displacements = calculate_match_template_shift(aia171_test_mc, template=submap) assert_allclose(test_displacements['x'], aia171_mc_arcsec_displacements['x'], rtol=5e-2, atol=0) assert_allclose(test_displacements['y'], aia171_mc_arcsec_displacements['y'], rtol=5e-2, atol=0) # Test setting the template as something other than a ndarray and a # GenericMap. This should throw a ValueError. with pytest.raises(ValueError): dummy_return_value = calculate_match_template_shift(aia171_test_mc, template='broken')
def test_calculate_match_template_shift(aia171_test_mc, aia171_mc_arcsec_displacements, aia171_test_map, aia171_test_map_layer, aia171_test_map_layer_shape): # Define these local variables to make the code more readable ny = aia171_test_map_layer_shape[0] nx = aia171_test_map_layer_shape[1] # Test to see if the code can recover the displacements. test_displacements = calculate_match_template_shift(aia171_test_mc) assert_allclose(test_displacements['x'], aia171_mc_arcsec_displacements['x'], rtol=5e-2, atol=0) assert_allclose(test_displacements['y'], aia171_mc_arcsec_displacements['y'], rtol=5e-2, atol=0 ) # Test setting the template as a ndarray template_ndarray = aia171_test_map_layer[ny / 4: 3 * ny / 4, nx / 4: 3 * nx / 4] test_displacements = calculate_match_template_shift(aia171_test_mc, template=template_ndarray) assert_allclose(test_displacements['x'], aia171_mc_arcsec_displacements['x'], rtol=5e-2, atol=0) assert_allclose(test_displacements['y'], aia171_mc_arcsec_displacements['y'], rtol=5e-2, atol=0) # Test setting the template as GenericMap submap = aia171_test_map.submap([nx / 4, 3 * nx / 4]*u.pix, [ny / 4, 3 * ny / 4]*u.pix) test_displacements = calculate_match_template_shift(aia171_test_mc, template=submap) assert_allclose(test_displacements['x'], aia171_mc_arcsec_displacements['x'], rtol=5e-2, atol=0) assert_allclose(test_displacements['y'], aia171_mc_arcsec_displacements['y'], rtol=5e-2, atol=0) # Test setting the template as something other than a ndarray and a # GenericMap. This should throw a ValueError. with pytest.raises(ValueError): dummy_return_value = calculate_match_template_shift(aia171_test_mc, template='broken')
def test_mapcube_coalign_by_match_template(aia171_test_mc, aia171_test_map_layer_shape): # Define these local variables to make the code more readable ny = aia171_test_map_layer_shape[0] nx = aia171_test_map_layer_shape[1] # Get the calculated test displacements test_displacements = calculate_match_template_shift(aia171_test_mc) # Test passing in displacements test_mc = mapcube_coalign_by_match_template(aia171_test_mc, shift=test_displacements) # Make sure the output is a mapcube assert isinstance(test_mc, map.MapCube) # Test returning with no clipping. Output layers should have the same size # as the original input layer. test_mc = mapcube_coalign_by_match_template(aia171_test_mc, clip=False) assert test_mc[0].data.shape == aia171_test_map_layer_shape assert test_mc[1].data.shape == aia171_test_map_layer_shape # Test the returned mapcube using the default - clipping on. # All output layers should have the same size # which is smaller than the input by a known amount test_mc = mapcube_coalign_by_match_template(aia171_test_mc) x_displacement_pixels = test_displacements["x"] / test_mc[0].scale.x y_displacement_pixels = test_displacements["y"] / test_mc[0].scale.y expected_clipping = calculate_clipping(y_displacement_pixels, x_displacement_pixels) number_of_pixels_clipped = [np.sum(np.abs(expected_clipping[0])), np.sum(np.abs(expected_clipping[1]))] assert test_mc[0].data.shape == (ny - number_of_pixels_clipped[0].value, nx - number_of_pixels_clipped[1].value) assert test_mc[1].data.shape == (ny - number_of_pixels_clipped[0].value, nx - number_of_pixels_clipped[1].value) # Test the returned mapcube explicitly using clip=True. # All output layers should have the same size # which is smaller than the input by a known amount test_mc = mapcube_coalign_by_match_template(aia171_test_mc, clip=True) x_displacement_pixels = test_displacements["x"] / test_mc[0].scale.x y_displacement_pixels = test_displacements["y"] / test_mc[0].scale.y expected_clipping = calculate_clipping(y_displacement_pixels, x_displacement_pixels) number_of_pixels_clipped = [np.sum(np.abs(expected_clipping[0])), np.sum(np.abs(expected_clipping[1]))] assert test_mc[0].data.shape == (ny - number_of_pixels_clipped[0].value, nx - number_of_pixels_clipped[1].value) assert test_mc[1].data.shape == (ny - number_of_pixels_clipped[0].value, nx - number_of_pixels_clipped[1].value) # Test that the reference pixel of each map in the coaligned mapcube is # correct. for im, m in enumerate(aia171_test_mc): for i_s, s in enumerate(["x", "y"]): assert_allclose( aia171_test_mc[im].reference_pixel[i_s] - test_mc[im].reference_pixel[i_s], test_displacements[s][im] / m.scale[i_s], rtol=5e-2, atol=0, )
def test_mapcube_coalign_by_match_template(aia171_test_mc, aia171_test_map_layer_shape): # Define these local variables to make the code more readable ny = aia171_test_map_layer_shape[0] nx = aia171_test_map_layer_shape[1] # Get the calculated test displacements test_displacements = calculate_match_template_shift(aia171_test_mc) # Test passing in displacements test_mc = mapcube_coalign_by_match_template(aia171_test_mc, shift=test_displacements) # Make sure the output is a mapcube assert(isinstance(test_mc, map.MapCube)) # Test returning with no clipping. Output layers should have the same size # as the original input layer. test_mc = mapcube_coalign_by_match_template(aia171_test_mc, clip=False) assert(test_mc[0].data.shape == aia171_test_map_layer_shape) assert(test_mc[1].data.shape == aia171_test_map_layer_shape) # Test the returned mapcube using the default - clipping on. # All output layers should have the same size # which is smaller than the input by a known amount test_mc = mapcube_coalign_by_match_template(aia171_test_mc) x_displacement_pixels = test_displacements['x'] / test_mc[0].scale.x y_displacement_pixels = test_displacements['y'] / test_mc[0].scale.y expected_clipping = calculate_clipping(y_displacement_pixels, x_displacement_pixels) number_of_pixels_clipped = [np.sum(np.abs(expected_clipping[0])), np.sum(np.abs(expected_clipping[1]))] assert(test_mc[0].data.shape == (ny - number_of_pixels_clipped[0].value, nx - number_of_pixels_clipped[1].value)) assert(test_mc[1].data.shape == (ny - number_of_pixels_clipped[0].value, nx - number_of_pixels_clipped[1].value)) # Test the returned mapcube explicitly using clip=True. # All output layers should have the same size # which is smaller than the input by a known amount test_mc = mapcube_coalign_by_match_template(aia171_test_mc, clip=True) x_displacement_pixels = test_displacements['x'] / test_mc[0].scale.x y_displacement_pixels = test_displacements['y'] / test_mc[0].scale.y expected_clipping = calculate_clipping(y_displacement_pixels, x_displacement_pixels) number_of_pixels_clipped = [np.sum(np.abs(expected_clipping[0])), np.sum(np.abs(expected_clipping[1]))] assert(test_mc[0].data.shape == (ny - number_of_pixels_clipped[0].value, nx - number_of_pixels_clipped[1].value)) assert(test_mc[1].data.shape == (ny - number_of_pixels_clipped[0].value, nx - number_of_pixels_clipped[1].value)) # Test that the reference pixel of each map in the coaligned mapcube is # correct. for im, m in enumerate(aia171_test_mc): for i_s, s in enumerate(['x', 'y']): assert_allclose(aia171_test_mc[im].reference_pixel[i_s] - test_mc[im].reference_pixel[i_s], test_displacements[s][im] / m.scale[i_s], rtol=5e-2, atol=0)
def test_mapcube_coalign_by_match_template(aia171_test_mc, aia171_test_map_layer_shape): # Define these local variables to make the code more readable ny = aia171_test_map_layer_shape[0] nx = aia171_test_map_layer_shape[1] # Get the test displacements test_displacements = calculate_match_template_shift(aia171_test_mc) # Test passing in displacements test_mc = mapcube_coalign_by_match_template(aia171_test_mc, shift=test_displacements) # Make sure the output is a mapcube assert(isinstance(test_mc, map.MapCube)) # Test returning with no clipping. Output layers should have the same size # as the original input layer. test_mc = mapcube_coalign_by_match_template(aia171_test_mc, clip=False) assert(test_mc[0].data.shape == aia171_test_map_layer_shape) assert(test_mc[1].data.shape == aia171_test_map_layer_shape) # Test the returned mapcube using the default - clipping on. # All output layers should have the same size # which is smaller than the input by a known amount test_mc = mapcube_coalign_by_match_template(aia171_test_mc) x_displacement_pixels = test_displacements['x'] / test_mc[0].scale.x y_displacement_pixels = test_displacements['y'] / test_mc[0].scale.y expected_clipping = calculate_clipping(y_displacement_pixels, x_displacement_pixels) number_of_pixels_clipped = [np.sum(np.abs(expected_clipping[0])), np.sum(np.abs(expected_clipping[1]))] assert(test_mc[0].data.shape == (ny - number_of_pixels_clipped[0].value, nx - number_of_pixels_clipped[1].value)) assert(test_mc[1].data.shape == (ny - number_of_pixels_clipped[0].value, nx - number_of_pixels_clipped[1].value)) # Test the returned mapcube explicitly using clip=True. # All output layers should have the same size # which is smaller than the input by a known amount test_mc = mapcube_coalign_by_match_template(aia171_test_mc, clip=True) x_displacement_pixels = test_displacements['x'] / test_mc[0].scale.x y_displacement_pixels = test_displacements['y'] / test_mc[0].scale.y expected_clipping = calculate_clipping(y_displacement_pixels, x_displacement_pixels) number_of_pixels_clipped = [np.sum(np.abs(expected_clipping[0])), np.sum(np.abs(expected_clipping[1]))] assert(test_mc[0].data.shape == (ny - number_of_pixels_clipped[0].value, nx - number_of_pixels_clipped[1].value)) assert(test_mc[1].data.shape == (ny - number_of_pixels_clipped[0].value, nx - number_of_pixels_clipped[1].value))
def test_mapcube_coalign_by_match_template(aia171_test_mc, aia171_test_map_layer_shape): # Define these local variables to make the code more readable ny = aia171_test_map_layer_shape[0] nx = aia171_test_map_layer_shape[1] # Get the test displacements test_displacements = calculate_match_template_shift(aia171_test_mc) # Test passing in displacements test_mc = mapcube_coalign_by_match_template(aia171_test_mc, shift=test_displacements) # Make sure the output is a mapcube assert (isinstance(test_mc, map.MapCube)) # Test returning with no clipping. Output layers should have the same size # as the original input layer. test_mc = mapcube_coalign_by_match_template(aia171_test_mc, clip=False) assert (test_mc[0].data.shape == aia171_test_map_layer_shape) assert (test_mc[1].data.shape == aia171_test_map_layer_shape) # Test the returned mapcube using the default - clipping on. # All output layers should have the same size # which is smaller than the input by a known amount test_mc = mapcube_coalign_by_match_template(aia171_test_mc) x_displacement_pixels = test_displacements['x'].to( 'arcsec').value / test_mc[0].scale['x'] * u.pix y_displacement_pixels = test_displacements['y'].to( 'arcsec').value / test_mc[0].scale['y'] * u.pix expected_clipping = calculate_clipping(y_displacement_pixels, x_displacement_pixels) number_of_pixels_clipped = [ np.sum(np.abs(expected_clipping[0])), np.sum(np.abs(expected_clipping[1])) ] assert (test_mc[0].data.shape == (ny - number_of_pixels_clipped[0].value, nx - number_of_pixels_clipped[1].value)) assert (test_mc[1].data.shape == (ny - number_of_pixels_clipped[0].value, nx - number_of_pixels_clipped[1].value)) # Test the returned mapcube explicitly using clip=True. # All output layers should have the same size # which is smaller than the input by a known amount test_mc = mapcube_coalign_by_match_template(aia171_test_mc, clip=True) x_displacement_pixels = test_displacements['x'].to( 'arcsec').value / test_mc[0].scale['x'] * u.pix y_displacement_pixels = test_displacements['y'].to( 'arcsec').value / test_mc[0].scale['y'] * u.pix expected_clipping = calculate_clipping(y_displacement_pixels, x_displacement_pixels) number_of_pixels_clipped = [ np.sum(np.abs(expected_clipping[0])), np.sum(np.abs(expected_clipping[1])) ] assert (test_mc[0].data.shape == (ny - number_of_pixels_clipped[0].value, nx - number_of_pixels_clipped[1].value)) assert (test_mc[1].data.shape == (ny - number_of_pixels_clipped[0].value, nx - number_of_pixels_clipped[1].value))