Exemplo n.º 1
0
def test_calc_res_cases():
    """Test calculation of various cases
    """

    instr = instrument.Instrument(instrument_type="tof")
    instr.detector.shape = "spherical"
    instr.calc_resolution([1, 0, 0, 0])

    instr = instrument.Instrument(instrument_type="tof")
    instr.calc_resolution([1, 0, 0, 0])
Exemplo n.º 2
0
def test_calc_res_cases():
    """Test different resolution cases
    """
    EXP = instrument.Instrument()
    EXP.sample.shape = np.eye(3)
    EXP.calc_resolution([1, 0, 0, 0])

    EXP.sample.shape = np.eye(3)[np.newaxis].reshape((1, 3, 3))
    EXP.calc_resolution([1, 0, 0, 0])

    EXP.horifoc = 1
    EXP.calc_resolution([1, 0, 0, 0])

    EXP.moncor = 1
    EXP.calc_resolution([1, 0, 0, 0])

    EXP.method = 1
    EXP.calc_resolution([1, 0, 0, 0])

    EXP.ana.thickness = 1
    EXP.ana.Q = 1.5
    EXP.calc_resolution([1, 0, 0, 0])

    EXP.Smooth = instrument.tools._Dummy('Smooth')
    EXP.Smooth.X = 1
    EXP.Smooth.Y = 1
    EXP.Smooth.Z = 1
    EXP.Smooth.E = 1
    EXP.calc_resolution([1, 0, 0, 0])
Exemplo n.º 3
0
def test_sma_conv():
    """Test SMA convolution
    """
    sample = Sample(6, 7, 8, 90, 90, 90)
    sample.u = [1, 0, 0]
    sample.v = [0, 0, 1]
    EXP = instrument.Instrument(14.7,
                                sample,
                                hcol=[80, 40, 40, 80],
                                vcol=[120, 120, 120, 120],
                                mono='pg(002)',
                                ana='pg(002)')
    EXP.moncor = 0

    p = np.array([3, 3, 3, 30, 0.4, 6e4, 40])
    H1, K1, L1, W1 = 1.5, 0, 0.35, np.arange(20, -0.5, -0.5)

    I14 = EXP.resolution_convolution_SMA(SMADemo, PrefDemo, 2,
                                         (H1, K1, L1, W1), 'fix', [15, 0], p)
    I15 = EXP.resolution_convolution_SMA(SMADemo, PrefDemo, 2,
                                         (H1, K1, L1, W1), 'mc', [1], p, 13)

    sumI14, sumI15 = np.sum(I14), np.sum(I15)

    assert (np.abs(sumIavg - sumI14) < sumIstd)
    assert (np.abs(sumIavg - sumI15) < sumIstd)

    EXP.resolution_convolution_SMA(SMADemo, PrefDemo2, 1, (H1, K1, L1, W1),
                                   'fix', None, p)
    with pytest.raises(ValueError):
        EXP.resolution_convolution_SMA(SMADemo, PrefDemo3, 0, (H1, K1, L1, W1),
                                       'fix', None, p)
Exemplo n.º 4
0
def test_projection_calc():
    """Test different cases of resolution ellipse slices/projections
    """
    EXP = instrument.Instrument()
    EXP.calc_resolution([1, 0, 0, 0])
    EXP.calc_projections([0, 1, 0, 0])
    EXP.get_resolution_params([0, 1, 0, 0], 'QxQy', 'slice')
    with pytest.raises(InstrumentError):
        EXP.get_resolution_params([1, 1, 0, 0], 'QxQy', 'slice')

    EXP = instrument.Instrument()
    EXP.get_resolution_params([1, 0, 0, 0], 'QxQy', 'slice')
    EXP.get_resolution_params([1, 0, 0, 0], 'QxQy', 'project')
    EXP.get_resolution_params([1, 0, 0, 0], 'QxW', 'slice')
    EXP.get_resolution_params([1, 0, 0, 0], 'QxW', 'project')
    EXP.get_resolution_params([1, 0, 0, 0], 'QyW', 'slice')
    EXP.get_resolution_params([1, 0, 0, 0], 'QyW', 'project')
Exemplo n.º 5
0
def test_errors():
    """Test exception handling
    """
    EXP = instrument.Instrument()
    EXP.sample.u = [1, 0, 0]
    EXP.sample.v = [2, 0, 0]
    with pytest.raises(ScatteringTriangleError):
        EXP.calc_resolution([1, 1, 0, 0])
Exemplo n.º 6
0
def test_calc_res_multi_point():
    """Tests calculation of cases with multiple point in `hkle`
    """

    instr = instrument.Instrument(instrument_type="tof")
    instr.calc_resolution([1, [0, 1, 1], 0, [0, 1, 2]])

    assert (instr.R0.size == 3)
    print(instr.RM.shape)
    assert (np.all(instr.RM.shape == (3, 4, 4)))
    assert (np.all(instr.RMS.shape == (3, 4, 4)))
Exemplo n.º 7
0
def gen_std_instr():
    """Generates a known instrument
    """
    instr = instrument.Instrument(instrument_type="tof")

    instr.l_pm = 1567
    instr.l_ms = 150
    instr.l_sd = 350

    instr.theta_i = 0.
    instr.phi_i = 0.

    instr.sigma_l_pm = 12.5
    instr.sigma_l_ms = 2.
    instr.sigma_l_sd = 0.75

    instr.sigma_theta_i = .459
    instr.sigma_theta = .1
    instr.sigma_phi_i = .688
    instr.sigma_phi = .2

    instr.tau_p = 66.59
    instr.tau_m = 16.65
    instr.tau_d = .1

    instr.detector.shape = "cylindrical"
    instr.detector.orientation = "vertical"

    instr.sample.a = 5
    instr.sample.b = 5
    instr.sample.c = 5
    instr.sample.u = [1, 0, 0]
    instr.sample.v = [0, 1, 0]

    instr.ei.wavevector = 1.13333333

    return instr
Exemplo n.º 8
0
def test_plotting(mock_show):
    """Test Plotting methods
    """
    EXP = instrument.Instrument()

    EXP.plot_instrument([1, 0, 0, 0])
    EXP.plot_projections([1, 0, 0, 0])
    EXP.calc_projections([[1, 2], 0, 0, 0])
    EXP.plot_projections([[1, 2], 0, 0, 0])

    EXP.guide.width = 1
    EXP.guide.height = 1
    EXP.mono.width = 1
    EXP.mono.height = 1
    EXP.sample.width = 1
    EXP.sample.height = 1
    EXP.sample.depth = 1
    EXP.ana.width = 1
    EXP.ana.height = 1
    EXP.detector.width = 1
    EXP.detector.height = 1
    EXP.arms = [10, 10, 10, 10]

    EXP.plot_instrument([1, 0, 0, 0])
Exemplo n.º 9
0

def PrefDemo3(H, K, L, W, EXP, p):
    r"""Prefactor example for convolution tests

    No prefactor

    """

    return


sumIavg = 1646.8109875866667
sumIstd = 0.67288676280070814 * 2

instr = instrument.Instrument(test=1)

instr.method = 0
instr.mono.tau = 'PG(002)'
instr.mono.mosaic = 25
instr.ana.tau = 'PG(002)'
instr.ana.mosaic = 25
instr.sample.a = 6
instr.sample.b = 7
instr.sample.c = 8
instr.sample.alpha = 90
instr.sample.beta = 90
instr.sample.gamma = 90
instr.hcol = [40, 40, 40, 40]
instr.vcol = [120, 120, 120, 120]
instr.efixed = 14.7