def test_all_coordinates_from_map(sub_smap): coordinates = all_coordinates_from_map(sub_smap) shape = sub_smap.data.shape assert coordinates.shape == (shape[0], shape[1]) assert isinstance(coordinates, SkyCoord) assert isinstance(coordinates.frame, BaseCoordinateFrame) assert coordinates.frame.name == sub_smap.coordinate_frame.name
def process_kcor_map(m, rsun=2.7, gamma=0.7): import skimage.exposure from sunpy.map.maputils import all_coordinates_from_map hpc_coords = all_coordinates_from_map(m) r = np.sqrt(hpc_coords.Tx ** 2 + hpc_coords.Ty ** 2) / m.rsun_obs mask = r > rsun # remove negative values for gamma correction rescaled_data = m.data # don't scale if NRGF if "PRODUCT" in m.fits_header: display_min = m.fits_header["DISPMIN"] display_max = m.fits_header["DISPMAX"] processed_data = np.clip(rescaled_data, display_min, display_max) - display_min processed_data /= display_max - display_min processed_map = Map(processed_data, m.meta, mask=mask) processed_map.plot_settings["cmap"] = kcor_nrgf_cmap() processed_map.plot_settings["norm"] = matplotlib.colors.NoNorm() return(processed_map) rescaled_data[rescaled_data < 0.0] = 0.0 adjusted_data = skimage.exposure.adjust_gamma(rescaled_data, gamma=gamma) processed_map = Map(adjusted_data, m.meta, mask=mask) return(processed_map)
def process_aia_map(m, rsun=1.2, threshold=35): from sunpy.map.maputils import all_coordinates_from_map hpc_coords = all_coordinates_from_map(m) r = np.sqrt(hpc_coords.Tx ** 2 + hpc_coords.Ty ** 2) / m.rsun_obs mask = ma.logical_and(r > rsun, m.data < threshold) processed_map = Map(m.data, m.meta, mask=mask) return(processed_map)
def mask_outside_disk(inst_map): # Find coordinates and radius hpc_coords = all_coordinates_from_map(inst_map) r = np.sqrt(hpc_coords.Tx**2 + hpc_coords.Ty**2) / inst_map.rsun_obs # Mask everything outside of the solar disk mask = ma.masked_greater_equal(r, 1) ma.set_fill_value(mask, np.nan) where_disk = np.where(mask.mask == 1) return where_disk
def test_coordinate_is_on_solar_disk(aia171_test_map, all_off_disk_map, all_on_disk_map, straddles_limb_map): off_disk = aia171_test_map.bottom_left_coord on_disk = aia171_test_map.center # Check for individual coordinates assert coordinate_is_on_solar_disk(on_disk) assert ~coordinate_is_on_solar_disk(off_disk) # Raise the error with pytest.raises(ValueError): coordinate_is_on_solar_disk( on_disk.transform_to(HeliographicStonyhurst)) # Check for sets of coordinates assert np.any( coordinate_is_on_solar_disk(all_coordinates_from_map(aia171_test_map))) assert np.any(~coordinate_is_on_solar_disk( all_coordinates_from_map(aia171_test_map))) assert np.all(~coordinate_is_on_solar_disk( all_coordinates_from_map(all_off_disk_map))) assert np.all( coordinate_is_on_solar_disk(all_coordinates_from_map(all_on_disk_map))) assert np.any( coordinate_is_on_solar_disk( all_coordinates_from_map(straddles_limb_map))) assert np.any(~coordinate_is_on_solar_disk( all_coordinates_from_map(straddles_limb_map)))
def test_all_coordinates_from_map(sub_smap): coordinates = all_coordinates_from_map(sub_smap) shape = sub_smap.data.shape assert coordinates.shape == (shape[0], shape[1]) assert isinstance(coordinates, SkyCoord) assert isinstance(coordinates.frame, BaseCoordinateFrame) assert coordinates.frame.name == sub_smap.coordinate_frame.name xpix, ypix = sub_smap.world_to_pixel(coordinates[0, 0]) assert_quantity_allclose(xpix, 0 * u.pix, atol=1e-7 * u.pix) assert_quantity_allclose(ypix, 0 * u.pix, atol=1e-7 * u.pix) xpix, ypix = sub_smap.world_to_pixel(coordinates[-1, -1]) assert_quantity_allclose(xpix, sub_smap.dimensions[0] - 1 * u.pix) assert_quantity_allclose(ypix, sub_smap.dimensions[1] - 1 * u.pix)
def test_coordinate_is_on_solar_disk(aia171_test_map, all_off_disk_map, all_on_disk_map, straddles_limb_map): off_disk = aia171_test_map.bottom_left_coord on_disk = aia171_test_map.center # Check for individual coordinates assert coordinate_is_on_solar_disk(on_disk) assert ~coordinate_is_on_solar_disk(off_disk) # Raise the error with pytest.raises(ValueError): coordinate_is_on_solar_disk(on_disk.transform_to(HeliographicStonyhurst)) # Check for sets of coordinates assert np.any(coordinate_is_on_solar_disk(all_coordinates_from_map(aia171_test_map))) assert np.any(~coordinate_is_on_solar_disk(all_coordinates_from_map(aia171_test_map))) assert np.all(~coordinate_is_on_solar_disk(all_coordinates_from_map(all_off_disk_map))) assert np.all(coordinate_is_on_solar_disk(all_coordinates_from_map(all_on_disk_map))) assert np.any(coordinate_is_on_solar_disk(all_coordinates_from_map(straddles_limb_map))) assert np.any(~coordinate_is_on_solar_disk(all_coordinates_from_map(straddles_limb_map)))
# To find the brightest pixel, we find the maximum in the AIA image data # then transform that pixel coordinate to a map coordinate. pixel_pos = np.argwhere(aia.data == aia.data.max()) * u.pixel hpc_max = aia.pixel_to_world(pixel_pos[:, 1], pixel_pos[:, 0]) ############################################################################### # Let's plot the results. fig = plt.figure() ax = plt.subplot(projection=aia) aia.plot() ax.plot_coord(hpc_max, 'bx', color='white', marker='x', markersize=15) plt.show() ############################################################################### # A utility function gives us access to the helioprojective coordinate of each # pixels. We create a new array which contains the normalized radial position # for each pixel adjusted for the position of the brightest pixel # (using ``hpc_max``) and then create a new map. hpc_coords = all_coordinates_from_map(aia) r_mask = np.sqrt((hpc_coords.Tx - hpc_max.Tx)**2 + (hpc_coords.Ty - hpc_max.Ty)**2) / aia.rsun_obs mask = ma.masked_less_equal(r_mask, 0.1) scaled_map = sunpy.map.Map(aia.data, aia.meta, mask=mask.mask) ############################################################################### # Let's plot the results. fig = plt.figure() ax = plt.subplot(projection=scaled_map) scaled_map.plot() plt.show()
def match_disk(fits_file, ref_fits): sun_map = sunpy.map.Map(fits_file) hpc_coords = all_coordinates_from_map(sun_map) r = np.sqrt(hpc_coords.Tx ** 2 + hpc_coords.Ty ** 2) / sun_map.rsun_obs mask = ma.masked_less_equal(r, 1) sun_map.data[:] -= sun_map.data.min() sun_map.data[:] += 10e-6 if sun_map.detector == 'EUVI': sq_img = sun_map.data * sun_map.data sun_map.data[:] = sq_img[:] if sun_map.detector == 'EIT': sq_img = np.sqrt(sun_map.data) sun_map.data[:] = sq_img[:] masked = sun_map.data * mask.mask masked[masked == 0] = np.nan # force scale of 1 arcsec per pix scale = 1 / sun_map.scale[1].value masked = rescale(masked, sun_map.scale[1].value, anti_aliasing=False) crpix = masked.shape[0]/2 crop = masked[int(crpix - 600):int(crpix + 600), int(crpix - 600):int(crpix + 600)] # ------------------------------------ sun_map = sunpy.map.Map(ref_fits) hpc_coords = all_coordinates_from_map(sun_map) r = np.sqrt(hpc_coords.Tx ** 2 + hpc_coords.Ty ** 2) / sun_map.rsun_obs mask = ma.masked_less_equal(r, 1) sun_map.data[:] -= sun_map.data.min() sun_map.data[:] += 10e-6 if sun_map.detector == 'EUVI': sq_img = sun_map.data * sun_map.data sun_map.data[:] = sq_img[:] if sun_map.detector == 'EIT': sq_img = np.sqrt(sun_map.data) sun_map.data[:] = sq_img[:] masked = sun_map.data * mask.mask masked[masked == 0] = np.nan # force scale of 1 arcsec per pix scale = 1 / sun_map.scale[1].value masked = rescale(masked, sun_map.scale[1].value, anti_aliasing=False) crpix = masked.shape[0]/2 crop_ref = masked[int(crpix - 600):int(crpix + 600), int(crpix - 600):int(crpix + 600)] matched = match_histograms(crop, crop_ref) fig = plt.figure() ax = plt.subplot("131") im = ax.imshow(crop) ax.set_title('EUVI squared') fig.colorbar(im, ax=ax) ax = plt.subplot("132") im = ax.imshow(matched) ax.set_title('EUVI matched') fig.colorbar(im, ax=ax) ax = plt.subplot("133") im = ax.imshow(crop_ref) ax.set_title('EIT Square Root') fig.colorbar(im, ax=ax) return matched