コード例 #1
0
    def setUp(self):

        # rad = radio.Max2769B(noise_level=0.)
        utc_date = datetime.datetime.utcnow()
        self.config = settings.from_file(TEST_CONFIG)
        self.config.load_antenna_positions(
            cal_ant_positions_file=TEST_ANTENNA_POSITIONS)

        rad = radio.Max2769B(
            noise_level=[0.0 for _ in range(self.config.get_num_antenna())])
        sources = [
            simulation_source.SimulationSource(
                r=1e9,
                amplitude=1.0,
                azimuth=angle.from_dms(2.0),
                elevation=angle.from_dms(50.0),
                sample_duration=rad.sample_duration,
            )
        ]
        ant_models = [
            antenna_model.GpsPatchAntenna()
            for i in range(self.config.get_num_antenna())
        ]
        ants = [
            antennas.Antenna(self.config.get_loc(), pos)
            for pos in self.config.get_antenna_positions()
        ]
        self.timebase = np.arange(0, rad.sample_duration,
                                  1.0 / rad.sampling_rate)

        ant_sigs = antennas.antennas_signal(ants, ant_models, sources,
                                            self.timebase)
        self.obs = rad.get_full_obs(ant_sigs, utc_date, self.config,
                                    self.timebase)
コード例 #2
0
  def setUp(self):
    self.utc_date = datetime.datetime.utcnow()
    self.config = settings.from_file(TEST_CONFIG)
    self.config.load_antenna_positions(cal_ant_positions_file=TEST_ANTENNA_POSITIONS)

    self.rad = radio.Max2769B(noise_level=[0. for _ in range(self.config.get_num_antenna())])
    self.sources = [simulation_source.SimulationSource(r=1e9,amplitude = 1.0, azimuth = angle.from_dms(2.0), elevation = angle.from_dms(50.0), sample_duration = self.rad.sample_duration)]
    self.ants = [antennas.Antenna(self.config.get_loc(), pos) for pos in self.config.get_antenna_positions()]
    self.ant_models = [antenna_model.GpsPatchAntenna() for i in range(self.config.get_num_antenna())]
    self.cor = correlator.Correlator()
    self.timebase = np.arange(0, self.rad.sample_duration, 1.0/self.rad.sampling_rate)

    ant_sigs_full = antennas.antennas_signal(self.ants, self.ant_models, self.sources, self.timebase)
    obs = self.rad.get_full_obs(ant_sigs_full, self.utc_date, self.config, self.timebase)
    vis = self.cor.correlate(obs)
    self.full_vis = np.array(vis.v)

    ant_sigs_simp = antennas.antennas_simplified_signal(self.ants, self.ant_models, self.sources, self.rad.baseband_timebase, self.rad.int_freq)
    obs = self.rad.get_simplified_obs(ant_sigs_simp, self.utc_date, config = self.config)
    vis2 = self.cor.correlate(obs)
    self.sim_vis = np.array(vis2.v)

    plt.figure(figsize=(4,4))
    plt.scatter(self.full_vis.real,self.full_vis.imag, label='full')
    plt.scatter(self.sim_vis.real,self.sim_vis.imag, color='red', label='simpl')
    plt.legend()
    plt.show()
