Skip to content

Commit 482ce26

Browse files
committed
remoe output_to_Fits from mask to abstract mask
1 parent 34ae6ff commit 482ce26

6 files changed

Lines changed: 35 additions & 167 deletions

File tree

autoarray/mask/abstract_mask.py

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
from pathlib import Path
77
from typing import Dict, Union
88

9+
from autoconf.fitsable import output_to_fits
10+
911
from autoarray.abstract_ndarray import AbstractNDArray
1012

11-
from autoarray import exc
1213
from autoarray import type as ty
1314

1415
logging.basicConfig()
@@ -92,10 +93,38 @@ def pixel_scale_header(self) -> Dict:
9293
def dimensions(self) -> int:
9394
return len(self.shape)
9495

95-
def output_to_fits(self, file_path: Union[Path, str], overwrite: bool = False):
96-
"""
97-
Overwrite with method to output the mask to a `.fits` file.
96+
def output_to_fits(self, file_path, overwrite=False):
9897
"""
98+
Write the Mask to a .fits file.
99+
100+
Before outputting a 2D NumPy array mask, the array may be flipped upside-down using np.flipud depending on
101+
the project config files. This is for Astronomy projects so that structures appear the same orientation
102+
as `.fits` files loaded in DS9.
103+
104+
Parameters
105+
----------
106+
file_path
107+
The full path of the file that is output, including the file name and `.fits` extension.
108+
overwrite
109+
If `True` and a file already exists with the input file_path the .fits file is overwritten. If `False`, an
110+
error is raised.
111+
112+
Returns
113+
-------
114+
None
115+
116+
Examples
117+
--------
118+
mask = Mask2D(mask=np.full(shape=(5,5), fill_value=False))
119+
mask.output_to_fits(file_path='/path/to/file/filename.fits', overwrite=True)
120+
"""
121+
output_to_fits(
122+
values=self.astype("float"),
123+
file_path=file_path,
124+
overwrite=overwrite,
125+
header_dict=self.pixel_scale_header,
126+
ext_name="mask"
127+
)
99128

100129
@property
101130
def pixels_in_mask(self) -> int:

autoarray/mask/mask_1d.py

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
from __future__ import annotations
22

3-
from astropy.io import fits
43
import logging
54
import numpy as np
65
from pathlib import Path
76
from typing import Dict, List, Tuple, Union
87

9-
from autoconf.fitsable import output_to_fits
10-
118
from autoarray.mask.abstract_mask import Mask
129

1310
from autoarray.mask.derive.grid_1d import DeriveGrid1D
@@ -177,50 +174,4 @@ def pixel_scale_header(self) -> Dict:
177174
"""
178175
return {
179176
"PIXSCA": self.pixel_scales[0],
180-
}
181-
182-
@property
183-
def hdu_for_output(self) -> fits.PrimaryHDU:
184-
"""
185-
The mask as a HDU object, which can be output to a .fits file.
186-
187-
The header of the HDU is used to store the `pixel_scale` of the array, which is used by the `Array1D.from_hdu`.
188-
189-
This method is used in other projects (E.g. PyAutoGalaxy, PyAutoLens) to conveniently output the array to .fits
190-
files.
191-
192-
Returns
193-
-------
194-
The HDU containing the data and its header which can then be written to .fits.
195-
"""
196-
return array_1d_util.hdu_for_output_from(
197-
array_1d=self.astype("float"), header_dict=self.pixel_scale_header
198-
)
199-
200-
def output_to_fits(self, file_path: Union[Path, str], overwrite: bool = False):
201-
"""
202-
Write the 1D mask to a .fits file.
203-
204-
Parameters
205-
----------
206-
file_path
207-
The full path of the file that is output, including the file name and .fits extension.
208-
overwrite
209-
If `True` and a file already exists with the input file_path the .fits file is overwritten. If `False`,
210-
an error is raised.
211-
212-
Returns
213-
-------
214-
None
215-
216-
Examples
217-
--------
218-
mask = Mask1D(mask=np.full(shape=(5,), fill_value=False))
219-
mask.output_to_fits(file_path='/path/to/file/filename.fits', overwrite=True)
220-
"""
221-
output_to_fits(
222-
values=self.astype("float"),
223-
file_path=file_path,
224-
overwrite=overwrite,
225-
header_dict=self.pixel_scale_header,
226-
)
177+
}

autoarray/mask/mask_2d.py

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from __future__ import annotations
2-
from astropy.io import fits
32
import logging
43
import numpy as np
54
from pathlib import Path
@@ -11,7 +10,7 @@
1110
from autoarray.structures.arrays.uniform_2d import Array2D
1211

1312
from autoconf import cached_property
14-
from autoconf.fitsable import ndarray_via_fits_from, output_to_fits
13+
from autoconf.fitsable import ndarray_via_fits_from
1514

1615
from autoarray.mask.abstract_mask import Mask
1716

@@ -722,57 +721,6 @@ def pixel_scale_header(self) -> Dict:
722721
"PIXSCAX": self.pixel_scales[1],
723722
}
724723

