def disabled_test_weird_os4(): mod = make_anisocado_model(oversampling=4, degree=5) mod = make_anisocado_model(oversampling=4, degree=5) mod.render() y, x = np.mgrid[-200:200:401j, -200:200:401j] mod(x, y)
def inner(): # These imports are necessary to be able to execute in a forkserver context; it does not copy the full memory space, so # we'd have to rely on the target to know the imports from thesis_lib.testdata.recipes import scopesim_grid import numpy as np from thesis_lib.scopesim_helper import make_anisocado_model psf = make_anisocado_model(lowpass=5) return scopesim_grid(seed=seed, N1d=10, perturbation=2., custom_subpixel_psf=psf, magnitude=lambda N: np.random.uniform(18, 24, N))
ys, xs = np.indices(detected_img.shape) for y, x in zip(ys.flatten(), xs.flatten()): psf_model.x_0 = x psf_model.y_0 = y if detected_img[y, x]: out += detected_img[y, x] * log(psf_model(xs, ys))[::-1, ::-1] return out # %% detections = np.zeros((31, 31)) detections[15, 15] = 2 detections[16, 20] = 1 detections[3, 8] = 1 model = make_anisocado_model() like = likelyhood(detections, model) y, x = np.indices(detections.shape) plt.figure() model.x_0 = 15 plt.imshow(like) # %% # %% # %% import anisocado psf = anisocado.AnalyticalScaoPsf() img = psf.psf_latest
rng = np.random.default_rng(seed=10) guess_table = input_table.copy() guess_table['x_orig'] = guess_table['x'] guess_table['y_orig'] = guess_table['y'] guess_table.rename_columns(['x', 'y', 'f'], [xguessname, yguessname, fluxguessname]) guess_table['x_0'] += rng.uniform(-perturbation, perturbation, len(guess_table)) guess_table['y_0'] += rng.uniform(-perturbation, perturbation, len(guess_table)) guess_table.sort(fluxguessname, reverse=True) return guess_table # %% anisocado_psf = make_anisocado_model() # %% [markdown] # # Noisefloor # %% def do_photometry(seed): rng = np.random.default_rng(seed=seed) def recipe(): return scopesim_grid(N1d=7, border=100, perturbation=7, magnitude=lambda N: rng.uniform(15, 26, N), custom_subpixel_psf=anisocado_psf,
@copying_lru_cache(maxsize=2) def make_delta_model(): from photutils import FittableImageModel data = np.zeros((401, 401)) ycenter, xcenter = center_of_image(data) data[int(ycenter),int(xcenter)] = 1 return FittableImageModel(data, oversampling=2, degree=5) # The following tests take quite long to run and tolerances are pretty low. # Not sure if debugging this will leads somewhere @pytest.mark.parametrize('single_star', [None, make_delta_model(), make_anisocado_model(), make_anisocado_model(lowpass=5), make_gauss_model(0.5)], indirect=True) def test_single_star_image(single_star): img, table = single_star xcenter, ycenter = center_of_image(img) xcentroid, ycentroid = centroid_quadratic(img, fit_boxsize=5) xref, yref = table[INPUT_TABLE_NAMES[X]][0], table[INPUT_TABLE_NAMES[Y]][0] assert np.abs(xref-xcentroid) < 0.005 assert np.abs(yref-ycentroid) < 0.005 # currently stars are not placed dead center due to 0.5 pixel offset from scopesim #assert np.abs(xcenter-xref) < 0.01 #assert np.abs(ycenter-yref) < 0.01
micado_default.cmds["!SIM.sub_pixel.flag"] = True micado_convpsf = micado_base() element_idx = [ element.meta['name'] for element in micado_convpsf.optics_manager.optical_elements ].index('default_ro') psf_effect = make_psf() micado_convpsf.optics_manager.add_effect(psf_effect, ext=element_idx) micado_convpsf['relay_psf'].include = False micado_convpsf['micado_ncpas_psf'].include = False micado_convpsf.cmds["!SIM.sub_pixel.flag"] = True micado_subpixel = micado_base() micado_subpixel.cmds["!SIM.sub_pixel.flag"] = "psf_eval" micado_subpixel.cmds["!SIM.sub_pixel.psf"] = make_anisocado_model() micado_subpixel['relay_psf'].include = False micado_subpixel['micado_ncpas_psf'].include = False filter_name = 'MICADO/filters/TC_filter_K-cont.dat' spectral_types = ['A0V'] pixel_scale = 0.004 * u.arcsec / u.pixel n_pixel = 1024 * u.pixel max_coord = n_pixel - 1 * u.pixel # size 1024 to max index 1023 def to_as_expected(px_coord): if not isinstance(px_coord, u.Quantity): px_coord *= u.pixel
if not os.path.exists(outdir): os.mkdir(outdir) # %% [markdown] # # Runtime # %% # Definitions for generating data cfg = config.Config() cfg.use_catalogue_positions = True cfg.separation_factor = 20 cfg.photometry_iterations = 1 cfg.perturb_catalogue_guess = 0.01 cfg.fitshape = 51 epsf = make_anisocado_model() def benchmark_parameter_constraints(posbound, fluxbound, groupsize, seed=0): def recipe(): return scopesim_groups(N1d=1, border=300, group_size=groupsize, group_radius=12, jitter=13, magnitude=lambda N: np.random.normal(21, 2, N), custom_subpixel_psf=epsf, seed=seed) cfg.bounds = { 'x_0': (posbound, posbound),
def test_anisocado_model_normalized(oversampling, degree, lowpass): mod = make_anisocado_model(oversampling=oversampling, degree=degree, lowpass=lowpass) assert np.abs(np.sum(mod.render()) - 1) < 1e4
figa = plots.plot_xy_deviation(result_table_multi_conv) figb = plots.plot_xy_deviation(result_table_multi_subpixel) # %% lowpass_config.oversampling = 2 lowpass_config.cutout_size = 40 lowpass_config.fitshape = 25 #session_std = Session(lowpass_config, 'scopesim_grid_16_perturb2_mag18_24') #session_known_psf = Session(lowpass_config, 'scopesim_grid_16_perturb2_mag18_24') session_std = Session(lowpass_config, 'gausscluster_N2000_mag22_subpixel') session_known_psf = Session(lowpass_config, 'gausscluster_N2000_mag22_subpixel') session_std.do_it_all() session_known_psf.epsf = make_anisocado_model() session_known_psf.do_astrometry() # %% figa = plots.plot_xy_deviation(session_std.tables.valid_result_table) figb = plots.plot_xy_deviation(session_known_psf.tables.valid_result_table) # %% fig, axs = plt.subplots(1, 2) axs[0].imshow(session_known_psf.epsf.data, norm=LogNorm()) axs[1].imshow(session_std.epsf.data, norm=LogNorm()) # %%
def anisocado_model(request): return scopesim_helper.make_anisocado_model(lowpass=request.param)