示例#1
0
def get_psfs(*, separation):
    ps = PhotonSieve(diameter=diameter)
    wavelengths = np.array([33.4e-9, 33.4e-9 + separation])

    psfs_focus = PSFs(ps,
                      source_wavelengths=wavelengths,
                      measurement_wavelengths=wavelengths,
                      num_copies=6,
                      image_width=303)

    psfs_csbs = PSFs(ps,
                     source_wavelengths=wavelengths,
                     num_copies=10,
                     image_width=303)
    csbs(psfs_csbs, sse_cost, 12, lam=10**-4.5, order=1)

    return psfs_focus, psfs_csbs
示例#2
0
def cost(tikhonov_lam_exp, csbs_lam_exp):

    # csbs_grid
    psfs.copies = np.repeat(12, 12)
    # csbs_focus
    # psfs.copies = np.repeat(12, 2)
    csbs(psfs, sse_cost, 12, lam=10**csbs_lam_exp, order=1)
    measured = get_measurements(psfs=psfs, sources=truth, real=True)
    measured_noisy = add_noise(measured, model='poisson', max_count=500)
    recon = tikhonov(
            sources=measured,
            psfs=psfs,
            measurements=measured_noisy,
            tikhonov_lam=10**tikhonov_lam_exp
    )

    plt.imshow(recon[0])
    plt.show()
    plt.pause(.05)
    return compare_ssim(truth[0], recon[0]) + compare_ssim(truth[1], recon[1])
示例#3
0
dfts = np.fft.fftshift(dfts, axes=(2, 3))

psfs_sq.psf_dfts = dfts
psfs_sq.psfs = np.fft.ifft2(psfs_sq.psf_dfts)

plotter4d(np.fft.fftshift(
    np.abs(psfs_sq.psf_dfts.reshape(7, 7, 301, 301)),
    axes=(2, 3),
),
          figsize=(5, 5),
          scale=True)
plt.savefig('square_dfts.png', dpi=300)

# %% csbs_ps -----

csbs(psfs_ps, sse_cost, 10, lam=1e0, order=1)
fourier_slices(psfs_ps)
plt.savefig('photonsieve_csbs.png', dpi=300)

# %% csbs_sq -----

plt.cla()
plt.close()

