Exemplo n.º 1
0
def test_info_serialize_method():
    """
    Unit test of context manager to set info.serialize_method.  Normally just
    used to set this for writing a Table to file (FITS, ECSV, HDF5).
    """
    t = table.Table({
        'tm': time.Time([1, 2], format='cxcsec'),
        'sc': coordinates.SkyCoord([1, 2], [1, 2], unit='deg'),
        'mc': table.MaskedColumn([1, 2], mask=[True, False]),
        'mc2': table.MaskedColumn([1, 2], mask=[True, False])
    })

    origs = {}
    for name in ('tm', 'mc', 'mc2'):
        origs[name] = deepcopy(t[name].info.serialize_method)

    # Test setting by name and getting back to originals
    with serialize_method_as(t, {'tm': 'test_tm', 'mc': 'test_mc'}):
        for name in ('tm', 'mc'):
            assert all(t[name].info.serialize_method[key] == 'test_' + name
                       for key in t[name].info.serialize_method)
        assert t['mc2'].info.serialize_method == origs['mc2']
        assert not hasattr(t['sc'].info, 'serialize_method')

    for name in ('tm', 'mc', 'mc2'):
        assert t[name].info.serialize_method == origs[name]  # dict compare
    assert not hasattr(t['sc'].info, 'serialize_method')

    # Test setting by name and class, where name takes precedence.  Also
    # test that it works for subclasses.
    with serialize_method_as(t, {
            'tm': 'test_tm',
            'mc': 'test_mc',
            table.Column: 'test_mc2'
    }):
        for name in ('tm', 'mc', 'mc2'):
            assert all(t[name].info.serialize_method[key] == 'test_' + name
                       for key in t[name].info.serialize_method)
        assert not hasattr(t['sc'].info, 'serialize_method')

    for name in ('tm', 'mc', 'mc2'):
        assert t[name].info.serialize_method == origs[name]  # dict compare
    assert not hasattr(t['sc'].info, 'serialize_method')

    # Test supplying a single string that all applies to all columns with
    # a serialize_method.
    with serialize_method_as(t, 'test'):
        for name in ('tm', 'mc', 'mc2'):
            assert all(t[name].info.serialize_method[key] == 'test'
                       for key in t[name].info.serialize_method)
        assert not hasattr(t['sc'].info, 'serialize_method')

    for name in ('tm', 'mc', 'mc2'):
        assert t[name].info.serialize_method == origs[name]  # dict compare
    assert not hasattr(t['sc'].info, 'serialize_method')
Exemplo n.º 2
0
def test_info_serialize_method():
    """
    Unit test of context manager to set info.serialize_method.  Normally just
    used to set this for writing a Table to file (FITS, ECSV, HDF5).
    """
    t = table.Table({'tm': time.Time([1, 2], format='cxcsec'),
                     'sc': coordinates.SkyCoord([1, 2], [1, 2], unit='deg'),
                     'mc': table.MaskedColumn([1, 2], mask=[True, False]),
                     'mc2': table.MaskedColumn([1, 2], mask=[True, False])}
                    )

    origs = {}
    for name in ('tm', 'mc', 'mc2'):
        origs[name] = deepcopy(t[name].info.serialize_method)

    # Test setting by name and getting back to originals
    with serialize_method_as(t, {'tm': 'test_tm', 'mc': 'test_mc'}):
        for name in ('tm', 'mc'):
            assert all(t[name].info.serialize_method[key] == 'test_' + name
                       for key in t[name].info.serialize_method)
        assert t['mc2'].info.serialize_method == origs['mc2']
        assert not hasattr(t['sc'].info, 'serialize_method')

    for name in ('tm', 'mc', 'mc2'):
        assert t[name].info.serialize_method == origs[name]  # dict compare
    assert not hasattr(t['sc'].info, 'serialize_method')

    # Test setting by name and class, where name takes precedence.  Also
    # test that it works for subclasses.
    with serialize_method_as(t, {'tm': 'test_tm', 'mc': 'test_mc',
                                 table.Column: 'test_mc2'}):
        for name in ('tm', 'mc', 'mc2'):
            assert all(t[name].info.serialize_method[key] == 'test_' + name
                       for key in t[name].info.serialize_method)
        assert not hasattr(t['sc'].info, 'serialize_method')

    for name in ('tm', 'mc', 'mc2'):
        assert t[name].info.serialize_method == origs[name]  # dict compare
    assert not hasattr(t['sc'].info, 'serialize_method')

    # Test supplying a single string that all applies to all columns with
    # a serialize_method.
    with serialize_method_as(t, 'test'):
        for name in ('tm', 'mc', 'mc2'):
            assert all(t[name].info.serialize_method[key] == 'test'
                       for key in t[name].info.serialize_method)
        assert not hasattr(t['sc'].info, 'serialize_method')

    for name in ('tm', 'mc', 'mc2'):
        assert t[name].info.serialize_method == origs[name]  # dict compare
    assert not hasattr(t['sc'].info, 'serialize_method')
