def _init_phaser(self): #if not self._phaser_dirty: # self._log("Phaser already initialised.","DEBUG") # return self._clear_phaser() self._phaser = spimage.sp_phaser_alloc() pe = spimage.SpEngineCUDA self._log("Initialising phaser with the phasing algorithm %s and the support algorithm %s." % (self._phasing_algorithms[0]["type"],self._support_algorithms[0]["type"])) spimage.sp_phaser_init(self._phaser, self._phasing_algorithms[0]["spimage_phasing"], self._support_algorithms[0]["spimage_support_array"], pe) spimage.sp_phaser_set_amplitudes(self._phaser, self._sp_amplitudes) spimage.sp_phaser_init_model(self._phaser, None, spimage.SpModelRandomPhases) spimage.sp_phaser_init_support(self._phaser, self._sp_initial_support, 0, 0) self._phaser_dirty = False self._log("Phaser initialized.","DEBUG")
def _init_phaser(self): #if not self._phaser_dirty: # self._log("Phaser already initialised.","DEBUG") # return self._clear_phaser() self._sp_phaser = spimage.sp_phaser_alloc() if self._use_gpu: pe = spimage.SpEngineCUDA else: pe = spimage.SpEngineCPU self._log("Initialising phaser with the phasing algorithm %s and the support algorithm %s." % (self._phasing_algorithms[0]["type"],self._support_algorithms[0]["type"])) spimage.sp_phaser_init(self._sp_phaser, self._phasing_algorithms[0]["spimage_phasing"], self._support_algorithms[0]["spimage_support_array"], pe) spimage.sp_phaser_set_amplitudes(self._sp_phaser, self._sp_amplitudes) spimage.sp_phaser_init_model(self._sp_phaser, None, spimage.SpModelRandomPhases) spimage.sp_phaser_init_support(self._sp_phaser, self._sp_initial_support, 0, 0) self._phaser_dirty = False self._log("Phaser initialized.","DEBUG")
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
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
# constraints = spimage.SpNoConstraints # constraints = spimage.SpPositiveComplexObject # Additional constraints, other than Fourier-constraint or Real-constraint. constraints = spimage.SpPositiveRealObject phase_alg_main = spimage.sp_phasing_hio_alloc(beta, constraints) phase_alg_refine = spimage.sp_phasing_er_alloc(constraints) # create phaser phaser = spimage.sp_phaser_alloc() spimage.sp_phaser_init(phaser, phase_alg_main, sup_alg_static, spimage.SpEngineCUDA) spimage.sp_phaser_set_amplitudes(phaser, amplitudes) spimage.sp_phaser_init_model(phaser, None, spimage.SpModelRandomPhases) spimage.sp_phaser_init_support(phaser, support, 0, 0) def run_it(number_of_iterations): spimage.sp_phaser_iterate(phaser, number_of_iterations) run_it(NUMBER_OF_ITERATIONS) phaser.algorithm = phase_alg_refine run_it(NUMBER_OF_REFINE_ITERATIONS) # Output data model = spimage.sp_phaser_model(phaser) support = spimage.sp_phaser_support(phaser) fmodel = spimage.sp_phaser_fmodel(phaser) spimage.sp_image_write(model, OUTPUT_DIR + "run_{}_model.h5".format(run_id), 0)
_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) model_out = _spimage.sp_phaser_model(phaser) support_out = _spimage.sp_phaser_support(phaser) fmodel_out = _spimage.sp_phaser_fmodel(phaser) real_space_end = _spimage.sp_phaser_model_before_projection(phaser) fourier_space_end = _spimage.sp_phaser_fmodel(phaser)