Beispiel #1
0
def test_SellmeierMedium():
    rng = np.random.default_rng(57)
    # Silica coefficients
    # https://refractiveindex.info/?shelf=main&book=SiO2&page=Malitson
    B1 = 0.6961663
    B2 = 0.4079426
    B3 = 0.8974794
    C1 = 0.00467914825849
    C2 = 0.013512063073959999
    C3 = 97.93400253792099
    silica = batoid.SellmeierMedium([B1, B2, B3, C1, C2, C3])
    silica2 = batoid.SellmeierMedium(B1, B2, B3, C1, C2, C3)
    silica3 = batoid.SellmeierMedium(C1=C1, C2=C2, C3=C3, B1=B1, B2=B2, B3=B3)
    assert silica == silica2
    assert silica == silica3
    with np.testing.assert_raises(TypeError):
        batoid.SellmeierMedium(B1)
    with np.testing.assert_raises(ValueError):
        batoid.SellmeierMedium(B1, B2, B3, C1, C2, C3, B1)

    wavelengths = rng.uniform(300e-9, 1100e-9, size=1000)
    indices = silica.getN(wavelengths)
    for w, index in zip(wavelengths, indices):
        assert silica.getN(w) == index

    # CSV also from refractiveindex.info
    filename = os.path.join(os.path.dirname(__file__), "testdata",
                            "silicaDispersion.csv")
    wmicron, ncsv = np.loadtxt(filename, delimiter=',').T
    n = silica.getN(wmicron * 1e-6)
    np.testing.assert_allclose(n, ncsv, atol=0, rtol=1e-13)
    do_pickle(silica)
Beispiel #2
0
def test_ne():
    objs = [
        batoid.ConstMedium(1.0),
        batoid.ConstMedium(1.1),
        batoid.TableMedium([1, 2, 3], [3, 4, 3]),
        batoid.SellmeierMedium([
            0.6961663, 0.4079426, 0.8974794, 0.0684043**2, 0.1162414**2,
            9.896161**2
        ]),
        batoid.SellmeierMedium([
            0.4079426, 0.6961663, 0.8974794, 0.0684043**2, 0.1162414**2,
            9.896161**2
        ]),
        batoid.SumitaMedium([
            2.2705778, -0.010059376, 0.010414999, 0.00028872517, -2.2214495e-5,
            1.4258559e-6
        ]),
        batoid.SumitaMedium([
            -0.010059376, 2.2705778, 0.010414999, 0.00028872517, -2.2214495e-5,
            1.4258559e-6
        ]),
        batoid.Air(),
        batoid.Air(pressure=100)
    ]
    all_obj_diff(objs)
Beispiel #3
0
def test_silica_sellmeier_table():
    import random
    import time
    random.seed(577)

    # File from phosim
    filename = os.path.join(batoid.datadir, "media", "silica_dispersion.txt")
    wave, n = np.genfromtxt(filename).T
    wave *= 1e-6  # microns -> meters
    table = batoid.Table(wave, n, batoid.Table.Interpolant.linear)
    table_silica = batoid.TableMedium(table)

    # Coefficients from
    # https://refractiveindex.info/?shelf=main&book=SiO2&page=Malitson
    sellmeier_silica = batoid.SellmeierMedium(0.6961663, 0.4079426, 0.8974794,
                                              0.0684043**2, 0.1162414**2,
                                              9.896161**2)

    # Making this a timing test too for fun
    ws = []
    for i in range(100000):
        ws.append(random.uniform(0.3e-6, 1.2e-6))
    table_n = []
    sellmeier_n = []
    t0 = time.time()
    for w in ws:
        table_n.append(table_silica.getN(w))
    t1 = time.time()
    for w in ws:
        sellmeier_n.append(sellmeier_silica.getN(w))
    t2 = time.time()
    print("TableMedium took {} s".format(t1 - t0))
    print("SellmeierMedium took {} s".format(t2 - t1))
    np.testing.assert_allclose(table_n, sellmeier_n, atol=1e-6, rtol=0)
    do_pickle(sellmeier_silica)
Beispiel #4
0
def parse_medium(value):
    from numbers import Real
    if isinstance(value, batoid.Medium):
        return value
    elif isinstance(value, Real):
        return batoid.ConstMedium(value)
    elif isinstance(value, str):
        if value == 'air':
            return batoid.Air()
        elif value == 'silica':
            return batoid.SellmeierMedium(0.6961663, 0.4079426, 0.8974794,
                                          0.0684043**2, 0.1162414**2,
                                          9.896161**2)
        elif value == 'hsc_air':
            return batoid.ConstMedium(1.0)
        w = [0.4, 0.6, 0.75, 0.9, 1.1]
        w = [w_ * 1e-6 for w_ in w]
        if value == 'hsc_silica':
            return batoid.TableMedium(
                batoid.Table(w, [
                    1.47009272, 1.45801158, 1.45421013, 1.45172729, 1.44917721
                ], batoid.Table.Interpolant.linear))
        elif value == 'hsc_bsl7y':
            return batoid.TableMedium(
                batoid.Table(w, [
                    1.53123287, 1.51671428, 1.51225242, 1.50939738, 1.50653251
                ], batoid.Table.Interpolant.linear))
        elif value == 'hsc_pbl1y':
            return batoid.TableMedium(
                batoid.Table(w, [
                    1.57046066, 1.54784671, 1.54157395, 1.53789058, 1.53457169
                ], batoid.Table.Interpolant.linear))
        elif value == 'NLAK10':
            return batoid.SellmeierMedium(1.72878017, 0.169257825, 1.19386956,
                                          0.00886014635, 0.0363416509,
                                          82.9009069)
        elif value == 'PFK85':
            return batoid.SumitaMedium(2.1858326, -0.0050155632, 0.0075107775,
                                       0.00017770562, -1.2164148e-05,
                                       6.1341005e-07)
        elif value == 'BK7':
            return batoid.SellmeierMedium(1.03961212, 0.231792344, 1.01046945,
                                          0.00600069867, 0.0200179144,
                                          103.560653)
        else:
            raise RuntimeError("Unknown medium {}".format(value))
