Optimizing weighting functions for cryo-electron microscopy