# Path: py/fiberassign/vis.py
# def plot_qa(data, outroot, outformat="pdf", labels=False):
#     """Make plots of QA data.
#     """
#     set_matplotlib_pdf_backend()
#     # Imported here, to ensure that the backend has been set.
#     from matplotlib.patches import Patch
# 
#     hw = load_hardware()
#     tile_radius = hw.focalplane_radius_deg
# 
#     fontpt = 1
#     linewidth = 0.1
# 
#     fig = plt.figure(figsize=(12, 10))
# 
#     plot_param = [
#         ("Total Fibers Assigned Per Tile", ["assign_total"], 5000, 5),
#         ("Standards Assigned Per Tile", ["assign_std"], 100, 2),
#         ("Sky Assigned Per Tile", ["assign_sky", "assign_suppsky"], 400, 2),
#     ]
# 
#     pindx = 1
#     for title, key, desired, incr in plot_param:
#         ax = fig.add_subplot(3, 1, pindx)
#         ax.set_aspect("equal")
#         xmin = 360.0
#         xmax = 0.0
#         ymin = 90.0
#         ymax = -90.0
#         for tid, props in data.items():
#             xcent = props["tile_ra"]
#             ycent = props["tile_dec"]
#             if xcent > xmax:
#                 xmax = xcent
#             if xcent < xmin:
#                 xmin = xcent
#             if ycent > ymax:
#                 ymax = ycent
#             if ycent < ymin:
#                 ymin = ycent
#             keytot = np.sum([props[x] for x in key])
#             color = plot_qa_tile_color(desired, keytot, incr)
#             circ = plt.Circle((xcent, ycent), radius=tile_radius, fc="none",
#                               ec=color, linewidth=linewidth)
#             ax.add_artist(circ)
#             if labels:
#                 ax.text(xcent, ycent, "{}".format(tid),
#                         color=color, fontsize=fontpt,
#                         horizontalalignment='center',
#                         verticalalignment='center',
#                         bbox=None)
# 
#         margin = 1.1 * tile_radius
# 
#         xmin -= margin
#         xmax += margin
#         ymin -= margin
#         ymax += margin
#         if xmin < 0.0:
#             xmin = 0.0
#         if xmax > 360.0:
#             xmax = 360.0
#         if ymin < -90.0:
#             ymin = -90.0
#         if ymax > 90.0:
#             ymax = 90.0
# 
#         ax.set_xlim(left=xmin, right=xmax)
#         ax.set_ylim(bottom=ymin, top=ymax)
#         ax.set_xlabel("RA (degrees)", fontsize="large")
#         ax.set_ylabel("DEC (degrees)", fontsize="large")
#         ax.set_title(title)
# 
#         c_high = plot_qa_tile_color(desired, desired+1, incr)
#         c_exact = plot_qa_tile_color(desired, desired, incr)
#         c_low_one = plot_qa_tile_color(desired, desired-incr, incr)
#         c_low_two = plot_qa_tile_color(desired, desired-2*incr, incr)
#         c_low = plot_qa_tile_color(desired, 0, incr)
# 
#         c_low_two_val = desired - incr
#         c_low_val = desired - 2 * incr
# 
#         legend_elements = [
#             Patch(facecolor=c_high, edgecolor="none",
#                   label="> {} assigned".format(desired)),
#             Patch(facecolor=c_exact, edgecolor="none",
#                   label="Exactly {} assigned".format(desired)),
#             Patch(facecolor=c_low_one, edgecolor="none",
#                   label="< {} assigned".format(desired)),
#             Patch(facecolor=c_low_two, edgecolor="none",
#                   label="< {} assigned".format(c_low_two_val)),
#             Patch(facecolor=c_low, edgecolor="none",
#                   label="< {} assigned".format(c_low_val)),
#         ]
#         ax.legend(handles=legend_elements, loc="best",
#                   fontsize="x-small")
#         pindx += 1
# 
#     outfile = "{}.{}".format(outroot, outformat)
#     plt.savefig(outfile, dpi=300, format="pdf")
# 
#     return


import os
import argparse
import json
from ..vis import plot_qa
        args = parser.parse_args()
    else:
        args = parser.parse_args(optlist)

    # Check directory
    if not os.path.isfile(args.qafile):
        raise RuntimeError("Input file {} does not exist".format(args.qafile))

    if args.outroot is None:
        args.outroot = os.path.splitext(args.qafile)[0]

    return args


def run_plot_qa(args):
    """Run QA plotting.

    This uses the previously parsed options to read input data and make a
    plot of the QA results.

    Args:
        args (namespace): The parsed arguments.

    Returns:
        None

    """
    qadata = None
    with open(args.qafile, "r") as f:
        qadata = json.load(f)