コード例 #3
0
ファイル: stream_vis.py プロジェクト: tmolteno/TART
def get_vis_object(data, runtime_config):
    n_samples = 2**runtime_config['vis']['N_samples_exp']
    timestamp = datetime.datetime.utcnow()
    config = settings.from_file(runtime_config['telescope_config_path'])
    num_ant = config.get_num_antenna()
    v = []
    baselines = []
    xnor_cos = data[0:-24:2]
    xnor_sin = data[1:-24:2]
    corr_cos_i_cos_j = get_corr(xnor_cos, n_samples)
    corr_cos_i_sin_j = get_corr(xnor_sin, n_samples)
    means = (data[-24:])/float(n_samples)*2.-1
    #print(means)
    for i in range(0, num_ant):
        for j in range(i+1, num_ant):
            idx = len(baselines)
            baselines.append([i, j])
            v_real = correlator.van_vleck_correction((-means[i]*means[j]) + corr_cos_i_cos_j[idx])
            v_imag = correlator.van_vleck_correction((-means[i]*means[j]) + corr_cos_i_sin_j[idx])
            #v_real = (-means[i]*means[j]) + corr_cos_i_cos_j[idx]
            #v_imag = (-means[i]*means[j]) + corr_cos_i_sin_j[idx]
            v_com = correlator.combine_real_imag(v_real, v_imag)
            v.append(v_com)
    vis = visibility.Visibility(config, timestamp)
    vis.set_visibilities(v, baselines)
    return vis, means, timestamp
コード例 #4
0
ファイル: stream_vis.py プロジェクト: mfkiwl/TART-2769
def get_vis_object(data, runtime_config):
    n_samples = 2**runtime_config['vis']['N_samples_exp']
    timestamp = datetime.datetime.utcnow()
    config = settings.from_file(runtime_config['telescope_config_path'])
    num_ant = config.get_num_antenna()
    v = []
    baselines = []
    xnor_cos = data[0:-24:2]
    xnor_sin = data[1:-24:2]
    corr_cos_i_cos_j = get_corr(xnor_cos, n_samples)
    corr_cos_i_sin_j = get_corr(xnor_sin, n_samples)
    means = (data[-24:])/float(n_samples)*2.-1
    #print(means)
    for i in range(0, num_ant):
        for j in range(i+1, num_ant):
            idx = len(baselines)
            baselines.append([i, j])
            v_real = correlator.van_vleck_correction((-means[i]*means[j]) + corr_cos_i_cos_j[idx])
            v_imag = correlator.van_vleck_correction((-means[i]*means[j]) + corr_cos_i_sin_j[idx])
            #v_real = (-means[i]*means[j]) + corr_cos_i_cos_j[idx]
            #v_imag = (-means[i]*means[j]) + corr_cos_i_sin_j[idx]
            v_com = correlator.combine_real_imag(v_real, v_imag)
            v.append(v_com)
    vis = visibility.Visibility(config, timestamp)
    vis.set_visibilities(v, baselines)
    return vis, means, timestamp
コード例 #5
0
ファイル: test_observation.py プロジェクト: tmolteno/TART
    def setUp(self):

        ts = datetime.datetime.utcnow()
        self.config = settings.from_file('tart/test/test_telescope_config.json')
        self.test_len = 2**8
        # generate some fake data
        self.data = [np.random.randint(0,2,self.test_len) for _ in range(self.config.get_num_antenna())]
        self.obs = Observation(timestamp=ts, config=self.config, data=self.data)
コード例 #6
0
    def setUp(self):
        self.utc_date = datetime.datetime.utcnow()
        self.config = settings.from_file(TEST_CONFIG)
        self.config.load_antenna_positions(
            cal_ant_positions_file=TEST_ANTENNA_POSITIONS)

        self.rad = radio.Max2769B(
            noise_level=[0.0 for _ in range(self.config.get_num_antenna())])
        self.sources = [
            simulation_source.SimulationSource(
                r=1e9,
                amplitude=1.0,
                azimuth=angle.from_dms(2.0),
                elevation=angle.from_dms(50.0),
                sample_duration=self.rad.sample_duration,
            )
        ]
        self.ants = [
            antennas.Antenna(self.config.get_loc(), pos)
            for pos in self.config.get_antenna_positions()
        ]
        self.ant_models = [
            antenna_model.GpsPatchAntenna()
            for i in range(self.config.get_num_antenna())
        ]
        self.cor = correlator.Correlator()
        self.timebase = np.arange(0, self.rad.sample_duration,
                                  1.0 / self.rad.sampling_rate)

        ant_sigs_full = antennas.antennas_signal(self.ants, self.ant_models,
                                                 self.sources, self.timebase)
        obs = self.rad.get_full_obs(ant_sigs_full, self.utc_date, self.config,
                                    self.timebase)
        vis = self.cor.correlate(obs)
        self.full_vis = np.array(vis.v)

        ant_sigs_simp = antennas.antennas_simplified_signal(
            self.ants,
            self.ant_models,
            self.sources,
            self.rad.baseband_timebase,
            self.rad.int_freq,
        )
        obs = self.rad.get_simplified_obs(ant_sigs_simp,
                                          self.utc_date,
                                          config=self.config)
        vis2 = self.cor.correlate(obs)
        self.sim_vis = np.array(vis2.v)

        plt.figure(figsize=(4, 4))
        plt.scatter(self.full_vis.real, self.full_vis.imag, label="full")
        plt.scatter(self.sim_vis.real,
                    self.sim_vis.imag,
                    color="red",
                    label="simpl")
        plt.legend()
        plt.show()
