def createMovie(movie_name): # Create drift file, this is used to displace the localizations in the # PSF measurement movie. # dz = numpy.arange(-z_range, z_range + 0.001, 0.01) drift_data = numpy.zeros((dz.size, 3)) drift_data[:, 2] = dz numpy.savetxt("drift.txt", drift_data) bg_f = lambda s, x, y, i3: background.UniformBackground( s, x, y, i3, photons=bg) cam_f = lambda s, x, y, i3: camera.Ideal(s, x, y, i3, camera_offset) drift_f = lambda s, x, y, i3: drift.DriftFromFile(s, x, y, i3, "drift.txt") pp_f = lambda s, x, y, i3: photophysics.SimpleSTORM(s, x, y, i3, signal) psf_f = lambda s, x, y, i3: psf.PupilFunction(s, x, y, i3, pixel_size, [[0.8, 2, 2]]) sim = simulate.Simulate(background_factory=bg_f, camera_factory=cam_f, drift_factory=drift_f, photophysics_factory=pp_f, psf_factory=psf_f, x_size=x_size, y_size=y_size) sim.simulate(movie_name, "random_locs.hdf5", dz.size)
def makeSampleData(): # Create sample bead data for fiducial tracking. # # Create randomly located localizations file. # print("Creating random localizations.") sim_path = os.path.dirname(inspect.getfile(storm_analysis)) + "/simulator/" subprocess.call([ "python", sim_path + "emitters_uniform_random.py", "--bin", "random.hdf5", "--density", str(density), "--margin", str(margin), "--sx", str(x_size), "--sy", str(y_size) ]) # Create X/Y/Z drift file. # dx = numpy.random.normal(loc=x_loc, scale=x_scale, size=n_frames) dy = numpy.random.normal(loc=y_loc, scale=y_scale, size=n_frames) # Integrate dx, dy for i in range(1, dx.size): dx[i] = dx[i - 1] + dx[i] dy[i] = dy[i - 1] + dy[i] drift_data = numpy.zeros((dx.size, 3)) drift_data[:, 0] = dx drift_data[:, 1] = dy numpy.savetxt("drift.txt", drift_data) # Create simulated data for fiducial tracking. # bg_f = lambda s, x, y, h5: background.UniformBackground( s, x, y, h5, photons=10) cam_f = lambda s, x, y, h5: camera.Ideal(s, x, y, h5, camera_offset) drift_f = lambda s, x, y, h5: drift.DriftFromFile(s, x, y, h5, "drift.txt") pp_f = lambda s, x, y, h5: photophysics.SimpleSTORM( s, x, y, h5, 4000, on_time=10.0, off_time=1.0) psf_f = lambda s, x, y, h5: psf.GaussianPSF(s, x, y, h5, pixel_size) sim = simulate.Simulate(background_factory=bg_f, camera_factory=cam_f, drift_factory=drift_f, photophysics_factory=pp_f, psf_factory=psf_f, x_size=x_size, y_size=y_size) sim.simulate("fiducials.tif", "random.hdf5", n_frames)
def test_simulate_2(): """ (Simple) STORM photo-physics, pure astigmatism PSF, EMCCD camera. """ dax_name = storm_analysis.getPathOutputTest("test_sim2.dax") bin_name = storm_analysis.getData("test/data/test_sim.hdf5") sim = simulate.Simulate(background_factory = lambda settings, xs, ys, i3data : background.UniformBackground(settings, xs, ys, i3data, photons = 20), camera_factory = lambda settings, xs, ys, i3data : camera.EMCCD(settings, xs, ys, i3data, 100.0, emccd_gain = 5.0, preamp_gain = 1.0, read_noise = 5), photophysics_factory = lambda settings, xs, ys, i3data : photophysics.SimpleSTORM(settings, xs, ys, i3data, 4000.0, off_time = 10.0), psf_factory = lambda settings, xs, ys, i3data : psf.PupilFunction(settings, xs, ys, i3data, 160.0, [[1.3, 2, 2]]), x_size = 100, y_size = 75) sim.simulate(dax_name, bin_name, 5)
def createMovieRandom(n_frames): bg_f = lambda s, x, y, i3: background.UniformBackground( s, x, y, i3, photons=bg) cam_f = lambda s, x, y, i3: camera.Ideal(s, x, y, i3, camera_offset) pp_f = lambda s, x, y, i3: photophysics.SimpleSTORM(s, x, y, i3, signal) psf_f = lambda s, x, y, i3: psf.GaussianPSF(s, x, y, i3, pixel_size) sim = simulate.Simulate(background_factory=bg_f, camera_factory=cam_f, photophysics_factory=pp_f, psf_factory=psf_f, x_size=x_size, y_size=y_size) sim.simulate("random.tif", "random_locs.hdf5", n_frames)
def createMovie(gain=1.0, offset=100.0): bg_f = lambda s, x, y, h5: background.GaussianBackground( s, x, y, h5, photons=bg) cam_f = lambda s, x, y, h5: camera.Ideal(s, x, y, h5, offset, gain=gain) pp_f = lambda s, x, y, h5: photophysics.SimpleSTORM( s, x, y, h5, photons=signal) psf_f = lambda s, x, y, h5: psf.GaussianPSF(s, x, y, h5, pixel_size) sim = simulate.Simulate(background_factory=bg_f, camera_factory=cam_f, photophysics_factory=pp_f, psf_factory=psf_f, x_size=x_size, y_size=y_size) sim.simulate("test.tif", "sim_locs.hdf5", n_frames)
def makeSampleData(): # Create sample bead data for fiducial tracking. # # Create randomly located localizations file. # print("Creating random localizations.") emittersUniformRandom.emittersUniformRandom("random.hdf5", density, margin, x_size, y_size, 0.0) # Create X/Y/Z drift file. # dx = numpy.random.normal(loc=x_loc, scale=x_scale, size=n_frames) dy = numpy.random.normal(loc=y_loc, scale=y_scale, size=n_frames) # Integrate dx, dy for i in range(1, dx.size): dx[i] = dx[i - 1] + dx[i] dy[i] = dy[i - 1] + dy[i] drift_data = numpy.zeros((dx.size, 3)) drift_data[:, 0] = dx drift_data[:, 1] = dy numpy.savetxt("drift.txt", drift_data) # Create simulated data for fiducial tracking. # bg_f = lambda s, x, y, h5: background.UniformBackground( s, x, y, h5, photons=10) cam_f = lambda s, x, y, h5: camera.Ideal(s, x, y, h5, camera_offset) drift_f = lambda s, x, y, h5: drift.DriftFromFile(s, x, y, h5, "drift.txt") pp_f = lambda s, x, y, h5: photophysics.SimpleSTORM( s, x, y, h5, 4000, on_time=10.0, off_time=1.0) psf_f = lambda s, x, y, h5: psf.GaussianPSF(s, x, y, h5, pixel_size) sim = simulate.Simulate(background_factory=bg_f, camera_factory=cam_f, drift_factory=drift_f, photophysics_factory=pp_f, psf_factory=psf_f, x_size=x_size, y_size=y_size) sim.simulate("fiducials.tif", "random.hdf5", n_frames)
def makeData(): index = 1 # Gaussian non-uniform background, STORM. if True: for elt in ["drift_xy.txt", "drift_xyz.txt"]: bg = settings.background photons = settings.photons wdir = "test_{0:02d}".format(index) print(wdir) if not os.path.exists(wdir): os.makedirs(wdir) bg_f = lambda s, x, y, i3: background.GaussianBackground( s, x, y, i3, photons=bg) cam_f = lambda s, x, y, i3: camera.Ideal(s, x, y, i3, settings. camera_offset) drift_f = lambda s, x, y, i3: drift.DriftFromFile(s, x, y, i3, elt) pp_f = lambda s, x, y, i3: photophysics.SimpleSTORM( s, x, y, i3, photons) psf_f = lambda s, x, y, i3: psf.GaussianPSF( s, x, y, i3, settings.pixel_size) sim = simulate.Simulate(background_factory=bg_f, camera_factory=cam_f, drift_factory=drift_f, photophysics_factory=pp_f, psf_factory=psf_f, x_size=settings.x_size, y_size=settings.y_size) sim.simulate(wdir + "/test.dax", "clusters_list.hdf5", settings.n_frames) #sim.simulate(wdir + "/test.dax", "lines_list.hdf5", settings.n_frames) index += 1
def makeData(dither = False): index = 1 # Gaussian PSF, uniform background. if True: for [bg, photons] in settings.photons: wdir = "test_{0:02d}".format(index) print(wdir) if not os.path.exists(wdir): os.makedirs(wdir) bg_f = lambda s, x, y, i3 : background.UniformBackground(s, x, y, i3, photons = bg) cam_f = lambda s, x, y, i3 : camera.Ideal(s, x, y, i3, settings.camera_offset) pp_f = lambda s, x, y, i3 : photophysics.AlwaysOn(s, x, y, i3, photons) psf_f = lambda s, x, y, i3 : psf.GaussianPSF(s, x, y, i3, settings.pixel_size) sim = simulate.Simulate(background_factory = bg_f, camera_factory = cam_f, photophysics_factory = pp_f, psf_factory = psf_f, dither = dither, x_size = settings.x_size, y_size = settings.y_size) sim.simulate(wdir + "/test.dax", "grid_list.hdf5", settings.n_frames) index += 1 # Pupil Function PSF. if False: for [bg, photons] in settings.photons: wdir = "test_{0:02d}".format(index) print(wdir) if not os.path.exists(wdir): os.makedirs(wdir) bg_f = lambda s, x, y, i3 : background.UniformBackground(s, x, y, i3, photons = bg) cam_f = lambda s, x, y, i3 : camera.Ideal(s, x, y, i3, settings.camera_offset) pp_f = lambda s, x, y, i3 : photophysics.AlwaysOn(s, x, y, i3, photons) psf_f = lambda s, x, y, i3 : psf.PupilFunction(s, x, y, i3, settings.pixel_size, []) sim = simulate.Simulate(background_factory = bg_f, camera_factory = cam_f, photophysics_factory = pp_f, psf_factory = psf_f, x_size = settings.x_size, y_size = settings.y_size) sim.simulate(wdir + "/test.dax", "grid_list.hdf5", settings.n_frames) index += 1 # Gaussian non-uniform background, always on. if False: for [bg, photons] in settings.photons: wdir = "test_{0:02d}".format(index) print(wdir) if not os.path.exists(wdir): os.makedirs(wdir) bg_f = lambda s, x, y, i3 : background.GaussianBackground(s, x, y, i3, photons = bg) cam_f = lambda s, x, y, i3 : camera.Ideal(s, x, y, i3, settings.camera_offset) pp_f = lambda s, x, y, i3 : photophysics.AlwaysOn(s, x, y, i3, photons) psf_f = lambda s, x, y, i3 : psf.GaussianPSF(s, x, y, i3, settings.pixel_size) sim = simulate.Simulate(background_factory = bg_f, camera_factory = cam_f, photophysics_factory = pp_f, psf_factory = psf_f, x_size = settings.x_size, y_size = settings.y_size) sim.simulate(wdir + "/test.dax", "grid_list.hdf5", settings.n_frames) index += 1 # Uniform background, STORM. if False: for [bg, photons] in settings.photons: wdir = "test_{0:02d}".format(index) print(wdir) if not os.path.exists(wdir): os.makedirs(wdir) bg_f = lambda s, x, y, i3 : background.UniformBackground(s, x, y, i3, photons = bg) cam_f = lambda s, x, y, i3 : camera.Ideal(s, x, y, i3, settings.camera_offset) pp_f = lambda s, x, y, i3 : photophysics.SimpleSTORM(s, x, y, i3, photons) psf_f = lambda s, x, y, i3 : psf.GaussianPSF(s, x, y, i3, settings.pixel_size) sim = simulate.Simulate(background_factory = bg_f, camera_factory = cam_f, photophysics_factory = pp_f, psf_factory = psf_f, x_size = settings.x_size, y_size = settings.y_size) sim.simulate(wdir + "/test.dax", "random_list.hdf5", settings.n_frames) index += 1 # Gaussian non-uniform background, STORM. if False: for [bg, photons] in settings.photons: wdir = "test_{0:02d}".format(index) print(wdir) if not os.path.exists(wdir): os.makedirs(wdir) bg_f = lambda s, x, y, i3 : background.GaussianBackground(s, x, y, i3, photons = bg) cam_f = lambda s, x, y, i3 : camera.Ideal(s, x, y, i3, settings.camera_offset) pp_f = lambda s, x, y, i3 : photophysics.SimpleSTORM(s, x, y, i3, photons) psf_f = lambda s, x, y, i3 : psf.GaussianPSF(s, x, y, i3, settings.pixel_size) sim = simulate.Simulate(background_factory = bg_f, camera_factory = cam_f, photophysics_factory = pp_f, psf_factory = psf_f, x_size = settings.x_size, y_size = settings.y_size) sim.simulate(wdir + "/test.dax", "random_list.hdf5", settings.n_frames) index += 1 # Sloped non-uniform background, always on. if False: for [bg, photons] in settings.photons: wdir = "test_{0:02d}".format(index) print(wdir) if not os.path.exists(wdir): os.makedirs(wdir) bg_f = lambda s, x, y, i3 : background.SlopedBackground(s, x, y, i3, slope = 0.4, offset = 10) cam_f = lambda s, x, y, i3 : camera.Ideal(s, x, y, i3, settings.camera_offset) pp_f = lambda s, x, y, i3 : photophysics.AlwaysOn(s, x, y, i3, photons) psf_f = lambda s, x, y, i3 : psf.GaussianPSF(s, x, y, i3, settings.pixel_size) sim = simulate.Simulate(background_factory = bg_f, camera_factory = cam_f, photophysics_factory = pp_f, psf_factory = psf_f, dither = True, x_size = settings.x_size, y_size = settings.y_size) sim.simulate(wdir + "/test.dax", "grid_list.hdf5", settings.n_frames) index += 1 # Sine non-uniform background, always on. if False: for [bg, photons] in settings.photons: wdir = "test_{0:02d}".format(index) print(wdir) if not os.path.exists(wdir): os.makedirs(wdir) bg_f = lambda s, x, y, i3 : background.SineBackground(s, x, y, i3, photons = bg, period = 45) cam_f = lambda s, x, y, i3 : camera.Ideal(s, x, y, i3, settings.camera_offset) pp_f = lambda s, x, y, i3 : photophysics.AlwaysOn(s, x, y, i3, photons) psf_f = lambda s, x, y, i3 : psf.GaussianPSF(s, x, y, i3, settings.pixel_size) sim = simulate.Simulate(background_factory = bg_f, camera_factory = cam_f, photophysics_factory = pp_f, psf_factory = psf_f, dither = True, x_size = settings.x_size, y_size = settings.y_size) sim.simulate(wdir + "/test.dax", "grid_list.hdf5", settings.n_frames) index += 1 # Create "peak_locations" file if needed. # if hasattr(settings, "peak_locations") and (settings.peak_locations is not None): with saH5Py.SAH5Py("test_01/test_ref.hdf5") as h5: locs = h5.getLocalizationsInFrame(0) if settings.peak_locations.endswith(".hdf5"): saH5Py.saveLocalizations(settings.peak_locations, locs) else: numpy.savetxt(settings.peak_locations, numpy.transpose(numpy.vstack((locs['x'], locs['y'], locs['height'], locs['background']))))
for elt in ["drift_xy.txt", "drift_xyz.txt"]: bg = settings.background photons = settings.photons wdir = "test_{0:02d}".format(index) print(wdir) if not os.path.exists(wdir): os.makedirs(wdir) bg_f = lambda s, x, y, i3: background.GaussianBackground( s, x, y, i3, photons=bg) cam_f = lambda s, x, y, i3: camera.Ideal(s, x, y, i3, settings. camera_offset) drift_f = lambda s, x, y, i3: drift.DriftFromFile(s, x, y, i3, elt) pp_f = lambda s, x, y, i3: photophysics.SimpleSTORM( s, x, y, i3, photons) psf_f = lambda s, x, y, i3: psf.GaussianPSF(s, x, y, i3, settings. pixel_size) sim = simulate.Simulate(background_factory=bg_f, camera_factory=cam_f, drift_factory=drift_f, photophysics_factory=pp_f, psf_factory=psf_f, x_size=settings.x_size, y_size=settings.y_size) sim.simulate(wdir + "/test.dax", "clusters_list.hdf5", settings.n_frames) #sim.simulate(wdir + "/test.dax", "lines_list.hdf5", settings.n_frames)
def makeData(): # Create .bin files for each plane. h5_locs = saH5Py.loadLocalizations("grid_list.hdf5") # Load channel to channel mapping file. with open("map.map", 'rb') as fp: mappings = pickle.load(fp) # Add z offset to reference localizations. x = h5_locs["x"].copy() y = h5_locs["y"].copy() z = h5_locs["z"].copy() + settings.z_planes[0] h5_temp = {"x" : x, "y" : y, "z" : z} saH5Py.saveLocalizations("sim_input_c1.hdf5", h5_temp) # Create a movie for first plane. [bg, photons] = settings.photons # Adjust photons by the number of planes. photons = photons/float(len(settings.z_planes)) bg_f = lambda s, x, y, i3 : background.UniformBackground(s, x, y, i3, photons = bg) cam_f = lambda s, x, y, i3 : camera.SCMOS(s, x, y, i3, "calib.npy") pp_f = lambda s, x, y, i3 : photophysics.SimpleSTORM(s, x, y, i3, photons = photons, on_time = settings.on_time, off_time = settings.off_time) psf_f = lambda s, x, y, i3 : psf.PupilFunction(s, x, y, i3, settings.pixel_size, settings.pupil_fn) sim = simulate.Simulate(background_factory = bg_f, camera_factory = cam_f, photophysics_factory = pp_f, psf_factory = psf_f, x_size = settings.x_size, y_size = settings.y_size) sim.simulate(os.path.join(settings.wdir, "test_c1.dax"), "sim_input_c1.hdf5", settings.n_frames) # Create other movies. for i in range(1, len(settings.z_planes)): cx = mappings["0_" + str(i) + "_x"] cy = mappings["0_" + str(i) + "_y"] z_offset = settings.z_planes[i] - settings.z_planes[0] pp_f = lambda s, x, y, i3 : photophysics.Duplicate(s, x, y, i3, h5_name = os.path.join(settings.wdir, "test_c1_ref.hdf5"), cx = cx, cy = cy, z_offset = z_offset) sim = simulate.Simulate(background_factory = bg_f, camera_factory = cam_f, photophysics_factory = pp_f, psf_factory = psf_f, x_size = settings.x_size, y_size = settings.y_size) sim.simulate(os.path.join(settings.wdir, "test_c" + str(i+1) + ".dax"), "sim_input_c1.hdf5", # This is not actually used. settings.n_frames) # Remove any old XML files. for elt in glob.glob(os.path.join(settings.wdir, "job*.xml")): os.remove(elt) # Make analysis XML files. splitAnalysisXML.splitAnalysisXML(settings.wdir, "multiplane.xml", 0, settings.n_frames, settings.divisions)
def makeDataSpliner(): index = 1 # Non-uniform background, STORM. # if False: for [bg, photons] in settings.photons: wdir = "test_{0:02d}".format(index) print(wdir) if not os.path.exists(wdir): os.makedirs(wdir) bg_f = lambda s, x, y, i3: background.GaussianBackground( s, x, y, i3, photons=bg) cam_f = lambda s, x, y, i3: camera.Ideal(s, x, y, i3, settings. camera_offset) pp_f = lambda s, x, y, i3: photophysics.SimpleSTORM( s, x, y, i3, photons) psf_f = lambda s, x, y, i3: psf.GaussianPSF( s, x, y, i3, settings.pixel_size) sim = simulate.Simulate(background_factory=bg_f, camera_factory=cam_f, photophysics_factory=pp_f, psf_factory=psf_f, x_size=settings.x_size, y_size=settings.y_size) sim.simulate(wdir + "/test.dax", "random_list.hdf5", settings.n_frames) index += 1 # Ideal camera movies, PSF using the measured spline. # if False: for [bg, photons] in settings.photons: wdir = "test_{0:02d}".format(index) print(wdir) if not os.path.exists(wdir): os.makedirs(wdir) bg_f = lambda s, x, y, i3: background.UniformBackground( s, x, y, i3, photons=bg) cam_f = lambda s, x, y, i3: camera.Ideal(s, x, y, i3, settings. camera_offset) pp_f = lambda s, x, y, i3: photophysics.AlwaysOn( s, x, y, i3, photons) psf_f = lambda s, x, y, i3: psf.Spline(s, x, y, i3, settings. pixel_size, "psf.spline") sim = simulate.Simulate(background_factory=bg_f, camera_factory=cam_f, photophysics_factory=pp_f, psf_factory=psf_f, x_size=settings.x_size, y_size=settings.y_size) sim.simulate(wdir + "/test.dax", "grid_list.hdf5", settings.n_frames) index += 1 # Create "peak_locations" file if needed. # if hasattr(settings, "peak_locations") and (settings.peak_locations is not None): with saH5Py.SAH5Py("test_01/test_ref.hdf5") as h5: locs = h5.getLocalizationsInFrame(0) if settings.peak_locations.endswith(".hdf5"): saH5Py.saveLocalizations(settings.peak_locations, locs) else: numpy.savetxt( settings.peak_locations, numpy.transpose( numpy.vstack((locs['x'], locs['y'], locs['height'], locs['background']))))