Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Measurement asdf #70

Merged
merged 39 commits into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
c9fc451
Add basic setup
vhirtham Jun 16, 2020
3332058
add base classes and schemas
CagtayFabry Jun 16, 2020
2cd8e8a
add sensor files
CagtayFabry Jun 16, 2020
d320e78
Move data classes to measurement package
vhirtham Jun 16, 2020
e72303c
Add example test
vhirtham Jun 16, 2020
fcd775c
Backup
vhirtham Jun 17, 2020
ad4b1f2
Add signal class
vhirtham Jun 18, 2020
ea60df3
Add measurement class and expand example
vhirtham Jun 18, 2020
3cc1234
Add draft for mathematical function class (some parts missing)
vhirtham Jun 19, 2020
3a150bd
Add serialization of mathematical function parameters
vhirtham Jun 22, 2020
13b73b3
Test build without sympy
vhirtham Jun 22, 2020
7ed167c
rename asdf tests folder to asdf_tests and add __init__.py files
CagtayFabry Jun 22, 2020
e245a35
add sympy to environment.yml
CagtayFabry Jun 22, 2020
77997f1
add example notebook with quantities
CagtayFabry Jun 22, 2020
472eb74
Merge branch 'dev_asdf' into measurement_asdf
vhirtham Jun 24, 2020
55f33be
add allOf syntax to validator testcase
CagtayFabry Jun 24, 2020
a721222
update the measurement example notebook
CagtayFabry Jun 24, 2020
6e1d013
Merge branch 'measurement_asdf' of https://github.com/BAMWelDX/weldx …
CagtayFabry Jun 24, 2020
1d173f0
Modify LCS to support units
vhirtham Jun 25, 2020
6d976b6
Add coordinate system section to measurement notebook
vhirtham Jun 25, 2020
b5793c1
add sympy dependency to setup.py
CagtayFabry Jun 26, 2020
e1a4ac6
black formatting
CagtayFabry Jun 26, 2020
9413970
Merge remote-tracking branch 'remotes/origin/dev_asdf' into measureme…
CagtayFabry Jul 6, 2020
fe13874
typo fixes in example notebook
CagtayFabry Jul 10, 2020
63c57fa
move measurement_example.ipynb to tutorials
CagtayFabry Jul 10, 2020
68ca52e
test against pint.Quantity in LCS constructor
CagtayFabry Jul 10, 2020
352bfb4
update CHANGELOG.md
CagtayFabry Jul 10, 2020
08cbacb
update .typo-ci.yml
CagtayFabry Jul 10, 2020
af590aa
add asdf schema titles and descriptions
CagtayFabry Jul 10, 2020
af7276b
add descriptions and remove unused sensor class
CagtayFabry Jul 10, 2020
b75ce3b
update asdf type docstrings
CagtayFabry Jul 10, 2020
00bc361
update mathematical_expression.py docstrings
CagtayFabry Jul 10, 2020
ae6ccc4
add docstrings
CagtayFabry Jul 10, 2020
50b8f84
update test
CagtayFabry Jul 10, 2020
7f3c30f
Merge branch 'dev_asdf' into measurement_asdf
CagtayFabry Jul 10, 2020
17ae8bf
Fix some typos
vhirtham Jul 10, 2020
d9c22c8
Fix errors due to merge of master
vhirtham Jul 10, 2020
83babf0
Fix flake8 and pydocstyle issues
vhirtham Jul 10, 2020
2d9b73c
Fix isort issue(?)
vhirtham Jul 10, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .typo-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ excluded_words:
- pandas
- xarray
- scipy
- sympy
- pytest
- pydocstyle
- matplotlib
Expand Down Expand Up @@ -79,6 +80,9 @@ excluded_words:
- ipython
# scipy ---------------------------------------
- Slerp
# sympy ---------------------------------------
- lambdify
- sympify
# welding -------------------------------------
- weldment
# conda ---------------------------------------
Expand All @@ -101,3 +105,5 @@ excluded_words:
- xyz
- bamwelding
- netcdf
- msm
- Beckhoff
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,15 @@
`weldx.transformations.CoordinateSystemManager`.
- add test for `xarray.DataArray`, `xarray.Dataset`, `weldx.transformations.LocalCoordinateSystem` and
`weldx.transformations.CoordinateSystemManager` serialization.
- allow using `pint.Quantity` coordinates in `weldx.transformations.LocalCoordinateSystem` [#70]
- add measurement related ASDF serialization classes: [#70]
- `equipment/generic_equipment-1.0.0`
- `measurement/data-1.0.0`
- `data_transformation-1.0.0`
- `measurement/error-1.0.0`
- `measurement/measurement-1.0.0`
- `measurement/measurement_chain-1.0.0`
- `measurement/signal-1.0.0`
- `measurement/source-1.0.0`
- add ASDF support for `sympy` expressions with `core/mathematical_expression-1.0.0` [#70]
- add example notebook for measurement chains in tutorials [#70]
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dependencies:
- numpy>=1.18
- pandas>=1.0
- scipy>=1.4
- sympy>=1.6
- xarray>=0.15
- pint>=0.11
- bottleneck
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"pandas>=1.0",
"xarray>=0.15",
"scipy>=1.4",
"sympy>=1.6",
"pint>=0.11",
"asdf>=2.6",
"bottleneck>=1.3",
Expand Down
20 changes: 8 additions & 12 deletions tests/asdf_tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def get_local_coordinate_system(time_dep_orientation: bool, time_dep_coordinates
A local coordinate system

"""
coords = [2, 5, 1]
coords = Q_(np.asarray([2.0, 5.0, 1.0]), "mm")
orientation = tf.rotation_matrix_z(np.pi / 3)

if not time_dep_orientation and not time_dep_coordinates:
Expand Down Expand Up @@ -247,22 +247,18 @@ def are_coordinate_system_managers_equal(
def get_example_coordinate_system_manager():
"""Get a consistent CoordinateSystemManager instance for test purposes."""
csm = tf.CoordinateSystemManager("root")
csm.add_coordinate_system(
"lcs_01", "root", tf.LocalCoordinateSystem(coordinates=[1, 2, 3])
)
csm.add_coordinate_system(
csm.create_cs("lcs_01", "root", coordinates=[1, 2, 3])
csm.create_cs(
"lcs_02",
"root",
tf.LocalCoordinateSystem(
orientation=tf.rotation_matrix_z(np.pi / 3), coordinates=[4, -7, 8]
),
orientation=tf.rotation_matrix_z(np.pi / 3),
coordinates=[4, -7, 8],
)
csm.add_coordinate_system(
csm.create_cs(
"lcs_03",
"lcs_02",
tf.LocalCoordinateSystem(
orientation=tf.rotation_matrix_y(np.pi / 11), coordinates=[4, -7, 8]
),
orientation=tf.rotation_matrix_y(np.pi / 11),
coordinates=[4, -7, 8],
)
return csm

Expand Down
120 changes: 120 additions & 0 deletions tests/test_measurement.py
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()])
Loading