Skip to content

Commit 34ae6ff

Browse files
committed
pixel scale dict works in 1d and 2d
1 parent 5bfd24d commit 34ae6ff

10 files changed

Lines changed: 44 additions & 90 deletions

File tree

autoarray/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@
8989
from .structures.visibilities import VisibilitiesNoiseMap
9090

9191
from autoconf import conf
92-
from autoconf.fitsable import ndarray_via_hdu_from, ndarray_via_fits_from, header_obj_from
92+
from autoconf.fitsable import ndarray_via_hdu_from
93+
from autoconf.fitsable import ndarray_via_fits_from
94+
from autoconf.fitsable import header_obj_from
95+
from autoconf.fitsable import output_to_fits
96+
from autoconf.fitsable import hdu_list_for_output_from
9397

9498
conf.instance.register(__file__)
9599

autoarray/mask/abstract_mask.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ def pixel_scale_header(self) -> Dict:
8787
-------
8888
A dictionary containing the pixel scale of the mask, which can be output to a .fits file.
8989
"""
90-
return {
91-
"PIXSCAY": self.pixel_scales[0],
92-
"PIXSCAX": self.pixel_scales[1],
93-
}
9490

9591
@property
9692
def dimensions(self) -> int:

autoarray/mask/mask_1d.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import logging
55
import numpy as np
66
from pathlib import Path
7-
from typing import List, Tuple, Union
7+
from typing import Dict, List, Tuple, Union
88

99
from autoconf.fitsable import output_to_fits
1010

@@ -163,6 +163,22 @@ def shape_native(self) -> Tuple[int]:
163163
def shape_slim(self) -> Tuple[int]:
164164
return self.shape
165165

166+
@property
167+
def pixel_scale_header(self) -> Dict:
168+
"""
169+
Returns the pixel scales of the mask as a header dictionary, which can be written to a .fits file.
170+
171+
A 2D mask has different pixel scale variables for each dimension, the header therefore contain both pixel
172+
scales as separate y and x entries.
173+
174+
Returns
175+
-------
176+
A dictionary containing the pixel scale of the mask, which can be output to a .fits file.
177+
"""
178+
return {
179+
"PIXSCA": self.pixel_scales[0],
180+
}
181+
166182
@property
167183
def hdu_for_output(self) -> fits.PrimaryHDU:
168184
"""

autoarray/mask/mask_2d.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
from __future__ import annotations
22
from astropy.io import fits
3-
import copy
43
import logging
54
import numpy as np
65
from pathlib import Path
7-
from typing import TYPE_CHECKING, List, Tuple, Union
6+
from typing import TYPE_CHECKING, Dict, List, Tuple, Union
87

98
from autoarray.structures.abstract_structure import Structure
109

@@ -706,6 +705,23 @@ def unmasked_blurred_array_from(self, padded_array, psf, image_shape) -> Array2D
706705
padded_array=blurred_image, image_shape=image_shape
707706
)
708707

