Example #1
0
 def setUp(self):
     self.sources = np.ones((2, 4, 4))
     self.ps = PhotonSieve()
     wavelengths = np.array([33.4e-9, 33.5e-9])
     self.psfs = PSFs(self.ps,
                      source_wavelengths=wavelengths,
                      measurement_wavelengths=wavelengths)
     measured = get_measurements(sources=self.sources,
                                 psfs=self.psfs,
                                 real=True)
     self.measured_noisy = add_noise(measured,
                                     max_count=10,
                                     model='poisson')
Example #2
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
Example #3
0
from mas.data import strands as sources
from mas.forward_model import add_noise, get_measurements, get_contributions
from mas.psf_generator import PhotonSieve, PSFs
from mas.plotting import plotter4d
from mas.csbs import csbs
from mas import sse_cost
import numpy as np
import matplotlib.pyplot as plt

# %% psfs -----

ps = PhotonSieve()
wavelengths = np.array([33.4, 33.5]) * 1e-9
sources = sources[np.array((0, 1))].reshape((2, 1, 160, 160))
psfs = PSFs(
    sieve=ps,
    source_wavelengths=wavelengths,
    measurement_wavelengths=wavelengths,
    num_copies=1
)

# %% contributions -----

contributions = get_contributions(sources=sources[:, 0, :, :], psfs=psfs, real=True)
plt = plotter4d(
    contributions,
    title='measurement contributions',
    column_labels=wavelengths,
    sup_xlabel='source wavelengths',
    row_labels=wavelengths,
    sup_ylabel='measurement wavelengths',
Example #4
0
from mas.psf_generator import PSFs, PhotonSieve, circ_incoherent_psf
from mas.deconvolution import tikhonov, admm
from mas.deconvolution.admm import bm3d_pnp
from mas.plotting import plotter4d
from mas.data import strands_ext
from functools import partial
from skimage.measure import compare_ssim as ssim

# %% meas ------------------------

source_wavelengths = np.array([33.4e-9, 33.5e-9])
num_sources = len(source_wavelengths)
meas_size = [160,160]
sources = strands_ext[0:num_sources]
sources_ref = size_equalizer(sources, ref_size=meas_size)
ps = PhotonSieve(diameter=16e-2, smallest_hole_diameter=7e-6)

# generate psfs
psfs = PSFs(
    ps,
    sampling_interval=3.5e-6,
    measurement_wavelengths=source_wavelengths,
    source_wavelengths=source_wavelengths,
    psf_generator=circ_incoherent_psf,
    # image_width=psf_width,
    num_copies=1
)

# ############## INVERSE CRIME ##############
# measured = get_measurements(
#     sources=sources,
Example #5
0
from mas.plotting import plotter4d
from mas.forward_model import get_measurements
from mas.psf_generator import PhotonSieve, PSFs
from mas.decorators import vectorize
from scipy.ndimage.interpolation import shift
from mas.data import strands
# from scipy.ndimage import fourier_shift

original = strands[0]
offset = (25, 25)
# shifted = np.fft.ifft2(fourier_shift(np.fft.fft2(original), offset))
shifted = shift(original, shift=offset, mode='wrap')

# %% psfs -----

ps = PhotonSieve(diameter=10e-2)
wavelengths = np.array([33.4e-9])
psfs = PSFs(
    sieve=ps,
    source_wavelengths=wavelengths,
    measurement_wavelengths=wavelengths,
    num_copies=1
)

# %% measure -----

measured_original = get_measurements(
    sources=original[np.newaxis, :, :],
    psfs=psfs,
    real=True
)[0]
Example #6
0
#!/bin/env python3
# Evan Widloski - 2018-10-14
# generate some PSFs and save to HDF5 file

from mas.psf_generator import PSFs, PhotonSieve, circ_incoherent_psf
import numpy as np
import h5py

# generate photon sieve
ps = PhotonSieve(diameter=80e-3,
                 smallest_hole_diameter=7e-6,
                 hole_diameter_to_zone_width=7 / 6)

# generate psfs for 632.8nm at [0, 1, 2, 3, 5, 7] DOF away from focus
source_wavelengths = np.array([632.8e-9])
dof_array = np.array([0, 1, 2, 3, 5, 7])
dof = 2 * ps.smallest_hole_diameter**2 / source_wavelengths
focal_length = ps.diameter * ps.smallest_hole_diameter / source_wavelengths

psfs = PSFs(
    ps,
    source_wavelengths=source_wavelengths,
    measurement_wavelengths=ps.diameter * ps.smallest_hole_diameter /
    (focal_length + dof_array * dof),
    image_width=3001,
    sampling_interval=2.2e-6,
    psf_generator=circ_incoherent_psf,
)

# save to file
with h5py.File('/tmp/psfs.h5', 'w') as f:
Example #7
0
# source_wavelengths = np.array((90.359e-9, 90.399e-9))
# diameter = 5e-2
# smallest_hole_diameter = 15e-6
# csbs_lam = 5e-5
source_wavelengths = np.array((33.4e-9, 33.402e-9))
diameter = 16e-2
smallest_hole_diameter = 7e-6
print('DOF_separation = {}'.format(
    diameter * (source_wavelengths[1] - source_wavelengths[0]) /
    (2 * smallest_hole_diameter * source_wavelengths[0])))
sources = np.load('sources.npy')
order = 1
csbs_lam = 5e-4

ps = PhotonSieve(diameter=diameter,
                 smallest_hole_diameter=smallest_hole_diameter)
psfs_csbs = PSFs(
    ps,
    sampling_interval=3.5e-6,
    measurement_wavelengths=30,
    source_wavelengths=source_wavelengths,
    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,
Example #8
0
    def __init__(
            self,
            # experiment parameters
            exp_time=10,  # s
            drift_angle=-45,  # degrees
            drift_velocity=0.2e-3,  # meters / s
            angle_velocity=0,  # deg / s
            max_count=20,
            noise_model=get_visors_noise(),
            wavelengths=np.array([30.4e-9]),
            # CCD parameters
            frame_rate=4,  # Hz
            ccd_size=np.array((750, 750)),
            start=(1500, 1500),
            pixel_size=14e-6,  # meters
            # simulation subpixel parameters
        resolution_ratio=2,  # CCD pixel_size / simulation pixel_size
            fov_ratio=2,  # simulated FOV / CCD FOV
            # strand parameters
        scene=None,  # pregenerated scene
            num_strands=100,  # num strands per CCD FOV
            # sieve parameters
        diameter=75e-3,  # meters
            smallest_hole_diameter=17e-6,  # meters
    ):
        from mas.psf_generator import PSFs, PhotonSieve
        from mas.forward_model import get_measurements
        from mas.tracking import video

        self.ps = PhotonSieve(diameter=diameter,
                              smallest_hole_diameter=smallest_hole_diameter)
        self.psfs = PSFs(self.ps,
                         sampling_interval=pixel_size / resolution_ratio,
                         source_wavelengths=wavelengths,
                         measurement_wavelengths=wavelengths)

        # load common high resolution scene from file
        if scene is not None:
            scene = np.copy(scene)
        elif (num_strands, fov_ratio, resolution_ratio,
              ccd_size[0]) == (100, 2, 5, 160):
            from mas.data import strand_highres
            self.scene = strand_highres
        elif (num_strands, fov_ratio, resolution_ratio,
              ccd_size[0]) == (100, 2, 2, 750):
            from mas.data import strand_highres2
            self.scene = strand_highres2
        else:
            self.scene = strands(
                num_strands=int(num_strands * fov_ratio * ccd_size[0] / 160),
                thickness=22 * resolution_ratio,
                image_width=ccd_size[0] * resolution_ratio * fov_ratio,
                initial_width=3 * ccd_size[0] * resolution_ratio * fov_ratio)

        self.scene = get_measurements(sources=self.scene[np.newaxis, :, :],
                                      psfs=self.psfs)[0]

        self.scene *= max_count / np.max(self.scene)

        self.frames_clean, self.midpoint_coords = video(
            scene=self.scene,
            frame_rate=frame_rate,
            exp_time=exp_time,
            drift_angle=drift_angle,
            drift_velocity=drift_velocity,
            angle_velocity=angle_velocity,
            ccd_size=ccd_size,
            resolution_ratio=resolution_ratio,
            pixel_size=pixel_size,
            start=start)

        # add noise to the frames
        if noise_model is not None:
            self.frames = noise_model(self.frames_clean, frame_rate)
        else:
            self.frames = self.frames_clean

        self.true_drift = drift_velocity / frame_rate * np.array([
            -np.sin(np.deg2rad(drift_angle)),  # use image coordinate system
            np.cos(np.deg2rad(drift_angle))
        ]) / pixel_size
Example #9
0
#!/bin/env python3
# Comparison of in focus and out of focus PSFs for 9nm and 33.4nm

import matplotlib.pyplot as plt
from mas.psf_generator import PSFs, PhotonSieve, circ_incoherent_psf, sieve_incoherent_psf
from mas.plotting import plotter4d
import numpy as np

wavelengths = np.array([9, 33.5]) * 1e-9
ps = PhotonSieve(diameter=8e-2)
psfs = PSFs(sieve=ps,
            source_wavelengths=wavelengths,
            measurement_wavelengths=wavelengths,
            image_width=301,
            psf_generator=sieve_incoherent_psf)

# focused 9nm
plt.imshow(np.abs(psfs.psfs[0, 0]))
plt.axis([140, 160, 140, 160])
plt.title('9 nm, focused')
plt.savefig('9nm.png')
# focused 33.5nm
plt.imshow(np.abs(psfs.psfs[1, 1]))
plt.axis([140, 160, 140, 160])
plt.title('33.4 nm, focused')
plt.savefig('33.4nm.png')
plt.show()