コード例 #7
0
ファイル: test_radio.py プロジェクト: tmolteno/TART
 def setUp(self):
   self.config = settings.from_file('./tart/test/test_telescope_config.json')
   self.config.load_antenna_positions(cal_ant_positions_file='./tart/test/test_calibrated_antenna_positions.json')
   # noiselvls =  0.1.*np.ones(config.get_num_antenna())
   num_ant = self.config.get_num_antenna()
   noiselvls =  0. * np.ones(num_ant)
   self.rad = Max2769B(noise_level = noiselvls)
   self.sources = [simulation_source.SimulationSource(r=1e9,amplitude = 1.0, azimuth = angle.from_dms(0.), elevation = angle.from_dms(90.), sample_duration = self.rad.sample_duration)]
   self.ants = [antennas.Antenna(self.config.get_loc(), pos) for pos in self.config.get_antenna_positions()]
   self.ant_models = [antenna_model.GpsPatchAntenna() for i in range(num_ant)]
   self.utc_date = datetime.datetime.utcnow()
コード例 #8
0
def dummy_vis():
    config = settings.from_file("tart/test/test_telescope_config.json")
    ret = visibility.Visibility(config=config, timestamp=datetime.datetime.utcnow())
    b = []
    v = []
    for j in range(24):
        for i in range(24):
            if i > j:
                b.append([j, i])
                v.append(np.random.uniform(0, 1) + np.random.uniform(0, 1) * (1.0j))
    ret.set_visibilities(b=b, v=np.array(v))
    return ret
コード例 #9
0
ファイル: service.py プロジェクト: tmolteno/TART
def calibrate_from_vis(cal_measurements, runtime_config):
    MODE = 'mini'
    #simp (use only when noise present)\
    #mini, perfect visibilities.\
    #full

    SETTINGS = settings.from_file(runtime_config['telescope_config_path'])
    loc = location.get_loc(SETTINGS)
    
    ANTS = [antennas.Antenna(loc, pos)
            for pos in runtime_config['antenna_positions']]
    ANT_MODELS = [antenna_model.GpsPatchAntenna() for i in range(SETTINGS.get_num_antenna())]
    NOISE_LVLS = 0.0 * np.ones(SETTINGS.get_num_antenna())
    RAD = radio.Max2769B(n_samples=2**12, noise_level=NOISE_LVLS)
    COR = correlator.Correlator()

    global msd_vis, sim_vis
    sim_vis = {}
    msd_vis = {}
    sim_sky = {}

    for m in cal_measurements:
        timestamp = dateutil.parser.parse(m['data']['timestamp'])

        key = '%f,%f,%s' % (m['el'], m['az'], timestamp)
        # Generate model visibilities according to specified point source positions
        sim_sky[key] = skymodel.Skymodel(0, location=loc,
                                         gps=0, thesun=0, known_cosmic=0)
        sim_sky[key].add_src(radio_source.ArtificialSource(loc, timestamp, r=100.0, el=m['el'], az=m['az']))
        v_sim = get_vis(sim_sky[key], COR, RAD, ANTS, ANT_MODELS, SETTINGS, timestamp, mode=MODE)
        sim_vis[key] = calibration.CalibratedVisibility(v_sim)

        # Construct (un)calibrated visibility objects from received measured visibilities
        vis = vis_object_from_response(m['data']['vis']['data'], timestamp, SETTINGS)
        msd_vis[key] = calibration.CalibratedVisibility(vis)

    # Define initial optimisation paramters

    opt_param = np.ones(46)
    opt_param[:23] = np.ones(23)
    opt_param[23:] = np.zeros(23)

    # Run optimisation
    RES = minimize(optimize_phaseNgain, opt_param)

    utc_date = datetime.datetime.utcnow()
    phases = list(msd_vis.values())[0].get_phase_offset(np.arange(24))
    gains = list(msd_vis.values())[0].get_gain(np.arange(24))

    #content =  msd_vis.values()[0].to_json(filename='/dev/null')
    db.insert_gain(utc_date, gains, phases)
    db.update_calibration_process_state('idle')
    return {}
