コード例 #1
0
ファイル: bias_modelling_bayes.py プロジェクト: akutkin/SACA
    # fig.tight_layout()
    # fig.savefig(os.path.join(data_dir, 'bias_corner_{}.eps'.format(freq)),
    #             dpi=1200, format='eps')

    # Estimate bias using bootstrap
    boot_dir = '/home/ilya/Dropbox/papers/boot/bias/new/stationary/boot'
    for i in range(1, 101, 1):
        art_fits_fname = 'art_{}_{}.fits'.format(freq, i)
        art_fits_path = os.path.join(data_dir, art_fits_fname)
        dfm_model_path = os.path.join(data_dir,
                                      'out_{}_{}.mdl'.format(freq, i))
        bootstrap_uvfits_with_difmap_model(
            art_fits_path,
            dfm_model_path,
            boot_dir=boot_dir,
            out_txt_file=os.path.join(boot_dir,
                                      'bias_{}_{}.txt'.format(freq, i)),
            out_plot_file=None,
            n_boot=100,
            niter=100)

originals = dict()
corrected = dict()
for freq in ('x', 'j', 'u'):
    originals[freq] = list()
    corrected[freq] = list()
    biases = list()
    r1 = list()
    for i in range(1, 101, 1):
        bias_file = os.path.join(boot_dir, 'bias_{}_{}.txt'.format(freq, i))
        with open(bias_file, 'r') as fo:
コード例 #2
0
ファイル: test_pairs.py プロジェクト: akutkin/SACA
# download_mojave_uv_fits(source, epochs=[epoch], bands=['u'],
#                         download_dir=data_dir)

uv_fits_fname = mojave_uv_fits_fname(source, 'u', epoch)
uv_fits_path = os.path.join(data_dir, uv_fits_fname)
original_model_path = os.path.join(data_dir, 'initial.mdl')
cg1 = CGComponent(2., 0., 0., 0.2)
cg2 = CGComponent(0.25, 0., 0.2, 0.2)
mdl = Model(stokes='I')
mdl.add_components(cg1, cg2)
uvdata = UVData(uv_fits_path)
noise = uvdata.noise()
for i in range(1, 2):
    uvdata = UVData(uv_fits_path)
    uvdata.substitute([mdl])
    uvdata.noise_add(noise)
    art_fits_fname = 'art_{}.fits'.format(i)
    art_fits_path = os.path.join(data_dir, art_fits_fname)
    uvdata.save(art_fits_path)
    modelfit_difmap(art_fits_fname, 'initial.mdl', 'out_{}.mdl'.format(i),
                    niter=100, path=data_dir, mdl_path=data_dir,
                    out_path=data_dir)

from bootstrap import bootstrap_uvfits_with_difmap_model
i=1
art_fits_fname = 'art_{}.fits'.format(i)
art_fits_path = os.path.join(data_dir, art_fits_fname)
bootstrap_uvfits_with_difmap_model(art_fits_path, os.path.join(data_dir, 'out_{}.mdl'.format(i)),
                                   boot_dir=os.path.join(data_dir, 'boot'),
                                   pairs=False)
コード例 #3
0
    uvdata = UVData(uv_fits_path)
    try:
        del uvdata.hdu.header['HISTORY']
        uvdata.save(rewrite=True, downscale_by_freq=False)
    except KeyError:
        pass

    out_txt_file = os.path.join(txt_file_dir, 'errors_{}.mod'.format(epoch))
    out_png_file = os.path.join(txt_file_dir, 'errors_{}.png'.format(epoch))
    try:
        bootstrap_uvfits_with_difmap_model(uv_fits_path,
                                           original_model_path,
                                           n_boot=100,
                                           boot_dir=boot_dir,
                                           out_txt_file=out_txt_file,
                                           out_plot_file=out_png_file,
                                           clean_after=True,
                                           niter=200,
                                           out_rchisq_file=os.path.join(
                                               txt_file_dir,
                                               "{}_rchisq.dat".format(epoch)))
    except IOError:
        with open(os.path.join(txt_file_dir, '{}_io_error.txt'.format(epoch)),
                  'w'):
            print("IO Error")
        continue
    except VerifyError:
        with open(
                os.path.join(txt_file_dir,
                             '{}_verify_error.txt'.format(epoch)), 'w'):
            print("Verify Error")
