Beispiel #1
0
def test_asdf_groove(groove: IsoBaseGroove, expected_dtype):
    """Test ASDF functionality for all grooves.

    Parameters
    ----------
    groove:
       Groove instance to be tested.

    expected_dtype:
       Expected type of the groove to be tested.

    """
    k = "groove"
    tree = {k: groove}

    data = _write_read_buffer(tree)
    assert isinstance(
        data[k], expected_dtype
    ), f"Did not match expected type {expected_dtype} on item {data[k]}"
    # test content equality using dataclass built-in functions
    assert (
        groove == data[k]
    ), f"Could not correctly reconstruct groove of type {type(groove)}"
    # test to_profile
    assert isinstance(
        groove.to_profile(), Profile
    ), f"Error calling plot function of {type(groove)} "

    # call plot function
    fig, ax = plt.subplots()
    groove.plot(ax=ax)
    plt.close(fig)
Beispiel #2
0
def test_xarray_dataset(copy_arrays, lazy_load):
    dsx = get_xarray_example_dataset()
    tree = {"dsx": dsx}
    dsx_file = _write_read_buffer(tree,
                                  open_kwargs={
                                      "copy_arrays": copy_arrays,
                                      "lazy_load": lazy_load
                                  })["dsx"]
    assert dsx.identical(dsx_file)
Beispiel #3
0
def test_unit_validator(test):
    data = _write_read_buffer({"root_node": test})
    test_read = data["root_node"]
    assert isinstance(data, dict)
    assert test_read.length_prop == test.length_prop
    assert test_read.velocity_prop == test.velocity_prop
    assert np.all(test_read.current_prop == test.current_prop)
    assert np.all(test_read.nested_prop["q1"] == test.nested_prop["q1"])
    assert test_read.nested_prop["q2"] == test.nested_prop["q2"]
    assert test_read.simple_prop == test.simple_prop
Beispiel #4
0
def test_xarray_data_array(copy_arrays, lazy_load):
    """Test ASDF read/write of xarray.DataArray."""
    dax = get_xarray_example_data_array()
    tree = {"dax": dax}
    dax_file = _write_read_buffer(tree,
                                  open_kwargs={
                                      "copy_arrays": copy_arrays,
                                      "lazy_load": lazy_load
                                  })["dax"]
    assert dax.identical(dax_file)
Beispiel #5
0
def test_coordinate_system_manager(copy_arrays, lazy_load):
    csm = get_example_coordinate_system_manager()
    tree = {"cs_hierarchy": csm}
    data = _write_read_buffer(tree,
                              open_kwargs={
                                  "copy_arrays": copy_arrays,
                                  "lazy_load": lazy_load
                              })
    csm_file = data["cs_hierarchy"]
    assert csm == csm_file
Beispiel #6
0
def test_local_coordinate_system(time_dep_orientation, time_dep_coordinates,
                                 copy_arrays, lazy_load):
    """Test (de)serialization of LocalCoordinateSystem in ASDF."""
    lcs = get_local_coordinate_system(time_dep_orientation,
                                      time_dep_coordinates)
    data = _write_read_buffer({"lcs": lcs},
                              open_kwargs={
                                  "copy_arrays": copy_arrays,
                                  "lazy_load": lazy_load
                              })
    assert data["lcs"] == lcs
Beispiel #7
0
def test_time_series_discrete(ts, copy_arrays, lazy_load):
    ts_file = _write_read_buffer({"ts": ts},
                                 open_kwargs={
                                     "copy_arrays": copy_arrays,
                                     "lazy_load": lazy_load
                                 })["ts"]
    if isinstance(ts.data, ME):
        assert ts.data == ts_file.data
    else:
        assert np.all(ts_file.data == ts.data)
    assert np.all(ts_file.time == ts.time)
    assert ts_file.interpolation == ts.interpolation