コード例 #10
0
    def setUp(self):

        ts = datetime.datetime.utcnow()
        self.config = settings.from_file(
            'tart/test/test_telescope_config.json')
        self.test_len = 2**8
        # generate some fake data
        self.data = [
            np.random.randint(0, 2, self.test_len)
            for _ in range(self.config.get_num_antenna())
        ]
        self.obs = Observation(timestamp=ts,
                               config=self.config,
                               data=self.data)
コード例 #11
0
  def setUp(self):

    # rad = radio.Max2769B(noise_level=0.)
    utc_date = datetime.datetime.utcnow()
    self.config = settings.from_file(TEST_CONFIG)
    self.config.load_antenna_positions(cal_ant_positions_file=TEST_ANTENNA_POSITIONS)

    rad = radio.Max2769B(noise_level=[0. for _ in range(self.config.get_num_antenna())])
    sources = [simulation_source.SimulationSource(r=1e9, amplitude = 1.0, azimuth = angle.from_dms(2.0), elevation = angle.from_dms(50.0), sample_duration = rad.sample_duration)]
    ant_models = [antenna_model.GpsPatchAntenna() for i in range(self.config.get_num_antenna())]
    ants = [antennas.Antenna(self.config.get_loc(), pos) for pos in self.config.get_antenna_positions()]
    self.timebase = np.arange(0, rad.sample_duration, 1.0/rad.sampling_rate)

    ant_sigs = antennas.antennas_signal(ants, ant_models, sources, self.timebase)
    self.obs = rad.get_full_obs(ant_sigs, utc_date, self.config, self.timebase)
コード例 #12
0
def run_acquire_raw(tart, runtime_config):
    runtime_config['acquire'] = 1
    tart.reset()
    tart.debug(on=not runtime_config['acquire'], \
                shift=runtime_config['shifter'], \
                count=runtime_config['counter'], \
                noisy=runtime_config['verbose'])
    tart.capture(on=True, source=0, noisy=runtime_config['verbose'])
    tart.set_sample_delay(runtime_config['sample_delay'])
    tart.centre(runtime_config['centre'], noisy=runtime_config['verbose'])
    t_stmp, path = create_timestamp_and_path(
        runtime_config['raw']['base_path'])
    tart.start_acquisition(1.1, True)

    while not tart.data_ready():
        tart.pause(duration=0.005, noisy=True)
    print('\nAcquisition complete, beginning read-back.')
    #tart.capture(on=False, noisy=runtime_config['verbose'])

    data = tart.read_data(
        num_words=np.power(2, runtime_config['raw']['N_samples_exp']))

    d, d_json = get_status_json(tart)
    runtime_config['status'] = d
    tart.reset()

    print('reshape antenna data')
    data = np.asarray(data, dtype=np.uint8)
    ant_data = np.flipud(np.unpackbits(data).reshape(-1, 24).T)

    if runtime_config['raw']['save']:
        config = settings.from_file(runtime_config['telescope_config_path'])

        fname = "data_{}.hdf".format(t_stmp.strftime('%Y-%m-%d_%H_%M_%S.%f'))

        filename = path + fname

        obs = observation.Observation(t_stmp, config, savedata=ant_data)
        obs.to_hdf5(filename)
        print(('saved to: ', filename))
        return {'filename': filename, 'sha256': sha256_checksum(filename)}
    return {}
    print('\nDone.')
