# Path: sncosmo/bandpasses.py
# def get_bandpass(name, *args):
#     """Get a Bandpass from the registry by name."""
#     if isinstance(name, Bandpass):
#         return name
#     if len(args) == 0:
#         return _BANDPASSES.retrieve(name)
#     else:
#         interp = _BANDPASS_INTERPOLATORS.retrieve(name)
#         return interp.at(*args)
# 
# Path: sncosmo/utils.py
# def dict_to_array(d):
#     """Convert a dictionary of lists (or single values) to a structured
#     numpy.ndarray."""
# 
#     # Convert all lists/values to 1-d arrays, in order to let numpy
#     # figure out the necessary size of the string arrays.
#     new_d = OrderedDict()
#     for key in d:
#         new_d[key] = np.atleast_1d(d[key])
# 
#     # Determine dtype of output array.
#     dtype = [(key, arr.dtype)
#              for key, arr in new_d.items()]
# 
#     # Initialize ndarray and then fill it.
#     col_len = max([len(v) for v in new_d.values()])
#     result = np.empty(col_len, dtype=dtype)
#     for key in new_d:
#         result[key] = new_d[key]
# 
#     return result


import json
import math
import os
import numpy as np
from collections import OrderedDict
from astropy import wcs
from astropy.io import fits
from astropy.table import Table
from .bandpasses import get_bandpass
from .utils import dict_to_array
    from astropy.utils.data import get_pkg_data_filename
    from astropy.utils.data import get_pkg_data_filename
        # Now we're reading data
        items = line.split(delim)
        for col, item in zip(cols, items):
            col.append(_cast_str(item))

    data = OrderedDict(zip(colnames, cols))
    return meta, data


# -----------------------------------------------------------------------------
# Reader: salt2

def _expand_bands(band_list, meta):
    """Given a list containing band names, return a list of Bandpass objects"""

    # Treat dependent bandpasses based on metadata contents
    # TODO: need a way to figure out which bands are position dependent!
    #       for now, we assume *all* or none are.
    if "X_FOCAL_PLANE" in meta and "Y_FOCAL_PLANE" in meta:
        r = math.sqrt(meta["X_FOCAL_PLANE"]**2 + meta["Y_FOCAL_PLANE"]**2)

        # map name to object for unique bands
        name_to_band = {name: get_bandpass(name, r)
                        for name in set(band_list)}

        return [name_to_band[name] for name in band_list]

    else:
        # For other bandpasses, get_bandpass will return the same object
        # on each call, so just use it directly.

# Path: sncosmo/bandpasses.py
# def get_bandpass(name, *args):
#     """Get a Bandpass from the registry by name."""
#     if isinstance(name, Bandpass):
#         return name
#     if len(args) == 0:
#         return _BANDPASSES.retrieve(name)
#     else:
#         interp = _BANDPASS_INTERPOLATORS.retrieve(name)
#         return interp.at(*args)
# 
# Path: sncosmo/utils.py
# def dict_to_array(d):
#     """Convert a dictionary of lists (or single values) to a structured
#     numpy.ndarray."""
# 
#     # Convert all lists/values to 1-d arrays, in order to let numpy
#     # figure out the necessary size of the string arrays.
#     new_d = OrderedDict()
#     for key in d:
#         new_d[key] = np.atleast_1d(d[key])
# 
#     # Determine dtype of output array.
#     dtype = [(key, arr.dtype)
#              for key, arr in new_d.items()]
# 
#     # Initialize ndarray and then fill it.
#     col_len = max([len(v) for v in new_d.values()])
#     result = np.empty(col_len, dtype=dtype)
#     for key in new_d:
#         result[key] = new_d[key]
# 
#     return result


# Path: sncosmo/io.py
import json
import math
import os
import numpy as np
from collections import OrderedDict
from astropy import wcs
from astropy.io import fits
from astropy.table import Table
from .bandpasses import get_bandpass
from .utils import dict_to_array
    from astropy.utils.data import get_pkg_data_filename
    from astropy.utils.data import get_pkg_data_filename

        # Now we're reading data
        items = line.split(delim)
        for col, item in zip(cols, items):
            col.append(_cast_str(item))

    data = OrderedDict(zip(colnames, cols))
    return meta, data


# -----------------------------------------------------------------------------
# Reader: salt2

def _expand_bands(band_list, meta):
    """Given a list containing band names, return a list of Bandpass objects"""

    # Treat dependent bandpasses based on metadata contents
    # TODO: need a way to figure out which bands are position dependent!
    #       for now, we assume *all* or none are.
    if "X_FOCAL_PLANE" in meta and "Y_FOCAL_PLANE" in meta:
        r = math.sqrt(meta["X_FOCAL_PLANE"]**2 + meta["Y_FOCAL_PLANE"]**2)

        # map name to object for unique bands
        name_to_band = {name: get_bandpass(name, r)
                        for name in set(band_list)}

        return [name_to_band[name] for name in band_list]

    else:
        # For other bandpasses, get_bandpass will return the same object
        # on each call, so just use it directly.

        return [get_bandpass(name) for name in band_list]