Skip to content

Commit

Permalink
simulation: make sample gen faster
Browse files Browse the repository at this point in the history
  • Loading branch information
antonxy committed Feb 2, 2022
1 parent ac7d4dd commit 75451f7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
1 change: 1 addition & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ in rec {
pypkgs.ipython
pypkgs.scipy
pypkgs.pyside2
pypkgs.scikitimage
];

#LD_LIBRARY_PATH = "${pypkgs.pyside.dev}/lib";
Expand Down
2 changes: 1 addition & 1 deletion sim_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self):
self.exposure_lbl = QtWidgets.QLabel()
layout.addRow("Exposure time", self.exposure_lbl)

self.reconstruction_size_txt = QtWidgets.QLineEdit("128")
self.reconstruction_size_txt = QtWidgets.QLineEdit("256")
layout.addRow("Reconstruction size N", self.reconstruction_size_txt)

self.reconstruction_offset_x = QtWidgets.QLineEdit("0")
Expand Down
20 changes: 11 additions & 9 deletions sim_simulated_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
from scipy.ndimage import gaussian_filter
import numpy.fft as fft
from numpy import newaxis
import skimage
import skimage.draw
import time
import random

import matplotlib.pyplot as plt

Expand All @@ -25,7 +28,7 @@ def fft_downsample(img, block_size=2):

class SIMSimulatedSystem:
def __init__(self):
self.N = 128
self.N = 256
# Optics parameters
pixelsize = 11 # camera pixel size, um
magnification = 1.5 # objective magnification
Expand Down Expand Up @@ -69,19 +72,18 @@ def configure_camera(self, exposure_time_sec):
pass

def sample(self):
# Sample
O = np.zeros((self.sim_N, self.sim_N))
# TODO this is slow, do something smarter
axy = self.coords(self.sim_N)
for i in range(200):
xyshift = (np.random.rand(1, 2) - 0.5) * self.sample_width
xy_shifted = axy + xyshift
O = np.maximum(O, ((np.sum((xy_shifted)**2, axis=2) < 5**2) * (np.random.rand(1) + 1)))
return np.maximum(O, (np.sum((axy)**2, axis=2) < 200**2)) * 20
center = (random.random() * self.sim_N for i in range(2))
rr, cc = skimage.draw.disk(center, 5 / self._dx * self.sim_oversample, shape=O.shape)
O[rr, cc] += 1.0
rr, cc = skimage.draw.disk((self.sim_N / 2, self.sim_N / 2), 200 / self._dx * self.sim_oversample, shape=O.shape)
O[rr, cc] += 1.0
return O

def illumination(self, pattern_deg):
I = np.zeros((self.sim_N, self.sim_N))
deg_to_um = 1000.0
deg_to_um = 700.0
center_um = np.array([self.sample_width / 2] * 2)
pattern_um = (pattern_deg * deg_to_um) + center_um
pattern_idx = np.round(pattern_um / self._dx * self.sim_oversample).astype(np.int32)
Expand Down

0 comments on commit 75451f7

Please sign in to comment.