Пример #1
0
 def test_plot_offset(self):
     with mpl_plot_check():
         self.table_summary.plot_offset_distribution()
Пример #2
0
def test_plot_allsky():
    m = WcsNDMap.create(binsz=10 * u.deg)
    with mpl_plot_check():
        m.plot()
Пример #3
0
 def test_plot_background_rate(self):
     with mpl_plot_check():
         self.obs_summary.plot_background_rate()
Пример #4
0
 def test_plot_bias(self):
     with mpl_plot_check():
         self.edisp.plot_bias()
Пример #5
0
def test_plot_correlation(covariance_diagonal):
    with mpl_plot_check():
        covariance_diagonal.plot_correlation()
Пример #6
0
 def test_plot(self, flux_points):
     with mpl_plot_check():
         flux_points.plot()
Пример #7
0
 def test_plot_migration(self):
     with mpl_plot_check():
         self.edisp.plot_migration()
Пример #8
0
def test_map_fit(sky_model, geom, geom_etrue):
    dataset_1 = get_map_dataset(geom, geom_etrue, name="test-1")
    dataset_2 = get_map_dataset(geom, geom_etrue, name="test-2")
    datasets = Datasets([dataset_1, dataset_2])

    models = Models(datasets.models)
    models.insert(0, sky_model)

    models["test-1-bkg"].spectral_model.norm.value = 0.5
    models["test-model"].spatial_model.sigma.frozen = True

    datasets.models = models
    dataset_2.counts = dataset_2.npred()
    dataset_1.counts = dataset_1.npred()

    models["test-1-bkg"].spectral_model.norm.value = 0.49
    models["test-2-bkg"].spectral_model.norm.value = 0.99

    fit = Fit(datasets)
    result = fit.run()

    assert result.success
    assert "minuit" in repr(result)

    npred = dataset_1.npred().data.sum()
    assert_allclose(npred, 7525.790688, rtol=1e-3)
    assert_allclose(result.total_stat, 21625.845714, rtol=1e-3)

    pars = result.parameters
    assert_allclose(pars["lon_0"].value, 0.2, rtol=1e-2)
    assert_allclose(pars["lon_0"].error, 0.002244, rtol=1e-2)

    assert_allclose(pars["index"].value, 3, rtol=1e-2)
    assert_allclose(pars["index"].error, 0.024277, rtol=1e-2)

    assert_allclose(pars["amplitude"].value, 1e-11, rtol=1e-2)
    assert_allclose(pars["amplitude"].error, 4.216154e-13, rtol=1e-2)

    # background norm 1
    assert_allclose(pars[8].value, 0.5, rtol=1e-2)
    assert_allclose(pars[8].error, 0.015811, rtol=1e-2)

    # background norm 2
    assert_allclose(pars[11].value, 1, rtol=1e-2)
    assert_allclose(pars[11].error, 0.02147, rtol=1e-2)

    # test mask_safe evaluation
    dataset_1.mask_safe = geom.energy_mask(energy_min=1 * u.TeV)
    dataset_2.mask_safe = geom.energy_mask(energy_min=1 * u.TeV)

    stat = fit.datasets.stat_sum()
    assert_allclose(stat, 14823.772744, rtol=1e-5)

    region = sky_model.spatial_model.to_region()

    initial_counts = dataset_1.counts.copy()
    with mpl_plot_check():
        dataset_1.plot_residuals(kwargs_spectral=dict(region=region))

    # check dataset has not changed
    assert initial_counts == dataset_1.counts

    # test model evaluation outside image
    dataset_1.models[0].spatial_model.lon_0.value = 150
    dataset_1.npred()
    assert not dataset_1._evaluators["test-model"].contributes
Пример #9
0
def test_plot_constant_model():
    time_range = [Time.now(), Time.now() + 1 * u.d]
    constant_model = ConstantTemporalModel(const=1)
    with mpl_plot_check():
        constant_model.plot(time_range)
Пример #10
0
 def test_plot_gamma_rate(self):
     with mpl_plot_check():
         self.obs_summary.plot_gamma_rate()
Пример #11
0
def test_lightcurve_plot(lc):
    with mpl_plot_check():
        lc.plot()
Пример #12
0
 def test_plot_background(self):
     with mpl_plot_check():
         self.obs_summary.plot_background_vs_livetime()
Пример #13
0
 def test_plot_excess(self):
     with mpl_plot_check():
         self.obs_summary.plot_excess_vs_livetime()
Пример #14
0
 def test_plot_significance(self):
     with mpl_plot_check():
         self.obs_summary.plot_significance_vs_livetime()
Пример #15
0
    def test_plot_fit(self):
        dataset = self.dataset.copy()
        dataset.models = SkyModel(spectral_model=PowerLawSpectralModel())

        with mpl_plot_check():
            dataset.plot_fit()
Пример #16
0
 def test_peek(self, psf):
     with mpl_plot_check():
         psf.peek()
Пример #17
0
    def test_plot_off_regions(self):
        from gammapy.visualization import plot_spectrum_datasets_off_regions

        with mpl_plot_check():
            plot_spectrum_datasets_off_regions([self.dataset])
Пример #18
0
def test_psf_3d_plot_vs_rad(psf_3d):
    with mpl_plot_check():
        psf_3d.plot_psf_vs_rad()
Пример #19
0
 def test_plot_likelihood(self, flux_points_likelihood):
     with mpl_plot_check():
         flux_points_likelihood.plot_ts_profiles()
Пример #20
0
def test_psf_3d_plot_containment(psf_3d):
    with mpl_plot_check():
        psf_3d.plot_containment_radius()
Пример #21
0
 def test_plot_matrix(self):
     with mpl_plot_check():
         self.edisp.plot_matrix()
Пример #22
0
def test_psf_3d_peek(psf_3d):
    with mpl_plot_check():
        psf_3d.peek()
Пример #23
0
 def test_peek(self):
     with mpl_plot_check():
         self.edisp.peek()
Пример #24
0
def test_plot_allsky():
    axis = MapAxis([0, 1], node_type="edges")
    m = WcsNDMap.create(binsz=10 * u.deg, axes=[axis])
    with mpl_plot_check():
        m.plot()
Пример #25
0
def test_plot_grid():
    axis = MapAxis([0, 1, 2], node_type="edges")
    m = WcsNDMap.create(binsz=0.1 * u.deg, width=1 * u.deg, axes=[axis])
    with mpl_plot_check():
        m.plot_grid()
Пример #26
0
def test_plot_grid(geom_true):
    spatial_model = MyCustomGaussianModel(frame="galactic")
    with mpl_plot_check():
        spatial_model.plot_grid(geom=geom_true)
Пример #27
0
def test_plot_nan():
    m = Map.create(width=10, binsz=1)
    m.data += np.nan
    with mpl_plot_check():
        m.plot(add_cbar=False)
Пример #28
0
    def test_fp_dataset_plot_fit(fit):
        fp_dataset = fit.datasets[0]

        with mpl_plot_check():
            fp_dataset.plot_fit(kwargs_residuals=dict(method="diff/model"))
Пример #29
0
 def test_plot_zenith(self):
     with mpl_plot_check():
         self.table_summary.plot_zenith_distribution()
Пример #30
0
    def test_fp_dataset_plot_fit(dataset):

        with mpl_plot_check():
            dataset.plot_fit(kwargs_residuals=dict(method="diff/model"))