Skip to content

Commit f7bda00

Browse files
Jammy2211Jammy2211
authored andcommitted
remove unmasked dataset and replace with exception
1 parent 8f0e9eb commit f7bda00

File tree

1 file changed

+11
-32
lines changed

1 file changed

+11
-32
lines changed

autoarray/dataset/imaging/dataset.py

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ def __init__(
8888
If True, the noise-map is checked to ensure all values are above zero.
8989
"""
9090

91-
self.unmasked = None
92-
9391
self.disable_fft_pad = disable_fft_pad
9492

9593
if psf is not None:
@@ -340,26 +338,26 @@ def apply_mask(self, mask: Mask2D, disable_fft_pad: bool = False) -> "Imaging":
340338
Apply a mask to the imaging dataset, whereby the mask is applied to the image data, noise-map and other
341339
quantities one-by-one.
342340
343-
The original unmasked imaging data is stored as the `self.unmasked` attribute. This is used to ensure that if
344-
the `apply_mask` function is called multiple times, every mask is always applied to the original unmasked
345-
imaging dataset.
341+
The `apply_mask` function cannot be called multiple times, if it is a mask may remove data, therefore
342+
an exception is raised. If you wish to apply a new mask, reload the dataset from .fits files.
346343
347344
Parameters
348345
----------
349346
mask
350347
The 2D mask that is applied to the image.
351348
"""
352-
if self.data.mask.is_all_false:
353-
unmasked_dataset = self
354-
else:
355-
unmasked_dataset = self.unmasked
349+
if not self.data.mask.is_all_false:
350+
raise exc.DatasetException(
351+
"The mask has already been applied to the dataset, therefore a new mask cannot be applied. "
352+
"If you wish to apply a new mask, please reload the dataset from .fits files."
353+
)
356354

357-
data = Array2D(values=unmasked_dataset.data.native, mask=mask)
355+
data = Array2D(values=self.data.native, mask=mask)
358356

359-
noise_map = Array2D(values=unmasked_dataset.noise_map.native, mask=mask)
357+
noise_map = Array2D(values=self.noise_map.native, mask=mask)
360358

361-
if unmasked_dataset.noise_covariance_matrix is not None:
362-
noise_covariance_matrix = unmasked_dataset.noise_covariance_matrix
359+
if self..noise_covariance_matrix is not None:
360+
noise_covariance_matrix = self..noise_covariance_matrix
363361

364362
noise_covariance_matrix = np.delete(
365363
noise_covariance_matrix, mask.derive_indexes.masked_slim, 0
@@ -386,8 +384,6 @@ def apply_mask(self, mask: Mask2D, disable_fft_pad: bool = False) -> "Imaging":
386384
disable_fft_pad=disable_fft_pad,
387385
)
388386

389-
dataset.unmasked = unmasked_dataset
390-
391387
logger.info(
392388
f"IMAGING - Data masked, contains a total of {mask.pixels_in_mask} image-pixels"
393389
)
@@ -454,18 +450,6 @@ def apply_noise_scaling(
454450
else:
455451
data = self.data.native.array
456452

457-
data_unmasked = Array2D.no_mask(
458-
values=data,
459-
shape_native=self.data.shape_native,
460-
pixel_scales=self.data.pixel_scales,
461-
)
462-
463-
noise_map_unmasked = Array2D.no_mask(
464-
values=noise_map,
465-
shape_native=self.noise_map.shape_native,
466-
pixel_scales=self.noise_map.pixel_scales,
467-
)
468-
469453
data = Array2D(values=data, mask=self.data.mask)
470454

471455
noise_map = Array2D(values=noise_map, mask=self.data.mask)
@@ -481,11 +465,6 @@ def apply_noise_scaling(
481465
check_noise_map=False,
482466
)
483467

484-
if self.unmasked is not None:
485-
dataset.unmasked = self.unmasked
486-
dataset.unmasked.data = data_unmasked
487-
dataset.unmasked.noise_map = noise_map_unmasked
488-
489468
logger.info(
490469
f"IMAGING - Data noise scaling applied, a total of {mask.pixels_in_mask} pixels were scaled to large noise values."
491470
)

0 commit comments

Comments
 (0)