|
1 | | -import copy |
2 | | -import numpy as np |
3 | | -from typing import Callable, Optional |
4 | | - |
5 | | -from autoarray.plot.visuals.two_d import Visuals2D |
6 | | -from autoarray.plot.mat_plot.two_d import MatPlot2D |
7 | | -from autoarray.plot.auto_labels import AutoLabels |
8 | | -from autoarray.plot.abstract_plotters import AbstractPlotter |
9 | | -from autoarray.plot.plots.array import plot_array |
10 | | -from autoarray.structures.plot.structure_plotters import ( |
11 | | - _lines_from_visuals, |
12 | | - _positions_from_visuals, |
13 | | - _mask_edge_from, |
14 | | - _grid_from_visuals, |
15 | | - _output_for_mat_plot, |
16 | | - _zoom_array, |
17 | | -) |
18 | | -from autoarray.dataset.imaging.dataset import Imaging |
19 | | - |
20 | | - |
21 | | -class ImagingPlotterMeta(AbstractPlotter): |
22 | | - def __init__( |
23 | | - self, |
24 | | - dataset: Imaging, |
25 | | - mat_plot_2d: MatPlot2D = None, |
26 | | - visuals_2d: Visuals2D = None, |
27 | | - ): |
28 | | - super().__init__(mat_plot_2d=mat_plot_2d, visuals_2d=visuals_2d) |
29 | | - self.dataset = dataset |
30 | | - |
31 | | - @property |
32 | | - def imaging(self): |
33 | | - return self.dataset |
34 | | - |
35 | | - def _plot_array(self, array, auto_filename: str, title: str, ax=None): |
36 | | - """Internal helper: plot an Array2D via plot_array().""" |
37 | | - if array is None: |
38 | | - return |
39 | | - |
40 | | - is_sub = self.mat_plot_2d.is_for_subplot |
41 | | - if ax is None: |
42 | | - ax = self.mat_plot_2d.setup_subplot() if is_sub else None |
43 | | - |
44 | | - output_path, filename, fmt = _output_for_mat_plot( |
45 | | - self.mat_plot_2d, is_sub, auto_filename |
46 | | - ) |
47 | | - |
48 | | - array = _zoom_array(array) |
49 | | - |
50 | | - try: |
51 | | - arr = array.native.array |
52 | | - extent = array.geometry.extent |
53 | | - except AttributeError: |
54 | | - arr = np.asarray(array) |
55 | | - extent = None |
56 | | - |
57 | | - plot_array( |
58 | | - array=arr, |
59 | | - ax=ax, |
60 | | - extent=extent, |
61 | | - mask=_mask_edge_from(array if hasattr(array, "mask") else None, self.visuals_2d), |
62 | | - grid=_grid_from_visuals(self.visuals_2d), |
63 | | - positions=_positions_from_visuals(self.visuals_2d), |
64 | | - lines=_lines_from_visuals(self.visuals_2d), |
65 | | - title=title, |
66 | | - colormap=self.mat_plot_2d.cmap.cmap, |
67 | | - use_log10=self.mat_plot_2d.use_log10, |
68 | | - output_path=output_path, |
69 | | - output_filename=filename, |
70 | | - output_format=fmt, |
71 | | - structure=array, |
72 | | - ) |
73 | | - |
74 | | - def figures_2d( |
75 | | - self, |
76 | | - data: bool = False, |
77 | | - noise_map: bool = False, |
78 | | - psf: bool = False, |
79 | | - signal_to_noise_map: bool = False, |
80 | | - over_sample_size_lp: bool = False, |
81 | | - over_sample_size_pixelization: bool = False, |
82 | | - title_str: Optional[str] = None, |
83 | | - ): |
84 | | - if data: |
85 | | - self._plot_array( |
86 | | - array=self.dataset.data, |
87 | | - auto_filename="data", |
88 | | - title=title_str or "Data", |
89 | | - ) |
90 | | - |
91 | | - if noise_map: |
92 | | - self._plot_array( |
93 | | - array=self.dataset.noise_map, |
94 | | - auto_filename="noise_map", |
95 | | - title=title_str or "Noise-Map", |
96 | | - ) |
97 | | - |
98 | | - if psf: |
99 | | - if self.dataset.psf is not None: |
100 | | - self._plot_array( |
101 | | - array=self.dataset.psf.kernel, |
102 | | - auto_filename="psf", |
103 | | - title=title_str or "Point Spread Function", |
104 | | - ) |
105 | | - |
106 | | - if signal_to_noise_map: |
107 | | - self._plot_array( |
108 | | - array=self.dataset.signal_to_noise_map, |
109 | | - auto_filename="signal_to_noise_map", |
110 | | - title=title_str or "Signal-To-Noise Map", |
111 | | - ) |
112 | | - |
113 | | - if over_sample_size_lp: |
114 | | - self._plot_array( |
115 | | - array=self.dataset.grids.over_sample_size_lp, |
116 | | - auto_filename="over_sample_size_lp", |
117 | | - title=title_str or "Over Sample Size (Light Profiles)", |
118 | | - ) |
119 | | - |
120 | | - if over_sample_size_pixelization: |
121 | | - self._plot_array( |
122 | | - array=self.dataset.grids.over_sample_size_pixelization, |
123 | | - auto_filename="over_sample_size_pixelization", |
124 | | - title=title_str or "Over Sample Size (Pixelization)", |
125 | | - ) |
126 | | - |
127 | | - def subplot( |
128 | | - self, |
129 | | - data: bool = False, |
130 | | - noise_map: bool = False, |
131 | | - psf: bool = False, |
132 | | - signal_to_noise_map: bool = False, |
133 | | - over_sampling: bool = False, |
134 | | - over_sampling_pixelization: bool = False, |
135 | | - auto_filename: str = "subplot_dataset", |
136 | | - ): |
137 | | - self._subplot_custom_plot( |
138 | | - data=data, |
139 | | - noise_map=noise_map, |
140 | | - psf=psf, |
141 | | - signal_to_noise_map=signal_to_noise_map, |
142 | | - over_sampling=over_sampling, |
143 | | - over_sampling_pixelization=over_sampling_pixelization, |
144 | | - auto_labels=AutoLabels(filename=auto_filename), |
145 | | - ) |
146 | | - |
147 | | - def subplot_dataset(self): |
148 | | - use_log10_original = self.mat_plot_2d.use_log10 |
149 | | - |
150 | | - self.open_subplot_figure(number_subplots=9) |
151 | | - |
152 | | - self.figures_2d(data=True) |
153 | | - |
154 | | - contour_original = copy.copy(self.mat_plot_2d.contour) |
155 | | - |
156 | | - self.mat_plot_2d.use_log10 = True |
157 | | - self.mat_plot_2d.contour = False |
158 | | - self.figures_2d(data=True) |
159 | | - self.mat_plot_2d.use_log10 = False |
160 | | - self.mat_plot_2d.contour = contour_original |
161 | | - |
162 | | - self.figures_2d(noise_map=True) |
163 | | - self.figures_2d(psf=True) |
164 | | - |
165 | | - self.mat_plot_2d.use_log10 = True |
166 | | - self.figures_2d(psf=True) |
167 | | - self.mat_plot_2d.use_log10 = False |
168 | | - |
169 | | - self.figures_2d(signal_to_noise_map=True) |
170 | | - self.figures_2d(over_sample_size_lp=True) |
171 | | - self.figures_2d(over_sample_size_pixelization=True) |
172 | | - |
173 | | - self.mat_plot_2d.output.subplot_to_figure(auto_filename="subplot_dataset") |
174 | | - self.close_subplot_figure() |
175 | | - |
176 | | - self.mat_plot_2d.use_log10 = use_log10_original |
177 | | - |
178 | | - |
179 | | -class ImagingPlotter(AbstractPlotter): |
180 | | - def __init__( |
181 | | - self, |
182 | | - dataset: Imaging, |
183 | | - mat_plot_2d: MatPlot2D = None, |
184 | | - visuals_2d: Visuals2D = None, |
185 | | - ): |
186 | | - super().__init__(mat_plot_2d=mat_plot_2d, visuals_2d=visuals_2d) |
187 | | - |
188 | | - self.dataset = dataset |
189 | | - |
190 | | - self._imaging_meta_plotter = ImagingPlotterMeta( |
191 | | - dataset=self.dataset, |
192 | | - mat_plot_2d=self.mat_plot_2d, |
193 | | - visuals_2d=self.visuals_2d, |
194 | | - ) |
195 | | - |
196 | | - self.figures_2d = self._imaging_meta_plotter.figures_2d |
197 | | - self.subplot = self._imaging_meta_plotter.subplot |
198 | | - self.subplot_dataset = self._imaging_meta_plotter.subplot_dataset |
| 1 | +import copy |
| 2 | +import numpy as np |
| 3 | +from typing import Optional |
| 4 | + |
| 5 | +from autoarray.plot.mat_plot.two_d import MatPlot2D |
| 6 | +from autoarray.plot.auto_labels import AutoLabels |
| 7 | +from autoarray.plot.abstract_plotters import AbstractPlotter |
| 8 | +from autoarray.plot.plots.array import plot_array |
| 9 | +from autoarray.structures.plot.structure_plotters import ( |
| 10 | + _auto_mask_edge, |
| 11 | + _numpy_lines, |
| 12 | + _numpy_grid, |
| 13 | + _numpy_positions, |
| 14 | + _output_for_mat_plot, |
| 15 | + _zoom_array, |
| 16 | +) |
| 17 | +from autoarray.dataset.imaging.dataset import Imaging |
| 18 | + |
| 19 | + |
| 20 | +class ImagingPlotterMeta(AbstractPlotter): |
| 21 | + def __init__( |
| 22 | + self, |
| 23 | + dataset: Imaging, |
| 24 | + mat_plot_2d: MatPlot2D = None, |
| 25 | + grid=None, |
| 26 | + positions=None, |
| 27 | + lines=None, |
| 28 | + ): |
| 29 | + super().__init__(mat_plot_2d=mat_plot_2d) |
| 30 | + self.dataset = dataset |
| 31 | + self.grid = grid |
| 32 | + self.positions = positions |
| 33 | + self.lines = lines |
| 34 | + |
| 35 | + @property |
| 36 | + def imaging(self): |
| 37 | + return self.dataset |
| 38 | + |
| 39 | + def _plot_array(self, array, auto_filename: str, title: str, ax=None): |
| 40 | + if array is None: |
| 41 | + return |
| 42 | + |
| 43 | + is_sub = self.mat_plot_2d.is_for_subplot |
| 44 | + if ax is None: |
| 45 | + ax = self.mat_plot_2d.setup_subplot() if is_sub else None |
| 46 | + |
| 47 | + output_path, filename, fmt = _output_for_mat_plot( |
| 48 | + self.mat_plot_2d, is_sub, auto_filename |
| 49 | + ) |
| 50 | + |
| 51 | + array = _zoom_array(array) |
| 52 | + |
| 53 | + try: |
| 54 | + arr = array.native.array |
| 55 | + extent = array.geometry.extent |
| 56 | + except AttributeError: |
| 57 | + arr = np.asarray(array) |
| 58 | + extent = None |
| 59 | + |
| 60 | + plot_array( |
| 61 | + array=arr, |
| 62 | + ax=ax, |
| 63 | + extent=extent, |
| 64 | + mask=_auto_mask_edge(array) if hasattr(array, "mask") else None, |
| 65 | + grid=_numpy_grid(self.grid), |
| 66 | + positions=_numpy_positions(self.positions), |
| 67 | + lines=_numpy_lines(self.lines), |
| 68 | + title=title, |
| 69 | + colormap=self.mat_plot_2d.cmap.cmap, |
| 70 | + use_log10=self.mat_plot_2d.use_log10, |
| 71 | + output_path=output_path, |
| 72 | + output_filename=filename, |
| 73 | + output_format=fmt, |
| 74 | + structure=array, |
| 75 | + ) |
| 76 | + |
| 77 | + def figures_2d( |
| 78 | + self, |
| 79 | + data: bool = False, |
| 80 | + noise_map: bool = False, |
| 81 | + psf: bool = False, |
| 82 | + signal_to_noise_map: bool = False, |
| 83 | + over_sample_size_lp: bool = False, |
| 84 | + over_sample_size_pixelization: bool = False, |
| 85 | + title_str: Optional[str] = None, |
| 86 | + ): |
| 87 | + if data: |
| 88 | + self._plot_array( |
| 89 | + array=self.dataset.data, |
| 90 | + auto_filename="data", |
| 91 | + title=title_str or "Data", |
| 92 | + ) |
| 93 | + if noise_map: |
| 94 | + self._plot_array( |
| 95 | + array=self.dataset.noise_map, |
| 96 | + auto_filename="noise_map", |
| 97 | + title=title_str or "Noise-Map", |
| 98 | + ) |
| 99 | + if psf: |
| 100 | + if self.dataset.psf is not None: |
| 101 | + self._plot_array( |
| 102 | + array=self.dataset.psf.kernel, |
| 103 | + auto_filename="psf", |
| 104 | + title=title_str or "Point Spread Function", |
| 105 | + ) |
| 106 | + if signal_to_noise_map: |
| 107 | + self._plot_array( |
| 108 | + array=self.dataset.signal_to_noise_map, |
| 109 | + auto_filename="signal_to_noise_map", |
| 110 | + title=title_str or "Signal-To-Noise Map", |
| 111 | + ) |
| 112 | + if over_sample_size_lp: |
| 113 | + self._plot_array( |
| 114 | + array=self.dataset.grids.over_sample_size_lp, |
| 115 | + auto_filename="over_sample_size_lp", |
| 116 | + title=title_str or "Over Sample Size (Light Profiles)", |
| 117 | + ) |
| 118 | + if over_sample_size_pixelization: |
| 119 | + self._plot_array( |
| 120 | + array=self.dataset.grids.over_sample_size_pixelization, |
| 121 | + auto_filename="over_sample_size_pixelization", |
| 122 | + title=title_str or "Over Sample Size (Pixelization)", |
| 123 | + ) |
| 124 | + |
| 125 | + def subplot( |
| 126 | + self, |
| 127 | + data: bool = False, |
| 128 | + noise_map: bool = False, |
| 129 | + psf: bool = False, |
| 130 | + signal_to_noise_map: bool = False, |
| 131 | + over_sampling: bool = False, |
| 132 | + over_sampling_pixelization: bool = False, |
| 133 | + auto_filename: str = "subplot_dataset", |
| 134 | + ): |
| 135 | + self._subplot_custom_plot( |
| 136 | + data=data, |
| 137 | + noise_map=noise_map, |
| 138 | + psf=psf, |
| 139 | + signal_to_noise_map=signal_to_noise_map, |
| 140 | + over_sampling=over_sampling, |
| 141 | + over_sampling_pixelization=over_sampling_pixelization, |
| 142 | + auto_labels=AutoLabels(filename=auto_filename), |
| 143 | + ) |
| 144 | + |
| 145 | + def subplot_dataset(self): |
| 146 | + use_log10_original = self.mat_plot_2d.use_log10 |
| 147 | + |
| 148 | + self.open_subplot_figure(number_subplots=9) |
| 149 | + self.figures_2d(data=True) |
| 150 | + |
| 151 | + contour_original = copy.copy(self.mat_plot_2d.contour) |
| 152 | + self.mat_plot_2d.use_log10 = True |
| 153 | + self.mat_plot_2d.contour = False |
| 154 | + self.figures_2d(data=True) |
| 155 | + self.mat_plot_2d.use_log10 = False |
| 156 | + self.mat_plot_2d.contour = contour_original |
| 157 | + |
| 158 | + self.figures_2d(noise_map=True) |
| 159 | + self.figures_2d(psf=True) |
| 160 | + |
| 161 | + self.mat_plot_2d.use_log10 = True |
| 162 | + self.figures_2d(psf=True) |
| 163 | + self.mat_plot_2d.use_log10 = False |
| 164 | + |
| 165 | + self.figures_2d(signal_to_noise_map=True) |
| 166 | + self.figures_2d(over_sample_size_lp=True) |
| 167 | + self.figures_2d(over_sample_size_pixelization=True) |
| 168 | + |
| 169 | + self.mat_plot_2d.output.subplot_to_figure(auto_filename="subplot_dataset") |
| 170 | + self.close_subplot_figure() |
| 171 | + |
| 172 | + self.mat_plot_2d.use_log10 = use_log10_original |
| 173 | + |
| 174 | + |
| 175 | +class ImagingPlotter(AbstractPlotter): |
| 176 | + def __init__( |
| 177 | + self, |
| 178 | + dataset: Imaging, |
| 179 | + mat_plot_2d: MatPlot2D = None, |
| 180 | + grid=None, |
| 181 | + positions=None, |
| 182 | + lines=None, |
| 183 | + ): |
| 184 | + super().__init__(mat_plot_2d=mat_plot_2d) |
| 185 | + self.dataset = dataset |
| 186 | + |
| 187 | + self._imaging_meta_plotter = ImagingPlotterMeta( |
| 188 | + dataset=self.dataset, |
| 189 | + mat_plot_2d=self.mat_plot_2d, |
| 190 | + grid=grid, |
| 191 | + positions=positions, |
| 192 | + lines=lines, |
| 193 | + ) |
| 194 | + |
| 195 | + self.figures_2d = self._imaging_meta_plotter.figures_2d |
| 196 | + self.subplot = self._imaging_meta_plotter.subplot |
| 197 | + self.subplot_dataset = self._imaging_meta_plotter.subplot_dataset |
0 commit comments