How to use the ehtim.observing.obs_simulate 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 / ehtim / calibrating / pol_cal.py View on Github external
mask=[]

    # Do everything in a circular basis
    im_circ = im.switch_polrep('circ')        

    if dtype not in ['vis','amp']:
        raise Exception('dtype must be vis or amp')

    # Create the obsdata object for searching 
    obs_test = obs.copy()
    obs_test = obs_test.switch_polrep('circ')

    # Check to see if the field rotation is corrected
    if obs_test.frcal == False:
        print("Field rotation angles have not been corrected. Correcting now...")
        obs_test.data = simobs.apply_jones_inverse(obs_test,frcal=False,dcal=True,verbose=False)
        obs_test.frcal = True

    # List of all sites present in the observation
    allsites = list(set(np.hstack((obs.data['t1'], obs.data['t2']))))

    if len(sites) == 0:
        print("No stations specified for leakage calibration: defaulting to calibrating all !")
        sites = allsites

    # only include sites that are present
    sites = [s for s in sites if s in allsites]
    site_index = [list(obs.tarr['site']).index(s) for s in sites]

    (dataRR, sigmaRR, ARR) = iu.chisqdata(obs, im_circ, mask=mask, dtype=dtype, pol='RR', ttype=ttype, fft_pad_factor=fft_pad_factor)
    (dataLL, sigmaLL, ALL) = iu.chisqdata(obs, im_circ, mask=mask, dtype=dtype, pol='LL', ttype=ttype, fft_pad_factor=fft_pad_factor)
    (dataRL, sigmaRL, ARL) = iu.chisqdata(obs, im_circ, mask=mask, dtype=dtype, pol='RL', ttype=ttype, fft_pad_factor=fft_pad_factor)
github achael / eht-imaging / ehtim / image.py View on Github external
obs =  ehtim.obsdata.Obsdata(obs.ra, obs.dec, obs.rf, obs.bw, obsdata, obs.tarr,
                                             source=obs.source, mjd=obs.mjd, polrep=obs_in.polrep,
                                             ampcal=ampcal, phasecal=phasecal,
                                             opacitycal=True, dcal=True, frcal=True,
                                             timetype=obs.timetype, scantable=obs.scans)
                                             #these are always set to True after inverse jones call


        # No Jones Matrices, Add noise the old way
        # NOTE There is an asymmetry here - in the old way, we don't offer the ability to *not* unscale estimated noise.
        else:

            if caltable_path:
                print('WARNING: the caltable is currently only saved if you apply noise with a Jones Matrix')

            obsdata = simobs.add_noise(obs, add_th_noise=add_th_noise,
                                       ampcal=ampcal, phasecal=phasecal, opacitycal=opacitycal,
                                       gainp=gainp, taup=taup, gain_offset=gain_offset, seed=seed)

            obs =  ehtim.obsdata.Obsdata(obs.ra, obs.dec, obs.rf, obs.bw, obsdata, obs.tarr,
                                         source=obs.source, mjd=obs.mjd, polrep=obs_in.polrep,
                                         ampcal=ampcal, phasecal=phasecal, opacitycal=True, dcal=True, frcal=True,
                                         timetype=obs.timetype, scantable=obs.scans)
                                         #these are always set to True after inverse jones call

        return obs
github achael / eht-imaging / ehtim / movie.py View on Github external
taup (float): the fractional std. dev. of the random error on the opacities
               dtermp (float): the fractional std. dev. of the random error on the D-terms
               dterm_offset (float): the base dterm offset at all sites, or a dict giving one dterm offset per site

            Returns:
               (Obsdata): an observation object

        """

        print("Producing clean visibilities from movie . . . ")
        obs = self.observe_same_nonoise(obs_in, sgrscat=sgrscat, ttype=ttype, fft_pad_factor=fft_pad_factor, repeat=repeat)

        # Jones Matrix Corruption & Calibration
        if jones:
            print("Applying Jones Matrices to data . . . ")
            obsdata = simobs.add_jones_and_noise(obs, add_th_noise=add_th_noise,
                                                 opacitycal=opacitycal, ampcal=ampcal,
                                                 phasecal=phasecal, dcal=dcal, frcal=frcal,
                                                 stabilize_scan_phase=stabilize_scan_phase,
                                                 stabilize_scan_amp=stabilize_scan_amp,
                                                 gainp=gainp, taup=taup, gain_offset=gain_offset,
                                                 dtermp=dtermp,dterm_offset=dterm_offset)

            obs =  ehtim.obsdata.Obsdata(obs.ra, obs.dec, obs.rf, obs.bw, obsdata, obs.tarr,
                                         source=obs.source, mjd=obs.mjd, polrep=obs_in.polrep,
                                         ampcal=ampcal, phasecal=phasecal, opacitycal=opacitycal, dcal=dcal, frcal=frcal,
                                         timetype=obs.timetype, scantable=obs.scans)

            if inv_jones:
                obsdata = simobs.apply_jones_inverse(obs, opacitycal=opacitycal, dcal=dcal, frcal=frcal)

                obs =  ehtim.obsdata.Obsdata(obs.ra, obs.dec, obs.rf, obs.bw, obsdata, obs.tarr,
github achael / eht-imaging / ehtim / image.py View on Github external
Args:
               uv (ndarray): an array of uv points
               sgrscat (bool): if True, the visibilites will be blurred by the Sgr A* scattering kernel
               polrep_obs (str): 'stokes' or 'circ' sets the data polarimetric representtion

               ttype (str): if "fast" or "nfft" use FFT to produce visibilities. Else "direct" for DTFT
               fft_pad_factor (float): zero pad the image to fft_pad_factor * image size in FFT

           Returns:
               (list): a list of [I,Q,U,V] visibilities
        """

        if polrep_obs not in ['stokes','circ']:
            raise Exception("polrep_obs must be either 'stokes' or 'circ'")

        data = simobs.sample_vis(self, uv, sgrscat=sgrscat, polrep_obs=polrep_obs,
                                       ttype=ttype, cache=cache, fft_pad_factor=fft_pad_factor)
        return data
