56 catalog: astropy.table.Table | pd.DataFrame,
57 columns_true: List[str],
58 columns_false: List[str],
59 selection: Optional[np.array],
61 """Apply additional boolean selection columns.
63 catalog : `pandas.DataFrame` | `astropy.table.Table`
64 The catalog to select from.
65 columns_true : `list` [`str`]
66 Columns that must be True for selection.
67 columns_false : `list` [`str`]
68 Columns that must be False for selection.
69 selection : `numpy.array`
70 A prior selection array. Default all true.
74 selection : `numpy.array`
75 The final selection array.
79 is_pd = isinstance(catalog, pd.DataFrame)
81 warnings.warn(
"pandas usage in MatchProbabilisticTask is deprecated; it will be removed "
82 " in favour of astropy.table after release 28.0.0", category=FutureWarning)
83 select_additional = (len(columns_true) + len(columns_false)) > 0
86 selection = np.ones(len(catalog), dtype=bool)
87 for column
in columns_true:
90 values = catalog[column]
if not is_pd
else catalog[column].values
91 selection &= (np.isfinite(values) & (values != 0))
92 for column
in columns_false:
93 values = catalog[column]
if not is_pd
else catalog[column].values
94 selection &= (values == 0)
107 catalog_ref: astropy.table.Table | pd.DataFrame,
108 catalog_target: astropy.table.Table | pd.DataFrame,
109 select_ref: np.array =
None,
110 select_target: np.array =
None,
111 wcs: afwGeom.SkyWcs =
None,
112 logger: logging.Logger =
None,
113 logging_n_rows: int =
None,
114 ) -> Tuple[pd.DataFrame, pd.DataFrame, Dict[int, str]]:
115 """Match sources in a reference tract catalog with a target catalog.
119 catalog_ref : `pandas.DataFrame` | `astropy.table.Table`
120 A reference catalog to match objects/sources from.
121 catalog_target : `pandas.DataFrame` | `astropy.table.Table`
122 A target catalog to match reference objects/sources to.
123 select_ref : `numpy.array`
124 A boolean array of the same length as `catalog_ref` selecting the sources that can be matched.
125 select_target : `numpy.array`
126 A boolean array of the same length as `catalog_target` selecting the sources that can be matched.
127 wcs : `lsst.afw.image.SkyWcs`
128 A coordinate system to convert catalog positions to sky coordinates. Only used if
129 `self.config.coords_ref_to_convert` is set.
130 logger : `logging.Logger`
131 A Logger for logging.
132 logging_n_rows : `int`
133 Number of matches to make before outputting incremental log message.
137 catalog_out_ref : `pandas.DataFrame` | `astropy.table.Table`
138 Reference matched catalog with indices of target matches.
139 catalog_out_target : `pandas.DataFrame` | `astropy.table.Table`
140 Reference matched catalog with indices of target matches.
146 is_ref_pd = isinstance(catalog_ref, pd.DataFrame)
147 is_target_pd = isinstance(catalog_target, pd.DataFrame)
148 if is_ref_pd
or is_target_pd:
149 warnings.warn(
"pandas usage in MatchProbabilisticTask is deprecated; it will be removed "
150 " in favour of astropy.table after release 28.0.0", category=FutureWarning)
154 if config.column_ref_order
is None:
156 catalog_ref.loc[:, config.columns_ref_flux].values
158 [catalog_ref[key]
for key
in config.columns_ref_flux]
160 flux_tot = np.nansum(fluxes, axis=1
if is_ref_pd
else 0)
161 catalog_ref[
"flux_total"] = flux_tot
162 if config.mag_brightest_ref != -np.inf
or config.mag_faintest_ref != np.inf:
164 -2.5 * np.log10(flux_tot) + config.coord_format.mag_zeropoint_ref
166 select_mag = (mag_tot >= config.mag_brightest_ref) & (
167 mag_tot <= config.mag_faintest_ref
170 select_mag = np.isfinite(flux_tot)
171 if select_ref
is None:
172 select_ref = select_mag
174 select_ref &= select_mag
176 with warnings.catch_warnings():
178 warnings.filterwarnings(action=
"ignore", category=FutureWarning)
181 columns_true=config.columns_ref_select_true,
182 columns_false=config.columns_ref_select_false,
183 selection=select_ref,
186 catalog=catalog_target,
187 columns_true=config.columns_target_select_true,
188 columns_false=config.columns_target_select_false,
189 selection=select_target,
193 "Beginning MatcherProbabilistic.match with %d/%d ref sources selected vs %d/%d target",
196 np.sum(select_target),
200 catalog_out_ref, catalog_out_target, exceptions = self.
matcher.
match(
203 select_ref=select_ref,
204 select_target=select_target,
206 logging_n_rows=logging_n_rows,
208 radec_to_xy_func=radec_to_xy,
211 return catalog_out_ref, catalog_out_target, exceptions
216 catalog_ref: astropy.table.Table | pd.DataFrame,
217 catalog_target: astropy.table.Table | pd.DataFrame,
218 wcs: afwGeom.SkyWcs =
None,
220 ) -> pipeBase.Struct:
221 """Match sources in a reference tract catalog with a target catalog.
225 catalog_ref : `pandas.DataFrame` | `astropy.table.Table`
226 A reference catalog to match objects/sources from.
227 catalog_target : `pandas.DataFrame` | `astropy.table.Table`
228 A target catalog to match reference objects/sources to.
229 wcs : `lsst.afw.image.SkyWcs`
230 A coordinate system to convert catalog positions to sky coordinates.
231 Only needed if `config.coords_ref_to_convert` is used to convert
232 reference catalog sky coordinates to pixel positions.
233 kwargs : Additional keyword arguments to pass to `match`.
237 retStruct : `lsst.pipe.base.Struct`
238 A struct with output_ref and output_target attribute containing the
239 output matched catalogs, as well as a dict
242 is_ref_pd = isinstance(catalog_ref, pd.DataFrame)
243 is_target_pd = isinstance(catalog_target, pd.DataFrame)
245 catalog_ref.reset_index(inplace=
True)
247 catalog_target.reset_index(inplace=
True)
248 if is_ref_pd
or is_target_pd:
249 warnings.warn(
"pandas usage in MatchProbabilisticTask is deprecated; it will be removed "
250 " in favour of astropy.table after release 28.0.0", category=FutureWarning)
251 with warnings.catch_warnings():
253 warnings.filterwarnings(action=
"ignore", category=FutureWarning)
254 catalog_ref, catalog_target, exceptions = self.
match(
255 catalog_ref, catalog_target, wcs=wcs, **kwargs
258 return pipeBase.Struct(
259 cat_output_ref=catalog_ref,
260 cat_output_target=catalog_target,
261 exceptions=exceptions,