# 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/magsystems.py
# def get_magsystem(name):
#     """Get a MagSystem from the registry by name."""
#     if isinstance(name, MagSystem):
#         return name
#     return _MAGSYSTEMS.retrieve(name)
# 
# Path: sncosmo/utils.py
# def alias_map(aliased, aliases, required=()):
#     """For each key in ``aliases``, find the item in ``aliased`` matching
#     exactly one of the corresponding items in ``aliases``.
# 
#     Parameters
#     ----------
#     aliased : list of str
#         Input keys, will be values in output map.
#     aliases : dict of sets
#         Dictionary where keys are "canonical name" and values are sets of
#         possible aliases.
#     required : list_like
#         Keys in ``aliases`` that are considered required. An error is raised
#         if no alias is found in ``aliased``.
# 
# 
#     Returns
#     -------
# 
#     Example::
# 
#         >>> aliases = {'a':set(['a', 'a_']), 'b':set(['b', 'b_'])}
#         >>> alias_map(['A', 'B_', 'foo'], aliases)
#         {'a': 'A', 'b': 'B_'}
# 
# 
# 
#     """
#     lowered_to_orig = {key.lower(): key for key in aliased}
#     lowered = set(lowered_to_orig.keys())
#     mapping = {}
#     for key, key_aliases in aliases.items():
#         common = lowered & key_aliases
#         if len(common) == 1:
#             mapping[key] = lowered_to_orig[common.pop()]
# 
#         elif len(common) == 0 and key in required:
#             raise ValueError('no alias found for {!r} (possible '
#                              'case-independent aliases: {})'.format(
#                                  key,
#                                  ', '.join(repr(ka) for ka in key_aliases)))
#         elif len(common) > 1:
#             raise ValueError('multiple aliases found for {!r}: {}'
#                              .format(key, ', '.join(repr(a) for a in common)))
# 
#     return mapping


import copy
import numpy as np
from collections import OrderedDict
from astropy.table import Table
from .bandpasses import get_bandpass
from .magsystems import get_magsystem
from .utils import alias_map
        """

        factor = self._normalization_factor(zp, zpsys)

        newdata = copy.copy(self)
        newdata.flux = factor * self.flux
        newdata.fluxerr = factor * self.fluxerr
        newdata.zp = np.full(len(self), zp, dtype=np.float64)
        newdata.zpsys = np.full(len(self), zpsys, dtype=np.array(zpsys).dtype)
        if newdata.fluxcov is not None:
            newdata.fluxcov = factor * factor[:, None] * self.fluxcov

        return newdata

    def normalized_flux(self, zp=25., zpsys='ab'):
        return self._normalization_factor(zp, zpsys) * self.flux

    def _normalization_factor(self, zp, zpsys):
        """Factor such that multiplying by this amount brings all fluxes onto
        the given zeropoint and zeropoint system."""

        normmagsys = get_magsystem(zpsys)
        factor = np.empty(len(self), dtype=float)

        for b in set(self.band.tolist()):
            mask = self.band == b
            bandfactor = 10.**(0.4 * (zp - self.zp[mask]))
            bandzpsys = self.zpsys[mask]
            for ms in set(bandzpsys):
                mask2 = bandzpsys == ms

# 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/magsystems.py
# def get_magsystem(name):
#     """Get a MagSystem from the registry by name."""
#     if isinstance(name, MagSystem):
#         return name
#     return _MAGSYSTEMS.retrieve(name)
# 
# Path: sncosmo/utils.py
# def alias_map(aliased, aliases, required=()):
#     """For each key in ``aliases``, find the item in ``aliased`` matching
#     exactly one of the corresponding items in ``aliases``.
# 
#     Parameters
#     ----------
#     aliased : list of str
#         Input keys, will be values in output map.
#     aliases : dict of sets
#         Dictionary where keys are "canonical name" and values are sets of
#         possible aliases.
#     required : list_like
#         Keys in ``aliases`` that are considered required. An error is raised
#         if no alias is found in ``aliased``.
# 
# 
#     Returns
#     -------
# 
#     Example::
# 
#         >>> aliases = {'a':set(['a', 'a_']), 'b':set(['b', 'b_'])}
#         >>> alias_map(['A', 'B_', 'foo'], aliases)
#         {'a': 'A', 'b': 'B_'}
# 
# 
# 
#     """
#     lowered_to_orig = {key.lower(): key for key in aliased}
#     lowered = set(lowered_to_orig.keys())
#     mapping = {}
#     for key, key_aliases in aliases.items():
#         common = lowered & key_aliases
#         if len(common) == 1:
#             mapping[key] = lowered_to_orig[common.pop()]
# 
#         elif len(common) == 0 and key in required:
#             raise ValueError('no alias found for {!r} (possible '
#                              'case-independent aliases: {})'.format(
#                                  key,
#                                  ', '.join(repr(ka) for ka in key_aliases)))
#         elif len(common) > 1:
#             raise ValueError('multiple aliases found for {!r}: {}'
#                              .format(key, ', '.join(repr(a) for a in common)))
# 
#     return mapping


# Path: sncosmo/photdata.py
import copy
import numpy as np
from collections import OrderedDict
from astropy.table import Table
from .bandpasses import get_bandpass
from .magsystems import get_magsystem
from .utils import alias_map

        """

        factor = self._normalization_factor(zp, zpsys)

        newdata = copy.copy(self)
        newdata.flux = factor * self.flux
        newdata.fluxerr = factor * self.fluxerr
        newdata.zp = np.full(len(self), zp, dtype=np.float64)
        newdata.zpsys = np.full(len(self), zpsys, dtype=np.array(zpsys).dtype)
        if newdata.fluxcov is not None:
            newdata.fluxcov = factor * factor[:, None] * self.fluxcov

        return newdata

    def normalized_flux(self, zp=25., zpsys='ab'):
        return self._normalization_factor(zp, zpsys) * self.flux

    def _normalization_factor(self, zp, zpsys):
        """Factor such that multiplying by this amount brings all fluxes onto
        the given zeropoint and zeropoint system."""

        normmagsys = get_magsystem(zpsys)
        factor = np.empty(len(self), dtype=float)

        for b in set(self.band.tolist()):
            mask = self.band == b
            bandfactor = 10.**(0.4 * (zp - self.zp[mask]))
            bandzpsys = self.zpsys[mask]
            for ms in set(bandzpsys):
                mask2 = bandzpsys == ms

                ms = get_magsystem(ms)