@@ -78,16 +78,15 @@ def flt_ind_str_arr(
7878 list_of_lists = [flt_str_list, int_str_list]
7979 else:
8080 list_of_lists = [int_str_list, flt_str_list]
81- zipped = zip(*list_of_lists, strict=True)
82- return np.array(["_".join(zpval) for zpval in zipped])
81+ return np.array(["_".join(zpval) for zpval in zip(*list_of_lists, strict=True)])
8382
8483
8584def _add_freq_order(spw_id: IntArray, freq_arr: FloatArray) -> IntArray:
8685 """
8786 Get the sorting order for the frequency axis after an add.
8887
8988 Sort first by spw then by channel, but don't reorder channels if they are
90- changing monotonically (all ascending or descending).
89+ changing monotonically (all ascending or descending) within the spw .
9190
9291 Parameters
9392 ----------
@@ -5678,6 +5677,35 @@ def __add__(
56785677 strict_uvw_antpos_check=strict_uvw_antpos_check,
56795678 )
56805679
5680+ if (
5681+ this.flex_spw_polarization_array is not None
5682+ or other.flex_spw_polarization_array is not None
5683+ ):
5684+ # special checking for flex_spw
5685+ if (this.flex_spw_polarization_array is None) != (
5686+ other.flex_spw_polarization_array is None
5687+ ):
5688+ raise ValueError(
5689+ "Cannot add a flex-pol and non-flex-pol UVData objects. Use "
5690+ "the `remove_flex_pol` method to convert the objects to "
5691+ "have a regular polarization axis."
5692+ )
5693+ elif this.flex_spw_polarization_array is not None:
5694+ this_flexpol_dict = this.flexpol_dict()
5695+ other_flexpol_dict = other.flexpol_dict()
5696+ for key in other_flexpol_dict:
5697+ try:
5698+ if this_flexpol_dict[key] != other_flexpol_dict[key]:
5699+ raise ValueError(
5700+ "Cannot add a flex-pol UVData objects where "
5701+ "the same spectral window contains different "
5702+ "polarizations. Use the `remove_flex_pol` "
5703+ "method to convert the objects to have a "
5704+ "regular polarization axis."
5705+ )
5706+ except KeyError:
5707+ this_flexpol_dict[key] = other_flexpol_dict[key]
5708+
56815709 # Define parameters that must be the same to add objects
56825710 compatibility_params = ["_vis_units"]
56835711
@@ -5717,7 +5745,7 @@ def __add__(
57175745 "other": getattr(other, overlap_params[0]),
57185746 }
57195747
5720- # Check we don't have overlapping data
5748+ # Check if we have overlapping data
57215749 axis_inds = {}
57225750 for axis, val_arr in axis_vals.items():
57235751 both_inds, this_inds, other_inds = np.intersect1d(
@@ -5730,10 +5758,11 @@ def __add__(
57305758 }
57315759
57325760 history_update_string = ""
5761+ # TODO do this programmatically for multidimensional parameters
57335762 if not self.metadata_only and np.all(
57345763 [len(axis_inds[axis]["both"]) > 0 for axis in axis_inds]
57355764 ):
5736- # check that overlapping data is not valid
5765+ # We have overlaps, check that overlapping data is not valid
57375766 this_inds = np.ravel_multi_index(
57385767 (
57395768 axis_inds["Nblts"]["this"][:, np.newaxis, np.newaxis],
@@ -5778,35 +5807,6 @@ def __add__(
57785807 }
57795808 # find the indices in "other" but not in "this"
57805809 for axis in axes:
5781- if axis == "Nfreqs" and (
5782- this.flex_spw_polarization_array is not None
5783- or other.flex_spw_polarization_array is not None
5784- ):
5785- # special checking for flex_spw
5786- if (this.flex_spw_polarization_array is None) != (
5787- other.flex_spw_polarization_array is None
5788- ):
5789- raise ValueError(
5790- "Cannot add a flex-pol and non-flex-pol UVData objects. Use "
5791- "the `remove_flex_pol` method to convert the objects to "
5792- "have a regular polarization axis."
5793- )
5794- elif this.flex_spw_polarization_array is not None:
5795- this_flexpol_dict = this.flexpol_dict()
5796- other_flexpol_dict = other.flexpol_dict()
5797- for key in other_flexpol_dict:
5798- try:
5799- if this_flexpol_dict[key] != other_flexpol_dict[key]:
5800- raise ValueError(
5801- "Cannot add a flex-pol UVData objects where "
5802- "the same spectral window contains different "
5803- "polarizations. Use the `remove_flex_pol` "
5804- "method to convert the objects to have a "
5805- "regular polarization axis."
5806- )
5807- except KeyError:
5808- this_flexpol_dict[key] = other_flexpol_dict[key]
5809-
58105810 temp = np.nonzero(
58115811 ~np.isin(axis_vals[axis]["other"], axis_vals[axis]["this"])
58125812 )[0]
@@ -5865,7 +5865,7 @@ def __add__(
58655865 }
58665866 for axis, ind_dict in axis_inds.items():
58675867 if len(ind_dict["this"]) != 0:
5868- # there is some overlap, so sorting matters
5868+ # there is some overlap, so check sorting
58695869 this_argsort = np.argsort(ind_dict["this"])
58705870 other_argsort = np.argsort(ind_dict["other"])
58715871
@@ -5878,7 +5878,7 @@ def __add__(
58785878
58795879 getattr(this, reorder_method[axis]["method"])(**kwargs)
58805880
5881- # Pad out self to accommodate new data
5881+ # start updating parameters
58825882 new_axis_inds = {}
58835883 order_dict = {"Nblts": None, "Nfreqs": None, "Npols": None}
58845884 for axis in axes:
@@ -5916,7 +5916,7 @@ def __add__(
59165916 else:
59175917 new_axis_inds[axis] = axis_vals[axis]["this"]
59185918
5919- # Now fill in multidimensional arrays
5919+ # Now fill in multidimensional parameters
59205920 t2o_dict = {}
59215921 for axis, inds_dict in axis_vals.items():
59225922 t2o_dict[axis] = np.nonzero(
@@ -5946,9 +5946,9 @@ def __add__(
59465946 # Update N parameters (e.g. Npols)
59475947 this.Ntimes = len(np.unique(this.time_array))
59485948 this.Nbls = len(np.unique(this.baseline_array))
5949- this.Nblts = this.uvw_array.shape[0]
5949+ this.Nblts = this.baseline_array.size
59505950 this.Nfreqs = this.freq_array.size
5951- this.Npols = this.polarization_array.shape[0]
5951+ this.Npols = this.polarization_array.size
59525952 this.Nants_data = this._calc_nants_data()
59535953
59545954 # Update filename parameter
@@ -5983,7 +5983,7 @@ def __add__(
59835983 )
59845984
59855985 # Reset blt_order if blt axis was added to
5986- if len(t2o_dict[ "Nblts"]) > 0 :
5986+ if "Nblts" in sort_axes :
59875987 this.blt_order = ("time", "baseline")
59885988
59895989 this.set_rectangularity(force=True)
0 commit comments