Skip to content

Commit

Permalink
TimeSeries (#76)
Browse files Browse the repository at this point in the history
* Add new core package and move MathematicalExpression to it
* Test MathematicalExpression
* Add and test TimeSeries class
* Add ASDF schemas for MathematicalExpession and TimeSeries
* Add and test utility.pandas_time_delta_to_quantity

Co-authored-by: Cagtay Fabry <43667554+CagtayFabry@users.noreply.github.com>
  • Loading branch information
vhirtham and CagtayFabry authored Jul 27, 2020
1 parent 860e09c commit be0fdac
Show file tree
Hide file tree
Showing 26 changed files with 1,712 additions and 142 deletions.
1 change: 1 addition & 0 deletions .typo-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ excluded_words:
- dtype
- hstack
- isclose
- issubdtype
- linalg
- matmul
- ndarray
Expand Down
1 change: 0 additions & 1 deletion .vulture_whitelist.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""White list for the static analyzer 'vulture'."""

from tests.test_visualization import Axes3D

from weldx.transformations import LocalCoordinateSystem, WeldxAccessor

Axes3D # unused import
Expand Down
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
- `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](https://github.com/BAMWelDX/weldx/pull/70)
- add example notebook for measurement chains in tutorials [#70](https://github.com/BAMWelDX/weldx/pull/70)
- add and test support for `sympy` expressions with 'weldx.core.MathematicalExpression' and ASDF serialization in '`core/mathematical_expression-1.0.0` [#70](https://github.com/BAMWelDX/weldx/pull/70), [#76](https://github.com/BAMWelDX/weldx/pull/76)
- add and test class to describe time series - 'weldx.core.TimeSeries' [#76](https://github.com/BAMWelDX/weldx/pull/76)
- add `wx_property_tag` validator [#72](https://github.com/BAMWelDX/weldx/pull/72)

the `wx_property_tag` validator restricts **all** properties of an object to a single tag.
Expand All @@ -39,5 +40,5 @@
```
It can be used as a "named" mapping replacement instead of YAML `arrays`.
- add `core/transoformations/rotation-1.0.0` schema that implements `scipy.spatial.transform.Rotation` and `transformations.WXRotation` class to create custom tagged `Rotation` instances for custom serialization. [#79]
- update requirements to `asdf>=2.7` [#83]
- update `anyOf` to `oneOf` in ASDF schemas [#83]
- update requirements to `asdf>=2.7` [#83](https://github.com/BAMWelDX/weldx/pull/83)
- update `anyOf` to `oneOf` in ASDF schemas [#83](https://github.com/BAMWelDX/weldx/pull/83)
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dependencies:
- black
- codecov
- flake8=3.7
- isort>=5.1
- pydocstyle=5
- pytest
- pytest-cov
Expand Down
29 changes: 14 additions & 15 deletions scripts/aws_run.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
"""Run the AWS Data Dictionary debug example."""

import asdf
import pprint

from weldx.constants import WELDX_QUANTITY as Q_
import asdf

from weldx.asdf.extension import WeldxExtension, WeldxAsdfExtension
from weldx.asdf.extension import WeldxAsdfExtension, WeldxExtension
from weldx.asdf.tags.weldx.aws.design.base_metal import BaseMetal
from weldx.asdf.tags.weldx.aws.design.connection import Connection

# weld design -----------------------------------------------------------------
from weldx.asdf.tags.weldx.aws.design.joint_penetration import JointPenetration
from weldx.asdf.tags.weldx.aws.design.sub_assembly import SubAssembly
from weldx.asdf.tags.weldx.aws.design.weld_details import WeldDetails
from weldx.asdf.tags.weldx.aws.design.weldment import Weldment
from weldx.asdf.tags.weldx.aws.design.workpiece import Workpiece
from weldx.asdf.tags.weldx.aws.process.arc_welding_process import ArcWeldingProcess

# welding process -----------------------------------------------------------------
from weldx.asdf.tags.weldx.aws.process.gas_component import GasComponent
from weldx.asdf.tags.weldx.aws.process.shielding_gas_type import ShieldingGasType
from weldx.asdf.tags.weldx.aws.process.shielding_gas_for_procedure import (
ShieldingGasForProcedure,
)
from weldx.asdf.tags.weldx.aws.process.arc_welding_process import ArcWeldingProcess

# weld design -----------------------------------------------------------------
from weldx.asdf.tags.weldx.aws.design.joint_penetration import JointPenetration
from weldx.asdf.tags.weldx.aws.design.weld_details import WeldDetails
from weldx.asdf.tags.weldx.aws.design.connection import Connection
from weldx.asdf.tags.weldx.aws.design.workpiece import Workpiece
from weldx.asdf.tags.weldx.aws.design.sub_assembly import SubAssembly
from weldx.asdf.tags.weldx.aws.design.weldment import Weldment
from weldx.asdf.tags.weldx.aws.design.base_metal import BaseMetal
from weldx.asdf.tags.weldx.aws.process.shielding_gas_type import ShieldingGasType
from weldx.asdf.tags.weldx.core.iso_groove import get_groove

from weldx.constants import WELDX_QUANTITY as Q_

# welding process -----------------------------------------------------------------
gas_comp = [
Expand Down
21 changes: 10 additions & 11 deletions scripts/groove_load_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@

import asdf

from weldx.asdf.extension import WeldxExtension, WeldxAsdfExtension
from weldx.asdf.extension import WeldxAsdfExtension, WeldxExtension
from weldx.asdf.tags.weldx.core.iso_groove import (
VGroove,
UGroove,
DHUGroove,
DHVGroove,
DUGroove,
DVGroove,
FFGroove,
HUGroove,
HVGroove,
IGroove,
UGroove,
UVGroove,
VGroove,
VVGroove,
HVGroove,
HUGroove,
DVGroove,
DUGroove,
DHVGroove,
DHUGroove,
FFGroove,
)


opened = asdf.open("testfile.yml", extensions=[WeldxAsdfExtension(), WeldxExtension()])

if isinstance(opened["test001"], VGroove):
Expand Down
4 changes: 2 additions & 2 deletions scripts/groove_save_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import asdf

from weldx.constants import WELDX_QUANTITY as Q_
from weldx.asdf.extension import WeldxExtension, WeldxAsdfExtension
from weldx.asdf.extension import WeldxAsdfExtension, WeldxExtension
from weldx.asdf.tags.weldx.core.iso_groove import get_groove
from weldx.constants import WELDX_QUANTITY as Q_

v_groove = get_groove(
groove_type="VGroove",
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

from os import path

import versioneer
from setuptools import find_packages, setup

import versioneer

# add README.md as long description
this_directory = path.abspath(path.dirname(__file__))
with open(path.join(this_directory, "README.md"), encoding="utf-8") as f:
Expand Down
3 changes: 2 additions & 1 deletion tests/_helpers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Provides some utility functions for tests."""

import weldx.transformations as tf
import numpy as np

import weldx.transformations as tf


def rotated_coordinate_system(
angle_x=np.pi / 3,
Expand Down
70 changes: 70 additions & 0 deletions tests/asdf_tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import weldx.transformations as tf
from weldx.asdf.extension import WeldxAsdfExtension, WeldxExtension
from weldx.constants import WELDX_QUANTITY as Q_
from weldx.core import MathematicalExpression, TimeSeries

# xarray.DataArray ---------------------------------------------------------------------

Expand Down Expand Up @@ -356,3 +357,72 @@ def test_coordinate_system_manager_load():
csm_file = f.tree["cs_hierarchy"]

assert are_coordinate_system_managers_equal(csm_exp, csm_file)


# weldx.core.TimeSeries ----------------------------------------------------------------

buffer_ts = BytesIO()


def get_example_time_series(num):
if num == 1:
return TimeSeries(Q_(42, "m"))
if num == 2:
return TimeSeries(Q_([42, 23, 12], "m"), time=pd.TimedeltaIndex([0, 2, 5]))
if num == 4:
return TimeSeries(Q_([42, 23, 12], "m"), time=pd.TimedeltaIndex([0, 2, 4]))

expr = MathematicalExpression(
"a*t+b", parameters={"a": Q_(2, "1/s"), "b": Q_(5, "")}
)
return TimeSeries(expr)


def test_time_series_save():
"""Test if a TimeSeries can be written to an asdf file."""
tree = {
"ts1": get_example_time_series(1),
"ts2": get_example_time_series(2),
"ts3": get_example_time_series(3),
"ts4": get_example_time_series(4),
}
with asdf.AsdfFile(
tree, extensions=[WeldxExtension(), WeldxAsdfExtension()], copy_arrays=True
) as f:
f.write_to(buffer_ts)
buffer_ts.seek(0)


def test_time_series_load():
"""Test if a TimeSeries can be read from an asdf file."""
f = asdf.open(
buffer_ts, extensions=[WeldxExtension(), WeldxAsdfExtension()], lazy_load=False,
)

ts1_exp = get_example_time_series(1)
ts1_file = f.tree["ts1"]
assert ts1_file.data == ts1_exp.data
assert ts1_file.time == ts1_exp.time
assert ts1_file.interpolation == ts1_exp.interpolation

ts2_exp = get_example_time_series(2)
ts2_file = f.tree["ts2"]
assert np.all(ts2_file.data == ts2_exp.data)
assert np.all(ts2_file.time == ts2_exp.time)
assert ts2_file.interpolation == ts2_exp.interpolation

ts3_exp = get_example_time_series(3)
ts3_file = f.tree["ts3"]

expr_exp = ts3_exp.data
expr_file = ts3_file.data

assert expr_exp == expr_file
assert ts3_file.time == ts3_exp.time
assert ts3_file.interpolation == ts3_exp.interpolation

ts4_exp = get_example_time_series(4)
ts4_file = f.tree["ts4"]
assert np.all(ts4_file.data == ts4_exp.data)
assert np.all(ts4_file.time == ts4_exp.time)
assert ts4_file.interpolation == ts4_exp.interpolation
27 changes: 14 additions & 13 deletions tests/asdf_tests/test_groove.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
"""Test all ASDF groove implementations."""

from io import BytesIO

import asdf
import matplotlib.pyplot as plt
import pytest

from weldx.geometry import Profile
from weldx.constants import WELDX_QUANTITY as Q_
from weldx.asdf.extension import WeldxExtension, WeldxAsdfExtension
from weldx.asdf.extension import WeldxAsdfExtension, WeldxExtension
from weldx.asdf.tags.weldx.core.iso_groove import (
get_groove,
BaseGroove,
VGroove,
UGroove,
DHUGroove,
DHVGroove,
DUGroove,
DVGroove,
FFGroove,
HUGroove,
HVGroove,
IGroove,
UGroove,
UVGroove,
VGroove,
VVGroove,
HVGroove,
HUGroove,
DVGroove,
DUGroove,
DHVGroove,
DHUGroove,
FFGroove,
get_groove,
)
from weldx.constants import WELDX_QUANTITY as Q_
from weldx.geometry import Profile


def _create_test_grooves():
Expand Down
Loading

0 comments on commit be0fdac

Please sign in to comment.