Пример #1
0
def _simulate_sphere_data(params, theory):
    detector = hp.detector_grid(shape=100, spacing=.1)
    metadata = {
        'medium_index': 1.33,
        'illum_wavelen': 0.660,
        'illum_polarization': (1, 0)
    }
    sphere = hp.scattering.Sphere(n=params['n'],
                                  r=params['r'],
                                  center=(params['x'], params['y'],
                                          params['z']))
    if theory == 'mieonly':
        alpha = params['alpha']
        metadata['scaling'] = alpha
    elif theory == 'mielens':
        lens_angle = params['lens_angle']
        metadata['theory'] = hp.scattering.theory.MieLens(
            lens_angle=lens_angle)

    holo = hp.scattering.calc_holo(detector, sphere, **metadata)
    np.random.seed(RANDOM_SEED)
    noise = params['noise_sd'] * np.random.randn(*holo.shape)
    noisy_holo = hp.core.metadata.copy_metadata(holo, holo + noise)
    torch_holo = tensor(noisy_holo.values.squeeze(), dtype=torch.float32)
    return {'x': noisy_holo, 'y': torch_holo}
Пример #2
0
def bisphere(a_p, n_p, z_p, theta, phi, noise=True):
    px = int(feature_extent(a_p, n_p, z_p, config)) * 2
    detector = hp.detector_grid(2 * px, mag)
    center = (mag * px, mag * px, z_p)

    delta = np.array([
        np.cos(phi) * np.cos(theta),
        np.sin(phi) * np.cos(theta),
        np.sin(theta)
    ])
    c1 = +1.001 * a_p * delta
    c2 = -1.001 * a_p * delta
    cluster = np.array([c1, c2])

    cluster_return = cluster.copy().tolist()

    cluster += center

    s1 = Sphere(center=cluster[0], n=n_p, r=a_p)
    s2 = Sphere(center=cluster[1], n=n_p, r=a_p)

    dimer = Spheres([s1, s2])

    holo = np.squeeze(
        calc_holo(detector,
                  dimer,
                  medium_index=n_m,
                  illum_wavelen=wv,
                  illum_polarization=(1, 0))).data

    #noise
    if noise:
        holo += np.random.normal(0., 0.05, holo.shape)

    return holo, cluster_return
Пример #3
0
def make_field(particle_number, height, config):

    #Angles to rotate agg
    angle_1 = random.randint(1, 360)
    angle_2 = random.randint(1, 360)

    #Setting up medium, camera, and laser variables
    shape, _ = config['shape']
    spacing = config['instrument']['magnification']
    medium_index = config['instrument']['n_m']
    illum_wavelen = config['instrument']['wavelength']
    illum_polarization = (1, 0)
    detector = hp.detector_grid(shape=shape, spacing=spacing)

    #Particle_params
    radius = random.random(config['particle']['a_p'])
    refractive = random.random(config['particle']['n_p'])

    #choose random data_set
    data_name = (str(random.randint(0, 19)) + '.csv')

    #read in data
    df = pd.read_csv(data_name)
    x = df['x'].tolist()
    y = df['y'].tolist()
    z = df['z'].tolist()

    #Clear non-essential items
    x = x[0:particle_number + 1]
    y = y[0:particle_number + 1]
    z = z[0:particle_number + 1]

    #adjust distance between particles for particle size
    x = [item / (1 / (2 * radius)) for item in x]
    y = [item / (1 / (2 * radius)) for item in y]
    z = [item / (1 / (2 * radius)) for item in z]

    #rotate around x and then y axis
    x, y, z = rotation(x, y, z, angle_1, 'x')
    x, y, z = rotation(x, y, z, angle_2, 'y')

    #position agg
    x = [(item + shape * spacing / 2) for item in x]
    y = [(item + shape * spacing / 2) for item in y]
    z = [(item + height) for item in z]

    #scatter
    field = scatter(x,
                    y,
                    z,
                    particle_number,
                    radius,
                    detector,
                    medium_index,
                    illum_wavelen,
                    illum_polarization,
                    theory=Mie,
                    refractive=refractive)
    return field
