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