コード例 #13
0
ファイル: highlevel_modes_api.py プロジェクト: tmolteno/TART
def run_acquire_raw(tart, runtime_config):
    runtime_config['acquire'] = 1
    tart.reset()
    tart.debug(on=not runtime_config['acquire'], \
                shift=runtime_config['shifter'], \
                count=runtime_config['counter'], \
                noisy=runtime_config['verbose'])
    tart.capture(on=True, source=0, noisy=runtime_config['verbose'])
    tart.set_sample_delay(runtime_config['sample_delay'])
    tart.centre(runtime_config['centre'], noisy=runtime_config['verbose'])
    t_stmp, path = create_timestamp_and_path(runtime_config['raw']['base_path'])
    tart.start_acquisition(1.1, True)

    while not tart.data_ready():
        tart.pause(duration=0.005, noisy=True)
    print('\nAcquisition complete, beginning read-back.')
    #tart.capture(on=False, noisy=runtime_config['verbose'])

    data = tart.read_data(num_words=np.power(2, runtime_config['raw']['N_samples_exp']))

    d, d_json = get_status_json(tart)
    runtime_config['status'] = d
    tart.reset()

    print('reshape antenna data')
    data = np.asarray(data,dtype=np.uint8)
    ant_data = np.flipud(np.unpackbits(data).reshape(-1,24).T)

    if runtime_config['raw']['save']:
        config = settings.from_file(runtime_config['telescope_config_path'])
        
        fname = "data_{}.hdf".format(t_stmp.strftime('%Y-%m-%d_%H_%M_%S.%f'))
        
        filename = path + fname

        obs = observation.Observation(t_stmp, config, savedata=ant_data)
        obs.to_hdf5(filename)
        print(('saved to: ', filename))
        return {'filename':filename, 'sha256':sha256_checksum(filename)}
    return {}
    print('\nDone.')
コード例 #14
0
ファイル: test_radio.py プロジェクト: mfkiwl/TART-2769
 def setUp(self):
     self.config = settings.from_file("./tart/test/test_telescope_config.json")
     self.config.load_antenna_positions(
         cal_ant_positions_file="./tart/test/test_calibrated_antenna_positions.json"
     )
     # noiselvls =  0.1.*np.ones(config.get_num_antenna())
     num_ant = self.config.get_num_antenna()
     noiselvls = 0.0 * np.ones(num_ant)
     self.rad = Max2769B(noise_level=noiselvls)
     self.sources = [
         simulation_source.SimulationSource(
             r=1e9,
             amplitude=1.0,
             azimuth=angle.from_dms(0.0),
             elevation=angle.from_dms(90.0),
             sample_duration=self.rad.sample_duration,
         )
     ]
     self.ants = [
         antennas.Antenna(self.config.get_loc(), pos)
         for pos in self.config.get_antenna_positions()
     ]
     self.ant_models = [antenna_model.GpsPatchAntenna() for i in range(num_ant)]
     self.utc_date = datetime.datetime.utcnow()
コード例 #15
0
 def test_load(self):
     ts = datetime.datetime.utcnow()
     config = from_file('tart/test/test_telescope_config.json')
     self.assertTrue(config.Dict is not None)
