Skip to content

Commit 136e693

Browse files
committed
Add mask type methods, Add NoneType support to pyvisgen polarization argument
1 parent 6819134 commit 136e693

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

pyvisgrid/core/gridder.py

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,38 @@ class GridData:
6161
def __str__(self):
6262
return self.__dict__
6363

64+
def get_mask_complex(self):
65+
"""
66+
Returns the gridded mask as a complex array with
67+
the form ``mask.real + 1j * mask.imag``.
68+
69+
Returns
70+
-------
71+
numpy.ndarray: Complex mask
72+
"""
73+
return self.mask_real + 1j * self.mask_imag
74+
75+
def get_mask_abs_phase(self):
76+
"""
77+
Returns the gridded mask as amplitude and phase.
78+
79+
Returns
80+
-------
81+
tuple[numpy.ndarray]: Amplitude and phase of the complex mask.
82+
"""
83+
mask_complex = self.get_mask_complex()
84+
return np.abs(mask_complex), np.angle(mask_complex)
85+
86+
def get_mask_real_imag(self):
87+
"""
88+
Returns the gridded mask as real and imaginary parts.
89+
90+
Returns
91+
-------
92+
tuple[numpy.ndarray]: Real and parts of the complex mask.
93+
"""
94+
return self.mask_real, self.mask_imag
95+
6496

6597
class Gridder:
6698
def __init__(
@@ -242,7 +274,7 @@ def from_pyvisgen(
242274
img_size: int,
243275
fov: float,
244276
stokes_components: list[str] | str = "I",
245-
polarizations: list[str] | str = "",
277+
polarizations: list[str] | str | None = None,
246278
):
247279
"""
248280
Initializes the gridder with the visibility data which is generated by the
@@ -275,8 +307,8 @@ def from_pyvisgen(
275307
This can either be a list of components (e.g. ``['I', 'V']``) or a single
276308
string. Default is ``'I'``.
277309
278-
polarizations : list[str] | str, optional
279-
The polarization type. Default is ``''``.
310+
polarizations : list[str] | str | None, optional
311+
The polarization type. Default is ``None``.
280312
"""
281313
u_meter = vis_data.u
282314
v_meter = vis_data.v
@@ -304,6 +336,9 @@ def from_pyvisgen(
304336
if isinstance(stokes_components, str):
305337
stokes_components = [stokes_components]
306338

339+
if polarizations is None:
340+
polarizations = ""
341+
307342
if isinstance(polarizations, str):
308343
polarizations = [polarizations]
309344

pyvisgrid/plotting/plotting.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,9 @@ def plot_mask(
379379
im, ax=ax, shrink=colorbar_shrink, label="$(u,v)$ per frequel in 1/fq"
380380
)
381381
case "abs":
382+
mask_abs, _ = grid_data.get_mask_abs_phase()
382383
im = ax.imshow(
383-
np.abs(grid_data.mask_real + 1j * grid_data.mask_imag),
384+
mask_abs,
384385
norm=norm,
385386
origin="lower",
386387
interpolation="none",
@@ -389,8 +390,9 @@ def plot_mask(
389390
)
390391
fig.colorbar(im, ax=ax, shrink=colorbar_shrink, label="Amplitude in a.u.")
391392
case "phase":
393+
_, mask_phase = grid_data.get_mask_abs_phase()
392394
im = ax.imshow(
393-
np.angle(grid_data.mask_real + 1j * grid_data.mask_imag),
395+
mask_phase,
394396
norm=norm,
395397
origin="lower",
396398
interpolation="none",

0 commit comments

Comments
 (0)