# Path: py/fiberassign/test/simulate.py
# def sim_data_dir():
# def test_subdir_create(name):
# def sim_science_fractions():
# def sim_focalplane(rundate=None, fakepos=False):
# def sim_stuck_sky(dirnm, hw, tiles):
#     def radec2xyz(r, d):
# def sim_tiles(path, selectfile=None):
# def sim_targets(path, tgtype, tgoffset, density=5000.0, science_frac=None):
# def petal_rotation(npos, reverse=False):
#         J = np.flatnonzero(r2 < maxr2)


import os
import shutil
import unittest
import glob
import json
import numpy as np
import fitsio
import desimodel
from datetime import datetime
from fiberassign.utils import option_list, GlobalTimers
from fiberassign.hardware import load_hardware
from fiberassign.tiles import load_tiles, Tiles
from fiberassign.targets import (TARGET_TYPE_SCIENCE, TARGET_TYPE_SKY,
                                 TARGET_TYPE_SUPPSKY,
                                 TARGET_TYPE_STANDARD, TARGET_TYPE_SAFE,
                                 Targets, TargetsAvailable, targets_in_tiles,
                                 LocationsAvailable, load_target_file, create_tagalong)
from fiberassign.assign import (Assignment, write_assignment_fits,
                                write_assignment_ascii, merge_results,
                                read_assignment_fits_tile, run)
from fiberassign.stucksky import stuck_on_sky
from fiberassign.qa import qa_tiles
from fiberassign.vis import plot_tiles, plot_qa
from fiberassign.scripts.assign import parse_assign, run_assign_full
from fiberassign.scripts.plot import parse_plot, run_plot
from fiberassign.scripts.qa import parse_qa, run_qa
from fiberassign.scripts.qa_plot import parse_plot_qa, run_plot_qa
from .simulate import (test_subdir_create, sim_tiles, sim_targets,
                       sim_focalplane, petal_rotation, test_assign_date,
                       sim_stuck_sky)
                    self.assertEqual(tgprior, props.priority)
            for tgid, tgra, tgdec, tgsub, tgprior, tgobs in zip(
                    ftargets["TARGETID"],
                    ftargets["RA"],
                    ftargets["DEC"],
                    ftargets["SUBPRIORITY"],
                    ftargets["PRIORITY"],
                    ftargets["OBSCONDITIONS"]):
                props = tgs.get(tgid)
                self.assertEqual(tgsub, props.subpriority)
                self.assertEqual(tgprior, props.priority)

        plot_tiles(glob.glob(os.path.join(test_dir, "basic_tile-*")), petals=plotpetals,
                   serial=True)

        plot_tiles(glob.glob(os.path.join(test_dir, "full_tile-*")), petals=plotpetals,
                   serial=True)
        return

    def test_stucksky(self):
        return self.test_full(do_stucksky=True)

    def test_full(self, do_stucksky=False):
        test_dir = test_subdir_create("assign_test_full")
        np.random.seed(123456789)
        input_mtl = os.path.join(test_dir, "mtl.fits")
        input_std = os.path.join(test_dir, "standards.fits")
        input_sky = os.path.join(test_dir, "sky.fits")
        input_suppsky = os.path.join(test_dir, "suppsky.fits")
        tgoff = 0

# Path: py/fiberassign/test/simulate.py
# def sim_data_dir():
# def test_subdir_create(name):
# def sim_science_fractions():
# def sim_focalplane(rundate=None, fakepos=False):
# def sim_stuck_sky(dirnm, hw, tiles):
#     def radec2xyz(r, d):
# def sim_tiles(path, selectfile=None):
# def sim_targets(path, tgtype, tgoffset, density=5000.0, science_frac=None):
# def petal_rotation(npos, reverse=False):
#         J = np.flatnonzero(r2 < maxr2)


# Path: py/fiberassign/test/test_assign.py
import os
import shutil
import unittest
import glob
import json
import numpy as np
import fitsio
import desimodel
from datetime import datetime
from fiberassign.utils import option_list, GlobalTimers
from fiberassign.hardware import load_hardware
from fiberassign.tiles import load_tiles, Tiles
from fiberassign.targets import (TARGET_TYPE_SCIENCE, TARGET_TYPE_SKY,
                                 TARGET_TYPE_SUPPSKY,
                                 TARGET_TYPE_STANDARD, TARGET_TYPE_SAFE,
                                 Targets, TargetsAvailable, targets_in_tiles,
                                 LocationsAvailable, load_target_file, create_tagalong)
from fiberassign.assign import (Assignment, write_assignment_fits,
                                write_assignment_ascii, merge_results,
                                read_assignment_fits_tile, run)
from fiberassign.stucksky import stuck_on_sky
from fiberassign.qa import qa_tiles
from fiberassign.vis import plot_tiles, plot_qa
from fiberassign.scripts.assign import parse_assign, run_assign_full
from fiberassign.scripts.plot import parse_plot, run_plot
from fiberassign.scripts.qa import parse_qa, run_qa
from fiberassign.scripts.qa_plot import parse_plot_qa, run_plot_qa
from .simulate import (test_subdir_create, sim_tiles, sim_targets,
                       sim_focalplane, petal_rotation, test_assign_date,
                       sim_stuck_sky)

                    self.assertEqual(tgprior, props.priority)
            for tgid, tgra, tgdec, tgsub, tgprior, tgobs in zip(
                    ftargets["TARGETID"],
                    ftargets["RA"],
                    ftargets["DEC"],
                    ftargets["SUBPRIORITY"],
                    ftargets["PRIORITY"],
                    ftargets["OBSCONDITIONS"]):
                props = tgs.get(tgid)
                self.assertEqual(tgsub, props.subpriority)
                self.assertEqual(tgprior, props.priority)

        plot_tiles(glob.glob(os.path.join(test_dir, "basic_tile-*")), petals=plotpetals,
                   serial=True)

        plot_tiles(glob.glob(os.path.join(test_dir, "full_tile-*")), petals=plotpetals,
                   serial=True)
        return

    def test_stucksky(self):
        return self.test_full(do_stucksky=True)

    def test_full(self, do_stucksky=False):
        test_dir = test_subdir_create("assign_test_full")
        np.random.seed(123456789)
        input_mtl = os.path.join(test_dir, "mtl.fits")
        input_std = os.path.join(test_dir, "standards.fits")
        input_sky = os.path.join(test_dir, "sky.fits")
        input_suppsky = os.path.join(test_dir, "suppsky.fits")
        tgoff = 0

        nscience = sim_targets(