Beispiel #8
0
    def test_asdf_serialization(copy_arrays, lazy_load, store_content):
        """Test the asdf serialization of the `ExternalFile` class.

        Parameters
        ----------
        copy_arrays : bool
            If `False`, arrays are accessed via memory mapping whenever possible while
            reading them.
        lazy_load : bool
            If `True`, items from the asdf file are not loaded until accessed.
        store_content : bool
            If `True`, the file content is stored in the asdf file.

        """
        ef = ExternalFile(
            f"{weldx_root_dir}/doc/_static/WelDX_notext.ico",
            asdf_save_content=store_content,
        )
        tree = {"file": ef}
        ef_file = _write_read_buffer(tree,
                                     open_kwargs={
                                         "copy_arrays": copy_arrays,
                                         "lazy_load": lazy_load
                                     })["file"]

        assert ef.filename == ef_file.filename
        assert ef.suffix == ef_file.suffix
        assert ef.directory == ef_file.directory
        assert ef.hostname == ef_file.hostname

        assert ef.created == ef_file.created
        assert ef.modified == ef_file.modified
        assert ef.size == ef_file.size

        assert ef.hashing_algorithm == ef_file.hashing_algorithm

        if store_content:
            with OSFS(weldx_root_dir) as file_system:
                original_hash = file_system.hash(
                    "doc/_static/WelDX_notext.ico", "md5")

            with MemoryFS() as file_system:
                ef_file.write_to("", file_system)
                assert file_system.hash("WelDX_notext.ico",
                                        "md5") == original_hash
Beispiel #9
0
def test_meta_attr():
    e = Error(3.0)

    ts = pd.Timestamp("2020-01-01")
    setattr(ts, META_ATTR, {"name": "Timestamp"})

    setattr(e, META_ATTR, {"ts": ts})
    setattr(e, USER_ATTR, {"description": "user info"})

    tree = {"Error": e}

    data = _write_read_buffer(tree)

    e2 = data["Error"]

    assert e2 == e
    assert getattr(e2, META_ATTR) == getattr(e, META_ATTR)
    assert getattr(e2, USER_ATTR) == getattr(e, USER_ATTR)
    assert getattr(getattr(e2, META_ATTR)["ts"], META_ATTR) == getattr(ts, META_ATTR)
Beispiel #10
0
    def test_asdf_serialization(copy_arrays, lazy_load):
        coordinates = [
            [0.0, 0.0, 0.0],
            [1.0, 0.0, 0.0],
            [1.0, 1.0, 0.0],
            [0.0, 1.0, 0.0],
        ]

        triangles = [[0, 1, 2], [2, 3, 0]]

        pc = SpatialData(coordinates=coordinates, triangles=triangles)
        tree = {"point_cloud": pc}
        pc_file = _write_read_buffer(tree,
                                     open_kwargs={
                                         "copy_arrays": copy_arrays,
                                         "lazy_load": lazy_load
                                     })["point_cloud"]

        assert np.all(pc_file.coordinates == pc.coordinates)
Beispiel #11
0
def test_coordinate_system_manager_time_dependencies(copy_arrays, lazy_load,
                                                     csm_time_ref):
    """Test serialization of time components from CSM and its attached LCS."""
    lcs_tdp_1_time_ref = None
    if csm_time_ref is None:
        lcs_tdp_1_time_ref = pd.Timestamp("2000-03-17")
    lcs_tdp_1 = tf.LocalCoordinateSystem(
        coordinates=[[1, 2, 3], [4, 5, 6]],
        time=pd.TimedeltaIndex([1, 2], "D"),
        time_ref=lcs_tdp_1_time_ref,
    )
    lcs_tdp_2 = tf.LocalCoordinateSystem(
        coordinates=[[3, 7, 3], [9, 5, 8]],
        time=pd.TimedeltaIndex([1, 2], "D"),
        time_ref=pd.Timestamp("2000-03-21"),
    )

    csm_root = tf.CoordinateSystemManager("root", "csm_root", csm_time_ref)
    csm_root.add_cs("cs_1", "root", lcs_tdp_2)

    csm_sub_1 = tf.CoordinateSystemManager("cs_2", "csm_sub_1", csm_time_ref)
    csm_sub_1.add_cs("cs_1", "cs_2", lcs_tdp_2)
    csm_sub_1.add_cs("cs_3", "cs_2", lcs_tdp_1)

    csm_sub_2 = tf.CoordinateSystemManager("cs_4", "csm_sub_2")
    csm_sub_2.create_cs("cs_1", "cs_4")

    csm_root.merge(csm_sub_1)
    csm_root.merge(csm_sub_2)

    tree = {"cs_hierarchy": csm_root}
    data = _write_read_buffer(tree,
                              open_kwargs={
                                  "copy_arrays": copy_arrays,
                                  "lazy_load": lazy_load
                              })
    csm_file = data["cs_hierarchy"]
    assert csm_root == csm_file
