# Path: batoid/medium.py
# class SumitaMedium(Medium):
#     r"""A `Medium` with Sumita dispersion formula, also known as the Schott
#     dispersion formula.
# 
#     The Sumita formula is
# 
#     .. math::
# 
#         n = \sqrt{A_0 + A_1 \lambda^2 + \sum_{i=2}^5 A_i \lambda^{-2 (i-1)}}
# 
#     where :math:`\lambda` is the vacuum wavelength in microns.
# 
#     Parameters
#     ----------
#     coefs: array of float
#         Sumita coefficients (A0, A1, A2, A3, A4, A5)
#     """
#     def __init__(self, *args, **kwargs):
#         if len(args) == 6:
#             coefs = tuple(args)
#         elif len(args) == 1:
#             coefs = tuple(args[0])
#         elif kwargs:
#             coefs = tuple([
#                 kwargs[k] for k in ['A0', 'A1', 'A2', 'A3', 'A4', 'A5']
#             ])
#         else:
#             raise ValueError("Incorrect number of arguments")
#         self.coefs = coefs
#         self._medium = _batoid.CPPSumitaMedium(*coefs)
# 
#     def __eq__(self, rhs):
#         if type(rhs) == type(self):
#             return self.coefs == rhs.coefs
#         return False
# 
#     def __getstate__(self):
#         return self.coefs
# 
#     def __setstate__(self, coefs):
#         self.coefs = coefs
#         self._medium = _batoid.CPPSumitaMedium(*coefs)
# 
#     def __hash__(self):
#         return hash(("batoid.SumitaMedium", self.coefs))
# 
#     def __repr__(self):
#         return f"SumitaMedium({self.coefs})"
# 
# class TableMedium(Medium):
#     """A `Medium` with refractive index defined via a lookup table.
# 
#     Parameters
#     ----------
#     wavelengths : array of float
#         Wavelengths in meters.
#     ns : array of float
#         Refractive indices.
#     """
#     def __init__(self, wavelengths, ns):
#         self.wavelengths = np.array(wavelengths)
#         self.ns = np.array(ns)
#         self._medium = _batoid.CPPTableMedium(
#             self.wavelengths.ctypes.data,
#             self.ns.ctypes.data,
#             len(self.wavelengths)
#         )
# 
#     @classmethod
#     def fromTxt(cls, filename, **kwargs):
#         """Load a text file with refractive index information in it.
#         The file should have two columns, the first with wavelength in microns,
#         and the second with the corresponding refractive indices.
#         """
#         import os
#         try:
#             wavelength, n = np.loadtxt(filename, unpack=True, **kwargs)
#         except IOError:
#             import glob
#             from . import datadir
#             filenames = glob.glob(os.path.join(datadir, "**", "*.txt"))
#             for candidate in filenames:
#                 if os.path.basename(candidate) == filename:
#                     wavelength, n = np.loadtxt(candidate, unpack=True, **kwargs)
#                     break
#             else:
#                 raise FileNotFoundError(filename)
#         return TableMedium(wavelength*1e-6, n)
# 
#     def __eq__(self, rhs):
#         if type(rhs) == type(self):
#             return (
#                 np.array_equal(self.wavelengths, rhs.wavelengths)
#                 and np.array_equal(self.ns, rhs.ns)
#             )
#         return False
# 
#     def __getstate__(self):
#         return self.wavelengths, self.ns
# 
#     def __setstate__(self, args):
#         self.__init__(*args)
# 
#     def __hash__(self):
#         return hash((
#             "batoid.TableMedium", tuple(self.wavelengths), tuple(self.ns)
#         ))
# 
#     def __repr__(self):
#         return f"TableMedium({self.wavelengths!r}, {self.ns!r})"


from batoid.medium import SumitaMedium, TableMedium
from test_helpers import timer, do_pickle, all_obj_diff
import os
import numpy as np
import batoid
        ns = rng.uniform(1.0, 1.5, size=6)
        table_medium = batoid.TableMedium(ws, ns)
        testws = rng.uniform(300e-9, 1100e-9, size=100)
        for w in testws:
            np.testing.assert_allclose(
                table_medium.getN(w),
                np.interp(w, ws, ns),
                rtol=0, atol=1e-14
            )
        np.testing.assert_allclose(
            table_medium.getN(testws),
            np.interp(testws, ws, ns),
            rtol=0, atol=1e-14
        )
    do_pickle(table_medium)

    # Test load from file
    filename = os.path.join(
        os.path.dirname(__file__),
        "testdata",
        "silicaDispersion.csv"
    )
    medium1 = batoid.TableMedium.fromTxt(
        filename, delimiter=','
    )
    wmicron, ncsv = np.loadtxt(filename, delimiter=',').T
    medium2 = batoid.TableMedium(wmicron*1e-6, ncsv)
    assert medium1 == medium2

    # Load from datadir

