25import lsst.utils
as utils
26from .matcher_probabilistic
import MatchProbabilisticConfig, MatcherProbabilistic
31from typing
import Dict, Set, Tuple
33__all__ = [
'MatchProbabilisticTask']
37 """Run MatchProbabilistic on a reference and target catalog covering the same tract.
39 ConfigClass = MatchProbabilisticConfig
40 _DefaultName = "matchProbabilistic"
52 catalog_ref: pd.DataFrame,
53 catalog_target: pd.DataFrame,
54 select_ref: np.array =
None,
55 select_target: np.array =
None,
56 wcs: afwGeom.SkyWcs =
None,
57 logger: logging.Logger =
None,
58 logging_n_rows: int =
None,
59 ) -> Tuple[pd.DataFrame, pd.DataFrame, Dict[int, str]]:
60 """Match sources in a reference tract catalog with a target catalog.
64 catalog_ref : `pandas.DataFrame`
65 A reference catalog to match objects/sources from.
66 catalog_target : `pandas.DataFrame`
67 A target catalog to match reference objects/sources to.
68 select_ref : `numpy.array`
69 A boolean array of the same length
as `catalog_ref` selecting the sources that can be matched.
70 select_target : `numpy.array`
71 A boolean array of the same length
as `catalog_target` selecting the sources that can be matched.
72 wcs : `lsst.afw.image.SkyWcs`
73 A coordinate system to convert catalog positions to sky coordinates. Only used
if
74 `self.config.coords_ref_to_convert`
is set.
75 logger : `logging.Logger`
77 logging_n_rows : `int`
78 Number of matches to make before outputting incremental log message.
82 catalog_out_ref : `pandas.DataFrame`
83 Reference matched catalog
with indices of target matches.
84 catalog_out_target : `pandas.DataFrame`
85 Reference matched catalog
with indices of target matches.
92 if config.column_order
is None:
93 flux_tot = np.nansum(catalog_ref.loc[:, config.columns_ref_flux].values, axis=1)
94 catalog_ref[
'flux_total'] = flux_tot
95 if config.mag_brightest_ref != -np.inf
or config.mag_faintest_ref != np.inf:
96 mag_tot = -2.5 * np.log10(flux_tot) + config.mag_zeropoint_ref
97 select_mag = (mag_tot >= config.mag_brightest_ref) & (
98 mag_tot <= config.mag_faintest_ref)
100 select_mag = np.isfinite(flux_tot)
101 if select_ref
is None:
102 select_ref = select_mag
104 select_ref &= select_mag
106 if config.coords_ref_to_convert:
107 ra_ref, dec_ref = [catalog_ref[column]
for column
in config.coords_ref_to_convert.keys()]
108 factor = config.coords_ref_factor
110 for ra, dec
in zip(ra_ref, dec_ref)]
111 xy_true = wcs.skyToPixel(radec_true)
113 for idx_coord, column_out
in enumerate(config.coords_ref_to_convert.values()):
114 catalog_ref[column_out] = np.array([xy[idx_coord]
for xy
in xy_true])
116 select_additional = (len(config.columns_target_select_true)
117 + len(config.columns_target_select_false)) > 0
118 if select_additional:
119 if select_target
is None:
120 select_target = np.ones(len(catalog_target), dtype=bool)
121 for column
in config.columns_target_select_true:
122 select_target &= catalog_target[column].values
123 for column
in config.columns_target_select_false:
124 select_target &= ~catalog_target[column].values
126 logger.info(
'Beginning MatcherProbabilistic.match with %d/%d ref sources selected vs %d/%d target',
127 np.sum(select_ref), len(select_ref), np.sum(select_target), len(select_target))
129 catalog_out_ref, catalog_out_target, exceptions = self.
matchermatcher.
match(
132 select_ref=select_ref,
133 select_target=select_target,
135 logging_n_rows=logging_n_rows,
138 return catalog_out_ref, catalog_out_target, exceptions
140 @utils.timer.timeMethod
143 catalog_ref: pd.DataFrame,
144 catalog_target: pd.DataFrame,
145 wcs: afwGeom.SkyWcs =
None,
147 ) -> pipeBase.Struct:
148 """Match sources in a reference tract catalog with a target catalog.
152 catalog_ref : `pandas.DataFrame`
153 A reference catalog to match objects/sources from.
154 catalog_target : `pandas.DataFrame`
155 A target catalog to match reference objects/sources to.
156 wcs : `lsst.afw.image.SkyWcs`
157 A coordinate system to convert catalog positions to sky coordinates.
158 Only needed
if `config.coords_ref_to_convert`
is used to convert
159 reference catalog sky coordinates to pixel positions.
160 kwargs : Additional keyword arguments to
pass to `match`.
164 retStruct : `lsst.pipe.base.Struct`
165 A struct
with output_ref
and output_target attribute containing the
166 output matched catalogs,
as well
as a dict
168 catalog_ref, catalog_target, exceptions = self.matchmatch(catalog_ref, catalog_target, wcs=wcs, **kwargs)
169 return pipeBase.Struct(cat_output_ref=catalog_ref, cat_output_target=catalog_target,
170 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)
Set[str] columns_in_ref(self)