def polar_dev(result_table_combined, result_tables): result_table_combined.sort('id') for tab in result_tables: tab.sort('id') # todo exclude outlier fluxes xs = np.array([tab['x_fit'] for tab in result_tables]).flatten() ys = np.array([tab['y_fit'] for tab in result_tables]).flatten() xdev = np.array([ tab['x_fit'] - result_table_combined['x_fit'] for tab in result_tables ]).flatten() ydev = np.array([ tab['y_fit'] - result_table_combined['y_fit'] for tab in result_tables ]).flatten() flux = np.array([tab['flux_fit'] for tab in result_tables]).flatten() # shuffle entries to not imprint structure on plot rng = np.random.default_rng(10) order = rng.permutation(range(len(xdev))) xdev, ydev, flux = xdev[order], ydev[order], flux[order] xstd = np.std(xdev) _, _, xstd_clipped = sigma_clipped_stats(xstd, sigma=100) ystd = np.std(xdev) _, _, ystd_clipped = sigma_clipped_stats(ystd, sigma=100) fig = plt.figure(figsize=(6, 6)) ax = fig.add_subplot(projection='polar') #ax.set_rscale('symlog') norm = LogNorm(1, flux.max()) cmap = mpl.cm.get_cmap('plasma').copy() cmap.set_under('green') squish_base = 8 #plt.scatter(np.arctan2(xdev,ydev), (xdev**2+ydev**2)**(1/16) , alpha=0.03, s=10, c=flux, norm=norm, cmap=cmap, linewidths=0) plt.scatter(np.arctan2(xdev, ydev), (xdev**2 + ydev**2)**(1 / squish_base), alpha=0.35, s=8, c=flux, norm=norm, cmap=cmap, linewidths=0) #plt.scatter(np.arctan2(xdev,ydev), (xdev**2+ydev**2)**(1/16) , alpha=0.5, s=3, c=flux, norm=norm, cmap=cmap, linewidths=0) rs = np.array([0.1, 0.01**(1 / squish_base), 1.]) rlabels = [f'{r:.2e}' for r in rs**squish_base] ax.set_rticks(rs, rlabels, backgroundcolor=(1, 1, 1, 0.8)) ax.set_rlabel_position(67) ax.set_thetagrids([]) cbar = plt.colorbar(mpl.cm.ScalarMappable(norm=norm, cmap=cmap), label='log(flux)', shrink=0.8) save_plot(out_dir, 'naco_xy_density') xstd, ystd, xstd_clipped, ystd_clipped, np.sqrt(np.max(xdev**2 + ydev**2)) return xdev, ydev, flux
# %% #seed=0 #rng = np.random.default_rng(seed) #def recipe(): # return scopesim_grid(N1d=7, border=100, perturbation=7, # magnitude=lambda N: rng.uniform(15, 16, N), # custom_subpixel_psf=anisocado_psf, seed=seed) #img_noisefloor, tab_noisefloor = read_or_generate_image(f'grid7_pert7_seed{seed}', recipe=recipe, force_generate=False) #plt.figure() #plt.imshow(img_noisefloor[10:-10,10:-10], norm=LogNorm()) #plt.colorbar() # %% plot_dev_vs_mag(noisefloor_result[noisefloor_result['flux_fit'] > 1000]) save_plot(out_dir, 'synthetic_grid_noisefloor') # %% [markdown] # # Grid Best effort # %% def grid_photometry(): fit_stages_grid = [ FitStage(1, 1e-10, 1e-11, np.inf, all_individual), # first stage: get flux approximately right FitStage(10, 0.52, 0.52, 150_000, brightest_simultaneous(3)), FitStage(10, 0.52, 0.52, 80_000, not_brightest_individual(3)), #FitStage(30, 0.1, 0.1, 20_000, all_individual), #FitStage(30, 0.1, 0.1, 5_000, all_simultaneous) ]
cmap = plt.get_cmap('prism') xy_curr = np.array((group['x_fit'], group['y_fit'])).T if len(group)>=3: hull = ConvexHull(xy_curr) vertices = xy_curr[hull.vertices] poly=Polygon(vertices, fill=False, color=cmap(group_id/max_id),alpha=0.8) plt.gca().add_patch(poly) plt.scatter(core_group['x_fit'], core_group['y_fit'], color=cmap(group_id/max_id), s=8, alpha=0.2) groups = make_groups(result_table, 8, 10) do_plotting(groups) groups = make_groups(result_table, 12, 40) do_plotting(groups) groups = make_groups(result_table, 21, 40) do_plotting(groups) groups = make_groups(result_table, 51, 30) do_plotting(groups) groups = make_groups(result_table, 100, 80) do_plotting(groups) groups = make_groups(result_table, 200, 80) do_plotting(groups) plt.imshow(img, norm=LogNorm()) save_plot('.', 'totally_valid_plot') pass
points=1000, bw_method=0.3) fake_handles.append(vp['cmedians']) labels.append('small bounds') xs = np.linspace(3, 30, 1000) p = plt.plot(xs, 0.5 * xs**2) fake_handles.append(p[0]) labels.append(r'$0.5 \, {N_{\mathrm{group}}}^2$') plt.legend(fake_handles, labels, loc='upper left') plt.xlabel('number of stars in fitted star-group') plt.ylabel('runtime in seconds') plt.yscale('log') save_plot(outdir, 'group_fit_bounds_runtime') # %% [markdown] # # Qualitative analysis of restriction effect # %% def recipe(): return scopesim_groups(N1d=8, border=50, group_size=1, group_radius=1, jitter=2, magnitude=lambda N: np.random.normal(21, 2, N), custom_subpixel_psf=epsf, seed=10)
# %% # the cluster template generates a lot of very faint sources, only show the ones that could reasonably be detected. # filtered_input_table = scc_session.tables.input_table[ scc_session.tables.input_table[INPUT_TABLE_NAMES[MAGNITUDE]] > 1e-12] fig = plots.plot_image_with_source_and_measured( scc_session.image, filtered_input_table, scc_session.tables.result_table) plt.xlim(0, 1024) plt.ylim(0, 1024) cb = plt.colorbar(shrink=0.7) cb.set_label('pixel count') fig.set_size_inches(7, 7) plt.tight_layout() save_plot(outdir, 'standard_photutils') # %% [markdown] # # Benchmark Images # %% sg_session = Session(default_config, 'scopesim_grid_16_perturb2_mag18_24') gc_session = Session(default_config, 'gausscluster_N2000_mag22') # %% #fig = plots_and_sanitycheck.plot_image_with_source_and_measured( # photometry_result_sg.image, photometry_result_sg.input_table, photometry_result_sg.result_table) def show_image(img): fig = plt.figure()
y, x = np.mgrid[-fitshape / 2:fitshape / 2:1j * fitshape, -fitshape / 2:fitshape / 2:1j * fitshape] psffind = StarFinder(threshold=10, kernel=initial_epsf(x, y), min_separation=20, exclude_border=True, peakmax=10_000, brightest=400) epsf_sources_improved = psffind(img_combined) # %% plt.figure() plt.imshow(img_combined, norm=LogNorm()) plt.plot(epsf_sources_improved['xcentroid'], epsf_sources_improved['ycentroid'], 'rx') save_plot(out_dir, 'naco_epsfstars') # %% epsf_sources_improved['x'] = epsf_sources_improved['xcentroid'] epsf_sources_improved['y'] = epsf_sources_improved['ycentroid'] epsf_stars = extract_stars(NDData(img_combined - SExtractorBackground()(img_combined)), epsf_sources_improved, size=(fitshape + 2, fitshape + 2)) from thesis_lib.util import make_gauss_kernel builder = EPSFBuilder(oversampling=4, smoothing_kernel=make_gauss_kernel(1.4), maxiters=7) improved_epsf, _ = cached(lambda: builder.build_epsf(epsf_stars), cache_dir / 'improved_epsf_naco',