Beispiel #12
0
def test_generic_measurement():
    """Test basic measurement creation and ASDF read/write."""
    data_01 = msm.Data(
        name="Welding current", data=xr.DataArray([1, 2, 3, 4], dims=["time"])
    )

    data_02 = msm.Data(
        name="Welding voltage", data=xr.DataArray([10, 20, 30, 40], dims=["time"])
    )

    src_01 = msm.Source(
        name="Current Sensor",
        output_signal=msm.Signal("analog", "V", data=None),
        error=msm.Error(1337.42),
    )

    src_02 = msm.Source(
        name="Voltage Sensor",
        output_signal=msm.Signal("analog", "V", data=None),
        error=msm.Error(1),
    )

    dp_01 = msm.DataTransformation(
        name="AD conversion current measurement",
        input_signal=src_01.output_signal,
        output_signal=msm.Signal("digital", "V", data=None),
        error=msm.Error(999.0),
    )

    dp_02 = msm.DataTransformation(
        name="Calibration current measurement",
        input_signal=dp_01.output_signal,
        output_signal=msm.Signal("digital", "A", data=data_01),
        error=msm.Error(43.0),
    )

    dp_03 = msm.DataTransformation(
        name="AD conversion voltage measurement",
        input_signal=dp_02.output_signal,
        output_signal=msm.Signal("digital", "V", data=None),
        error=msm.Error(2.0),
    )

    dp_04 = msm.DataTransformation(
        name="Calibration voltage measurement",
        input_signal=dp_03.output_signal,
        output_signal=msm.Signal("digital", "V", data=data_02),
        error=msm.Error(Q_(3.0, "percent")),
    )

    chn_01 = msm.MeasurementChain(
        name="Current measurement", data_source=src_01, data_processors=[dp_01, dp_02]
    )

    chn_02 = msm.MeasurementChain(
        name="Voltage measurement", data_source=src_02, data_processors=[dp_03, dp_04]
    )

    eqp_01 = msm.GenericEquipment(
        "Current Sensor", sources=[src_01], data_transformations=[dp_02]
    )
    eqp_02 = msm.GenericEquipment(
        "AD Converter", sources=None, data_transformations=[dp_01, dp_03]
    )
    eqp_03 = msm.GenericEquipment(
        "Voltage Sensor", sources=None, data_transformations=[dp_04]
    )

    measurement_01 = msm.Measurement(
        name="Current measurement", data=[data_01], measurement_chain=chn_01
    )
    measurement_02 = msm.Measurement(
        name="Voltage measurement", data=[data_02], measurement_chain=chn_02
    )

    equipment = [eqp_01, eqp_02, eqp_03]
    measurement_data = [data_01, data_02]
    measurement_chains = [chn_01]
    measurements = [measurement_01, measurement_02]
    sources = [src_01]
    processors = [dp_01, dp_02]

    [a, x, b] = sympy.symbols("a x b")
    expr_01 = MathematicalExpression(a * x + b)
    expr_01.set_parameter("a", 2)
    expr_01.set_parameter("b", 3)
    print(expr_01.parameters)
    print(expr_01.get_variable_names())
    print(expr_01.evaluate(x=3))

    tree = {
        "equipment": equipment,
        "data": measurement_data,
        "measurements": measurements,
        # "expression": expr_01,
        "measurement_chains": measurement_chains,
        "data_sources": sources,
        "data_processors": processors,
    }

    _write_read_buffer(tree)