708+
@property
709+
def pixel_scale_header(self) -> Dict:
710+
"""
711+
Returns the pixel scales of the mask as a header dictionary, which can be written to a .fits file.
712+
713+
A 2D mask has different pixel scale variables for each dimension, the header therefore contain both pixel
714+
scales as separate y and x entries.
715+
716+
Returns
717+
-------
718+
A dictionary containing the pixel scale of the mask, which can be output to a .fits file.
719+
"""
720+
return {
721+
"PIXSCAY": self.pixel_scales[0],
722+
"PIXSCAX": self.pixel_scales[1],
723+
}
724+
709725
@property
710726
def hdu_for_output(self) -> fits.PrimaryHDU:
711727
"""

autoarray/plot/multi_plotters.py

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -270,74 +270,6 @@ def output_subplot(self, filename_suffix: str = ""):
270270
)
271271
plotter.close_subplot_figure()
272272

273-
def output_to_fits(
274-
self,
275-
func_name_list: List[str],
276-
figure_name_list: List[str],
277-
filename: str,
278-
tag_list: Optional[List[str]] = None,
279-
remove_fits_first: bool = False,
280-
**kwargs,
281-
):
282-
"""
283-
Outputs a list of figures of the plotter objects in the `plotter_list` to a single .fits file.
284-
285-
This function takes as input lists of function names and figure names and then calls them via
286-
the `plotter_list` with an interface that outputs each to a .fits file.
287-
288-
For example, if you have multiple `ImagingPlotter` objects and want to output the `data` and `noise_map` of
289-
each to a single .fits files, you would input:
290-
291-
- `func_name_list=['figures_2d', 'figures_2d']` and
292-
- `figure_name_list=['data', 'noise_map']`.
293-
294-
The implementation of this code is hacky, with it using a specific interface in the `Output` object
295-
which sets the format to `fits_multi` to call a function which outputs the .fits files. A major visualuzation
296-
refactor is required to make this more elegant.
297-
298-
Parameters
299-
----------
300-
func_name_list
301-
The list of function names that are called to plot the figures on the subplot.
302-
figure_name_list
303-
The list of figure names that are plotted on the subplot.
304-
filenane
305-
The filename that the .fits file is output to.
306-
tag_list
307-
The list of tags that are used to set the `EXTNAME` of each hdu of the .fits file.
308-
remove_fits_first
309-
If the .fits file already exists, it is removed before the new .fits file is output, else it is updated
310-
with the figure going into the next hdu.
311-
kwargs
312-
Any additional keyword arguments that are passed to the function that plots the figure on the subplot.
313-
"""
314-
315-
output_path = self.plotter_list[0].mat_plot_2d.output.output_path_from(
316-
format="fits_multi"
317-
)
318-
output_fits_file = Path(output_path) / f"{filename}.fits"
319-
320-
if remove_fits_first:
321-
output_fits_file.unlink(missing_ok=True)
322-
323-
for i, plotter in enumerate(self.plotter_list):
324-
plotter.mat_plot_2d.output._format = "fits_multi"
325-
326-
plotter.set_filename(filename=f"{filename}")
327-
328-
for j, (func_name, figure_name) in enumerate(
329-
zip(func_name_list, figure_name_list)
330-
):
331-
if tag_list is not None:
332-
plotter.mat_plot_2d.output._tag_fits_multi = tag_list[j]
333-
334-
self.plot_via_func(
335-
plotter=plotter,
336-
figure_name=figure_name,
337-
func_name=func_name,
338-
kwargs=kwargs,
339-
)
340-
341273

342274
class MultiYX1DPlotter:
343275
def __init__(

autoarray/plot/wrap/base/output.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -153,17 +153,6 @@ def to_figure(
153153
file_path=path.join(output_path, f"{filename}.fits"),
154154
overwrite=True,
155155
)
156-
elif format == "fits_multi":
157-
if structure is not None:
158-
from autoarray.structures.arrays.array_2d_util import (
159-
update_fits_file,
160-
)
161-
162-
update_fits_file(
163-
arr=structure.native,
164-
file_path=path.join(output_path, f"{filename}.fits"),
165-
tag=self._tag_fits_multi,
166-
)
167156

168157
def subplot_to_figure(self, auto_filename: Optional[str] = None):
169158
"""

test_autoarray/mask/test_mask_2d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ def test__from_fits__output_to_fits():
363363
file_path=path.join(test_data_path, "mask.fits"), hdu=0
364364
)
365365

366-
assert header["PIXSCALE"] == 1.0
366+
assert header["PIXSCAY"] == 1.0
367367

368368

369369
def test__from_fits__with_resized_mask_shape():

test_autoarray/structures/arrays/test_array_2d_util.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ def test__resized_array_2d_from__padding_with_new_origin():
286286
)
287287
).all()
288288

289+
289290
def test__replace_noise_map_2d_values_where_image_2d_values_are_negative():
290291
image_2d = np.ones(shape=(2, 2))
291292

test_autoarray/structures/arrays/test_uniform_1d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def test__output_to_fits():
165165
file_path=path.join(test_data_path, "array.fits"), hdu=0
166166
)
167167

168-
assert header_load["PIXSCALE"] == 1.0
168+
assert header_load["PIXSCA"] == 1.0
169169

170170

171171
def test__recursive_shape_storage():

test_autoarray/structures/arrays/test_uniform_2d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def test__output_to_fits():
224224
)
225225

226226
assert (array_from_fits.native == np.ones((3, 3))).all()
227-
assert array_from_fits.header.header_sci_obj["PIXSCALE"] == 1.0
227+
assert array_from_fits.header.header_sci_obj["PIXSCAY"] == 1.0
228228

229229

230230
def test__manual_native__exception_raised_if_input_array_is_2d_and_not_shape_of_mask():

0 commit comments

Comments
 (0)