Exemple #1
0
    def test_psf_comparison(self):
        """Validate a generated kernel against the same thing from PSFGenerator"""

        k_actual = psf.GibsonLanni(size_x=16,
                                   size_y=16,
                                   size_z=8,
                                   pz=0.,
                                   wavelength=.610,
                                   na=1.4,
                                   res_lateral=.1,
                                   res_axial=.25).generate()

        # The following image used for comparison was generated via PSFGenerator
        # with these arguments (where any not mentioned were left at default):
        # Optical Model: "Gibson & Lanni 3D Optical Model"
        # NA: 1.4
        # Particle position Z: 0
        # Wavelength: 610 (nm)
        # Pixelsize XY: 100 (nm)
        # Z-step: 250 (nm)
        # Size XYZ: 16, 16, 8
        path = data._get_dataset_path(os.path.join('psfs', 'psfgen1.tif'))
        k_expect = io.imread(path)

        assert_almost_equal(k_actual, k_expect, decimal=4)
Exemple #2
0
    def test_psf_config_io(self):
        """Validate that PSF can be saved to and restored from configuration files"""
        import tempfile

        # Generate a PSF object with at least some non-default args
        k1 = psf.GibsonLanni(size_x=16,
                             size_y=16,
                             size_z=8,
                             pz=0.,
                             wavelength=.425,
                             na=.75,
                             res_lateral=.377,
                             res_axial=1.5)

        # Create kernel from psf and save as configuration file
        d_before = k1.generate()
        f = tempfile.mktemp(suffix='.json', prefix='psf-config')
        k1.save(f)

        # Restore from configuration file and generate kernel again
        k2 = psf.GibsonLanni.load(f)
        d_after = k2.generate()

        # Check that both configuration and generated kernels are equal
        self.assertEqual(k1.config, k2.config)
        assert_array_equal(d_before, d_after)

        # Delete config file
        os.unlink(f)
Exemple #3
0
    def generatePSF(self):
        psf = fd_psf.GibsonLanni(   size_x=self.sizeX,
                                    size_y=self.sizeY,
                                    size_z=self.sizeZ,
                                    na=self.LensNA,
                                    wavelength=self.ExcitationWavelength/1000,
                                    m=self.NominalMagnification,
                                    ns=self.RefractiveIndex,
                                    #min_wavelength=self.minWavelength/1000
                                    )

        return psf.generate()
    def create_psf(self):
        experiment_metadata = experiment_global['experiment_json']
        args = dict(
            # Set psf dimensions to match volumes
            size_x=int(experiment_metadata['tileWidth']),
            size_y=int(experiment_metadata['tileHeight']),
            size_z=int(experiment_metadata['numZPlanes']),

            # Magnification factor
            m=float(experiment_metadata['magnification']),

            # Numerical aperture
            na=float(experiment_metadata['aperture']),

            # Axial resolution in microns (nm in akoya config)
            res_axial=float(experiment_metadata['zPitch']) / 1000.,

            # Lateral resolution in microns (nm in akoya config)
            res_lateral=float(experiment_metadata['xyResolution']) / 1000.,

            # Immersion refractive index
            ni0=1.0,

            # Set "particle position" in Gibson-Lannie to 0 which gives a
            # Born & Wolf kernel as a degenerate case
            pz=0.)

        multi_psf = {}
        psf_struct = {'wavelength': [], 'psf': []}
        ch_names = list(experiment_metadata['wavelengths'])

        for n in range(len(ch_names)):
            wavelength = float(experiment_metadata['wavelengths'][n])

            psf_single = fd_psf.GibsonLanni(**{
                **args,
                **{
                    'wavelength': wavelength / 1000.
                }
            }).generate()
            psf_struct = {'wavelength': wavelength, 'psf': psf_single}
            multi_psf.update({''.join(['CH', str(n + 1)]): psf_struct})
            psf_struct = {'wavelength': [], 'psf': []}
            p_value = ((n + 1) * 100) / len(ch_names)
            self.bar.setValue(p_value)

        self.bar.setValue(p_value)
        experiment_global['multi_psf'] = multi_psf
Exemple #5
0
def generate_psfs(config):
    mag, na, res_axial_nm, res_lateral_nm, objective_type, em_wavelength_nm = config.microscope_params
    args = dict(
        # Set psf dimensions to match volumes
        size_x=config.tile_width,
        size_y=config.tile_height,
        size_z=config.n_z_planes,

        # Magnification factor
        m=mag,

        # Numerical aperture
        na=na,

        # Axial resolution in microns
        res_axial=res_axial_nm / 1000.,

        # Lateral resolution in microns
        res_lateral=res_lateral_nm / 1000.,

        # Immersion refractive index
        ni0=get_immersion_ri(objective_type),

        # Set "particle position" in Gibson-Lannie to 0 which gives a
        # Born & Wolf kernel as a degenerate case
        pz=0.,

        # Lower this parameter as it was shown to produce results more
        # closely resembling PSFGenerator, especially for higher energy light
        min_wavelength=0.35)

    logger.debug('Generating PSFs from experiment configuration file')
    # Specify a psf for each emission wavelength in microns
    return [
        fd_psf.GibsonLanni(**{
            **args,
            **{
                'wavelength': w / 1000.
            }
        }).generate() for w in em_wavelength_nm
    ]
Exemple #6
0
def generate_psfs(args, config):
    args = dict(
        # Set psf dimensions to match volumes
        size_x=config.exp_config['tile_width'],
        size_y=config.exp_config['tile_height'],
        size_z=config.exp_config['num_z_planes'],

        # Magnification factor
        m=config.exp_config['magnification'],

        # Numerical aperture
        na=config.exp_config['numerical_aperture'],

        # Axial resolution in microns (nm in akoya config)
        res_axial=config.exp_config['z_pitch'] / 1000.,

        # Lateral resolution in microns (nm in akoya config)
        res_lateral=config.exp_config['per_pixel_XY_resolution'] / 1000.,

        # Immersion refractive index
        ni0=utils.get_immersion_ri(config.exp_config['objectiveType']),

        # Set "particle position" in Gibson-Lannie to 0 which gives a
        # Born & Wolf kernel as a degenerate case
        pz=0.)

    logger.debug('Generating PSFs from experiment configuration file')
    # Specify a psf for each emission wavelength in microns (nm in akoya config)
    return [
        fd_psf.GibsonLanni(**{
            **args,
            **{
                'wavelength': w / 1000.
            }
        }).generate() for w in config.exp_config['emission_wavelengths']
    ]