2727from ..utils import phasing as phs_utils
2828from ..utils.io import hdf5 as hdf5_utils
2929from ..utils.phasing import _get_focus_xyz, _get_nearfield_delay
30+ from ..utils.types import FloatArray, IntArray, StrArray
3031from ..uvbase import UVBase
3132from .initializers import new_uvdata
3233
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]
@@ -5410,7 +5488,7 @@ def fix_phase(self, *, use_ant_pos=True):
54105488 use_ant_pos=False,
54115489 )
54125490
5413- def blt_str_arr(self):
5491+ def blt_str_arr(self) -> StrArray :
54145492 """Create a string array with baseline and time info for matching purposes."""
54155493 return flt_ind_str_arr(
54165494 fltarr=self.time_array,
@@ -5419,7 +5497,7 @@ def blt_str_arr(self):
54195497 flt_first=True,
54205498 )
54215499
5422- def spw_freq_str_arr(self):
5500+ def spw_freq_str_arr(self) -> StrArray :
54235501 """Create a string array with spw and freq info for matching purposes."""
54245502 return flt_ind_str_arr(
54255503 fltarr=self.freq_array,
@@ -5428,7 +5506,7 @@ def spw_freq_str_arr(self):
54285506 flt_first=False,
54295507 )
54305508
5431- def flexpol_dict(self):
5509+ def flexpol_dict(self) -> dict :
54325510 """Create a dict with flexpol information for comparison."""
54335511 return dict(zip(self.spw_array, self.flex_spw_polarization_array, strict=True))
54345512
@@ -5732,7 +5810,7 @@ def __add__(
57325810 ):
57335811 # deal with the possibility of spws with channels in
57345812 # descending order.
5735- order_dict[axis] = _get_freq_order (
5813+ order_dict[axis] = _add_freq_order (
57365814 np.concatenate(
57375815 (
57385816 this.flex_spw_id_array,
0 commit comments