# Path: batoid/medium.py
# class SumitaMedium(Medium):
#     r"""A `Medium` with Sumita dispersion formula, also known as the Schott
#     dispersion formula.
# 
#     The Sumita formula is
# 
#     .. math::
# 
#         n = \sqrt{A_0 + A_1 \lambda^2 + \sum_{i=2}^5 A_i \lambda^{-2 (i-1)}}
# 
#     where :math:`\lambda` is the vacuum wavelength in microns.
# 
#     Parameters
#     ----------
#     coefs: array of float
#         Sumita coefficients (A0, A1, A2, A3, A4, A5)
#     """
#     def __init__(self, *args, **kwargs):
#         if len(args) == 6:
#             coefs = tuple(args)
#         elif len(args) == 1:
#             coefs = tuple(args[0])
#         elif kwargs:
#             coefs = tuple([
#                 kwargs[k] for k in ['A0', 'A1', 'A2', 'A3', 'A4', 'A5']
#             ])
#         else:
#             raise ValueError("Incorrect number of arguments")
#         self.coefs = coefs
#         self._medium = _batoid.CPPSumitaMedium(*coefs)
# 
#     def __eq__(self, rhs):
#         if type(rhs) == type(self):
#             return self.coefs == rhs.coefs
#         return False
# 
#     def __getstate__(self):
#         return self.coefs
# 
#     def __setstate__(self, coefs):
#         self.coefs = coefs
#         self._medium = _batoid.CPPSumitaMedium(*coefs)
# 
#     def __hash__(self):
#         return hash(("batoid.SumitaMedium", self.coefs))
# 
#     def __repr__(self):
#         return f"SumitaMedium({self.coefs})"
# 
# class TableMedium(Medium):
#     """A `Medium` with refractive index defined via a lookup table.
# 
#     Parameters
#     ----------
#     wavelengths : array of float
#         Wavelengths in meters.
#     ns : array of float
#         Refractive indices.
#     """
#     def __init__(self, wavelengths, ns):
#         self.wavelengths = np.array(wavelengths)
#         self.ns = np.array(ns)
#         self._medium = _batoid.CPPTableMedium(
#             self.wavelengths.ctypes.data,
#             self.ns.ctypes.data,
#             len(self.wavelengths)
#         )
# 
#     @classmethod
#     def fromTxt(cls, filename, **kwargs):
#         """Load a text file with refractive index information in it.
#         The file should have two columns, the first with wavelength in microns,
#         and the second with the corresponding refractive indices.
#         """
#         import os
#         try:
#             wavelength, n = np.loadtxt(filename, unpack=True, **kwargs)
#         except IOError:
#             import glob
#             from . import datadir
#             filenames = glob.glob(os.path.join(datadir, "**", "*.txt"))
#             for candidate in filenames:
#                 if os.path.basename(candidate) == filename:
#                     wavelength, n = np.loadtxt(candidate, unpack=True, **kwargs)
#                     break
#             else:
#                 raise FileNotFoundError(filename)
#         return TableMedium(wavelength*1e-6, n)
# 
#     def __eq__(self, rhs):
#         if type(rhs) == type(self):
#             return (
#                 np.array_equal(self.wavelengths, rhs.wavelengths)
#                 and np.array_equal(self.ns, rhs.ns)
#             )
#         return False
# 
#     def __getstate__(self):
#         return self.wavelengths, self.ns
# 
#     def __setstate__(self, args):
#         self.__init__(*args)
# 
#     def __hash__(self):
#         return hash((
#             "batoid.TableMedium", tuple(self.wavelengths), tuple(self.ns)
#         ))
# 
#     def __repr__(self):
#         return f"TableMedium({self.wavelengths!r}, {self.ns!r})"


# Path: tests/test_Medium.py
from batoid.medium import SumitaMedium, TableMedium
from test_helpers import timer, do_pickle, all_obj_diff
import os
import numpy as np
import batoid

        ns = rng.uniform(1.0, 1.5, size=6)
        table_medium = batoid.TableMedium(ws, ns)
        testws = rng.uniform(300e-9, 1100e-9, size=100)
        for w in testws:
            np.testing.assert_allclose(
                table_medium.getN(w),
                np.interp(w, ws, ns),
                rtol=0, atol=1e-14
            )
        np.testing.assert_allclose(
            table_medium.getN(testws),
            np.interp(testws, ws, ns),
            rtol=0, atol=1e-14
        )
    do_pickle(table_medium)

    # Test load from file
    filename = os.path.join(
        os.path.dirname(__file__),
        "testdata",
        "silicaDispersion.csv"
    )
    medium1 = batoid.TableMedium.fromTxt(
        filename, delimiter=','
    )
    wmicron, ncsv = np.loadtxt(filename, delimiter=',').T
    medium2 = batoid.TableMedium(wmicron*1e-6, ncsv)
    assert medium1 == medium2

    # Load from datadir

    medium3 = batoid.TableMedium.fromTxt("silica_dispersion.txt")