int main() { sp_data *sp; sp_create(&sp); sp_srand(sp, 12345); sp->sr = SR; sp->len = sp->sr * LEN; uint32_t t, u; SPFLOAT in1 = 0, out1 = 0; SPFLOAT in2 = 0, out2 = 0; sp_phaser *unit[NUM]; for(u = 0; u < NUM; u++) { sp_phaser_create(&unit[u]); sp_phaser_init(sp, unit[u]); } for(t = 0; t < sp->len; t++) { for(u = 0; u < NUM; u++) sp_phaser_compute(sp, unit[u], &in1, &in2, &out1, &out2); } for(u = 0; u < NUM; u++) sp_phaser_destroy(&unit[u]); sp_destroy(&sp); return 0; }
int main() { UserData ud; sp_data *sp; sp_create(&sp); sp_phaser_create(&ud.phaser); sp_diskin_create(&ud.disk); sp_diskin_init(sp, ud.disk, "oneart.wav"); sp_phaser_init(sp, ud.phaser); sp->len = 44100 * 5; sp_process(sp, &ud, process); sp_phaser_destroy(&ud.phaser); sp_diskin_destroy(&ud.disk); sp_destroy(&sp); return 0; }
int main(int argc, char ** argv){ if(argc < 5){ printf("Usage: %s <object_with_modes> <masked_amplitudes> <threshold> <output> [use constraints]\n",argv[0]); exit(0); } Image * obj = sp_image_read(argv[1],0); Image * amp = sp_image_read(argv[2],0); real threshold = atof(argv[3]); Image * sup = sp_image_duplicate(obj,SP_COPY_ALL); real max = sp_image_max(obj,0,0,0,0); for(int i= 0;i<sp_image_size(sup);i++){ if(sp_cabs(sup->image->data[i]) > threshold*max){ sup->image->data[i] = sp_cinit(1,0); }else{ sup->image->data[i] = sp_cinit(0,0); } } sp_image_write(sup,"input_support.h5",0); real beta = 0.9; SpPhasingAlgorithm * alg; if(argv > 5){ alg = sp_phasing_er_alloc(SpPositiveRealObject); }else{ alg = sp_phasing_er_alloc(SpNoConstraints); } // SpPhasingAlgorithm * alg = sp_phasing_raar_alloc(beta,SpNoConstraints); SpSupportAlgorithm * sup_alg = NULL; SpPhaser * ph = sp_phaser_alloc(); sp_phaser_init(ph,alg,sup_alg,SpEngineAutomatic); sp_phaser_set_objective(ph,SpRecoverAmplitudes); sp_phaser_init_support(ph,sup,0,0); Image * phased_amplitudes = sp_image_fft(obj); for(int i = 0;i<sp_image_size(obj);i++){ phased_amplitudes->mask->data[i] = amp->mask->data[i]; if(!amp->mask->data[i]){ phased_amplitudes->image->data[i] = sp_cinit(0,0); } } sp_image_write(phased_amplitudes,"input_phased_amplitudes.h5",0); Image * zeroed_obj = sp_image_ifft(phased_amplitudes); sp_image_scale(zeroed_obj,1.0/sp_image_size(obj)); sp_phaser_set_phased_amplitudes(ph,phased_amplitudes); if(sp_phaser_init_model(ph,zeroed_obj,0)){ fprintf(stderr,"Error while initializing model!\n"); } sp_image_write(zeroed_obj,"zeroed_obj.h5",0); int iter = 500; if(sp_phaser_iterate(ph,iter)){ fprintf(stderr,"Error while iterating!\n"); } Image * out = sp_image_duplicate(sp_phaser_model(ph),SP_COPY_ALL); Image * output_amplitudes = sp_image_fft(out); for(int i = 0;i<sp_image_size(obj);i++){ if(amp->mask->data[i]){ output_amplitudes->image->data[i] = phased_amplitudes->image->data[i]; } } sp_image_write(output_amplitudes,"output_phased_amplitudes.h5",0); out = sp_image_ifft(output_amplitudes); sp_image_scale(out,1.0/sp_image_size(out)); sp_image_write(out,argv[4],0); }
void complete_reconstruction_clean(Image * amp, Image * initial_support,Options * opts){ SpPhasingAlgorithm * alg = NULL; Log log; init_log(&log); opts->flog = NULL; opts->cur_iteration = 0; SpPhasingConstraints phasing_constraints = SpNoConstraints; if(opts->enforce_real && opts->enforce_positivity){ phasing_constraints |= SpPositiveRealObject; }else if(opts->enforce_real){ phasing_constraints |= SpRealObject; }else if(opts->enforce_positivity){ phasing_constraints |= SpPositiveComplexObject; } if(opts->enforce_centrosymmetry){ phasing_constraints |= SpCentrosymmetricObject; } // if (opts->enforce_ramp) { // phasing_constraints |= SpRampObject; // } if(get_algorithm(opts,&log) == HIO){ alg = sp_phasing_hio_alloc(opts->beta_evolution,phasing_constraints); } if(get_algorithm(opts,&log) == RAAR){ alg = sp_phasing_raar_alloc(opts->beta_evolution,phasing_constraints); } if(get_algorithm(opts,&log) == DIFF_MAP){ alg = sp_phasing_diff_map_alloc(opts->beta_evolution,get_gamma1(opts),get_gamma2(opts),phasing_constraints); } SpSupportArray * sup_alg = NULL; if(opts->support_update_algorithm == FIXED){ sup_alg = sp_support_array_init(sp_support_threshold_alloc(opts->support_blur_evolution,opts->threshold_evolution), opts->iterations); } if(opts->support_update_algorithm == DECREASING_AREA){ sup_alg = sp_support_array_init(sp_support_area_alloc(opts->support_blur_evolution,opts->object_area_evolution), opts->iterations);; } if (opts->support_update_algorithm == TEMPLATE_AREA){ sup_alg = sp_support_array_init(sp_support_template_alloc(opts->init_support,opts->template_blur_radius, opts->template_area_evolution),opts->iterations); } if (opts->support_update_algorithm == STATIC){ sup_alg = sp_support_array_init(sp_support_static_alloc(),opts->iterations); } if(!alg || !sup_alg){ hawk_fatal("Algorithm is NULL!\nBlame the programmer!"); } if (opts->support_closure_radius > 0) { sp_support_array_append(sup_alg,sp_support_close_alloc(opts->support_closure_radius)); } // !CHANGE! if (opts->center_image){ sp_support_array_append(sup_alg,sp_support_centre_image_alloc()); } SpPhaser * ph = sp_phaser_alloc(); sp_phaser_init(ph,alg,sup_alg,opts->phasing_engine); sp_phaser_set_amplitudes(ph,amp); sp_phaser_init_model(ph,opts->image_guess,0); //sp_phaser_init_support(ph,initial_support,0,0); if (opts->init_support == NULL) { sp_phaser_init_support(ph,initial_support,SpSupportFromPatterson,opts->init_level); } else { sp_phaser_init_support(ph,initial_support,0,0); } output_initial_images(sp_phaser_model(ph),initial_support); while(opts->max_iterations == 0 || opts->cur_iteration < opts->max_iterations){ char buffer[1024]; int to_output = opts->output_period-(ph->iteration)%opts->output_period; int to_log = opts->log_output_period-(ph->iteration)%opts->log_output_period; int to_iterate = sp_min(to_output,to_log); // int timer = sp_timer_start(); sp_phaser_iterate(ph,to_iterate); // printf("hawk - %d iterations in %d ms\n",to_iterate,(int)sp_timer_stop(timer)); opts->cur_iteration = ph->iteration; if(to_iterate == to_log){ output_from_phaser(ph,opts,&log); } if(to_iterate == to_output){ sprintf(buffer,"real_space-%07d.h5",ph->iteration-1); //hawk_image_write(sp_phaser_model(ph),buffer,opts->output_precision); Image * rs = apply_output_projection(sp_phaser_model_with_support(ph), opts->output_projection, sp_phaser_amplitudes(ph)); hawk_image_write(rs,buffer,opts->output_precision); sprintf(buffer,"support-%07d.h5",ph->iteration-1); hawk_image_write(sp_phaser_support(ph),buffer,opts->output_precision); sprintf(buffer,"fourier_space-%07d.h5",ph->iteration-1); hawk_image_write(sp_phaser_fmodel_with_mask(ph),buffer,opts->output_precision); // appending in cxidb file format is currently only implemented for 2D images if (amp->num_dimensions == SP_2D) { // initialize flag to include iteration number with the last 32 bits long long flag = ph->iteration; flag = (flag << 32) | 8; // copy support to data Image for (unsigned i = 0; i < sp_image_size(sp_phaser_support(ph)); i++) { rs->mask->data[i] = (int) sp_real(sp_phaser_support(ph)->image->data[i]); } // append data to cxidb file hawk_image_write(rs, "reconstruction.cxi", flag); } sp_image_free(rs); } } }