コード例 #1
0
ファイル: test_specInterface.py プロジェクト: op3/hdtv
def test_cmd_spectrum_write(fmt, temp_file, suffix=""):
    assert len(s.spectra.dict) == 0
    hdtvcmd("spectrum get {}".format(testspectrum))
    assert len(s.spectra.dict) == 1
    f, ferr = hdtvcmd("spectrum write {} {}{}".format(temp_file, fmt, suffix))
    assert "Wrote spectrum with id 0 to file {}".format(temp_file) in f
    assert os.path.getsize(temp_file) > 0
コード例 #2
0
ファイル: test_specInterface.py プロジェクト: op3/hdtv
def test_cmd_spectrum_list(numspecs):
    assert len(s.spectra.dict) == 0
    for _ in range(numspecs):
        hdtvcmd("spectrum get {}".format(testspectrum))
    f, ferr = hdtvcmd("spectrum list")
    assert len(s.spectra.dict) == numspecs
    assert len(f.split("\n")) == numspecs + 2
コード例 #3
0
def test_cmd_cal_eff_read_cov(parfile, covfile, efffunction):
    hdtvcmd("calibration efficiency set {}".format(efffunction))
    hdtvcmd("calibration efficiency read parameter {}".format(parfile))
    f, ferr = hdtvcmd(
        "calibration efficiency read covariance {}".format(covfile))
    assert ferr == ""
    assert f == ""
コード例 #4
0
def test_cmd_cal_pos_recalibrate():
    hdtvcmd("fit peakfind -a -t 0.005")
    hdtvcmd("fit position assign 3.0 1173.228(3) 5.0 1332.492(4)")
    f, ferr = hdtvcmd("calibration position recalibrate")
    assert ferr == ""
    assert "Calibrated spectrum with id 0" in f
    assert "Chi" in f
コード例 #5
0
ファイル: test_specInterface.py プロジェクト: op3/hdtv
def test_cmd_spectrum_write_invalid_format(temp_file):
    assert len(s.spectra.dict) == 0
    hdtvcmd("spectrum get {}".format(testspectrum))
    assert len(s.spectra.dict) == 1
    f, ferr = hdtvcmd("spectrum write {} invalid 0".format(temp_file))
    assert os.path.getsize(temp_file) == 0
    assert "Failed to write spectrum: Invalid format specified" in ferr
コード例 #6
0
ファイル: test_fitmap.py プロジェクト: op3/hdtv-unattached
def test_cmd_fit_position():
    spec_interface.tv.specIf.LoadSpectra(testspectrum, None)
    hdtvcmd("fit peakfind -a -t 0.05")
    f, ferr = hdtvcmd(
        "fit position assign 10.0 1173.228(3) 12.0 1332.492(4)",
        "fit position erase 10.0 12.0")
    assert ferr == ""
コード例 #7
0
ファイル: test_dblookup.py プロジェクト: op3/hdtv-unattached
def test_cmd_db_lookup_base():
    f, ferr = hdtvcmd("db lookup")
    assert "usage" in f
    assert "arguments" in ferr

    f, ferr = hdtvcmd("db lookup 0")
    assert ferr == ""
    assert "Found 0 results" in f
コード例 #8
0
ファイル: test_specInterface.py プロジェクト: op3/hdtv
def test_cmd_spectrum_calbin_root_tv(parameter):
    assert len(s.spectra.dict) == 0
    hdtvcmd("spectrum get {}".format(testspectrum))
    assert len(s.spectra.dict) == 1

    with warnings.catch_warnings(record=True) as w:
        f, ferr = hdtvcmd("spectrum calbin {} 0".format(parameter))
        assert "Calbinning 0 with binsize=" in f
コード例 #9
0
ファイル: test_specInterface.py プロジェクト: op3/hdtv
def test_cmd_spectrum_delete_all(numspecs):
    assert len(s.spectra.dict) == 0
    for _ in range(numspecs):
        hdtvcmd("spectrum get {}".format(testspectrum))
    assert len(s.spectra.dict) == numspecs

    hdtvcmd("spectrum delete all")
    assert len(s.spectra.dict) == 0
