def _init_support_algorithms(self):
     if not self._support_algorithms_dirty:
         self._log("Support algorithms already initialised.","DEBUG")
         return       
     i = 0
     for alg_conf in self._support_algorithms_configs:
         alg = dict(alg_conf)
         if alg_conf["number_of_iterations"] is None:
             if len(self._support_algorithms_configs) == 1:
                 alg["number_of_iterations"] = self._number_of_iterations
             else:
                 self._log("Number of iterations can not be None if many support algorithms are specified. Please report this error.","ERROR")
                 return
         if alg["type"] == "area":
             blur_radius = spimage.sp_smap_alloc(2)
             spimage.sp_smap_insert(blur_radius, i, alg["blur_init"])
             spimage.sp_smap_insert(blur_radius, i + alg["number_of_iterations"], alg["blur_final"])
             support_area = spimage.sp_smap_alloc(2)
             spimage.sp_smap_insert(support_area, i,alg["area_init"])
             spimage.sp_smap_insert(support_area, i + alg["number_of_iterations"],alg["area_final"])
             alg["spimage_support_array"] = spimage.sp_support_array_init(spimage.sp_support_area_alloc(blur_radius, support_area),alg["update_period"])
         elif alg["type"] == "threshold":
             blur_radius = spimage.sp_smap_alloc(2)
             spimage.sp_smap_insert(blur_radius, i, alg["blur_init"])
             spimage.sp_smap_insert(blur_radius, i + alg["number_of_iterations"], alg["blur_final"])
             threshold = spimage.sp_smap_alloc(2)
             spimage.sp_smap_insert(threshold, i, alg["threshold_init"])
             spimage.sp_smap_insert(threshold, i + alg["number_of_iterations"], alg["threshold_final"])
             alg["spimage_support_array"] = spimage.sp_support_array_init(spimage.sp_support_threshold_alloc(blur_radius, threshold),alg["update_period"])
         elif alg["type"] == "static":
             alg["update_period"] = alg["number_of_iterations"]
             alg["spimage_support_array"] = spimage.sp_support_array_init(spimage.sp_support_static_alloc(),alg["update_period"])
         else:
             self._log("No valid support algorithm set. This error should be reported!","ERROR")
             return
         if alg["center_image"]:
             spimage.sp_support_array_append(alg["spimage_support_array"],spimage.sp_support_centre_image_alloc())
             self._log("Enabling center image in real space, it will be done with every support update.")
         else:
             self._log("Center real space image disabled.")
         i += alg["number_of_iterations"]
         self._support_algorithms.append(alg)
     self._support_algorithms_dirty = False
     self._log("Support algorithms initialised.","DEBUG")
 def _init_support_algorithms(self):
     if not self._support_algorithms_dirty:
         self._log("Support algorithms already initialised.","DEBUG")
         return       
     i = 0
     for alg_conf in self._support_algorithms_configs:
         alg = dict(alg_conf)
         if alg_conf["number_of_iterations"] is None:
             if len(self._support_algorithms_configs) == 1:
                 alg["number_of_iterations"] = self._number_of_iterations
             else:
                 self._log("Number of iterations can not be None if many support algorithms are specified. Please report this error.","ERROR")
                 return
         if alg["type"] == "area":
             self._blur_radius = spimage.sp_smap_alloc(2)
             spimage.sp_smap_insert(self._blur_radius, i, alg["blur_init"])
             spimage.sp_smap_insert(self._blur_radius, i + alg["number_of_iterations"], alg["blur_final"])
             self._support_area = spimage.sp_smap_alloc(2)
             spimage.sp_smap_insert(self._support_area, i,alg["area_init"])
             spimage.sp_smap_insert(self._support_area, i + alg["number_of_iterations"],alg["area_final"])
             alg["spimage_support_array"] = spimage.sp_support_array_init(spimage.sp_support_area_alloc(self._blur_radius, self._support_area),alg["update_period"])
         elif alg["type"] == "threshold":
             self._blur_radius = spimage.sp_smap_alloc(2)
             spimage.sp_smap_insert(self._blur_radius, i, alg["blur_init"])
             spimage.sp_smap_insert(self._blur_radius, i + alg["number_of_iterations"], alg["blur_final"])
             self._threshold = spimage.sp_smap_alloc(2)
             spimage.sp_smap_insert(self._threshold, i, alg["threshold_init"])
             spimage.sp_smap_insert(self._threshold, i + alg["number_of_iterations"], alg["threshold_final"])
             alg["spimage_support_array"] = spimage.sp_support_array_init(spimage.sp_support_threshold_alloc(self._blur_radius, self._threshold),alg["update_period"])
         elif alg["type"] == "static":
             alg["update_period"] = alg["number_of_iterations"]
             alg["spimage_support_array"] = spimage.sp_support_array_init(spimage.sp_support_static_alloc(),alg["update_period"])
         else:
             self._log("No valid support algorithm set. This error should be reported!","ERROR")
             return
         if alg["center_image"]:
             spimage.sp_support_array_append(alg["spimage_support_array"],spimage.sp_support_centre_image_alloc())
             self._log("Enabling center image in real space, it will be done with every support update.")
         else:
             self._log("Center real space image disabled.")
         i += alg["number_of_iterations"]
         self._support_algorithms.append(alg)
     self._support_algorithms_dirty = False
     self._log("Support algorithms initialised.","DEBUG")
