示例#1
0
def test_angular_array_conversion():
    """
    Test AngularConversion of AngularArray with regular values.

    Conversion of [q in 1/nm] to [u in 'None'].
    """
    spec_pnt_sys = SpectralPoint(
        quantity="wavelength", unit="nm", value=525.)
    ang_array_user = AngularArray(
        quantity="q", unit="1/nm", dataarray=np.linspace(0., 0.024, 11))
    ang_conv = AngularConverter(ang_array_user, spec_pnt_sys)
    ang_array_sys = ang_conv.u_to_s(ang_array_user)
    aa_sys_expected = np.array([0., 0.20053523, 0.40107046, 0.60160568,
                                0.80214091, 1.00267614, 1.20321137,
                                1.4037466, 1.60428183, 1.80481705,
                                2.00535228])
    assert_allclose(
        ang_array_sys.data, aa_sys_expected, rtol=2e-07, atol=1e-16)
    assert_equal(ang_array_sys.quantity, "u")
    assert_equal(ang_array_sys.unit, "None")

    # reverse the conversion
    ang_array_us2 = ang_conv.s_to_u(ang_array_sys)
    assert_allclose(
        ang_array_us2.data, ang_array_user.data, rtol=2e-07, atol=1e-16)
    assert_equal(ang_array_us2.quantity, "q")
    assert_equal(ang_array_us2.unit, "1/nm")
示例#2
0
def test_angular_range_conversion():
    """
    Test AngularConversion of AngularRange with regular values.

    Conversion of [q in 1/nm] to [u in 'None']
    """
    spec_pnt_sys = SpectralPoint(
        quantity="wavelength", unit="nm", value=525.)
    ang_range_user = AngularRange(
        quantity="q", unit="1/nm", begin=0., end=0.012,
        sampling_points=100, scale="linear")
    ang_conv = AngularConverter(ang_range_user, spec_pnt_sys)
    ang_range_sys = ang_conv.u_to_s(ang_range_user)
    assert_equal(ang_range_sys.begin, 0.)
    assert_allclose(ang_range_sys.end, 1.00267614, rtol=2e-07, atol=1e-16)
    assert_equal(ang_range_sys.quantity, "u")
    assert_equal(ang_range_sys.unit, "None")
    assert_equal(ang_range_sys.sampling_points, 100)
    assert_equal(ang_range_sys.scale, "linear")

    # reverse the conversion
    ang_range_us2 = ang_conv.s_to_u(ang_range_sys)
    assert_allclose(
        ang_range_user.begin, ang_range_us2.begin, rtol=2e-07, atol=1e-16)
    assert_allclose(
        ang_range_user.end, ang_range_us2.end, rtol=2e-07, atol=1e-16)
    assert_equal(ang_range_us2.quantity, "q")
    assert_equal(ang_range_us2.unit, "1/nm")