コード例 #16
0
ファイル: test_correlator.py プロジェクト: tmolteno/TART
  def test_correlator_simp(self):
    from tart.operation import settings
    from tart.simulation import simulation_source
    from tart.util import angle
    from tart.util import constants
    from tart.simulation import radio
    import datetime


    import numpy as np
    N = 20
    a0 = np.random.randint(0,2,2**N)
    a1 = np.random.randint(0,2,2**N)
    self.assertAlmostEqual(corr_b(a0,a1,N), corr_b_pat(a0,a1))
    
    from tart.operation import observation
    from tart.operation import settings
    import datetime
    t = datetime.datetime.utcnow()
    c = settings.from_file(TEST_SCOPE_CONFIG)
    c.Dict['num_antenna'] = 2
    d = [a0,a1]
    o = observation.Observation(timestamp=t, config=c, data=d)
    
    cor = Correlator(van_vleck_corr=True)
    vis_a = cor.correlate(o,mode='roll')
    #vis_b = cor.correlate_roll(o)
    vis_c = cor.correlate(o,mode='fftw_hilbert')
    #print(vis_a.vis(0,1), vis_b.vis(0,1), vis_c.vis(0,1))

    sample_duration = 16.02e-1
    sample_duration = 4e-1
    config = settings.from_file(TEST_SCOPE_CONFIG)
    rad = radio.Max2769B(noise_level = np.ones(config.get_num_antenna()))
    src = simulation_source.SimulationSource(amplitude = 1., azimuth = angle.from_dms(0.), elevation = angle.from_dms(5.), sample_duration = sample_duration)
    fc0 = rad.int_freq

    int_sig = np.exp(-2.0j*np.pi*fc0*rad.baseband_timebase)

    def add_noise(sig):
      return sig + np.random.normal(0.,0.1,len(sig))

    def sig2binary(signal):
      return np.array([1. if (x>=0) else 0. for x in signal])

    antsig1 = src.s_baseband(rad.baseband_timebase) * int_sig

    for fraction in np.random.uniform(-np.pi/3,np.pi/3,10):
      dt = ((2.*np.pi)/src.omega)*fraction
      print('dt', dt)
      antsig2 = (src.s_baseband(rad.baseband_timebase+dt) * int_sig * np.exp(1.0j*src.omega*dt))

      antsig1 = add_noise(antsig1.real)
      antsig2 = add_noise(antsig2.real)

      d = [sig2binary(antsig1),sig2binary(antsig2)]
      obs = observation.Observation(timestamp=t, config=c, data=d)

      vis_a = cor.correlate(o,mode='roll')
      #vis_b = cor.correlate_roll(o)
      vis_c = cor.correlate(o,mode='fftw_hilbert')
      vis_d = cor.correlate(o,mode='fftw_hilbert_sign')
      
      #print(vis_a.vis(0,1),vis_b.vis(0,1))
      print(vis_a.vis(0,1),vis_c.vis(0,1))
      print(vis_a.vis(0,1),vis_d.vis(0,1))
      #print(vis_b.vis(0,1),vis_c.vis(0,1))
      #print(vis_b.vis(0,1),vis_d.vis(0,1))
      print(vis_c.vis(0,1),vis_d.vis(0,1))
      
      #self.assertAlmostEqual(vis_a.vis(0,1),vis_b.vis(0,1),4)
      self.assertAlmostEqual(vis_a.vis(0,1),vis_c.vis(0,1),4)
      self.assertAlmostEqual(vis_a.vis(0,1),vis_d.vis(0,1),4)
      #self.assertAlmostEqual(vis_b.vis(0,1),vis_c.vis(0,1),4)
      #self.assertAlmostEqual(vis_b.vis(0,1),vis_d.vis(0,1),4)
      self.assertAlmostEqual(vis_c.vis(0,1),vis_d.vis(0,1),4)
             

      
      vis = cor.correlate(obs,mode='roll')
      cor_out = angle.from_dms(angle.wrap_360(np.angle(vis.v[0], deg=True)))
      input_angle = angle.from_dms(angle.wrap_360(dt*src.omega*180./np.pi)) #.to_degrees()
      #print(cor_out, input_angle)
      #print(type(cor_out),  type(input_angle))
      #print(cor_out - input_angle)
      self.assertLess(np.abs((cor_out - input_angle).to_degrees()), 30.)
