# Path: py/fiberassign/utils.py
# def option_list(opts):
# def assert_isoformat_utc(time_str):
# def get_date_cutoff(datetype, cutoff_case):
# def get_svn_version(svn_dir):
# def get_last_line(fn):
# def read_ecsv_keys(fn):


import numpy as np
import fitsio
import desimodel.focalplane.gfa
    import astropy.units as u
from astropy.table import Table
from desitarget.gaiamatch import gaia_psflike
from ._internal import Tiles
from .utils import Logger, Timer
    from astropy.coordinates import SkyCoord
    synth_r_mag = np.array(tab["GAIA_PHOT_G_MEAN_MAG"])

    for order,c in enumerate(coeffs):
            synth_r_mag += c * color**order

    synth_r_flux = np.power(10, (22.5-synth_r_mag)/2.5)

    # -99 is the FLUX_R placeholder that GFA_TARGETS uses
    synth_r_flux[badcolor] = -99.0

    return synth_r_flux

def get_gfa_targets(tiles, gfafile, faintlim=99):
     
    """Returns a list of tables of GFA targets on each tile

    Args:
        tiles: table with columns TILEID, RA, DEC; or Tiles object
        targets: table of targets with columsn RA, DEC

    Returns:
        list of tables (one row per input tile) with the subset of targets
        that are covered by GFAs on each tile.  Each table has additional
        `GFA_LOC` column indicating 0-9 which GFA was covered.

    Note that a given target could be covered by GFAs on more than one tile.

    Output is a list of astropy Tables; inputs can be numpy structured arrays
    or astropy Tables
    """

# Path: py/fiberassign/utils.py
# def option_list(opts):
# def assert_isoformat_utc(time_str):
# def get_date_cutoff(datetype, cutoff_case):
# def get_svn_version(svn_dir):
# def get_last_line(fn):
# def read_ecsv_keys(fn):


# Path: py/fiberassign/gfa.py
import numpy as np
import fitsio
import desimodel.focalplane.gfa
    import astropy.units as u
from astropy.table import Table
from desitarget.gaiamatch import gaia_psflike
from ._internal import Tiles
from .utils import Logger, Timer
    from astropy.coordinates import SkyCoord

    synth_r_mag = np.array(tab["GAIA_PHOT_G_MEAN_MAG"])

    for order,c in enumerate(coeffs):
            synth_r_mag += c * color**order

    synth_r_flux = np.power(10, (22.5-synth_r_mag)/2.5)

    # -99 is the FLUX_R placeholder that GFA_TARGETS uses
    synth_r_flux[badcolor] = -99.0

    return synth_r_flux

def get_gfa_targets(tiles, gfafile, faintlim=99):
     
    """Returns a list of tables of GFA targets on each tile

    Args:
        tiles: table with columns TILEID, RA, DEC; or Tiles object
        targets: table of targets with columsn RA, DEC

    Returns:
        list of tables (one row per input tile) with the subset of targets
        that are covered by GFAs on each tile.  Each table has additional
        `GFA_LOC` column indicating 0-9 which GFA was covered.

    Note that a given target could be covered by GFAs on more than one tile.

    Output is a list of astropy Tables; inputs can be numpy structured arrays
    or astropy Tables
    """

    log = Logger.get()