def test_get_order_plot_multi(make_data_path, clean_astro_ui):
    """Rather than fake data, use a known dataset.

    Here we pretend we have three orders but with the same
    response (except that the ARF is 0.5, 0.4, 0.25 of the
    normal ARF).
    """

    setup_order_plot(make_data_path)

    fplot = ui.get_fit_plot()
    oplot = ui.get_order_plot()

    # The idea is to compare the X range of plot_fit to plot_order
    # (but accessed just using the plot objects rather than creating
    # an actual plot).
    #
    # First some safety checks
    assert fplot.dataplot.xlo == pytest.approx(fplot.modelplot.xlo)
    assert fplot.dataplot.xhi == pytest.approx(fplot.modelplot.xhi)

    assert len(oplot.xlo) == 3
    assert len(oplot.xhi) == 3
    assert len(oplot.y) == 3

    assert oplot.xlo[1] == pytest.approx(oplot.xlo[0])
    assert oplot.xlo[2] == pytest.approx(oplot.xlo[0])

    assert oplot.xhi[1] == pytest.approx(oplot.xhi[0])
    assert oplot.xhi[2] == pytest.approx(oplot.xhi[0])

    # We know the y values are 0.5, 0.4, 0.25 times the original arf
    # so we can compare them.
    #
    assert oplot.y[1] == pytest.approx(oplot.y[0] * 0.4 / 0.5)
    assert oplot.y[2] == pytest.approx(oplot.y[0] * 0.25 / 0.5)

    xlo = oplot.xlo[0]
    xhi = oplot.xhi[0]
    assert len(xlo) == 564
    assert xlo[0] == pytest.approx(0.46720001101493835)
    assert xhi[-1] == pytest.approx(9.869600296020508)

    # The model plot is technically drawn the same way as the order plot
    # (ungrouped) but it uses different code (sherpa.astro.plot.ModelHistogram)
    # so let's compare.
    #
    mplot = ui.get_model_plot()
    assert mplot.xlo[0] == pytest.approx(0.46720001101493835)
    assert mplot.xhi[-1] == pytest.approx(9.869600296020508)

    # Also compare to the fit plot (which is grouped)
    #
    assert fplot.modelplot.xlo[0] == pytest.approx(0.46720001101493835)
    assert fplot.modelplot.xhi[-1] == pytest.approx(9.869600296020508)
Exemplo n.º 2
0
    def plot(self):
        '''Plot model with current parameters'''
        import sherpa.astro.ui as sherpa

        if self.xpa is None:
            import matplotlib.pylab as plt
            sherpa.plot_fit_delchi()
            plt.show()
            return

        plots = self.xpaget(self.xpa, "plot")  # Get a list of plots.

        plots.split(" ")
        newplot = ("dax_model_editor" not in plots)

        _f = sherpa.get_fit_plot()
        _d = _f.dataplot
        _m = _f.modelplot

        if _d.xerr is None:
            _d.xerr = (_d.x-_d.x)  # zeros
            
        if self.x_label is None:
            xlab = _f.dataplot.xlabel
        else:
            xlab = self.x_label

        if self.y_label is None:
            ylab = _f.dataplot.ylabel
        else:
            ylab = self.y_label

        import dax.dax_plot_utils as dax_plot

        if hasattr(_m, "xlo"):
            mx = list(_m.xlo)
            mx.append(_m.xhi[-1])
            my = list(_m.y)
            my.append(_m.y[-1])
            step = True
        else:
            mx = _m.x
            my = _m.y
            step = False

        dax_plot.blt_plot_model(self.xpa, mx, my,
                           "Dax Model Editor Plot",                            
                           xlab, ylab, step=step,
                           new=newplot, winname="dax_model_editor")

        dax_plot.blt_plot_data(self.xpa, _d.x, _d.xerr/2.0, _d.y, _d.yerr)

        delta = (_d.y-_m.y)/_d.yerr
        ones = _d.yerr*0.0+1.0
        dax_plot.blt_plot_delchisqr( self.xpa, _d.x, _d.xerr/2.0, delta, ones, "")
