def max_3D_pixel_error(t1, t2, r=1.0): """ Compute maximum pixel error between two sets of orientation parameters assuming object has radius r, t1 is the projection transformation of the first projection and t2 of the second one, respectively: t = Transform({"type":"spider","phi":phi,"theta":theta,"psi":psi}) t.set_trans(Vec2f(-tx, -ty)) Note the function is symmetric in t1, t2. """ pass #IMPORTIMPORTIMPORT from EMAN2 import Vec2f pass #IMPORTIMPORTIMPORT import types dummy = EMAN2_cppwrap.Transform() if (type(dummy) != type(t1)): t = EMAN2_cppwrap.Transform({ "type": "spider", "phi": t1[0], "theta": t1[1], "psi": t1[2] }) t.set_trans(EMAN2_cppwrap.Vec2f(-t1[3], -t1[4])) else: t = t1 if (type(dummy) != type(t2)): u = EMAN2_cppwrap.Transform({ "type": "spider", "phi": t2[0], "theta": t2[1], "psi": t2[2] }) u.set_trans(EMAN2_cppwrap.Vec2f(-t2[3], -t2[4])) else: u = t2 return EMAN2_cppwrap.EMData().max_3D_pixel_error(t, u, r)
def shc( data, refrings, list_of_reference_angles, numr, xrng, yrng, step, an=-1.0, sym="c1", finfo=None, ): number_of_checked_refs = 0 mode = "F" nx = data.get_xsize() ny = data.get_ysize() # center is in SPIDER convention cnx = old_div(nx, 2) + 1 cny = old_div(ny, 2) + 1 if an >= 0.0: ant = numpy.cos(numpy.radians(an)) else: ant = -1.0 # phi, theta, psi, sxo, syo = get_params_proj(data) t1 = data.get_attr("xform.projection") dp = t1.get_params("spider") ou = numr[-3] sxi = round(-dp["tx"], 2) syi = round(-dp["ty"], 2) txrng = search_range(nx, ou, sxi, xrng) tyrng = search_range(ny, ou, syi, yrng) if finfo: finfo.write( "Old parameters: %9.4f %9.4f %9.4f %9.4f %9.4f\n" % (dp["phi"], dp["theta"], dp["psi"], -dp["tx"], -dp["ty"]) ) finfo.flush() z1, z2, z3, z4, z5 = sp_utilities.get_params_proj(data, "xform.anchor") finfo.write( "Anc parameters: %9.4f %9.4f %9.4f %9.4f %9.4f\n" % (z1, z2, z3, -z4, -z5) ) finfo.flush() previousmax = data.get_attr("previousmax") [ang, sxs, sys, mirror, iref, peak, checked_refs] = EMAN2_cppwrap.Util.shc( data, refrings, list_of_reference_angles, txrng, tyrng, step, ant, mode, numr, cnx - sxi, cny - syi, sym, ) iref = int(iref) number_of_checked_refs += int(checked_refs) if peak <= previousmax: return -1.0e23, 0.0, number_of_checked_refs, -1 """Multiline Comment50""" else: # The ormqip returns parameters such that the transformation is applied first, the mirror operation second. # What that means is that one has to change the the Eulerian angles so they point into mirrored direction: phi+180, 180-theta, 180-psi if mirror: phi = (refrings[iref].get_attr("phi") + 540.0) % 360.0 theta = 180.0 - refrings[iref].get_attr("theta") psi = (540.0 - refrings[iref].get_attr("psi") - ang) % 360.0 else: phi = refrings[iref].get_attr("phi") theta = refrings[iref].get_attr("theta") psi = (360.0 + refrings[iref].get_attr("psi") - ang) % 360.0 s2x = sxs + sxi s2y = sys + syi # set_params_proj(data, [phi, theta, psi, s2x, s2y]) t2 = EMAN2_cppwrap.Transform( {"type": "spider", "phi": phi, "theta": theta, "psi": psi} ) t2.set_trans(EMAN2_cppwrap.Vec2f(-s2x, -s2y)) data.set_attr("xform.projection", t2) data.set_attr("previousmax", peak) # Find the pixel error that is minimum over symmetry transformations if sym == "nomirror" or sym == "c1": pixel_error = sp_pixel_error.max_3D_pixel_error(t1, t2, numr[-3]) else: ts = t2.get_sym_proj(sym) # only do it if it is not c1 pixel_error = +1.0e23 for ut in ts: # we do not care which position minimizes the error pixel_error = min( sp_pixel_error.max_3D_pixel_error(t1, ut, numr[-3]), pixel_error ) if finfo: finfo.write( "New parameters: %9.4f %9.4f %9.4f %9.4f %9.4f %10.5f %11.3e\n\n" % (phi, theta, psi, s2x, s2y, peak, pixel_error) ) finfo.flush() return peak, pixel_error, number_of_checked_refs, iref