Пример #3
0
def get_basic_phaser(amplitudes, support, mask=None):
    """This function is not finished"""
    if mask is None:
        amplitudes_sp = image_from_array(amplitudes)
    else:
        amplitudes_sp = image_from_array(amplitudes, mask)
    beta = _spimage.sp_smap_alloc(1)
    _spimage.sp_smap_insert(beta, 0, 0.9)
    phase_alg = _spimage.sp_phasing_hio_alloc(beta, _spimage.SpNoConstraints)
    support_sp = image_from_array(support)
    sup_alg = _spimage.sp_support_array_init(_spimage.sp_support_static_alloc(), 20)

    phaser = _spimage.sp_phaser_alloc()
    _spimage.sp_phaser_init(phaser, phase_alg, sup_alg, _spimage.SpEngineCUDA)
    _spimage.sp_phaser_set_amplitudes(phaser, amplitudes_sp)
    _spimage.sp_phaser_init_model(phaser, None, _spimage.SpModelRandomPhases)
    _spimage.sp_phaser_init_support(phaser, support_sp, 0, 0)

    return phaser
Пример #4
0
def get_basic_phaser(amplitudes, support, mask=None, algorithm=None):
    """This function is not finished"""
    if mask is None:
        amplitudes_sp = image_from_array(amplitudes)
    else:
        amplitudes_sp = image_from_array(amplitudes, mask)
    if algorithm is None:
        beta = _spimage.sp_smap_alloc(1)
        _spimage.sp_smap_insert(beta, 0, 0.9)
        phase_alg = _spimage.sp_phasing_hio_alloc(beta,
                                                  _spimage.SpNoConstraints)
    else:
        phase_alg = algorithm
    support_sp = image_from_array(support)
    sup_alg = _spimage.sp_support_array_init(
        _spimage.sp_support_static_alloc(), 20)

    phaser = _spimage.sp_phaser_alloc()
    _spimage.sp_phaser_init(phaser, phase_alg, sup_alg, _spimage.SpEngineCUDA)
    _spimage.sp_phaser_set_amplitudes(phaser, amplitudes_sp)
    _spimage.sp_phaser_init_model(phaser, None, _spimage.SpModelRandomPhases)
    _spimage.sp_phaser_init_support(phaser, support_sp, 0, 0)

    return phaser
