Example #1
0
def cml_refine_agls(Prj, Ori, delta):
    from copy import deepcopy
    from utilities import amoeba
    global g_n_prj

    scales = [delta] * (g_n_prj + 2)

    for iprj in xrange(g_n_prj):
        # init vec_in
        vec_in = [Ori[4 * iprj], Ori[4 * iprj + 1], Ori[4 * iprj + 2]]
        # prepare vec_data
        vec_data = [Prj, deepcopy(Ori), iprj]
        # simplex
        optvec, disc, niter = amoeba(vec_in,
                                     scales,
                                     cml_refine_agls_wrap_dev,
                                     data=vec_data)
        # assign new angles refine
        Ori[4 * iprj] = (optvec[0] + 360) % 360
        Ori[4 * iprj + 1] = optvec[1]
        Ori[4 * iprj + 2] = optvec[2]
        print 'refine:', iprj, 'angles:', Ori[4 * iprj:4 * iprj +
                                              4], 'disc:', -disc

    return Ori
Example #2
0
def fit_tanh(dres, low = 0.1):
	"""
		dres - list produced by the fsc funcion
		dres[0] - absolute frequencies
		dres[1] - fsc, because it was calculated from the dataset split into halves, convert it to full using rn = 2r/(1+r)
		dres[2] - number of points use to calculate fsc coeff
		low cutoff of the fsc curve
		return parameters of the tanh filter: freq - cutoff frequency at which filter value is 0.5, and fall_off, the 'width' of the filter
	"""
	def fit_tanh_func(args, data):
		from math import pi, tanh
		v = 0.0

		if(data[1][0] < 0.0 ):
			data[1][0] *= -1.0

		for i in xrange(len(data[0])):
			fsc =  2*data[1][i]/(1.0+data[1][i])
			if args[0]==0 or args[1]==0: qt=0
			else: qt  = fsc - 0.5*( tanh(pi*(data[0][i]+args[0])/2.0/args[1]/args[0]) - tanh(pi*(data[0][i]-args[0])/2.0/args[1]/args[0]) )
			v  -= qt*qt
		#print args,v
		return v

	setzero = False
	for i in xrange(1,len(dres[0])):
		if not setzero:
			if(2*dres[1][i]/(1.0+dres[1][i]) <low):  setzero = True
		if setzero:  dres[1][i] = 0.0

	freq = -1.0
	for i in xrange(1,len(dres[0])-1):
		if ( (2*dres[1][i]/(1.0+dres[1][i]) ) < 0.5):
			freq = dres[0][i-1]
			break
	if freq < 0.0:
		# the curve never falls below 0.5, most likely something's wrong; however, return reasonable values
		freq = 0.4
		fall_off = 0.2
		return freq, fall_off

	from utilities import amoeba
	args   = [freq, 0.1]
	scale  = [0.05, 0.05]
	result = amoeba(args, scale, fit_tanh_func, data = dres)

	'''
	args[0] = result[0][0]
	args[1] = result[0][1]
	#print  args
	from math import pi, tanh
	for i in xrange(len(dres[0])):
		fsc = 2*dres[1][i]/(1.0+dres[1][i])
		print i, dres[0][i],fsc , 0.5*( tanh(pi*(dres[0][i]+args[0])/2.0/args[1]/args[0]) - tanh(pi*(dres[0][i]-args[0])/2.0/args[1]/args[0]) )
		#qt  = fsc - 0.5*( tanh(pi*(dres[0][i]+args[0])/2.0/args[1]/args[0]) - tanh(pi*(dres[0][i]-args[0])/2.0/args[1]/args[0]) )
	'''
	return result[0][0], result[0][1]
Example #3
0
def cml_refine_agls(Prj, Ori, delta):
	from copy      import deepcopy
	from utilities import amoeba
	global g_n_prj
	
	scales = [delta] * (g_n_prj + 2)

	for iprj in xrange(g_n_prj):
		# init vec_in
		vec_in   = [Ori[4*iprj], Ori[4*iprj+1], Ori[4*iprj+2]]
		# prepare vec_data
		vec_data = [Prj, deepcopy(Ori), iprj]
		# simplex
		optvec, disc, niter = amoeba(vec_in, scales, cml_refine_agls_wrap_dev, data = vec_data)
		# assign new angles refine
		Ori[4*iprj]   = (optvec[0]+360)%360
		Ori[4*iprj+1] = optvec[1]
		Ori[4*iprj+2] = optvec[2]
		print 'refine:', iprj, 'angles:', Ori[4*iprj:4*iprj+4], 'disc:', -disc

	return Ori