25import lsst.utils
as utils
26from .matcher_probabilistic
import MatchProbabilisticConfig, MatcherProbabilistic
31from typing
import Dict, 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"
50 return self.config.columns_in_ref
54 return self.config.columns_in_target
58 catalog_ref: pd.DataFrame,
59 catalog_target: pd.DataFrame,
60 select_ref: np.array =
None,
61 select_target: np.array =
None,
62 wcs: afwGeom.SkyWcs =
None,
63 logger: logging.Logger =
None,
64 logging_n_rows: int =
None,
65 ) -> Tuple[pd.DataFrame, pd.DataFrame, Dict[int, str]]:
66 """Match sources in a reference tract catalog with a target catalog.
70 catalog_ref : `pandas.DataFrame`
71 A reference catalog to match objects/sources from.
72 catalog_target : `pandas.DataFrame`
73 A target catalog to match reference objects/sources to.
74 select_ref : `numpy.array`
75 A boolean array of the same length
as `catalog_ref` selecting the sources that can be matched.
76 select_target : `numpy.array`
77 A boolean array of the same length
as `catalog_target` selecting the sources that can be matched.
78 wcs : `lsst.afw.image.SkyWcs`
79 A coordinate system to convert catalog positions to sky coordinates. Only used
if
80 `self.config.coords_ref_to_convert`
is set.
81 logger : `logging.Logger`
83 logging_n_rows : `int`
84 Number of matches to make before outputting incremental log message.
88 catalog_out_ref : `pandas.DataFrame`
89 Reference matched catalog
with indices of target matches.
90 catalog_out_target : `pandas.DataFrame`
91 Reference matched catalog
with indices of target matches.
98 if config.column_ref_order
is None:
99 flux_tot = np.nansum(catalog_ref.loc[:, config.columns_ref_flux].values, axis=1)
100 catalog_ref[
'flux_total'] = flux_tot
101 if config.mag_brightest_ref != -np.inf
or config.mag_faintest_ref != np.inf:
102 mag_tot = -2.5*np.log10(flux_tot) + config.coord_format.mag_zeropoint_ref
103 select_mag = (mag_tot >= config.mag_brightest_ref) & (
104 mag_tot <= config.mag_faintest_ref)
106 select_mag = np.isfinite(flux_tot)
107 if select_ref
is None:
108 select_ref = select_mag
110 select_ref &= select_mag
112 select_additional = (len(config.columns_target_select_true)
113 + len(config.columns_target_select_false)) > 0
114 if select_additional:
115 if select_target
is None:
116 select_target = np.ones(len(catalog_target), dtype=bool)
117 for column
in config.columns_target_select_true:
118 select_target &= catalog_target[column].values
119 for column
in config.columns_target_select_false:
120 select_target &= ~catalog_target[column].values
122 logger.info(
'Beginning MatcherProbabilistic.match with %d/%d ref sources selected vs %d/%d target',
123 np.sum(select_ref), len(select_ref), np.sum(select_target), len(select_target))
125 catalog_out_ref, catalog_out_target, exceptions = self.
matchermatcher.
match(
128 select_ref=select_ref,
129 select_target=select_target,
131 logging_n_rows=logging_n_rows,
133 radec_to_xy_func=radec_to_xy,
136 return catalog_out_ref, catalog_out_target, exceptions
138 @utils.timer.timeMethod
141 catalog_ref: pd.DataFrame,
142 catalog_target: pd.DataFrame,
143 wcs: afwGeom.SkyWcs =
None,
145 ) -> pipeBase.Struct:
146 """Match sources in a reference tract catalog with a target catalog.
150 catalog_ref : `pandas.DataFrame`
151 A reference catalog to match objects/sources from.
152 catalog_target : `pandas.DataFrame`
153 A target catalog to match reference objects/sources to.
154 wcs : `lsst.afw.image.SkyWcs`
155 A coordinate system to convert catalog positions to sky coordinates.
156 Only needed
if `config.coords_ref_to_convert`
is used to convert
157 reference catalog sky coordinates to pixel positions.
158 kwargs : Additional keyword arguments to
pass to `match`.
162 retStruct : `lsst.pipe.base.Struct`
163 A struct
with output_ref
and output_target attribute containing the
164 output matched catalogs,
as well
as a dict
166 catalog_ref.reset_index(inplace=True)
167 catalog_target.reset_index(inplace=
True)
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)
def radec_to_xy(ra_vec, dec_vec, factor, afwGeom.SkyWcs wcs)