Пример #1
0
def iterate_data(dataset,weights,pixel_step=25,iter_no=5,pixel_mask=None):
    start_gain = array.ones(len(dataset))
    gain,first_ave,ar,esds,K = overlap.find_gain_fr(dataset,weights,pixel_step,start_gain,pixel_mask=pixel_mask)
    chisquared,residual_map = overlap.get_statistics_fr(gain,first_ave,dataset,dataset.var,pixel_step,pixel_mask)
    Plot1.set_dataset(Dataset(first_ave))
    Plot2.set_dataset(zeros_like(first_ave))
    old_result = first_ave    #store for later
    chisq_history = [chisquared]
    if iter_no > 0:
        no_iters = iter_no
    else:
        no_iters = abs(iter_no)
    for cycle_no in range(no_iters+1):
        esdflag = cycle_no == iter_no
        if cycle_no > 3 and iter_no < 0:
            esdflag = (esdflag or (abs(chisq_history[-2]-chisq_history[-1]))<0.005)
        gain,interim_result,ar,esds,K = overlap.find_gain_fr(dataset,weights,pixel_step,gain,arminus1=ar,pixel_mask=pixel_mask,errors=esdflag)
        chisquared,residual_map = overlap.get_statistics_fr(gain,interim_result,dataset,dataset.var,pixel_step,pixel_mask)
        chisq_history.append(chisquared)
        if not cycle_no % ((iter_no/2)+1):             # +1 to avoid division by zero for single step iterations
            print "Plotting cycle %d" % cycle_no
            Plot1.add_dataset(Dataset(interim_result))#,label="%d" % cycle_no)
            Plot2.add_dataset(Dataset(interim_result-first_ave))#,label="%d" % cycle_no)
            old_result = interim_result
            Plot3.set_dataset(Dataset(chisq_history))#,label="%d" % cycle_no)
    print 'Maximum shift/error: %f' % max(ar/esds)
    return gain,dataset,interim_result,residual_map,chisquared,esds,first_ave
Пример #2
0
def iterate_data(dataset,pixel_step=25,iter_no=5,pixel_mask=None,plot_clear=True,algo="FordRollett"):
    """Iteratively refine the gain. The pixel_step is the number of steps a tube takes before it
    overlaps with the next tube. iter_no is the number of iterations. Pixel_mask has a zero for any
    tube that should be excluded. Algo 'ford rollett' applies the algorithm of Ford and Rollet, 
    Acta Cryst. (1968) B24, p293"""
    import overlap
    start_gain = array.ones(len(dataset))
    if algo == "FordRollett":
        gain,first_ave,chisquared,residual_map,ar,esds = overlap.find_gain_fr(dataset,dataset,pixel_step,start_gain,pixel_mask=pixel_mask)
    else:
        gain,first_ave,chisquared,residual_map,esds = overlap.find_gain(dataset,dataset,pixel_step,start_gain,pixel_mask=pixel_mask)
    old_result = first_ave    #store for later
    chisq_history = [chisquared]
    for cycle_no in range(iter_no+1):
        esdflag = (cycle_no == iter_no)  # need esds as well
        if algo == "FordRollett":
            gain,interim_result,chisquared,residual_map,ar,esds = overlap.find_gain_fr(dataset,dataset,pixel_step,gain,arminus1=ar,pixel_mask=pixel_mask,errors=esdflag)
        else:
            gain,interim_result,chisquared,residual_map,ar,esds = overlap.find_gain(dataset,dataset,pixel_step,gain,pixel_mask=pixel_mask,errors=esdflag)
        chisq_history.append(chisquared)
        # Calculate the errors using the full, not truncated, dataset
    print 'Chisquared: ' + `chisq_history`
    return gain,dataset,interim_result,residual_map,chisquared,esds,first_ave