github achael / eht-imaging / ehtim / image.py View on Github external
caltable_path (string): The path and prefix that a caltable is saved with if adding noise through a Jones matrix
               seed (int): seeds the random component of the noise terms. do not set to 0!

           Returns:
               (Obsdata): an observation object
        """

        if seed!=False:
            np.random.seed(seed=seed)

        obs = self.observe_same_nonoise(obs_in, sgrscat=sgrscat, ttype=ttype, fft_pad_factor=fft_pad_factor)

        # Jones Matrix Corruption & Calibration
        if jones:
            obsdata = simobs.add_jones_and_noise(obs, add_th_noise=add_th_noise,
                                                 opacitycal=opacitycal, ampcal=ampcal,
                                                 phasecal=phasecal, dcal=dcal, frcal=frcal, rlgaincal=rlgaincal,
                                                 stabilize_scan_phase=stabilize_scan_phase,
                                                 stabilize_scan_amp=stabilize_scan_amp, neggains=neggains,
                                                 gainp=gainp, taup=taup, gain_offset=gain_offset,
                                                 dterm_offset=dterm_offset,
                                                 caltable_path=caltable_path, seed=seed)

            obs =  ehtim.obsdata.Obsdata(obs.ra, obs.dec, obs.rf, obs.bw, obsdata, obs.tarr,
                                         source=obs.source, mjd=obs.mjd, polrep=obs_in.polrep,
                                         ampcal=ampcal, phasecal=phasecal, opacitycal=opacitycal, dcal=dcal, frcal=frcal,
                                         timetype=obs.timetype, scantable=obs.scans)

            if inv_jones:
                obsdata = simobs.apply_jones_inverse(obs, opacitycal=opacitycal, dcal=dcal, frcal=frcal)
github achael / eht-imaging / ehtim / image.py View on Github external
if (np.abs(self.ra - obs.ra) > tolerance) or (np.abs(self.dec - obs.dec) > tolerance):
            raise Exception("Image coordinates are not the same as observtion coordinates!")
        if (np.abs(self.rf - obs.rf)/obs.rf > tolerance):
            raise Exception("Image frequency is not the same as observation frequency!")

        if ttype=='direct' or ttype=='fast' or ttype=='nfft':
            print("Producing clean visibilities from image with " + ttype + " FT . . . ")
        else:
            raise Exception("ttype=%s, options for ttype are 'direct', 'fast', 'nfft'"%ttype)

        # Copy data to be safe
        obsdata = copy.deepcopy(obs.data)

        # Extract uv datasample
        uv = recarr_to_ndarr(obsdata[['u','v']],'f8')
        data = simobs.sample_vis(self, uv, sgrscat=sgrscat, polrep_obs=obs.polrep,
                                       ttype=ttype, cache=cache, fft_pad_factor=fft_pad_factor)

        # put visibilities into the obsdata
        if obs.polrep=='stokes':
            obsdata['vis'] = data[0]
            if not(data[1] is None):
                obsdata['qvis'] = data[1]
                obsdata['uvis'] = data[2]
                obsdata['vvis'] = data[3]

        elif obs.polrep=='circ':
            obsdata['rrvis'] = data[0]
            if not(data[1] is None):
                obsdata['llvis'] = data[1]
            if not(data[2] is None):
                obsdata['rlvis'] = data[2]
github achael / eht-imaging / ehtim / movie.py View on Github external
for i in range(len(obslist)):
            obsdata = obslist[i]

            # Frame number
            mjd = obsmjds[i]
            n = int(np.floor((mjd - mjdstart) * 86400. / self.framedur))

            if (n >= len(self.frames)):
                if repeat: n = np.mod(n, len(self.frames))
                else: raise Exception("Obs times outside of movie range of MJD %f - %f" % (mjdstart, mjdend))


            # Get the frame visibilities
            uv = recarr_to_ndarr(obsdata[['u','v']],'f8')
            im = self.get_frame(n)
            data = simobs.sample_vis(im, uv, sgrscat=sgrscat, polrep_obs=obs.polrep,
                                         ttype=ttype, fft_pad_factor=fft_pad_factor, zero_empty_pol=True)

            # Put visibilities into the obsdata
            if obs.polrep=='stokes':
                obsdata['vis'] = data[0]
                if not(data[1] is None):
                    obsdata['qvis'] = data[1]
                    obsdata['uvis'] = data[2]
                    obsdata['vvis'] = data[3]

            elif obs.polrep=='circ':
                obsdata['rrvis'] = data[0]
                if not(data[1] is None):
                    obsdata['llvis'] = data[1]
                if not(data[2] is None):
                    obsdata['rlvis'] = data[2]