コード例 #17
0
ファイル: test_settings.py プロジェクト: tmolteno/TART
 def test_load(self):
     ts = datetime.datetime.utcnow()
     config = from_file('tart/test/test_telescope_config.json')
     self.assertTrue(config.Dict is not None)
コード例 #18
0
    def test_correlator_simp(self):
        from tart.operation import settings
        from tart.simulation import simulation_source
        from tart.util import angle
        from tart.util import constants
        from tart.simulation import radio
        import datetime

        import numpy as np

        N = 20
        a0 = np.random.randint(0, 2, 2**N)
        a1 = np.random.randint(0, 2, 2**N)
        self.assertAlmostEqual(corr_b(a0, a1, N), corr_b_pat(a0, a1))

        from tart.operation import observation
        from tart.operation import settings
        import datetime

        t = datetime.datetime.utcnow()
        c = settings.from_file(TEST_SCOPE_CONFIG)
        c.Dict["num_antenna"] = 2
        d = [a0, a1]
        o = observation.Observation(timestamp=t, config=c, data=d)

        cor = Correlator(van_vleck_corr=True)
        vis_a = cor.correlate(o, mode="roll")
        # vis_b = cor.correlate_roll(o)
        vis_c = cor.correlate(o, mode="fftw_hilbert")
        # print(vis_a.vis(0,1), vis_b.vis(0,1), vis_c.vis(0,1))

        sample_duration = 16.02e-1
        sample_duration = 4e-1
        config = settings.from_file(TEST_SCOPE_CONFIG)
        rad = radio.Max2769B(noise_level=np.ones(config.get_num_antenna()))
        src = simulation_source.SimulationSource(
            amplitude=1.0,
            azimuth=angle.from_dms(0.0),
            elevation=angle.from_dms(5.0),
            sample_duration=sample_duration,
        )
        fc0 = rad.int_freq

        int_sig = np.exp(-2.0j * np.pi * fc0 * rad.baseband_timebase)

        def add_noise(sig):
            return sig + np.random.normal(0.0, 0.1, len(sig))

        def sig2binary(signal):
            return np.array([1.0 if (x >= 0) else 0.0 for x in signal])

        antsig1 = src.s_baseband(rad.baseband_timebase) * int_sig

        for fraction in np.random.uniform(-np.pi / 3, np.pi / 3, 10):
            dt = ((2.0 * np.pi) / src.omega) * fraction
            print("dt", dt)
            antsig2 = (src.s_baseband(rad.baseband_timebase + dt) * int_sig *
                       np.exp(1.0j * src.omega * dt))

            antsig1 = add_noise(antsig1.real)
            antsig2 = add_noise(antsig2.real)

            d = [sig2binary(antsig1), sig2binary(antsig2)]
            obs = observation.Observation(timestamp=t, config=c, data=d)

            vis_a = cor.correlate(o, mode="roll")
            # vis_b = cor.correlate_roll(o)
            vis_c = cor.correlate(o, mode="fftw_hilbert")
            vis_d = cor.correlate(o, mode="fftw_hilbert_sign")

            # print(vis_a.vis(0,1),vis_b.vis(0,1))
            print(vis_a.vis(0, 1), vis_c.vis(0, 1))
            print(vis_a.vis(0, 1), vis_d.vis(0, 1))
            # print(vis_b.vis(0,1),vis_c.vis(0,1))
            # print(vis_b.vis(0,1),vis_d.vis(0,1))
            print(vis_c.vis(0, 1), vis_d.vis(0, 1))

            # self.assertAlmostEqual(vis_a.vis(0,1),vis_b.vis(0,1),4)
            self.assertAlmostEqual(vis_a.vis(0, 1), vis_c.vis(0, 1), 4)
            self.assertAlmostEqual(vis_a.vis(0, 1), vis_d.vis(0, 1), 4)
            # self.assertAlmostEqual(vis_b.vis(0,1),vis_c.vis(0,1),4)
            # self.assertAlmostEqual(vis_b.vis(0,1),vis_d.vis(0,1),4)
            self.assertAlmostEqual(vis_c.vis(0, 1), vis_d.vis(0, 1), 4)

            vis = cor.correlate(obs, mode="roll")
            cor_out = angle.from_dms(
                angle.wrap_360(np.angle(vis.v[0], deg=True)))
            input_angle = angle.from_dms(
                angle.wrap_360(dt * src.omega * 180.0 /
                               np.pi))  # .to_degrees()
            # print(cor_out, input_angle)
            # print(type(cor_out),  type(input_angle))
            # print(cor_out - input_angle)
            self.assertLess(np.abs((cor_out - input_angle).to_degrees()), 30.0)
