コード例 #1
0
    def wl_peak_counts(
        self,
        nbins: int,
        field_conversion: str,
        of: str = "orig",
        limits: Optional[tuple] = None,
    ) -> pd.DataFrame:
        """
        Signal peak counts. This is used commonly used in weak-lensing,
        but it doesn't need to stop there...
        """
        if field_conversion == "normalize":
            _map = self.data[of] - np.mean(self.skymap.data[of])
        else:
            _map = self.data[of]

        if limits is None:
            lower_bound = np.percentile(self.data[of],
                                        5)  # np.min(self.data[of])
            upper_bound = np.percentile(self.data[of],
                                        95)  # np.max(self.data[of])
        else:
            lower_bound = min(limits)
            upper_bound = max(limits)

        map_bins = np.arange(lower_bound, upper_bound,
                             (upper_bound - lower_bound) / nbins)
        _map = ConvergenceMap(data=_map, angle=self._opening_angle * un.deg)
        _kappa, _pos = _map.locatePeaks(map_bins)

        _hist, _kappa = np.histogram(_kappa, bins=nbins, density=False)
        _kappa = (_kappa[1:] + _kappa[:-1]) / 2
        peak_counts_dic = {"kappa": _kappa, "counts": _hist}
        peak_counts_df = pd.DataFrame(data=peak_counts_dic)
        return peak_counts_df
コード例 #2
0
    def from_sky(
        cls,
        skymap: Type[SkyArray],
        on: str,
        bin_dsc: dict,
        kernel_width: float = 5,
        direction: int = 1,
        filters: bool = True,
    ) -> "Dipoles":
        """
        Find peaks on the dipole signal map. It is assumed that the convergence maps
        were created with astrild.rays.visuals.map and filter with:
            I) high-pass II) DGD3 III) low-pass gaussian filters.

        Args:
            kernel_width: Smoothing kernel with [arcmin]
        Returns:
        """
        if filters is True:
            skymap = cls._filter(skymap, kernel_width, direction)

        thresholds = cls._get_convergence_thresholds(
            sky_array=skymap.data[bin_dsc["on"]], nbins=bin_dsc["nbins"])

        _map = ConvergenceMap(data=skymap.data[on],
                              angle=skymap.opening_angle * un.deg)
        deltaT, pos_deg = _map.locatePeaks(thresholds)
        deltaT, pos_deg = cls._remove_peaks_crossing_edge(
            skymap.npix, skymap.opening_angle, kernel_width, deltaT, pos_deg)
        assert len(deltaT) != 0, "No peaks"
        peak_dir = {
            "deltaT": deltaT,
            "x_deg": pos_deg[:, 0],
            "y_deg": pos_deg[:, 1],
        }

        # find significance of peaks
        peak_dir["snr"] = cls._signal_to_noise_ratio(peak_dir["deltaT"],
                                                     _map.data)
        peak_dir["x_pix"] = np.rint(peak_dir["x_deg"] * skymap.npix /
                                    skymap.opening_angle).astype(int)
        peak_dir["y_pix"] = np.rint(peak_dir["y_deg"] * skymap.npix /
                                    skymap.opening_angle).astype(int)
        peak_df = pd.DataFrame(data=peak_dir)
        # attrs is experimental and may change without warning.
        peak_df.attrs["map_file"] = skymap.map_file
        peak_df.attrs["filters"] = filters
        peak_df.attrs["kernel_width"] = kernel_width
        return cls.from_dataframe(peak_df)
コード例 #3
0
ファイル: tunnel.py プロジェクト: Christovis/astrild
    def find_peaks(
        self,
        on: str,
        field_conversion: str,
        thresholds_dsc: dict,
        snr_sigma: Optional[float] = None,
        save: bool = False,
    ) -> None:
        """
        Find peaks on convergence map. It is assumed that the convergence maps
        were created with astrild.rays.visuals.map and have appropriate
        smoothing and galaxy shape noise.

        Args:
        Returns:
        """
        self.on = on
        if field_conversion == "normalize":
            _map = self.skymap.data[on] - np.mean(self.skymap.data[on])
        else:
            _map = self.skymap.data[on]

        thresholds = self._get_convergence_thresholds(**thresholds_dsc)

        _map = ConvergenceMap(data=_map,
                              angle=self.skymap.opening_angle * un.deg)
        _peaks = {}
        _peaks["kappa"], _peaks["pos"] = _map.locatePeaks(thresholds)
        _peaks["kappa"], _peaks["pos"] = self._remove_peaks_crossing_edge(
            **_peaks)
        assert len(_peaks["kappa"]) != 0, "No peaks"

        # find significance of peaks
        _peaks["snr"] = self._signal_to_noise_ratio(_peaks["kappa"], _map.data,
                                                    snr_sigma)
        self.peaks = _peaks
        if save:
            # IO.save()
            pass