Skip to content
Snippets Groups Projects
Commit ee1e82e1 authored by Martin Lange's avatar Martin Lange
Browse files

make auto-transfer usable from components, resolve cyclic import

parent 2df83d63
No related branches found
No related tags found
1 merge request!154Auto-transfer infos
......@@ -4,7 +4,7 @@ from pathlib import Path
import numpy as np
from pyevtk.hl import imageToVTK
from ..tools import get_enum_value
from ..tools.enum_helper import get_enum_value
from .grid_tools import (
CellType,
Grid,
......
......@@ -17,7 +17,7 @@ import pint
# isort: on
from ..errors import FinamDataError, FinamMetaDataError
from .grid_spec import NoGrid
from . import grid_spec
from .grid_tools import Grid, GridBase
# set default format to cf-convention for pint.dequantify
......@@ -58,7 +58,7 @@ def _gen_dims(ndim, info, time=None):
"""
# create correct dims (time always first)
dims = ["time"] if time else []
if isinstance(info.grid, NoGrid):
if isinstance(info.grid, grid_spec.NoGrid):
# xarray has dim_0, dim_1 ... as default names
dims += [f"dim_{i}" for i in range(ndim)]
else:
......@@ -124,7 +124,7 @@ def to_xarray(data, name, info, time=None, no_time_check=False):
# reshape arrays
data = data.reshape(info.grid.data_shape, order=info.grid.order)
elif isinstance(info.grid, NoGrid):
elif isinstance(info.grid, grid_spec.NoGrid):
if len(data.shape) != info.grid.dim:
raise FinamDataError(
f"to_xarray: number of dimensions in data doesn't match expected number. "
......@@ -451,7 +451,7 @@ def _check_shape(xdata, grid, with_time):
f"check: given data has wrong shape. "
f"Got {in_shape}, expected {grid.data_shape}"
)
if isinstance(grid, NoGrid) and len(in_shape) != grid.dim:
if isinstance(grid, grid_spec.NoGrid) and len(in_shape) != grid.dim:
raise FinamDataError(
f"check: given data has wrong number of dimensions. "
f"Got {len(in_shape)}, expected {grid.dim}"
......
......@@ -208,7 +208,9 @@ class Component(IComponent, Loggable, ABC):
"""The component's ConnectHelper"""
return self._connector
def create_connector(self, pull_data=None, cache=True):
def create_connector(
self, pull_data=None, in_info_rules=None, out_info_rules=None, cache=True
):
"""
Create the component's ConnectHelper
......@@ -216,6 +218,10 @@ class Component(IComponent, Loggable, ABC):
----------
pull_data : arraylike
Names of the inputs that are to be pulled.
in_info_rules : dict
Info transfer rules for inputs.
out_info_rules : dict
Info transfer rules for outputs.
cache : bool
Whether data and :class:`.Info` objects passed via :meth:`try_connect() <.Component.try_connect>`
are cached for later calls. Default ``True``.
......@@ -226,6 +232,8 @@ class Component(IComponent, Loggable, ABC):
self.inputs,
self.outputs,
pull_data=pull_data,
in_info_rules=in_info_rules,
out_info_rules=out_info_rules,
cache=cache,
)
self.inputs.frozen = True
......
......@@ -36,8 +36,12 @@ Connect helper
.. autosummary::
:toctree: generated
connect_helper.ConnectHelper
ConnectHelper
FromInput
FromOutput
FromValue
"""
from .connect_helper import ConnectHelper, FromInput, FromOutput, FromValue
from .cwd_helper import execute_in_cwd, set_directory
from .enum_helper import get_enum_value
from .log_helper import (
......@@ -57,3 +61,4 @@ __all__ += [
"LogStdOutStdErr",
"LogCStdOutStdErr",
]
__all__ += ["ConnectHelper", "FromInput", "FromOutput", "FromValue"]
"""IOList for Components."""
"""Enum conversion helper."""
from enum import Enum
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment