Example #1
0
def test_coordset_set(coord0, coord1, coord2):
    coords = CoordSet(coord2, [coord0, coord0.copy()], coord1)
    assert str(coords) == repr(
        coords
    ) == 'CoordSet: [x:time-on-stream, y:[_1:wavenumber, _2:wavenumber], z:temperature]'

    coords.set_titles('time', 'dddd', 'celcius')
    assert str(
        coords
    ) == 'CoordSet: [x:time, y:[_1:wavenumber, _2:wavenumber], z:celcius]'

    coords.set_titles(x='time', z='celcius', y_1='length')
    assert str(coords) == repr(
        coords
    ) == 'CoordSet: [x:time, y:[_1:length, _2:wavenumber], z:celcius]'

    coords.set_titles('t', ('l', 'g'), x='x')
    assert str(coords) == 'CoordSet: [x:x, y:[_1:l, _2:g], z:celcius]'

    coords.set_titles(('t', ('l', 'g')), z='z')
    assert str(coords) == 'CoordSet: [x:t, y:[_1:l, _2:g], z:z]'

    coords.set_titles()  # nothing happens
    assert str(coords) == 'CoordSet: [x:t, y:[_1:l, _2:g], z:z]'

    with pytest.raises(DimensionalityError):  # because units doesn't match
        coords.set_units(('km/s', ('s', 'm')), z='radian')

    coords.set_units(('km/s', ('s', 'm')), z='radian',
                     force=True)  # force change
    assert str(coords) == 'CoordSet: [x:t, y:[_1:l, _2:wavelength], z:z]'
    assert coords.y_1.units == ur('s')

    # set item

    coords['z'] = coord2
    assert str(
        coords) == 'CoordSet: [x:t, y:[_1:l, _2:wavelength], z:temperature]'

    coords['temperature'] = coord1
    assert str(
        coords) == 'CoordSet: [x:t, y:[_1:l, _2:wavelength], z:time-on-stream]'

    coords['y_2'] = coord2
    assert str(
        coords
    ) == 'CoordSet: [x:t, y:[_1:l, _2:temperature], z:time-on-stream]'

    coords['_1'] = coord2
    assert str(
        coords
    ) == 'CoordSet: [x:t, y:[_1:temperature, _2:temperature], z:time-on-stream]'

    coords['t'] = coord2
    assert str(
        coords
    ) == 'CoordSet: [x:temperature, y:[_1:temperature, _2:temperature], z:time-on-stream]'

    coord2.title = 'zaza'
    coords['temperature'] = coord2
    assert str(
        coords
    ) == 'CoordSet: [x:zaza, y:[_1:temperature, _2:temperature], z:time-on-stream]'

    coords['temperature'] = coord2
    assert str(
        coords
    ) == 'CoordSet: [x:zaza, y:[_1:zaza, _2:temperature], z:time-on-stream]'

    coords.set(coord1, coord0, coord2)
    assert str(coords) == 'CoordSet: [x:zaza, y:wavenumber, z:time-on-stream]'

    coords.z = coord0
    assert str(coords) == 'CoordSet: [x:zaza, y:wavenumber, z:wavenumber]'

    coords.zaza = coord0
    assert str(
        coords) == 'CoordSet: [x:wavenumber, y:wavenumber, z:wavenumber]'

    coords.wavenumber = coord2
    assert str(coords) == 'CoordSet: [x:zaza, y:wavenumber, z:wavenumber]'
Example #2
0
def test_coordset_set(coord0, coord1, coord2):
    coords = CoordSet(coord2, [coord0, coord0.copy()], coord1)
    assert (
        str(coords) == repr(coords) ==
        "CoordSet: [x:time-on-stream, y:[_1:wavenumber, _2:wavenumber], z:temperature]"
    )

    coords.set_titles("time", "dddd", "celsius")
    assert (str(coords) ==
            "CoordSet: [x:time, y:[_1:wavenumber, _2:wavenumber], z:celsius]")

    coords.set_titles(x="time", z="celsius", y_1="length")
    assert (str(coords) == repr(coords) ==
            "CoordSet: [x:time, y:[_1:length, _2:wavenumber], z:celsius]")

    coords.set_titles("t", ("l", "g"), x="x")
    assert str(coords) == "CoordSet: [x:x, y:[_1:l, _2:g], z:celsius]"

    coords.set_titles(("t", ("l", "g")), z="z")
    assert str(coords) == "CoordSet: [x:t, y:[_1:l, _2:g], z:z]"

    coords.set_titles()  # nothing happens
    assert str(coords) == "CoordSet: [x:t, y:[_1:l, _2:g], z:z]"

    with pytest.raises(DimensionalityError):  # because units doesn't match
        coords.set_units(("km/s", ("s", "m")), z="radian")

    coords.set_units(("km/s", ("s", "m")), z="radian",
                     force=True)  # force change
    assert str(coords) == "CoordSet: [x:t, y:[_1:l, _2:wavelength], z:z]"
    assert coords.y_1.units == ur("s")

    # set item

    coords["z"] = coord2
    assert str(
        coords) == "CoordSet: [x:t, y:[_1:l, _2:wavelength], z:temperature]"

    coords["temperature"] = coord1
    assert str(
        coords) == "CoordSet: [x:t, y:[_1:l, _2:wavelength], z:time-on-stream]"

    coords["y_2"] = coord2
    assert str(
        coords
    ) == "CoordSet: [x:t, y:[_1:l, _2:temperature], z:time-on-stream]"

    coords["_1"] = coord2
    assert (
        str(coords) ==
        "CoordSet: [x:t, y:[_1:temperature, _2:temperature], z:time-on-stream]"
    )

    coords["t"] = coord2
    assert (
        str(coords) ==
        "CoordSet: [x:temperature, y:[_1:temperature, _2:temperature], z:time-on-stream]"
    )

    coord2.title = "zaza"
    coords["temperature"] = coord2
    assert (
        str(coords) ==
        "CoordSet: [x:zaza, y:[_1:temperature, _2:temperature], z:time-on-stream]"
    )

    coords["temperature"] = coord2
    assert (
        str(coords) ==
        "CoordSet: [x:zaza, y:[_1:zaza, _2:temperature], z:time-on-stream]")

    coords.set(coord1, coord0, coord2)
    assert str(coords) == "CoordSet: [x:zaza, y:wavenumber, z:time-on-stream]"

    coords.z = coord0
    assert str(coords) == "CoordSet: [x:zaza, y:wavenumber, z:wavenumber]"

    coords.zaza = coord0
    assert str(
        coords) == "CoordSet: [x:wavenumber, y:wavenumber, z:wavenumber]"

    coords.wavenumber = coord2
    assert str(coords) == "CoordSet: [x:zaza, y:wavenumber, z:wavenumber]"