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

Add map config #39

Merged
merged 2 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 8 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
description="Simple alignment and transformation between coordinate frames",
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
version="1.0.13",
version="1.0.14",
author="Equinor ASA",
author_email="arnts@equinor.com, euel@equinor.com, chjo@equinor.com",
license="MIT",
Expand All @@ -23,7 +23,12 @@
"Topic :: Software Development :: Libraries",
],
include_package_data=True,
install_requires=["scipy", "numpy"],
install_requires=["scipy", "numpy", "dacite"],
python_requires=">=3.8",
tests_require=["pytest"],
extras_require={
"dev": [
"pytest",
"black",
]
},
)
14 changes: 14 additions & 0 deletions src/alitra/models/map_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import json
from dataclasses import dataclass
from pathlib import Path

from dacite import from_dict

from alitra.frame_dataclasses import PointList

Expand All @@ -8,3 +12,13 @@ class MapConfig:
map_name: str
robot_reference_points: PointList
asset_reference_points: PointList


def load_map_config(map_config_path: Path) -> MapConfig:
with open(map_config_path) as json_file:
map_config_dict = json.load(json_file)

return from_dict(
data_class=MapConfig,
data=map_config_dict,
)
38 changes: 38 additions & 0 deletions tests/models/test_map_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from pathlib import Path

import pytest

from alitra.frame_dataclasses import Point, PointList
from alitra.models.map_config import MapConfig, load_map_config

expected_map_config = MapConfig(
map_name="test_map",
robot_reference_points=PointList(
points=[
Point(x=10, y=20, z=30, frame="robot"),
Point(x=40, y=50, z=60, frame="robot"),
Point(x=70, y=80, z=90, frame="robot"),
],
frame="robot",
),
asset_reference_points=PointList(
points=[
Point(x=11, y=21, z=31, frame="asset"),
Point(x=41, y=51, z=61, frame="asset"),
Point(x=71, y=81, z=91, frame="asset"),
],
frame="asset",
),
)


def test_load_map_config():
map_config_path = Path("./tests/test_data/test_map_config/test_map_config.json")
map_config: MapConfig = load_map_config(map_config_path)
assert map_config == expected_map_config


def test_invalid_file_path():
map_config_path = Path("./tests/test_data/test_map_config/no_file.json")
with pytest.raises(Exception):
load_map_config(map_config_path)
49 changes: 49 additions & 0 deletions tests/test_data/test_map_config/test_map_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"map_name": "test_map",
"robot_reference_points": {
"points": [
{
"x": 10,
"y": 20,
"z": 30,
"frame": "robot"
},
{
"x": 40,
"y": 50,
"z": 60,
"frame": "robot"
},
{
"x": 70,
"y": 80,
"z": 90,
"frame": "robot"
}
],
"frame": "robot"
},
"asset_reference_points": {
"points": [
{
"x": 11,
"y": 21,
"z": 31,
"frame": "asset"
},
{
"x": 41,
"y": 51,
"z": 61,
"frame": "asset"
},
{
"x": 71,
"y": 81,
"z": 91,
"frame": "asset"
}
],
"frame": "asset"
}
}