Beispiel #1
0
def test_pp_conversion_to_physics_3_points():
    pchip_uc = PchipUnitConv([1, 3, 5], [1, 3, 6])
    assert pchip_uc.eng_to_phys(1) == 1
    assert numpy.round(pchip_uc.eng_to_phys(2), 4) == 1.8875
    assert pchip_uc.eng_to_phys(3) == 3
    assert numpy.round(pchip_uc.eng_to_phys(4), 4) == 4.3625
    assert pchip_uc.eng_to_phys(5) == 6
Beispiel #2
0
def test_pp_conversion_to_physics_3_points():
    pchip_uc = PchipUnitConv([1, 3, 5], [1, 3, 6])
    assert pchip_uc.eng_to_phys(1) == 1
    assert np.round(pchip_uc.eng_to_phys(2), 4) == 1.8875
    assert pchip_uc.eng_to_phys(3) == 3
    assert np.round(pchip_uc.eng_to_phys(4), 4) == 4.3625
    assert pchip_uc.eng_to_phys(5) == 6
Beispiel #3
0
def load_pchip_unitconv(filepath: Path) -> Dict[int, PchipUnitConv]:
    """Load pchip unit conversions from a csv file.

    Args:
        filename: The file from which to load.

    Returns:
        dict: A dictionary of the unit conversions.
    """
    unitconvs: Dict[int, PchipUnitConv] = {}
    data = collections.defaultdict(list)
    with csv_loader(filepath) as csv_reader:
        for item in csv_reader:
            data[(int(item["uc_id"]))].append(
                (float(item["eng"]), float(item["phy"])))
    # Create PchipUnitConv for each item and put in the dict
    for uc_id in data:
        eng = [x[0] for x in sorted(data[uc_id])]
        phy = [x[1] for x in sorted(data[uc_id])]
        u = PchipUnitConv(eng, phy, name=uc_id)
        unitconvs[uc_id] = u
    return unitconvs
Beispiel #4
0
def test_PchipUnitConv_with_additional_function():
    pchip_uc = PchipUnitConv([2, 4], [2, 4], f1, f2)
    assert pchip_uc.eng_to_phys(2) == 4.0
    assert pchip_uc.eng_to_phys(3) == 6.0
    assert pchip_uc.phys_to_eng(4.0) == 2
    assert pchip_uc.phys_to_eng(6.0) == 3
Beispiel #5
0
def test_pp_conversion_to_machine_2_points():
    pchip_uc = PchipUnitConv([1, 3], [1, 3])
    assert pchip_uc.phys_to_eng(1) == 1
    assert pchip_uc.phys_to_eng(1.5) == 1.5
Beispiel #6
0
def test_ppconversion_to_physics_2_points():
    pchip_uc = PchipUnitConv([1, 3], [1, 3])
    assert pchip_uc.eng_to_phys(1) == 1
    assert pchip_uc.eng_to_phys(2) == 2
    assert pchip_uc.eng_to_phys(3) == 3
Beispiel #7
0
def test_PchipUnitConv_with_additional_function():
    pchip_uc = PchipUnitConv([2, 4], [2, 4], f1, f2)
    assert pchip_uc.eng_to_phys(2) == 4.0
    assert pchip_uc.eng_to_phys(3) == 6.0
    assert pchip_uc.phys_to_eng(4.0) == 2
    assert pchip_uc.phys_to_eng(6.0) == 3
Beispiel #8
0
def test_PchipUnitConv_with_solution_outside_bounds_raises_UnitsException():
    # This is a linear relationship, but the root is 0, outside of the
    # range of measurements.
    pchip_uc = PchipUnitConv((1, 2, 3), (1, 2, 3))
    with pytest.raises(pytac.exceptions.UnitsException):
        pchip_uc.phys_to_eng(0)
Beispiel #9
0
def test_PchipInterpolator_raises_ValueError_if_y_not_monotonic():
    with pytest.raises(ValueError):
        PchipUnitConv([1, 2, 3], [1, 3, 2])
Beispiel #10
0
def test_PchipInterpolator_raises_ValueError_if_x_not_monotonically_increasing(
):
    with pytest.raises(ValueError):
        PchipUnitConv([1, 3, 2], [1, 2, 3])
    with pytest.raises(ValueError):
        PchipUnitConv([-1, -2, -3], [-1, -2, -3])
Beispiel #11
0
def test_pp_conversion_to_machine_2_points():
    pchip_uc = PchipUnitConv([1, 3], [1, 3])
    assert pchip_uc.phys_to_eng(1) == 1
    assert pchip_uc.phys_to_eng(1.5) == 1.5
Beispiel #12
0
def test_ppconversion_to_physics_2_points():
    pchip_uc = PchipUnitConv([1, 3], [1, 3])
    assert pchip_uc.eng_to_phys(1) == 1
    assert pchip_uc.eng_to_phys(2) == 2
    assert pchip_uc.eng_to_phys(3) == 3