def gen_photons_per_src(self, utc_date, radio, config, n_samp=1): """ Generate n_samp photons per source""" sources = [] # for src in self.known_objects: if self.l1_catalog: for src in get_L1_srcs(utc_date): if src["el"] > self.l1_elevation_threshold: l = len(self.l1_allowed) if (l == 0) or (src["name"] in self.l1_allowed["names"]): if l != 0: s_str = self.l1_allowed["strength_log10"][ self.l1_allowed["names"].index(src["name"]) ] # print(s_str, type(s_str)) amplitude = np.power(10, s_str) else: amplitude = 1.0 print(src["name"], src["az"], src["el"]) sources.append( simulation_source.SimulationSource( r=src["r"], amplitude=amplitude, azimuth=angle.from_dms(src["az"]), elevation=angle.from_dms(src["el"]), sample_duration=radio.n_samples / radio.ref_freq, ) ) # print('here') for src in self.known_objects: print("extra", src) # for src in self.get_src_objects(location.get_loc(config), utc_date): ra, declination = src.radec(utc_date) dx, dy = np.random.multivariate_normal( [0.0, 0.0], np.identity(2) * np.power(src.width, 2.0), n_samp ).T for j in range(n_samp): el, az = location.get_loc(config).equatorial_to_horizontal( utc_date, ra + angle.from_dms(dx[j]), declination + angle.from_dms(dy[j]), ) sources.append( simulation_source.SimulationSource( r=src.r, amplitude=src.jansky(utc_date) / self.get_int_src_flux(utc_date) * 1.0 / n_samp, azimuth=az, elevation=el, sample_duration=radio.n_samples / radio.ref_freq, ) ) print(len(sources)) return sources
def gen_n_photons(self, config, utc_date, radio, n=10): """ Generate a total of n photons. Sources with more jansky will contribute more photons""" cumulativ_src_flux = self.get_cum_src_flux(utc_date) int_src_flux = cumulativ_src_flux[-1] rel_noise_flux = 0.0 tot_flux = int_src_flux * (1.0 + rel_noise_flux) src_identifier = np.random.uniform(0.0, tot_flux, n) hi, _ = np.histogram(src_identifier, bins=cumulativ_src_flux) ret = [] for src_num, count in enumerate(hi): src = self.known_objects[src_num] # Assume the sky is flat. # this will also cause problems at problems at boundaries of dec. dx, dy = np.random.multivariate_normal( [0.0, 0.0], np.identity(2) * np.power(src.width, 2.0), count ).T ra, declination = src.radec(utc_date) for j in range(count): el, az = location.get_loc(config).equatorial_to_horizontal( utc_date, ra + angle.from_dms(dx[j]), declination + angle.from_dms(dy[j]), ) ret.append( simulation_source.SimulationSource( amplitude=1.0 / n, azimuth=az, elevation=el, sample_duration=radio.n_samples / radio.ref_freq, ) ) return ret
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)
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()
def gen_beam( self, utc_date_init, utc_date_obs, config, radio, az_deg=20.0, el_deg=80.0 ): """ Generate point source with constant at RA and DEC according to given az and el at time utc_date_init""" sources = [] ra, dec = location.get_loc(config).horizontal_to_equatorial( utc_date_init, angle.from_dms(el_deg), angle.from_dms(az_deg) ) src = radio_source.CosmicSource(ra, dec) el, az = src.to_horizontal(location.get_loc(config), utc_date_obs) sources.append( simulation_source.SimulationSource( amplitude=1.0, azimuth=az, elevation=el, sample_duration=radio.n_samples / radio.ref_freq, ) ) return sources
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()
from tart.simulation import antennas from tart.simulation import spectrum from tart.imaging import antenna_model from tart.util import angle from tart.simulation.radio import * config = settings.Settings("../test/test_telescope_config.json") num_ant = config.get_num_antenna() noiselvls = 0.1 * np.ones(num_ant) rad = Max2769B(n_samples=2**14, noise_level=noiselvls) sources = [ simulation_source.SimulationSource( amplitude=1.0, azimuth=angle.from_dms(0.0), elevation=angle.from_dms(90.0), sample_duration=rad.sample_duration, ) ] ants = [ antennas.Antenna(config.get_loc(), pos) for pos in config.ant_positions ] ant_models = [antenna_model.GpsPatchAntenna() for i in range(num_ant)] utc_date = datetime.datetime.utcnow() plt.figure() ant_sigs = antennas.antennas_signal(ants, ant_models, sources, rad.timebase) rad_sig_full = rad.sampled_signal(ant_sigs[0, :], 0, rad.sample_duration) obs_full = rad.get_full_obs(ant_sigs, utc_date, config)
# -*- coding: utf-8 -*- import numpy as np from tart.simulation import radio from tart.simulation import antennas from tart.simulation import simulation_source from tart.operation import settings if __name__ == "__main__": import numpy as np rad = radio.Max2769B(sample_duration=1e-5) sources = [ simulation_source.SimulationSource( amplitude=1.0, elevation=30.0, azimuth=0.0, sample_duration=rad.sample_duration, ) ] print("Radio Sampling Rate %g" % rad.sampling_rate) config = settings.Settings("../../tools/operation/telescope_config.json") ants = [ antennas.Antenna(config.get_loc(), pos) for pos in config.ant_positions ] ant_sigs = antennas.antennas_new(ants, sources, rad.timebase) num_radio_samples = (len(rad.timebase) / rad.freq_mult) + 1 sampled_signals = np.zeros((config.get_num_antenna(), num_radio_samples)) for i in range(0, config.get_num_antenna()):
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)