Beispiel #13
0
def test_gmaw_process(inputs):
    data = _write_read_buffer({"root": inputs})
    assert data["root"] == inputs
Beispiel #14
0
def test_time_classes(inputs):
    data = _write_read_buffer({"root": inputs})
    assert np.all(data["root"] == inputs)
Beispiel #15
0
def test_shape_validator_exceptions(test_input):
    with pytest.raises(ValidationError):
        _write_read_buffer({"root": test_input})
Beispiel #16
0
def test_property_tag_validator(test_input):
    """Test custom ASDF shape validators."""
    _write_read_buffer({"root_node": test_input})
Beispiel #17
0
def test_rotation(inputs):
    data = _write_read_buffer({"rot": inputs})
    assert np.allclose(data["rot"].as_quat(), inputs.as_quat())
Beispiel #18
0
def test_property_tag_validator_exceptions(test_input, err):
    """Test custom ASDF shape validators."""
    with pytest.raises(err):
        _write_read_buffer({"root_node": test_input})
Beispiel #19
0
def test_shape_validator(test_input):
    _write_read_buffer({"root": test_input})
Beispiel #20
0
def test_aws_example():
    """Test validity of current AWS Data Dictionary standard implementation."""
    # welding process -----------------------------------------------------------------
    gas_comp = [
        GasComponent("argon", Q_(82, "percent")),
        GasComponent("carbon dioxide", Q_(18, "percent")),
    ]
    gas_type = ShieldingGasType(gas_component=gas_comp, common_name="SG")

    gas_for_procedure = ShieldingGasForProcedure(
        use_torch_shielding_gas=True,
        torch_shielding_gas=gas_type,
        torch_shielding_gas_flowrate=Q_(20, "l / min"),
    )

    arc_welding_process = ArcWeldingProcess("GMAW")
    with pytest.raises(ValueError):  # test for non viable process string
        ArcWeldingProcess("NON_EXISTENT_PROCESS")

    process = {
        "arc_welding_process": arc_welding_process,
        "shielding_gas": gas_for_procedure,
    }

    # weld design -----------------------------------------------------------------
    v_groove = get_groove(
        groove_type="VGroove",
        workpiece_thickness=Q_(9, "mm"),
        groove_angle=Q_(50, "deg"),
        root_face=Q_(4, "mm"),
        root_gap=Q_(2, "mm"),
    )
    u_groove = get_groove(
        groove_type="UGroove",
        workpiece_thickness=Q_(15, "mm"),
        bevel_angle=Q_(9, "deg"),
        bevel_radius=Q_(6, "mm"),
        root_face=Q_(3, "mm"),
        root_gap=Q_(1, "mm"),
    )

    joint_penetration = JointPenetration(
        complete_or_partial="completePenetration",
        root_penetration=Q_(1.0, "mm"))
    weld_details = WeldDetails(joint_design=v_groove,
                               weld_sizes=Q_(320, "mm"),
                               number_of_passes=1)
    weld_details2 = WeldDetails(joint_design=u_groove,
                                weld_sizes=Q_(320, "mm"),
                                number_of_passes=1)
    connection1 = Connection(
        joint_type="butt_joint",
        weld_type="singleVGroove",
        joint_penetration=joint_penetration,
        weld_details=weld_details,
    )
    connection2 = Connection(
        joint_type="butt_joint",
        weld_type="singleUGroove",
        joint_penetration=joint_penetration,
        weld_details=weld_details2,
    )
    workpieces = [Workpiece(geometry="V-Groove")]
    sub_assembly = [
        SubAssembly(workpiece=workpieces, connection=connection1),
        SubAssembly(workpiece=workpieces, connection=connection2),
    ]

    weldment = Weldment(sub_assembly)

    base_metal = BaseMetal("steel", "plate", Q_(10.3, "mm"))

    tree = dict(process=process, weldment=weldment, base_metal=base_metal)

    data = _write_read_buffer(tree)
    assert isinstance(data, dict)