def test_save_source_pha_fits(clean_astro_ui, tmp_path):
    """Can we write out data for save_source? DataPHA and FITS
    """

    from sherpa.astro.io import read_table_blocks

    ui.load_arrays(1, [1, 2], [5, 10], ui.DataPHA)

    # we need a response
    egrid = np.asarray([0.1, 0.2, 0.4])
    elo = egrid[:-1]
    ehi = egrid[1:]
    rmf = create_delta_rmf(elo, ehi, e_min=elo, e_max=ehi)
    ui.set_rmf(rmf)

    yarf = np.asarray([10, 20])
    arf = create_arf(elo, ehi, yarf)
    ui.set_arf(arf)

    ui.set_source(ui.const1d.cmdl)
    cmdl.c0 = 2

    out = tmp_path / 'model.dat'
    outfile = str(out)
    ui.save_source(outfile)

    ans = read_table_blocks(outfile)
    blocks = ans[1]
    assert len(blocks) == 2
    check_table(blocks[2], {
        'XLO': [0.1, 0.2],
        'XHI': [0.2, 0.4],
        'SOURCE': [2, 2]
    })
def test_save_resid_datapha_fits(tmp_path):
    """Residual, DataPHA, FITS"""

    from sherpa.astro.io import read_table_blocks

    ui.load_arrays(1, [1, 2], [5, 10], ui.DataPHA)

    # we need a response
    egrid = np.asarray([0.1, 0.2, 0.4])
    elo = egrid[:-1]
    ehi = egrid[1:]
    rmf = create_delta_rmf(elo, ehi, e_min=elo, e_max=ehi)
    ui.set_rmf(rmf)

    yarf = np.asarray([10, 20])
    arf = create_arf(elo, ehi, yarf)
    ui.set_arf(arf)

    ui.set_source(ui.const1d.cmdl)
    cmdl.c0 = 2

    out = tmp_path / 'resid.out'
    outfile = str(out)
    ui.save_resid(outfile)

    ans = read_table_blocks(outfile)
    blocks = ans[1]
    assert len(blocks) == 2
    check_table(blocks[2], {'X': [0.15, 0.3], 'RESID': [30, 10]})
def test_save_data_data1d_fits(tmp_path):
    """Does save_data work for Data1D? FITS"""

    from sherpa.astro.io import read_table_blocks

    ui.load_arrays(1, [1, 2, 3], [5, 4, 3], ui.Data1D)

    out = tmp_path / "data.dat"
    outfile = str(out)
    ui.save_data(outfile, ascii=False)

    ans = read_table_blocks(outfile)
    blocks = ans[1]
    assert len(blocks) == 2
    check_table(blocks[2], {'X': [1, 2, 3], 'Y': [5, 4, 3]})
def test_save_resid_data1d_fits(tmp_path):
    """Residual, Data1D, FITS"""

    from sherpa.astro.io import read_table_blocks

    ui.load_arrays(1, [100, 200], [20, 230], ui.Data1D)
    ui.set_source(ui.const1d.cmdl)
    cmdl.c0 = 220

    out = tmp_path / 'resid.out'
    outfile = str(out)
    ui.save_resid(outfile)

    ans = read_table_blocks(outfile)
    blocks = ans[1]
    assert len(blocks) == 2
    check_table(blocks[2], {'X': [100, 200], 'RESID': [-200, 10]})
def test_save_model_fits(savefunc, mtype, clean_astro_ui, tmp_path):
    """Can we write out data for save_source/model? Data1D and FITS

    As this is not a PHA dataset, the two shouldbe the same bar the
    header line.
    """

    from sherpa.astro.io import read_table_blocks

    ui.load_arrays(1, [1, 2], [5, 10])
    ui.set_source(ui.polynom1d.cmdl)
    cmdl.c0 = -5
    cmdl.c1 = 10

    out = tmp_path / 'model.dat'
    outfile = str(out)
    savefunc(outfile)

    ans = read_table_blocks(outfile)
    blocks = ans[1]
    assert len(blocks) == 2
    check_table(blocks[2], {'X': [1, 2], mtype: [5, 15]})
示例#6
0
    def read(self, filename):
        filename, cols, hdr = read_table_blocks(filename)

        emethod = None
        for key in hdr.keys():
            if 'EMETHOD' in hdr[key]:
                emethod = hdr[key]['EMETHOD'].strip().upper()

        if emethod is not None and emethod.startswith('PCA1DADD'):
            bias = cols[2]['BIAS']
            component = cols[3]['COMPONENT']
            fvariance = cols[3]['FVARIANCE']
            eigenval = cols[3]['EIGENVAL']
            eigenvec = cols[3]['EIGENVEC']
            return PCA1DAdd(bias, component, fvariance, eigenval, eigenvec)

        elif emethod is not None and emethod.startswith('SIM1DADD'):
            bias = cols[2]['BIAS']
            component = cols[3]['COMPONENT']
            simcomp = cols[3]['SIMCOMP']
            return SIM1DAdd(bias, component, simcomp)

        raise TypeError("Unknown simulation ARF '%s'" % filename)
示例#7
0
    def read(self, filename):
        filename, cols, hdr = read_table_blocks(filename)

        emethod = None
        for key in hdr.keys():
            if hdr[key].has_key('EMETHOD'):
                emethod = hdr[key]['EMETHOD'].strip().upper()

        if emethod is not None and emethod.startswith('PCA1DADD'):
            bias      = cols[2]['BIAS']
            component = cols[3]['COMPONENT']
            fvariance = cols[3]['FVARIANCE']
            eigenval  = cols[3]['EIGENVAL']
            eigenvec  = cols[3]['EIGENVEC']
            return PCA1DAdd(bias, component, fvariance, eigenval, eigenvec)

        elif emethod is not None and emethod.startswith('SIM1DADD'):
            bias      = cols[2]['BIAS']
            component = cols[3]['COMPONENT']
            simcomp   = cols[3]['SIMCOMP'] 
            return SIM1DAdd(bias, component, simcomp)

        raise TypeError("Unknown simulation ARF '%s'" % filename)