コード例 #10
0
ファイル: test_specInterface.py プロジェクト: op3/hdtv
def test_cmd_spectrum_delete_none():
    assert len(s.spectra.dict) == 0
    hdtvcmd("spectrum get {}".format(testspectrum))
    assert len(s.spectra.dict) == 1

    f, ferr = hdtvcmd("spectrum delete")
    assert "WARNING: Nothing to do" in ferr
    assert len(s.spectra.dict) == 1
コード例 #11
0
ファイル: test_specInterface.py プロジェクト: op3/hdtv
def test_cmd_spectrum_calbin_spline_order(spline_order):
    assert len(s.spectra.dict) == 0
    hdtvcmd("spectrum get {}".format(testspectrum))
    assert len(s.spectra.dict) == 1

    with warnings.catch_warnings(record=True) as w:
        f, ferr = hdtvcmd("spectrum calbin -k {} 0".format(spline_order))
        assert "Calbinning 0 with" in f
コード例 #12
0
ファイル: test_specInterface.py プロジェクト: op3/hdtv
def test_cmd_spectrum_resample():
    assert len(s.spectra.dict) == 0
    hdtvcmd("spectrum get {}".format(testspectrum))
    assert len(s.spectra.dict) == 1

    with warnings.catch_warnings(record=True) as w:
        f, ferr = hdtvcmd("spectrum resample 0")
        assert "Total area changed by" in f
コード例 #13
0
ファイル: test_specInterface.py プロジェクト: op3/hdtv
def test_cmd_spectrum_copy(copy, matches):
    assert len(s.spectra.dict) == 0
    for _ in range(3):
        hdtvcmd("spectrum get {}".format(testspectrum))
    assert len(s.spectra.dict) == 3
    f, ferr = hdtvcmd("spectrum copy {}".format(copy))
    for match in matches:
        assert "Copied spectrum {}".format(match) in f
コード例 #14
0
ファイル: test_specInterface.py プロジェクト: op3/hdtv
def test_cmd_spectrum_delete_several(numspecs):
    assert len(s.spectra.dict) == 0
    for _ in range(numspecs):
        hdtvcmd("spectrum get {}".format(testspectrum))
    assert len(s.spectra.dict) == numspecs

    specs = " ".join(str(e) for e in range(numspecs))
    hdtvcmd("spectrum delete {}".format(specs))
    assert len(s.spectra.dict) == 0
コード例 #15
0
ファイル: test_specInterface.py プロジェクト: op3/hdtv
def test_cmd_spectrum_normalize():
    assert len(s.spectra.dict) == 0
    for _ in range(3):
        hdtvcmd("spectrum get {}".format(testspectrum))
    assert len(s.spectra.dict) == 3
    for specids, norm in [("0", 0.3), ("0 1 2", 0.2)]:
        hdtvcmd("spectrum normalize {} {}".format(specids, norm))
        assert get_spec(0).norm == norm
    assert get_spec(2).norm == 0.2
コード例 #16
0
ファイル: test_specInterface.py プロジェクト: op3/hdtv
def test_cmd_spectrum_info():
    assert len(s.spectra.dict) == 0
    hdtvcmd("spectrum get {}".format(testspectrum))
    assert len(s.spectra.dict) == 1

    f, ferr = hdtvcmd("spectrum info")
    assert ferr == ""
    # If lots of stuff is printed, `spectrum info` is doing its job.
    assert len(f.split("\n")) == 9
コード例 #17
0
ファイル: test_specInterface.py プロジェクト: op3/hdtv
def test_cmd_spectrum_delete():
    assert len(s.spectra.dict) == 0
    f, ferr = hdtvcmd("spectrum get {}".format(testspectrum))
    res_specfile, specid = re.search(r"Loaded (.*) into (\d+)", f).groups()

    assert len(s.spectra.dict) == 1

    f, ferr = hdtvcmd("spectrum delete {}".format(specid))
    assert len(s.spectra.dict) == 0
コード例 #18
0
ファイル: test_specInterface.py プロジェクト: op3/hdtv
def test_cmd_spectrum_rebin(ngroup):
    assert len(s.spectra.dict) == 0
    hdtvcmd("spectrum get {}".format(testspectrum))
    assert len(s.spectra.dict) == 1

    with warnings.catch_warnings(record=True) as w:
        f, ferr = hdtvcmd("spectrum rebin 0 {}".format(ngroup))
        assert "Rebinning 0 with {} bins per new bin".format(ngroup) in f
        assert get_spec(0).hist.hist.GetNbinsX() == 8192 // ngroup
