Ejemplo n.º 1
0
def test_L2_Abs_angle():
    '''Test that that shadow area increases with angle.
    The comparison number was calculated by H. M. Guenther in response
    to Arcus DQ36.'''
    l2_dims = {'period': 0.966 * u.mm, 'bardepth': 0.5 * u.mm,
               'barwidth': 0.1 * u.mm}

    l2 = L2Abs(l2_dims=l2_dims)
    p1 = l2(generate_test_photons(1))

    l2 = L2Abs(l2_dims=l2_dims, orientation=euler2mat(np.deg2rad(1.8), 0, 0, 'szxy'))
    p2 = l2(generate_test_photons(1))

    assert np.isclose(p2['probability'][0] / p1['probability'][0], 0.979, rtol=1e-3)
Ejemplo n.º 2
0
def test_FlatStack():
    '''Run a stack of two elements and check that both are applied to the photons.'''
    fs = marxs.optics.FlatStack(
        position=[0, 5, 0],
        zoom=2,
        elements=[marxs.optics.EnergyFilter, marxs.optics.FlatDetector],
        keywords=[{
            'filterfunc': lambda x: 0.5
        }, {}])
    # Check all layers are at the same position
    assert np.allclose(fs.geometry['center'], np.array([0, 5, 0, 1]))
    assert np.allclose(fs.elements[0].geometry['center'],
                       np.array([0, 5, 0, 1]))
    assert np.allclose(fs.elements[1].geometry['center'],
                       np.array([0, 5, 0, 1]))
    assert np.allclose(fs.pos4d, fs.elements[1].pos4d)

    p = generate_test_photons(5)
    # Photons 0, 1 miss the stack
    p['pos'][:, 1] = [0, 1, 3.1, 4, 5]
    fs.loc_coos_name = ['a', 'b']
    p = fs(p)
    assert np.allclose(p['probability'], [1, 1, .5, .5, .5])
    assert np.all(np.isnan(p['a'][:2]))
    assert np.allclose(p['a'][2:], [-1.9, -1., 0])
Ejemplo n.º 3
0
def test_efficiency_table_in_use():
    '''Use table in a optical element'''
    efftab = InterpolateEfficiencyTable(get_pkg_data_filename('grating_efficiency.csv'), k=2)
    cat = CATGrating(order_selector=efftab, d=0.001)
    photons = generate_test_photons(500)
    photons = cat(photons)
    assert np.isclose((photons['order']==0).sum(), len(photons) / 2, rtol=.05)
Ejemplo n.º 4
0
def test_L2_Abs_angle():
    '''Test that that shadow area increases with angle.
    The comparison number was calculated by H. M. Guenther in response
    to Arcus DQ36.'''
    l2_dims = {'period': 0.966 * u.mm, 'bardepth': 0.5 * u.mm,
               'barwidth': 0.1 * u.mm}

    l2 = catgrating.L2Abs(l2_dims=l2_dims)
    p1 = l2(generate_test_photons(1))

    l2 = catgrating.L2Abs(l2_dims=l2_dims,
                          orientation=euler2mat(np.deg2rad(1.8), 0, 0, 'szxy'))
    p2 = l2(generate_test_photons(1))

    assert np.isclose(p2['probability'][0] / p1['probability'][0], 0.979,
                      rtol=1e-3)
Ejemplo n.º 5
0
def test_L2_Abs():
    '''Check L2 absorption against numbers calculated by Ralf Heilmann.'''
    photons = generate_test_photons(1)
    l2 = L2Abs(l2_dims={'period': 0.966 * u.mm, 'bardepth': 0.5 * u.mm,
                        'barwidth': 0.1 * u.mm})
    photons = l2(photons)
    assert np.isclose(photons['probability'], 0.81, rtol=0.02)
Ejemplo n.º 6
0
def test_scalingSitransparancy():
    '''The module has data for 1 mu Si and scales that to the depth of the
    grating. Test against known-good coefficient from CXRO.'''
    photons = generate_test_photons(1)
    cat = L1(order_selector=OrderSelector([-5]), relativearea=0.,
             depth=4*u.mu, d=0.00001)
    photons = cat(photons)
    assert np.isclose(photons['probability'][0], 0.22458, rtol=1e-4)
Ejemplo n.º 7
0
def test_L2_Abs():
    '''Check L2 absorption against numbers calculated by Ralf Heilmann.'''
    photons = generate_test_photons(1)
    l2 = catgrating.L2Abs(l2_dims={'period': 0.966 * u.mm,
                                   'bardepth': 0.5 * u.mm,
                                   'barwidth': 0.1 * u.mm})
    photons = l2(photons)
    assert np.isclose(photons['probability'], 0.81, rtol=0.02)
Ejemplo n.º 8
0
def test_efficiency_table_in_use():
    '''Use table in a optical element'''
    efftab = catgrating.InterpolateEfficiencyTable(get_pkg_data_filename('grating_efficiency.csv'), k=2)
    cat = CATGrating(order_selector=efftab, d=0.001)
    photons = generate_test_photons(5000)
    photons = cat(photons)
    assert np.isclose((photons['order'] == 0).sum(), len(photons) / 2,
                      rtol=.05)
