Skip to content

Commit

Permalink
Test grid to and from dict functionality - disabled
Browse files Browse the repository at this point in the history
This requires setting the comparison method in the TurbineGrid and Grid classes. While this can be done with
field(eq=cmp_using(eq=np.array_equal))
this adds a lot of additional code to the attribute declarations and makes them difficult to read. Holding off for now but I wanted to leave the test in place for future reference.
  • Loading branch information
rafmudaf committed Dec 1, 2023
1 parent 4624c5e commit e246fab
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
19 changes: 18 additions & 1 deletion floris/type_dec.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@
import attrs
import numpy as np
import numpy.typing as npt
from attrs import Attribute, define
from attrs import (
Attribute,
# cmp_using,
define,
# field,
)


### Define general data types used throughout
Expand All @@ -51,6 +56,18 @@ def floris_array_converter(data: Iterable) -> np.ndarray:
raise TypeError(e.args[0] + f". Data given: {data}")
return a

# def array_field(**kwargs) -> Callable:
# """
# A wrapper for the :py:func:`attr.field` function that converts the input to a Numpy array,
# adds a comparison function specific to Numpy arrays, and passes through all additional
# keyword arguments.
# """
# return field(
# converter=floris_array_converter,
# eq=cmp_using(eq=np.array_equal),
# **kwargs
# )

def _attr_serializer(inst: type, field: Attribute, value: Any):
if isinstance(value, np.ndarray):
return value.tolist()
Expand Down
8 changes: 5 additions & 3 deletions tests/turbine_grid_unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@


import numpy as np
import pytest

from floris.utilities import Vec3
from floris.simulation import TurbineGrid
from tests.conftest import (
N_TURBINES,
N_WIND_DIRECTIONS,
Expand All @@ -25,7 +24,10 @@
)


# TODO: test the dimension expansion
# def test_from_dict_as_dict(turbine_grid_fixture):
# grid_dict = turbine_grid_fixture.as_dict()
# new_grid = TurbineGrid.from_dict(grid_dict)
# assert new_grid == turbine_grid_fixture


def test_set_grid(turbine_grid_fixture):
Expand Down

0 comments on commit e246fab

Please sign in to comment.