# Path: pyem/star.py
# def parse_star(starfile, keep_index=False, augment=True, nrows=sys.maxsize):
#     tables = star_table_offsets(starfile)
#     dfs = {t: parse_star_table(starfile, offset=tables[t][0], nrows=min(tables[t][3], nrows), keep_index=keep_index)
#            for t in tables}
#     if Relion.OPTICDATA in dfs:
#         if Relion.PARTICLEDATA in dfs:
#             data_table = Relion.PARTICLEDATA
#         elif Relion.MICROGRAPHDATA in dfs:
#             data_table = Relion.MICROGRAPHDATA
#         elif Relion.IMAGEDATA in dfs:
#             data_table = Relion.IMAGEDATA
#         else:
#             data_table = None
#         if data_table is not None:
#             df = pd.merge(dfs[Relion.OPTICDATA], dfs[data_table], on=Relion.OPTICSGROUP)
#         else:
#             df = dfs[Relion.OPTICDATA]
#     else:
#         df = dfs[next(iter(dfs))]
#     df = check_defaults(df, inplace=True)
#     if augment:
#         augment_star_ucsf(df, inplace=True)
#     return df


import sys
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
    import argparse
from matplotlib.projections.polar import PolarTransform
from matplotlib.transforms import Affine2D
from mpl_toolkits.axisartist import angle_helper
from mpl_toolkits.axisartist import floating_axes
from pyem.star import parse_star
    aux_ax.patch = ax1.patch
    ax1.patch.zorder = 0.9
    return ax1, aux_ax


if __name__ == "__main__":

    parser = argparse.ArgumentParser()
    parser.add_argument("--alpha", help="Scatter plot alpha value",
                        type=float, default=0.75)
    parser.add_argument("--cmap", help="Colormap for matplotlib",
                        default="magma")
    parser.add_argument("--class", help="Breakdown angular distribution by class",
                        type=int, dest="cls")
    parser.add_argument("--dpi", help="DPI of output",
                        type=int, default=300)
    parser.add_argument("--figsize", help="Figure size for matplotlib",
                        type=int, default=10)
    parser.add_argument("--format", help="Output image format",
                        default="png", choices=["png", "pdf", "ps", "eps", "svg"])
    parser.add_argument("--psi", help="Plot tilt and psi instead of tilt and rot",
                        action="store_true")
    parser.add_argument("--rmax", help="Upper limit of radial axis (probably ~45 or 180)",
                        type=int)
    parser.add_argument("--samples", help="Number of angular samples in [0, pi] (e.g. 36 for 5 deg. steps)",
                        type=int, default=36)
    parser.add_argument("--scale", help="Size of largest scatter point",
                        type=float, default=20)
    parser.add_argument("--subplot", help="Draw multiple plots as subplots of a single figure")
    parser.add_argument("--title", help="Custom figure title")

# Path: pyem/star.py
# def parse_star(starfile, keep_index=False, augment=True, nrows=sys.maxsize):
#     tables = star_table_offsets(starfile)
#     dfs = {t: parse_star_table(starfile, offset=tables[t][0], nrows=min(tables[t][3], nrows), keep_index=keep_index)
#            for t in tables}
#     if Relion.OPTICDATA in dfs:
#         if Relion.PARTICLEDATA in dfs:
#             data_table = Relion.PARTICLEDATA
#         elif Relion.MICROGRAPHDATA in dfs:
#             data_table = Relion.MICROGRAPHDATA
#         elif Relion.IMAGEDATA in dfs:
#             data_table = Relion.IMAGEDATA
#         else:
#             data_table = None
#         if data_table is not None:
#             df = pd.merge(dfs[Relion.OPTICDATA], dfs[data_table], on=Relion.OPTICSGROUP)
#         else:
#             df = dfs[Relion.OPTICDATA]
#     else:
#         df = dfs[next(iter(dfs))]
#     df = check_defaults(df, inplace=True)
#     if augment:
#         augment_star_ucsf(df, inplace=True)
#     return df


# Path: angdist.py
import sys
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
    import argparse
from matplotlib.projections.polar import PolarTransform
from matplotlib.transforms import Affine2D
from mpl_toolkits.axisartist import angle_helper
from mpl_toolkits.axisartist import floating_axes
from pyem.star import parse_star

    aux_ax.patch = ax1.patch
    ax1.patch.zorder = 0.9
    return ax1, aux_ax


if __name__ == "__main__":

    parser = argparse.ArgumentParser()
    parser.add_argument("--alpha", help="Scatter plot alpha value",
                        type=float, default=0.75)
    parser.add_argument("--cmap", help="Colormap for matplotlib",
                        default="magma")
    parser.add_argument("--class", help="Breakdown angular distribution by class",
                        type=int, dest="cls")
    parser.add_argument("--dpi", help="DPI of output",
                        type=int, default=300)
    parser.add_argument("--figsize", help="Figure size for matplotlib",
                        type=int, default=10)
    parser.add_argument("--format", help="Output image format",
                        default="png", choices=["png", "pdf", "ps", "eps", "svg"])
    parser.add_argument("--psi", help="Plot tilt and psi instead of tilt and rot",
                        action="store_true")
    parser.add_argument("--rmax", help="Upper limit of radial axis (probably ~45 or 180)",
                        type=int)
    parser.add_argument("--samples", help="Number of angular samples in [0, pi] (e.g. 36 for 5 deg. steps)",
                        type=int, default=36)
    parser.add_argument("--scale", help="Size of largest scatter point",
                        type=float, default=20)
    parser.add_argument("--subplot", help="Draw multiple plots as subplots of a single figure")
    parser.add_argument("--title", help="Custom figure title")

    parser.add_argument("--transparent", help="Use transparent background in output figure",