Beispiel #5
0
def test_ne():
    filename = os.path.join(batoid.datadir, "media", "silica_dispersion.txt")
    wave, n = np.genfromtxt(filename).T
    wave *= 1e-6  # microns -> meters
    table = batoid.Table(wave, n, batoid.Table.Interpolant.linear)
    table2 = batoid.Table(wave * 1.01, n, batoid.Table.Interpolant.linear)

    objs = [
        batoid.ConstMedium(1.0),
        batoid.ConstMedium(1.1),
        batoid.TableMedium(table),
        batoid.TableMedium(table2),
        batoid.SellmeierMedium(0.6961663, 0.4079426, 0.8974794, 0.0684043**2,
                               0.1162414**2, 9.896161**2),
        batoid.SellmeierMedium(0.4079426, 0.6961663, 0.8974794, 0.0684043**2,
                               0.1162414**2, 9.896161**2),
        batoid.Air(),
        batoid.Air(pressure=100)
    ]
    all_obj_diff(objs)
Beispiel #6
0
def parse_medium(value):
    from numbers import Real
    if isinstance(value, batoid.Medium):
        return value
    elif isinstance(value, Real):
        return batoid.ConstMedium(value)
    elif isinstance(value, str):
        if value == 'air':
            return batoid.Air()
        elif value == 'silica':
            return batoid.SellmeierMedium(0.6961663, 0.4079426, 0.8974794,
                                          0.0684043**2, 0.1162414**2,
                                          9.896161**2)
        elif value == 'hsc_air':
            return batoid.ConstMedium(1.0)
        w = [0.4, 0.6, 0.75, 0.9, 1.1]
        w = [w_ * 1e-6 for w_ in w]
        w_desi = [
            365.015, 435.835, 486.133, 587.562, 656.273, 852.110, 1013.98
        ]
        w_desi = [w_ * 1e-9 for w_ in w_desi]
        if value == 'hsc_silica':
            return batoid.TableMedium(
                batoid.Table(w, [
                    1.47009272, 1.45801158, 1.45421013, 1.45172729, 1.44917721
                ], batoid.Table.Interpolant.linear))
        elif value == 'hsc_bsl7y':
            return batoid.TableMedium(
                batoid.Table(w, [
                    1.53123287, 1.51671428, 1.51225242, 1.50939738, 1.50653251
                ], batoid.Table.Interpolant.linear))
        elif value == 'hsc_pbl1y':
            return batoid.TableMedium(
                batoid.Table(w, [
                    1.57046066, 1.54784671, 1.54157395, 1.53789058, 1.53457169
                ], batoid.Table.Interpolant.linear))
        elif value == 'desi_C1':
            # Use melt data from DESI-2880-v2
            return batoid.TableMedium(
                batoid.Table(w_desi, [
                    1.474580, 1.466730, 1.463162, 1.458499, 1.456402, 1.452500,
                    1.450278
                ], batoid.Table.Interpolant.linear))
        elif value == 'desi_C2':
            # Use melt data from DESI-2880-v2
            return batoid.TableMedium(
                batoid.Table(w_desi, [
                    1.474641, 1.466791, 1.463223, 1.458561, 1.45646, 1.452563,
                    1.450342
                ], batoid.Table.Interpolant.linear))
        elif value == 'desi_ADC1':
            # Use melt data from DESI-2880-v2
            return batoid.TableMedium(
                batoid.Table(w_desi, [
                    1.536945, 1.527374, 1.523070, 1.517498, 1.515022, 1.510508,
                    1.508023
                ], batoid.Table.Interpolant.linear))
        elif value == 'desi_ADC2':
            # Use melt data from DESI-2880-v2
            return batoid.TableMedium(
                batoid.Table(w_desi, [
                    1.536225, 1.526635, 1.522325, 1.516746, 1.514267, 1.509743,
                    1.507246
                ], batoid.Table.Interpolant.linear))
        elif value == 'desi_C3':
            # Use generic fused silica until melt data is available.
            return batoid.TableMedium(
                batoid.Table(w_desi, [
                    1.474555, 1.466701, 1.463132, 1.458467, 1.45637, 1.452469,
                    1.450245
                ], batoid.Table.Interpolant.linear))
        elif value == 'desi_C4':
            # Use generic fused silica until melt data is available.
            return batoid.TableMedium(
                batoid.Table(w_desi, [
                    1.474555, 1.466701, 1.463132, 1.458467, 1.45637, 1.452469,
                    1.450245
                ], batoid.Table.Interpolant.linear))
        elif value == 'NLAK10':
            return batoid.SellmeierMedium(1.72878017, 0.169257825, 1.19386956,
                                          0.00886014635, 0.0363416509,
                                          82.9009069)
        elif value == 'PFK85':
            return batoid.SumitaMedium(2.1858326, -0.0050155632, 0.0075107775,
                                       0.00017770562, -1.2164148e-05,
                                       6.1341005e-07)
        elif value == 'BK7':
            return batoid.SellmeierMedium(1.03961212, 0.231792344, 1.01046945,
                                          0.00600069867, 0.0200179144,
                                          103.560653)
        else:
            raise RuntimeError("Unknown medium {}".format(value))