# Path: sedfitter/utils/validator.py
# def validate_array(name, value, domain=None, ndim=1, shape=None, physical_type=None):
# 
#     validate_physical_type(name, value, physical_type)
# 
#     # First convert to a Numpy array:
#     if type(value) in [list, tuple]:
#         value = np.array(value)
# 
#     # Check the value is an array with the right number of dimensions
#     if not isinstance(value, np.ndarray) or value.ndim != ndim:
#         if ndim == 1:
#             raise TypeError("{0} should be a 1-d sequence".format(name))
#         else:
#             raise TypeError("{0} should be a {1:d}-d array".format(name, ndim))
# 
#     # Check that the shape matches that expected
#     if shape is not None and value.shape != shape:
#         if ndim == 1:
#             raise ValueError("{0} has incorrect length (expected {1} but found {2})".format(name, shape[0], value.shape[0]))
#         else:
#             # On Windows, shapes can contain long integers, so we fix this to
#             # have consistent error messages across platforms.
#             expected_shape = tuple(int(x) for x in shape)
#             actual_shape = tuple(int(x) for x in value.shape)
#             raise ValueError("{0} has incorrect shape (expected {1} but found {2})".format(name, expected_shape, actual_shape))
# 
#     return value
# 
# Path: sedfitter/sed/helpers.py
# def parse_unit_safe(unit_string):
#     if unit_string in UNIT_MAPPING:
#         return UNIT_MAPPING[unit_string]
#     else:
#         return u.Unit(unit_string, parse_strict=False)
# 
# def assert_allclose_quantity(q1, q2):
#     if q1 is None and q2 is None:
#         return True
#     if q1 is None or q2 is None:
#         raise AssertionError()
#     else:
#         np.testing.assert_allclose(q1.value, q2.to(q1.unit).value)
# 
# def convert_flux(nu, flux, target_unit, distance=None):
#     """
#     Convert flux to a target unit
#     """
# 
#     curr_unit = flux.unit
# 
#     if curr_unit.is_equivalent(u.erg / u.s):
#         flux = flux / distance ** 2
#     elif curr_unit.is_equivalent(u.Jy):
#         flux = flux * nu
#     elif not curr_unit.is_equivalent(u.erg / u.cm ** 2 / u.s):
#         raise Exception("Don't know how to convert {0} to ergs/cm^2/s" % (flux.unit))
# 
#     # Convert to requested unit
# 
#     if target_unit.is_equivalent(u.erg / u.s):
#         flux = flux * distance ** 2
#     elif target_unit.is_equivalent(u.Jy):
#         flux = flux / nu
#     elif not target_unit.is_equivalent(u.erg / u.cm ** 2 / u.s):
#         raise Exception("Don't know how to convert %s to %s" % (curr_unit, target_unit))
# 
#     return flux.to(target_unit)


import os
import numpy as np
from astropy import log
from astropy.io import fits
from astropy.table import Table
from scipy.interpolate import interp1d
from astropy import units as u
from ..utils.validator import validate_array
from .helpers import parse_unit_safe, assert_allclose_quantity, convert_flux
        from copy import deepcopy
class SED(object):

    def __init__(self):

        # Metadata
        self.name = None
        self.distance = None

        # Spectral info
        self.wav = None
        self.nu = None

        # Apertures
        self.apertures = None

        # Fluxes
        self.flux = None
        self.error = None

    def __eq__(self, other):

        try:

            assert self.name == other.name

            assert_allclose_quantity(self.distance, other.distance)

            assert_allclose_quantity(self.wav, other.wav)
            assert_allclose_quantity(self.nu, other.nu)


# Path: sedfitter/utils/validator.py
# def validate_array(name, value, domain=None, ndim=1, shape=None, physical_type=None):
# 
#     validate_physical_type(name, value, physical_type)
# 
#     # First convert to a Numpy array:
#     if type(value) in [list, tuple]:
#         value = np.array(value)
# 
#     # Check the value is an array with the right number of dimensions
#     if not isinstance(value, np.ndarray) or value.ndim != ndim:
#         if ndim == 1:
#             raise TypeError("{0} should be a 1-d sequence".format(name))
#         else:
#             raise TypeError("{0} should be a {1:d}-d array".format(name, ndim))
# 
#     # Check that the shape matches that expected
#     if shape is not None and value.shape != shape:
#         if ndim == 1:
#             raise ValueError("{0} has incorrect length (expected {1} but found {2})".format(name, shape[0], value.shape[0]))
#         else:
#             # On Windows, shapes can contain long integers, so we fix this to
#             # have consistent error messages across platforms.
#             expected_shape = tuple(int(x) for x in shape)
#             actual_shape = tuple(int(x) for x in value.shape)
#             raise ValueError("{0} has incorrect shape (expected {1} but found {2})".format(name, expected_shape, actual_shape))
# 
#     return value
# 
# Path: sedfitter/sed/helpers.py
# def parse_unit_safe(unit_string):
#     if unit_string in UNIT_MAPPING:
#         return UNIT_MAPPING[unit_string]
#     else:
#         return u.Unit(unit_string, parse_strict=False)
# 
# def assert_allclose_quantity(q1, q2):
#     if q1 is None and q2 is None:
#         return True
#     if q1 is None or q2 is None:
#         raise AssertionError()
#     else:
#         np.testing.assert_allclose(q1.value, q2.to(q1.unit).value)
# 
# def convert_flux(nu, flux, target_unit, distance=None):
#     """
#     Convert flux to a target unit
#     """
# 
#     curr_unit = flux.unit
# 
#     if curr_unit.is_equivalent(u.erg / u.s):
#         flux = flux / distance ** 2
#     elif curr_unit.is_equivalent(u.Jy):
#         flux = flux * nu
#     elif not curr_unit.is_equivalent(u.erg / u.cm ** 2 / u.s):
#         raise Exception("Don't know how to convert {0} to ergs/cm^2/s" % (flux.unit))
# 
#     # Convert to requested unit
# 
#     if target_unit.is_equivalent(u.erg / u.s):
#         flux = flux * distance ** 2
#     elif target_unit.is_equivalent(u.Jy):
#         flux = flux / nu
#     elif not target_unit.is_equivalent(u.erg / u.cm ** 2 / u.s):
#         raise Exception("Don't know how to convert %s to %s" % (curr_unit, target_unit))
# 
#     return flux.to(target_unit)


# Path: sedfitter/sed/sed.py
import os
import numpy as np
from astropy import log
from astropy.io import fits
from astropy.table import Table
from scipy.interpolate import interp1d
from astropy import units as u
from ..utils.validator import validate_array
from .helpers import parse_unit_safe, assert_allclose_quantity, convert_flux
        from copy import deepcopy

class SED(object):

    def __init__(self):

        # Metadata
        self.name = None
        self.distance = None

        # Spectral info
        self.wav = None
        self.nu = None

        # Apertures
        self.apertures = None

        # Fluxes
        self.flux = None
        self.error = None

    def __eq__(self, other):

        try:

            assert self.name == other.name

            assert_allclose_quantity(self.distance, other.distance)

            assert_allclose_quantity(self.wav, other.wav)
            assert_allclose_quantity(self.nu, other.nu)


            assert_allclose_quantity(self.apertures, other.apertures)