コード例 #19
0
ファイル: test_specInterface.py プロジェクト: op3/hdtv
def test_cmd_spectrum_calbin_calibrated():
    assert len(s.spectra.dict) == 0
    hdtvcmd("spectrum get {}".format(testspectrum))
    assert len(s.spectra.dict) == 1
    hdtvcmd("calibration position set 5 2.2".format(testspectrum))

    with warnings.catch_warnings(record=True) as w:
        f, ferr = hdtvcmd("spectrum calbin -d 0")
        assert "Calbinning 0 with" in f
コード例 #20
0
ファイル: test_specInterface.py プロジェクト: op3/hdtv
def test_cmd_spectrum_calbin_binsize(binsize):
    assert len(s.spectra.dict) == 0
    hdtvcmd("spectrum get {}".format(testspectrum))
    assert len(s.spectra.dict) == 1

    with warnings.catch_warnings(record=True) as w:
        f, ferr = hdtvcmd("spectrum calbin -b {} 0".format(binsize))
        assert "Calbinning 0 with binsize={}".format(binsize) in f
        assert get_spec(0).hist.hist.GetNbinsX() == int(ceil(
            8191 / binsize)) + 1
コード例 #21
0
ファイル: test_specInterface.py プロジェクト: op3/hdtv
def test_cmd_spectrum_subtract(specfile0, specfile1):
    assert len(s.spectra.dict) == 0
    hdtvcmd("spectrum get {}".format(specfile0))
    hdtvcmd("spectrum get {}".format(specfile1))
    assert len(s.spectra.dict) == 2
    spec0_count = get_spec(0).hist.hist.GetSum()
    spec1_count = get_spec(1).hist.hist.GetSum()
    f, ferr = hdtvcmd("spectrum subtract 0 1")
    assert "Subtracting 1 from 0" in f
    new_count = get_spec(0).hist.hist.GetSum()
    assert spec0_count - spec1_count - new_count < 0.00001 * spec0_count
コード例 #22
0
ファイル: test_specInterface.py プロジェクト: op3/hdtv
def test_cmd_spectrum_add_normalize(specfile0, specfile1):
    assert len(s.spectra.dict) == 0
    hdtvcmd("spectrum get {}".format(specfile0))
    hdtvcmd("spectrum get {}".format(specfile1))
    assert len(s.spectra.dict) == 2
    spec0_count = get_spec(0).hist.hist.GetSum()
    spec1_count = get_spec(1).hist.hist.GetSum()
    f, ferr = hdtvcmd("spectrum add -n 2 0 1")
    assert "Adding 0 to 2" in f
    spec2_count = get_spec(2).hist.hist.GetSum()
    assert spec0_count + spec1_count - 2 * spec2_count < 0.00001 * spec2_count
コード例 #23
0
ファイル: test_specInterface.py プロジェクト: op3/hdtv
def test_cmd_spectrum_multiply(factor, specids, response):
    assert len(s.spectra.dict) == 0
    for _ in range(3):
        hdtvcmd("spectrum get {}".format(testspectrum))
    assert len(s.spectra.dict) == 3
    orig_count = get_spec(0).hist.hist.GetSum()
    f, ferr = hdtvcmd("spectrum multiply {} {}".format(specids, factor))
    for spec in response:
        assert "Multiplying {} with {}".format(spec, factor) in f
    new_count = get_spec(0).hist.hist.GetSum()
    assert orig_count * factor - new_count < 0.00001 * new_count
コード例 #24
0
ファイル: test_specInterface.py プロジェクト: op3/hdtv
def test_cmd_spectrum_activate_multi(numspecs):
    assert len(s.spectra.dict) == 0
    for _ in range(numspecs):
        hdtvcmd("spectrum get {}".format(testspectrum))
    assert len(s.spectra.dict) == numspecs

    f, ferr = hdtvcmd("spectrum activate all")
    if numspecs > 1:
        assert "Can only activate one spectrum" in ferr
    else:
        assert "" == ferr
        assert "" == f
