Skip to content

model_result()

modelskill.model_result

model_result(data, *, aux_items=None, gtype=None, **kwargs)

A factory function for creating an appropriate object based on the data input.

Parameters:

Name Type Description Default
data DataInputType

The data to be used for creating the ModelResult object.

required
aux_items Optional[list[int | str]]

Auxiliary items, by default None

None
gtype Optional[Literal['point', 'track', 'unstructured', 'grid']]

The geometry type of the data. If not specified, it will be guessed from the data.

None
**kwargs Any

Additional keyword arguments to be passed to the ModelResult constructor.

{}

Examples:

>>> import modelskill as ms
>>> ms.model_result("Oresund2D.dfsu", item=0)
<DfsuModelResult> 'Oresund2D'
>>> ms.model_result("ERA5_DutchCoast.nc", item="swh", name="ERA5")
<GridModelResult> 'ERA5'
Source code in modelskill/model/factory.py
def model_result(
    data: DataInputType,
    *,
    aux_items: Optional[list[int | str]] = None,
    gtype: Optional[Literal["point", "track", "unstructured", "grid"]] = None,
    **kwargs: Any,
) -> Any:
    """A factory function for creating an appropriate object based on the data input.

    Parameters
    ----------
    data : DataInputType
        The data to be used for creating the ModelResult object.
    aux_items : Optional[list[int | str]]
        Auxiliary items, by default None
    gtype : Optional[Literal["point", "track", "unstructured", "grid"]]
        The geometry type of the data. If not specified, it will be guessed from the data.
    **kwargs
        Additional keyword arguments to be passed to the ModelResult constructor.

    Examples
    --------
    >>> import modelskill as ms
    >>> ms.model_result("Oresund2D.dfsu", item=0)
    <DfsuModelResult> 'Oresund2D'
    >>> ms.model_result("ERA5_DutchCoast.nc", item="swh", name="ERA5")
    <GridModelResult> 'ERA5'
    """
    if gtype is None:
        geometry = _guess_gtype(data)
    else:
        geometry = GeometryType.from_string(gtype)

    return _modelresult_lookup[geometry](
        data=data,
        aux_items=aux_items,
        **kwargs,
    )