Exemplo n.º 3
0
def test_plot_order_multi(make_data_path, clean_astro_ui):
    """Rather than fake data, use a known dataset.

    Here we pretend we have three orders but with the same
    response (except that the ARF is 0.5, 0.4, 0.25 of the
    normal ARF).
    """

    pha = make_data_path('3c273.pi')
    ui.load_pha(pha)

    # It has already loaded in one response
    arf = ui.get_arf(resp_id=1)
    arf.specresp *= 0.5

    for order, scale in enumerate([0.4, 0.25], 2):
        ui.load_arf(make_data_path('3c273.arf'), resp_id=order)
        ui.load_rmf(make_data_path('3c273.rmf'), resp_id=order)

        arf = ui.get_arf(resp_id=order)
        arf.specresp *= scale

    ui.set_source(ui.powlaw1d.pl)

    ui.notice(0.5, 7)
    ui.ignore(3, 4)

    fplot = ui.get_fit_plot()
    oplot = ui.get_order_plot()

    # The idea is to compare the X range of plot_fit to plot_order
    # (but accessed just using the plot objects rather than creating
    # an actual plot).
    #
    # First some safety checks
    assert fplot.dataplot.xlo == pytest.approx(fplot.modelplot.xlo)
    assert fplot.dataplot.xhi == pytest.approx(fplot.modelplot.xhi)

    assert len(oplot.xlo) == 3
    assert len(oplot.xhi) == 3
    assert len(oplot.y) == 3

    assert oplot.xlo[1] == pytest.approx(oplot.xlo[0])
    assert oplot.xlo[2] == pytest.approx(oplot.xlo[0])

    assert oplot.xhi[1] == pytest.approx(oplot.xhi[0])
    assert oplot.xhi[2] == pytest.approx(oplot.xhi[0])

    # We know the y values are 0.5, 0.4, 0.25 times the original arf
    # so we can compare them.
    #
    assert oplot.y[1] == pytest.approx(oplot.y[0] * 0.4 / 0.5)
    assert oplot.y[2] == pytest.approx(oplot.y[0] * 0.25 / 0.5)

    xlo = oplot.xlo[0]
    xhi = oplot.xhi[0]
    assert len(xlo) == 564
    assert xlo[0] == pytest.approx(0.46720001101493835)
    assert xhi[-1] == pytest.approx(9.869600296020508)

    # The model plot is technically drawn the same way as the order plot
    # (ungrouped) but it uses different code (sherpa.astro.plot.ModelHistogram)
    # so let's compare.
    #
    mplot = ui.get_model_plot()
    assert mplot.xlo[0] == pytest.approx(0.46720001101493835)
    assert mplot.xhi[-1] == pytest.approx(9.869600296020508)

    # Also compare to the fit plot (which is grouped)
    #
    assert fplot.modelplot.xlo[0] == pytest.approx(0.46720001101493835)
    assert fplot.modelplot.xhi[-1] == pytest.approx(9.869600296020508)
Exemplo n.º 4
0
solver = BXASolver(id=id, prior=priorfunction, parameters=parameters)

solver.run(resume=True,
           verbose=True,
           n_live_points=args.num_live_points,
           outputfiles_basename=prefix,
           frac_remain=0.01,
           min_ess=1000)

if not os.path.exists('%sfit.json' % prefix):
    print('collecting fit plot data')
    set_analysis(id, 'ener', 'counts')
    group_adapt(id, 30)
    set_stat('chi2gehrels')
    pl = get_fit_plot(id)
    myplot = dict(counts=int(get_data(id).counts.sum()),
                  background_counts=int(get_bkg(id).counts.sum()),
                  data=pl.dataplot.y.tolist(),
                  dataerr=pl.dataplot.yerr.tolist(),
                  x=pl.dataplot.x.tolist(),
                  xerr=pl.dataplot.xerr.tolist(),
                  instances=[])
    for row in tqdm.tqdm(solver.results['samples']):
        for p, v in zip(parameters, row):
            p.val = v
        pl = get_fit_plot(id)
        myplot['instances'].append(pl.modelplot.y.tolist())

    srcnh.val = 20
    pl = get_fit_plot(id)