def aia171_test_mc(aia171_test_map, aia171_test_map_layer, aia171_test_mc_pixel_displacements): # Create a map that has been shifted a known amount. d1 = sp_shift(aia171_test_map_layer, aia171_test_mc_pixel_displacements) m1 = Map((d1, aia171_test_map.meta)) # Create the mapsequence return Map([aia171_test_map, m1], sequence=True)
def aia171_test_mc(aia171_test_map, aia171_test_map_layer, aia171_test_mc_pixel_displacements): # Create a map that has been shifted a known amount. d1 = sp_shift(aia171_test_map_layer, aia171_test_mc_pixel_displacements) m1 = map.Map((d1, aia171_test_map.meta)) # Create the mapcube return map.Map([aia171_test_map, m1], cube=True)
def lagmatrix(x, lags): """ Returns a matrix of lagged arrays Parameters ---------- :param x: array-like array to lag. first observation is the earliest :param lags: array-like or range with numbers >=0 the lags to create Returns ------- :return: array-like 2-d array of the lagged values """ lags_number = len(lags) n = len(x) xa = np.asarray(x) lagged_matrix = np.zeros(shape=(n, lags_number)) for col, lag in zip(range(lags_number), lags): lagged_matrix[:, col] = sp_shift(xa, lag, cval=np.NaN) return lagged_matrix
def test_mapcube_coalign_by_match_template(): # take the AIA image and shift it # Pixel displacements have the y-displacement as the first entry nx = layer_shape[1] ny = layer_shape[0] pixel_displacements = np.asarray([1.6, 10.1]) known_displacements = { 'x': np.asarray([0.0, pixel_displacements[1] * testmap.scale['x']]), 'y': np.asarray([0.0, pixel_displacements[0] * testmap.scale['y']]) } # Create a map that has been shifted a known amount. d1 = sp_shift(testmap.data, pixel_displacements) m1 = map.Map((d1, testmap.meta)) # Create the mapcube mc = map.Map([testmap, m1], cube=True) # Test to see if the code can recover the displacements. Do the coalignment # using the "return_displacements_only" option test_displacements = mapcube_coalign_by_match_template( mc, return_displacements_only=True) # Assert assert_allclose(test_displacements['x'], known_displacements['x'], rtol=5e-2, atol=0) assert_allclose(test_displacements['y'], known_displacements['y'], rtol=5e-2, atol=0) # Test setting the template as a ndarray template_ndarray = testmap.data[ny / 4:3 * ny / 4, nx / 4:3 * nx / 4] test_displacements = mapcube_coalign_by_match_template( mc, template=template_ndarray, return_displacements_only=True) # Assert assert_allclose(test_displacements['x'], known_displacements['x'], rtol=5e-2, atol=0) assert_allclose(test_displacements['y'], known_displacements['y'], rtol=5e-2, atol=0) # Test setting the template as GenericMap submap = testmap.submap([nx / 4, 3 * nx / 4], [ny / 4, 3 * ny / 4], units='pixels') test_displacements = mapcube_coalign_by_match_template( mc, template=submap, return_displacements_only=True) # Assert assert_allclose(test_displacements['x'], known_displacements['x'], rtol=5e-2, atol=0) assert_allclose(test_displacements['y'], known_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. try: test_displacements = mapcube_coalign_by_match_template( mc, template='broken') except ValueError: pass # Test passing in displacements test_apply_displacements = { 'x': -test_displacements['x'], 'y': -test_displacements['y'] } test_displacements = mapcube_coalign_by_match_template( mc, apply_displacements=test_apply_displacements, return_displacements_only=True) assert_allclose(test_displacements['x'], test_apply_displacements['x'], rtol=5e-2, atol=0) assert_allclose(test_displacements['y'], test_apply_displacements['y'], rtol=5e-2, atol=0) # Test returning using the "with_displacements" option test_output = mapcube_coalign_by_match_template(mc, with_displacements=True) # Assert assert (isinstance(test_output[0], map.MapCube)) assert_allclose(test_output[1]['x'], known_displacements['x'], rtol=5e-2, atol=0) assert_allclose(test_output[1]['y'], known_displacements['y'], rtol=5e-2, atol=0) # Test returning with no extra options - the code returns a mapcube only test_output = mapcube_coalign_by_match_template(mc) 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 = mapcube_coalign_by_match_template(mc, clip=False) assert (test_mc[0].data.shape == testmap.data.shape) assert (test_mc[1].data.shape == testmap.data.shape)