コード例 #4
0
refitted_mdl_fname = 'new2.mdl'
refitted_mdl_path = os.path.join(source_dir, refitted_mdl_fname)
# modelfit_difmap(uv_fits_fname, dfm_model_fname, refitted_mdl_fname,
#                 niter=300, path=source_dir, mdl_path=source_dir,
#                 out_path=source_dir)

# comps = import_difmap_model(refitted_mdl_fname, source_dir)
# model = Model(stokes='I')
# model.add_components(*comps)
# uvdata = UVData(uv_fits_path)
# fig = uvdata.uvplot()
# uvdata.substitute([model])
# uvdata.uvplot(fig=fig, color='r')

# bootstrapped_uv_fits = sorted(glob.glob(os.path.join(source_dir,
#                                                      'bootstrapped_data*.fits')))
fig = bootstrap_uvfits_with_difmap_model(uv_fits_path, refitted_mdl_path,
                                         boot_dir=source_dir, n_boot=100,
                                         clean_after=False,
                                         use_kde=True,
                                         use_v=False,
                                         out_plot_file=os.path.join(source_dir, 'plot.pdf'),
                                         niter=150,
                                         bootstrapped_uv_fits=None)
# from bootstrap import analyze_bootstrap_samples
# booted_mdl_paths = glob.glob(os.path.join(source_dir, 'mdl_booted*'))
# fig = analyze_bootstrap_samples(refitted_mdl_fname, booted_mdl_paths,
#                                 dfm_model_dir=source_dir, plot_comps=[11, 10],
#                                 plot_file=os.path.join(source_dir, '0_1_boot.eps'),
#                                 txt_file=os.path.join(source_dir, 'txt.txt'))
コード例 #5
0
# DOESNT WORK - ERRORS STILL SMALL
import os
from mojave import mojave_uv_fits_fname
from uv_data import UVData
from bootstrap import bootstrap_uvfits_with_difmap_model

data_dir = '/home/ilya/silke'
epoch = '2017_01_28'
original_model_fname = '2017_01_28us'
original_model_path = os.path.join(data_dir, original_model_fname)
uv_fits_fname = mojave_uv_fits_fname('0851+202', 'u', epoch)
uv_fits_path = os.path.join(data_dir, uv_fits_fname)
uvdata = UVData(uv_fits_path)
uvdata.noise_add({baseline: [0.137] for baseline in uvdata.baselines})
new_fits_path = os.path.join(data_dir, 'added_noise.fits')
uvdata.save(new_fits_path)
bootstrap_uvfits_with_difmap_model(new_fits_path,
                                   original_model_path,
                                   boot_dir=os.path.join(data_dir, 'boot'))
コード例 #6
0
ファイル: silke_processing.py プロジェクト: akutkin/SACA
    uv_fits_fname = mojave_uv_fits_fname('0851+202', 'u', epoch)
    uv_fits_path = os.path.join(data_dir, uv_fits_fname)

    uvdata = UVData(uv_fits_path)
    try:
        del uvdata.hdu.header['HISTORY']
        uvdata.save(rewrite=True, downscale_by_freq=False)
    except KeyError:
        pass

    out_txt_file = os.path.join(txt_file_dir, 'errors_{}.dml'.format(epoch))
    out_png_file = os.path.join(txt_file_dir, 'errors_{}.png'.format(epoch))
    try:
        bootstrap_uvfits_with_difmap_model(uv_fits_path, original_model_path,
                                           n_boot=300, boot_dir=boot_dir,
                                           out_txt_file=out_txt_file,
                                           out_plot_file=out_png_file,
                                           clean_after=True, niter=200)
    # except IOError:
    #     with open(os.path.join(txt_file_dir, '{}_io_error.txt'.format(epoch)), 'w'):
    #         print "IO Error"
    #     continue
    except VerifyError:
        with open(os.path.join(txt_file_dir, '{}_verify_error.txt'.format(epoch)), 'w'):
            print "Verify Error"
        bootstrapped_uv_fits = sorted(glob.glob(os.path.join(boot_dir,
                                                             'bootstrapped_data*.fits')))
        for file_ in bootstrapped_uv_fits:
            os.unlink(file_)
        continue