@@ -46,13 +46,34 @@ def flt_ind_str_arr(*, fltarr, intarr, flt_tols, flt_first=True):
4646 prec_int = 8
4747 flt_str_list = ["{1:.{0}f}".format(prec_flt, flt) for flt in fltarr]
4848 int_str_list = [str(intv).zfill(prec_int) for intv in intarr]
49+ list_of_lists = []
4950 if flt_first:
50- zipped = zip( flt_str_list, int_str_list, strict=True)
51+ list_of_lists = [ flt_str_list, int_str_list]
5152 else:
52- zipped = zip(int_str_list, flt_str_list, strict=True)
53+ list_of_lists = [int_str_list, flt_str_list]
54+ zipped = zip(*list_of_lists, strict=True)
5355 return np.array(["_".join(zpval) for zpval in zipped])
5456
5557
58+ def _get_freq_order(spw_id, freq_arr):
59+ spws = np.unique(spw_id)
60+ f_order = np.concatenate([np.where(spw_id == spw)[0] for spw in np.unique(spw_id)])
61+
62+ # With spectral windows sorted, check and see if channels within
63+ # windows need sorting. If they are ordered in ascending or descending
64+ # fashion, leave them be. If not, sort in ascending order
65+ for spw in spws:
66+ select_mask = spw_id[f_order] == spw
67+ check_freqs = freq_arr[f_order[select_mask]]
68+ if not np.all(np.diff(check_freqs) > 0) and not np.all(
69+ np.diff(check_freqs) < 0
70+ ):
71+ subsort_order = f_order[select_mask]
72+ f_order[select_mask] = subsort_order[np.argsort(check_freqs)]
73+
74+ return f_order
75+
76+
5677def _axis_add_helper(this, other, axis_name: str, other_inds, final_order=None):
5778 update_params = this._get_param_axis(axis_name, single_named_axis=True)
5879 other_form_dict = {axis_name: other_inds}
@@ -5680,7 +5701,6 @@ def __add__(
56805701 "Nfreqs": {"method": "reorder_freqs", "parameter": "channel_order"},
56815702 "Npols": {"method": "reorder_pols", "parameter": "order"},
56825703 }
5683- order_dict = {"Nblts": None, "Nfreqs": None, "Npols": None}
56845704 for axis, ind_dict in axis_inds.items():
56855705 if len(ind_dict["this"]) != 0:
56865706 # there is some overlap, so sorting matters
@@ -5698,13 +5718,31 @@ def __add__(
56985718
56995719 # Pad out self to accommodate new data
57005720 new_axis_inds = {}
5721+ order_dict = {"Nblts": None, "Nfreqs": None, "Npols": None}
57015722 for axis_ind, axis in enumerate(axes):
57025723 if len(new_inds[axis]) > 0:
57035724 new_axis_inds[axis] = np.concatenate(
57045725 (axis_vals[axis]["this"], axis_vals[axis]["other"][new_inds[axis]])
57055726 )
57065727 if axis == "Npols":
57075728 order_dict[axis] = np.argsort(np.abs(new_axis_inds[axis]))
5729+ elif axis == "Nfreqs" and (
5730+ np.any(np.diff(this.freq_array) < 0)
5731+ or np.any(np.diff(other.freq_array) < 0)
5732+ ):
5733+ # deal with the possibility of spws with channels in
5734+ # descending order.
5735+ order_dict[axis] = _get_freq_order(
5736+ np.concatenate(
5737+ (
5738+ this.flex_spw_id_array,
5739+ other.flex_spw_id_array[new_inds[axis]],
5740+ )
5741+ ),
5742+ np.concatenate(
5743+ (this.freq_array, other.freq_array[new_inds[axis]])
5744+ ),
5745+ )
57085746 else:
57095747 order_dict[axis] = np.argsort(new_axis_inds[axis])
57105748
0 commit comments