-
Notifications
You must be signed in to change notification settings - Fork 25
Description
Documenting some cleanup tasks to follow the Common-lines reorg work. Adding the associated code review comments below for reference (see #1341 for more info):
I have 3 suggestions about the same sort of code. Its not new code, just migrated. Maybe it can be improved (maybe not). Make a followup issue to review those in the future after the reorg stuff. Low priority, just something I might have missed before. Thanks
In src/aspire/abinitio/commonline_utils.py:
>
- Rj_tilde = Ri_tildes[j]
+ # Generate shifted versions of images.
+ pf_i_shifted = np.array([pf_i * shift_phase for shift_phase in shift_phases])
can we just multiply these arrays....
In src/aspire/abinitio/commonline_utils.py:
>
- # Perform correlation, corrs is shape n_shifts x len(theta_ijs).
- corrs = np.array(
- [
- np.dot(pf_i_shift[c1], np.conj(pf_j[c2]))
- for pf_i_shift in pf_i_shifted
- for c1, c2 in zip(c1s, c2s)
- ]
- )
+ # Compute all possible rotations between the i'th and j'th images.
+ Us = np.array(
Similarly here, seems like a broadcast would work? This might be a rare case where einsum could be useful.
In src/aspire/abinitio/commonline_utils.py:
>
- # Reshape to group by shift and symmetric order.
- corrs = corrs.reshape((n_shifts, order, len(theta_ijs) // order))
+ # Find the angle between common lines induced by the rotations.
+ c1s = np.array([[-U[1, 2], U[0, 2]] for U in Us])
+ c2s = np.array([[U[2, 1], -U[2, 0]] for U in Us])
+
+ # Convert from angles to indices.
+ c1s = _cl_angles_to_ind(c1s, n_theta)
+ c2s = _cl_angles_to_ind(c2s, n_theta)
+
+ # Perform correlation, corrs is shape n_shifts x len(theta_ijs).
+ corrs = np.array(
This would probably be clearer without the nested list comprehension. And you might not need to reshape it ....