@@ -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 ----------
@@ -5697,6 +5696,35 @@ def __add__(
56975696 strict_uvw_antpos_check=strict_uvw_antpos_check,
56985697 )
56995698
5699+ if (
5700+ this.flex_spw_polarization_array is not None
5701+ or other.flex_spw_polarization_array is not None
5702+ ):
5703+ # special checking for flex_spw
5704+ if (this.flex_spw_polarization_array is None) != (
5705+ other.flex_spw_polarization_array is None
5706+ ):
5707+ raise ValueError(
5708+ "Cannot add a flex-pol and non-flex-pol UVData objects. Use "
5709+ "the `remove_flex_pol` method to convert the objects to "
5710+ "have a regular polarization axis."
5711+ )
5712+ elif this.flex_spw_polarization_array is not None:
5713+ this_flexpol_dict = this.flexpol_dict()
5714+ other_flexpol_dict = other.flexpol_dict()
5715+ for key in other_flexpol_dict:
5716+ try:
5717+ if this_flexpol_dict[key] != other_flexpol_dict[key]:
5718+ raise ValueError(
5719+ "Cannot add a flex-pol UVData objects where "
5720+ "the same spectral window contains different "
5721+ "polarizations. Use the `remove_flex_pol` "
5722+ "method to convert the objects to have a "
5723+ "regular polarization axis."
5724+ )
5725+ except KeyError:
5726+ this_flexpol_dict[key] = other_flexpol_dict[key]
5727+
57005728 # Define parameters that must be the same to add objects
57015729 compatibility_params = ["_vis_units"]
57025730
@@ -5736,7 +5764,7 @@ def __add__(
57365764 "other": getattr(other, overlap_params[0]),
57375765 }
57385766
5739- # Check we don't have overlapping data
5767+ # Check if we have overlapping data
57405768 axis_inds = {}
57415769 for axis, val_arr in axis_vals.items():
57425770 both_inds, this_inds, other_inds = np.intersect1d(
@@ -5749,10 +5777,11 @@ def __add__(
57495777 }
57505778
57515779 history_update_string = ""
5780+ # TODO do this programmatically for multidimensional parameters
57525781 if not self.metadata_only and np.all(
57535782 [len(axis_inds[axis]["both"]) > 0 for axis in axis_inds]
57545783 ):
5755- # check that overlapping data is not valid
5784+ # We have overlaps, check that overlapping data is not valid
57565785 this_inds = np.ravel_multi_index(
57575786 (
57585787 axis_inds["Nblts"]["this"][:, np.newaxis, np.newaxis],
@@ -5797,35 +5826,6 @@ def __add__(
57975826 }
57985827 # find the indices in "other" but not in "this"
57995828 for axis in axes:
5800- if axis == "Nfreqs" and (
5801- this.flex_spw_polarization_array is not None
5802- or other.flex_spw_polarization_array is not None
5803- ):
5804- # special checking for flex_spw
5805- if (this.flex_spw_polarization_array is None) != (
5806- other.flex_spw_polarization_array is None
5807- ):
5808- raise ValueError(
5809- "Cannot add a flex-pol and non-flex-pol UVData objects. Use "
5810- "the `remove_flex_pol` method to convert the objects to "
5811- "have a regular polarization axis."
5812- )
5813- elif this.flex_spw_polarization_array is not None:
5814- this_flexpol_dict = this.flexpol_dict()
5815- other_flexpol_dict = other.flexpol_dict()
5816- for key in other_flexpol_dict:
5817- try:
5818- if this_flexpol_dict[key] != other_flexpol_dict[key]:
5819- raise ValueError(
5820- "Cannot add a flex-pol UVData objects where "
5821- "the same spectral window contains different "
5822- "polarizations. Use the `remove_flex_pol` "
5823- "method to convert the objects to have a "
5824- "regular polarization axis."
5825- )
5826- except KeyError:
5827- this_flexpol_dict[key] = other_flexpol_dict[key]
5828-
58295829 temp = np.nonzero(
58305830 ~np.isin(axis_vals[axis]["other"], axis_vals[axis]["this"])
58315831 )[0]
@@ -5884,7 +5884,7 @@ def __add__(
58845884 }
58855885 for axis, ind_dict in axis_inds.items():
58865886 if len(ind_dict["this"]) != 0:
5887- # there is some overlap, so sorting matters
5887+ # there is some overlap, so check sorting
58885888 this_argsort = np.argsort(ind_dict["this"])
58895889 other_argsort = np.argsort(ind_dict["other"])
58905890
@@ -5897,7 +5897,7 @@ def __add__(
58975897
58985898 getattr(this, reorder_method[axis]["method"])(**kwargs)
58995899
5900- # Pad out self to accommodate new data
5900+ # start updating parameters
59015901 new_axis_inds = {}
59025902 order_dict = {"Nblts": None, "Nfreqs": None, "Npols": None}
59035903 for axis in axes:
@@ -5935,7 +5935,7 @@ def __add__(
59355935 else:
59365936 new_axis_inds[axis] = axis_vals[axis]["this"]
59375937
5938- # Now fill in multidimensional arrays
5938+ # Now fill in multidimensional parameters
59395939 t2o_dict = {}
59405940 for axis, inds_dict in axis_vals.items():
59415941 t2o_dict[axis] = np.nonzero(
@@ -5965,9 +5965,9 @@ def __add__(
59655965 # Update N parameters (e.g. Npols)
59665966 this.Ntimes = len(np.unique(this.time_array))
59675967 this.Nbls = len(np.unique(this.baseline_array))
5968- this.Nblts = this.uvw_array.shape[0]
5968+ this.Nblts = this.baseline_array.size
59695969 this.Nfreqs = this.freq_array.size
5970- this.Npols = this.polarization_array.shape[0]
5970+ this.Npols = this.polarization_array.size
59715971 this.Nants_data = this._calc_nants_data()
59725972
59735973 # Update filename parameter
@@ -6002,7 +6002,7 @@ def __add__(
60026002 )
60036003
60046004 # Reset blt_order if blt axis was added to
6005- if len(t2o_dict[ "Nblts"]) > 0 :
6005+ if "Nblts" in sort_axes :
60066006 this.blt_order = ("time", "baseline")
60076007
60086008 this.set_rectangularity(force=True)
0 commit comments