コード例 #25
0
def test_cmd_spectrum_hide(numspecs):
    numhidespecs = max(1, numspecs // 2)
    assert len(s.spectra.dict) == 0
    for _ in range(numspecs):
        hdtvcmd("spectrum get {}".format(testspectrum))
    assert len(s.spectra.dict) == numspecs

    specs = ' '.join(str(e) for e in range(numhidespecs))
    hdtvcmd("spectrum hide {}".format(specs))

    f, ferr = hdtvcmd("spectrum list -v")
    assert len(s.spectra.dict) == numspecs
    assert len(f.split('\n')) == numspecs - numhidespecs + 2
コード例 #26
0
ファイル: test_dblookup.py プロジェクト: op3/hdtv-unattached
def test_cmd_db_lookup_sort_key(specs, reverse=False):
    if reverse:
        f, ferr = hdtvcmd("db lookup {} -k energy -r".format(specs))
    else:
        f, ferr = hdtvcmd("db lookup {} -k energy".format(specs))
    old_value = sys.float_info.max if reverse else sys.float_info.min
    for line in f.split('\n')[2:-3]:
        new_value = float(line.split("|")[3].split("(")[0].strip())
        if reverse:
            assert new_value < old_value
        else:
            assert new_value > old_value
        old_value = new_value
コード例 #27
0
ファイル: test_specInterface.py プロジェクト: op3/hdtv
def test_cmd_spectrum_show(numspecs):
    numshowspecs = max(1, numspecs // 2)
    assert len(s.spectra.dict) == 0
    for _ in range(numspecs):
        hdtvcmd("spectrum get {}".format(testspectrum))
    assert len(s.spectra.dict) == numspecs

    specs = " ".join(str(e) for e in range(numshowspecs))
    hdtvcmd("spectrum show {}".format(specs))

    f, ferr = hdtvcmd("spectrum list -v")
    assert len(s.spectra.dict) == numspecs
    assert len(f.split("\n")) == numshowspecs + 2
コード例 #28
0
ファイル: test_specInterface.py プロジェクト: op3/hdtv
def test_cmd_spectrum_name(name):
    assert len(s.spectra.dict) == 0
    hdtvcmd("spectrum get {}".format(testspectrum))
    assert len(s.spectra.dict) == 1

    f, ferr = hdtvcmd("spectrum name {}".format(name))
    print(ferr)
    print(f)
    assert ferr == ""
    assert "Renamed spectrum 0 to &#x27;{}&#x27;".format(name) in f

    f, ferr = hdtvcmd("spectrum list")
    assert name in f
コード例 #29
0
ファイル: test_specInterface.py プロジェクト: op3/hdtv
def test_cmd_spectrum_activate(numspecs):
    assert len(s.spectra.dict) == 0
    for _ in range(numspecs):
        hdtvcmd("spectrum get {}".format(testspectrum))
    assert len(s.spectra.dict) == numspecs

    for specid in range(numspecs):
        hdtvcmd("spectrum activate {}".format(specid))
        f, ferr = hdtvcmd("spectrum list")
        for i, line in enumerate(f.split("\n")):
            if i == specid + 2:
                assert "|   AV |" in line
            elif i > 2:
                assert "|    V |" in line
コード例 #30
0
def test_cmd_fit_various():
    hdtvcmd("fit function peak activate theuerkauf")
    spec_interface.LoadSpectra(testspectrum)
    assert len(spec_interface.spectra.dict) == 1
    f, ferr = setup_fit()
    assert f == ""
    assert ferr == ""
    f, ferr = hdtvcmd("fit execute")
    assert "WorkFit on spectrum: 0" in f
    assert ".0 |" in f
    assert ".1 |" in f
    assert "2 peaks in WorkFit" in f
    f, ferr = hdtvcmd("fit store")
    assert f == "Storing workFit with ID 0"
    assert ferr == ""
    f, ferr = hdtvcmd("fit clear", "fit list")
    assert ferr == ""
    assert "Fits in Spectrum 0" in f
    f, ferr = hdtvcmd(
        "fit hide 0",
        "fit show 0",
        "fit show decomposition 0",
        "fit hide decomposition 0",
        "fit show residuals 0",
        "fit hide residuals 0")
    assert ferr == ""
    assert f == ""
    f, ferr = hdtvcmd("fit activate 0")
    assert "Activating fit 0" in f
    assert ferr == ""
    f, ferr = hdtvcmd("fit delete 0",
                      "fit function peak activate ee")
    assert ferr == ""
    assert f == ""