190 ):
191 """Format matched catalogs that may require coordinate conversions.
192
193 Parameters
194 ----------
195 catalog_ref : `pandas.DataFrame`
196 A reference catalog for comparison to `catalog_target`.
197 catalog_target : `pandas.DataFrame`
198 A target catalog with measurements for comparison to `catalog_ref`.
199 select_ref : `numpy.ndarray`, (Nref,)
200 A boolean array of len `catalog_ref`, True for valid match candidates.
201 select_target : `numpy.ndarray`, (Ntarget,)
202 A boolean array of len `catalog_target`, True for valid match candidates.
203 radec_to_xy_func : `typing.Callable`
204 Function taking equal-length ra, dec arrays and returning an ndarray of
205 - ``x``: current parameter (`float`).
206 - ``extra_args``: additional arguments (`dict`).
207 return_converted_columns : `bool`
208 Whether to return converted columns in the `coord1` and `coord2`
209 attributes, rather than keep the original values.
210 kwargs
211
212 Returns
213 -------
214 compcat_ref, compcat_target : `ComparableCatalog`
215 Comparable catalogs corresponding to the input reference and target.
216
217 """
218 convert_ref = self.coords_ref_to_convert
219 if convert_ref and not callable(radec_to_xy_func):
220 raise TypeError('radec_to_xy_func must be callable if converting ref coords')
221
222
223 extras_ref, extras_target = (
224 CatalogExtras(catalog, select=select, coordinate_factor=coord_factor)
225 for catalog, select, coord_factor in zip(
226 (catalog_ref, catalog_target),
227 (select_ref, select_target),
228 (self.coords_ref_factor, self.coords_target_factor),
229 )
230 )
231
232 compcats = []
233
234
235 for catalog, extras, (column1, column2), convert in (
236 (catalog_ref, extras_ref, (self.column_ref_coord1, self.column_ref_coord2), convert_ref),
237 (catalog_target, extras_target, (self.column_target_coord1, self.column_target_coord2), False),
238 ):
239 coord1, coord2 = (
240 _mul_column(catalog[column], extras.coordinate_factor)
241 for column in (column1, column2)
242 )
243 if convert:
244 xy_ref = radec_to_xy_func(coord1, coord2, self.coords_ref_factor, **kwargs)
245 for idx_coord, column_out in enumerate(self.coords_ref_to_convert.values()):
246 coord = np.array([xy[idx_coord] for xy in xy_ref])
247 catalog[column_out] = coord
248 if convert_ref and return_converted_columns:
249 column1, column2 = self.coords_ref_to_convert.values()
250 coord1, coord2 = catalog[column1], catalog[column2]
251 if isinstance(coord1, pd.Series):
252 coord1 = coord1.values
253 if isinstance(coord2, pd.Series):
254 coord2 = coord2.values
255
256 compcats.append(ComparableCatalog(
257 catalog=catalog, column_coord1=column1, column_coord2=column2,
258 coord1=coord1, coord2=coord2, extras=extras,
259 ))
260
261 return tuple(compcats)
262
263