How to use the ehtim.obsdata.load_uvfits function in ehtim

To help you get started, we’ve selected a few ehtim examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github achael / eht-imaging / scripts / imgsum.py View on Github external
else: aipscc=False
    if opt.no_debias: debias=False
    else: debias=True
    if opt.no_ebar: ebar=False
    else: ebar=True
    if opt.no_gains: gainplots=False
    else: gainplots=True
    if opt.no_cphase: cphaseplots=False
    else: cphaseplots=True
    if opt.no_camp: campplots=False
    else: campplots=True
    if opt.no_amp: ampplots=False
    else: ampplots=True

    im = eh.image.load_fits(opt.inputim, aipscc=aipscc)
    obs = eh.obsdata.load_uvfits(opt.inputobs)
    obs_uncal = eh.obsdata.load_uvfits(opt.inputobs_uncal)

    basename = os.path.splitext(os.path.basename(opt.inputim))[0]
    outdir = str(opt.o)
    if outdir[-1] == '/': outname = outdir + basename + '.pdf'
    elif outdir[-3:] == 'pdf': outname = outdir
    else: outname = outdir +'/' + basename + '.pdf'

    args = [im, obs, obs_uncal, outname]
    kwargs = {'commentstr':opt.c, 'outdir':outdir,'ebar':ebar,'cfun':opt.cfun,'snrcut':snrcut,
              'sysnoise':opt.systematic_noise,'syscnoise':opt.systematic_cphase_noise,'fontsize':opt.fontsize,
              'gainplots':gainplots,'cphaseplots':cphaseplots,'campplots':campplots, 'ampplots':ampplots, 'debias':debias,  
              'cp_uv_min':cp_uv_min}

    eh.plotting.summary_plots.imgsum(*args, **kwargs)
github achael / eht-imaging / examples / example_modelfit.py View on Github external
from __future__ import print_function

import matplotlib.pyplot as plt
import numpy as np
import ehtim as eh

import ehtim.modeling.modeling_utils as mu

# Define the ground-truth model
mod = eh.model.Model()
mod.add_ring(1., 50.*eh.RADPERUAS)
mod.add_ring(0.5, 30.*eh.RADPERUAS, 5.*eh.RADPERUAS, 5.*eh.RADPERUAS) #For testing gradients
mod.make_image(100.*eh.RADPERUAS, 128).blur_circ(5.*eh.RADPERUAS).display()

# Create an observation
obs = eh.obsdata.load_uvfits('/home/michael/Dropbox/ER5_polarization_calibration/ER5/postproc-hops-lo/3.+netcal/3601/hops_3601_M87+netcal.uvfits')
obs.add_scans()
obs = obs.avg_coherent(0.,scan_avg=True)
obs = mod.observe_same(obs,ampcal=True,phasecal=True)

# Testing the chi^2
dtypes = ['vis','amp','bs','cphase','logcamp','camp','logamp', 'logcamp_diag', 'cphase_diag'] #, 'bs', 'amp', 'cphase', 'cphase_diag', 'camp', 'logcamp', 'logcamp_diag']
for dtype in dtypes:
    print('\nTesting chi^2 dtype:',dtype)
    chisqdata = eh.modeling.modeling_utils.chisqdata(obs, dtype)
    chisq = eh.modeling.modeling_utils.chisq(mod, chisqdata[2], chisqdata[0], chisqdata[1], dtype)
    print("chisq: %f" % chisq)
    print('\nTesting gradient')
    for x in [['F0',1e-10,0],['d',1e-4*eh.RADPERUAS,1],['x0',1e-4*eh.RADPERUAS,2],['y0',1e-4*eh.RADPERUAS,3]]:
        mod2 = mod.copy()
        dx = x[1]
        mod2.params[0][x[0]] += dx
github achael / eht-imaging / scripts / calibrate.py View on Github external
args = parser.parse_args()

if args.output is None:
    args.output = os.path.basename(args.input[:-14])+'+netcal.uvfits'
print("Parameters:")
print("    input: ", args.input)
print("    caltab directory:", args.caldir)
print("    output:", args.output)
print("    prune: ", args.prune)
print("    ampzbl:", args.ampzbl)
print("    tavg:  ", args.tavg)
#print("    pol:   ", args.pol)
print("    rescl: ", args.rescl)

# Load uvfits file
obs = eh.obsdata.load_uvfits(args.input, polrep='circ')
print("Flagging the SMA Reference Antenna...")
obs = obs.flag_sites(["SR"])
print("Flagging points with anomalous snr...")
obs = obs.flag_anomalous('llsnr', robust_nsigma_cut=3.0)
obs = obs.flag_anomalous('rrsnr', robust_nsigma_cut=3.0)

