Ejemplo n.º 1
0
 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")
 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")
Ejemplo n.º 3
0
def smap(values):
    """Create spimage smap object from iterable of (iteration, value) pairs."""
    import collections
    if not isinstance(values, collections.Iterable):
        values = [(0, values)]

    smap_out = _spimage.sp_smap_alloc(len(values))
    for i in values:
        _spimage.sp_smap_insert(smap_out, i[0], i[1])

    return smap_out
Ejemplo n.º 4
0
def smap(values):
    """Create spimage smap object from iterable of (iteration, value)
    pairs."""
    import collections
    if not isinstance(values, collections.Iterable):
        values = [(0, values)]

    smap_out = _spimage.sp_smap_alloc(len(values))
    for i in values:
        _spimage.sp_smap_insert(smap_out, i[0], i[1])

    return smap_out
 def _init_phasing_algorithms(self):
     if not self._phasing_algorithms_dirty:
         self._log("Phasing algorithms already initialised.","DEBUG")
         return       
     i = 0
     for alg_conf in self._phasing_algorithms_configs:
         alg = dict(alg_conf)
         if alg_conf["number_of_iterations"] is None:
             if len(self._phasing_algorithms_configs) == 1:
                 alg["number_of_iterations"] = self._number_of_iterations
             else:
                 self._log("Number of iterations can not be None if many phasing algorithms are specified. Please report this error.","ERROR")
                 return
         # constraints
         constraints = spimage.SpNoConstraints
         if "constraints" in alg:
             if "enforce_positivity" in alg["constraints"] and "enforce_real" in alg["constraints"]:
                 constraints |= spimage.SpPositiveRealObject
             elif "enforce_real" in alg["constraints"]:
                 constraints |= spimage.SpRealObject
             elif "enforce_positivity" in alg["constraints"]:
                 constraints |= spimage.SpPositiveComplexObject
             if "enforce_centrosymmetry" in alg["constraints"]:
                 constraints |= spimage.SpCentrosymmetricObject
         # phasing algorithm
         if alg["type"] in ["raar","hio","diffmap"]:
             alg["beta"] = spimage.sp_smap_alloc(1)
             spimage.sp_smap_insert(alg["beta"], i,alg["beta_init"])
             spimage.sp_smap_insert(alg["beta"], i+alg["number_of_iterations"], alg["beta_final"])
         if alg["type"] == "raar":
             alg["spimage_phasing"] = spimage.sp_phasing_raar_alloc(alg["beta"], constraints)
         elif alg["type"] == "hio":
             alg["spimage_phasing"] = spimage.sp_phasing_hio_alloc(alg["beta"], constraints)
         elif alg["type"] == "diffmap":
             alg["spimage_phasing"] = spimage.sp_phasing_diffmap_alloc(alg["beta"], alg["gamma1"], alg["gamma2"], constraints)
         elif alg["type"] == "er":
             alg["spimage_phasing"] = spimage.sp_phasing_er_alloc(constraints)
         else:
             self._log("Phasing algorithm %s not implemented. Please report this error!" % type,"ERROR")
             return
         i += alg["number_of_iterations"]
         self._phasing_algorithms.append(alg)
     self._phasing_algorithms_dirty = False
     self._log("Phasing algorithm initialised.","DEBUG")
Ejemplo n.º 6
0
 def _init_phasing_algorithms(self):
     if not self._phasing_algorithms_dirty:
         self._log("Phasing algorithms already initialised.","DEBUG")
         return       
     i = 0
     for alg_conf in self._phasing_algorithms_configs:
         alg = dict(alg_conf)
         if alg_conf["number_of_iterations"] is None:
             if len(self._phasing_algorithms_configs) == 1:
                 alg["number_of_iterations"] = self._number_of_iterations
             else:
                 self._log("Number of iterations can not be None if many phasing algorithms are specified. Please report this error.","ERROR")
                 return
         # constraints
         constraints = spimage.SpNoConstraints
         if "constraints" in alg:
             if "enforce_positivity" in alg["constraints"] and "enforce_real" in alg["constraints"]:
                 constraints |= spimage.SpPositiveRealObject
             elif "enforce_real" in alg["constraints"]:
                 constraints |= spimage.SpRealObject
             elif "enforce_positivity" in alg["constraints"]:
                 constraints |= spimage.SpPositiveComplexObject
             if "enforce_centrosymmetry" in alg["constraints"]:
                 constraints |= spimage.SpCentrosymmetricObject
         # phasing algorithm
         if alg["type"] in ["raar","hio","diffmap"]:
             alg["beta"] = spimage.sp_smap_alloc(1)
             spimage.sp_smap_insert(alg["beta"], i,alg["beta_init"])
             spimage.sp_smap_insert(alg["beta"], i+alg["number_of_iterations"], alg["beta_final"])
         if alg["type"] == "raar":
             alg["spimage_phasing"] = spimage.sp_phasing_raar_alloc(alg["beta"], constraints)
         elif alg["type"] == "hio":
             alg["spimage_phasing"] = spimage.sp_phasing_hio_alloc(alg["beta"], constraints)
         elif alg["type"] == "diffmap":
             alg["spimage_phasing"] = spimage.sp_phasing_diff_map_alloc(alg["beta"], alg["gamma1"], alg["gamma2"], constraints)
         elif alg["type"] == "er":
             alg["spimage_phasing"] = spimage.sp_phasing_er_alloc(constraints)
         else:
             self._log("Phasing algorithm %s not implemented. Please report this error!" % type,"ERROR")
             return
         i += alg["number_of_iterations"]
         self._phasing_algorithms.append(alg)
     self._phasing_algorithms_dirty = False
     self._log("Phasing algorithm initialised.","DEBUG")
Ejemplo n.º 7
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
Ejemplo n.º 8
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