def test_apply_shifts(aia171_test_map): # take two copies of the AIA image and create a test mapcube. mc = map.Map([aia171_test_map, aia171_test_map], cube=True) # Pixel displacements have the y-displacement as the first entry numerical_displacements = {"x": np.asarray([0.0, -2.7]), "y": np.asarray([0.0, -10.4])} astropy_displacements = {"x": numerical_displacements["x"] * u.pix, "y": numerical_displacements["y"] * u.pix} # Test to see if the code can detect the fact that the input shifts are not # astropy quantities with pytest.raises(TypeError): tested = apply_shifts(mc, numerical_displacements["y"], astropy_displacements["x"]) with pytest.raises(TypeError): tested = apply_shifts(mc, astropy_displacements["y"], numerical_displacements["x"]) with pytest.raises(TypeError): tested = apply_shifts(mc, numerical_displacements["y"], numerical_displacements["x"]) # Test returning with no extra options - the code returns a mapcube only test_output = apply_shifts(mc, astropy_displacements["y"], astropy_displacements["x"]) assert(isinstance(test_output, map.MapCube)) # Test returning with no clipping. Output layers should have the same size # as the original input layer. test_mc = apply_shifts(mc, astropy_displacements["y"], astropy_displacements["x"], clip=False) assert(test_mc[0].data.shape == aia171_test_map.data.shape) assert(test_mc[1].data.shape == aia171_test_map.data.shape) # Test returning with clipping. Output layers should be smaller than the # original layer by a known amount. test_mc = apply_shifts(mc, astropy_displacements["y"], astropy_displacements["x"], clip=True) for i in range(0, len(test_mc.maps)): clipped = calculate_clipping(astropy_displacements["y"], astropy_displacements["x"]) assert(test_mc[i].data.shape[0] == mc[i].data.shape[0] - np.max(clipped[0].value)) assert(test_mc[i].data.shape[1] == mc[i].data.shape[1] - np.max(clipped[1].value)) # Test returning with default clipping. The default clipping is set to # true, that is the mapcube is clipped. Output layers should be smaller # than the original layer by a known amount. test_mc = apply_shifts(mc, astropy_displacements["y"], astropy_displacements["x"]) for i in range(0, len(test_mc.maps)): clipped = calculate_clipping(astropy_displacements["y"], astropy_displacements["x"]) assert(test_mc[i].data.shape[0] == mc[i].data.shape[0] - np.max(clipped[0].value)) assert(test_mc[i].data.shape[1] == mc[i].data.shape[1] - np.max(clipped[1].value)) # Test that keywords are correctly passed # Test for an individual keyword test_mc = apply_shifts(mc, astropy_displacements["y"], astropy_displacements["x"], clip=False, cval=np.nan) assert(np.all(np.logical_not(np.isfinite(test_mc[1].data[:, -1])))) # Test for a combination of keywords, and that changing the interpolation # order and how the edges are treated changes the results. test_mc1 = apply_shifts(mc, astropy_displacements["y"], astropy_displacements["x"], clip=False, order=2, mode='reflect') test_mc2 = apply_shifts(mc, astropy_displacements["y"], astropy_displacements["x"], clip=False) assert(np.all(test_mc1[1].data[:, -1] != test_mc2[1].data[:, -1]))
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_apply_shifts(aia171_test_map): # take two copies of the AIA image and create a test mapcube. mc = map.Map([aia171_test_map, aia171_test_map], cube=True) # Pixel displacements have the y-displacement as the first entry numerical_displacements = {"x": np.asarray([0.0, -2.7]), "y": np.asarray([0.0, -10.4])} astropy_displacements = {"x": numerical_displacements["x"] * u.pix, "y": numerical_displacements["y"] * u.pix} # Test to see if the code can detect the fact that the input shifts are not # astropy quantities with pytest.raises(TypeError): tested = apply_shifts(mc, numerical_displacements["y"], astropy_displacements["x"]) with pytest.raises(TypeError): tested = apply_shifts(mc, astropy_displacements["y"], numerical_displacements["x"]) with pytest.raises(TypeError): tested = apply_shifts(mc, numerical_displacements["y"], numerical_displacements["x"]) # Test returning with no extra options - the code returns a mapcube only test_output = apply_shifts(mc, astropy_displacements["y"], astropy_displacements["x"]) assert(isinstance(test_output, map.MapCube)) # Test returning with no clipping. Output layers should have the same size # as the original input layer. test_mc = apply_shifts(mc, astropy_displacements["y"], astropy_displacements["x"], clip=False) assert(test_mc[0].data.shape == aia171_test_map.data.shape) assert(test_mc[1].data.shape == aia171_test_map.data.shape) # Test returning with clipping. Output layers should be smaller than the # original layer by a known amount. test_mc = apply_shifts(mc, astropy_displacements["y"], astropy_displacements["x"], clip=True) for i in range(0, len(test_mc.maps)): clipped = calculate_clipping(astropy_displacements["y"], astropy_displacements["x"]) assert(test_mc[i].data.shape[0] == mc[i].data.shape[0] - np.max(clipped[0].value)) assert(test_mc[i].data.shape[1] == mc[i].data.shape[1] - np.max(clipped[1].value)) # Test returning with default clipping. The default clipping is set to # true, that is the mapcube is clipped. Output layers should be smaller # than the original layer by a known amount. test_mc = apply_shifts(mc, astropy_displacements["y"], astropy_displacements["x"]) for i in range(0, len(test_mc.maps)): clipped = calculate_clipping(astropy_displacements["y"], astropy_displacements["x"]) assert(test_mc[i].data.shape[0] == mc[i].data.shape[0] - np.max(clipped[0].value)) assert(test_mc[i].data.shape[1] == mc[i].data.shape[1] - np.max(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'] / 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_calculate_clipping(aia171_test_clipping): answer = calculate_clipping(aia171_test_clipping * u.pix, aia171_test_clipping * u.pix) assert_array_almost_equal(answer, ([2.0, 1.0] * u.pix, [2.0, 1.0] * u.pix))
def test_calculate_clipping(aia171_test_clipping): answer = calculate_clipping(aia171_test_clipping * u.pix, aia171_test_clipping * u.pix) assert_array_almost_equal(answer, ([2.0, 1.0]*u.pix, [2.0, 1.0]*u.pix))
def test_calculate_clipping(): answer = calculate_clipping(clip_test_array *u.pix, clip_test_array *u.pix) assert_array_almost_equal(answer, ([2.0, 1.0]*u.pix, [2.0, 1.0]*u.pix))
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))
def test_calculate_clipping(): answer = calculate_clipping(clip_test_array, clip_test_array) assert (answer == ([2.0, 1.0], [2.0, 1.0]))
def test_calculate_clipping(): answer = calculate_clipping(clip_test_array, clip_test_array) assert(answer == ([2.0, 1.0], [2.0, 1.0]))