Skip to content

Commit ac4c230

Browse files
committed
docstrings and annotations for convenience methods
1 parent 2bbd073 commit ac4c230

1 file changed

Lines changed: 87 additions & 9 deletions

File tree

src/pyuvdata/uvdata/uvdata.py

Lines changed: 87 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from ..utils import phasing as phs_utils
2828
from ..utils.io import hdf5 as hdf5_utils
2929
from ..utils.phasing import _get_focus_xyz, _get_nearfield_delay
30+
from ..utils.types import FloatArray, IntArray, StrArray
3031
from ..uvbase import UVBase
3132
from .initializers import new_uvdata
3233

@@ -40,8 +41,33 @@
4041
)
4142

4243

43-
def flt_ind_str_arr(*, fltarr, intarr, flt_tols, flt_first=True):
44-
"""Create a string array built from float and integer arrays for matching."""
44+
def flt_ind_str_arr(
45+
*,
46+
fltarr: FloatArray,
47+
intarr: IntArray,
48+
flt_tols: tuple[float, float],
49+
flt_first: bool = True,
50+
) -> StrArray:
51+
"""
52+
Create a string array built from float and integer arrays for matching.
53+
54+
Parameters
55+
----------
56+
fltarr : np.ndarray of float
57+
float array to be used in output string array
58+
intarr : np.ndarray of int
59+
integer array to be used in output string array
60+
flt_tols : 2-tuple of float
61+
Tolerances (relative, absolute) to use in formatting the floats as strings.
62+
flt_first : bool
63+
Whether to put the float first in the out put string or not (if False
64+
the int comes first.)
65+
66+
Returns
67+
-------
68+
np.ndarray of str
69+
String array that combines the float and integer values, useful for matching.
70+
"""
4571
prec_flt = -2 * np.floor(np.log10(flt_tols[-1])).astype(int)
4672
prec_int = 8
4773
flt_str_list = ["{1:.{0}f}".format(prec_flt, flt) for flt in fltarr]
@@ -55,7 +81,25 @@ def flt_ind_str_arr(*, fltarr, intarr, flt_tols, flt_first=True):
5581
return np.array(["_".join(zpval) for zpval in zipped])
5682

5783

58-
def _get_freq_order(spw_id, freq_arr):
84+
def _add_freq_order(spw_id: IntArray, freq_arr: FloatArray) -> IntArray:
85+
"""
86+
Get the sorting order for the frequency axis after an add.
87+
88+
Sort first by spw then by channel, but don't reorder channels if they are
89+
changing monotonically (all ascending or descending).
90+
91+
Parameters
92+
----------
93+
spw_id : np.ndarray of int
94+
SPW id array of combined data to be sorted.
95+
freq_arr : np.ndarray of float
96+
Frequency array of combined data to be sorted.
97+
98+
Returns
99+
-------
100+
f_order : np.ndarray of int
101+
index array giving the sort order.
102+
"""
59103
spws = np.unique(spw_id)
60104
f_order = np.concatenate([np.where(spw_id == spw)[0] for spw in np.unique(spw_id)])
61105

@@ -74,7 +118,29 @@ def _get_freq_order(spw_id, freq_arr):
74118
return f_order
75119

76120

77-
def _axis_add_helper(this, other, axis_name: str, other_inds, final_order=None):
121+
def _axis_add_helper(
122+
this: UVData,
123+
other: UVData,
124+
axis_name: str,
125+
other_inds: IntArray,
126+
final_order: IntArray | None = None,
127+
):
128+
"""
129+
Combine UVData objects along an axis.
130+
131+
Parameters
132+
----------
133+
this : UVData
134+
The left UVData object in the add.
135+
other : UVData
136+
The right UVData object in the add.
137+
axis_name : str
138+
The axis name (e.g. "Nblts", "Npols").
139+
other_inds : np.ndarray of int
140+
Indices into the other object along this axis to include.
141+
final_order : np.ndarray of int
142+
Final ordering array giving the sort order after concatenation.
143+
"""
78144
update_params = this._get_param_axis(axis_name, single_named_axis=True)
79145
other_form_dict = {axis_name: other_inds}
80146
for param, axis_list in update_params.items():
@@ -92,7 +158,19 @@ def _axis_add_helper(this, other, axis_name: str, other_inds, final_order=None):
92158
setattr(this, param, new_array)
93159

94160

95-
def _axis_fast_concat_helper(this, other, axis_name: str):
161+
def _axis_fast_concat_helper(this: UVData, other: UVData, axis_name: str):
162+
"""
163+
Concatenate UVData objects along an axis assuming no overlap.
164+
165+
Parameters
166+
----------
167+
this : UVData
168+
The left UVData object in the add.
169+
other : UVData
170+
The right UVData object in the add.
171+
axis_name : str
172+
The axis name (e.g. "Nblts", "Npols").
173+
"""
96174
update_params = this._get_param_axis(axis_name)
97175
for param, axis_list in update_params.items():
98176
axis = axis_list[0]
@@ -5429,7 +5507,7 @@ def fix_phase(self, *, use_ant_pos=True):
54295507
use_ant_pos=False,
54305508
)
54315509

5432-
def blt_str_arr(self):
5510+
def blt_str_arr(self) -> StrArray:
54335511
"""Create a string array with baseline and time info for matching purposes."""
54345512
return flt_ind_str_arr(
54355513
fltarr=self.time_array,
@@ -5438,7 +5516,7 @@ def blt_str_arr(self):
54385516
flt_first=True,
54395517
)
54405518

5441-
def spw_freq_str_arr(self):
5519+
def spw_freq_str_arr(self) -> StrArray:
54425520
"""Create a string array with spw and freq info for matching purposes."""
54435521
return flt_ind_str_arr(
54445522
fltarr=self.freq_array,
@@ -5447,7 +5525,7 @@ def spw_freq_str_arr(self):
54475525
flt_first=False,
54485526
)
54495527

5450-
def flexpol_dict(self):
5528+
def flexpol_dict(self) -> dict:
54515529
"""Create a dict with flexpol information for comparison."""
54525530
return dict(zip(self.spw_array, self.flex_spw_polarization_array, strict=True))
54535531

@@ -5751,7 +5829,7 @@ def __add__(
57515829
):
57525830
# deal with the possibility of spws with channels in
57535831
# descending order.
5754-
order_dict[axis] = _get_freq_order(
5832+
order_dict[axis] = _add_freq_order(
57555833
np.concatenate(
57565834
(
57575835
this.flex_spw_id_array,

0 commit comments

Comments
 (0)