|
4 | 4 | from typing import Optional, Union |
5 | 5 |
|
6 | 6 | from autoconf import cached_property |
| 7 | +from autoconf import instance |
7 | 8 |
|
8 | 9 | from autoarray.dataset.abstract.dataset import AbstractDataset |
9 | 10 | from autoarray.dataset.grids import GridsDataset |
@@ -95,6 +96,10 @@ def __init__( |
95 | 96 |
|
96 | 97 | if psf is not None and not disable_fft_pad and data.mask.shape != fft_shape: |
97 | 98 |
|
| 99 | + # If using real-space convolution instead of FFT, enforce odd-odd shapes |
| 100 | + if not psf.use_fft: |
| 101 | + fft_shape = tuple(s + 1 if s % 2 == 0 else s for s in fft_shape) |
| 102 | + |
98 | 103 | logger.info( |
99 | 104 | f"Imaging data has been trimmed or padded for FFT convolution.\n" |
100 | 105 | f" - Original shape : {data.mask.shape}\n" |
@@ -345,10 +350,13 @@ def apply_mask(self, mask: Mask2D, disable_fft_pad: bool = False) -> "Imaging": |
345 | 350 | mask |
346 | 351 | The 2D mask that is applied to the image. |
347 | 352 | """ |
348 | | - if not self.data.mask.is_all_false: |
| 353 | + invalid = np.logical_and(self.data.mask, np.logical_not(mask)) |
| 354 | + |
| 355 | + if np.any(invalid): |
349 | 356 | raise exc.DatasetException( |
350 | | - "The mask has already been applied to the dataset, therefore a new mask cannot be applied. " |
351 | | - "If you wish to apply a new mask, please reload the dataset from .fits files." |
| 357 | + "The new mask overlaps with pixels that are already unmasked in the dataset. " |
| 358 | + "You cannot apply a new mask on top of an existing one. " |
| 359 | + "If you wish to apply a different mask, please reload the dataset from .fits files." |
352 | 360 | ) |
353 | 361 |
|
354 | 362 | data = Array2D(values=self.data.native, mask=mask) |
|
0 commit comments