コード例 #19
0
ファイル: service.py プロジェクト: mfkiwl/TART-2769
def calibrate_from_vis(cal_measurements, runtime_config):
    MODE = 'mini'
    #simp (use only when noise present)\
    #mini, perfect visibilities.\
    #full

    SETTINGS = settings.from_file(runtime_config['telescope_config_path'])
    loc = location.get_loc(SETTINGS)

    ANTS = [
        antennas.Antenna(loc, pos)
        for pos in runtime_config['antenna_positions']
    ]
    ANT_MODELS = [
        antenna_model.GpsPatchAntenna()
        for i in range(SETTINGS.get_num_antenna())
    ]
    NOISE_LVLS = 0.0 * np.ones(SETTINGS.get_num_antenna())
    RAD = radio.Max2769B(n_samples=2**12, noise_level=NOISE_LVLS)
    COR = correlator.Correlator()

    global msd_vis, sim_vis
    sim_vis = {}
    msd_vis = {}
    sim_sky = {}

    for m in cal_measurements:
        timestamp = dateutil.parser.parse(m['data']['timestamp'])

        key = '%f,%f,%s' % (m['el'], m['az'], timestamp)
        # Generate model visibilities according to specified point source positions
        sim_sky[key] = skymodel.Skymodel(0,
                                         location=loc,
                                         gps=0,
                                         thesun=0,
                                         known_cosmic=0)
        sim_sky[key].add_src(
            radio_source.ArtificialSource(loc,
                                          timestamp,
                                          r=100.0,
                                          el=m['el'],
                                          az=m['az']))
        v_sim = get_vis(sim_sky[key],
                        COR,
                        RAD,
                        ANTS,
                        ANT_MODELS,
                        SETTINGS,
                        timestamp,
                        mode=MODE)
        sim_vis[key] = calibration.CalibratedVisibility(v_sim)

        # Construct (un)calibrated visibility objects from received measured visibilities
        vis = vis_object_from_response(m['data']['vis']['data'], timestamp,
                                       SETTINGS)
        msd_vis[key] = calibration.CalibratedVisibility(vis)

    # Define initial optimisation paramters

    opt_param = np.ones(46)
    opt_param[:23] = np.ones(23)
    opt_param[23:] = np.zeros(23)

    # Run optimisation
    RES = minimize(optimize_phaseNgain, opt_param)

    utc_date = datetime.datetime.utcnow()
    phases = list(msd_vis.values())[0].get_phase_offset(np.arange(24))
    gains = list(msd_vis.values())[0].get_gain(np.arange(24))

    #content =  msd_vis.values()[0].to_json(filename='/dev/null')
    db.insert_gain(utc_date, gains, phases)
    db.update_calibration_process_state('idle')
    return {}