csbs(psfs_sq, sse_cost, 10, lam=1e0, order=1)
plt.imshow(psfs_sq.copies.reshape(7, 7), cmap='magma')
plt.figtext(0.98,
            0.98,
            str(psfs_sq.csbs_params),
            horizontalalignment='right',
            rotation='vertical',
示例#4
0
from mas.psf_generator import PSFs, PhotonSieve, circ_incoherent_psf
import numpy as np
from matplotlib import pyplot as plt
import copy

# generate photon sieve with default parameters
ps = PhotonSieve()

# run csbs algorithm on a range of lambdas
lambdas = np.logspace(-10, 2, 20)
copies = []
orig_psfs = PSFs(ps,
                 source_wavelengths=np.array([33.4e-9, 33.7e-9, 33.8e-9]),
                 psf_generator=circ_incoherent_psf,
                 image_width=51)
for lam in lambdas:
    print('----------------------', lam)
    psfs = copy.deepcopy(orig_psfs)
    csbs(psfs, sse_cost, 10, lam=lam)
    copies.append(psfs.copies)

# 2D plot of (plane_locations, lambda) vs copies
plt.figure(constrained_layout=True)
plt.imshow(np.abs(copies), cmap='magma', aspect=1)
plt.ylabel('lambda')
plt.xlabel('plane locations')
plt.yticks(np.arange(len(lambdas)), np.round(lambdas, 3))
cbar = plt.colorbar()
cbar.set_label('Copies')
# plt.savefig('lambda_selection.png')
示例#5
0
psfs_mid = PSFs(ps,
                source_wavelengths=wavelengths,
                measurement_wavelengths=np.array(
                    [33.4e-9, 33.401e-9, 33.402e-9]),
                num_copies=6)
psfs_mid.copies = np.array([6, 1, 5])

psfs_outer = PSFs(ps,
                  source_wavelengths=wavelengths,
                  measurement_wavelengths=np.array(
                      [33.4e-9, 33.402e-9, 33.41e-9]),
                  num_copies=6)
psfs_outer.copies = np.array([6, 5, 1])

psfs_csbs = PSFs(ps, source_wavelengths=wavelengths, num_copies=10)
csbs(psfs_csbs, sse_cost, 12, lam=10**-4.5, order=1)

sources = strands[:2]

# %% data


def poop():
    global sources

    meas_focus = get_measurements(sources=sources,
                                  mode='circular',
                                  psfs=psfs_focus,
                                  real=True)
    meas_mid = get_measurements(sources=sources,
                                mode='circular',
示例#6
0
def vec_add_noise(x, **kwargs):
    x = np.repeat(x[np.newaxis], noise_copies, axis=0)
    return add_noise(x, **kwargs)


# %% csbs_grid -----
print('csbs_grid')

psfs[0] = PSFs(sieve=ps,
               source_wavelengths=wavelengths,
               measurement_wavelengths=10,
               num_copies=12)

# csbs(psfs[0], sse_cost, 12, lam=10**-3.75, order=1) # 10 counts
csbs(psfs[0], sse_cost, 12, lam=10**-3.5, order=1)  # 500 counts

measured = get_measurements(sources=sources, real=True, psfs=psfs[0])
measured_noisy = vec_add_noise(measured, max_count=max_count, model='Poisson')
recons[0] = vec_tikhonov(
    sources=sources,
    measurements=measured_noisy,
    psfs=psfs[0],
    # tikhonov_lam=10**-0.75, # 10 counts
    tikhonov_lam=10**-1.75,  # 500 counts
    tikhonov_order=1)

# %% csbs_focus -----
print('csbs_focus')

psfs[1] = PSFs(sieve=ps,
示例#7
0
    psf_generator=circ_incoherent_psf,
    image_width=501,
    # cropped_width=51,
    num_copies=10)

psfs_focus = PSFs(
    ps,
    sampling_interval=3.5e-6,
    measurement_wavelengths=source_wavelengths,
    source_wavelengths=source_wavelengths,
    psf_generator=circ_incoherent_psf,
    image_width=501,
    # cropped_width=psfs_csbs.psfs.shape[-1],
    num_copies=6)

psfs_csbs = csbs(psfs_csbs, sse_cost, 12, lam=csbs_lam, order=order)

# %% measure
psnr_focus, psnr_csbs, ssim_focus, ssim_csbs = [], [], [], []
measured_focus = get_measurements(sources=sources, psfs=psfs_focus)
measured_csbs = get_measurements(sources=sources, psfs=psfs_csbs)
for i in range(50):
    measured_noisy_focus = add_noise(measured_focus,
                                     dbsnr=15,
                                     model='Gaussian')
    measured_noisy_csbs = add_noise(measured_csbs, dbsnr=15, model='Gaussian')

    recon_focus = tikhonov(psfs=psfs_focus,
                           measurements=measured_noisy_focus,
                           tikhonov_lam=1e-3,
                           tikhonov_order=order)
示例#8
0
#!/bin/env python3
# Evan Widloski - 2018-05-22
# Plot results of CSBS algorithm at each iteration

from mas.csbs import csbs
from mas import sse_cost
from mas.psf_generator import PSFs, PhotonSieve, circ_incoherent_psf
from mas.plotting import fourier_slices, psf_slider
import numpy as np

# create photon sieve with default parameters
ps = PhotonSieve()
# generate psfs
psfs = PSFs(ps,
            source_wavelengths=np.array([33.4e-9, 33.7e-9, 33.8e-9]),
            psf_generator=circ_incoherent_psf,
            image_width=301,
            num_copies=5)

# run CSBS (modifies psfs in place)
csbs(psfs, sse_cost, 10, lam=1e-2, order=0)

# plot results
plt, _ = fourier_slices(psfs)
plt.show()
# plt.savefig('csbs_fourier_slices.png')