725-
@property
726-
def hdu_for_output(self) -> fits.PrimaryHDU:
727-
"""
728-
The mask as a HDU object, which can be output to a .fits file.
729-
730-
The header of the HDU is used to store the `pixel_scale` of the array, which is used by the `Array2D.from_hdu`.
731-
732-
This method is used in other projects (E.g. PyAutoGalaxy, PyAutoLens) to conveniently output the array to .fits
733-
files.
734-
735-
Returns
736-
-------
737-
The HDU containing the data and its header which can then be written to .fits.
738-
"""
739-
return array_2d_util.hdu_for_output_from(
740-
array_2d=self.astype("float"), header_dict=self.pixel_scale_header
741-
)
742-
743-
def output_to_fits(self, file_path, overwrite=False):
744-
"""
745-
Write the 2D Mask to a .fits file.
746-
747-
Before outputting a NumPy array, the array may be flipped upside-down using np.flipud depending on the project
748-
config files. This is for Astronomy projects so that structures appear the same orientation as `.fits` files
749-
loaded in DS9.
750-
751-
Parameters
752-
----------
753-
file_path
754-
The full path of the file that is output, including the file name and `.fits` extension.
755-
overwrite
756-
If `True` and a file already exists with the input file_path the .fits file is overwritten. If `False`, an
757-
error is raised.
758-
759-
Returns
760-
-------
761-
None
762-
763-
Examples
764-
--------
765-
mask = Mask2D(mask=np.full(shape=(5,5), fill_value=False))
766-
mask.output_to_fits(file_path='/path/to/file/filename.fits', overwrite=True)
767-
"""
768-
output_to_fits(
769-
values=self.astype("float"),
770-
file_path=file_path,
771-
overwrite=overwrite,
772-
header_dict=self.pixel_scale_header,
773-
ext_name="mask"
774-
)
775-
776724
@property
777725
def mask_centre(self) -> Tuple[float, float]:
778726
grid = grid_2d_util.grid_2d_slim_via_mask_from(

autoarray/structures/arrays/uniform_1d.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -268,21 +268,3 @@ def grid_radial(self) -> Grid1D:
268268
shape_native=self.shape_native,
269269
pixel_scales=self.pixel_scales,
270270
)
271-
272-
@property
273-
def hdu_for_output(self) -> fits.PrimaryHDU:
274-
"""
275-
The array as an HDU object, which can be output to a .fits file.
276-
277-
The header of the HDU is used to store the `pixel_scale` of the array, which is used by the `Array1D.from_hdu`.
278-
279-
This method is used in other projects (E.g. PyAutoGalaxy, PyAutoLens) to conveniently output the array to .fits
280-
files.
281-
282-
Returns
283-
-------
284-
The HDU containing the data and its header which can then be written to .fits.
285-
"""
286-
return array_2d_util.hdu_for_output_from(
287-
array_2d=self.native, header_dict=self.pixel_scale_header
288-
)

autoarray/structures/arrays/uniform_2d.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -610,28 +610,6 @@ def trimmed_after_convolution_from(
610610
store_native=self.store_native,
611611
)
612612

613-
def hdu_for_output_from(
614-
self, ext_name: Optional[str] = None, return_as_primary: bool = False
615-
) -> Union[fits.PrimaryHDU, fits.ImageHDU]:
616-
"""
617-
The array as an HDU object, which can be output to a .fits file.
618-
619-
The header of the HDU is used to store the `pixel_scale` of the array, which is used by the `Array2D.from_hdu`.
620-
621-
This method is used in other projects (E.g. PyAutoGalaxy, PyAutoLens) to conveniently output the array to .fits
622-
files.
623-
624-
Returns
625-
-------
626-
The HDU containing the data and its header which can then be written to .fits.
627-
"""
628-
return array_2d_util.hdu_for_output_from(
629-
array_2d=np.array(self.native),
630-
header_dict=self.pixel_scale_header,
631-
ext_name=ext_name,
632-
return_as_primary=return_as_primary,
633-
)
634-
635613

636614
class Array2D(AbstractArray2D):
637615
@classmethod

autoarray/structures/visibilities.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from abc import ABC
22

3-
from astropy.io import fits
4-
53
import logging
64
import numpy as np
75
from pathlib import Path
@@ -13,8 +11,6 @@
1311
from autoarray.structures.abstract_structure import Structure
1412
from autoarray.structures.grids.irregular_2d import Grid2DIrregular
1513

16-
from autoarray.structures.arrays import array_2d_util
17-
1814
logging.basicConfig()
1915
logger = logging.getLogger(__name__)
2016

@@ -103,22 +99,6 @@ def amplitudes(self) -> np.ndarray:
10399
def phases(self) -> np.ndarray:
104100
return np.arctan2(self.imag, self.real)
105101

106-
@property
107-
def hdu_for_output(self) -> fits.PrimaryHDU:
108-
"""
109-
The visibilities as an HDU object, which can be output to a .fits file.
110-
111-
This method is used in other projects (E.g. PyAutoGalaxy, PyAutoLens) to conveniently output the array to .fits
112-
files.
113-
114-
Returns
115-
-------
116-
The HDU containing the data which can then be written to .fits.
117-
"""
118-
return array_2d_util.hdu_for_output_from(
119-
array_2d=self.in_array,
120-
)
121-
122102
def output_to_fits(self, file_path: Union[Path, str], overwrite: bool = False):
123103
"""
124104
Output the visibilities to a .fits file.

0 commit comments

Comments
 (0)