25import lsst.utils
as utils
26from .matcher_probabilistic
import MatchProbabilisticConfig, MatcherProbabilistic
31from typing
import Dict, List, Optional, Set, Tuple
33__all__ = [
'MatchProbabilisticTask',
'radec_to_xy']
38 for ra, dec
in zip(ra_vec, dec_vec)]
39 return wcs.skyToPixel(radec_true)
43 """Run MatchProbabilistic on a reference and target catalog covering the same tract.
45 ConfigClass = MatchProbabilisticConfig
46 _DefaultName = "matchProbabilistic"
49 def _apply_select_bool(
50 catalog: pd.DataFrame,
51 columns_true: List[str],
52 columns_false: List[str],
53 selection: Optional[np.array],
55 """ Apply additional boolean selection columns.
57 catalog : `pandas.DataFrame`
58 The catalog to select from.
59 columns_true : `list` [`str`]
60 Columns that must be
True for selection.
61 columns_false : `list` [`str`]
62 Columns that must be
False for selection.
63 selection : `numpy.array`
64 A prior selection array. Default all true.
68 selection : `numpy.array`
69 The final selection array.
72 select_additional = (len(columns_true) + len(columns_false)) > 0
75 selection = np.ones(len(catalog), dtype=bool)
76 for column
in columns_true:
77 selection &= catalog[column].values
78 for column
in columns_false:
79 selection &= ~catalog[column].values
84 return self.config.columns_in_ref
88 return self.config.columns_in_target
92 catalog_ref: pd.DataFrame,
93 catalog_target: pd.DataFrame,
94 select_ref: np.array =
None,
95 select_target: np.array =
None,
96 wcs: afwGeom.SkyWcs =
None,
97 logger: logging.Logger =
None,
98 logging_n_rows: int =
None,
99 ) -> Tuple[pd.DataFrame, pd.DataFrame, Dict[int, str]]:
100 """Match sources in a reference tract catalog with a target catalog.
104 catalog_ref : `pandas.DataFrame`
105 A reference catalog to match objects/sources from.
106 catalog_target : `pandas.DataFrame`
107 A target catalog to match reference objects/sources to.
108 select_ref : `numpy.array`
109 A boolean array of the same length
as `catalog_ref` selecting the sources that can be matched.
110 select_target : `numpy.array`
111 A boolean array of the same length
as `catalog_target` selecting the sources that can be matched.
112 wcs : `lsst.afw.image.SkyWcs`
113 A coordinate system to convert catalog positions to sky coordinates. Only used
if
114 `self.config.coords_ref_to_convert`
is set.
115 logger : `logging.Logger`
116 A Logger
for logging.
117 logging_n_rows : `int`
118 Number of matches to make before outputting incremental log message.
122 catalog_out_ref : `pandas.DataFrame`
123 Reference matched catalog
with indices of target matches.
124 catalog_out_target : `pandas.DataFrame`
125 Reference matched catalog
with indices of target matches.
132 if config.column_ref_order
is None:
133 flux_tot = np.nansum(catalog_ref.loc[:, config.columns_ref_flux].values, axis=1)
134 catalog_ref[
'flux_total'] = flux_tot
135 if config.mag_brightest_ref != -np.inf
or config.mag_faintest_ref != np.inf:
136 mag_tot = -2.5*np.log10(flux_tot) + config.coord_format.mag_zeropoint_ref
137 select_mag = (mag_tot >= config.mag_brightest_ref) & (
138 mag_tot <= config.mag_faintest_ref)
140 select_mag = np.isfinite(flux_tot)
141 if select_ref
is None:
142 select_ref = select_mag
144 select_ref &= select_mag
148 columns_true=config.columns_ref_select_true,
149 columns_false=config.columns_ref_select_false,
153 catalog=catalog_target,
154 columns_true=config.columns_target_select_true,
155 columns_false=config.columns_target_select_false,
156 selection=select_target
159 logger.info(
'Beginning MatcherProbabilistic.match with %d/%d ref sources selected vs %d/%d target',
160 np.sum(select_ref), len(select_ref), np.sum(select_target), len(select_target))
162 catalog_out_ref, catalog_out_target, exceptions = self.
matcher.
match(
165 select_ref=select_ref,
166 select_target=select_target,
168 logging_n_rows=logging_n_rows,
170 radec_to_xy_func=radec_to_xy,
173 return catalog_out_ref, catalog_out_target, exceptions
175 @utils.timer.timeMethod
178 catalog_ref: pd.DataFrame,
179 catalog_target: pd.DataFrame,
180 wcs: afwGeom.SkyWcs =
None,
182 ) -> pipeBase.Struct:
183 """Match sources in a reference tract catalog with a target catalog.
187 catalog_ref : `pandas.DataFrame`
188 A reference catalog to match objects/sources from.
189 catalog_target : `pandas.DataFrame`
190 A target catalog to match reference objects/sources to.
191 wcs : `lsst.afw.image.SkyWcs`
192 A coordinate system to convert catalog positions to sky coordinates.
193 Only needed
if `config.coords_ref_to_convert`
is used to convert
194 reference catalog sky coordinates to pixel positions.
195 kwargs : Additional keyword arguments to
pass to `match`.
199 retStruct : `lsst.pipe.base.Struct`
200 A struct
with output_ref
and output_target attribute containing the
201 output matched catalogs,
as well
as a dict
203 catalog_ref.reset_index(inplace=True)
204 catalog_target.reset_index(inplace=
True)
205 catalog_ref, catalog_target, exceptions = self.
match(catalog_ref, catalog_target, wcs=wcs, **kwargs)
206 return pipeBase.Struct(cat_output_ref=catalog_ref, cat_output_target=catalog_target,
207 exceptions=exceptions)
pipeBase.Struct run(self, pd.DataFrame catalog_ref, pd.DataFrame catalog_target, afwGeom.SkyWcs wcs=None, **kwargs)
Tuple[pd.DataFrame, pd.DataFrame, Dict[int, str]] match(self, pd.DataFrame catalog_ref, pd.DataFrame catalog_target, np.array select_ref=None, np.array select_target=None, afwGeom.SkyWcs wcs=None, logging.Logger logger=None, int logging_n_rows=None)
def __init__(self, **kwargs)
Set[str] columns_in_target(self)
np.array _apply_select_bool(pd.DataFrame catalog, List[str] columns_true, List[str] columns_false, Optional[np.array] selection)
Set[str] columns_in_ref(self)
def radec_to_xy(ra_vec, dec_vec, factor, afwGeom.SkyWcs wcs)