def test_plot_map_validate_masks(arr, mask, umbra_mask): # Mask is 2D array for a in ([[1, 2, 3], [4, 5, 6], [7, 8, 9]], np.array([mask, mask])): with pytest.raises(TypeError) as e: plot_map(arr, a, umbra_mask) assert '`mask` must be a numpy.ndarray with 2 dimensions' in str( e.value) # Umbra mask is 2D array for a in ([[1, 2, 3], [4, 5, 6], [7, 8, 9]], np.array([umbra_mask, umbra_mask])): with pytest.raises(TypeError) as e: plot_map(arr, mask, a) assert '`umbra_mask` must be a numpy.ndarray with 2 dimensions' in str( e.value) # Mask wrong shape with pytest.raises(ValueError) as e: plot_map(arr, np.vstack([mask, mask]), umbra_mask) assert '`mask` must be the same shape as `arr`' in str(e.value) # Umbra mask wrong shape with pytest.raises(ValueError) as e: plot_map(arr, mask, np.vstack([umbra_mask, umbra_mask])) assert '`umbra_mask` must be the same shape as `arr`' in str(e.value)
def test_plot_map_unit_astropy(pytestconfig, arr): plot_map(arr, unit=(u.m / u.s))
def test_plot_map_unit(pytestconfig, arr): plot_map(arr, unit='test/unit')
def test_plot_map_vmax(pytestconfig, arr): plot_map(arr, vmax=4.5)
def test_plot_map_vmin(pytestconfig, arr): plot_map(arr, vmin=-4.5)
def test_plot_map_resolution_offset_masks(pytestconfig, arr, mask, umbra_mask): plot_map(arr, mask, umbra_mask, resolution=(2.5, 3 * u.kg / u.Hz), offset=(-3, -4))
def test_plot_map_colorbar(pytestconfig, arr): plot_map(arr, show_colorbar=False)
i = np.random.randint(0, arr.size, arr.size // 100) arr[np.unravel_index(i, arr.shape)] = np.nan return arr arr = a(x, y, low, high) # 2D array of velocities (y, x) #%% # Next, we shall import :func:`mcalf.visualisation.plot_map`. from mcalf.visualisation import plot_map #%% # We can now simply plot the 2D array. plot_map(arr) #%% # Notice that pixels with missing data (NaN) are shown in grey. #%% # By default, the velocity data are assumed to have units km/s. # If your data are not in km/s, you must either 1) rescale the # array such that it is in km/s, 2) attach an astropy unit # to the array to override the default, or 3) pass an # astropy unit to the ``unit`` parameter to override the # default. For example, we can change from km/s to m/s, import astropy.units as u plot_map(arr * 1000 * u.m / u.s)
def test_plot_map_both_masks(pytestconfig, arr, mask, umbra_mask): plot_map(arr, mask, umbra_mask)
def test_plot_map_umbra_mask(pytestconfig, arr, umbra_mask): plot_map(arr, umbra_mask=umbra_mask)
def test_plot_map_mask(pytestconfig, arr, mask): plot_map(arr, mask)
def test_plot_map_basic(pytestconfig, arr): plot_map(arr)
def test_plot_map_validate_arr(arr): for a in ([[1, 2, 3], [4, 5, 6], [7, 8, 9]], np.array([arr, arr])): with pytest.raises(TypeError) as e: plot_map(a) assert '`arr` must be a numpy.ndarray with 2 dimensions' in str( e.value)
def test_plot_map_unit_arr_astropy(pytestconfig, arr): plot_map(arr * u.m / u.s, unit='test/unit')
def test_plot_map_resolution(pytestconfig, arr): plot_map(arr, resolution=(2.5, 3 * u.kg / u.Hz))
def test_plot_map_lw(pytestconfig, arr, umbra_mask): plot_map(arr, umbra_mask=umbra_mask, lw=5.)
def test_plot_map_resolution_offset(pytestconfig, arr): plot_map(arr, resolution=(2.5, 3 * u.kg / u.Hz), offset=(-3, -4))
from mcalf.visualisation import plot_map fig, ax = plt.subplots(1, 2, sharey=True, constrained_layout=True) wing_data = np.log(spectra[0]) core_data = np.log(spectra[len(wavelengths) // 2]) res = { 'offset': (-25, -30), 'resolution': (0.098 * 5 * u.arcsec, 0.098 * 5 * u.arcsec), 'show_colorbar': False, } wing = plot_map(wing_data, ax=ax[0], **res, vmin=np.min(wing_data), vmax=np.max(wing_data)) core = plot_map(core_data, ax=ax[1], **res, vmin=np.min(core_data), vmax=np.max(core_data)) wing.set_cmap('gray') core.set_cmap('gray') ax[0].set_title('blue wing') ax[1].set_title('line core') ax[1].set_ylabel('')
# Calculate velocities # ~~~~~~~~~~~~~~~~~~~~ # # And finally, we can calculate Doppler # velocities for both the quiescent (absorption) # and active (emission) regimes. # (The model needs to be given so the stationary # line core wavelength is available.) quiescent = results.velocities(model, vtype='quiescent') active = results.velocities(model, vtype='active') from mcalf.visualisation import plot_map fig, axes = plt.subplots(2, constrained_layout=True) plot_map(quiescent, ax=axes[0]) plot_map(active, ax=axes[1]) plt.show() #%% # Export to FITS file # ~~~~~~~~~~~~~~~~~~~ # # The :class:`~mcalf.models.FitResults` object can # also be exported to a FITS file, results.save('ibis8542model_demo_fit.fits', model) #%% # The file has the following structure,