Пример #1
0
def test_resolution_per_bin():
    # For a normal distribution, the resolution at `percentile=68.27` is equal to 1 sigma
    size = 1000000
    loc = np.random.rand() * 100
    scale = np.random.rand() * 10
    x = np.linspace(0, 10, size)
    y_true = loc * np.ones(size)
    y_reco = np.random.normal(loc=loc, scale=scale, size=size)
    for scaling in ['s0', 's1', 's2', 's3', 's4']:
        bins, res = ana.resolution_per_bin(x,
                                           y_true,
                                           y_reco,
                                           bins=6,
                                           relative_scaling_method=scaling)
        np.testing.assert_allclose(
            res[:, 0],
            scale / ana.relative_scaling(y_true, y_reco, scaling).mean(),
            rtol=1e-1)

    bias = 50
    y_reco = np.random.normal(loc=loc + bias, scale=scale, size=size)
    bins, res = ana.resolution_per_bin(x, y_true, y_reco, bias_correction=True)
    np.testing.assert_allclose(res[:, 0],
                               scale /
                               ana.relative_scaling(y_true, y_reco).mean(),
                               rtol=1e-1)
Пример #2
0
def test_plot_resolution_difference():
    from ctaplot.ana.ana import resolution_per_bin, irf_cta
    size = 1000
    simu = np.logspace(-2, 2, size)
    reco = 2 * simu
    reco2 = 3 * simu
    irf = irf_cta()
    bin = irf.E_bin
    bins, res1 = resolution_per_bin(simu,
                                    simu,
                                    reco,
                                    bins=bin,
                                    relative_scaling_method='s1')
    bins, res2 = resolution_per_bin(simu,
                                    simu,
                                    reco2,
                                    bins=bin,
                                    relative_scaling_method='s1')
    plots.plot_resolution_difference(bins,
                                     res1,
                                     res2,
                                     ax=None,
                                     color='red',
                                     alpha=0.8,
                                     label='nice diff')
Пример #3
0
def test_plot_resolution():
    x = np.linspace(0, 10, 1000)
    y_true = 0.5 + np.random.rand(1000)
    y_reco = np.random.normal(loc=1, size=1000)
    from ctaplot.ana.ana import resolution_per_bin
    bins, res = resolution_per_bin(x, y_true, y_reco)
    plots.plot_resolution(bins, res, color='black')
Пример #4
0
def test_resolution_per_bin_empty():
    '''
    testing for empty bins
    '''
    # For a normal distribution, the resolution at `percentile=68.27` is equal to 1 sigma
    size = 1000000
    loc = np.random.rand() * 100
    scale = np.random.rand() * 10
    x = np.linspace(0, 10, size)
    bins = np.array([1, 2, 3, 5, 11, 15])
    y_true = loc * np.ones(size)
    y_reco = np.random.normal(loc=loc, scale=scale, size=size)
    for scaling in ['s0', 's1', 's2', 's3', 's4']:
        bins, res = ana.resolution_per_bin(x,
                                           y_true,
                                           y_reco,
                                           bins=bins,
                                           relative_scaling_method=scaling,
                                           bias_correction=True)
        v = scale / ana.relative_scaling(y_true, y_reco, scaling).mean()
        expected_res = np.array([v, v, v, v, 0])
        np.testing.assert_allclose(res[:, 0], expected_res, rtol=1e-1)