Ejemplo n.º 9
0
def test_catsupportbars():
    photons = generate_test_photons(5)
    p = catgrating.catsupportbars(photons.copy())
    assert np.all(p['probability'] == 0)

    photons['facet'] = np.arange(-1, 4)
    p = catgrating.catsupportbars(photons)
    assert np.all(p['probability'][1:] == 1)
    assert p['probability'][0] == 0
Ejemplo n.º 10
0
def test_scalingSitransparancy():
    '''The module has data for 1 mu Si and scales that to the depth of the
    grating. Test against known-good coefficient from CXRO.'''
    photons = generate_test_photons(100)
    cat = catgrating.L1(order_selector=OrderSelector([-5]),
                        l1_dims={'bardepth': 0.004 * u.mm,
                                 'period': 0.0001 * u.mm,
                                 'barwidth': 0.00009 * u.mm})
    photons = cat(photons)
    assert np.isclose(np.median(photons['probability']), 0.22458, rtol=1e-4)
Ejemplo n.º 11
0
def test_nonparallelCATGrating_simplifies_to_CATGrating():
    '''With all randomness parameters set to 0, the results
    should match a CAT grating exactly.'''
    photons = generate_test_photons(50)
    # Mix the photons up a little
    scat = RandomGaussianScatter(scatter=0.01)
    photons = scat(photons)
    order_selector = OrderSelector([2])
    cat = CATGrating(order_selector=order_selector, d=0.001)
    npcat = NonParallelCATGrating(order_selector=order_selector, d=0.001)
    p1 = cat(photons.copy())
    p2 = npcat(photons)
    assert np.all(p1['dir'] == p2['dir'])
Ejemplo n.º 12
0
def test_nonparallelCATGrating_simplifies_to_CATGrating():
    '''With all randomness parameters set to 0, the results
    should match a CAT grating exactly.'''
    photons = generate_test_photons(50)
    # Mix the photons up a little
    scat = RandomGaussianScatter(scatter=0.01 * u.rad)
    photons = scat(photons)
    order_selector = OrderSelector([2])
    cat = CATGrating(order_selector=order_selector, d=0.001)
    npcat = catgrating.NonParallelCATGrating(order_selector=order_selector,
                                             d=0.001)
    p1 = cat(photons.copy())
    p2 = npcat(photons)
    assert np.all(p1['dir'] == p2['dir'])
Ejemplo n.º 13
0
def test_L2_broadening():
    '''Compare calculated L2 broadening with the values calculated
    by Ralf Heilmann. Both calculation make simplications (e.g. assuming
    a circular hole), but should give the right order of magnitude for
    diffraction.'''
    photons = generate_test_photons(1000)
    photons['energy'] = 0.25  # 50 Ang
    l2 = L2Diffraction(l2_dims={'period': 0.966 * u.mm,
                                'barwidth': 0.1 * u.mm})
    photons = l2(photons)
    det = FlatDetector(position=[-1, 0, 0])
    photons = det(photons)
    sigma = np.std(photons['det_x'])
    # for small angles tan(alpha) = alpha
    # 1 arcsec = 4.8...e-6 rad
    # 0.5 is sigma calculated by Ralf Heilmann for a rectangular
    # aperture
    assert np.isclose(sigma, .5 * 4.8e-6, rtol=.5)
Ejemplo n.º 14
0
def test_L2_broadening():
    '''Compare calculated L2 broadening with the values calculated
    by Ralf Heilmann. Both calculation make simplications (e.g. assuming
    a circular hole), but should give the right order of magnitude for
    diffraction.'''
    photons = generate_test_photons(1000)
    photons['energy'] = 0.25  # 50 Ang
    l2 = catgrating.L2Diffraction(l2_dims={'period': 0.966 * u.mm,
                                           'barwidth': 0.1 * u.mm})
    photons = l2(photons)
    det = FlatDetector(position=[-1, 0, 0])
    photons = det(photons)
    sigma = np.std(photons['det_x'])
    # for small angles tan(alpha) = alpha
    # 1 arcsec = 4.8...e-6 rad
    # 0.5 is sigma calculated by Ralf Heilmann for a rectangular
    # aperture
    assert np.isclose(sigma, .5 * 4.8e-6, rtol=.5)
Ejemplo n.º 15
0
def test_FlatStack():
    '''Run a stack of two elements and check that both are applied to the photons.'''
    fs = marxs.optics.FlatStack(position=[0, 5, 0], zoom=2,
                                sequence=[marxs.optics.EnergyFilter, marxs.optics.FlatDetector],
                                keywords=[{'filterfunc': lambda x: 0.5},{}])
    # Check all layers are at the same position
    assert np.allclose(fs.geometry['center'], np.array([0, 5, 0, 1]))
    assert np.allclose(fs.sequence[0].geometry['center'], np.array([0, 5, 0, 1]))
    assert np.allclose(fs.sequence[1].geometry['center'], np.array([0, 5, 0, 1]))
    assert np.allclose(fs.pos4d, fs.sequence[1].pos4d)

    p = generate_test_photons(5)
    # Photons 0, 1 miss the stack
    p['pos'][:, 1] = [0, 1, 3.1, 4, 5]
    fs.loc_coos_name = ['a', 'b']
    p = fs(p)
    assert np.allclose(p['probability'], [1, 1, .5, .5, .5])
    assert np.all(np.isnan(p['a'][:2]))
    assert np.allclose(p['a'][2:], [-1.9, -1., 0])