# Path: sedfitter/sed/cube.py
# class SEDCube(BaseCube):
#     _physical_type = ('power', 'flux', 'spectral flux density')
# 
#     def get_sed(self, model_name):
# 
#         try:
#             sed_index = np.nonzero(self.names == model_name)[0][0]
#         except IndexError:
#             raise ValueError("Model '{0}' not found in SED cube".format(model_name))
# 
#         from .sed import SED
#         sed = SED()
#         sed.name = model_name
#         sed.distance = self.distance
#         sed.wav = self.wav
#         sed.nu = self.nu
#         sed.apertures = self.apertures
#         sed.flux = self.val[sed_index, :,:]
#         sed.error = self.unc[sed_index, :,:]
#         return sed


import numpy as np
from astropy import units as u
from ..cube import SEDCube
    n_ap = 3
    n_wav = 10

    s = SEDCube()

    s.names = ['name_{0:02d}'.format(i) for i in range(n_models)]

    s.apertures = np.linspace(10, 100, n_ap) * u.au

    s.wav = np.linspace(0.01, 5000, n_wav)[::-1] * u.micron

    s.distance = 1. * u.kpc

    s.val = np.random.random((n_models, n_ap, n_wav)) * u.mJy
    s.unc = np.random.random((n_models, n_ap, n_wav)) * u.mJy

    temp_file = tmpdir.join('test_roundtrip_sedcube').strpath

    s.write(temp_file)

    s2 = SEDCube.read(temp_file)

    assert s == s2


def test_roundrip_missing_optional(tmpdir):

    n_models = 30
    n_wav = 10


# Path: sedfitter/sed/cube.py
# class SEDCube(BaseCube):
#     _physical_type = ('power', 'flux', 'spectral flux density')
# 
#     def get_sed(self, model_name):
# 
#         try:
#             sed_index = np.nonzero(self.names == model_name)[0][0]
#         except IndexError:
#             raise ValueError("Model '{0}' not found in SED cube".format(model_name))
# 
#         from .sed import SED
#         sed = SED()
#         sed.name = model_name
#         sed.distance = self.distance
#         sed.wav = self.wav
#         sed.nu = self.nu
#         sed.apertures = self.apertures
#         sed.flux = self.val[sed_index, :,:]
#         sed.error = self.unc[sed_index, :,:]
#         return sed


# Path: sedfitter/sed/tests/test_cube.py
import numpy as np
from astropy import units as u
from ..cube import SEDCube

    n_ap = 3
    n_wav = 10

    s = SEDCube()

    s.names = ['name_{0:02d}'.format(i) for i in range(n_models)]

    s.apertures = np.linspace(10, 100, n_ap) * u.au

    s.wav = np.linspace(0.01, 5000, n_wav)[::-1] * u.micron

    s.distance = 1. * u.kpc

    s.val = np.random.random((n_models, n_ap, n_wav)) * u.mJy
    s.unc = np.random.random((n_models, n_ap, n_wav)) * u.mJy

    temp_file = tmpdir.join('test_roundtrip_sedcube').strpath

    s.write(temp_file)

    s2 = SEDCube.read(temp_file)

    assert s == s2


def test_roundrip_missing_optional(tmpdir):

    n_models = 30
    n_wav = 10


    s = SEDCube()