コード例 #1
0
def test_init():
    significance = 0.1
    gross = False
    energy_bins = 10
    analysis = H0(significance=significance,
                  gross=gross,
                  energy_bins=energy_bins)

    np.testing.assert_equal(analysis.log_significance, np.log10(significance))
    np.testing.assert_equal(analysis.gross, gross)
    np.testing.assert_equal(analysis.triggers.shape, (0, energy_bins + 1))
コード例 #2
0
def test_zero_counts_gross():
    # accept all pvals
    significance = 1.0
    energy_bins = 10

    analysis = H0(significance=significance,
                  gross=True,
                  energy_bins=energy_bins)

    spectrum1 = np.zeros((10, ))
    spectrum2 = np.zeros((10, ))
    # run twice for initialization
    analysis.run_gross(spectrum1, 1)
    analysis.run_gross(spectrum2, 2)

    obs = analysis.triggers
    exp = np.array([[1.0, 0.0, 0.0, 0.0]])
    np.testing.assert_equal(obs, exp)
コード例 #3
0
def test_gross():
    stride = 10
    integration = 10

    # run handler script with analysis parameter
    analysis = H0()
    classifier = RadClass(stride,
                          integration,
                          test_data.datapath,
                          test_data.filename,
                          analysis=analysis)
    classifier.run_all()

    obs_timestamp = analysis.triggers[0][0]
    exp_timestamp = timestamps[-(rejected_H0_time + integration)]
    np.testing.assert_equal(obs_timestamp, exp_timestamp)
    # there should only be one rejected hypothesis
    obs_rows = analysis.triggers.shape[0]
    exp_rows = 1
    np.testing.assert_equal(obs_rows, exp_rows)
コード例 #4
0
def test_write_gross():
    stride = 10
    integration = 10
    filename = 'h0test_gross.csv'

    # run handler script with analysis parameter
    analysis = H0()
    classifier = RadClass(stride,
                          integration,
                          test_data.datapath,
                          test_data.filename,
                          analysis=analysis)
    classifier.run_all()
    analysis.write(filename)

    results = np.loadtxt(filename, delimiter=',')
    # expected shape is only 1D because only 1 entry is expected
    obs = results.shape
    exp = (4, )
    np.testing.assert_equal(obs, exp)

    os.remove(filename)
コード例 #5
0
def test_zero_counts_channel():
    # accept all pvals
    significance = 1.0
    energy_bins = 10

    analysis = H0(significance=significance,
                  gross=False,
                  energy_bins=energy_bins)

    spectrum1 = np.zeros((10, ))
    spectrum2 = np.zeros((10, ))
    spectrum2[0] = 100.0
    # run twice for initialization
    analysis.run_channels(spectrum1, 1)
    analysis.run_channels(spectrum2, 2)

    obs_pvals = analysis.triggers[0][1:]
    obs_ts = analysis.triggers[0][0]
    np.testing.assert_equal(obs_ts, 1)
    # only the first channel will have failed
    np.testing.assert_equal(np.count_nonzero(obs_pvals), 1)
    # check that the first channel alone is rejected
    np.testing.assert_equal(np.sum(obs_pvals), obs_pvals[0])
コード例 #6
0
def test_write_channel():
    stride = 10
    integration = 10
    filename = 'h0test_channel.csv'

    # run handler script with analysis parameter
    analysis = H0(gross=False, energy_bins=test_data.energy_bins)
    classifier = RadClass(stride,
                          integration,
                          test_data.datapath,
                          test_data.filename,
                          analysis=analysis)
    classifier.run_all()
    analysis.write(filename)

    results = np.loadtxt(filename, delimiter=',')
    # 1 extra columns are required for timestamp
    # expected shape is only 1D because only 1 entry is expected
    obs = results.shape
    exp = (test_data.energy_bins + 1, )
    np.testing.assert_equal(obs, exp)

    os.remove(filename)