Exemple #1
0
    def load_vis(self, uv_file, reweight=True, img_sz_kwargs={}):
        '''Read in a file with visibilities.
            
        Parameters
        ----------
        uv_file : str
            Name of file, generated by uvplot, to load.
        reweight : bool, optional
            Reweight so that null model has chi squared = 1.
        img_s_kwargs : dict
            Keywords to pass to galario.get_image_size.
        '''

        # get the file, assume we're getting the output from uvplot
        u, v, Re, Im, w = np.require(np.loadtxt(uv_file, unpack=True),
                                     requirements=["C_CONTIGUOUS"])

        # meaning we can get the mean wavelength like so
        with open(uv_file) as f:
            _ = f.readline()
            tmp = f.readline()

        wavelength = float(tmp.strip().split('=')[1])
        print('wavelength is {} mm'.format(wavelength * 1e3))

        self.wavelength = wavelength
        self.u = u / wavelength
        self.v = v / wavelength
        self.re = u
        self.im = u

        # re-weight so that chi^2 for null model is 1
        reweight_factor = np.sum((Re**2.0 + Im**2.0) * w) / len(w)
        if reweight:
            print('reweighting factor used {}'.format(reweight_factor))
            w /= reweight_factor
        else:
            print('reweighting factor unused {}'.format(reweight_factor))

        self.w = w

        # get image pixel scale and size
        self.nxy, self.dxy = gd.get_image_size(self.u,
                                               self.v,
                                               **img_sz_kwargs,
                                               verbose=True)
        self.dxy_arcsec = self.dxy / arcsec
Exemple #2
0
##### Because we don't want each thread to use multiple core for numpy computation. That forces the use of a proper multithreading
import os
os.environ["OMP_NUM_THREADS"] = "1"

##### load data
u, v, Re, Im, w = np.require(np.loadtxt("uvtable2.txt", unpack=True),
                             requirements='C')

##### for conversion
#wavelength = 0.00087  # [m]
#u /= wavelength
#v /= wavelength

##### get size of the image
nxy, dxy = get_image_size(
    u, v, verbose=False)  # Number of pixel, width of a pixel in rad

##### radial grid parameters, fixed
Rmin = 1e-6  # arcsec
dR = 0.0006  # arcsec
nR = int(2 / dR)
dR *= arcsec
Rmin *= arcsec
##### Define a mesh for the space
R = np.linspace(Rmin, Rmin + dR * nR, nR, endpoint=False)


##### Define a gaussian profile
def GaussianProfile(f0, sigma):
    """ Gaussian brightness profile.
    """
    ### return gaussian profile
    return f, r


# ========================== Code =========================

### READ UV TABLE AND GET VISIBILITIES
print("\nReading in UV table: " + args.uvtable)
u, v, re, im, w = np.loadtxt(args.uvtable, unpack=True)
u, v = np.ascontiguousarray(u), np.ascontiguousarray(v)
u /= args.wavelength
v /= args.wavelength

### GET IMAGE SIZE
print("\nImage size: ")
nxy, dxy = g_double.get_image_size(u, v, verbose=True, f_max=2.1, f_min=2.0)
rmin, dr, nr = 1e-4 * arcsec, 0.001 * arcsec, 20000

### CHECK FOR EMCEE RESULTS FILE
if os.path.isfile(args.mcmcfile) == False:
    print("File for plotting not found!")
    sys.exit()

### GET EMCEE RESULTS
if args.chain_recall:
    chain_recall = args.chain_recall
else:
    chain_recall = 500
samples_all = np.load(args.mcmcfile)
nwalkers, nsteps, ndim = samples_all.shape
samples = samples_all[:, -chain_recall:, :].reshape((-1, ndim))
Exemple #4
0
wavelength = float(tmp.strip().split('=')[1])
#print('wavelength is {} mm'.format(wavelength*1e3))

u /= wavelength
v /= wavelength

# estimate re-weighting factor (so that chi^2 for null model would be 1, and d.o.f = 2*len(w))
# weights would need to be multiplied by this number
#reweight_factor = 2*len(w) / np.sum( (Re**2.0 + Im**2.0) * w )
#print('reweighting factor is {}'.format(reweight_factor))

# In[4]:

# set image properties, can alter f_max for higher or lower resolution
nxy, dxy = gd.get_image_size(u, v, verbose=True)
dxy_arcsec = dxy / arcsec

# In[5]:

# decide what density model we want to use
model_name = 'peri_glow'

# In[6]:

# make the image object. by default this is asisymmetric
# (i.e. model='los_image_axisym', and has no anomaly parameter)
ii = alma.image.Image(arcsec_pix=dxy_arcsec,
                      image_size=(nxy, nxy),
                      model='los_image',
                      dens_model=model_name,
Exemple #5
0
        #        print('{}, {} rows, \twave {:9.7f}mm,'
        #              '\treweight factor {:g}'.format(os.path.basename(f),len(w),
        #                                              wavelength_tmp*1e3,
        #                                              fw[-1]))

        uvdata.append((u, v, Re, Im, w))
        all_weights = np.append(all_weights, w)

# In[4]:

# set image properties, take greatest resolution needed
nxy = 0
dxy = 1
for vis in uvdata:
    u, v, _, _, _ = vis
    nxy_tmp, dxy_tmp = gd.get_image_size(u, v, verbose=False)
    if nxy_tmp > nxy and dxy_tmp < dxy:
        nxy = nxy_tmp
        dxy = dxy_tmp

dxy_arcsec = dxy / arcsec
#print('Final nxy:{}, dxy:{}, dxy arcsec:{}'.format(nxy, dxy, dxy_arcsec))

# In[5]:

# decide what density model we want to use
model_name = 'peri_glow'

# In[6]:

# make the image object, one will be used for all fields
Exemple #6
0
    ValsBinList = BinnedValues(vals, radtemp)
    WeightsBinList = BinnedValues(weights, radtemp)
    m, e, NoneIndex = BinningMeansAndErrors(ValsBinList, WeightsBinList)
    r = np.delete(r, NoneIndex)
    e = np.transpose(e)
    return (r, m, e)


from galario.double import get_image_size, chi2Profile, sampleProfile


def extractvalues(location, lconv=500, percentiles=[0.15, 0.5, 0.85]):
    """extracts the values from a npy file created by OptimizationGalario. Returns the percentiles you asked for. Lconv is the converged length
    """
    samples, _, _, _ = np.load(location, allow_pickle=True)
    l1, l2, l3 = samples.shape
    samples_converged = samples[:, -lconv:, :].reshape(lconv * l1, l3)
    values = np.percentile(samples_converged, percentiles, axis=0)
    return (values)


nxy, dxy = get_image_size(u, v, verbose=False)


def ComputeVisibilities(RadialModel):
    return (sampleProfile(RadialModel, Rmin, dR, nxy, dxy, u, v))


def ReandIm(x):
    return (np.real(x), np.imag(x))