def test12(): tel = SKA1_low() tel.dec_deg = tel.lat_deg tel.obs_length_h = 0 tel.num_times = 1 tel.grid_cell_size_m = tel.station_diameter_m / 2 def taper_r_profile(r, amps): n = amps.shape[0] i = np.round(r * (n - 1)).astype(np.int) return amps[i] from scipy import interpolate n = 100 x = np.linspace(0, 1, n) y = taylor_win(n, -28) f = interpolate.interp1d(x, y, kind='cubic') # tel.plot_min_sep(500, f) tel.num_trials = 3 tel.trail_timeout_s = 20 tel.add_tapered_core(150, 500, f) try_id = tel.layouts['tapered_core']['info']['attempt_id'] info = tel.layouts['tapered_core']['info'][try_id] print(try_id, info.keys(), info['max_tries'], info['total_tries'], info['time_taken'], info['total_tries']/info['time_taken'])
def test1(): tel = SKA1_low() tel.dec_deg = tel.lat_deg tel.obs_length_h = 0 tel.num_times = 1 tel.grid_cell_size_m = tel.station_diameter_m / 2 def taper_r_profile(r, num_amps, amps): """0.0 <= r < 1.0""" i = int(r * num_amps) return amps[i] # from scipy import interpolate n = 5000 y = taylor_win(n, -28) # x = np.linspace(0, 1, n) # f = interpolate.interp1d(x, y, kind='cubic') opts = dict(num_amps=n, amps=y) tel.num_trials = 1 tel.trail_timeout_s = 2 tel.add_ska1_v5(r_max=5000) # tel.uv_sensitivity(100, 100, 5000, log_bins=True, ) tel.plot_grid(show=True) # tel.eval_psf_rms_r(100) # tel.uv_hist(100, b_max=1000, plot=True, log_bins=True, bar=True) # tel.uv_sensitivity(100) # tel.eval_psf_rms_r(100) tel.eval_psf(plot1d=True)
def plot_core_profile(): def get_taper_profile(taper_func, r, **kwargs): if kwargs is not None: t = taper_func(r, **kwargs) else: t = taper_func(r) return t sll = -28 n_taylor = 10000 r = np.linspace(0, 1, 100) t1 = get_taper_profile(AnalyseUnwrapV5._taper_r_profile, r, amps=taylor_win(n_taylor, sll), taper_r_min=0.0) import matplotlib.pyplot as plt fig, ax = plt.subplots(figsize=(8, 5)) ax.plot(r, 35 / t1, 'k-', label='v7 core taper profile') ax.set_xlabel('Fractional radius') ax.set_ylabel('Minimum station separation (m)') ax.grid() ax.set_ylim(34) # ax.legend(loc='best') fig.savefig('station_min_dist.png') plt.close(fig)
def _add_core_01(tel, num_stations=224, core_radius_m=510, sll=-28): n_taylor = 10000 tel.num_trials = 4 tel.trial_timeout_s = 45.0 tel.seed = 40011245 args = dict(amps=taylor_win(n_taylor, sll), taper_r_min=0.0) tel.add_tapered_core(num_stations, core_radius_m, AnalyseUnwrapV5._taper_r_profile, **args) # print('seed =', tel.seed) return tel
def test9(): def taper_func_1(r): return 1 - (r / 2)**1.5 def taper_func_2(r, hwhm=1.5): c = hwhm / (2 * log(2))**0.5 return np.exp(-r**2 / (2 * c**2)) def taper_r_profile(r, amps): n = amps.shape[0] # Find the index nearest to r # FIXME(BM) check this is right... i = np.round(r * (n - 1)).astype(np.int) return amps[i] def get_taper_profile(taper_func, r, **kwargs): if kwargs is not None: t = taper_func(r, **kwargs) else: t = taper_func(r) return t r = np.linspace(0, 1, 100) # r = np.random.rand(100) t1 = get_taper_profile(taper_func_1, r) t2 = get_taper_profile(taper_func_2, r, hwhm=0.7) t3 = get_taper_profile(taper_r_profile, r, amps=taylor_win(1000, -22)) fig, ax = plt.subplots() ax.plot(r, t1, 'b.', label='t1') ax.plot(r, t2, 'r.', label='gauss') ax.plot(r, t3, 'g.', label='r profile (taylor)') ax.plot(ax.get_xlim(), [0.5, 0.5], 'r--') ax.plot([0.7, 0.7], ax.get_ylim(), 'r--') ax.grid() ax.legend() plt.show() return # r_max = 500 # n = 11 # sll = -28 # nbar = int(np.ceil(2.0 * (np.arccosh(10**(-sll / 20.0)) / np.pi)**2 + 0.5)) # # r = np.arange(w.shape[0]) * ((r_max * 2) / (n + 1)) # r = np.linspace(0, 1, n) # print(r.shape, w.shape) fig, ax = plt.subplots() ax.plot(r, w, '.-') ax.grid() plt.show()
def test10(): n = 5 x = np.linspace(0, 1, n) y = taylor_win(n, -28) from scipy import interpolate f = interpolate.interp1d(x, y, kind='cubic') x_new = np.random.rand(10000) x_new.sort() fig, ax = plt.subplots() ax.plot(x, y, '+-') ax.plot(x_new, f(x_new), '-') plt.show()
def model08(self, name='model08', add_core=True): """Proposed SKA v6 configuration option 1 4 rings of 21 stations (84 total) r0 = 500m, r5 = 1700m with no ring at r0 72 station arms from r0 = 1700m with no point at 1700 to r21 at 6.4 km (ie 6 stations symmmetric about 6.4km) Note(BM) might have to shrink this a bit to match 1km LV reticulation core of 224 + 6 stations (uniform or tapered up to 500m) """ metrics = Metrics(self.out_dir) # TODO(BM) hybrid of model1 with a custom generated core # and avoiding cable lengths > 1km in arm clusters. # For the log spiral arms also generate from a single arm and rotate # with stride 3 to generate arms. (put 162 - 18? in arms) and # (224 + 18 in the core) to recover some short baselines. from math import log, exp import matplotlib.pyplot as plt tel = SKA1_low_analysis(name + '_r08') tel.station_diameter_m = 35 tel.obs_length_h = self.obs_length_h tel.num_times = self.num_times tel.dec_deg = tel.lat_deg # Core core_radius_m = 480 sll = -24 n_taylor = 10000 tel.num_trials = 2 tel.trial_timeout_s = 30.0 # Inner rings num_rings = 5 num_per_ring = 17 ring_r0 = 580 ring_r5 = 1700 ring_radii = np.logspace(np.log10(ring_r0), np.log10(ring_r5), num_rings) print('ring radii =', ring_radii) print('ring spacing = ', np.diff(ring_radii)) # Arms # arm_r0 = 1805 arm_r0 = ring_r5 + core_radius_m / 2 # arm_r1 = 7135 arm_r1 = 6400 # ============== Core tel.seed = 74383209 args = dict(amps=taylor_win(n_taylor, sll), taper_r_min=0.30) # 510m worked ok tel.add_tapered_core(224 + 2, 480, AnalyseUnwrapV5.__taper_r_profile, **args) print('final seed =', tel.layouts['tapered_core']['info']['final_seed']) # tel.add_ska1_v5(r_max=500) # ============== Rings # TODO(BM) rotate every other ring so radii don't align np.random.seed(1) for i, r in enumerate(ring_radii[0:2]): print('xxx', i, r) # tel.add_ring(num_per_ring, r, # delta_theta=(360/(num_per_ring * 2)) * (i%2)) tel.add_ring(num_per_ring, r, delta_theta=np.random.randint(low=0, high=360)) # tel.add_ring(num_per_ring, r, delta_theta=0) # tel.layouts['test_st'] = dict(x=np.array([2e3]), y=np.array([0e3])) tel.grid_cell_size_m = tel.station_diameter_m metrics.analyse_telescope(tel, 0, self.eval_metrics) return tel # ============= Spiral arms # tel.add_log_spiral_2(25, arm_r0, arm_r1, 0.515, 3, 'inner_arms', 0) tel.add_log_spiral_3(25, self.start_inner, arm_r0, arm_r1, 0.515, self.num_arms, self.theta0_deg) # tel.add_symmetric_log_spiral(25, arm_r0, arm_r1, 0.515, 3, # 'inner_arms', self.delta_theta_deg_inner) x, _, _ = tel.get_coords_enu() print('total stations =', x.size) # Plotting layout metrics.analyse_telescope(tel, 0, self.eval_metrics) metrics.save_results(name) # metrics.plot_cable_length_compare() metrics.plot_comparisons() return tel
def model06(self, name='model06', add_core=True, r_values=None): """Model06 == no cables > 1km, an improved core""" # Initialise metrics class metrics = Metrics(self.out_dir) # TODO(BM) hybrid of model1 with a custom generated core # and avoiding cable lengths > 1km in arm clusters. # For the log spiral arms also generate from a single arm and rotate # with stride 3 to generate arms. (put 162 - 18? in arms) and # (224 + 18 in the core) to recover some short baselines. from math import log, exp import matplotlib.pyplot as plt def taper_func_1(r): return 1 - (r / 2)**1.5 def taper_func_2(r, hwhm=1.5, taper_r_min=0): r = np.asarray(r) c = hwhm / (2 * log(2))**0.5 values = np.exp(-((r - taper_r_min) / (1 - taper_r_min))**2 / 2 * c**2) values[r < taper_r_min] = 1.0 return values def taper_r_profile(r, amps, taper_r_min=0): """Nearest neighbour matching. FIXME(BM) double check this""" r = np.asarray(r) idx = np.round( ((r - taper_r_min) / (1 - taper_r_min)) * (amps.size - 1)) values = np.asarray(amps[idx.astype(np.int)]) values[r < taper_r_min] = 1.0 return values def get_taper_profile(taper_func, r, **kwargs): if kwargs is not None: t = taper_func(r, **kwargs) else: t = taper_func(r) return t tel = SKA1_low_analysis(name) sll = -28 n_taylor = 10000 r = np.linspace(0, 1, 100) t1 = get_taper_profile(taper_func_1, r) t2 = get_taper_profile(taper_func_2, r, hwhm=1.0) t2a = get_taper_profile(taper_func_2, r, hwhm=1.0, taper_r_min=0.25) t3 = get_taper_profile(taper_r_profile, r, amps=taylor_win(n_taylor, sll)) t4 = get_taper_profile(taper_r_profile, r, amps=taylor_win(n_taylor, sll), taper_r_min=0.25) fig, ax = plt.subplots() ax.plot(r, tel.station_diameter_m / t1, 'k-', label='Power law') ax.plot(r, tel.station_diameter_m / t2, 'b-', label='Gaussian') ax.plot(r, tel.station_diameter_m / t2a, 'b--', label='Gaussian rmin') ax.plot(r, tel.station_diameter_m / t3, 'r-', label='Taylor %i' % sll) ax.plot(r, tel.station_diameter_m / t4, 'r--', label='Taylor rmin %i' % sll) ax.set_xlabel('Fractional radius') ax.set_ylabel('Minimum station separation (m)') ax.grid() ax.set_ylim(34) ax.legend(loc='best') fig.savefig('station_min_dist.png') # plt.show() plt.close(fig) core_radius_m = 480 tel.num_trials = 10 tel.trial_timeout_s = 30.0 tel.seed = 24183655 args = dict(amps=taylor_win(n_taylor, sll), taper_r_min=0.25) tel.add_tapered_core(224 + 18, core_radius_m, taper_r_profile, **args) tel.plot_layout(filename=name + '.png', show_decorations=False, plot_radii=[500]) print('final seed =', tel.layouts['tapered_core']['info']['final_seed']) print(tel.seed) tel.add_log_spiral_2(20, 480, 6000, 0.515, 3, 'inner_arms', 0) x1, y1, _ = tel.get_coords_enu() tel_v5 = SKA1_low_analysis('ska1_v5') tel_v5.add_ska1_v5(r_max=6400) x2, y2, _ = tel_v5.get_coords_enu() # Side by side comparison to ska v5 core fig, axes = plt.subplots(figsize=(16, 8), ncols=2) for xy in zip(x1, y1): axes[0].add_artist( plt.Circle(xy, tel.station_diameter_m / 2, fill=True, color='k', alpha=0.5)) for xy in zip(x2, y2): axes[1].add_artist( plt.Circle(xy, tel.station_diameter_m / 2, fill=True, color='k', alpha=0.5)) for ax in axes: ax.add_artist(plt.Circle((0, 0), 500, fill=False, color='r')) ax.set_aspect('equal') ax.set_xlim(-600, 600) ax.set_ylim(-600, 600) plt.show() plt.close(fig) # Side by side comparison to ska v5 core fig, axes = plt.subplots(figsize=(16, 8), ncols=2) for xy in zip(x1, y1): axes[0].add_artist( plt.Circle(xy, tel.station_diameter_m / 2, fill=True, color='k', alpha=0.5)) for xy in zip(x2, y2): axes[1].add_artist( plt.Circle(xy, tel.station_diameter_m / 2, fill=True, color='k', alpha=0.5)) for ax in axes: ax.add_artist(plt.Circle((0, 0), 500, fill=False, color='r')) ax.set_aspect('equal') ax.set_xlim(-7e3, 7e3) ax.set_ylim(-7e3, 7e3) plt.show() plt.close(fig) # TODO(BM) add cluster centres into the spiral arms... tel.plot_layout(show_decorations=True, xy_lim=2.5e3, plot_radii=[500, 6400]) tel.plot_layout(show_decorations=True, xy_lim=7e3, plot_radii=[500, 6400])