Пример #5
0
def support_static():
    """Create a support update array with only a static support."""
    algorithm = _spimage.sp_support_array_init(_spimage.sp_support_static_alloc(), 20)
    return algorithm
Пример #6
0
    _numpy.random.seed()
    _spimage.sp_srand(_numpy.random.randint(1e6))
    intensities = _spimage.sp_image_read(options.pattern, 0)
    if intensities.shifted == 0:
        amplitudes = _spimage.sp_image_shift(intensities)
    else:
        amplitudes = _spimage.sp_image_duplicate(intensities, _spimage.SP_COPY_ALL)
    _spimage.sp_image_dephase(amplitudes)
    _spimage.sp_image_to_amplitudes(amplitudes)

    real_space = _spimage.sp_image_read(options.real_space, 0)
    support = _spimage.sp_image_read(options.support, 0)

    phase_alg = _spimage.sp_phasing_er_alloc(_spimage.SpNoConstraints)

    sup_alg = _spimage.sp_support_array_init(_spimage.sp_support_static_alloc(), 20)

    # create phaser
    phaser = _spimage.sp_phaser_alloc()
    _spimage.sp_phaser_init(phaser, phase_alg, sup_alg, _spimage.SpEngineCUDA)
    _spimage.sp_phaser_set_amplitudes(phaser, amplitudes)
    _spimage.sp_phaser_init_model(phaser, real_space, 0)
    _spimage.sp_phaser_init_support(phaser, support, 0, 0)

    #real_space_s = _spimage.sp_image_shift(real_space)
    fourier_space = _spimage.sp_image_ifftw3(real_space)

    ereal_start = _numpy.sqrt((abs(real_space.image[~_numpy.bool8(support.image)])**2).sum() / (abs(real_space.image)**2).sum())
    efourier_start = _numpy.sqrt(((abs(fourier_space.image[_numpy.bool8(amplitudes.mask)]) - abs(amplitudes.image[_numpy.bool8(amplitudes.mask)]))**2).sum() / ((abs(amplitudes.image[_numpy.bool8(amplitudes.mask)])**2).sum() + (abs(fourier_space.image[~_numpy.bool8(amplitudes.mask)])**2).sum()))

    _spimage.sp_phaser_iterate(phaser, options.number_of_iterations)
Пример #7
0
def support_static():
    """Create a support update array with only a static support."""
    algorithm = _spimage.sp_support_array_init(
        _spimage.sp_support_static_alloc(), 20)
    return algorithm
Пример #8
0
    intensities = _spimage.sp_image_read(args.pattern, 0)
    if intensities.shifted == 0:
        amplitudes = _spimage.sp_image_shift(intensities)
    else:
        amplitudes = _spimage.sp_image_duplicate(intensities,
                                                 _spimage.SP_COPY_ALL)
    _spimage.sp_image_dephase(amplitudes)
    _spimage.sp_image_to_amplitudes(amplitudes)

    real_space = _spimage.sp_image_read(args.real_space, 0)
    support = _spimage.sp_image_read(args.support, 0)

    phase_alg = _spimage.sp_phasing_er_alloc(_spimage.SpNoConstraints)

    sup_alg = _spimage.sp_support_array_init(
        _spimage.sp_support_static_alloc(), 20)

    # create phaser
    phaser = _spimage.sp_phaser_alloc()
    _spimage.sp_phaser_init(phaser, phase_alg, sup_alg, _spimage.SpEngineCUDA)
    _spimage.sp_phaser_set_amplitudes(phaser, amplitudes)
    _spimage.sp_phaser_init_model(phaser, real_space, 0)
    _spimage.sp_phaser_init_support(phaser, support, 0, 0)

    fourier_space = _spimage.sp_image_ifftw3(real_space)

    support = _numpy.bool8(support.image)
    ereal_start = _numpy.sqrt((abs(real_space.image[~support])**2).sum() /
                              (abs(real_space.image)**2).sum())

    mask = _numpy.bool8(amplitudes.mask)