# Path: py/fiberassign/vis.py
# def plot_qa(data, outroot, outformat="pdf", labels=False):
#     """Make plots of QA data.
#     """
#     set_matplotlib_pdf_backend()
#     # Imported here, to ensure that the backend has been set.
#     from matplotlib.patches import Patch
# 
#     hw = load_hardware()
#     tile_radius = hw.focalplane_radius_deg
# 
#     fontpt = 1
#     linewidth = 0.1
# 
#     fig = plt.figure(figsize=(12, 10))
# 
#     plot_param = [
#         ("Total Fibers Assigned Per Tile", ["assign_total"], 5000, 5),
#         ("Standards Assigned Per Tile", ["assign_std"], 100, 2),
#         ("Sky Assigned Per Tile", ["assign_sky", "assign_suppsky"], 400, 2),
#     ]
# 
#     pindx = 1
#     for title, key, desired, incr in plot_param:
#         ax = fig.add_subplot(3, 1, pindx)
#         ax.set_aspect("equal")
#         xmin = 360.0
#         xmax = 0.0
#         ymin = 90.0
#         ymax = -90.0
#         for tid, props in data.items():
#             xcent = props["tile_ra"]
#             ycent = props["tile_dec"]
#             if xcent > xmax:
#                 xmax = xcent
#             if xcent < xmin:
#                 xmin = xcent
#             if ycent > ymax:
#                 ymax = ycent
#             if ycent < ymin:
#                 ymin = ycent
#             keytot = np.sum([props[x] for x in key])
#             color = plot_qa_tile_color(desired, keytot, incr)
#             circ = plt.Circle((xcent, ycent), radius=tile_radius, fc="none",
#                               ec=color, linewidth=linewidth)
#             ax.add_artist(circ)
#             if labels:
#                 ax.text(xcent, ycent, "{}".format(tid),
#                         color=color, fontsize=fontpt,
#                         horizontalalignment='center',
#                         verticalalignment='center',
#                         bbox=None)
# 
#         margin = 1.1 * tile_radius
# 
#         xmin -= margin
#         xmax += margin
#         ymin -= margin
#         ymax += margin
#         if xmin < 0.0:
#             xmin = 0.0
#         if xmax > 360.0:
#             xmax = 360.0
#         if ymin < -90.0:
#             ymin = -90.0
#         if ymax > 90.0:
#             ymax = 90.0
# 
#         ax.set_xlim(left=xmin, right=xmax)
#         ax.set_ylim(bottom=ymin, top=ymax)
#         ax.set_xlabel("RA (degrees)", fontsize="large")
#         ax.set_ylabel("DEC (degrees)", fontsize="large")
#         ax.set_title(title)
# 
#         c_high = plot_qa_tile_color(desired, desired+1, incr)
#         c_exact = plot_qa_tile_color(desired, desired, incr)
#         c_low_one = plot_qa_tile_color(desired, desired-incr, incr)
#         c_low_two = plot_qa_tile_color(desired, desired-2*incr, incr)
#         c_low = plot_qa_tile_color(desired, 0, incr)
# 
#         c_low_two_val = desired - incr
#         c_low_val = desired - 2 * incr
# 
#         legend_elements = [
#             Patch(facecolor=c_high, edgecolor="none",
#                   label="> {} assigned".format(desired)),
#             Patch(facecolor=c_exact, edgecolor="none",
#                   label="Exactly {} assigned".format(desired)),
#             Patch(facecolor=c_low_one, edgecolor="none",
#                   label="< {} assigned".format(desired)),
#             Patch(facecolor=c_low_two, edgecolor="none",
#                   label="< {} assigned".format(c_low_two_val)),
#             Patch(facecolor=c_low, edgecolor="none",
#                   label="< {} assigned".format(c_low_val)),
#         ]
#         ax.legend(handles=legend_elements, loc="best",
#                   fontsize="x-small")
#         pindx += 1
# 
#     outfile = "{}.{}".format(outroot, outformat)
#     plt.savefig(outfile, dpi=300, format="pdf")
# 
#     return


# Path: py/fiberassign/scripts/qa_plot.py
import os
import argparse
import json
from ..vis import plot_qa

        args = parser.parse_args()
    else:
        args = parser.parse_args(optlist)

    # Check directory
    if not os.path.isfile(args.qafile):
        raise RuntimeError("Input file {} does not exist".format(args.qafile))

    if args.outroot is None:
        args.outroot = os.path.splitext(args.qafile)[0]

    return args


def run_plot_qa(args):
    """Run QA plotting.

    This uses the previously parsed options to read input data and make a
    plot of the QA results.

    Args:
        args (namespace): The parsed arguments.

    Returns:
        None

    """
    qadata = None
    with open(args.qafile, "r") as f:
        qadata = json.load(f)

    plot_qa(qadata, args.outroot, labels=args.labels)