Exemplo n.º 3
0
def test_info_serialize_method_exception():
    """
    Unit test of context manager to set info.serialize_method.  Normally just
    used to set this for writing a Table to file (FITS, ECSV, HDF5).
    """
    t = simple_table(masked=True)
    origs = deepcopy(t['a'].info.serialize_method)
    try:
        with serialize_method_as(t, 'test'):
            assert all(t['a'].info.serialize_method[key] == 'test'
                       for key in t['a'].info.serialize_method)
            raise ZeroDivisionError()
    except ZeroDivisionError:
        pass

    assert t['a'].info.serialize_method == origs  # dict compare
Exemplo n.º 4
0
def test_info_serialize_method_exception():
    """
    Unit test of context manager to set info.serialize_method.  Normally just
    used to set this for writing a Table to file (FITS, ECSV, HDF5).
    """
    t = simple_table(masked=True)
    origs = deepcopy(t['a'].info.serialize_method)
    try:
        with serialize_method_as(t, 'test'):
            assert all(t['a'].info.serialize_method[key] == 'test'
                       for key in t['a'].info.serialize_method)
            raise ZeroDivisionError()
    except ZeroDivisionError:
        pass

    assert t['a'].info.serialize_method == origs  # dict compare
Exemplo n.º 5
0
print('fitting ' + str(prior.nsrc) + ' sources \n')
print('using ' + str(prior.snpix) + ' pixels')

from xidplus.numpyro_fit import LOFAR150

fit = LOFAR150.LOFAR_150(prior, num_samples=1000, num_warmup=1000)
samples = fit.get_samples()['src_f']
posterior = xidplus.posterior_numpyro(fit, [prior])

if os.path.exists(
        'data/xidplus_results/pybdsf/xidplus_run_{}'.format(n)) == True:
    ()
else:
    os.mkdir('data/xidplus_results/pybdsf/xidplus_run_{}'.format(n))

xidplus.save(
    [prior], posterior,
    'data/xidplus_results/pybdsf/xidplus_run_{}/lofar_xidplus_fir_{}_rerun.pkl'
    .format(n, n))

LOFAR_cat = cat.create_LOFAR_cat(posterior, prior, 0)
LOFAR_cat = Table.read(LOFAR_cat)

with serialize_method_as(LOFAR_cat, None):
    registry.write(
        LOFAR_cat,
        'data/xidplus_results/pybdsf/xidplus_run_{}/lofar_xidplus_fir_{}_rerun.fits'
        .format(n, n),
        format='fits',
        overwrite=True)
posterior = xidplus.posterior_stan(fit, [prior250, prior350, prior500])
priors = [prior250, prior350, prior500]
import xidplus.catalogue as cat
SPIRE_cat = cat.create_SPIRE_cat(posterior, priors[0], priors[1], priors[2])
SPIRE_cat = Table.read(SPIRE_cat)

mask = [SPIRE_cat['HELP_ID'][i] in ids for i in range(len(SPIRE_cat))]
SPIRE_cat = SPIRE_cat[mask]