Пример #4
0
def make_fake_data():
    detector = holopy.detector_grid([40, 40], spacing=2.878e-7)
    fake_data = calc_holo(
        detector,
        SPHERE,
        medium_index=1.33,
        illum_wavelen=6.58e-7,
        illum_polarization=(1, 0),
        theory='auto',
        scaling=CORRECT_ALPHA,)
    return fake_data
Пример #5
0
def sphere(a_p, n_p, z_p):
    px = int(feature_extent(a_p, n_p, z_p, config))
    detector = hp.detector_grid(2 * px, mag)
    center = (mag * px, mag * px, z_p)
    s = Sphere(center=center, n=n_p, r=a_p)

    holo = np.squeeze(
        calc_holo(detector,
                  s,
                  medium_index=n_m,
                  illum_wavelen=wv,
                  illum_polarization=(1, 0))).data

    #noise
    holo += np.random.normal(0., 0.05, holo.shape)

    return holo
Пример #6
0
from holopy.scattering import Spheres
from holopy.scattering import Cylinder

from holopy.core.io import get_example_data_path
imagepath = get_example_data_path('image0002.h5')
exp_img = hp.load(imagepath)
"""
Qui se vuoi fissare due posizioni specifiche
"""
sphere1 = Sphere(center=(20, 20, 7), n=1.59, r=0.3)  #all in micro m units
sphere2 = Sphere(center=(25.6, 25.6, 7), n=1.59, r=0.3)
collection = Spheres([sphere1, sphere2])
medium_index = 1.33
illum_wavelength = 0.660
illum_polarization = (1, 0)
detector = hp.detector_grid(shape=512, spacing=0.1)  #spacing=pix size

holo = calc_holo(detector, collection, medium_index, illum_wavelength,
                 illum_polarization)

hp.show(holo)
"""
for look the trasversal profile of hologram centred in partice position 

plt.title('Hologram')
plt.plot(holo[256])
plt.xlabel("Pixel")
plt.ylabel("Intensity")
plt.title('Holo Intensity')
plt.xlim(100, 400)
"""
Пример #7
0
import holopy as hp
from holopy.scattering import calc_holo, Sphere

sphere = Sphere(n=1.59, r=.5, center=(4, 4, 5))
detector = hp.detector_grid(shape=100, spacing=.1)
medium_index = 1.33
illum_wavelen = 0.660
illum_polarization = (1, 0)

from holopy.core.io import get_example_data_path
imagepath = get_example_data_path('image01.jpg')
exp_img = hp.load_image(imagepath,
                        spacing=0.0851,
                        medium_index=medium_index,
                        illum_wavelen=illum_wavelen,
                        illum_polarization=illum_polarization)
exp_img = exp_img[{'x': slice(0, 100), 'y': slice(0, 100)}]

