-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add draft for mathematical function class based on SymPy * Add serialization of mathematical function class * Add measurement example notebook * Add example notebook with quantities * Add allOf syntax to validator testcase * Add unit support to LCS
- Loading branch information
1 parent
a5052f0
commit 930c5f9
Showing
36 changed files
with
1,336 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
"""Test the measurement package.""" | ||
from io import BytesIO | ||
|
||
import asdf | ||
import sympy | ||
import xarray as xr | ||
|
||
import weldx.measurement as msm | ||
from weldx.asdf.extension import WeldxAsdfExtension, WeldxExtension | ||
from weldx.asdf.tags.weldx.core.mathematical_expression import MathematicalExpression | ||
from weldx.constants import WELDX_QUANTITY as Q_ | ||
|
||
|
||
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, | ||
} | ||
|
||
asdf_buffer = BytesIO() | ||
|
||
with asdf.AsdfFile(tree, extensions=[WeldxExtension(), WeldxAsdfExtension()]) as f: | ||
f.write_to(asdf_buffer) | ||
asdf_buffer.seek(0) | ||
|
||
asdf.open(asdf_buffer, extensions=[WeldxExtension(), WeldxAsdfExtension()]) |
Oops, something went wrong.