# Rescale noise if needed
if args.rescl:
    noise_scale_factor = obs.estimate_noise_rescale_factor()
    if np.isnan(noise_scale_factor):
        print("WARNING: failed to estimate noise scale factor; do not rescale")
    else:
        obs = obs.rescale_noise(noise_scale_factor)

# Optional: A-priori calibrate by applying the caltable
if args.caldir != None:
github achael / eht-imaging / examples / example_starwarps.py View on Github external
# parameters associated with EM 
nIters = 30
NHIST = 5000
stop=1e-10
maxit=4000

# directory where to save results
SAVE = True
dirname = '../results'


############## load data ##############

# load in the data
obs = eh.obsdata.load_uvfits(obsname)

# split the observations based upon the time
obs_List = sw.splitObs(obs)

############## reconstruct movie with no warp field ##############

# initialize the mean and the image covariance for the prior. 
# this can be a single image to be the same mean and covariance for each 
# time, or different for each time by appending an image/matrix for each timestep

# initialize mean
meanImg = []
emptyprior = eh.image.make_square(obs, NPIX, fov)
gaussprior = emptyprior.add_gauss(flux, (fwhm, fwhm, 0, 0, 0))
meanImg.append(gaussprior.copy())
github eventhorizontelescope / 2019-D01-02 / eht-imaging / eht-imaging_pipeline.py View on Github external
# repeat imaging with blurring to assure good convergence
def converge(major=3, blur_frac=1.0):
    for repeat in range(major):
        init = imgr.out_last().blur_circ(blur_frac*res)
        imgr.init_next = init
        imgr.make_image_I(show_updates=False)

#-------------------------------------------------------------------------------
# Prepare the data
#-------------------------------------------------------------------------------

# Load a single uvfits file
if args.infile2 == '':
    # load the uvfits file
    obs = eh.obsdata.load_uvfits(obsfile)

    # scan-average the data
    # identify the scans (times of continous observation) in the data
    obs.add_scans()

    # coherently average the scans, which can be averaged due to ad-hoc phasing
    obs = obs.avg_coherent(0.,scan_avg=True)

# If two uvfits files are passed as input (e.g., high and low band) then use both datasets,
# but do not form closure quantities between the two datasets
else:
    # load the two uvfits files
    obs1 = eh.obsdata.load_uvfits(obsfile)
    obs2 = eh.obsdata.load_uvfits(args.infile2)

    # Average data based on individual scan lengths
github eventhorizontelescope / 2019-D01-02 / eht-imaging / eht-imaging_pipeline.py View on Github external
if args.infile2 == '':
    # load the uvfits file
    obs = eh.obsdata.load_uvfits(obsfile)

    # scan-average the data
    # identify the scans (times of continous observation) in the data
    obs.add_scans()

    # coherently average the scans, which can be averaged due to ad-hoc phasing
    obs = obs.avg_coherent(0.,scan_avg=True)

# If two uvfits files are passed as input (e.g., high and low band) then use both datasets,
# but do not form closure quantities between the two datasets
else:
    # load the two uvfits files
    obs1 = eh.obsdata.load_uvfits(obsfile)
    obs2 = eh.obsdata.load_uvfits(args.infile2)

    # Average data based on individual scan lengths
    obs1.add_scans()
    obs2.add_scans()
    obs1 = obs1.avg_coherent(0.,scan_avg=True)
    obs2 = obs2.avg_coherent(0.,scan_avg=True)

    # Add a slight offset to avoid mixed closure products
    obs2.data['time'] += 0.00001

    # concatenate the observations into a single observation object
    obs = obs1.copy()
    obs.data = np.concatenate([obs1.data,obs2.data])

# Estimate the total flux density from the ALMA(AA) -- APEX(AP) zero baseline
github achael / eht-imaging / scripts / cli_blur_comp.py View on Github external
def generate_metricmtx(fpath_, directory_):
    path = fpath_
    dirname = directory_

    # get the image names
    filenames = [x for x in os.listdir(path + dirname + '/images/') if x.endswith('.fits') ]

    # load the obs file
    obs = eh.obsdata.load_uvfits(path + dirname + '/' + dirname + '.uvfits')
    beamparams = obs.fit_beam()

    # load the images
    imarr = []
    for i in range(len(filenames)):
        imarr.append(eh.image.load_fits(path + dirname + '/images/' + filenames[i]))

    # do the image comparisions 
    (metric_mtx, fracsteps) = comp.image_consistency(imarr, beamparams, metric='nxcorr', blursmall=True, beam_max=1.0, beam_steps=5, savepath=[])

    return (metric_mtx, fracsteps, beamparams, imarr)
github achael / eht-imaging / ehtim / pipeline.py View on Github external
def load(name):
        return eh.obsdata.load_uvfits(name)