if os.path.exists('data/fir/v0_7/SPIRE/xidplus_run_{}'.format(taskid)) == True:
    ()
else:
    os.mkdir('data/fir/v0_7/SPIRE/xidplus_run_{}'.format(taskid))

xidplus.save([prior250, prior350, prior500], posterior,
             'data/fir/v0_7/SPIRE/xidplus_run_{}/lofar_xidplus_fir_{}'.format(
                 taskid, taskid))

#the next couple of lines are an alternative way to save astropy table since the Table.write method is currently broken
with serialize_method_as(SPIRE_cat, None):
    registry.write(
        SPIRE_cat,
        'data/fir/v0_7/SPIRE/xidplus_run_{}/lofar_xidplus_fir_{}.fits'.format(
            taskid, taskid),
        format='fits',
        overwrite=True)
#Table.write(SPIRE_cat,'data/fir/v0_7/SPIRE/xidplus_run_{}/lofar_xidplus_fir_{}.fits'.format(taskid,taskid),overwrite=True)

time1 = time.time()
print('total time taken = {}'.format(time1 - time0))
Exemplo n.º 7
0
posterior = xidplus.posterior_stan(fit, [prior100, prior160])

priors = [prior100, prior160]

import xidplus.catalogue as cat
PACS_cat = cat.create_PACS_cat(posterior, priors[0], priors[1])
PACS_cat = Table.read(PACS_cat)

mask = [PACS_cat['help_id'][i] in ids for i in range(len(PACS_cat))]
PACS_cat = PACS_cat[mask]

if os.path.exists(
        'data/fir/PACS_no_lofar/xidplus_run_{}'.format(taskid)) == True:
    ()
else:
    os.mkdir('data/fir/PACS_no_lofar/xidplus_run_{}'.format(taskid))
xidplus.save(
    [prior100, prior160], posterior,
    'data/fir/PACS_no_lofar/xidplus_run_{}/lofar_xidplus_fir_{}'.format(
        taskid, taskid))
#the next couple of lines are an alternative way to save astropy table since the Table.write method is currently broken
with serialize_method_as(PACS_cat, None):
    registry.write(
        PACS_cat,
        'data/fir/PACS_no_lofar/xidplus_run_{}/lofar_xidplus_fir_{}.fits'.
        format(taskid, taskid),
        format='fits',
        overwrite=True)
#Table.write(PACS_cat,'data/fir/PACS/xidplus_run_{}/lofar_xidplus_fir_{}_rerun.fits'.format(taskid,taskid),overwrite=True)
Exemplo n.º 8
0
posterior = xidplus.posterior_stan(fit, [prior250])
priors = [prior250]

import xidplus.catalogue as cat
MIPS_cat = cat.create_MIPS_cat(posterior, priors[0], 0)
MIPS_cat = Table.read(MIPS_cat)

mask = [MIPS_cat['help_id'][i] in ids for i in range(len(MIPS_cat))]
MIPS_cat = MIPS_cat[mask]

if os.path.exists(
        'data/fir/MIPS_no_lofar/xidplus_run_{}'.format(taskid)) == True:
    ()
else:
    os.mkdir('data/fir/MIPS_no_lofar/xidplus_run_{}'.format(taskid))

xidplus.save(
    [prior250], posterior,
    'data/fir/MIPS_no_lofar/xidplus_run_{}/lofar_xidplus_fir_{}'.format(
        taskid, taskid))

#the next couple of lines are an alternative way to save astropy table since the Table.write method is currently broken
with serialize_method_as(MIPS_cat, None):
    registry.write(
        MIPS_cat,
        'data/fir/MIPS_no_lofar/xidplus_run_{}/lofar_xidplus_fir_{}.fits'.
        format(taskid, taskid),
        format='fits',
        overwrite=True)
#Table.write(MIPS_cat,'data/fir/MIPS/xidplus_run_{}/lofar_xidplus_fir_{}_rerun.fits'.format(taskid,taskid),overwrite=True)