Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return amplitude list to allow photometric comparison #12

Merged
merged 2 commits into from
May 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
204 changes: 183 additions & 21 deletions notebooks/JWST_PSF_reconstruction.ipynb

Large diffs are not rendered by default.

307 changes: 107 additions & 200 deletions notebooks/testing.ipynb

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions psfr/psfr.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def stack_psf(star_list, oversampling=1, mask_list=None, error_map_list=None, sa
else:
mask_list_one_step = None
for j in range(num_iteration):
psf_guess = one_step_psf_estimate(star_list, psf_guess, center_list, mask_list_one_step,
psf_guess, amplitude_list = one_step_psf_estimate(star_list, psf_guess, center_list, mask_list_one_step,
error_map_list=error_map_list, oversampling=oversampling,
**kwargs_psf_stacking, **kwargs_one_step)
if j % n_recenter == 0 and j != 0:
Expand Down Expand Up @@ -145,7 +145,7 @@ def _updatefig(i):
anim.save(animation_options['output_dir'])
plt.close()

return psf_guess, center_list, mask_list
return psf_guess, center_list, mask_list, amplitude_list


def one_step_psf_estimate(star_list, psf_guess, center_list, mask_list=None, error_map_list=None, oversampling=1,
Expand Down Expand Up @@ -297,7 +297,7 @@ def one_step_psf_estimate(star_list, psf_guess, center_list, mask_list=None, err
amplitude_list=amplitude_list, error_map_list=error_map_list_psf,
**psf_stacking_options)
kernel_new = kernel_util.cut_psf(kernel_new, psf_size=len(psf_guess))
return kernel_new
return kernel_new, amplitude_list


def psf_error_map(star_list, psf_kernel, center_list, mask_list=None, error_map_list=None, oversampling=1):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_Examples/test_JWST.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_reconstruct_psf():
star = psfr.shift_psf(psf_center=kernel, oversampling=5, shift=[x_shift, y_shift], degrade=True, n_pix_star=kernel.shape[0]/oversampling)
star_list_webb.append(star)

psf_psfr_super, center_list_psfr_super, mask_list = psfr.stack_psf(star_list_webb, oversampling=oversampling,
psf_psfr_super, center_list_psfr_super, mask_list, amplitude_list = psfr.stack_psf(star_list_webb, oversampling=oversampling,
saturation_limit=None, num_iteration=10,
n_recenter=20)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_Examples/test_gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def stack_psf_guassian_high_res(oversampling, num_stars, kwargs_one_step, num_it
star = oversampled2regular(star, oversampling=oversampling_compute)
star_list.append(star)

psf_after, center_list_after, mask_list = stack_psf(star_list, oversampling=oversampling,
psf_after, center_list_after, mask_list,amplitude_list = stack_psf(star_list, oversampling=oversampling,
saturation_limit=None, num_iteration=num_iteration,
n_recenter=n_recenter, verbose=False, kwargs_one_step=kwargs_one_step)

Expand Down
14 changes: 7 additions & 7 deletions tests/test_psfr.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def test_one_step_psf_estimation():
star = util.array2image(flux_model)
star_list.append(star)

psf_after = psfr.one_step_psf_estimate(star_list, psf_guess, center_list, mask_list=None, error_map_list=None,
psf_after, amplitude_list= psfr.one_step_psf_estimate(star_list, psf_guess, center_list, mask_list=None, error_map_list=None,
step_factor=0.2)
# psf_after should be a better guess of psf_true than psf_guess
diff_after = np.sum((psf_after - psf_true) ** 2)
Expand All @@ -184,14 +184,14 @@ def test_one_step_psf_estimation():
psf_true_super = util.array2image(flux_true_super)
psf_true_super /= np.sum(psf_true_super)

psf_after_super = psfr.one_step_psf_estimate(star_list, psf_guess_super, center_list, mask_list=None,
psf_after_super, amplitude_list = psfr.one_step_psf_estimate(star_list, psf_guess_super, center_list, mask_list=None,
error_map_list=None, step_factor=0.2, oversampling=oversampling)
diff_after = np.sum((psf_after_super - psf_true_super) ** 2)
diff_before = np.sum((psf_guess_super - psf_true_super) ** 2)
assert diff_after < diff_before

# de-shifting in oversampled space (should be a bit lower quality but still better than initial guess)
psf_after_super = psfr.one_step_psf_estimate(star_list, psf_guess_super, center_list, mask_list=None,
psf_after_super, amplitude_list = psfr.one_step_psf_estimate(star_list, psf_guess_super, center_list, mask_list=None,
error_map_list=None, step_factor=0.2, oversampling=oversampling,
oversampled_residual_deshifting=True)
diff_after = np.sum((psf_after_super - psf_true_super) ** 2)
Expand Down Expand Up @@ -226,14 +226,14 @@ def test_saturation_limit():
star_list_webb.append(star)

# psf reconstructed with a saturation limit
psf_psfr_super_sat, center_list_psfr_super_sat, mask_list_sat = psfr.stack_psf(star_list_webb,
psf_psfr_super_sat, center_list_psfr_super_sat, mask_list_sat, amplitude_list_sat = psfr.stack_psf(star_list_webb,
oversampling=oversampling,
saturation_limit=saturation_limit,
num_iteration=10,
n_recenter=20,
centroid_optimizer='Nelder-Mead')
# psf reconstructed without a saturation limit
psf_psfr_super, center_list_psfr_super, mask_list = psfr.stack_psf(star_list_webb, oversampling=oversampling,
psf_psfr_super, center_list_psfr_super, mask_list, amplitude_list_super = psfr.stack_psf(star_list_webb, oversampling=oversampling,
saturation_limit=None, num_iteration=10,
n_recenter=20)

Expand Down Expand Up @@ -269,12 +269,12 @@ def test_noisy_psf():
star_noisy = star + star_n1 + star_n2
star_list_webb_noisy.append(star_noisy)

psf_psfr_super_noisy, center_list_psfr_super_sat, mask_list_sat = psfr.stack_psf(star_list_webb_noisy,
psf_psfr_super_noisy, center_list_psfr_super_sat, mask_list_sat, amplitude_list_noisy = psfr.stack_psf(star_list_webb_noisy,
oversampling=oversampling,
saturation_limit=None,
num_iteration=10,
n_recenter=5)
psf_psfr_super, center_list_psfr_super_sat, mask_list_sat = psfr.stack_psf(star_list_webb,
psf_psfr_super, center_list_psfr_super_sat, mask_list_sat, amplitude_list = psfr.stack_psf(star_list_webb,
oversampling=oversampling,
saturation_limit=None, num_iteration=10,
n_recenter=20)
Expand Down