from holopy.scattering import Spheres
s1 = Sphere(center=(5, 5, 5), n=1.59, r=.5)
s2 = Sphere(center=(4, 4, 5), n=1.59, r=.5)
collection = Spheres([s1, s2])
holo = calc_holo(exp_img, collection)
hp.show(holo)
Пример #8
0
def trisphere(a_p, n_p, z_p, alpha, theta, phi, check_geom=False):
    '''                                                                                                                                                                                                     
    alpha: angle of 3rd monomer wrt dimer                                                                                                                                                                   
    -alpha=pi/3: equilateral triangle                                                                                                                                                                       
    -alpha between pi/3 and 5pi/3 (no overlaps)                                                                                                                                                             
                                                                                                                                                                                                            
    theta, phi: rotation angles                                                                                                                                                                             
    -theta=0 : aligned along xy plane                                                                                                                                                                       
    -theta between 0 and 2pi                                                                                                                                                                                
    -phi between 0 and 2pi                                                                                                                                                                                  
    '''
    px = int(feature_extent(a_p, n_p, z_p, config)) * 2
    detector = hp.detector_grid(2 * px, mag)
    center = (mag * px, mag * px, z_p)

    if alpha < np.pi / 3 or alpha > 5 * np.pi / 3:
        raise Exception("Invalid value for alpha")

    #rotation about origin
    #delta = np.array([np.cos(phi)*np.cos(theta), np.sin(phi)*np.cos(theta), np.sin(theta)])
    delta = np.array([1, 0, 0])

    #angle of third monomer wrt dimer
    delta_2 = np.array([-np.cos(alpha), np.sin(alpha), 0])
    c1 = 1.001 * a_p * delta
    c2 = -1.001 * a_p * delta
    c3 = c1 + 2.001 * a_p * delta_2

    cluster = np.array([c1, c2, c3])

    #get centroid of trimer and re-center
    centroid = np.mean(np.array([c1, c2, c3]), axis=0)
    cluster -= centroid

    #rotate trimer
    zax = np.array([0, 0, 1])
    xax = np.array([1, 0, 0])
    zrot = lambda c: rotate(c, zax, phi)
    xrot = lambda c: rotate(c, xax, theta)

    cluster = zrot(cluster)
    cluster = xrot(cluster)

    cluster_return = cluster.copy().tolist()

    #place in particle position
    cluster += center

    s1 = Sphere(center=cluster[0], n=n_p, r=a_p)
    s2 = Sphere(center=cluster[1], n=n_p, r=a_p)
    s3 = Sphere(center=cluster[2], n=n_p, r=a_p)

    trimer = Spheres([s1, s2, s3])

    r_sum = 4 * a_p
    if check_geom:
        #geometry check
        npix = 60  #npix x npix grid
        coord_range = np.linspace(mag * px - r_sum, mag * px + r_sum, num=npix)
        x, y = np.meshgrid(coord_range, coord_range)
        trimer_points = np.zeros((npix, npix))
        for i in range(npix):
            for j in range(npix):
                coord = [x[i][j], y[i][j], z_p]
                if trimer.contains(coord):
                    trimer_points[i][j] = 1
        plt.imshow(trimer_points)
        plt.show()

    holo = np.squeeze(
        calc_holo(detector,
                  trimer,
                  medium_index=n_m,
                  illum_wavelen=wv,
                  illum_polarization=(1, 0))).data

    #noise
    holo += np.random.normal(0., 0.05, holo.shape)

    return holo, cluster_return
Пример #9
0
## If the figures do not pop out in a different window,
## use this command in the console window:
## %matplotlib qt

import holopy as hp
from holopy.scattering import calc_holo, Sphere
import numpy as np
from holopy.scattering import calc_scat_matrix, calc_intensity, calc_field
import matplotlib.pyplot as plt

medium_index = 1.33
illum_wavelen = 0.750  # 750nm
illum_polarization = (1, 0)  # x polarized
sphere_z_position = 2  # in microns
detector = hp.detector_grid(shape=201, spacing=.1)
distant_sphere = Sphere(r=0.5,
                        n=1.59,
                        center=(10.05, 10.05, sphere_z_position))

## Calculate the field here given above paramters
scat = calc_field(detector, distant_sphere, medium_index, illum_wavelen,
                  illum_polarization)
scattered_matrix = scat.data
scat_intensity_x = scattered_matrix[0, :, :, 0]
scat_intensity_y = scattered_matrix[1, :, :, 0]
scat_intensity_z = scattered_matrix[2, :, :, 0]

# real value
scat_x_real = scat_intensity_x.real
# imaginary value
Пример #10
0
import holopy as hp
from holopy.scattering import calc_holo, Sphere

sphere = Sphere(n = 1.59, r = .5, center = (4, 4, 5))
detector = hp.detector_grid(shape = 100, spacing = .1)
medium_index = 1.33
illum_wavelen = 0.660
illum_polarization = (1,0)

from holopy.core.io import get_example_data_path
imagepath = get_example_data_path('image01.jpg')
exp_img = hp.load_image(imagepath, spacing=0.0851, medium_index=medium_index, illum_wavelen=illum_wavelen, illum_polarization=illum_polarization)
exp_img = exp_img[{'x':slice(0,100),'y':slice(0,100)}]

from holopy.scattering import Spheres
s1 = Sphere(center=(5, 5, 5), n = 1.59, r = .5)
s2 = Sphere(center=(4, 4, 5), n = 1.59, r = .5)
collection = Spheres([s1, s2])
holo = calc_holo(exp_img, collection)
hp.show(holo)