Exemplo n.º 1
0
def test_get_bkg_plot(idval):
    """Basic testing of get_bkg_plot
    """

    setup_example_bkg(idval)
    if idval is None:
        bp = ui.get_bkg_plot()
    else:
        bp = ui.get_bkg_plot(idval)

    assert bp.x == pytest.approx(_data_chan)

    # normalise by exposure time and bin width, but bin width here
    # is 1 (because it is being measured in channels).
    #
    yexp = _data_bkg / 1201.0 / _bexpscale
    assert bp.y == pytest.approx(yexp)

    assert bp.title == 'example-bkg'
    assert bp.xlabel == 'Channel'
    assert bp.ylabel == 'Counts/sec/channel'
Exemplo n.º 2
0
def test_get_bkg_plot_energy(idval):
    """Basic testing of get_bkg_plot: energy
    """

    # The way I have set up the data means that set_analysis
    # doesn't seem to change the setting for the background,
    # which should be tracked down (Sep 2019) but not just now.
    #
    setup_example_bkg(idval)
    if idval is None:
        ui.set_analysis('energy')
        ui.get_bkg().units = 'energy'
        bp = ui.get_bkg_plot()
    else:
        ui.set_analysis(idval, 'energy')
        ui.get_bkg(idval).units = 'energy'
        bp = ui.get_bkg_plot(idval)

    # TODO: is this a bug in the plotting code, or does it just
    # indicate that the test hasn't set up the correct invariants
    # (which may be true as the code above has to change the units
    # setting of the background object)?
    #
    # I was expecting bp.x to return energy and not channel values
    #
    assert bp.x == pytest.approx(_data_chan)

    # normalise by exposure time and bin width, but bin width here
    # is 1 (because it is being measured in channels).
    #
    yexp = _data_bkg / 1201.0 / _bexpscale
    assert bp.y == pytest.approx(yexp)

    assert bp.title == 'example-bkg'
    assert bp.xlabel == 'Energy (keV)'
    assert bp.ylabel == 'Counts/sec/keV'
Exemplo n.º 3
0
Arquivo: qq.py Projeto: amasini90/BXA
def qq_export(id=None, bkg=False, outfile='qq.txt', elow=None, ehigh=None):
    """
	Export Q-Q plot into a file for plotting.

	:param id: spectrum id to use (see get_bkg_plot/get_data_plot)
	:param bkg: whether to use get_bkg_plot or get_data_plot
	:param outfile: filename to write results into
	:param elow: low energy limit
	:param ehigh: low energy limit

	Example::

		qq.qq_export('bg', outfile='my_bg_qq', elow=0.2, ehigh=10)

	"""
    # data
    d = ui.get_bkg_plot(id=id) if bkg else ui.get_data_plot(id=id)
    e = d.x
    mask = logical_and(e >= elow, e <= ehigh)
    data = d.y[mask].cumsum()
    d = ui.get_bkg_model_plot(id=id) if bkg else ui.get_model_plot(id=id)
    e = d.xlo
    mask = logical_and(e >= elow, e <= ehigh)
    e = e[mask]
    model = d.y[mask].cumsum()
    last_stat = ui.get_stat()
    ui.set_stat(ksstat)
    ks = ui.calc_stat()
    ui.set_stat(cvmstat)
    cvm = ui.calc_stat()
    ui.set_stat(adstat)
    ad = ui.calc_stat()
    ui.set_stat(last_stat)
    ad = ui.calc_stat()

    ui.set_stat('chi2gehrels')
    chi2 = ui.calc_stat()
    ui.set_stat('cstat')
    cstat = ui.calc_stat()
    ui.set_stat(last_stat)
    stats = dict(ks=ks, cvm=cvm, ad=ad, cstat=cstat, chi2=chi2)

    numpy.savetxt(outfile, numpy.transpose([e, data, model]))
    json.dump(stats, open(outfile + '.json', 'w'), indent=4)
Exemplo n.º 4
0
def qq_export(id=None, bkg=False, outfile='qq.txt', elow=None, ehigh=None):
	"""
	Export Q-Q plot into a file for plotting.

	:param id: spectrum id to use (see get_bkg_plot/get_data_plot)
	:param bkg: whether to use get_bkg_plot or get_data_plot
	:param outfile: filename to write results into
	:param elow: low energy limit
	:param ehigh: low energy limit

	Example::

		qq.qq_export('bg', outfile='my_bg_qq', elow=0.2, ehigh=10)
	"""
	# data
	d = ui.get_bkg_plot(id=id) if bkg else ui.get_data_plot(id=id)
	e = d.x
	mask = logical_and(e >= elow, e <= ehigh)
	data = d.y[mask].cumsum()
	d = ui.get_bkg_model_plot(id=id) if bkg else ui.get_model_plot(id=id)
	e = d.xlo
	mask = logical_and(e >= elow, e <= ehigh)
	e = e[mask]
	model = d.y[mask].cumsum()
	last_stat = ui.get_stat()
	ui.set_stat(ksstat)
	ks = ui.calc_stat()
	ui.set_stat(cvmstat)
	cvm = ui.calc_stat()
	ui.set_stat(adstat)
	ad = ui.calc_stat()
	ui.set_stat(last_stat)
	ad = ui.calc_stat()
	
	ui.set_stat('chi2gehrels')
	chi2 = ui.calc_stat()
	ui.set_stat('cstat')
	cstat = ui.calc_stat()
	ui.set_stat(last_stat)
	stats = dict(ks=ks, cvm=cvm, ad=ad, cstat=cstat, chi2=chi2)
	
	numpy.savetxt(outfile, numpy.transpose([e, data, model]))
	json.dump(stats, open(outfile + '.json', 'w'), indent=4)