# Path: star.py
# def main(args):


import glob
import logging
import sys
import numpy as np
    import argparse
from star import parse_star, write_star
from EMAN2 import EMData, Vec3f, Transform
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


def main(args):
    star = parse_star(args.input, keep_index=False)

    if args.class_2d is not None:
        refs = glob.glob(args.class_2d)
    elif args.class_3d is not None:
        refs = glob.glob(args.class_3d)
    else:
        refs = []
    
    shifts = []
    for r in refs:
        if args.class_3d is not None:
            refmap = EMData(r)
            com = Vec3f(*refmap.phase_cog()[:3])
            shifts.append(com)
        else:
            stack = EMData.read_images(r)
            for im in stack:
                com = Vec2f(*im.phase_cog()[:2])
                shifts.append(com)

    if args.class_2d is None and args.class_3d is None:
        for ptcl in star.rows:
            im = EMData.read_image(ptcl)
            com = im.phase_cog()

# Path: star.py
# def main(args):


# Path: recenter.py
import glob
import logging
import sys
import numpy as np
    import argparse
from star import parse_star, write_star
from EMAN2 import EMData, Vec3f, Transform

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


def main(args):
    star = parse_star(args.input, keep_index=False)

    if args.class_2d is not None:
        refs = glob.glob(args.class_2d)
    elif args.class_3d is not None:
        refs = glob.glob(args.class_3d)
    else:
        refs = []
    
    shifts = []
    for r in refs:
        if args.class_3d is not None:
            refmap = EMData(r)
            com = Vec3f(*refmap.phase_cog()[:3])
            shifts.append(com)
        else:
            stack = EMData.read_images(r)
            for im in stack:
                com = Vec2f(*im.phase_cog()[:2])
                shifts.append(com)

    if args.class_2d is None and args.class_3d is None:
        for ptcl in star.rows:
            im = EMData.read_image(ptcl)
            com = im.phase_cog()

            ptcl["rlnOriginX"] += com[0]