Example #1
0
 def setup(self):
     self.kernels_new = CWTKernels(n_scale=2,
                                   min_scale=3.0,
                                   step_scale=2.6,
                                   old=False)
     self.kernels_old = CWTKernels(n_scale=2,
                                   min_scale=3.0,
                                   step_scale=2.6,
                                   old=True)
Example #2
0
    def setup(self):
        filename = "$GAMMAPY_DATA/tests/unbundled/poisson_stats_image/counts.fits.gz"
        image = Map.read(filename)
        background = image.copy(data=np.ones(image.data.shape, dtype=float))

        self.kernels = CWTKernels(n_scale=2,
                                  min_scale=3.0,
                                  step_scale=2.6,
                                  old=False)
        self.data = dict(image=image, background=background)
        self.cwt = CWT(kernels=self.kernels,
                       significance_threshold=2.0,
                       keep_history=True)
Example #3
0
def run_cwt():
    data = make_poisson_data()

    cwt_kernels = CWTKernels(n_scale=2,
                             min_scale=3.0,
                             step_scale=2.6,
                             old=False)
    cwt = CWT(kernels=cwt_kernels,
              significance_threshold=2.,
              keep_history=True)
    cwt_data = CWTData(counts=data['image'],
                       background=data['background'],
                       n_scale=cwt_kernels.n_scale)

    cwt.analyze(data=cwt_data)
    return cwt_data
Example #4
0
class TestCWTKernels:
    """Test CWTKernels"""
    def setup(self):
        self.kernels_new = CWTKernels(n_scale=2,
                                      min_scale=3.0,
                                      step_scale=2.6,
                                      old=False)
        self.kernels_old = CWTKernels(n_scale=2,
                                      min_scale=3.0,
                                      step_scale=2.6,
                                      old=True)

    def test_info(self):
        info_dict = self.kernels_new._info()
        assert_allclose(info_dict["Minimal scale"], self.kernels_new.min_scale)
        assert_allclose(info_dict["Kernels approx sum"], 0.99988318386)
        assert_allclose(info_dict["Kernels approx max"], 0.000386976177431)

    def test_cwt_kernels_new(self):
        assert_allclose(self.kernels_new.scales, [3.0, 7.8])
        assert_allclose(self.kernels_new.kern_approx.sum(), 0.99988318386)
        assert_allclose(self.kernels_new.kern_approx.max(), 0.000386976177431)
        assert_allclose(self.kernels_new.kern_base[0].sum(), 3.01663209714e-05)
        assert_allclose(self.kernels_new.kern_base[0].max(), 8.59947060958e-05)
        assert_allclose(self.kernels_new.kern_base[1].sum(), 4.84548284275e-06)
        assert_allclose(self.kernels_new.kern_base[1].max(), 1.88182106053e-06)

    def test_cwt_kernels_old(self):
        assert_allclose(self.kernels_old.scales, [3.0, 7.8])
        assert_allclose(self.kernels_old.kern_approx.sum(), 0.99988318386)
        assert_allclose(self.kernels_old.kern_approx.max(), 0.000386976177431)
        assert_allclose(self.kernels_old.kern_base[0].sum(), 0.000207093150419)
        assert_allclose(self.kernels_old.kern_base[0].max(), 0.0150679236063)
        assert_allclose(self.kernels_old.kern_base[1].sum(), 0.000146764160432)
        assert_allclose(self.kernels_old.kern_base[1].max(), 0.002228982782)

    def test_info_table(self):
        t = self.kernels_new.info_table
        assert_equal(t.colnames, ["Name", "Source"])
        assert_equal(len(t), 13)
Example #5
0
# In[ ]:


# Input parameters for CWTKernels
N_SCALE = 2  # Number of scales considered.
MIN_SCALE = 6.  # First scale used.
STEP_SCALE = 1.3  # Base scaling factor.


# In[ ]:


from gammapy.detect import CWTKernels

cwt_kernels = CWTKernels(
    n_scale=N_SCALE, min_scale=MIN_SCALE, step_scale=STEP_SCALE
)
print(cwt_kernels.info_table)


# Other parameters are optional, in this demonstration define them all.

# In[ ]:


MAX_ITER = 10  # The maximum number of iterations of the CWT algorithm.
TOL = 1e-5  # Tolerance for stopping criterion.
SIGNIFICANCE_THRESHOLD = 2.  # Measure of statistical significance.
SIGNIFICANCE_ISLAND_THRESHOLD = (
    None
)  # Measure is used for cleaning of isolated pixel islands.