Skip to content

WindTurbine Data Classes

examples.wind_turbine.data_classes

Blade

Bases: DomainModel

This represents the reading version of blade.

It is used to when data is retrieved from CDF.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the blade.

required
data_record

The data record of the blade node.

required
is_damaged

The is damaged field.

required
name

Name of the instance

required
sensor_positions

The sensor position field.

required
Source code in examples/wind_turbine/data_classes/_blade.py
class Blade(DomainModel):
    """This represents the reading version of blade.

    It is used to when data is retrieved from CDF.

    Args:
        space: The space where the node is located.
        external_id: The external id of the blade.
        data_record: The data record of the blade node.
        is_damaged: The is damaged field.
        name: Name of the instance
        sensor_positions: The sensor position field.
    """

    _view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "Blade", "1")

    space: str = DEFAULT_INSTANCE_SPACE
    node_type: Union[dm.DirectRelationReference, None] = None
    is_damaged: Optional[bool] = None
    name: Optional[str] = None
    sensor_positions: Optional[list[SensorPosition]] = Field(default=None, repr=False)

    def as_write(self) -> BladeWrite:
        """Convert this read version of blade to the writing version."""
        return BladeWrite(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecordWrite(existing_version=self.data_record.version),
            is_damaged=self.is_damaged,
            name=self.name,
        )

    def as_apply(self) -> BladeWrite:
        """Convert this read version of blade to the writing version."""
        warnings.warn(
            "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
            UserWarning,
            stacklevel=2,
        )
        return self.as_write()

    @classmethod
    def _update_connections(
        cls,
        instances: dict[dm.NodeId | str, Blade],  # type: ignore[override]
        nodes_by_id: dict[dm.NodeId | str, DomainModel],
        edges_by_source_node: dict[dm.NodeId, list[dm.Edge | DomainRelation]],
    ) -> None:
        from ._sensor_position import SensorPosition

        for node in nodes_by_id.values():
            if (
                isinstance(node, SensorPosition)
                and node.blade is not None
                and (blade := instances.get(as_pygen_node_id(node.blade)))
            ):
                if blade.sensor_positions is None:
                    blade.sensor_positions = []
                blade.sensor_positions.append(node)

as_apply()

Convert this read version of blade to the writing version.

Source code in examples/wind_turbine/data_classes/_blade.py
def as_apply(self) -> BladeWrite:
    """Convert this read version of blade to the writing version."""
    warnings.warn(
        "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
        UserWarning,
        stacklevel=2,
    )
    return self.as_write()

as_write()

Convert this read version of blade to the writing version.

Source code in examples/wind_turbine/data_classes/_blade.py
def as_write(self) -> BladeWrite:
    """Convert this read version of blade to the writing version."""
    return BladeWrite(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecordWrite(existing_version=self.data_record.version),
        is_damaged=self.is_damaged,
        name=self.name,
    )

BladeGraphQL

Bases: GraphQLCore

This represents the reading version of blade, used when data is retrieved from CDF using GraphQL.

It is used when retrieving data from CDF using GraphQL.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the blade.

required
data_record

The data record of the blade node.

required
is_damaged

The is damaged field.

required
name

Name of the instance

required
sensor_positions

The sensor position field.

required
Source code in examples/wind_turbine/data_classes/_blade.py
class BladeGraphQL(GraphQLCore):
    """This represents the reading version of blade, used
    when data is retrieved from CDF using GraphQL.

    It is used when retrieving data from CDF using GraphQL.

    Args:
        space: The space where the node is located.
        external_id: The external id of the blade.
        data_record: The data record of the blade node.
        is_damaged: The is damaged field.
        name: Name of the instance
        sensor_positions: The sensor position field.
    """

    view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "Blade", "1")
    is_damaged: Optional[bool] = None
    name: Optional[str] = None
    sensor_positions: Optional[list[SensorPositionGraphQL]] = Field(default=None, repr=False)

    @model_validator(mode="before")
    def parse_data_record(cls, values: Any) -> Any:
        if not isinstance(values, dict):
            return values
        if "lastUpdatedTime" in values or "createdTime" in values:
            values["dataRecord"] = DataRecordGraphQL(
                created_time=values.pop("createdTime", None),
                last_updated_time=values.pop("lastUpdatedTime", None),
            )
        return values

    @field_validator("sensor_positions", mode="before")
    def parse_graphql(cls, value: Any) -> Any:
        if not isinstance(value, dict):
            return value
        if "items" in value:
            return value["items"]
        return value

    # We do the ignore argument type as we let pydantic handle the type checking
    @no_type_check
    def as_read(self) -> Blade:
        """Convert this GraphQL format of blade to the reading format."""
        if self.data_record is None:
            raise ValueError("This object cannot be converted to a read format because it lacks a data record.")
        return Blade(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecord(
                version=0,
                last_updated_time=self.data_record.last_updated_time,
                created_time=self.data_record.created_time,
            ),
            is_damaged=self.is_damaged,
            name=self.name,
            sensor_positions=[sensor_position.as_read() for sensor_position in self.sensor_positions or []],
        )

    # We do the ignore argument type as we let pydantic handle the type checking
    @no_type_check
    def as_write(self) -> BladeWrite:
        """Convert this GraphQL format of blade to the writing format."""
        return BladeWrite(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecordWrite(existing_version=0),
            is_damaged=self.is_damaged,
            name=self.name,
        )

as_read()

Convert this GraphQL format of blade to the reading format.

Source code in examples/wind_turbine/data_classes/_blade.py
@no_type_check
def as_read(self) -> Blade:
    """Convert this GraphQL format of blade to the reading format."""
    if self.data_record is None:
        raise ValueError("This object cannot be converted to a read format because it lacks a data record.")
    return Blade(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecord(
            version=0,
            last_updated_time=self.data_record.last_updated_time,
            created_time=self.data_record.created_time,
        ),
        is_damaged=self.is_damaged,
        name=self.name,
        sensor_positions=[sensor_position.as_read() for sensor_position in self.sensor_positions or []],
    )

as_write()

Convert this GraphQL format of blade to the writing format.

Source code in examples/wind_turbine/data_classes/_blade.py
@no_type_check
def as_write(self) -> BladeWrite:
    """Convert this GraphQL format of blade to the writing format."""
    return BladeWrite(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecordWrite(existing_version=0),
        is_damaged=self.is_damaged,
        name=self.name,
    )

BladeList

Bases: DomainModelList[Blade]

List of blades in the read version.

Source code in examples/wind_turbine/data_classes/_blade.py
class BladeList(DomainModelList[Blade]):
    """List of blades in the read version."""

    _INSTANCE = Blade

    def as_write(self) -> BladeWriteList:
        """Convert these read versions of blade to the writing versions."""
        return BladeWriteList([node.as_write() for node in self.data])

    def as_apply(self) -> BladeWriteList:
        """Convert these read versions of primitive nullable to the writing versions."""
        warnings.warn(
            "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
            UserWarning,
            stacklevel=2,
        )
        return self.as_write()

    @property
    def sensor_positions(self) -> SensorPositionList:
        from ._sensor_position import SensorPosition, SensorPositionList

        return SensorPositionList(
            [item for items in self.data for item in items.sensor_positions or [] if isinstance(item, SensorPosition)]
        )

as_apply()

Convert these read versions of primitive nullable to the writing versions.

Source code in examples/wind_turbine/data_classes/_blade.py
def as_apply(self) -> BladeWriteList:
    """Convert these read versions of primitive nullable to the writing versions."""
    warnings.warn(
        "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
        UserWarning,
        stacklevel=2,
    )
    return self.as_write()

as_write()

Convert these read versions of blade to the writing versions.

Source code in examples/wind_turbine/data_classes/_blade.py
def as_write(self) -> BladeWriteList:
    """Convert these read versions of blade to the writing versions."""
    return BladeWriteList([node.as_write() for node in self.data])

BladeWrite

Bases: DomainModelWrite

This represents the writing version of blade.

It is used to when data is sent to CDF.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the blade.

required
data_record

The data record of the blade node.

required
is_damaged

The is damaged field.

required
name

Name of the instance

required
Source code in examples/wind_turbine/data_classes/_blade.py
class BladeWrite(DomainModelWrite):
    """This represents the writing version of blade.

    It is used to when data is sent to CDF.

    Args:
        space: The space where the node is located.
        external_id: The external id of the blade.
        data_record: The data record of the blade node.
        is_damaged: The is damaged field.
        name: Name of the instance
    """

    _view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "Blade", "1")

    space: str = DEFAULT_INSTANCE_SPACE
    node_type: Union[dm.DirectRelationReference, dm.NodeId, tuple[str, str], None] = None
    is_damaged: Optional[bool] = None
    name: Optional[str] = None

    def _to_instances_write(
        self,
        cache: set[tuple[str, str]],
        write_none: bool = False,
        allow_version_increase: bool = False,
    ) -> ResourcesWrite:
        resources = ResourcesWrite()
        if self.as_tuple_id() in cache:
            return resources

        properties: dict[str, Any] = {}

        if self.is_damaged is not None or write_none:
            properties["is_damaged"] = self.is_damaged

        if self.name is not None or write_none:
            properties["name"] = self.name

        if properties:
            this_node = dm.NodeApply(
                space=self.space,
                external_id=self.external_id,
                existing_version=None if allow_version_increase else self.data_record.existing_version,
                type=as_direct_relation_reference(self.node_type),
                sources=[
                    dm.NodeOrEdgeData(
                        source=self._view_id,
                        properties=properties,
                    )
                ],
            )
            resources.nodes.append(this_node)
            cache.add(self.as_tuple_id())

        return resources

BladeWriteList

Bases: DomainModelWriteList[BladeWrite]

List of blades in the writing version.

Source code in examples/wind_turbine/data_classes/_blade.py
class BladeWriteList(DomainModelWriteList[BladeWrite]):
    """List of blades in the writing version."""

    _INSTANCE = BladeWrite

DataSheet

Bases: DomainModel

This represents the reading version of data sheet.

It is used to when data is retrieved from CDF.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the data sheet.

required
data_record

The data record of the data sheet node.

required
description

Description of the instance

required
directory

Contains the path elements from the source (if the source system has a file system hierarchy or similar.)

required
is_uploaded

Specifies if the file content has been uploaded to Cognite Data Fusion or not.

required
mime_type

The MIME type of the file.

required
name

Name of the instance

required
uploaded_time

The time the file upload completed.

required
Source code in examples/wind_turbine/data_classes/_data_sheet.py
class DataSheet(DomainModel):
    """This represents the reading version of data sheet.

    It is used to when data is retrieved from CDF.

    Args:
        space: The space where the node is located.
        external_id: The external id of the data sheet.
        data_record: The data record of the data sheet node.
        description: Description of the instance
        directory: Contains the path elements from the source (if the source system has a file system hierarchy or similar.)
        is_uploaded: Specifies if the file content has been uploaded to Cognite Data Fusion or not.
        mime_type: The MIME type of the file.
        name: Name of the instance
        uploaded_time: The time the file upload completed.
    """

    _view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "DataSheet", "1")

    space: str = DEFAULT_INSTANCE_SPACE
    node_type: Union[dm.DirectRelationReference, None] = None
    description: Optional[str] = None
    directory: Optional[str] = None
    is_uploaded: Optional[bool] = Field(None, alias="isUploaded")
    mime_type: Optional[str] = Field(None, alias="mimeType")
    name: Optional[str] = None
    uploaded_time: Optional[datetime.datetime] = Field(None, alias="uploadedTime")

    def as_write(self) -> DataSheetWrite:
        """Convert this read version of data sheet to the writing version."""
        return DataSheetWrite(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecordWrite(existing_version=self.data_record.version),
            description=self.description,
            directory=self.directory,
            mime_type=self.mime_type,
            name=self.name,
        )

    def as_apply(self) -> DataSheetWrite:
        """Convert this read version of data sheet to the writing version."""
        warnings.warn(
            "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
            UserWarning,
            stacklevel=2,
        )
        return self.as_write()

as_apply()

Convert this read version of data sheet to the writing version.

Source code in examples/wind_turbine/data_classes/_data_sheet.py
def as_apply(self) -> DataSheetWrite:
    """Convert this read version of data sheet to the writing version."""
    warnings.warn(
        "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
        UserWarning,
        stacklevel=2,
    )
    return self.as_write()

as_write()

Convert this read version of data sheet to the writing version.

Source code in examples/wind_turbine/data_classes/_data_sheet.py
def as_write(self) -> DataSheetWrite:
    """Convert this read version of data sheet to the writing version."""
    return DataSheetWrite(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecordWrite(existing_version=self.data_record.version),
        description=self.description,
        directory=self.directory,
        mime_type=self.mime_type,
        name=self.name,
    )

DataSheetGraphQL

Bases: GraphQLCore

This represents the reading version of data sheet, used when data is retrieved from CDF using GraphQL.

It is used when retrieving data from CDF using GraphQL.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the data sheet.

required
data_record

The data record of the data sheet node.

required
description

Description of the instance

required
directory

Contains the path elements from the source (if the source system has a file system hierarchy or similar.)

required
is_uploaded

Specifies if the file content has been uploaded to Cognite Data Fusion or not.

required
mime_type

The MIME type of the file.

required
name

Name of the instance

required
uploaded_time

The time the file upload completed.

required
Source code in examples/wind_turbine/data_classes/_data_sheet.py
class DataSheetGraphQL(GraphQLCore):
    """This represents the reading version of data sheet, used
    when data is retrieved from CDF using GraphQL.

    It is used when retrieving data from CDF using GraphQL.

    Args:
        space: The space where the node is located.
        external_id: The external id of the data sheet.
        data_record: The data record of the data sheet node.
        description: Description of the instance
        directory: Contains the path elements from the source (if the source system has a file system hierarchy or similar.)
        is_uploaded: Specifies if the file content has been uploaded to Cognite Data Fusion or not.
        mime_type: The MIME type of the file.
        name: Name of the instance
        uploaded_time: The time the file upload completed.
    """

    view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "DataSheet", "1")
    description: Optional[str] = None
    directory: Optional[str] = None
    is_uploaded: Optional[bool] = Field(None, alias="isUploaded")
    mime_type: Optional[str] = Field(None, alias="mimeType")
    name: Optional[str] = None
    uploaded_time: Optional[datetime.datetime] = Field(None, alias="uploadedTime")

    @model_validator(mode="before")
    def parse_data_record(cls, values: Any) -> Any:
        if not isinstance(values, dict):
            return values
        if "lastUpdatedTime" in values or "createdTime" in values:
            values["dataRecord"] = DataRecordGraphQL(
                created_time=values.pop("createdTime", None),
                last_updated_time=values.pop("lastUpdatedTime", None),
            )
        return values

    # We do the ignore argument type as we let pydantic handle the type checking
    @no_type_check
    def as_read(self) -> DataSheet:
        """Convert this GraphQL format of data sheet to the reading format."""
        if self.data_record is None:
            raise ValueError("This object cannot be converted to a read format because it lacks a data record.")
        return DataSheet(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecord(
                version=0,
                last_updated_time=self.data_record.last_updated_time,
                created_time=self.data_record.created_time,
            ),
            description=self.description,
            directory=self.directory,
            is_uploaded=self.is_uploaded,
            mime_type=self.mime_type,
            name=self.name,
            uploaded_time=self.uploaded_time,
        )

    # We do the ignore argument type as we let pydantic handle the type checking
    @no_type_check
    def as_write(self) -> DataSheetWrite:
        """Convert this GraphQL format of data sheet to the writing format."""
        return DataSheetWrite(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecordWrite(existing_version=0),
            description=self.description,
            directory=self.directory,
            mime_type=self.mime_type,
            name=self.name,
        )

as_read()

Convert this GraphQL format of data sheet to the reading format.

Source code in examples/wind_turbine/data_classes/_data_sheet.py
@no_type_check
def as_read(self) -> DataSheet:
    """Convert this GraphQL format of data sheet to the reading format."""
    if self.data_record is None:
        raise ValueError("This object cannot be converted to a read format because it lacks a data record.")
    return DataSheet(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecord(
            version=0,
            last_updated_time=self.data_record.last_updated_time,
            created_time=self.data_record.created_time,
        ),
        description=self.description,
        directory=self.directory,
        is_uploaded=self.is_uploaded,
        mime_type=self.mime_type,
        name=self.name,
        uploaded_time=self.uploaded_time,
    )

as_write()

Convert this GraphQL format of data sheet to the writing format.

Source code in examples/wind_turbine/data_classes/_data_sheet.py
@no_type_check
def as_write(self) -> DataSheetWrite:
    """Convert this GraphQL format of data sheet to the writing format."""
    return DataSheetWrite(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecordWrite(existing_version=0),
        description=self.description,
        directory=self.directory,
        mime_type=self.mime_type,
        name=self.name,
    )

DataSheetList

Bases: DomainModelList[DataSheet]

List of data sheets in the read version.

Source code in examples/wind_turbine/data_classes/_data_sheet.py
class DataSheetList(DomainModelList[DataSheet]):
    """List of data sheets in the read version."""

    _INSTANCE = DataSheet

    def as_write(self) -> DataSheetWriteList:
        """Convert these read versions of data sheet to the writing versions."""
        return DataSheetWriteList([node.as_write() for node in self.data])

    def as_apply(self) -> DataSheetWriteList:
        """Convert these read versions of primitive nullable to the writing versions."""
        warnings.warn(
            "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
            UserWarning,
            stacklevel=2,
        )
        return self.as_write()

as_apply()

Convert these read versions of primitive nullable to the writing versions.

Source code in examples/wind_turbine/data_classes/_data_sheet.py
def as_apply(self) -> DataSheetWriteList:
    """Convert these read versions of primitive nullable to the writing versions."""
    warnings.warn(
        "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
        UserWarning,
        stacklevel=2,
    )
    return self.as_write()

as_write()

Convert these read versions of data sheet to the writing versions.

Source code in examples/wind_turbine/data_classes/_data_sheet.py
def as_write(self) -> DataSheetWriteList:
    """Convert these read versions of data sheet to the writing versions."""
    return DataSheetWriteList([node.as_write() for node in self.data])

DataSheetWrite

Bases: DomainModelWrite

This represents the writing version of data sheet.

It is used to when data is sent to CDF.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the data sheet.

required
data_record

The data record of the data sheet node.

required
description

Description of the instance

required
directory

Contains the path elements from the source (if the source system has a file system hierarchy or similar.)

required
mime_type

The MIME type of the file.

required
name

Name of the instance

required
Source code in examples/wind_turbine/data_classes/_data_sheet.py
class DataSheetWrite(DomainModelWrite):
    """This represents the writing version of data sheet.

    It is used to when data is sent to CDF.

    Args:
        space: The space where the node is located.
        external_id: The external id of the data sheet.
        data_record: The data record of the data sheet node.
        description: Description of the instance
        directory: Contains the path elements from the source (if the source system has a file system hierarchy or similar.)
        mime_type: The MIME type of the file.
        name: Name of the instance
    """

    _view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "DataSheet", "1")

    space: str = DEFAULT_INSTANCE_SPACE
    node_type: Union[dm.DirectRelationReference, dm.NodeId, tuple[str, str], None] = None
    description: Optional[str] = None
    directory: Optional[str] = None
    mime_type: Optional[str] = Field(None, alias="mimeType")
    name: Optional[str] = None

    def _to_instances_write(
        self,
        cache: set[tuple[str, str]],
        write_none: bool = False,
        allow_version_increase: bool = False,
    ) -> ResourcesWrite:
        resources = ResourcesWrite()
        if self.as_tuple_id() in cache:
            return resources

        properties: dict[str, Any] = {}

        if self.description is not None or write_none:
            properties["description"] = self.description

        if self.directory is not None or write_none:
            properties["directory"] = self.directory

        if self.is_uploaded is not None or write_none:
            properties["isUploaded"] = self.is_uploaded

        if self.mime_type is not None or write_none:
            properties["mimeType"] = self.mime_type

        if self.name is not None or write_none:
            properties["name"] = self.name

        if self.uploaded_time is not None or write_none:
            properties["uploadedTime"] = (
                self.uploaded_time.isoformat(timespec="milliseconds") if self.uploaded_time else None
            )

        if properties:
            this_node = dm.NodeApply(
                space=self.space,
                external_id=self.external_id,
                existing_version=None if allow_version_increase else self.data_record.existing_version,
                type=as_direct_relation_reference(self.node_type),
                sources=[
                    dm.NodeOrEdgeData(
                        source=self._view_id,
                        properties=properties,
                    )
                ],
            )
            resources.nodes.append(this_node)
            cache.add(self.as_tuple_id())

        return resources

DataSheetWriteList

Bases: DomainModelWriteList[DataSheetWrite]

List of data sheets in the writing version.

Source code in examples/wind_turbine/data_classes/_data_sheet.py
class DataSheetWriteList(DomainModelWriteList[DataSheetWrite]):
    """List of data sheets in the writing version."""

    _INSTANCE = DataSheetWrite

Distance

Bases: DomainRelation

This represents the reading version of distance.

It is used to when data is retrieved from CDF.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the distance.

required
data_record

The data record of the distance edge.

required
end_node

The end node of this edge.

required
distance

The distance field.

required
Source code in examples/wind_turbine/data_classes/_distance.py
class Distance(DomainRelation):
    """This represents the reading version of distance.

    It is used to when data is retrieved from CDF.

    Args:
        space: The space where the node is located.
        external_id: The external id of the distance.
        data_record: The data record of the distance edge.
        end_node: The end node of this edge.
        distance: The distance field.
    """

    _view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "Distance", "1")
    space: str = DEFAULT_INSTANCE_SPACE
    end_node: Union[Metmast, WindTurbine, str, dm.NodeId]
    distance: Optional[float] = None

    def as_write(self) -> DistanceWrite:
        """Convert this read version of distance to the writing version."""
        return DistanceWrite(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecordWrite(existing_version=self.data_record.version),
            end_node=self.end_node.as_write() if isinstance(self.end_node, DomainModel) else self.end_node,
            distance=self.distance,
        )

    def as_apply(self) -> DistanceWrite:
        """Convert this read version of distance to the writing version."""
        warnings.warn(
            "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
            UserWarning,
            stacklevel=2,
        )
        return self.as_write()

as_apply()

Convert this read version of distance to the writing version.

Source code in examples/wind_turbine/data_classes/_distance.py
def as_apply(self) -> DistanceWrite:
    """Convert this read version of distance to the writing version."""
    warnings.warn(
        "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
        UserWarning,
        stacklevel=2,
    )
    return self.as_write()

as_write()

Convert this read version of distance to the writing version.

Source code in examples/wind_turbine/data_classes/_distance.py
def as_write(self) -> DistanceWrite:
    """Convert this read version of distance to the writing version."""
    return DistanceWrite(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecordWrite(existing_version=self.data_record.version),
        end_node=self.end_node.as_write() if isinstance(self.end_node, DomainModel) else self.end_node,
        distance=self.distance,
    )

DistanceGraphQL

Bases: GraphQLCore

This represents the reading version of distance, used when data is retrieved from CDF using GraphQL.

It is used when retrieving data from CDF using GraphQL.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the distance.

required
data_record

The data record of the distance node.

required
end_node

The end node of this edge.

required
distance

The distance field.

required
Source code in examples/wind_turbine/data_classes/_distance.py
class DistanceGraphQL(GraphQLCore):
    """This represents the reading version of distance, used
    when data is retrieved from CDF using GraphQL.

    It is used when retrieving data from CDF using GraphQL.

    Args:
        space: The space where the node is located.
        external_id: The external id of the distance.
        data_record: The data record of the distance node.
        end_node: The end node of this edge.
        distance: The distance field.
    """

    view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "Distance", "1")
    end_node: Union[MetmastGraphQL, WindTurbineGraphQL, None] = None
    distance: Optional[float] = None

    # We do the ignore argument type as we let pydantic handle the type checking
    @no_type_check
    def as_read(self) -> Distance:
        """Convert this GraphQL format of distance to the reading format."""
        if self.data_record is None:
            raise ValueError("This object cannot be converted to a read format because it lacks a data record.")
        return Distance(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecord(
                version=0,
                last_updated_time=self.data_record.last_updated_time,
                created_time=self.data_record.created_time,
            ),
            end_node=self.end_node.as_read() if isinstance(self.end_node, GraphQLCore) else self.end_node,
            distance=self.distance,
        )

    # We do the ignore argument type as we let pydantic handle the type checking
    @no_type_check
    def as_write(self) -> DistanceWrite:
        """Convert this GraphQL format of distance to the writing format."""
        return DistanceWrite(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecordWrite(existing_version=0),
            end_node=self.end_node.as_write() if isinstance(self.end_node, DomainModel) else self.end_node,
            distance=self.distance,
        )

as_read()

Convert this GraphQL format of distance to the reading format.

Source code in examples/wind_turbine/data_classes/_distance.py
@no_type_check
def as_read(self) -> Distance:
    """Convert this GraphQL format of distance to the reading format."""
    if self.data_record is None:
        raise ValueError("This object cannot be converted to a read format because it lacks a data record.")
    return Distance(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecord(
            version=0,
            last_updated_time=self.data_record.last_updated_time,
            created_time=self.data_record.created_time,
        ),
        end_node=self.end_node.as_read() if isinstance(self.end_node, GraphQLCore) else self.end_node,
        distance=self.distance,
    )

as_write()

Convert this GraphQL format of distance to the writing format.

Source code in examples/wind_turbine/data_classes/_distance.py
@no_type_check
def as_write(self) -> DistanceWrite:
    """Convert this GraphQL format of distance to the writing format."""
    return DistanceWrite(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecordWrite(existing_version=0),
        end_node=self.end_node.as_write() if isinstance(self.end_node, DomainModel) else self.end_node,
        distance=self.distance,
    )

DistanceList

Bases: DomainRelationList[Distance]

List of distances in the reading version.

Source code in examples/wind_turbine/data_classes/_distance.py
class DistanceList(DomainRelationList[Distance]):
    """List of distances in the reading version."""

    _INSTANCE = Distance

    def as_write(self) -> DistanceWriteList:
        """Convert this read version of distance list to the writing version."""
        return DistanceWriteList([edge.as_write() for edge in self])

    def as_apply(self) -> DistanceWriteList:
        """Convert these read versions of distance list to the writing versions."""
        warnings.warn(
            "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
            UserWarning,
            stacklevel=2,
        )
        return self.as_write()

as_apply()

Convert these read versions of distance list to the writing versions.

Source code in examples/wind_turbine/data_classes/_distance.py
def as_apply(self) -> DistanceWriteList:
    """Convert these read versions of distance list to the writing versions."""
    warnings.warn(
        "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
        UserWarning,
        stacklevel=2,
    )
    return self.as_write()

as_write()

Convert this read version of distance list to the writing version.

Source code in examples/wind_turbine/data_classes/_distance.py
def as_write(self) -> DistanceWriteList:
    """Convert this read version of distance list to the writing version."""
    return DistanceWriteList([edge.as_write() for edge in self])

DistanceWrite

Bases: DomainRelationWrite

This represents the writing version of distance.

It is used to when data is sent to CDF.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the distance.

required
data_record

The data record of the distance edge.

required
end_node

The end node of this edge.

required
distance

The distance field.

required
Source code in examples/wind_turbine/data_classes/_distance.py
class DistanceWrite(DomainRelationWrite):
    """This represents the writing version of distance.

    It is used to when data is sent to CDF.

    Args:
        space: The space where the node is located.
        external_id: The external id of the distance.
        data_record: The data record of the distance edge.
        end_node: The end node of this edge.
        distance: The distance field.
    """

    _view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "Distance", "1")
    space: str = DEFAULT_INSTANCE_SPACE
    end_node: Union[MetmastWrite, WindTurbineWrite, str, dm.NodeId]
    distance: Optional[float] = None

    def _to_instances_write(
        self,
        cache: set[tuple[str, str]],
        start_node: DomainModelWrite,
        edge_type: dm.DirectRelationReference,
        write_none: bool = False,
        allow_version_increase: bool = False,
    ) -> ResourcesWrite:
        resources = ResourcesWrite()
        if self.external_id and (self.space, self.external_id) in cache:
            return resources

        _validate_end_node(start_node, self.end_node)

        if isinstance(self.end_node, DomainModelWrite):
            end_node = self.end_node.as_direct_reference()
        elif isinstance(self.end_node, str):
            end_node = dm.DirectRelationReference(self.space, self.end_node)
        elif isinstance(self.end_node, dm.NodeId):
            end_node = dm.DirectRelationReference(self.end_node.space, self.end_node.external_id)
        else:
            raise ValueError(f"Invalid type for equipment_module: {type(self.end_node)}")

        external_id = self.external_id or DomainRelationWrite.external_id_factory(start_node, self.end_node, edge_type)

        properties: dict[str, Any] = {}

        if self.distance is not None or write_none:
            properties["distance"] = self.distance

        if properties:
            this_edge = dm.EdgeApply(
                space=self.space,
                external_id=external_id,
                type=edge_type,
                start_node=start_node.as_direct_reference(),
                end_node=end_node,
                existing_version=None if allow_version_increase else self.data_record.existing_version,
                sources=[
                    dm.NodeOrEdgeData(
                        source=self._view_id,
                        properties=properties,
                    )
                ],
            )
            resources.edges.append(this_edge)
            cache.add((self.space, external_id))

        if isinstance(self.end_node, DomainModelWrite):
            other_resources = self.end_node._to_instances_write(cache)
            resources.extend(other_resources)

        return resources

DistanceWriteList

Bases: DomainRelationWriteList[DistanceWrite]

List of distances in the writing version.

Source code in examples/wind_turbine/data_classes/_distance.py
class DistanceWriteList(DomainRelationWriteList[DistanceWrite]):
    """List of distances in the writing version."""

    _INSTANCE = DistanceWrite

Gearbox

Bases: DomainModel

This represents the reading version of gearbox.

It is used to when data is retrieved from CDF.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the gearbox.

required
data_record

The data record of the gearbox node.

required
displacement_x

The displacement x field.

required
displacement_y

The displacement y field.

required
displacement_z

The displacement z field.

required
nacelle

The nacelle field.

required
Source code in examples/wind_turbine/data_classes/_gearbox.py
class Gearbox(DomainModel):
    """This represents the reading version of gearbox.

    It is used to when data is retrieved from CDF.

    Args:
        space: The space where the node is located.
        external_id: The external id of the gearbox.
        data_record: The data record of the gearbox node.
        displacement_x: The displacement x field.
        displacement_y: The displacement y field.
        displacement_z: The displacement z field.
        nacelle: The nacelle field.
    """

    _view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "Gearbox", "1")

    space: str = DEFAULT_INSTANCE_SPACE
    node_type: Union[dm.DirectRelationReference, None] = None
    displacement_x: Union[SensorTimeSeries, str, dm.NodeId, None] = Field(default=None, repr=False)
    displacement_y: Union[SensorTimeSeries, str, dm.NodeId, None] = Field(default=None, repr=False)
    displacement_z: Union[SensorTimeSeries, str, dm.NodeId, None] = Field(default=None, repr=False)
    nacelle: Optional[Nacelle] = Field(default=None, repr=False)

    def as_write(self) -> GearboxWrite:
        """Convert this read version of gearbox to the writing version."""
        return GearboxWrite(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecordWrite(existing_version=self.data_record.version),
            displacement_x=(
                self.displacement_x.as_write() if isinstance(self.displacement_x, DomainModel) else self.displacement_x
            ),
            displacement_y=(
                self.displacement_y.as_write() if isinstance(self.displacement_y, DomainModel) else self.displacement_y
            ),
            displacement_z=(
                self.displacement_z.as_write() if isinstance(self.displacement_z, DomainModel) else self.displacement_z
            ),
        )

    def as_apply(self) -> GearboxWrite:
        """Convert this read version of gearbox to the writing version."""
        warnings.warn(
            "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
            UserWarning,
            stacklevel=2,
        )
        return self.as_write()

    @classmethod
    def _update_connections(
        cls,
        instances: dict[dm.NodeId | str, Gearbox],  # type: ignore[override]
        nodes_by_id: dict[dm.NodeId | str, DomainModel],
        edges_by_source_node: dict[dm.NodeId, list[dm.Edge | DomainRelation]],
    ) -> None:
        from ._nacelle import Nacelle
        from ._sensor_time_series import SensorTimeSeries

        for instance in instances.values():
            if (
                isinstance(instance.displacement_x, (dm.NodeId, str))
                and (displacement_x := nodes_by_id.get(instance.displacement_x))
                and isinstance(displacement_x, SensorTimeSeries)
            ):
                instance.displacement_x = displacement_x
            if (
                isinstance(instance.displacement_y, (dm.NodeId, str))
                and (displacement_y := nodes_by_id.get(instance.displacement_y))
                and isinstance(displacement_y, SensorTimeSeries)
            ):
                instance.displacement_y = displacement_y
            if (
                isinstance(instance.displacement_z, (dm.NodeId, str))
                and (displacement_z := nodes_by_id.get(instance.displacement_z))
                and isinstance(displacement_z, SensorTimeSeries)
            ):
                instance.displacement_z = displacement_z
        for node in nodes_by_id.values():
            if (
                isinstance(node, Nacelle)
                and node.gearbox is not None
                and (gearbox := instances.get(as_pygen_node_id(node.gearbox)))
            ):
                if gearbox.nacelle is None:
                    gearbox.nacelle = node
                elif are_nodes_equal(node, gearbox.nacelle):
                    # This is the same node, so we don't need to do anything...
                    ...
                else:
                    warnings.warn(
                        f"Expected one direct relation for 'nacelle' in {gearbox.as_id()}."
                        f"Ignoring new relation {node!s} in favor of {gearbox.nacelle!s}."
                    )

as_apply()

Convert this read version of gearbox to the writing version.

Source code in examples/wind_turbine/data_classes/_gearbox.py
def as_apply(self) -> GearboxWrite:
    """Convert this read version of gearbox to the writing version."""
    warnings.warn(
        "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
        UserWarning,
        stacklevel=2,
    )
    return self.as_write()

as_write()

Convert this read version of gearbox to the writing version.

Source code in examples/wind_turbine/data_classes/_gearbox.py
def as_write(self) -> GearboxWrite:
    """Convert this read version of gearbox to the writing version."""
    return GearboxWrite(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecordWrite(existing_version=self.data_record.version),
        displacement_x=(
            self.displacement_x.as_write() if isinstance(self.displacement_x, DomainModel) else self.displacement_x
        ),
        displacement_y=(
            self.displacement_y.as_write() if isinstance(self.displacement_y, DomainModel) else self.displacement_y
        ),
        displacement_z=(
            self.displacement_z.as_write() if isinstance(self.displacement_z, DomainModel) else self.displacement_z
        ),
    )

GearboxGraphQL

Bases: GraphQLCore

This represents the reading version of gearbox, used when data is retrieved from CDF using GraphQL.

It is used when retrieving data from CDF using GraphQL.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the gearbox.

required
data_record

The data record of the gearbox node.

required
displacement_x

The displacement x field.

required
displacement_y

The displacement y field.

required
displacement_z

The displacement z field.

required
nacelle

The nacelle field.

required
Source code in examples/wind_turbine/data_classes/_gearbox.py
class GearboxGraphQL(GraphQLCore):
    """This represents the reading version of gearbox, used
    when data is retrieved from CDF using GraphQL.

    It is used when retrieving data from CDF using GraphQL.

    Args:
        space: The space where the node is located.
        external_id: The external id of the gearbox.
        data_record: The data record of the gearbox node.
        displacement_x: The displacement x field.
        displacement_y: The displacement y field.
        displacement_z: The displacement z field.
        nacelle: The nacelle field.
    """

    view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "Gearbox", "1")
    displacement_x: Optional[SensorTimeSeriesGraphQL] = Field(default=None, repr=False)
    displacement_y: Optional[SensorTimeSeriesGraphQL] = Field(default=None, repr=False)
    displacement_z: Optional[SensorTimeSeriesGraphQL] = Field(default=None, repr=False)
    nacelle: Optional[NacelleGraphQL] = Field(default=None, repr=False)

    @model_validator(mode="before")
    def parse_data_record(cls, values: Any) -> Any:
        if not isinstance(values, dict):
            return values
        if "lastUpdatedTime" in values or "createdTime" in values:
            values["dataRecord"] = DataRecordGraphQL(
                created_time=values.pop("createdTime", None),
                last_updated_time=values.pop("lastUpdatedTime", None),
            )
        return values

    @field_validator("displacement_x", "displacement_y", "displacement_z", "nacelle", mode="before")
    def parse_graphql(cls, value: Any) -> Any:
        if not isinstance(value, dict):
            return value
        if "items" in value:
            return value["items"]
        return value

    # We do the ignore argument type as we let pydantic handle the type checking
    @no_type_check
    def as_read(self) -> Gearbox:
        """Convert this GraphQL format of gearbox to the reading format."""
        if self.data_record is None:
            raise ValueError("This object cannot be converted to a read format because it lacks a data record.")
        return Gearbox(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecord(
                version=0,
                last_updated_time=self.data_record.last_updated_time,
                created_time=self.data_record.created_time,
            ),
            displacement_x=(
                self.displacement_x.as_read() if isinstance(self.displacement_x, GraphQLCore) else self.displacement_x
            ),
            displacement_y=(
                self.displacement_y.as_read() if isinstance(self.displacement_y, GraphQLCore) else self.displacement_y
            ),
            displacement_z=(
                self.displacement_z.as_read() if isinstance(self.displacement_z, GraphQLCore) else self.displacement_z
            ),
            nacelle=self.nacelle.as_read() if isinstance(self.nacelle, GraphQLCore) else self.nacelle,
        )

    # We do the ignore argument type as we let pydantic handle the type checking
    @no_type_check
    def as_write(self) -> GearboxWrite:
        """Convert this GraphQL format of gearbox to the writing format."""
        return GearboxWrite(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecordWrite(existing_version=0),
            displacement_x=(
                self.displacement_x.as_write() if isinstance(self.displacement_x, GraphQLCore) else self.displacement_x
            ),
            displacement_y=(
                self.displacement_y.as_write() if isinstance(self.displacement_y, GraphQLCore) else self.displacement_y
            ),
            displacement_z=(
                self.displacement_z.as_write() if isinstance(self.displacement_z, GraphQLCore) else self.displacement_z
            ),
        )

as_read()

Convert this GraphQL format of gearbox to the reading format.

Source code in examples/wind_turbine/data_classes/_gearbox.py
@no_type_check
def as_read(self) -> Gearbox:
    """Convert this GraphQL format of gearbox to the reading format."""
    if self.data_record is None:
        raise ValueError("This object cannot be converted to a read format because it lacks a data record.")
    return Gearbox(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecord(
            version=0,
            last_updated_time=self.data_record.last_updated_time,
            created_time=self.data_record.created_time,
        ),
        displacement_x=(
            self.displacement_x.as_read() if isinstance(self.displacement_x, GraphQLCore) else self.displacement_x
        ),
        displacement_y=(
            self.displacement_y.as_read() if isinstance(self.displacement_y, GraphQLCore) else self.displacement_y
        ),
        displacement_z=(
            self.displacement_z.as_read() if isinstance(self.displacement_z, GraphQLCore) else self.displacement_z
        ),
        nacelle=self.nacelle.as_read() if isinstance(self.nacelle, GraphQLCore) else self.nacelle,
    )

as_write()

Convert this GraphQL format of gearbox to the writing format.

Source code in examples/wind_turbine/data_classes/_gearbox.py
@no_type_check
def as_write(self) -> GearboxWrite:
    """Convert this GraphQL format of gearbox to the writing format."""
    return GearboxWrite(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecordWrite(existing_version=0),
        displacement_x=(
            self.displacement_x.as_write() if isinstance(self.displacement_x, GraphQLCore) else self.displacement_x
        ),
        displacement_y=(
            self.displacement_y.as_write() if isinstance(self.displacement_y, GraphQLCore) else self.displacement_y
        ),
        displacement_z=(
            self.displacement_z.as_write() if isinstance(self.displacement_z, GraphQLCore) else self.displacement_z
        ),
    )

GearboxList

Bases: DomainModelList[Gearbox]

List of gearboxes in the read version.

Source code in examples/wind_turbine/data_classes/_gearbox.py
class GearboxList(DomainModelList[Gearbox]):
    """List of gearboxes in the read version."""

    _INSTANCE = Gearbox

    def as_write(self) -> GearboxWriteList:
        """Convert these read versions of gearbox to the writing versions."""
        return GearboxWriteList([node.as_write() for node in self.data])

    def as_apply(self) -> GearboxWriteList:
        """Convert these read versions of primitive nullable to the writing versions."""
        warnings.warn(
            "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
            UserWarning,
            stacklevel=2,
        )
        return self.as_write()

    @property
    def displacement_x(self) -> SensorTimeSeriesList:
        from ._sensor_time_series import SensorTimeSeries, SensorTimeSeriesList

        return SensorTimeSeriesList(
            [item.displacement_x for item in self.data if isinstance(item.displacement_x, SensorTimeSeries)]
        )

    @property
    def displacement_y(self) -> SensorTimeSeriesList:
        from ._sensor_time_series import SensorTimeSeries, SensorTimeSeriesList

        return SensorTimeSeriesList(
            [item.displacement_y for item in self.data if isinstance(item.displacement_y, SensorTimeSeries)]
        )

    @property
    def displacement_z(self) -> SensorTimeSeriesList:
        from ._sensor_time_series import SensorTimeSeries, SensorTimeSeriesList

        return SensorTimeSeriesList(
            [item.displacement_z for item in self.data if isinstance(item.displacement_z, SensorTimeSeries)]
        )

    @property
    def nacelle(self) -> NacelleList:
        from ._nacelle import Nacelle, NacelleList

        return NacelleList([item.nacelle for item in self.data if isinstance(item.nacelle, Nacelle)])

as_apply()

Convert these read versions of primitive nullable to the writing versions.

Source code in examples/wind_turbine/data_classes/_gearbox.py
def as_apply(self) -> GearboxWriteList:
    """Convert these read versions of primitive nullable to the writing versions."""
    warnings.warn(
        "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
        UserWarning,
        stacklevel=2,
    )
    return self.as_write()

as_write()

Convert these read versions of gearbox to the writing versions.

Source code in examples/wind_turbine/data_classes/_gearbox.py
def as_write(self) -> GearboxWriteList:
    """Convert these read versions of gearbox to the writing versions."""
    return GearboxWriteList([node.as_write() for node in self.data])

GearboxWrite

Bases: DomainModelWrite

This represents the writing version of gearbox.

It is used to when data is sent to CDF.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the gearbox.

required
data_record

The data record of the gearbox node.

required
displacement_x

The displacement x field.

required
displacement_y

The displacement y field.

required
displacement_z

The displacement z field.

required
Source code in examples/wind_turbine/data_classes/_gearbox.py
class GearboxWrite(DomainModelWrite):
    """This represents the writing version of gearbox.

    It is used to when data is sent to CDF.

    Args:
        space: The space where the node is located.
        external_id: The external id of the gearbox.
        data_record: The data record of the gearbox node.
        displacement_x: The displacement x field.
        displacement_y: The displacement y field.
        displacement_z: The displacement z field.
    """

    _view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "Gearbox", "1")

    space: str = DEFAULT_INSTANCE_SPACE
    node_type: Union[dm.DirectRelationReference, dm.NodeId, tuple[str, str], None] = None
    displacement_x: Union[SensorTimeSeriesWrite, str, dm.NodeId, None] = Field(default=None, repr=False)
    displacement_y: Union[SensorTimeSeriesWrite, str, dm.NodeId, None] = Field(default=None, repr=False)
    displacement_z: Union[SensorTimeSeriesWrite, str, dm.NodeId, None] = Field(default=None, repr=False)

    @field_validator("displacement_x", "displacement_y", "displacement_z", mode="before")
    def as_node_id(cls, value: Any) -> Any:
        if isinstance(value, dm.DirectRelationReference):
            return dm.NodeId(value.space, value.external_id)
        elif isinstance(value, tuple) and len(value) == 2 and all(isinstance(item, str) for item in value):
            return dm.NodeId(value[0], value[1])
        elif isinstance(value, list):
            return [cls.as_node_id(item) for item in value]
        return value

    def _to_instances_write(
        self,
        cache: set[tuple[str, str]],
        write_none: bool = False,
        allow_version_increase: bool = False,
    ) -> ResourcesWrite:
        resources = ResourcesWrite()
        if self.as_tuple_id() in cache:
            return resources

        properties: dict[str, Any] = {}

        if self.displacement_x is not None:
            properties["displacement_x"] = {
                "space": self.space if isinstance(self.displacement_x, str) else self.displacement_x.space,
                "externalId": (
                    self.displacement_x if isinstance(self.displacement_x, str) else self.displacement_x.external_id
                ),
            }

        if self.displacement_y is not None:
            properties["displacement_y"] = {
                "space": self.space if isinstance(self.displacement_y, str) else self.displacement_y.space,
                "externalId": (
                    self.displacement_y if isinstance(self.displacement_y, str) else self.displacement_y.external_id
                ),
            }

        if self.displacement_z is not None:
            properties["displacement_z"] = {
                "space": self.space if isinstance(self.displacement_z, str) else self.displacement_z.space,
                "externalId": (
                    self.displacement_z if isinstance(self.displacement_z, str) else self.displacement_z.external_id
                ),
            }

        if properties:
            this_node = dm.NodeApply(
                space=self.space,
                external_id=self.external_id,
                existing_version=None if allow_version_increase else self.data_record.existing_version,
                type=as_direct_relation_reference(self.node_type),
                sources=[
                    dm.NodeOrEdgeData(
                        source=self._view_id,
                        properties=properties,
                    )
                ],
            )
            resources.nodes.append(this_node)
            cache.add(self.as_tuple_id())

        if isinstance(self.displacement_x, DomainModelWrite):
            other_resources = self.displacement_x._to_instances_write(cache)
            resources.extend(other_resources)

        if isinstance(self.displacement_y, DomainModelWrite):
            other_resources = self.displacement_y._to_instances_write(cache)
            resources.extend(other_resources)

        if isinstance(self.displacement_z, DomainModelWrite):
            other_resources = self.displacement_z._to_instances_write(cache)
            resources.extend(other_resources)

        return resources

GearboxWriteList

Bases: DomainModelWriteList[GearboxWrite]

List of gearboxes in the writing version.

Source code in examples/wind_turbine/data_classes/_gearbox.py
class GearboxWriteList(DomainModelWriteList[GearboxWrite]):
    """List of gearboxes in the writing version."""

    _INSTANCE = GearboxWrite

    @property
    def displacement_x(self) -> SensorTimeSeriesWriteList:
        from ._sensor_time_series import SensorTimeSeriesWrite, SensorTimeSeriesWriteList

        return SensorTimeSeriesWriteList(
            [item.displacement_x for item in self.data if isinstance(item.displacement_x, SensorTimeSeriesWrite)]
        )

    @property
    def displacement_y(self) -> SensorTimeSeriesWriteList:
        from ._sensor_time_series import SensorTimeSeriesWrite, SensorTimeSeriesWriteList

        return SensorTimeSeriesWriteList(
            [item.displacement_y for item in self.data if isinstance(item.displacement_y, SensorTimeSeriesWrite)]
        )

    @property
    def displacement_z(self) -> SensorTimeSeriesWriteList:
        from ._sensor_time_series import SensorTimeSeriesWrite, SensorTimeSeriesWriteList

        return SensorTimeSeriesWriteList(
            [item.displacement_z for item in self.data if isinstance(item.displacement_z, SensorTimeSeriesWrite)]
        )

GeneratingUnit

Bases: DomainModel

This represents the reading version of generating unit.

It is used to when data is retrieved from CDF.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the generating unit.

required
data_record

The data record of the generating unit node.

required
capacity

The capacity field.

required
description

Description of the instance

required
name

Name of the instance

required
Source code in examples/wind_turbine/data_classes/_generating_unit.py
class GeneratingUnit(DomainModel):
    """This represents the reading version of generating unit.

    It is used to when data is retrieved from CDF.

    Args:
        space: The space where the node is located.
        external_id: The external id of the generating unit.
        data_record: The data record of the generating unit node.
        capacity: The capacity field.
        description: Description of the instance
        name: Name of the instance
    """

    _view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "GeneratingUnit", "1")

    space: str = DEFAULT_INSTANCE_SPACE
    node_type: Union[dm.DirectRelationReference, None] = None
    capacity: Optional[float] = None
    description: Optional[str] = None
    name: Optional[str] = None

    def as_write(self) -> GeneratingUnitWrite:
        """Convert this read version of generating unit to the writing version."""
        return GeneratingUnitWrite(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecordWrite(existing_version=self.data_record.version),
            capacity=self.capacity,
            description=self.description,
            name=self.name,
        )

    def as_apply(self) -> GeneratingUnitWrite:
        """Convert this read version of generating unit to the writing version."""
        warnings.warn(
            "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
            UserWarning,
            stacklevel=2,
        )
        return self.as_write()

as_apply()

Convert this read version of generating unit to the writing version.

Source code in examples/wind_turbine/data_classes/_generating_unit.py
def as_apply(self) -> GeneratingUnitWrite:
    """Convert this read version of generating unit to the writing version."""
    warnings.warn(
        "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
        UserWarning,
        stacklevel=2,
    )
    return self.as_write()

as_write()

Convert this read version of generating unit to the writing version.

Source code in examples/wind_turbine/data_classes/_generating_unit.py
def as_write(self) -> GeneratingUnitWrite:
    """Convert this read version of generating unit to the writing version."""
    return GeneratingUnitWrite(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecordWrite(existing_version=self.data_record.version),
        capacity=self.capacity,
        description=self.description,
        name=self.name,
    )

GeneratingUnitGraphQL

Bases: GraphQLCore

This represents the reading version of generating unit, used when data is retrieved from CDF using GraphQL.

It is used when retrieving data from CDF using GraphQL.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the generating unit.

required
data_record

The data record of the generating unit node.

required
capacity

The capacity field.

required
description

Description of the instance

required
name

Name of the instance

required
Source code in examples/wind_turbine/data_classes/_generating_unit.py
class GeneratingUnitGraphQL(GraphQLCore):
    """This represents the reading version of generating unit, used
    when data is retrieved from CDF using GraphQL.

    It is used when retrieving data from CDF using GraphQL.

    Args:
        space: The space where the node is located.
        external_id: The external id of the generating unit.
        data_record: The data record of the generating unit node.
        capacity: The capacity field.
        description: Description of the instance
        name: Name of the instance
    """

    view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "GeneratingUnit", "1")
    capacity: Optional[float] = None
    description: Optional[str] = None
    name: Optional[str] = None

    @model_validator(mode="before")
    def parse_data_record(cls, values: Any) -> Any:
        if not isinstance(values, dict):
            return values
        if "lastUpdatedTime" in values or "createdTime" in values:
            values["dataRecord"] = DataRecordGraphQL(
                created_time=values.pop("createdTime", None),
                last_updated_time=values.pop("lastUpdatedTime", None),
            )
        return values

    # We do the ignore argument type as we let pydantic handle the type checking
    @no_type_check
    def as_read(self) -> GeneratingUnit:
        """Convert this GraphQL format of generating unit to the reading format."""
        if self.data_record is None:
            raise ValueError("This object cannot be converted to a read format because it lacks a data record.")
        return GeneratingUnit(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecord(
                version=0,
                last_updated_time=self.data_record.last_updated_time,
                created_time=self.data_record.created_time,
            ),
            capacity=self.capacity,
            description=self.description,
            name=self.name,
        )

    # We do the ignore argument type as we let pydantic handle the type checking
    @no_type_check
    def as_write(self) -> GeneratingUnitWrite:
        """Convert this GraphQL format of generating unit to the writing format."""
        return GeneratingUnitWrite(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecordWrite(existing_version=0),
            capacity=self.capacity,
            description=self.description,
            name=self.name,
        )

as_read()

Convert this GraphQL format of generating unit to the reading format.

Source code in examples/wind_turbine/data_classes/_generating_unit.py
@no_type_check
def as_read(self) -> GeneratingUnit:
    """Convert this GraphQL format of generating unit to the reading format."""
    if self.data_record is None:
        raise ValueError("This object cannot be converted to a read format because it lacks a data record.")
    return GeneratingUnit(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecord(
            version=0,
            last_updated_time=self.data_record.last_updated_time,
            created_time=self.data_record.created_time,
        ),
        capacity=self.capacity,
        description=self.description,
        name=self.name,
    )

as_write()

Convert this GraphQL format of generating unit to the writing format.

Source code in examples/wind_turbine/data_classes/_generating_unit.py
@no_type_check
def as_write(self) -> GeneratingUnitWrite:
    """Convert this GraphQL format of generating unit to the writing format."""
    return GeneratingUnitWrite(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecordWrite(existing_version=0),
        capacity=self.capacity,
        description=self.description,
        name=self.name,
    )

GeneratingUnitList

Bases: DomainModelList[GeneratingUnit]

List of generating units in the read version.

Source code in examples/wind_turbine/data_classes/_generating_unit.py
class GeneratingUnitList(DomainModelList[GeneratingUnit]):
    """List of generating units in the read version."""

    _INSTANCE = GeneratingUnit

    def as_write(self) -> GeneratingUnitWriteList:
        """Convert these read versions of generating unit to the writing versions."""
        return GeneratingUnitWriteList([node.as_write() for node in self.data])

    def as_apply(self) -> GeneratingUnitWriteList:
        """Convert these read versions of primitive nullable to the writing versions."""
        warnings.warn(
            "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
            UserWarning,
            stacklevel=2,
        )
        return self.as_write()

as_apply()

Convert these read versions of primitive nullable to the writing versions.

Source code in examples/wind_turbine/data_classes/_generating_unit.py
def as_apply(self) -> GeneratingUnitWriteList:
    """Convert these read versions of primitive nullable to the writing versions."""
    warnings.warn(
        "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
        UserWarning,
        stacklevel=2,
    )
    return self.as_write()

as_write()

Convert these read versions of generating unit to the writing versions.

Source code in examples/wind_turbine/data_classes/_generating_unit.py
def as_write(self) -> GeneratingUnitWriteList:
    """Convert these read versions of generating unit to the writing versions."""
    return GeneratingUnitWriteList([node.as_write() for node in self.data])

GeneratingUnitWrite

Bases: DomainModelWrite

This represents the writing version of generating unit.

It is used to when data is sent to CDF.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the generating unit.

required
data_record

The data record of the generating unit node.

required
capacity

The capacity field.

required
description

Description of the instance

required
name

Name of the instance

required
Source code in examples/wind_turbine/data_classes/_generating_unit.py
class GeneratingUnitWrite(DomainModelWrite):
    """This represents the writing version of generating unit.

    It is used to when data is sent to CDF.

    Args:
        space: The space where the node is located.
        external_id: The external id of the generating unit.
        data_record: The data record of the generating unit node.
        capacity: The capacity field.
        description: Description of the instance
        name: Name of the instance
    """

    _view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "GeneratingUnit", "1")

    space: str = DEFAULT_INSTANCE_SPACE
    node_type: Union[dm.DirectRelationReference, dm.NodeId, tuple[str, str], None] = None
    capacity: Optional[float] = None
    description: Optional[str] = None
    name: Optional[str] = None

    def _to_instances_write(
        self,
        cache: set[tuple[str, str]],
        write_none: bool = False,
        allow_version_increase: bool = False,
    ) -> ResourcesWrite:
        resources = ResourcesWrite()
        if self.as_tuple_id() in cache:
            return resources

        properties: dict[str, Any] = {}

        if self.capacity is not None or write_none:
            properties["capacity"] = self.capacity

        if self.description is not None or write_none:
            properties["description"] = self.description

        if self.name is not None or write_none:
            properties["name"] = self.name

        if properties:
            this_node = dm.NodeApply(
                space=self.space,
                external_id=self.external_id,
                existing_version=None if allow_version_increase else self.data_record.existing_version,
                type=as_direct_relation_reference(self.node_type),
                sources=[
                    dm.NodeOrEdgeData(
                        source=self._view_id,
                        properties=properties,
                    )
                ],
            )
            resources.nodes.append(this_node)
            cache.add(self.as_tuple_id())

        return resources

GeneratingUnitWriteList

Bases: DomainModelWriteList[GeneratingUnitWrite]

List of generating units in the writing version.

Source code in examples/wind_turbine/data_classes/_generating_unit.py
class GeneratingUnitWriteList(DomainModelWriteList[GeneratingUnitWrite]):
    """List of generating units in the writing version."""

    _INSTANCE = GeneratingUnitWrite

Generator

Bases: DomainModel

This represents the reading version of generator.

It is used to when data is retrieved from CDF.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the generator.

required
data_record

The data record of the generator node.

required
generator_speed_controller

The generator speed controller field.

required
generator_speed_controller_reference

The generator speed controller reference field.

required
nacelle

The nacelle field.

required
Source code in examples/wind_turbine/data_classes/_generator.py
class Generator(DomainModel):
    """This represents the reading version of generator.

    It is used to when data is retrieved from CDF.

    Args:
        space: The space where the node is located.
        external_id: The external id of the generator.
        data_record: The data record of the generator node.
        generator_speed_controller: The generator speed controller field.
        generator_speed_controller_reference: The generator speed controller reference field.
        nacelle: The nacelle field.
    """

    _view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "Generator", "1")

    space: str = DEFAULT_INSTANCE_SPACE
    node_type: Union[dm.DirectRelationReference, None] = None
    generator_speed_controller: Union[SensorTimeSeries, str, dm.NodeId, None] = Field(default=None, repr=False)
    generator_speed_controller_reference: Union[SensorTimeSeries, str, dm.NodeId, None] = Field(
        default=None, repr=False
    )
    nacelle: Optional[Nacelle] = Field(default=None, repr=False)

    def as_write(self) -> GeneratorWrite:
        """Convert this read version of generator to the writing version."""
        return GeneratorWrite(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecordWrite(existing_version=self.data_record.version),
            generator_speed_controller=(
                self.generator_speed_controller.as_write()
                if isinstance(self.generator_speed_controller, DomainModel)
                else self.generator_speed_controller
            ),
            generator_speed_controller_reference=(
                self.generator_speed_controller_reference.as_write()
                if isinstance(self.generator_speed_controller_reference, DomainModel)
                else self.generator_speed_controller_reference
            ),
        )

    def as_apply(self) -> GeneratorWrite:
        """Convert this read version of generator to the writing version."""
        warnings.warn(
            "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
            UserWarning,
            stacklevel=2,
        )
        return self.as_write()

    @classmethod
    def _update_connections(
        cls,
        instances: dict[dm.NodeId | str, Generator],  # type: ignore[override]
        nodes_by_id: dict[dm.NodeId | str, DomainModel],
        edges_by_source_node: dict[dm.NodeId, list[dm.Edge | DomainRelation]],
    ) -> None:
        from ._nacelle import Nacelle
        from ._sensor_time_series import SensorTimeSeries

        for instance in instances.values():
            if (
                isinstance(instance.generator_speed_controller, (dm.NodeId, str))
                and (generator_speed_controller := nodes_by_id.get(instance.generator_speed_controller))
                and isinstance(generator_speed_controller, SensorTimeSeries)
            ):
                instance.generator_speed_controller = generator_speed_controller
            if (
                isinstance(instance.generator_speed_controller_reference, (dm.NodeId, str))
                and (
                    generator_speed_controller_reference := nodes_by_id.get(
                        instance.generator_speed_controller_reference
                    )
                )
                and isinstance(generator_speed_controller_reference, SensorTimeSeries)
            ):
                instance.generator_speed_controller_reference = generator_speed_controller_reference
        for node in nodes_by_id.values():
            if (
                isinstance(node, Nacelle)
                and node.main_shaft is not None
                and (main_shaft := instances.get(as_pygen_node_id(node.main_shaft)))
            ):
                if main_shaft.nacelle is None:
                    main_shaft.nacelle = node
                elif are_nodes_equal(node, main_shaft.nacelle):
                    # This is the same node, so we don't need to do anything...
                    ...
                else:
                    warnings.warn(
                        f"Expected one direct relation for 'nacelle' in {main_shaft.as_id()}."
                        f"Ignoring new relation {node!s} in favor of {main_shaft.nacelle!s}."
                    )

as_apply()

Convert this read version of generator to the writing version.

Source code in examples/wind_turbine/data_classes/_generator.py
def as_apply(self) -> GeneratorWrite:
    """Convert this read version of generator to the writing version."""
    warnings.warn(
        "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
        UserWarning,
        stacklevel=2,
    )
    return self.as_write()

as_write()

Convert this read version of generator to the writing version.

Source code in examples/wind_turbine/data_classes/_generator.py
def as_write(self) -> GeneratorWrite:
    """Convert this read version of generator to the writing version."""
    return GeneratorWrite(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecordWrite(existing_version=self.data_record.version),
        generator_speed_controller=(
            self.generator_speed_controller.as_write()
            if isinstance(self.generator_speed_controller, DomainModel)
            else self.generator_speed_controller
        ),
        generator_speed_controller_reference=(
            self.generator_speed_controller_reference.as_write()
            if isinstance(self.generator_speed_controller_reference, DomainModel)
            else self.generator_speed_controller_reference
        ),
    )

GeneratorGraphQL

Bases: GraphQLCore

This represents the reading version of generator, used when data is retrieved from CDF using GraphQL.

It is used when retrieving data from CDF using GraphQL.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the generator.

required
data_record

The data record of the generator node.

required
generator_speed_controller

The generator speed controller field.

required
generator_speed_controller_reference

The generator speed controller reference field.

required
nacelle

The nacelle field.

required
Source code in examples/wind_turbine/data_classes/_generator.py
class GeneratorGraphQL(GraphQLCore):
    """This represents the reading version of generator, used
    when data is retrieved from CDF using GraphQL.

    It is used when retrieving data from CDF using GraphQL.

    Args:
        space: The space where the node is located.
        external_id: The external id of the generator.
        data_record: The data record of the generator node.
        generator_speed_controller: The generator speed controller field.
        generator_speed_controller_reference: The generator speed controller reference field.
        nacelle: The nacelle field.
    """

    view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "Generator", "1")
    generator_speed_controller: Optional[SensorTimeSeriesGraphQL] = Field(default=None, repr=False)
    generator_speed_controller_reference: Optional[SensorTimeSeriesGraphQL] = Field(default=None, repr=False)
    nacelle: Optional[NacelleGraphQL] = Field(default=None, repr=False)

    @model_validator(mode="before")
    def parse_data_record(cls, values: Any) -> Any:
        if not isinstance(values, dict):
            return values
        if "lastUpdatedTime" in values or "createdTime" in values:
            values["dataRecord"] = DataRecordGraphQL(
                created_time=values.pop("createdTime", None),
                last_updated_time=values.pop("lastUpdatedTime", None),
            )
        return values

    @field_validator("generator_speed_controller", "generator_speed_controller_reference", "nacelle", mode="before")
    def parse_graphql(cls, value: Any) -> Any:
        if not isinstance(value, dict):
            return value
        if "items" in value:
            return value["items"]
        return value

    # We do the ignore argument type as we let pydantic handle the type checking
    @no_type_check
    def as_read(self) -> Generator:
        """Convert this GraphQL format of generator to the reading format."""
        if self.data_record is None:
            raise ValueError("This object cannot be converted to a read format because it lacks a data record.")
        return Generator(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecord(
                version=0,
                last_updated_time=self.data_record.last_updated_time,
                created_time=self.data_record.created_time,
            ),
            generator_speed_controller=(
                self.generator_speed_controller.as_read()
                if isinstance(self.generator_speed_controller, GraphQLCore)
                else self.generator_speed_controller
            ),
            generator_speed_controller_reference=(
                self.generator_speed_controller_reference.as_read()
                if isinstance(self.generator_speed_controller_reference, GraphQLCore)
                else self.generator_speed_controller_reference
            ),
            nacelle=self.nacelle.as_read() if isinstance(self.nacelle, GraphQLCore) else self.nacelle,
        )

    # We do the ignore argument type as we let pydantic handle the type checking
    @no_type_check
    def as_write(self) -> GeneratorWrite:
        """Convert this GraphQL format of generator to the writing format."""
        return GeneratorWrite(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecordWrite(existing_version=0),
            generator_speed_controller=(
                self.generator_speed_controller.as_write()
                if isinstance(self.generator_speed_controller, GraphQLCore)
                else self.generator_speed_controller
            ),
            generator_speed_controller_reference=(
                self.generator_speed_controller_reference.as_write()
                if isinstance(self.generator_speed_controller_reference, GraphQLCore)
                else self.generator_speed_controller_reference
            ),
        )

as_read()

Convert this GraphQL format of generator to the reading format.

Source code in examples/wind_turbine/data_classes/_generator.py
@no_type_check
def as_read(self) -> Generator:
    """Convert this GraphQL format of generator to the reading format."""
    if self.data_record is None:
        raise ValueError("This object cannot be converted to a read format because it lacks a data record.")
    return Generator(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecord(
            version=0,
            last_updated_time=self.data_record.last_updated_time,
            created_time=self.data_record.created_time,
        ),
        generator_speed_controller=(
            self.generator_speed_controller.as_read()
            if isinstance(self.generator_speed_controller, GraphQLCore)
            else self.generator_speed_controller
        ),
        generator_speed_controller_reference=(
            self.generator_speed_controller_reference.as_read()
            if isinstance(self.generator_speed_controller_reference, GraphQLCore)
            else self.generator_speed_controller_reference
        ),
        nacelle=self.nacelle.as_read() if isinstance(self.nacelle, GraphQLCore) else self.nacelle,
    )

as_write()

Convert this GraphQL format of generator to the writing format.

Source code in examples/wind_turbine/data_classes/_generator.py
@no_type_check
def as_write(self) -> GeneratorWrite:
    """Convert this GraphQL format of generator to the writing format."""
    return GeneratorWrite(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecordWrite(existing_version=0),
        generator_speed_controller=(
            self.generator_speed_controller.as_write()
            if isinstance(self.generator_speed_controller, GraphQLCore)
            else self.generator_speed_controller
        ),
        generator_speed_controller_reference=(
            self.generator_speed_controller_reference.as_write()
            if isinstance(self.generator_speed_controller_reference, GraphQLCore)
            else self.generator_speed_controller_reference
        ),
    )

GeneratorList

Bases: DomainModelList[Generator]

List of generators in the read version.

Source code in examples/wind_turbine/data_classes/_generator.py
class GeneratorList(DomainModelList[Generator]):
    """List of generators in the read version."""

    _INSTANCE = Generator

    def as_write(self) -> GeneratorWriteList:
        """Convert these read versions of generator to the writing versions."""
        return GeneratorWriteList([node.as_write() for node in self.data])

    def as_apply(self) -> GeneratorWriteList:
        """Convert these read versions of primitive nullable to the writing versions."""
        warnings.warn(
            "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
            UserWarning,
            stacklevel=2,
        )
        return self.as_write()

    @property
    def generator_speed_controller(self) -> SensorTimeSeriesList:
        from ._sensor_time_series import SensorTimeSeries, SensorTimeSeriesList

        return SensorTimeSeriesList(
            [
                item.generator_speed_controller
                for item in self.data
                if isinstance(item.generator_speed_controller, SensorTimeSeries)
            ]
        )

    @property
    def generator_speed_controller_reference(self) -> SensorTimeSeriesList:
        from ._sensor_time_series import SensorTimeSeries, SensorTimeSeriesList

        return SensorTimeSeriesList(
            [
                item.generator_speed_controller_reference
                for item in self.data
                if isinstance(item.generator_speed_controller_reference, SensorTimeSeries)
            ]
        )

    @property
    def nacelle(self) -> NacelleList:
        from ._nacelle import Nacelle, NacelleList

        return NacelleList([item.nacelle for item in self.data if isinstance(item.nacelle, Nacelle)])

as_apply()

Convert these read versions of primitive nullable to the writing versions.

Source code in examples/wind_turbine/data_classes/_generator.py
def as_apply(self) -> GeneratorWriteList:
    """Convert these read versions of primitive nullable to the writing versions."""
    warnings.warn(
        "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
        UserWarning,
        stacklevel=2,
    )
    return self.as_write()

as_write()

Convert these read versions of generator to the writing versions.

Source code in examples/wind_turbine/data_classes/_generator.py
def as_write(self) -> GeneratorWriteList:
    """Convert these read versions of generator to the writing versions."""
    return GeneratorWriteList([node.as_write() for node in self.data])

GeneratorWrite

Bases: DomainModelWrite

This represents the writing version of generator.

It is used to when data is sent to CDF.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the generator.

required
data_record

The data record of the generator node.

required
generator_speed_controller

The generator speed controller field.

required
generator_speed_controller_reference

The generator speed controller reference field.

required
Source code in examples/wind_turbine/data_classes/_generator.py
class GeneratorWrite(DomainModelWrite):
    """This represents the writing version of generator.

    It is used to when data is sent to CDF.

    Args:
        space: The space where the node is located.
        external_id: The external id of the generator.
        data_record: The data record of the generator node.
        generator_speed_controller: The generator speed controller field.
        generator_speed_controller_reference: The generator speed controller reference field.
    """

    _view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "Generator", "1")

    space: str = DEFAULT_INSTANCE_SPACE
    node_type: Union[dm.DirectRelationReference, dm.NodeId, tuple[str, str], None] = None
    generator_speed_controller: Union[SensorTimeSeriesWrite, str, dm.NodeId, None] = Field(default=None, repr=False)
    generator_speed_controller_reference: Union[SensorTimeSeriesWrite, str, dm.NodeId, None] = Field(
        default=None, repr=False
    )

    @field_validator("generator_speed_controller", "generator_speed_controller_reference", mode="before")
    def as_node_id(cls, value: Any) -> Any:
        if isinstance(value, dm.DirectRelationReference):
            return dm.NodeId(value.space, value.external_id)
        elif isinstance(value, tuple) and len(value) == 2 and all(isinstance(item, str) for item in value):
            return dm.NodeId(value[0], value[1])
        elif isinstance(value, list):
            return [cls.as_node_id(item) for item in value]
        return value

    def _to_instances_write(
        self,
        cache: set[tuple[str, str]],
        write_none: bool = False,
        allow_version_increase: bool = False,
    ) -> ResourcesWrite:
        resources = ResourcesWrite()
        if self.as_tuple_id() in cache:
            return resources

        properties: dict[str, Any] = {}

        if self.generator_speed_controller is not None:
            properties["generator_speed_controller"] = {
                "space": (
                    self.space
                    if isinstance(self.generator_speed_controller, str)
                    else self.generator_speed_controller.space
                ),
                "externalId": (
                    self.generator_speed_controller
                    if isinstance(self.generator_speed_controller, str)
                    else self.generator_speed_controller.external_id
                ),
            }

        if self.generator_speed_controller_reference is not None:
            properties["generator_speed_controller_reference"] = {
                "space": (
                    self.space
                    if isinstance(self.generator_speed_controller_reference, str)
                    else self.generator_speed_controller_reference.space
                ),
                "externalId": (
                    self.generator_speed_controller_reference
                    if isinstance(self.generator_speed_controller_reference, str)
                    else self.generator_speed_controller_reference.external_id
                ),
            }

        if properties:
            this_node = dm.NodeApply(
                space=self.space,
                external_id=self.external_id,
                existing_version=None if allow_version_increase else self.data_record.existing_version,
                type=as_direct_relation_reference(self.node_type),
                sources=[
                    dm.NodeOrEdgeData(
                        source=self._view_id,
                        properties=properties,
                    )
                ],
            )
            resources.nodes.append(this_node)
            cache.add(self.as_tuple_id())

        if isinstance(self.generator_speed_controller, DomainModelWrite):
            other_resources = self.generator_speed_controller._to_instances_write(cache)
            resources.extend(other_resources)

        if isinstance(self.generator_speed_controller_reference, DomainModelWrite):
            other_resources = self.generator_speed_controller_reference._to_instances_write(cache)
            resources.extend(other_resources)

        return resources

GeneratorWriteList

Bases: DomainModelWriteList[GeneratorWrite]

List of generators in the writing version.

Source code in examples/wind_turbine/data_classes/_generator.py
class GeneratorWriteList(DomainModelWriteList[GeneratorWrite]):
    """List of generators in the writing version."""

    _INSTANCE = GeneratorWrite

    @property
    def generator_speed_controller(self) -> SensorTimeSeriesWriteList:
        from ._sensor_time_series import SensorTimeSeriesWrite, SensorTimeSeriesWriteList

        return SensorTimeSeriesWriteList(
            [
                item.generator_speed_controller
                for item in self.data
                if isinstance(item.generator_speed_controller, SensorTimeSeriesWrite)
            ]
        )

    @property
    def generator_speed_controller_reference(self) -> SensorTimeSeriesWriteList:
        from ._sensor_time_series import SensorTimeSeriesWrite, SensorTimeSeriesWriteList

        return SensorTimeSeriesWriteList(
            [
                item.generator_speed_controller_reference
                for item in self.data
                if isinstance(item.generator_speed_controller_reference, SensorTimeSeriesWrite)
            ]
        )

HighSpeedShaft

Bases: DomainModel

This represents the reading version of high speed shaft.

It is used to when data is retrieved from CDF.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the high speed shaft.

required
data_record

The data record of the high speed shaft node.

required
bending_moment_y

The bending moment y field.

required
bending_monent_x

The bending monent x field.

required
nacelle

The nacelle field.

required
torque

The torque field.

required
Source code in examples/wind_turbine/data_classes/_high_speed_shaft.py
class HighSpeedShaft(DomainModel):
    """This represents the reading version of high speed shaft.

    It is used to when data is retrieved from CDF.

    Args:
        space: The space where the node is located.
        external_id: The external id of the high speed shaft.
        data_record: The data record of the high speed shaft node.
        bending_moment_y: The bending moment y field.
        bending_monent_x: The bending monent x field.
        nacelle: The nacelle field.
        torque: The torque field.
    """

    _view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "HighSpeedShaft", "1")

    space: str = DEFAULT_INSTANCE_SPACE
    node_type: Union[dm.DirectRelationReference, None] = None
    bending_moment_y: Union[SensorTimeSeries, str, dm.NodeId, None] = Field(default=None, repr=False)
    bending_monent_x: Union[SensorTimeSeries, str, dm.NodeId, None] = Field(default=None, repr=False)
    nacelle: Optional[Nacelle] = Field(default=None, repr=False)
    torque: Union[SensorTimeSeries, str, dm.NodeId, None] = Field(default=None, repr=False)

    def as_write(self) -> HighSpeedShaftWrite:
        """Convert this read version of high speed shaft to the writing version."""
        return HighSpeedShaftWrite(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecordWrite(existing_version=self.data_record.version),
            bending_moment_y=(
                self.bending_moment_y.as_write()
                if isinstance(self.bending_moment_y, DomainModel)
                else self.bending_moment_y
            ),
            bending_monent_x=(
                self.bending_monent_x.as_write()
                if isinstance(self.bending_monent_x, DomainModel)
                else self.bending_monent_x
            ),
            torque=self.torque.as_write() if isinstance(self.torque, DomainModel) else self.torque,
        )

    def as_apply(self) -> HighSpeedShaftWrite:
        """Convert this read version of high speed shaft to the writing version."""
        warnings.warn(
            "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
            UserWarning,
            stacklevel=2,
        )
        return self.as_write()

    @classmethod
    def _update_connections(
        cls,
        instances: dict[dm.NodeId | str, HighSpeedShaft],  # type: ignore[override]
        nodes_by_id: dict[dm.NodeId | str, DomainModel],
        edges_by_source_node: dict[dm.NodeId, list[dm.Edge | DomainRelation]],
    ) -> None:
        from ._nacelle import Nacelle
        from ._sensor_time_series import SensorTimeSeries

        for instance in instances.values():
            if (
                isinstance(instance.bending_moment_y, (dm.NodeId, str))
                and (bending_moment_y := nodes_by_id.get(instance.bending_moment_y))
                and isinstance(bending_moment_y, SensorTimeSeries)
            ):
                instance.bending_moment_y = bending_moment_y
            if (
                isinstance(instance.bending_monent_x, (dm.NodeId, str))
                and (bending_monent_x := nodes_by_id.get(instance.bending_monent_x))
                and isinstance(bending_monent_x, SensorTimeSeries)
            ):
                instance.bending_monent_x = bending_monent_x
            if (
                isinstance(instance.torque, (dm.NodeId, str))
                and (torque := nodes_by_id.get(instance.torque))
                and isinstance(torque, SensorTimeSeries)
            ):
                instance.torque = torque
        for node in nodes_by_id.values():
            if (
                isinstance(node, Nacelle)
                and node.high_speed_shaft is not None
                and (high_speed_shaft := instances.get(as_pygen_node_id(node.high_speed_shaft)))
            ):
                if high_speed_shaft.nacelle is None:
                    high_speed_shaft.nacelle = node
                elif are_nodes_equal(node, high_speed_shaft.nacelle):
                    # This is the same node, so we don't need to do anything...
                    ...
                else:
                    warnings.warn(
                        f"Expected one direct relation for 'nacelle' in {high_speed_shaft.as_id()}."
                        f"Ignoring new relation {node!s} in favor of {high_speed_shaft.nacelle!s}."
                    )

as_apply()

Convert this read version of high speed shaft to the writing version.

Source code in examples/wind_turbine/data_classes/_high_speed_shaft.py
def as_apply(self) -> HighSpeedShaftWrite:
    """Convert this read version of high speed shaft to the writing version."""
    warnings.warn(
        "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
        UserWarning,
        stacklevel=2,
    )
    return self.as_write()

as_write()

Convert this read version of high speed shaft to the writing version.

Source code in examples/wind_turbine/data_classes/_high_speed_shaft.py
def as_write(self) -> HighSpeedShaftWrite:
    """Convert this read version of high speed shaft to the writing version."""
    return HighSpeedShaftWrite(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecordWrite(existing_version=self.data_record.version),
        bending_moment_y=(
            self.bending_moment_y.as_write()
            if isinstance(self.bending_moment_y, DomainModel)
            else self.bending_moment_y
        ),
        bending_monent_x=(
            self.bending_monent_x.as_write()
            if isinstance(self.bending_monent_x, DomainModel)
            else self.bending_monent_x
        ),
        torque=self.torque.as_write() if isinstance(self.torque, DomainModel) else self.torque,
    )

HighSpeedShaftGraphQL

Bases: GraphQLCore

This represents the reading version of high speed shaft, used when data is retrieved from CDF using GraphQL.

It is used when retrieving data from CDF using GraphQL.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the high speed shaft.

required
data_record

The data record of the high speed shaft node.

required
bending_moment_y

The bending moment y field.

required
bending_monent_x

The bending monent x field.

required
nacelle

The nacelle field.

required
torque

The torque field.

required
Source code in examples/wind_turbine/data_classes/_high_speed_shaft.py
class HighSpeedShaftGraphQL(GraphQLCore):
    """This represents the reading version of high speed shaft, used
    when data is retrieved from CDF using GraphQL.

    It is used when retrieving data from CDF using GraphQL.

    Args:
        space: The space where the node is located.
        external_id: The external id of the high speed shaft.
        data_record: The data record of the high speed shaft node.
        bending_moment_y: The bending moment y field.
        bending_monent_x: The bending monent x field.
        nacelle: The nacelle field.
        torque: The torque field.
    """

    view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "HighSpeedShaft", "1")
    bending_moment_y: Optional[SensorTimeSeriesGraphQL] = Field(default=None, repr=False)
    bending_monent_x: Optional[SensorTimeSeriesGraphQL] = Field(default=None, repr=False)
    nacelle: Optional[NacelleGraphQL] = Field(default=None, repr=False)
    torque: Optional[SensorTimeSeriesGraphQL] = Field(default=None, repr=False)

    @model_validator(mode="before")
    def parse_data_record(cls, values: Any) -> Any:
        if not isinstance(values, dict):
            return values
        if "lastUpdatedTime" in values or "createdTime" in values:
            values["dataRecord"] = DataRecordGraphQL(
                created_time=values.pop("createdTime", None),
                last_updated_time=values.pop("lastUpdatedTime", None),
            )
        return values

    @field_validator("bending_moment_y", "bending_monent_x", "nacelle", "torque", mode="before")
    def parse_graphql(cls, value: Any) -> Any:
        if not isinstance(value, dict):
            return value
        if "items" in value:
            return value["items"]
        return value

    # We do the ignore argument type as we let pydantic handle the type checking
    @no_type_check
    def as_read(self) -> HighSpeedShaft:
        """Convert this GraphQL format of high speed shaft to the reading format."""
        if self.data_record is None:
            raise ValueError("This object cannot be converted to a read format because it lacks a data record.")
        return HighSpeedShaft(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecord(
                version=0,
                last_updated_time=self.data_record.last_updated_time,
                created_time=self.data_record.created_time,
            ),
            bending_moment_y=(
                self.bending_moment_y.as_read()
                if isinstance(self.bending_moment_y, GraphQLCore)
                else self.bending_moment_y
            ),
            bending_monent_x=(
                self.bending_monent_x.as_read()
                if isinstance(self.bending_monent_x, GraphQLCore)
                else self.bending_monent_x
            ),
            nacelle=self.nacelle.as_read() if isinstance(self.nacelle, GraphQLCore) else self.nacelle,
            torque=self.torque.as_read() if isinstance(self.torque, GraphQLCore) else self.torque,
        )

    # We do the ignore argument type as we let pydantic handle the type checking
    @no_type_check
    def as_write(self) -> HighSpeedShaftWrite:
        """Convert this GraphQL format of high speed shaft to the writing format."""
        return HighSpeedShaftWrite(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecordWrite(existing_version=0),
            bending_moment_y=(
                self.bending_moment_y.as_write()
                if isinstance(self.bending_moment_y, GraphQLCore)
                else self.bending_moment_y
            ),
            bending_monent_x=(
                self.bending_monent_x.as_write()
                if isinstance(self.bending_monent_x, GraphQLCore)
                else self.bending_monent_x
            ),
            torque=self.torque.as_write() if isinstance(self.torque, GraphQLCore) else self.torque,
        )

as_read()

Convert this GraphQL format of high speed shaft to the reading format.

Source code in examples/wind_turbine/data_classes/_high_speed_shaft.py
@no_type_check
def as_read(self) -> HighSpeedShaft:
    """Convert this GraphQL format of high speed shaft to the reading format."""
    if self.data_record is None:
        raise ValueError("This object cannot be converted to a read format because it lacks a data record.")
    return HighSpeedShaft(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecord(
            version=0,
            last_updated_time=self.data_record.last_updated_time,
            created_time=self.data_record.created_time,
        ),
        bending_moment_y=(
            self.bending_moment_y.as_read()
            if isinstance(self.bending_moment_y, GraphQLCore)
            else self.bending_moment_y
        ),
        bending_monent_x=(
            self.bending_monent_x.as_read()
            if isinstance(self.bending_monent_x, GraphQLCore)
            else self.bending_monent_x
        ),
        nacelle=self.nacelle.as_read() if isinstance(self.nacelle, GraphQLCore) else self.nacelle,
        torque=self.torque.as_read() if isinstance(self.torque, GraphQLCore) else self.torque,
    )

as_write()

Convert this GraphQL format of high speed shaft to the writing format.

Source code in examples/wind_turbine/data_classes/_high_speed_shaft.py
@no_type_check
def as_write(self) -> HighSpeedShaftWrite:
    """Convert this GraphQL format of high speed shaft to the writing format."""
    return HighSpeedShaftWrite(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecordWrite(existing_version=0),
        bending_moment_y=(
            self.bending_moment_y.as_write()
            if isinstance(self.bending_moment_y, GraphQLCore)
            else self.bending_moment_y
        ),
        bending_monent_x=(
            self.bending_monent_x.as_write()
            if isinstance(self.bending_monent_x, GraphQLCore)
            else self.bending_monent_x
        ),
        torque=self.torque.as_write() if isinstance(self.torque, GraphQLCore) else self.torque,
    )

HighSpeedShaftList

Bases: DomainModelList[HighSpeedShaft]

List of high speed shafts in the read version.

Source code in examples/wind_turbine/data_classes/_high_speed_shaft.py
class HighSpeedShaftList(DomainModelList[HighSpeedShaft]):
    """List of high speed shafts in the read version."""

    _INSTANCE = HighSpeedShaft

    def as_write(self) -> HighSpeedShaftWriteList:
        """Convert these read versions of high speed shaft to the writing versions."""
        return HighSpeedShaftWriteList([node.as_write() for node in self.data])

    def as_apply(self) -> HighSpeedShaftWriteList:
        """Convert these read versions of primitive nullable to the writing versions."""
        warnings.warn(
            "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
            UserWarning,
            stacklevel=2,
        )
        return self.as_write()

    @property
    def bending_moment_y(self) -> SensorTimeSeriesList:
        from ._sensor_time_series import SensorTimeSeries, SensorTimeSeriesList

        return SensorTimeSeriesList(
            [item.bending_moment_y for item in self.data if isinstance(item.bending_moment_y, SensorTimeSeries)]
        )

    @property
    def bending_monent_x(self) -> SensorTimeSeriesList:
        from ._sensor_time_series import SensorTimeSeries, SensorTimeSeriesList

        return SensorTimeSeriesList(
            [item.bending_monent_x for item in self.data if isinstance(item.bending_monent_x, SensorTimeSeries)]
        )

    @property
    def nacelle(self) -> NacelleList:
        from ._nacelle import Nacelle, NacelleList

        return NacelleList([item.nacelle for item in self.data if isinstance(item.nacelle, Nacelle)])

    @property
    def torque(self) -> SensorTimeSeriesList:
        from ._sensor_time_series import SensorTimeSeries, SensorTimeSeriesList

        return SensorTimeSeriesList([item.torque for item in self.data if isinstance(item.torque, SensorTimeSeries)])

as_apply()

Convert these read versions of primitive nullable to the writing versions.

Source code in examples/wind_turbine/data_classes/_high_speed_shaft.py
def as_apply(self) -> HighSpeedShaftWriteList:
    """Convert these read versions of primitive nullable to the writing versions."""
    warnings.warn(
        "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
        UserWarning,
        stacklevel=2,
    )
    return self.as_write()

as_write()

Convert these read versions of high speed shaft to the writing versions.

Source code in examples/wind_turbine/data_classes/_high_speed_shaft.py
def as_write(self) -> HighSpeedShaftWriteList:
    """Convert these read versions of high speed shaft to the writing versions."""
    return HighSpeedShaftWriteList([node.as_write() for node in self.data])

HighSpeedShaftWrite

Bases: DomainModelWrite

This represents the writing version of high speed shaft.

It is used to when data is sent to CDF.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the high speed shaft.

required
data_record

The data record of the high speed shaft node.

required
bending_moment_y

The bending moment y field.

required
bending_monent_x

The bending monent x field.

required
torque

The torque field.

required
Source code in examples/wind_turbine/data_classes/_high_speed_shaft.py
class HighSpeedShaftWrite(DomainModelWrite):
    """This represents the writing version of high speed shaft.

    It is used to when data is sent to CDF.

    Args:
        space: The space where the node is located.
        external_id: The external id of the high speed shaft.
        data_record: The data record of the high speed shaft node.
        bending_moment_y: The bending moment y field.
        bending_monent_x: The bending monent x field.
        torque: The torque field.
    """

    _view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "HighSpeedShaft", "1")

    space: str = DEFAULT_INSTANCE_SPACE
    node_type: Union[dm.DirectRelationReference, dm.NodeId, tuple[str, str], None] = None
    bending_moment_y: Union[SensorTimeSeriesWrite, str, dm.NodeId, None] = Field(default=None, repr=False)
    bending_monent_x: Union[SensorTimeSeriesWrite, str, dm.NodeId, None] = Field(default=None, repr=False)
    torque: Union[SensorTimeSeriesWrite, str, dm.NodeId, None] = Field(default=None, repr=False)

    @field_validator("bending_moment_y", "bending_monent_x", "torque", mode="before")
    def as_node_id(cls, value: Any) -> Any:
        if isinstance(value, dm.DirectRelationReference):
            return dm.NodeId(value.space, value.external_id)
        elif isinstance(value, tuple) and len(value) == 2 and all(isinstance(item, str) for item in value):
            return dm.NodeId(value[0], value[1])
        elif isinstance(value, list):
            return [cls.as_node_id(item) for item in value]
        return value

    def _to_instances_write(
        self,
        cache: set[tuple[str, str]],
        write_none: bool = False,
        allow_version_increase: bool = False,
    ) -> ResourcesWrite:
        resources = ResourcesWrite()
        if self.as_tuple_id() in cache:
            return resources

        properties: dict[str, Any] = {}

        if self.bending_moment_y is not None:
            properties["bending_moment_y"] = {
                "space": self.space if isinstance(self.bending_moment_y, str) else self.bending_moment_y.space,
                "externalId": (
                    self.bending_moment_y
                    if isinstance(self.bending_moment_y, str)
                    else self.bending_moment_y.external_id
                ),
            }

        if self.bending_monent_x is not None:
            properties["bending_monent_x"] = {
                "space": self.space if isinstance(self.bending_monent_x, str) else self.bending_monent_x.space,
                "externalId": (
                    self.bending_monent_x
                    if isinstance(self.bending_monent_x, str)
                    else self.bending_monent_x.external_id
                ),
            }

        if self.torque is not None:
            properties["torque"] = {
                "space": self.space if isinstance(self.torque, str) else self.torque.space,
                "externalId": self.torque if isinstance(self.torque, str) else self.torque.external_id,
            }

        if properties:
            this_node = dm.NodeApply(
                space=self.space,
                external_id=self.external_id,
                existing_version=None if allow_version_increase else self.data_record.existing_version,
                type=as_direct_relation_reference(self.node_type),
                sources=[
                    dm.NodeOrEdgeData(
                        source=self._view_id,
                        properties=properties,
                    )
                ],
            )
            resources.nodes.append(this_node)
            cache.add(self.as_tuple_id())

        if isinstance(self.bending_moment_y, DomainModelWrite):
            other_resources = self.bending_moment_y._to_instances_write(cache)
            resources.extend(other_resources)

        if isinstance(self.bending_monent_x, DomainModelWrite):
            other_resources = self.bending_monent_x._to_instances_write(cache)
            resources.extend(other_resources)

        if isinstance(self.torque, DomainModelWrite):
            other_resources = self.torque._to_instances_write(cache)
            resources.extend(other_resources)

        return resources

HighSpeedShaftWriteList

Bases: DomainModelWriteList[HighSpeedShaftWrite]

List of high speed shafts in the writing version.

Source code in examples/wind_turbine/data_classes/_high_speed_shaft.py
class HighSpeedShaftWriteList(DomainModelWriteList[HighSpeedShaftWrite]):
    """List of high speed shafts in the writing version."""

    _INSTANCE = HighSpeedShaftWrite

    @property
    def bending_moment_y(self) -> SensorTimeSeriesWriteList:
        from ._sensor_time_series import SensorTimeSeriesWrite, SensorTimeSeriesWriteList

        return SensorTimeSeriesWriteList(
            [item.bending_moment_y for item in self.data if isinstance(item.bending_moment_y, SensorTimeSeriesWrite)]
        )

    @property
    def bending_monent_x(self) -> SensorTimeSeriesWriteList:
        from ._sensor_time_series import SensorTimeSeriesWrite, SensorTimeSeriesWriteList

        return SensorTimeSeriesWriteList(
            [item.bending_monent_x for item in self.data if isinstance(item.bending_monent_x, SensorTimeSeriesWrite)]
        )

    @property
    def torque(self) -> SensorTimeSeriesWriteList:
        from ._sensor_time_series import SensorTimeSeriesWrite, SensorTimeSeriesWriteList

        return SensorTimeSeriesWriteList(
            [item.torque for item in self.data if isinstance(item.torque, SensorTimeSeriesWrite)]
        )

MainShaft

Bases: DomainModel

This represents the reading version of main shaft.

It is used to when data is retrieved from CDF.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the main shaft.

required
data_record

The data record of the main shaft node.

required
bending_x

The bending x field.

required
bending_y

The bending y field.

required
calculated_tilt_moment

The calculated tilt moment field.

required
calculated_yaw_moment

The calculated yaw moment field.

required
nacelle

The nacelle field.

required
torque

The torque field.

required
Source code in examples/wind_turbine/data_classes/_main_shaft.py
class MainShaft(DomainModel):
    """This represents the reading version of main shaft.

    It is used to when data is retrieved from CDF.

    Args:
        space: The space where the node is located.
        external_id: The external id of the main shaft.
        data_record: The data record of the main shaft node.
        bending_x: The bending x field.
        bending_y: The bending y field.
        calculated_tilt_moment: The calculated tilt moment field.
        calculated_yaw_moment: The calculated yaw moment field.
        nacelle: The nacelle field.
        torque: The torque field.
    """

    _view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "MainShaft", "1")

    space: str = DEFAULT_INSTANCE_SPACE
    node_type: Union[dm.DirectRelationReference, None] = None
    bending_x: Union[SensorTimeSeries, str, dm.NodeId, None] = Field(default=None, repr=False)
    bending_y: Union[SensorTimeSeries, str, dm.NodeId, None] = Field(default=None, repr=False)
    calculated_tilt_moment: Union[SensorTimeSeries, str, dm.NodeId, None] = Field(default=None, repr=False)
    calculated_yaw_moment: Union[SensorTimeSeries, str, dm.NodeId, None] = Field(default=None, repr=False)
    nacelle: Optional[Nacelle] = Field(default=None, repr=False)
    torque: Union[SensorTimeSeries, str, dm.NodeId, None] = Field(default=None, repr=False)

    def as_write(self) -> MainShaftWrite:
        """Convert this read version of main shaft to the writing version."""
        return MainShaftWrite(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecordWrite(existing_version=self.data_record.version),
            bending_x=self.bending_x.as_write() if isinstance(self.bending_x, DomainModel) else self.bending_x,
            bending_y=self.bending_y.as_write() if isinstance(self.bending_y, DomainModel) else self.bending_y,
            calculated_tilt_moment=(
                self.calculated_tilt_moment.as_write()
                if isinstance(self.calculated_tilt_moment, DomainModel)
                else self.calculated_tilt_moment
            ),
            calculated_yaw_moment=(
                self.calculated_yaw_moment.as_write()
                if isinstance(self.calculated_yaw_moment, DomainModel)
                else self.calculated_yaw_moment
            ),
            torque=self.torque.as_write() if isinstance(self.torque, DomainModel) else self.torque,
        )

    def as_apply(self) -> MainShaftWrite:
        """Convert this read version of main shaft to the writing version."""
        warnings.warn(
            "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
            UserWarning,
            stacklevel=2,
        )
        return self.as_write()

    @classmethod
    def _update_connections(
        cls,
        instances: dict[dm.NodeId | str, MainShaft],  # type: ignore[override]
        nodes_by_id: dict[dm.NodeId | str, DomainModel],
        edges_by_source_node: dict[dm.NodeId, list[dm.Edge | DomainRelation]],
    ) -> None:
        from ._nacelle import Nacelle
        from ._sensor_time_series import SensorTimeSeries

        for instance in instances.values():
            if (
                isinstance(instance.bending_x, (dm.NodeId, str))
                and (bending_x := nodes_by_id.get(instance.bending_x))
                and isinstance(bending_x, SensorTimeSeries)
            ):
                instance.bending_x = bending_x
            if (
                isinstance(instance.bending_y, (dm.NodeId, str))
                and (bending_y := nodes_by_id.get(instance.bending_y))
                and isinstance(bending_y, SensorTimeSeries)
            ):
                instance.bending_y = bending_y
            if (
                isinstance(instance.calculated_tilt_moment, (dm.NodeId, str))
                and (calculated_tilt_moment := nodes_by_id.get(instance.calculated_tilt_moment))
                and isinstance(calculated_tilt_moment, SensorTimeSeries)
            ):
                instance.calculated_tilt_moment = calculated_tilt_moment
            if (
                isinstance(instance.calculated_yaw_moment, (dm.NodeId, str))
                and (calculated_yaw_moment := nodes_by_id.get(instance.calculated_yaw_moment))
                and isinstance(calculated_yaw_moment, SensorTimeSeries)
            ):
                instance.calculated_yaw_moment = calculated_yaw_moment
            if (
                isinstance(instance.torque, (dm.NodeId, str))
                and (torque := nodes_by_id.get(instance.torque))
                and isinstance(torque, SensorTimeSeries)
            ):
                instance.torque = torque
        for node in nodes_by_id.values():
            if (
                isinstance(node, Nacelle)
                and node.generator is not None
                and (generator := instances.get(as_pygen_node_id(node.generator)))
            ):
                if generator.nacelle is None:
                    generator.nacelle = node
                elif are_nodes_equal(node, generator.nacelle):
                    # This is the same node, so we don't need to do anything...
                    ...
                else:
                    warnings.warn(
                        f"Expected one direct relation for 'nacelle' in {generator.as_id()}."
                        f"Ignoring new relation {node!s} in favor of {generator.nacelle!s}."
                    )

as_apply()

Convert this read version of main shaft to the writing version.

Source code in examples/wind_turbine/data_classes/_main_shaft.py
def as_apply(self) -> MainShaftWrite:
    """Convert this read version of main shaft to the writing version."""
    warnings.warn(
        "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
        UserWarning,
        stacklevel=2,
    )
    return self.as_write()

as_write()

Convert this read version of main shaft to the writing version.

Source code in examples/wind_turbine/data_classes/_main_shaft.py
def as_write(self) -> MainShaftWrite:
    """Convert this read version of main shaft to the writing version."""
    return MainShaftWrite(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecordWrite(existing_version=self.data_record.version),
        bending_x=self.bending_x.as_write() if isinstance(self.bending_x, DomainModel) else self.bending_x,
        bending_y=self.bending_y.as_write() if isinstance(self.bending_y, DomainModel) else self.bending_y,
        calculated_tilt_moment=(
            self.calculated_tilt_moment.as_write()
            if isinstance(self.calculated_tilt_moment, DomainModel)
            else self.calculated_tilt_moment
        ),
        calculated_yaw_moment=(
            self.calculated_yaw_moment.as_write()
            if isinstance(self.calculated_yaw_moment, DomainModel)
            else self.calculated_yaw_moment
        ),
        torque=self.torque.as_write() if isinstance(self.torque, DomainModel) else self.torque,
    )

MainShaftGraphQL

Bases: GraphQLCore

This represents the reading version of main shaft, used when data is retrieved from CDF using GraphQL.

It is used when retrieving data from CDF using GraphQL.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the main shaft.

required
data_record

The data record of the main shaft node.

required
bending_x

The bending x field.

required
bending_y

The bending y field.

required
calculated_tilt_moment

The calculated tilt moment field.

required
calculated_yaw_moment

The calculated yaw moment field.

required
nacelle

The nacelle field.

required
torque

The torque field.

required
Source code in examples/wind_turbine/data_classes/_main_shaft.py
class MainShaftGraphQL(GraphQLCore):
    """This represents the reading version of main shaft, used
    when data is retrieved from CDF using GraphQL.

    It is used when retrieving data from CDF using GraphQL.

    Args:
        space: The space where the node is located.
        external_id: The external id of the main shaft.
        data_record: The data record of the main shaft node.
        bending_x: The bending x field.
        bending_y: The bending y field.
        calculated_tilt_moment: The calculated tilt moment field.
        calculated_yaw_moment: The calculated yaw moment field.
        nacelle: The nacelle field.
        torque: The torque field.
    """

    view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "MainShaft", "1")
    bending_x: Optional[SensorTimeSeriesGraphQL] = Field(default=None, repr=False)
    bending_y: Optional[SensorTimeSeriesGraphQL] = Field(default=None, repr=False)
    calculated_tilt_moment: Optional[SensorTimeSeriesGraphQL] = Field(default=None, repr=False)
    calculated_yaw_moment: Optional[SensorTimeSeriesGraphQL] = Field(default=None, repr=False)
    nacelle: Optional[NacelleGraphQL] = Field(default=None, repr=False)
    torque: Optional[SensorTimeSeriesGraphQL] = Field(default=None, repr=False)

    @model_validator(mode="before")
    def parse_data_record(cls, values: Any) -> Any:
        if not isinstance(values, dict):
            return values
        if "lastUpdatedTime" in values or "createdTime" in values:
            values["dataRecord"] = DataRecordGraphQL(
                created_time=values.pop("createdTime", None),
                last_updated_time=values.pop("lastUpdatedTime", None),
            )
        return values

    @field_validator(
        "bending_x", "bending_y", "calculated_tilt_moment", "calculated_yaw_moment", "nacelle", "torque", mode="before"
    )
    def parse_graphql(cls, value: Any) -> Any:
        if not isinstance(value, dict):
            return value
        if "items" in value:
            return value["items"]
        return value

    # We do the ignore argument type as we let pydantic handle the type checking
    @no_type_check
    def as_read(self) -> MainShaft:
        """Convert this GraphQL format of main shaft to the reading format."""
        if self.data_record is None:
            raise ValueError("This object cannot be converted to a read format because it lacks a data record.")
        return MainShaft(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecord(
                version=0,
                last_updated_time=self.data_record.last_updated_time,
                created_time=self.data_record.created_time,
            ),
            bending_x=self.bending_x.as_read() if isinstance(self.bending_x, GraphQLCore) else self.bending_x,
            bending_y=self.bending_y.as_read() if isinstance(self.bending_y, GraphQLCore) else self.bending_y,
            calculated_tilt_moment=(
                self.calculated_tilt_moment.as_read()
                if isinstance(self.calculated_tilt_moment, GraphQLCore)
                else self.calculated_tilt_moment
            ),
            calculated_yaw_moment=(
                self.calculated_yaw_moment.as_read()
                if isinstance(self.calculated_yaw_moment, GraphQLCore)
                else self.calculated_yaw_moment
            ),
            nacelle=self.nacelle.as_read() if isinstance(self.nacelle, GraphQLCore) else self.nacelle,
            torque=self.torque.as_read() if isinstance(self.torque, GraphQLCore) else self.torque,
        )

    # We do the ignore argument type as we let pydantic handle the type checking
    @no_type_check
    def as_write(self) -> MainShaftWrite:
        """Convert this GraphQL format of main shaft to the writing format."""
        return MainShaftWrite(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecordWrite(existing_version=0),
            bending_x=self.bending_x.as_write() if isinstance(self.bending_x, GraphQLCore) else self.bending_x,
            bending_y=self.bending_y.as_write() if isinstance(self.bending_y, GraphQLCore) else self.bending_y,
            calculated_tilt_moment=(
                self.calculated_tilt_moment.as_write()
                if isinstance(self.calculated_tilt_moment, GraphQLCore)
                else self.calculated_tilt_moment
            ),
            calculated_yaw_moment=(
                self.calculated_yaw_moment.as_write()
                if isinstance(self.calculated_yaw_moment, GraphQLCore)
                else self.calculated_yaw_moment
            ),
            torque=self.torque.as_write() if isinstance(self.torque, GraphQLCore) else self.torque,
        )

as_read()

Convert this GraphQL format of main shaft to the reading format.

Source code in examples/wind_turbine/data_classes/_main_shaft.py
@no_type_check
def as_read(self) -> MainShaft:
    """Convert this GraphQL format of main shaft to the reading format."""
    if self.data_record is None:
        raise ValueError("This object cannot be converted to a read format because it lacks a data record.")
    return MainShaft(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecord(
            version=0,
            last_updated_time=self.data_record.last_updated_time,
            created_time=self.data_record.created_time,
        ),
        bending_x=self.bending_x.as_read() if isinstance(self.bending_x, GraphQLCore) else self.bending_x,
        bending_y=self.bending_y.as_read() if isinstance(self.bending_y, GraphQLCore) else self.bending_y,
        calculated_tilt_moment=(
            self.calculated_tilt_moment.as_read()
            if isinstance(self.calculated_tilt_moment, GraphQLCore)
            else self.calculated_tilt_moment
        ),
        calculated_yaw_moment=(
            self.calculated_yaw_moment.as_read()
            if isinstance(self.calculated_yaw_moment, GraphQLCore)
            else self.calculated_yaw_moment
        ),
        nacelle=self.nacelle.as_read() if isinstance(self.nacelle, GraphQLCore) else self.nacelle,
        torque=self.torque.as_read() if isinstance(self.torque, GraphQLCore) else self.torque,
    )

as_write()

Convert this GraphQL format of main shaft to the writing format.

Source code in examples/wind_turbine/data_classes/_main_shaft.py
@no_type_check
def as_write(self) -> MainShaftWrite:
    """Convert this GraphQL format of main shaft to the writing format."""
    return MainShaftWrite(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecordWrite(existing_version=0),
        bending_x=self.bending_x.as_write() if isinstance(self.bending_x, GraphQLCore) else self.bending_x,
        bending_y=self.bending_y.as_write() if isinstance(self.bending_y, GraphQLCore) else self.bending_y,
        calculated_tilt_moment=(
            self.calculated_tilt_moment.as_write()
            if isinstance(self.calculated_tilt_moment, GraphQLCore)
            else self.calculated_tilt_moment
        ),
        calculated_yaw_moment=(
            self.calculated_yaw_moment.as_write()
            if isinstance(self.calculated_yaw_moment, GraphQLCore)
            else self.calculated_yaw_moment
        ),
        torque=self.torque.as_write() if isinstance(self.torque, GraphQLCore) else self.torque,
    )

MainShaftList

Bases: DomainModelList[MainShaft]

List of main shafts in the read version.

Source code in examples/wind_turbine/data_classes/_main_shaft.py
class MainShaftList(DomainModelList[MainShaft]):
    """List of main shafts in the read version."""

    _INSTANCE = MainShaft

    def as_write(self) -> MainShaftWriteList:
        """Convert these read versions of main shaft to the writing versions."""
        return MainShaftWriteList([node.as_write() for node in self.data])

    def as_apply(self) -> MainShaftWriteList:
        """Convert these read versions of primitive nullable to the writing versions."""
        warnings.warn(
            "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
            UserWarning,
            stacklevel=2,
        )
        return self.as_write()

    @property
    def bending_x(self) -> SensorTimeSeriesList:
        from ._sensor_time_series import SensorTimeSeries, SensorTimeSeriesList

        return SensorTimeSeriesList(
            [item.bending_x for item in self.data if isinstance(item.bending_x, SensorTimeSeries)]
        )

    @property
    def bending_y(self) -> SensorTimeSeriesList:
        from ._sensor_time_series import SensorTimeSeries, SensorTimeSeriesList

        return SensorTimeSeriesList(
            [item.bending_y for item in self.data if isinstance(item.bending_y, SensorTimeSeries)]
        )

    @property
    def calculated_tilt_moment(self) -> SensorTimeSeriesList:
        from ._sensor_time_series import SensorTimeSeries, SensorTimeSeriesList

        return SensorTimeSeriesList(
            [
                item.calculated_tilt_moment
                for item in self.data
                if isinstance(item.calculated_tilt_moment, SensorTimeSeries)
            ]
        )

    @property
    def calculated_yaw_moment(self) -> SensorTimeSeriesList:
        from ._sensor_time_series import SensorTimeSeries, SensorTimeSeriesList

        return SensorTimeSeriesList(
            [
                item.calculated_yaw_moment
                for item in self.data
                if isinstance(item.calculated_yaw_moment, SensorTimeSeries)
            ]
        )

    @property
    def nacelle(self) -> NacelleList:
        from ._nacelle import Nacelle, NacelleList

        return NacelleList([item.nacelle for item in self.data if isinstance(item.nacelle, Nacelle)])

    @property
    def torque(self) -> SensorTimeSeriesList:
        from ._sensor_time_series import SensorTimeSeries, SensorTimeSeriesList

        return SensorTimeSeriesList([item.torque for item in self.data if isinstance(item.torque, SensorTimeSeries)])

as_apply()

Convert these read versions of primitive nullable to the writing versions.

Source code in examples/wind_turbine/data_classes/_main_shaft.py
def as_apply(self) -> MainShaftWriteList:
    """Convert these read versions of primitive nullable to the writing versions."""
    warnings.warn(
        "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
        UserWarning,
        stacklevel=2,
    )
    return self.as_write()

as_write()

Convert these read versions of main shaft to the writing versions.

Source code in examples/wind_turbine/data_classes/_main_shaft.py
def as_write(self) -> MainShaftWriteList:
    """Convert these read versions of main shaft to the writing versions."""
    return MainShaftWriteList([node.as_write() for node in self.data])

MainShaftWrite

Bases: DomainModelWrite

This represents the writing version of main shaft.

It is used to when data is sent to CDF.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the main shaft.

required
data_record

The data record of the main shaft node.

required
bending_x

The bending x field.

required
bending_y

The bending y field.

required
calculated_tilt_moment

The calculated tilt moment field.

required
calculated_yaw_moment

The calculated yaw moment field.

required
torque

The torque field.

required
Source code in examples/wind_turbine/data_classes/_main_shaft.py
class MainShaftWrite(DomainModelWrite):
    """This represents the writing version of main shaft.

    It is used to when data is sent to CDF.

    Args:
        space: The space where the node is located.
        external_id: The external id of the main shaft.
        data_record: The data record of the main shaft node.
        bending_x: The bending x field.
        bending_y: The bending y field.
        calculated_tilt_moment: The calculated tilt moment field.
        calculated_yaw_moment: The calculated yaw moment field.
        torque: The torque field.
    """

    _view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "MainShaft", "1")

    space: str = DEFAULT_INSTANCE_SPACE
    node_type: Union[dm.DirectRelationReference, dm.NodeId, tuple[str, str], None] = None
    bending_x: Union[SensorTimeSeriesWrite, str, dm.NodeId, None] = Field(default=None, repr=False)
    bending_y: Union[SensorTimeSeriesWrite, str, dm.NodeId, None] = Field(default=None, repr=False)
    calculated_tilt_moment: Union[SensorTimeSeriesWrite, str, dm.NodeId, None] = Field(default=None, repr=False)
    calculated_yaw_moment: Union[SensorTimeSeriesWrite, str, dm.NodeId, None] = Field(default=None, repr=False)
    torque: Union[SensorTimeSeriesWrite, str, dm.NodeId, None] = Field(default=None, repr=False)

    @field_validator(
        "bending_x", "bending_y", "calculated_tilt_moment", "calculated_yaw_moment", "torque", mode="before"
    )
    def as_node_id(cls, value: Any) -> Any:
        if isinstance(value, dm.DirectRelationReference):
            return dm.NodeId(value.space, value.external_id)
        elif isinstance(value, tuple) and len(value) == 2 and all(isinstance(item, str) for item in value):
            return dm.NodeId(value[0], value[1])
        elif isinstance(value, list):
            return [cls.as_node_id(item) for item in value]
        return value

    def _to_instances_write(
        self,
        cache: set[tuple[str, str]],
        write_none: bool = False,
        allow_version_increase: bool = False,
    ) -> ResourcesWrite:
        resources = ResourcesWrite()
        if self.as_tuple_id() in cache:
            return resources

        properties: dict[str, Any] = {}

        if self.bending_x is not None:
            properties["bending_x"] = {
                "space": self.space if isinstance(self.bending_x, str) else self.bending_x.space,
                "externalId": self.bending_x if isinstance(self.bending_x, str) else self.bending_x.external_id,
            }

        if self.bending_y is not None:
            properties["bending_y"] = {
                "space": self.space if isinstance(self.bending_y, str) else self.bending_y.space,
                "externalId": self.bending_y if isinstance(self.bending_y, str) else self.bending_y.external_id,
            }

        if self.calculated_tilt_moment is not None:
            properties["calculated_tilt_moment"] = {
                "space": (
                    self.space if isinstance(self.calculated_tilt_moment, str) else self.calculated_tilt_moment.space
                ),
                "externalId": (
                    self.calculated_tilt_moment
                    if isinstance(self.calculated_tilt_moment, str)
                    else self.calculated_tilt_moment.external_id
                ),
            }

        if self.calculated_yaw_moment is not None:
            properties["calculated_yaw_moment"] = {
                "space": (
                    self.space if isinstance(self.calculated_yaw_moment, str) else self.calculated_yaw_moment.space
                ),
                "externalId": (
                    self.calculated_yaw_moment
                    if isinstance(self.calculated_yaw_moment, str)
                    else self.calculated_yaw_moment.external_id
                ),
            }

        if self.torque is not None:
            properties["torque"] = {
                "space": self.space if isinstance(self.torque, str) else self.torque.space,
                "externalId": self.torque if isinstance(self.torque, str) else self.torque.external_id,
            }

        if properties:
            this_node = dm.NodeApply(
                space=self.space,
                external_id=self.external_id,
                existing_version=None if allow_version_increase else self.data_record.existing_version,
                type=as_direct_relation_reference(self.node_type),
                sources=[
                    dm.NodeOrEdgeData(
                        source=self._view_id,
                        properties=properties,
                    )
                ],
            )
            resources.nodes.append(this_node)
            cache.add(self.as_tuple_id())

        if isinstance(self.bending_x, DomainModelWrite):
            other_resources = self.bending_x._to_instances_write(cache)
            resources.extend(other_resources)

        if isinstance(self.bending_y, DomainModelWrite):
            other_resources = self.bending_y._to_instances_write(cache)
            resources.extend(other_resources)

        if isinstance(self.calculated_tilt_moment, DomainModelWrite):
            other_resources = self.calculated_tilt_moment._to_instances_write(cache)
            resources.extend(other_resources)

        if isinstance(self.calculated_yaw_moment, DomainModelWrite):
            other_resources = self.calculated_yaw_moment._to_instances_write(cache)
            resources.extend(other_resources)

        if isinstance(self.torque, DomainModelWrite):
            other_resources = self.torque._to_instances_write(cache)
            resources.extend(other_resources)

        return resources

MainShaftWriteList

Bases: DomainModelWriteList[MainShaftWrite]

List of main shafts in the writing version.

Source code in examples/wind_turbine/data_classes/_main_shaft.py
class MainShaftWriteList(DomainModelWriteList[MainShaftWrite]):
    """List of main shafts in the writing version."""

    _INSTANCE = MainShaftWrite

    @property
    def bending_x(self) -> SensorTimeSeriesWriteList:
        from ._sensor_time_series import SensorTimeSeriesWrite, SensorTimeSeriesWriteList

        return SensorTimeSeriesWriteList(
            [item.bending_x for item in self.data if isinstance(item.bending_x, SensorTimeSeriesWrite)]
        )

    @property
    def bending_y(self) -> SensorTimeSeriesWriteList:
        from ._sensor_time_series import SensorTimeSeriesWrite, SensorTimeSeriesWriteList

        return SensorTimeSeriesWriteList(
            [item.bending_y for item in self.data if isinstance(item.bending_y, SensorTimeSeriesWrite)]
        )

    @property
    def calculated_tilt_moment(self) -> SensorTimeSeriesWriteList:
        from ._sensor_time_series import SensorTimeSeriesWrite, SensorTimeSeriesWriteList

        return SensorTimeSeriesWriteList(
            [
                item.calculated_tilt_moment
                for item in self.data
                if isinstance(item.calculated_tilt_moment, SensorTimeSeriesWrite)
            ]
        )

    @property
    def calculated_yaw_moment(self) -> SensorTimeSeriesWriteList:
        from ._sensor_time_series import SensorTimeSeriesWrite, SensorTimeSeriesWriteList

        return SensorTimeSeriesWriteList(
            [
                item.calculated_yaw_moment
                for item in self.data
                if isinstance(item.calculated_yaw_moment, SensorTimeSeriesWrite)
            ]
        )

    @property
    def torque(self) -> SensorTimeSeriesWriteList:
        from ._sensor_time_series import SensorTimeSeriesWrite, SensorTimeSeriesWriteList

        return SensorTimeSeriesWriteList(
            [item.torque for item in self.data if isinstance(item.torque, SensorTimeSeriesWrite)]
        )

Metmast

Bases: DomainModel

This represents the reading version of metmast.

It is used to when data is retrieved from CDF.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the metmast.

required
data_record

The data record of the metmast node.

required
position

The position field.

required
temperature

The temperature field.

required
tilt_angle

The tilt angle field.

required
wind_speed

The wind speed field.

required
wind_turbines

The wind turbine field.

required
Source code in examples/wind_turbine/data_classes/_metmast.py
class Metmast(DomainModel):
    """This represents the reading version of metmast.

    It is used to when data is retrieved from CDF.

    Args:
        space: The space where the node is located.
        external_id: The external id of the metmast.
        data_record: The data record of the metmast node.
        position: The position field.
        temperature: The temperature field.
        tilt_angle: The tilt angle field.
        wind_speed: The wind speed field.
        wind_turbines: The wind turbine field.
    """

    _view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "Metmast", "1")

    space: str = DEFAULT_INSTANCE_SPACE
    node_type: Union[dm.DirectRelationReference, None] = None
    position: Optional[float] = None
    temperature: Union[TimeSeries, str, None] = None
    tilt_angle: Union[TimeSeries, str, None] = None
    wind_speed: Union[TimeSeries, str, None] = None
    wind_turbines: Optional[list[Distance]] = Field(default=None, repr=False)

    def as_write(self) -> MetmastWrite:
        """Convert this read version of metmast to the writing version."""
        return MetmastWrite(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecordWrite(existing_version=self.data_record.version),
            position=self.position,
            temperature=(
                self.temperature.as_write() if isinstance(self.temperature, CogniteTimeSeries) else self.temperature
            ),
            tilt_angle=(
                self.tilt_angle.as_write() if isinstance(self.tilt_angle, CogniteTimeSeries) else self.tilt_angle
            ),
            wind_speed=(
                self.wind_speed.as_write() if isinstance(self.wind_speed, CogniteTimeSeries) else self.wind_speed
            ),
            wind_turbines=[wind_turbine.as_write() for wind_turbine in self.wind_turbines or []],
        )

    def as_apply(self) -> MetmastWrite:
        """Convert this read version of metmast to the writing version."""
        warnings.warn(
            "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
            UserWarning,
            stacklevel=2,
        )
        return self.as_write()

    @classmethod
    def _update_connections(
        cls,
        instances: dict[dm.NodeId | str, Metmast],  # type: ignore[override]
        nodes_by_id: dict[dm.NodeId | str, DomainModel],
        edges_by_source_node: dict[dm.NodeId, list[dm.Edge | DomainRelation]],
    ) -> None:
        from ._distance import Distance

        for instance in instances.values():
            if edges := edges_by_source_node.get(instance.as_id()):
                wind_turbines: list[Distance] = []
                for edge in edges:
                    value: DomainModel | DomainRelation | str | dm.NodeId
                    if isinstance(edge, DomainRelation):
                        value = edge
                    else:
                        other_end: dm.DirectRelationReference = (
                            edge.end_node
                            if edge.start_node.space == instance.space
                            and edge.start_node.external_id == instance.external_id
                            else edge.start_node
                        )
                        destination: dm.NodeId | str = (
                            as_node_id(other_end)
                            if other_end.space != DEFAULT_INSTANCE_SPACE
                            else other_end.external_id
                        )
                        if destination in nodes_by_id:
                            value = nodes_by_id[destination]
                        else:
                            value = destination
                    edge_type = edge.edge_type if isinstance(edge, DomainRelation) else edge.type

                    if edge_type == dm.DirectRelationReference("sp_pygen_power_enterprise", "Distance") and isinstance(
                        value, Distance
                    ):
                        wind_turbines.append(value)
                        if end_node := nodes_by_id.get(as_pygen_node_id(value.end_node)):
                            value.end_node = end_node  # type: ignore[assignment]

                instance.wind_turbines = wind_turbines

as_apply()

Convert this read version of metmast to the writing version.

Source code in examples/wind_turbine/data_classes/_metmast.py
def as_apply(self) -> MetmastWrite:
    """Convert this read version of metmast to the writing version."""
    warnings.warn(
        "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
        UserWarning,
        stacklevel=2,
    )
    return self.as_write()

as_write()

Convert this read version of metmast to the writing version.

Source code in examples/wind_turbine/data_classes/_metmast.py
def as_write(self) -> MetmastWrite:
    """Convert this read version of metmast to the writing version."""
    return MetmastWrite(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecordWrite(existing_version=self.data_record.version),
        position=self.position,
        temperature=(
            self.temperature.as_write() if isinstance(self.temperature, CogniteTimeSeries) else self.temperature
        ),
        tilt_angle=(
            self.tilt_angle.as_write() if isinstance(self.tilt_angle, CogniteTimeSeries) else self.tilt_angle
        ),
        wind_speed=(
            self.wind_speed.as_write() if isinstance(self.wind_speed, CogniteTimeSeries) else self.wind_speed
        ),
        wind_turbines=[wind_turbine.as_write() for wind_turbine in self.wind_turbines or []],
    )

MetmastGraphQL

Bases: GraphQLCore

This represents the reading version of metmast, used when data is retrieved from CDF using GraphQL.

It is used when retrieving data from CDF using GraphQL.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the metmast.

required
data_record

The data record of the metmast node.

required
position

The position field.

required
temperature

The temperature field.

required
tilt_angle

The tilt angle field.

required
wind_speed

The wind speed field.

required
wind_turbines

The wind turbine field.

required
Source code in examples/wind_turbine/data_classes/_metmast.py
class MetmastGraphQL(GraphQLCore):
    """This represents the reading version of metmast, used
    when data is retrieved from CDF using GraphQL.

    It is used when retrieving data from CDF using GraphQL.

    Args:
        space: The space where the node is located.
        external_id: The external id of the metmast.
        data_record: The data record of the metmast node.
        position: The position field.
        temperature: The temperature field.
        tilt_angle: The tilt angle field.
        wind_speed: The wind speed field.
        wind_turbines: The wind turbine field.
    """

    view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "Metmast", "1")
    position: Optional[float] = None
    temperature: Optional[TimeSeriesGraphQL] = None
    tilt_angle: Optional[TimeSeriesGraphQL] = None
    wind_speed: Optional[TimeSeriesGraphQL] = None
    wind_turbines: Optional[list[DistanceGraphQL]] = Field(default=None, repr=False)

    @model_validator(mode="before")
    def parse_data_record(cls, values: Any) -> Any:
        if not isinstance(values, dict):
            return values
        if "lastUpdatedTime" in values or "createdTime" in values:
            values["dataRecord"] = DataRecordGraphQL(
                created_time=values.pop("createdTime", None),
                last_updated_time=values.pop("lastUpdatedTime", None),
            )
        return values

    @field_validator("wind_turbines", mode="before")
    def parse_graphql(cls, value: Any) -> Any:
        if not isinstance(value, dict):
            return value
        if "items" in value:
            return value["items"]
        return value

    # We do the ignore argument type as we let pydantic handle the type checking
    @no_type_check
    def as_read(self) -> Metmast:
        """Convert this GraphQL format of metmast to the reading format."""
        if self.data_record is None:
            raise ValueError("This object cannot be converted to a read format because it lacks a data record.")
        return Metmast(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecord(
                version=0,
                last_updated_time=self.data_record.last_updated_time,
                created_time=self.data_record.created_time,
            ),
            position=self.position,
            temperature=self.temperature.as_read() if self.temperature else None,
            tilt_angle=self.tilt_angle.as_read() if self.tilt_angle else None,
            wind_speed=self.wind_speed.as_read() if self.wind_speed else None,
            wind_turbines=[wind_turbine.as_read() for wind_turbine in self.wind_turbines or []],
        )

    # We do the ignore argument type as we let pydantic handle the type checking
    @no_type_check
    def as_write(self) -> MetmastWrite:
        """Convert this GraphQL format of metmast to the writing format."""
        return MetmastWrite(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecordWrite(existing_version=0),
            position=self.position,
            temperature=self.temperature.as_write() if self.temperature else None,
            tilt_angle=self.tilt_angle.as_write() if self.tilt_angle else None,
            wind_speed=self.wind_speed.as_write() if self.wind_speed else None,
            wind_turbines=[wind_turbine.as_write() for wind_turbine in self.wind_turbines or []],
        )

as_read()

Convert this GraphQL format of metmast to the reading format.

Source code in examples/wind_turbine/data_classes/_metmast.py
@no_type_check
def as_read(self) -> Metmast:
    """Convert this GraphQL format of metmast to the reading format."""
    if self.data_record is None:
        raise ValueError("This object cannot be converted to a read format because it lacks a data record.")
    return Metmast(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecord(
            version=0,
            last_updated_time=self.data_record.last_updated_time,
            created_time=self.data_record.created_time,
        ),
        position=self.position,
        temperature=self.temperature.as_read() if self.temperature else None,
        tilt_angle=self.tilt_angle.as_read() if self.tilt_angle else None,
        wind_speed=self.wind_speed.as_read() if self.wind_speed else None,
        wind_turbines=[wind_turbine.as_read() for wind_turbine in self.wind_turbines or []],
    )

as_write()

Convert this GraphQL format of metmast to the writing format.

Source code in examples/wind_turbine/data_classes/_metmast.py
@no_type_check
def as_write(self) -> MetmastWrite:
    """Convert this GraphQL format of metmast to the writing format."""
    return MetmastWrite(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecordWrite(existing_version=0),
        position=self.position,
        temperature=self.temperature.as_write() if self.temperature else None,
        tilt_angle=self.tilt_angle.as_write() if self.tilt_angle else None,
        wind_speed=self.wind_speed.as_write() if self.wind_speed else None,
        wind_turbines=[wind_turbine.as_write() for wind_turbine in self.wind_turbines or []],
    )

MetmastList

Bases: DomainModelList[Metmast]

List of metmasts in the read version.

Source code in examples/wind_turbine/data_classes/_metmast.py
class MetmastList(DomainModelList[Metmast]):
    """List of metmasts in the read version."""

    _INSTANCE = Metmast

    def as_write(self) -> MetmastWriteList:
        """Convert these read versions of metmast to the writing versions."""
        return MetmastWriteList([node.as_write() for node in self.data])

    def as_apply(self) -> MetmastWriteList:
        """Convert these read versions of primitive nullable to the writing versions."""
        warnings.warn(
            "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
            UserWarning,
            stacklevel=2,
        )
        return self.as_write()

    @property
    def wind_turbines(self) -> DistanceList:
        from ._distance import Distance, DistanceList

        return DistanceList(
            [item for items in self.data for item in items.wind_turbines or [] if isinstance(item, Distance)]
        )

as_apply()

Convert these read versions of primitive nullable to the writing versions.

Source code in examples/wind_turbine/data_classes/_metmast.py
def as_apply(self) -> MetmastWriteList:
    """Convert these read versions of primitive nullable to the writing versions."""
    warnings.warn(
        "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
        UserWarning,
        stacklevel=2,
    )
    return self.as_write()

as_write()

Convert these read versions of metmast to the writing versions.

Source code in examples/wind_turbine/data_classes/_metmast.py
def as_write(self) -> MetmastWriteList:
    """Convert these read versions of metmast to the writing versions."""
    return MetmastWriteList([node.as_write() for node in self.data])

MetmastWrite

Bases: DomainModelWrite

This represents the writing version of metmast.

It is used to when data is sent to CDF.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the metmast.

required
data_record

The data record of the metmast node.

required
position

The position field.

required
temperature

The temperature field.

required
tilt_angle

The tilt angle field.

required
wind_speed

The wind speed field.

required
wind_turbines

The wind turbine field.

required
Source code in examples/wind_turbine/data_classes/_metmast.py
class MetmastWrite(DomainModelWrite):
    """This represents the writing version of metmast.

    It is used to when data is sent to CDF.

    Args:
        space: The space where the node is located.
        external_id: The external id of the metmast.
        data_record: The data record of the metmast node.
        position: The position field.
        temperature: The temperature field.
        tilt_angle: The tilt angle field.
        wind_speed: The wind speed field.
        wind_turbines: The wind turbine field.
    """

    _view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "Metmast", "1")

    space: str = DEFAULT_INSTANCE_SPACE
    node_type: Union[dm.DirectRelationReference, dm.NodeId, tuple[str, str], None] = None
    position: Optional[float] = None
    temperature: Union[TimeSeriesWrite, str, None] = None
    tilt_angle: Union[TimeSeriesWrite, str, None] = None
    wind_speed: Union[TimeSeriesWrite, str, None] = None
    wind_turbines: Optional[list[DistanceWrite]] = Field(default=None, repr=False)

    @field_validator("wind_turbines", mode="before")
    def as_node_id(cls, value: Any) -> Any:
        if isinstance(value, dm.DirectRelationReference):
            return dm.NodeId(value.space, value.external_id)
        elif isinstance(value, tuple) and len(value) == 2 and all(isinstance(item, str) for item in value):
            return dm.NodeId(value[0], value[1])
        elif isinstance(value, list):
            return [cls.as_node_id(item) for item in value]
        return value

    def _to_instances_write(
        self,
        cache: set[tuple[str, str]],
        write_none: bool = False,
        allow_version_increase: bool = False,
    ) -> ResourcesWrite:
        resources = ResourcesWrite()
        if self.as_tuple_id() in cache:
            return resources

        properties: dict[str, Any] = {}

        if self.position is not None or write_none:
            properties["position"] = self.position

        if self.temperature is not None or write_none:
            properties["temperature"] = (
                self.temperature
                if isinstance(self.temperature, str) or self.temperature is None
                else self.temperature.external_id
            )

        if self.tilt_angle is not None or write_none:
            properties["tilt_angle"] = (
                self.tilt_angle
                if isinstance(self.tilt_angle, str) or self.tilt_angle is None
                else self.tilt_angle.external_id
            )

        if self.wind_speed is not None or write_none:
            properties["wind_speed"] = (
                self.wind_speed
                if isinstance(self.wind_speed, str) or self.wind_speed is None
                else self.wind_speed.external_id
            )

        if properties:
            this_node = dm.NodeApply(
                space=self.space,
                external_id=self.external_id,
                existing_version=None if allow_version_increase else self.data_record.existing_version,
                type=as_direct_relation_reference(self.node_type),
                sources=[
                    dm.NodeOrEdgeData(
                        source=self._view_id,
                        properties=properties,
                    )
                ],
            )
            resources.nodes.append(this_node)
            cache.add(self.as_tuple_id())

        for wind_turbine in self.wind_turbines or []:
            if isinstance(wind_turbine, DomainRelationWrite):
                other_resources = wind_turbine._to_instances_write(
                    cache,
                    self,
                    dm.DirectRelationReference("sp_pygen_power_enterprise", "Distance"),
                )
                resources.extend(other_resources)

        if isinstance(self.temperature, CogniteTimeSeriesWrite):
            resources.time_series.append(self.temperature)

        if isinstance(self.tilt_angle, CogniteTimeSeriesWrite):
            resources.time_series.append(self.tilt_angle)

        if isinstance(self.wind_speed, CogniteTimeSeriesWrite):
            resources.time_series.append(self.wind_speed)

        return resources

MetmastWriteList

Bases: DomainModelWriteList[MetmastWrite]

List of metmasts in the writing version.

Source code in examples/wind_turbine/data_classes/_metmast.py
class MetmastWriteList(DomainModelWriteList[MetmastWrite]):
    """List of metmasts in the writing version."""

    _INSTANCE = MetmastWrite

    @property
    def wind_turbines(self) -> DistanceWriteList:
        from ._distance import DistanceWrite, DistanceWriteList

        return DistanceWriteList(
            [item for items in self.data for item in items.wind_turbines or [] if isinstance(item, DistanceWrite)]
        )

Nacelle

Bases: DomainModel

This represents the reading version of nacelle.

It is used to when data is retrieved from CDF.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the nacelle.

required
data_record

The data record of the nacelle node.

required
acc_from_back_side_x

The acc from back side x field.

required
acc_from_back_side_y

The acc from back side y field.

required
acc_from_back_side_z

The acc from back side z field.

required
gearbox

The gearbox field.

required
generator

The generator field.

required
high_speed_shaft

The high speed shaft field.

required
main_shaft

The main shaft field.

required
power_inverter

The power inverter field.

required
wind_turbine

The wind turbine field.

required
yaw_direction

The yaw direction field.

required
yaw_error

The yaw error field.

required
Source code in examples/wind_turbine/data_classes/_nacelle.py
class Nacelle(DomainModel):
    """This represents the reading version of nacelle.

    It is used to when data is retrieved from CDF.

    Args:
        space: The space where the node is located.
        external_id: The external id of the nacelle.
        data_record: The data record of the nacelle node.
        acc_from_back_side_x: The acc from back side x field.
        acc_from_back_side_y: The acc from back side y field.
        acc_from_back_side_z: The acc from back side z field.
        gearbox: The gearbox field.
        generator: The generator field.
        high_speed_shaft: The high speed shaft field.
        main_shaft: The main shaft field.
        power_inverter: The power inverter field.
        wind_turbine: The wind turbine field.
        yaw_direction: The yaw direction field.
        yaw_error: The yaw error field.
    """

    _view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "Nacelle", "1")

    space: str = DEFAULT_INSTANCE_SPACE
    node_type: Union[dm.DirectRelationReference, None] = None
    acc_from_back_side_x: Union[str, dm.NodeId, None] = Field(default=None)
    acc_from_back_side_y: Union[SensorTimeSeries, str, dm.NodeId, None] = Field(default=None, repr=False)
    acc_from_back_side_z: Union[SensorTimeSeries, str, dm.NodeId, None] = Field(default=None, repr=False)
    gearbox: Union[Gearbox, str, dm.NodeId, None] = Field(default=None, repr=False)
    generator: Union[Generator, str, dm.NodeId, None] = Field(default=None, repr=False)
    high_speed_shaft: Union[HighSpeedShaft, str, dm.NodeId, None] = Field(default=None, repr=False)
    main_shaft: Union[MainShaft, str, dm.NodeId, None] = Field(default=None, repr=False)
    power_inverter: Union[PowerInverter, str, dm.NodeId, None] = Field(default=None, repr=False)
    wind_turbine: Optional[WindTurbine] = Field(default=None, repr=False)
    yaw_direction: Union[SensorTimeSeries, str, dm.NodeId, None] = Field(default=None, repr=False)
    yaw_error: Union[SensorTimeSeries, str, dm.NodeId, None] = Field(default=None, repr=False)

    def as_write(self) -> NacelleWrite:
        """Convert this read version of nacelle to the writing version."""
        return NacelleWrite(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecordWrite(existing_version=self.data_record.version),
            acc_from_back_side_x=self.acc_from_back_side_x,
            acc_from_back_side_y=(
                self.acc_from_back_side_y.as_write()
                if isinstance(self.acc_from_back_side_y, DomainModel)
                else self.acc_from_back_side_y
            ),
            acc_from_back_side_z=(
                self.acc_from_back_side_z.as_write()
                if isinstance(self.acc_from_back_side_z, DomainModel)
                else self.acc_from_back_side_z
            ),
            gearbox=self.gearbox.as_write() if isinstance(self.gearbox, DomainModel) else self.gearbox,
            generator=self.generator.as_write() if isinstance(self.generator, DomainModel) else self.generator,
            high_speed_shaft=(
                self.high_speed_shaft.as_write()
                if isinstance(self.high_speed_shaft, DomainModel)
                else self.high_speed_shaft
            ),
            main_shaft=self.main_shaft.as_write() if isinstance(self.main_shaft, DomainModel) else self.main_shaft,
            power_inverter=(
                self.power_inverter.as_write() if isinstance(self.power_inverter, DomainModel) else self.power_inverter
            ),
            yaw_direction=(
                self.yaw_direction.as_write() if isinstance(self.yaw_direction, DomainModel) else self.yaw_direction
            ),
            yaw_error=self.yaw_error.as_write() if isinstance(self.yaw_error, DomainModel) else self.yaw_error,
        )

    def as_apply(self) -> NacelleWrite:
        """Convert this read version of nacelle to the writing version."""
        warnings.warn(
            "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
            UserWarning,
            stacklevel=2,
        )
        return self.as_write()

    @classmethod
    def _update_connections(
        cls,
        instances: dict[dm.NodeId | str, Nacelle],  # type: ignore[override]
        nodes_by_id: dict[dm.NodeId | str, DomainModel],
        edges_by_source_node: dict[dm.NodeId, list[dm.Edge | DomainRelation]],
    ) -> None:
        from ._gearbox import Gearbox
        from ._generator import Generator
        from ._high_speed_shaft import HighSpeedShaft
        from ._main_shaft import MainShaft
        from ._power_inverter import PowerInverter
        from ._sensor_time_series import SensorTimeSeries
        from ._wind_turbine import WindTurbine

        for instance in instances.values():
            if (
                isinstance(instance.acc_from_back_side_y, (dm.NodeId, str))
                and (acc_from_back_side_y := nodes_by_id.get(instance.acc_from_back_side_y))
                and isinstance(acc_from_back_side_y, SensorTimeSeries)
            ):
                instance.acc_from_back_side_y = acc_from_back_side_y
            if (
                isinstance(instance.acc_from_back_side_z, (dm.NodeId, str))
                and (acc_from_back_side_z := nodes_by_id.get(instance.acc_from_back_side_z))
                and isinstance(acc_from_back_side_z, SensorTimeSeries)
            ):
                instance.acc_from_back_side_z = acc_from_back_side_z
            if (
                isinstance(instance.gearbox, (dm.NodeId, str))
                and (gearbox := nodes_by_id.get(instance.gearbox))
                and isinstance(gearbox, Gearbox)
            ):
                instance.gearbox = gearbox
            if (
                isinstance(instance.generator, (dm.NodeId, str))
                and (generator := nodes_by_id.get(instance.generator))
                and isinstance(generator, Generator)
            ):
                instance.generator = generator
            if (
                isinstance(instance.high_speed_shaft, (dm.NodeId, str))
                and (high_speed_shaft := nodes_by_id.get(instance.high_speed_shaft))
                and isinstance(high_speed_shaft, HighSpeedShaft)
            ):
                instance.high_speed_shaft = high_speed_shaft
            if (
                isinstance(instance.main_shaft, (dm.NodeId, str))
                and (main_shaft := nodes_by_id.get(instance.main_shaft))
                and isinstance(main_shaft, MainShaft)
            ):
                instance.main_shaft = main_shaft
            if (
                isinstance(instance.power_inverter, (dm.NodeId, str))
                and (power_inverter := nodes_by_id.get(instance.power_inverter))
                and isinstance(power_inverter, PowerInverter)
            ):
                instance.power_inverter = power_inverter
            if (
                isinstance(instance.yaw_direction, (dm.NodeId, str))
                and (yaw_direction := nodes_by_id.get(instance.yaw_direction))
                and isinstance(yaw_direction, SensorTimeSeries)
            ):
                instance.yaw_direction = yaw_direction
            if (
                isinstance(instance.yaw_error, (dm.NodeId, str))
                and (yaw_error := nodes_by_id.get(instance.yaw_error))
                and isinstance(yaw_error, SensorTimeSeries)
            ):
                instance.yaw_error = yaw_error
        for node in nodes_by_id.values():
            if (
                isinstance(node, WindTurbine)
                and node.nacelle is not None
                and (nacelle := instances.get(as_pygen_node_id(node.nacelle)))
            ):
                if nacelle.wind_turbine is None:
                    nacelle.wind_turbine = node
                elif are_nodes_equal(node, nacelle.wind_turbine):
                    # This is the same node, so we don't need to do anything...
                    ...
                else:
                    warnings.warn(
                        f"Expected one direct relation for 'wind_turbine' in {nacelle.as_id()}."
                        f"Ignoring new relation {node!s} in favor of {nacelle.wind_turbine!s}."
                    )

as_apply()

Convert this read version of nacelle to the writing version.

Source code in examples/wind_turbine/data_classes/_nacelle.py
def as_apply(self) -> NacelleWrite:
    """Convert this read version of nacelle to the writing version."""
    warnings.warn(
        "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
        UserWarning,
        stacklevel=2,
    )
    return self.as_write()

as_write()

Convert this read version of nacelle to the writing version.

Source code in examples/wind_turbine/data_classes/_nacelle.py
def as_write(self) -> NacelleWrite:
    """Convert this read version of nacelle to the writing version."""
    return NacelleWrite(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecordWrite(existing_version=self.data_record.version),
        acc_from_back_side_x=self.acc_from_back_side_x,
        acc_from_back_side_y=(
            self.acc_from_back_side_y.as_write()
            if isinstance(self.acc_from_back_side_y, DomainModel)
            else self.acc_from_back_side_y
        ),
        acc_from_back_side_z=(
            self.acc_from_back_side_z.as_write()
            if isinstance(self.acc_from_back_side_z, DomainModel)
            else self.acc_from_back_side_z
        ),
        gearbox=self.gearbox.as_write() if isinstance(self.gearbox, DomainModel) else self.gearbox,
        generator=self.generator.as_write() if isinstance(self.generator, DomainModel) else self.generator,
        high_speed_shaft=(
            self.high_speed_shaft.as_write()
            if isinstance(self.high_speed_shaft, DomainModel)
            else self.high_speed_shaft
        ),
        main_shaft=self.main_shaft.as_write() if isinstance(self.main_shaft, DomainModel) else self.main_shaft,
        power_inverter=(
            self.power_inverter.as_write() if isinstance(self.power_inverter, DomainModel) else self.power_inverter
        ),
        yaw_direction=(
            self.yaw_direction.as_write() if isinstance(self.yaw_direction, DomainModel) else self.yaw_direction
        ),
        yaw_error=self.yaw_error.as_write() if isinstance(self.yaw_error, DomainModel) else self.yaw_error,
    )

NacelleGraphQL

Bases: GraphQLCore

This represents the reading version of nacelle, used when data is retrieved from CDF using GraphQL.

It is used when retrieving data from CDF using GraphQL.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the nacelle.

required
data_record

The data record of the nacelle node.

required
acc_from_back_side_x

The acc from back side x field.

required
acc_from_back_side_y

The acc from back side y field.

required
acc_from_back_side_z

The acc from back side z field.

required
gearbox

The gearbox field.

required
generator

The generator field.

required
high_speed_shaft

The high speed shaft field.

required
main_shaft

The main shaft field.

required
power_inverter

The power inverter field.

required
wind_turbine

The wind turbine field.

required
yaw_direction

The yaw direction field.

required
yaw_error

The yaw error field.

required
Source code in examples/wind_turbine/data_classes/_nacelle.py
class NacelleGraphQL(GraphQLCore):
    """This represents the reading version of nacelle, used
    when data is retrieved from CDF using GraphQL.

    It is used when retrieving data from CDF using GraphQL.

    Args:
        space: The space where the node is located.
        external_id: The external id of the nacelle.
        data_record: The data record of the nacelle node.
        acc_from_back_side_x: The acc from back side x field.
        acc_from_back_side_y: The acc from back side y field.
        acc_from_back_side_z: The acc from back side z field.
        gearbox: The gearbox field.
        generator: The generator field.
        high_speed_shaft: The high speed shaft field.
        main_shaft: The main shaft field.
        power_inverter: The power inverter field.
        wind_turbine: The wind turbine field.
        yaw_direction: The yaw direction field.
        yaw_error: The yaw error field.
    """

    view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "Nacelle", "1")
    acc_from_back_side_x: Optional[str] = Field(default=None)
    acc_from_back_side_y: Optional[SensorTimeSeriesGraphQL] = Field(default=None, repr=False)
    acc_from_back_side_z: Optional[SensorTimeSeriesGraphQL] = Field(default=None, repr=False)
    gearbox: Optional[GearboxGraphQL] = Field(default=None, repr=False)
    generator: Optional[GeneratorGraphQL] = Field(default=None, repr=False)
    high_speed_shaft: Optional[HighSpeedShaftGraphQL] = Field(default=None, repr=False)
    main_shaft: Optional[MainShaftGraphQL] = Field(default=None, repr=False)
    power_inverter: Optional[PowerInverterGraphQL] = Field(default=None, repr=False)
    wind_turbine: Optional[WindTurbineGraphQL] = Field(default=None, repr=False)
    yaw_direction: Optional[SensorTimeSeriesGraphQL] = Field(default=None, repr=False)
    yaw_error: Optional[SensorTimeSeriesGraphQL] = Field(default=None, repr=False)

    @model_validator(mode="before")
    def parse_data_record(cls, values: Any) -> Any:
        if not isinstance(values, dict):
            return values
        if "lastUpdatedTime" in values or "createdTime" in values:
            values["dataRecord"] = DataRecordGraphQL(
                created_time=values.pop("createdTime", None),
                last_updated_time=values.pop("lastUpdatedTime", None),
            )
        return values

    @field_validator(
        "acc_from_back_side_x",
        "acc_from_back_side_y",
        "acc_from_back_side_z",
        "gearbox",
        "generator",
        "high_speed_shaft",
        "main_shaft",
        "power_inverter",
        "wind_turbine",
        "yaw_direction",
        "yaw_error",
        mode="before",
    )
    def parse_graphql(cls, value: Any) -> Any:
        if not isinstance(value, dict):
            return value
        if "items" in value:
            return value["items"]
        return value

    # We do the ignore argument type as we let pydantic handle the type checking
    @no_type_check
    def as_read(self) -> Nacelle:
        """Convert this GraphQL format of nacelle to the reading format."""
        if self.data_record is None:
            raise ValueError("This object cannot be converted to a read format because it lacks a data record.")
        return Nacelle(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecord(
                version=0,
                last_updated_time=self.data_record.last_updated_time,
                created_time=self.data_record.created_time,
            ),
            acc_from_back_side_x=self.acc_from_back_side_x,
            acc_from_back_side_y=(
                self.acc_from_back_side_y.as_read()
                if isinstance(self.acc_from_back_side_y, GraphQLCore)
                else self.acc_from_back_side_y
            ),
            acc_from_back_side_z=(
                self.acc_from_back_side_z.as_read()
                if isinstance(self.acc_from_back_side_z, GraphQLCore)
                else self.acc_from_back_side_z
            ),
            gearbox=self.gearbox.as_read() if isinstance(self.gearbox, GraphQLCore) else self.gearbox,
            generator=self.generator.as_read() if isinstance(self.generator, GraphQLCore) else self.generator,
            high_speed_shaft=(
                self.high_speed_shaft.as_read()
                if isinstance(self.high_speed_shaft, GraphQLCore)
                else self.high_speed_shaft
            ),
            main_shaft=self.main_shaft.as_read() if isinstance(self.main_shaft, GraphQLCore) else self.main_shaft,
            power_inverter=(
                self.power_inverter.as_read() if isinstance(self.power_inverter, GraphQLCore) else self.power_inverter
            ),
            wind_turbine=(
                self.wind_turbine.as_read() if isinstance(self.wind_turbine, GraphQLCore) else self.wind_turbine
            ),
            yaw_direction=(
                self.yaw_direction.as_read() if isinstance(self.yaw_direction, GraphQLCore) else self.yaw_direction
            ),
            yaw_error=self.yaw_error.as_read() if isinstance(self.yaw_error, GraphQLCore) else self.yaw_error,
        )

    # We do the ignore argument type as we let pydantic handle the type checking
    @no_type_check
    def as_write(self) -> NacelleWrite:
        """Convert this GraphQL format of nacelle to the writing format."""
        return NacelleWrite(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecordWrite(existing_version=0),
            acc_from_back_side_x=self.acc_from_back_side_x,
            acc_from_back_side_y=(
                self.acc_from_back_side_y.as_write()
                if isinstance(self.acc_from_back_side_y, GraphQLCore)
                else self.acc_from_back_side_y
            ),
            acc_from_back_side_z=(
                self.acc_from_back_side_z.as_write()
                if isinstance(self.acc_from_back_side_z, GraphQLCore)
                else self.acc_from_back_side_z
            ),
            gearbox=self.gearbox.as_write() if isinstance(self.gearbox, GraphQLCore) else self.gearbox,
            generator=self.generator.as_write() if isinstance(self.generator, GraphQLCore) else self.generator,
            high_speed_shaft=(
                self.high_speed_shaft.as_write()
                if isinstance(self.high_speed_shaft, GraphQLCore)
                else self.high_speed_shaft
            ),
            main_shaft=self.main_shaft.as_write() if isinstance(self.main_shaft, GraphQLCore) else self.main_shaft,
            power_inverter=(
                self.power_inverter.as_write() if isinstance(self.power_inverter, GraphQLCore) else self.power_inverter
            ),
            yaw_direction=(
                self.yaw_direction.as_write() if isinstance(self.yaw_direction, GraphQLCore) else self.yaw_direction
            ),
            yaw_error=self.yaw_error.as_write() if isinstance(self.yaw_error, GraphQLCore) else self.yaw_error,
        )

as_read()

Convert this GraphQL format of nacelle to the reading format.

Source code in examples/wind_turbine/data_classes/_nacelle.py
@no_type_check
def as_read(self) -> Nacelle:
    """Convert this GraphQL format of nacelle to the reading format."""
    if self.data_record is None:
        raise ValueError("This object cannot be converted to a read format because it lacks a data record.")
    return Nacelle(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecord(
            version=0,
            last_updated_time=self.data_record.last_updated_time,
            created_time=self.data_record.created_time,
        ),
        acc_from_back_side_x=self.acc_from_back_side_x,
        acc_from_back_side_y=(
            self.acc_from_back_side_y.as_read()
            if isinstance(self.acc_from_back_side_y, GraphQLCore)
            else self.acc_from_back_side_y
        ),
        acc_from_back_side_z=(
            self.acc_from_back_side_z.as_read()
            if isinstance(self.acc_from_back_side_z, GraphQLCore)
            else self.acc_from_back_side_z
        ),
        gearbox=self.gearbox.as_read() if isinstance(self.gearbox, GraphQLCore) else self.gearbox,
        generator=self.generator.as_read() if isinstance(self.generator, GraphQLCore) else self.generator,
        high_speed_shaft=(
            self.high_speed_shaft.as_read()
            if isinstance(self.high_speed_shaft, GraphQLCore)
            else self.high_speed_shaft
        ),
        main_shaft=self.main_shaft.as_read() if isinstance(self.main_shaft, GraphQLCore) else self.main_shaft,
        power_inverter=(
            self.power_inverter.as_read() if isinstance(self.power_inverter, GraphQLCore) else self.power_inverter
        ),
        wind_turbine=(
            self.wind_turbine.as_read() if isinstance(self.wind_turbine, GraphQLCore) else self.wind_turbine
        ),
        yaw_direction=(
            self.yaw_direction.as_read() if isinstance(self.yaw_direction, GraphQLCore) else self.yaw_direction
        ),
        yaw_error=self.yaw_error.as_read() if isinstance(self.yaw_error, GraphQLCore) else self.yaw_error,
    )

as_write()

Convert this GraphQL format of nacelle to the writing format.

Source code in examples/wind_turbine/data_classes/_nacelle.py
@no_type_check
def as_write(self) -> NacelleWrite:
    """Convert this GraphQL format of nacelle to the writing format."""
    return NacelleWrite(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecordWrite(existing_version=0),
        acc_from_back_side_x=self.acc_from_back_side_x,
        acc_from_back_side_y=(
            self.acc_from_back_side_y.as_write()
            if isinstance(self.acc_from_back_side_y, GraphQLCore)
            else self.acc_from_back_side_y
        ),
        acc_from_back_side_z=(
            self.acc_from_back_side_z.as_write()
            if isinstance(self.acc_from_back_side_z, GraphQLCore)
            else self.acc_from_back_side_z
        ),
        gearbox=self.gearbox.as_write() if isinstance(self.gearbox, GraphQLCore) else self.gearbox,
        generator=self.generator.as_write() if isinstance(self.generator, GraphQLCore) else self.generator,
        high_speed_shaft=(
            self.high_speed_shaft.as_write()
            if isinstance(self.high_speed_shaft, GraphQLCore)
            else self.high_speed_shaft
        ),
        main_shaft=self.main_shaft.as_write() if isinstance(self.main_shaft, GraphQLCore) else self.main_shaft,
        power_inverter=(
            self.power_inverter.as_write() if isinstance(self.power_inverter, GraphQLCore) else self.power_inverter
        ),
        yaw_direction=(
            self.yaw_direction.as_write() if isinstance(self.yaw_direction, GraphQLCore) else self.yaw_direction
        ),
        yaw_error=self.yaw_error.as_write() if isinstance(self.yaw_error, GraphQLCore) else self.yaw_error,
    )

NacelleList

Bases: DomainModelList[Nacelle]

List of nacelles in the read version.

Source code in examples/wind_turbine/data_classes/_nacelle.py
class NacelleList(DomainModelList[Nacelle]):
    """List of nacelles in the read version."""

    _INSTANCE = Nacelle

    def as_write(self) -> NacelleWriteList:
        """Convert these read versions of nacelle to the writing versions."""
        return NacelleWriteList([node.as_write() for node in self.data])

    def as_apply(self) -> NacelleWriteList:
        """Convert these read versions of primitive nullable to the writing versions."""
        warnings.warn(
            "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
            UserWarning,
            stacklevel=2,
        )
        return self.as_write()

    @property
    def acc_from_back_side_y(self) -> SensorTimeSeriesList:
        from ._sensor_time_series import SensorTimeSeries, SensorTimeSeriesList

        return SensorTimeSeriesList(
            [item.acc_from_back_side_y for item in self.data if isinstance(item.acc_from_back_side_y, SensorTimeSeries)]
        )

    @property
    def acc_from_back_side_z(self) -> SensorTimeSeriesList:
        from ._sensor_time_series import SensorTimeSeries, SensorTimeSeriesList

        return SensorTimeSeriesList(
            [item.acc_from_back_side_z for item in self.data if isinstance(item.acc_from_back_side_z, SensorTimeSeries)]
        )

    @property
    def gearbox(self) -> GearboxList:
        from ._gearbox import Gearbox, GearboxList

        return GearboxList([item.gearbox for item in self.data if isinstance(item.gearbox, Gearbox)])

    @property
    def generator(self) -> GeneratorList:
        from ._generator import Generator, GeneratorList

        return GeneratorList([item.generator for item in self.data if isinstance(item.generator, Generator)])

    @property
    def high_speed_shaft(self) -> HighSpeedShaftList:
        from ._high_speed_shaft import HighSpeedShaft, HighSpeedShaftList

        return HighSpeedShaftList(
            [item.high_speed_shaft for item in self.data if isinstance(item.high_speed_shaft, HighSpeedShaft)]
        )

    @property
    def main_shaft(self) -> MainShaftList:
        from ._main_shaft import MainShaft, MainShaftList

        return MainShaftList([item.main_shaft for item in self.data if isinstance(item.main_shaft, MainShaft)])

    @property
    def power_inverter(self) -> PowerInverterList:
        from ._power_inverter import PowerInverter, PowerInverterList

        return PowerInverterList(
            [item.power_inverter for item in self.data if isinstance(item.power_inverter, PowerInverter)]
        )

    @property
    def wind_turbine(self) -> WindTurbineList:
        from ._wind_turbine import WindTurbine, WindTurbineList

        return WindTurbineList([item.wind_turbine for item in self.data if isinstance(item.wind_turbine, WindTurbine)])

    @property
    def yaw_direction(self) -> SensorTimeSeriesList:
        from ._sensor_time_series import SensorTimeSeries, SensorTimeSeriesList

        return SensorTimeSeriesList(
            [item.yaw_direction for item in self.data if isinstance(item.yaw_direction, SensorTimeSeries)]
        )

    @property
    def yaw_error(self) -> SensorTimeSeriesList:
        from ._sensor_time_series import SensorTimeSeries, SensorTimeSeriesList

        return SensorTimeSeriesList(
            [item.yaw_error for item in self.data if isinstance(item.yaw_error, SensorTimeSeries)]
        )

as_apply()

Convert these read versions of primitive nullable to the writing versions.

Source code in examples/wind_turbine/data_classes/_nacelle.py
def as_apply(self) -> NacelleWriteList:
    """Convert these read versions of primitive nullable to the writing versions."""
    warnings.warn(
        "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
        UserWarning,
        stacklevel=2,
    )
    return self.as_write()

as_write()

Convert these read versions of nacelle to the writing versions.

Source code in examples/wind_turbine/data_classes/_nacelle.py
def as_write(self) -> NacelleWriteList:
    """Convert these read versions of nacelle to the writing versions."""
    return NacelleWriteList([node.as_write() for node in self.data])

NacelleWrite

Bases: DomainModelWrite

This represents the writing version of nacelle.

It is used to when data is sent to CDF.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the nacelle.

required
data_record

The data record of the nacelle node.

required
acc_from_back_side_x

The acc from back side x field.

required
acc_from_back_side_y

The acc from back side y field.

required
acc_from_back_side_z

The acc from back side z field.

required
gearbox

The gearbox field.

required
generator

The generator field.

required
high_speed_shaft

The high speed shaft field.

required
main_shaft

The main shaft field.

required
power_inverter

The power inverter field.

required
yaw_direction

The yaw direction field.

required
yaw_error

The yaw error field.

required
Source code in examples/wind_turbine/data_classes/_nacelle.py
class NacelleWrite(DomainModelWrite):
    """This represents the writing version of nacelle.

    It is used to when data is sent to CDF.

    Args:
        space: The space where the node is located.
        external_id: The external id of the nacelle.
        data_record: The data record of the nacelle node.
        acc_from_back_side_x: The acc from back side x field.
        acc_from_back_side_y: The acc from back side y field.
        acc_from_back_side_z: The acc from back side z field.
        gearbox: The gearbox field.
        generator: The generator field.
        high_speed_shaft: The high speed shaft field.
        main_shaft: The main shaft field.
        power_inverter: The power inverter field.
        yaw_direction: The yaw direction field.
        yaw_error: The yaw error field.
    """

    _view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "Nacelle", "1")

    space: str = DEFAULT_INSTANCE_SPACE
    node_type: Union[dm.DirectRelationReference, dm.NodeId, tuple[str, str], None] = None
    acc_from_back_side_x: Union[str, dm.NodeId, None] = Field(default=None)
    acc_from_back_side_y: Union[SensorTimeSeriesWrite, str, dm.NodeId, None] = Field(default=None, repr=False)
    acc_from_back_side_z: Union[SensorTimeSeriesWrite, str, dm.NodeId, None] = Field(default=None, repr=False)
    gearbox: Union[GearboxWrite, str, dm.NodeId, None] = Field(default=None, repr=False)
    generator: Union[GeneratorWrite, str, dm.NodeId, None] = Field(default=None, repr=False)
    high_speed_shaft: Union[HighSpeedShaftWrite, str, dm.NodeId, None] = Field(default=None, repr=False)
    main_shaft: Union[MainShaftWrite, str, dm.NodeId, None] = Field(default=None, repr=False)
    power_inverter: Union[PowerInverterWrite, str, dm.NodeId, None] = Field(default=None, repr=False)
    yaw_direction: Union[SensorTimeSeriesWrite, str, dm.NodeId, None] = Field(default=None, repr=False)
    yaw_error: Union[SensorTimeSeriesWrite, str, dm.NodeId, None] = Field(default=None, repr=False)

    @field_validator(
        "acc_from_back_side_y",
        "acc_from_back_side_z",
        "gearbox",
        "generator",
        "high_speed_shaft",
        "main_shaft",
        "power_inverter",
        "yaw_direction",
        "yaw_error",
        mode="before",
    )
    def as_node_id(cls, value: Any) -> Any:
        if isinstance(value, dm.DirectRelationReference):
            return dm.NodeId(value.space, value.external_id)
        elif isinstance(value, tuple) and len(value) == 2 and all(isinstance(item, str) for item in value):
            return dm.NodeId(value[0], value[1])
        elif isinstance(value, list):
            return [cls.as_node_id(item) for item in value]
        return value

    def _to_instances_write(
        self,
        cache: set[tuple[str, str]],
        write_none: bool = False,
        allow_version_increase: bool = False,
    ) -> ResourcesWrite:
        resources = ResourcesWrite()
        if self.as_tuple_id() in cache:
            return resources

        properties: dict[str, Any] = {}

        if self.acc_from_back_side_x is not None:
            properties["acc_from_back_side_x"] = {
                "space": self.space if isinstance(self.acc_from_back_side_x, str) else self.acc_from_back_side_x.space,
                "externalId": (
                    self.acc_from_back_side_x
                    if isinstance(self.acc_from_back_side_x, str)
                    else self.acc_from_back_side_x.external_id
                ),
            }

        if self.acc_from_back_side_y is not None:
            properties["acc_from_back_side_y"] = {
                "space": self.space if isinstance(self.acc_from_back_side_y, str) else self.acc_from_back_side_y.space,
                "externalId": (
                    self.acc_from_back_side_y
                    if isinstance(self.acc_from_back_side_y, str)
                    else self.acc_from_back_side_y.external_id
                ),
            }

        if self.acc_from_back_side_z is not None:
            properties["acc_from_back_side_z"] = {
                "space": self.space if isinstance(self.acc_from_back_side_z, str) else self.acc_from_back_side_z.space,
                "externalId": (
                    self.acc_from_back_side_z
                    if isinstance(self.acc_from_back_side_z, str)
                    else self.acc_from_back_side_z.external_id
                ),
            }

        if self.gearbox is not None:
            properties["gearbox"] = {
                "space": self.space if isinstance(self.gearbox, str) else self.gearbox.space,
                "externalId": self.gearbox if isinstance(self.gearbox, str) else self.gearbox.external_id,
            }

        if self.generator is not None:
            properties["generator"] = {
                "space": self.space if isinstance(self.generator, str) else self.generator.space,
                "externalId": self.generator if isinstance(self.generator, str) else self.generator.external_id,
            }

        if self.high_speed_shaft is not None:
            properties["high_speed_shaft"] = {
                "space": self.space if isinstance(self.high_speed_shaft, str) else self.high_speed_shaft.space,
                "externalId": (
                    self.high_speed_shaft
                    if isinstance(self.high_speed_shaft, str)
                    else self.high_speed_shaft.external_id
                ),
            }

        if self.main_shaft is not None:
            properties["main_shaft"] = {
                "space": self.space if isinstance(self.main_shaft, str) else self.main_shaft.space,
                "externalId": self.main_shaft if isinstance(self.main_shaft, str) else self.main_shaft.external_id,
            }

        if self.power_inverter is not None:
            properties["power_inverter"] = {
                "space": self.space if isinstance(self.power_inverter, str) else self.power_inverter.space,
                "externalId": (
                    self.power_inverter if isinstance(self.power_inverter, str) else self.power_inverter.external_id
                ),
            }

        if self.yaw_direction is not None:
            properties["yaw_direction"] = {
                "space": self.space if isinstance(self.yaw_direction, str) else self.yaw_direction.space,
                "externalId": (
                    self.yaw_direction if isinstance(self.yaw_direction, str) else self.yaw_direction.external_id
                ),
            }

        if self.yaw_error is not None:
            properties["yaw_error"] = {
                "space": self.space if isinstance(self.yaw_error, str) else self.yaw_error.space,
                "externalId": self.yaw_error if isinstance(self.yaw_error, str) else self.yaw_error.external_id,
            }

        if properties:
            this_node = dm.NodeApply(
                space=self.space,
                external_id=self.external_id,
                existing_version=None if allow_version_increase else self.data_record.existing_version,
                type=as_direct_relation_reference(self.node_type),
                sources=[
                    dm.NodeOrEdgeData(
                        source=self._view_id,
                        properties=properties,
                    )
                ],
            )
            resources.nodes.append(this_node)
            cache.add(self.as_tuple_id())

        if isinstance(self.acc_from_back_side_y, DomainModelWrite):
            other_resources = self.acc_from_back_side_y._to_instances_write(cache)
            resources.extend(other_resources)

        if isinstance(self.acc_from_back_side_z, DomainModelWrite):
            other_resources = self.acc_from_back_side_z._to_instances_write(cache)
            resources.extend(other_resources)

        if isinstance(self.gearbox, DomainModelWrite):
            other_resources = self.gearbox._to_instances_write(cache)
            resources.extend(other_resources)

        if isinstance(self.generator, DomainModelWrite):
            other_resources = self.generator._to_instances_write(cache)
            resources.extend(other_resources)

        if isinstance(self.high_speed_shaft, DomainModelWrite):
            other_resources = self.high_speed_shaft._to_instances_write(cache)
            resources.extend(other_resources)

        if isinstance(self.main_shaft, DomainModelWrite):
            other_resources = self.main_shaft._to_instances_write(cache)
            resources.extend(other_resources)

        if isinstance(self.power_inverter, DomainModelWrite):
            other_resources = self.power_inverter._to_instances_write(cache)
            resources.extend(other_resources)

        if isinstance(self.yaw_direction, DomainModelWrite):
            other_resources = self.yaw_direction._to_instances_write(cache)
            resources.extend(other_resources)

        if isinstance(self.yaw_error, DomainModelWrite):
            other_resources = self.yaw_error._to_instances_write(cache)
            resources.extend(other_resources)

        return resources

NacelleWriteList

Bases: DomainModelWriteList[NacelleWrite]

List of nacelles in the writing version.

Source code in examples/wind_turbine/data_classes/_nacelle.py
class NacelleWriteList(DomainModelWriteList[NacelleWrite]):
    """List of nacelles in the writing version."""

    _INSTANCE = NacelleWrite

    @property
    def acc_from_back_side_y(self) -> SensorTimeSeriesWriteList:
        from ._sensor_time_series import SensorTimeSeriesWrite, SensorTimeSeriesWriteList

        return SensorTimeSeriesWriteList(
            [
                item.acc_from_back_side_y
                for item in self.data
                if isinstance(item.acc_from_back_side_y, SensorTimeSeriesWrite)
            ]
        )

    @property
    def acc_from_back_side_z(self) -> SensorTimeSeriesWriteList:
        from ._sensor_time_series import SensorTimeSeriesWrite, SensorTimeSeriesWriteList

        return SensorTimeSeriesWriteList(
            [
                item.acc_from_back_side_z
                for item in self.data
                if isinstance(item.acc_from_back_side_z, SensorTimeSeriesWrite)
            ]
        )

    @property
    def gearbox(self) -> GearboxWriteList:
        from ._gearbox import GearboxWrite, GearboxWriteList

        return GearboxWriteList([item.gearbox for item in self.data if isinstance(item.gearbox, GearboxWrite)])

    @property
    def generator(self) -> GeneratorWriteList:
        from ._generator import GeneratorWrite, GeneratorWriteList

        return GeneratorWriteList([item.generator for item in self.data if isinstance(item.generator, GeneratorWrite)])

    @property
    def high_speed_shaft(self) -> HighSpeedShaftWriteList:
        from ._high_speed_shaft import HighSpeedShaftWrite, HighSpeedShaftWriteList

        return HighSpeedShaftWriteList(
            [item.high_speed_shaft for item in self.data if isinstance(item.high_speed_shaft, HighSpeedShaftWrite)]
        )

    @property
    def main_shaft(self) -> MainShaftWriteList:
        from ._main_shaft import MainShaftWrite, MainShaftWriteList

        return MainShaftWriteList(
            [item.main_shaft for item in self.data if isinstance(item.main_shaft, MainShaftWrite)]
        )

    @property
    def power_inverter(self) -> PowerInverterWriteList:
        from ._power_inverter import PowerInverterWrite, PowerInverterWriteList

        return PowerInverterWriteList(
            [item.power_inverter for item in self.data if isinstance(item.power_inverter, PowerInverterWrite)]
        )

    @property
    def yaw_direction(self) -> SensorTimeSeriesWriteList:
        from ._sensor_time_series import SensorTimeSeriesWrite, SensorTimeSeriesWriteList

        return SensorTimeSeriesWriteList(
            [item.yaw_direction for item in self.data if isinstance(item.yaw_direction, SensorTimeSeriesWrite)]
        )

    @property
    def yaw_error(self) -> SensorTimeSeriesWriteList:
        from ._sensor_time_series import SensorTimeSeriesWrite, SensorTimeSeriesWriteList

        return SensorTimeSeriesWriteList(
            [item.yaw_error for item in self.data if isinstance(item.yaw_error, SensorTimeSeriesWrite)]
        )

PowerInverter

Bases: DomainModel

This represents the reading version of power inverter.

It is used to when data is retrieved from CDF.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the power inverter.

required
data_record

The data record of the power inverter node.

required
active_power_total

The active power total field.

required
apparent_power_total

The apparent power total field.

required
nacelle

The nacelle field.

required
reactive_power_total

The reactive power total field.

required
Source code in examples/wind_turbine/data_classes/_power_inverter.py
class PowerInverter(DomainModel):
    """This represents the reading version of power inverter.

    It is used to when data is retrieved from CDF.

    Args:
        space: The space where the node is located.
        external_id: The external id of the power inverter.
        data_record: The data record of the power inverter node.
        active_power_total: The active power total field.
        apparent_power_total: The apparent power total field.
        nacelle: The nacelle field.
        reactive_power_total: The reactive power total field.
    """

    _view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "PowerInverter", "1")

    space: str = DEFAULT_INSTANCE_SPACE
    node_type: Union[dm.DirectRelationReference, None] = None
    active_power_total: Union[SensorTimeSeries, str, dm.NodeId, None] = Field(default=None, repr=False)
    apparent_power_total: Union[SensorTimeSeries, str, dm.NodeId, None] = Field(default=None, repr=False)
    nacelle: Optional[Nacelle] = Field(default=None, repr=False)
    reactive_power_total: Union[SensorTimeSeries, str, dm.NodeId, None] = Field(default=None, repr=False)

    def as_write(self) -> PowerInverterWrite:
        """Convert this read version of power inverter to the writing version."""
        return PowerInverterWrite(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecordWrite(existing_version=self.data_record.version),
            active_power_total=(
                self.active_power_total.as_write()
                if isinstance(self.active_power_total, DomainModel)
                else self.active_power_total
            ),
            apparent_power_total=(
                self.apparent_power_total.as_write()
                if isinstance(self.apparent_power_total, DomainModel)
                else self.apparent_power_total
            ),
            reactive_power_total=(
                self.reactive_power_total.as_write()
                if isinstance(self.reactive_power_total, DomainModel)
                else self.reactive_power_total
            ),
        )

    def as_apply(self) -> PowerInverterWrite:
        """Convert this read version of power inverter to the writing version."""
        warnings.warn(
            "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
            UserWarning,
            stacklevel=2,
        )
        return self.as_write()

    @classmethod
    def _update_connections(
        cls,
        instances: dict[dm.NodeId | str, PowerInverter],  # type: ignore[override]
        nodes_by_id: dict[dm.NodeId | str, DomainModel],
        edges_by_source_node: dict[dm.NodeId, list[dm.Edge | DomainRelation]],
    ) -> None:
        from ._nacelle import Nacelle
        from ._sensor_time_series import SensorTimeSeries

        for instance in instances.values():
            if (
                isinstance(instance.active_power_total, (dm.NodeId, str))
                and (active_power_total := nodes_by_id.get(instance.active_power_total))
                and isinstance(active_power_total, SensorTimeSeries)
            ):
                instance.active_power_total = active_power_total
            if (
                isinstance(instance.apparent_power_total, (dm.NodeId, str))
                and (apparent_power_total := nodes_by_id.get(instance.apparent_power_total))
                and isinstance(apparent_power_total, SensorTimeSeries)
            ):
                instance.apparent_power_total = apparent_power_total
            if (
                isinstance(instance.reactive_power_total, (dm.NodeId, str))
                and (reactive_power_total := nodes_by_id.get(instance.reactive_power_total))
                and isinstance(reactive_power_total, SensorTimeSeries)
            ):
                instance.reactive_power_total = reactive_power_total
        for node in nodes_by_id.values():
            if (
                isinstance(node, Nacelle)
                and node.power_inverter is not None
                and (power_inverter := instances.get(as_pygen_node_id(node.power_inverter)))
            ):
                if power_inverter.nacelle is None:
                    power_inverter.nacelle = node
                elif are_nodes_equal(node, power_inverter.nacelle):
                    # This is the same node, so we don't need to do anything...
                    ...
                else:
                    warnings.warn(
                        f"Expected one direct relation for 'nacelle' in {power_inverter.as_id()}."
                        f"Ignoring new relation {node!s} in favor of {power_inverter.nacelle!s}."
                    )

as_apply()

Convert this read version of power inverter to the writing version.

Source code in examples/wind_turbine/data_classes/_power_inverter.py
def as_apply(self) -> PowerInverterWrite:
    """Convert this read version of power inverter to the writing version."""
    warnings.warn(
        "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
        UserWarning,
        stacklevel=2,
    )
    return self.as_write()

as_write()

Convert this read version of power inverter to the writing version.

Source code in examples/wind_turbine/data_classes/_power_inverter.py
def as_write(self) -> PowerInverterWrite:
    """Convert this read version of power inverter to the writing version."""
    return PowerInverterWrite(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecordWrite(existing_version=self.data_record.version),
        active_power_total=(
            self.active_power_total.as_write()
            if isinstance(self.active_power_total, DomainModel)
            else self.active_power_total
        ),
        apparent_power_total=(
            self.apparent_power_total.as_write()
            if isinstance(self.apparent_power_total, DomainModel)
            else self.apparent_power_total
        ),
        reactive_power_total=(
            self.reactive_power_total.as_write()
            if isinstance(self.reactive_power_total, DomainModel)
            else self.reactive_power_total
        ),
    )

PowerInverterGraphQL

Bases: GraphQLCore

This represents the reading version of power inverter, used when data is retrieved from CDF using GraphQL.

It is used when retrieving data from CDF using GraphQL.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the power inverter.

required
data_record

The data record of the power inverter node.

required
active_power_total

The active power total field.

required
apparent_power_total

The apparent power total field.

required
nacelle

The nacelle field.

required
reactive_power_total

The reactive power total field.

required
Source code in examples/wind_turbine/data_classes/_power_inverter.py
class PowerInverterGraphQL(GraphQLCore):
    """This represents the reading version of power inverter, used
    when data is retrieved from CDF using GraphQL.

    It is used when retrieving data from CDF using GraphQL.

    Args:
        space: The space where the node is located.
        external_id: The external id of the power inverter.
        data_record: The data record of the power inverter node.
        active_power_total: The active power total field.
        apparent_power_total: The apparent power total field.
        nacelle: The nacelle field.
        reactive_power_total: The reactive power total field.
    """

    view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "PowerInverter", "1")
    active_power_total: Optional[SensorTimeSeriesGraphQL] = Field(default=None, repr=False)
    apparent_power_total: Optional[SensorTimeSeriesGraphQL] = Field(default=None, repr=False)
    nacelle: Optional[NacelleGraphQL] = Field(default=None, repr=False)
    reactive_power_total: Optional[SensorTimeSeriesGraphQL] = Field(default=None, repr=False)

    @model_validator(mode="before")
    def parse_data_record(cls, values: Any) -> Any:
        if not isinstance(values, dict):
            return values
        if "lastUpdatedTime" in values or "createdTime" in values:
            values["dataRecord"] = DataRecordGraphQL(
                created_time=values.pop("createdTime", None),
                last_updated_time=values.pop("lastUpdatedTime", None),
            )
        return values

    @field_validator("active_power_total", "apparent_power_total", "nacelle", "reactive_power_total", mode="before")
    def parse_graphql(cls, value: Any) -> Any:
        if not isinstance(value, dict):
            return value
        if "items" in value:
            return value["items"]
        return value

    # We do the ignore argument type as we let pydantic handle the type checking
    @no_type_check
    def as_read(self) -> PowerInverter:
        """Convert this GraphQL format of power inverter to the reading format."""
        if self.data_record is None:
            raise ValueError("This object cannot be converted to a read format because it lacks a data record.")
        return PowerInverter(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecord(
                version=0,
                last_updated_time=self.data_record.last_updated_time,
                created_time=self.data_record.created_time,
            ),
            active_power_total=(
                self.active_power_total.as_read()
                if isinstance(self.active_power_total, GraphQLCore)
                else self.active_power_total
            ),
            apparent_power_total=(
                self.apparent_power_total.as_read()
                if isinstance(self.apparent_power_total, GraphQLCore)
                else self.apparent_power_total
            ),
            nacelle=self.nacelle.as_read() if isinstance(self.nacelle, GraphQLCore) else self.nacelle,
            reactive_power_total=(
                self.reactive_power_total.as_read()
                if isinstance(self.reactive_power_total, GraphQLCore)
                else self.reactive_power_total
            ),
        )

    # We do the ignore argument type as we let pydantic handle the type checking
    @no_type_check
    def as_write(self) -> PowerInverterWrite:
        """Convert this GraphQL format of power inverter to the writing format."""
        return PowerInverterWrite(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecordWrite(existing_version=0),
            active_power_total=(
                self.active_power_total.as_write()
                if isinstance(self.active_power_total, GraphQLCore)
                else self.active_power_total
            ),
            apparent_power_total=(
                self.apparent_power_total.as_write()
                if isinstance(self.apparent_power_total, GraphQLCore)
                else self.apparent_power_total
            ),
            reactive_power_total=(
                self.reactive_power_total.as_write()
                if isinstance(self.reactive_power_total, GraphQLCore)
                else self.reactive_power_total
            ),
        )

as_read()

Convert this GraphQL format of power inverter to the reading format.

Source code in examples/wind_turbine/data_classes/_power_inverter.py
@no_type_check
def as_read(self) -> PowerInverter:
    """Convert this GraphQL format of power inverter to the reading format."""
    if self.data_record is None:
        raise ValueError("This object cannot be converted to a read format because it lacks a data record.")
    return PowerInverter(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecord(
            version=0,
            last_updated_time=self.data_record.last_updated_time,
            created_time=self.data_record.created_time,
        ),
        active_power_total=(
            self.active_power_total.as_read()
            if isinstance(self.active_power_total, GraphQLCore)
            else self.active_power_total
        ),
        apparent_power_total=(
            self.apparent_power_total.as_read()
            if isinstance(self.apparent_power_total, GraphQLCore)
            else self.apparent_power_total
        ),
        nacelle=self.nacelle.as_read() if isinstance(self.nacelle, GraphQLCore) else self.nacelle,
        reactive_power_total=(
            self.reactive_power_total.as_read()
            if isinstance(self.reactive_power_total, GraphQLCore)
            else self.reactive_power_total
        ),
    )

as_write()

Convert this GraphQL format of power inverter to the writing format.

Source code in examples/wind_turbine/data_classes/_power_inverter.py
@no_type_check
def as_write(self) -> PowerInverterWrite:
    """Convert this GraphQL format of power inverter to the writing format."""
    return PowerInverterWrite(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecordWrite(existing_version=0),
        active_power_total=(
            self.active_power_total.as_write()
            if isinstance(self.active_power_total, GraphQLCore)
            else self.active_power_total
        ),
        apparent_power_total=(
            self.apparent_power_total.as_write()
            if isinstance(self.apparent_power_total, GraphQLCore)
            else self.apparent_power_total
        ),
        reactive_power_total=(
            self.reactive_power_total.as_write()
            if isinstance(self.reactive_power_total, GraphQLCore)
            else self.reactive_power_total
        ),
    )

PowerInverterList

Bases: DomainModelList[PowerInverter]

List of power inverters in the read version.

Source code in examples/wind_turbine/data_classes/_power_inverter.py
class PowerInverterList(DomainModelList[PowerInverter]):
    """List of power inverters in the read version."""

    _INSTANCE = PowerInverter

    def as_write(self) -> PowerInverterWriteList:
        """Convert these read versions of power inverter to the writing versions."""
        return PowerInverterWriteList([node.as_write() for node in self.data])

    def as_apply(self) -> PowerInverterWriteList:
        """Convert these read versions of primitive nullable to the writing versions."""
        warnings.warn(
            "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
            UserWarning,
            stacklevel=2,
        )
        return self.as_write()

    @property
    def active_power_total(self) -> SensorTimeSeriesList:
        from ._sensor_time_series import SensorTimeSeries, SensorTimeSeriesList

        return SensorTimeSeriesList(
            [item.active_power_total for item in self.data if isinstance(item.active_power_total, SensorTimeSeries)]
        )

    @property
    def apparent_power_total(self) -> SensorTimeSeriesList:
        from ._sensor_time_series import SensorTimeSeries, SensorTimeSeriesList

        return SensorTimeSeriesList(
            [item.apparent_power_total for item in self.data if isinstance(item.apparent_power_total, SensorTimeSeries)]
        )

    @property
    def nacelle(self) -> NacelleList:
        from ._nacelle import Nacelle, NacelleList

        return NacelleList([item.nacelle for item in self.data if isinstance(item.nacelle, Nacelle)])

    @property
    def reactive_power_total(self) -> SensorTimeSeriesList:
        from ._sensor_time_series import SensorTimeSeries, SensorTimeSeriesList

        return SensorTimeSeriesList(
            [item.reactive_power_total for item in self.data if isinstance(item.reactive_power_total, SensorTimeSeries)]
        )

as_apply()

Convert these read versions of primitive nullable to the writing versions.

Source code in examples/wind_turbine/data_classes/_power_inverter.py
def as_apply(self) -> PowerInverterWriteList:
    """Convert these read versions of primitive nullable to the writing versions."""
    warnings.warn(
        "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
        UserWarning,
        stacklevel=2,
    )
    return self.as_write()

as_write()

Convert these read versions of power inverter to the writing versions.

Source code in examples/wind_turbine/data_classes/_power_inverter.py
def as_write(self) -> PowerInverterWriteList:
    """Convert these read versions of power inverter to the writing versions."""
    return PowerInverterWriteList([node.as_write() for node in self.data])

PowerInverterWrite

Bases: DomainModelWrite

This represents the writing version of power inverter.

It is used to when data is sent to CDF.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the power inverter.

required
data_record

The data record of the power inverter node.

required
active_power_total

The active power total field.

required
apparent_power_total

The apparent power total field.

required
reactive_power_total

The reactive power total field.

required
Source code in examples/wind_turbine/data_classes/_power_inverter.py
class PowerInverterWrite(DomainModelWrite):
    """This represents the writing version of power inverter.

    It is used to when data is sent to CDF.

    Args:
        space: The space where the node is located.
        external_id: The external id of the power inverter.
        data_record: The data record of the power inverter node.
        active_power_total: The active power total field.
        apparent_power_total: The apparent power total field.
        reactive_power_total: The reactive power total field.
    """

    _view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "PowerInverter", "1")

    space: str = DEFAULT_INSTANCE_SPACE
    node_type: Union[dm.DirectRelationReference, dm.NodeId, tuple[str, str], None] = None
    active_power_total: Union[SensorTimeSeriesWrite, str, dm.NodeId, None] = Field(default=None, repr=False)
    apparent_power_total: Union[SensorTimeSeriesWrite, str, dm.NodeId, None] = Field(default=None, repr=False)
    reactive_power_total: Union[SensorTimeSeriesWrite, str, dm.NodeId, None] = Field(default=None, repr=False)

    @field_validator("active_power_total", "apparent_power_total", "reactive_power_total", mode="before")
    def as_node_id(cls, value: Any) -> Any:
        if isinstance(value, dm.DirectRelationReference):
            return dm.NodeId(value.space, value.external_id)
        elif isinstance(value, tuple) and len(value) == 2 and all(isinstance(item, str) for item in value):
            return dm.NodeId(value[0], value[1])
        elif isinstance(value, list):
            return [cls.as_node_id(item) for item in value]
        return value

    def _to_instances_write(
        self,
        cache: set[tuple[str, str]],
        write_none: bool = False,
        allow_version_increase: bool = False,
    ) -> ResourcesWrite:
        resources = ResourcesWrite()
        if self.as_tuple_id() in cache:
            return resources

        properties: dict[str, Any] = {}

        if self.active_power_total is not None:
            properties["active_power_total"] = {
                "space": self.space if isinstance(self.active_power_total, str) else self.active_power_total.space,
                "externalId": (
                    self.active_power_total
                    if isinstance(self.active_power_total, str)
                    else self.active_power_total.external_id
                ),
            }

        if self.apparent_power_total is not None:
            properties["apparent_power_total"] = {
                "space": self.space if isinstance(self.apparent_power_total, str) else self.apparent_power_total.space,
                "externalId": (
                    self.apparent_power_total
                    if isinstance(self.apparent_power_total, str)
                    else self.apparent_power_total.external_id
                ),
            }

        if self.reactive_power_total is not None:
            properties["reactive_power_total"] = {
                "space": self.space if isinstance(self.reactive_power_total, str) else self.reactive_power_total.space,
                "externalId": (
                    self.reactive_power_total
                    if isinstance(self.reactive_power_total, str)
                    else self.reactive_power_total.external_id
                ),
            }

        if properties:
            this_node = dm.NodeApply(
                space=self.space,
                external_id=self.external_id,
                existing_version=None if allow_version_increase else self.data_record.existing_version,
                type=as_direct_relation_reference(self.node_type),
                sources=[
                    dm.NodeOrEdgeData(
                        source=self._view_id,
                        properties=properties,
                    )
                ],
            )
            resources.nodes.append(this_node)
            cache.add(self.as_tuple_id())

        if isinstance(self.active_power_total, DomainModelWrite):
            other_resources = self.active_power_total._to_instances_write(cache)
            resources.extend(other_resources)

        if isinstance(self.apparent_power_total, DomainModelWrite):
            other_resources = self.apparent_power_total._to_instances_write(cache)
            resources.extend(other_resources)

        if isinstance(self.reactive_power_total, DomainModelWrite):
            other_resources = self.reactive_power_total._to_instances_write(cache)
            resources.extend(other_resources)

        return resources

PowerInverterWriteList

Bases: DomainModelWriteList[PowerInverterWrite]

List of power inverters in the writing version.

Source code in examples/wind_turbine/data_classes/_power_inverter.py
class PowerInverterWriteList(DomainModelWriteList[PowerInverterWrite]):
    """List of power inverters in the writing version."""

    _INSTANCE = PowerInverterWrite

    @property
    def active_power_total(self) -> SensorTimeSeriesWriteList:
        from ._sensor_time_series import SensorTimeSeriesWrite, SensorTimeSeriesWriteList

        return SensorTimeSeriesWriteList(
            [
                item.active_power_total
                for item in self.data
                if isinstance(item.active_power_total, SensorTimeSeriesWrite)
            ]
        )

    @property
    def apparent_power_total(self) -> SensorTimeSeriesWriteList:
        from ._sensor_time_series import SensorTimeSeriesWrite, SensorTimeSeriesWriteList

        return SensorTimeSeriesWriteList(
            [
                item.apparent_power_total
                for item in self.data
                if isinstance(item.apparent_power_total, SensorTimeSeriesWrite)
            ]
        )

    @property
    def reactive_power_total(self) -> SensorTimeSeriesWriteList:
        from ._sensor_time_series import SensorTimeSeriesWrite, SensorTimeSeriesWriteList

        return SensorTimeSeriesWriteList(
            [
                item.reactive_power_total
                for item in self.data
                if isinstance(item.reactive_power_total, SensorTimeSeriesWrite)
            ]
        )

Rotor

Bases: DomainModel

This represents the reading version of rotor.

It is used to when data is retrieved from CDF.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the rotor.

required
data_record

The data record of the rotor node.

required
rotor_speed_controller

The rotor speed controller field.

required
rpm_low_speed_shaft

The rpm low speed shaft field.

required
wind_turbine

The wind turbine field.

required
Source code in examples/wind_turbine/data_classes/_rotor.py
class Rotor(DomainModel):
    """This represents the reading version of rotor.

    It is used to when data is retrieved from CDF.

    Args:
        space: The space where the node is located.
        external_id: The external id of the rotor.
        data_record: The data record of the rotor node.
        rotor_speed_controller: The rotor speed controller field.
        rpm_low_speed_shaft: The rpm low speed shaft field.
        wind_turbine: The wind turbine field.
    """

    _view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "Rotor", "1")

    space: str = DEFAULT_INSTANCE_SPACE
    node_type: Union[dm.DirectRelationReference, None] = None
    rotor_speed_controller: Union[SensorTimeSeries, str, dm.NodeId, None] = Field(default=None, repr=False)
    rpm_low_speed_shaft: Union[SensorTimeSeries, str, dm.NodeId, None] = Field(default=None, repr=False)
    wind_turbine: Optional[WindTurbine] = Field(default=None, repr=False)

    def as_write(self) -> RotorWrite:
        """Convert this read version of rotor to the writing version."""
        return RotorWrite(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecordWrite(existing_version=self.data_record.version),
            rotor_speed_controller=(
                self.rotor_speed_controller.as_write()
                if isinstance(self.rotor_speed_controller, DomainModel)
                else self.rotor_speed_controller
            ),
            rpm_low_speed_shaft=(
                self.rpm_low_speed_shaft.as_write()
                if isinstance(self.rpm_low_speed_shaft, DomainModel)
                else self.rpm_low_speed_shaft
            ),
        )

    def as_apply(self) -> RotorWrite:
        """Convert this read version of rotor to the writing version."""
        warnings.warn(
            "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
            UserWarning,
            stacklevel=2,
        )
        return self.as_write()

    @classmethod
    def _update_connections(
        cls,
        instances: dict[dm.NodeId | str, Rotor],  # type: ignore[override]
        nodes_by_id: dict[dm.NodeId | str, DomainModel],
        edges_by_source_node: dict[dm.NodeId, list[dm.Edge | DomainRelation]],
    ) -> None:
        from ._sensor_time_series import SensorTimeSeries
        from ._wind_turbine import WindTurbine

        for instance in instances.values():
            if (
                isinstance(instance.rotor_speed_controller, (dm.NodeId, str))
                and (rotor_speed_controller := nodes_by_id.get(instance.rotor_speed_controller))
                and isinstance(rotor_speed_controller, SensorTimeSeries)
            ):
                instance.rotor_speed_controller = rotor_speed_controller
            if (
                isinstance(instance.rpm_low_speed_shaft, (dm.NodeId, str))
                and (rpm_low_speed_shaft := nodes_by_id.get(instance.rpm_low_speed_shaft))
                and isinstance(rpm_low_speed_shaft, SensorTimeSeries)
            ):
                instance.rpm_low_speed_shaft = rpm_low_speed_shaft
        for node in nodes_by_id.values():
            if (
                isinstance(node, WindTurbine)
                and node.rotor is not None
                and (rotor := instances.get(as_pygen_node_id(node.rotor)))
            ):
                if rotor.wind_turbine is None:
                    rotor.wind_turbine = node
                elif are_nodes_equal(node, rotor.wind_turbine):
                    # This is the same node, so we don't need to do anything...
                    ...
                else:
                    warnings.warn(
                        f"Expected one direct relation for 'wind_turbine' in {rotor.as_id()}."
                        f"Ignoring new relation {node!s} in favor of {rotor.wind_turbine!s}."
                    )

as_apply()

Convert this read version of rotor to the writing version.

Source code in examples/wind_turbine/data_classes/_rotor.py
def as_apply(self) -> RotorWrite:
    """Convert this read version of rotor to the writing version."""
    warnings.warn(
        "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
        UserWarning,
        stacklevel=2,
    )
    return self.as_write()

as_write()

Convert this read version of rotor to the writing version.

Source code in examples/wind_turbine/data_classes/_rotor.py
def as_write(self) -> RotorWrite:
    """Convert this read version of rotor to the writing version."""
    return RotorWrite(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecordWrite(existing_version=self.data_record.version),
        rotor_speed_controller=(
            self.rotor_speed_controller.as_write()
            if isinstance(self.rotor_speed_controller, DomainModel)
            else self.rotor_speed_controller
        ),
        rpm_low_speed_shaft=(
            self.rpm_low_speed_shaft.as_write()
            if isinstance(self.rpm_low_speed_shaft, DomainModel)
            else self.rpm_low_speed_shaft
        ),
    )

RotorGraphQL

Bases: GraphQLCore

This represents the reading version of rotor, used when data is retrieved from CDF using GraphQL.

It is used when retrieving data from CDF using GraphQL.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the rotor.

required
data_record

The data record of the rotor node.

required
rotor_speed_controller

The rotor speed controller field.

required
rpm_low_speed_shaft

The rpm low speed shaft field.

required
wind_turbine

The wind turbine field.

required
Source code in examples/wind_turbine/data_classes/_rotor.py
class RotorGraphQL(GraphQLCore):
    """This represents the reading version of rotor, used
    when data is retrieved from CDF using GraphQL.

    It is used when retrieving data from CDF using GraphQL.

    Args:
        space: The space where the node is located.
        external_id: The external id of the rotor.
        data_record: The data record of the rotor node.
        rotor_speed_controller: The rotor speed controller field.
        rpm_low_speed_shaft: The rpm low speed shaft field.
        wind_turbine: The wind turbine field.
    """

    view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "Rotor", "1")
    rotor_speed_controller: Optional[SensorTimeSeriesGraphQL] = Field(default=None, repr=False)
    rpm_low_speed_shaft: Optional[SensorTimeSeriesGraphQL] = Field(default=None, repr=False)
    wind_turbine: Optional[WindTurbineGraphQL] = Field(default=None, repr=False)

    @model_validator(mode="before")
    def parse_data_record(cls, values: Any) -> Any:
        if not isinstance(values, dict):
            return values
        if "lastUpdatedTime" in values or "createdTime" in values:
            values["dataRecord"] = DataRecordGraphQL(
                created_time=values.pop("createdTime", None),
                last_updated_time=values.pop("lastUpdatedTime", None),
            )
        return values

    @field_validator("rotor_speed_controller", "rpm_low_speed_shaft", "wind_turbine", mode="before")
    def parse_graphql(cls, value: Any) -> Any:
        if not isinstance(value, dict):
            return value
        if "items" in value:
            return value["items"]
        return value

    # We do the ignore argument type as we let pydantic handle the type checking
    @no_type_check
    def as_read(self) -> Rotor:
        """Convert this GraphQL format of rotor to the reading format."""
        if self.data_record is None:
            raise ValueError("This object cannot be converted to a read format because it lacks a data record.")
        return Rotor(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecord(
                version=0,
                last_updated_time=self.data_record.last_updated_time,
                created_time=self.data_record.created_time,
            ),
            rotor_speed_controller=(
                self.rotor_speed_controller.as_read()
                if isinstance(self.rotor_speed_controller, GraphQLCore)
                else self.rotor_speed_controller
            ),
            rpm_low_speed_shaft=(
                self.rpm_low_speed_shaft.as_read()
                if isinstance(self.rpm_low_speed_shaft, GraphQLCore)
                else self.rpm_low_speed_shaft
            ),
            wind_turbine=(
                self.wind_turbine.as_read() if isinstance(self.wind_turbine, GraphQLCore) else self.wind_turbine
            ),
        )

    # We do the ignore argument type as we let pydantic handle the type checking
    @no_type_check
    def as_write(self) -> RotorWrite:
        """Convert this GraphQL format of rotor to the writing format."""
        return RotorWrite(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecordWrite(existing_version=0),
            rotor_speed_controller=(
                self.rotor_speed_controller.as_write()
                if isinstance(self.rotor_speed_controller, GraphQLCore)
                else self.rotor_speed_controller
            ),
            rpm_low_speed_shaft=(
                self.rpm_low_speed_shaft.as_write()
                if isinstance(self.rpm_low_speed_shaft, GraphQLCore)
                else self.rpm_low_speed_shaft
            ),
        )

as_read()

Convert this GraphQL format of rotor to the reading format.

Source code in examples/wind_turbine/data_classes/_rotor.py
@no_type_check
def as_read(self) -> Rotor:
    """Convert this GraphQL format of rotor to the reading format."""
    if self.data_record is None:
        raise ValueError("This object cannot be converted to a read format because it lacks a data record.")
    return Rotor(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecord(
            version=0,
            last_updated_time=self.data_record.last_updated_time,
            created_time=self.data_record.created_time,
        ),
        rotor_speed_controller=(
            self.rotor_speed_controller.as_read()
            if isinstance(self.rotor_speed_controller, GraphQLCore)
            else self.rotor_speed_controller
        ),
        rpm_low_speed_shaft=(
            self.rpm_low_speed_shaft.as_read()
            if isinstance(self.rpm_low_speed_shaft, GraphQLCore)
            else self.rpm_low_speed_shaft
        ),
        wind_turbine=(
            self.wind_turbine.as_read() if isinstance(self.wind_turbine, GraphQLCore) else self.wind_turbine
        ),
    )

as_write()

Convert this GraphQL format of rotor to the writing format.

Source code in examples/wind_turbine/data_classes/_rotor.py
@no_type_check
def as_write(self) -> RotorWrite:
    """Convert this GraphQL format of rotor to the writing format."""
    return RotorWrite(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecordWrite(existing_version=0),
        rotor_speed_controller=(
            self.rotor_speed_controller.as_write()
            if isinstance(self.rotor_speed_controller, GraphQLCore)
            else self.rotor_speed_controller
        ),
        rpm_low_speed_shaft=(
            self.rpm_low_speed_shaft.as_write()
            if isinstance(self.rpm_low_speed_shaft, GraphQLCore)
            else self.rpm_low_speed_shaft
        ),
    )

RotorList

Bases: DomainModelList[Rotor]

List of rotors in the read version.

Source code in examples/wind_turbine/data_classes/_rotor.py
class RotorList(DomainModelList[Rotor]):
    """List of rotors in the read version."""

    _INSTANCE = Rotor

    def as_write(self) -> RotorWriteList:
        """Convert these read versions of rotor to the writing versions."""
        return RotorWriteList([node.as_write() for node in self.data])

    def as_apply(self) -> RotorWriteList:
        """Convert these read versions of primitive nullable to the writing versions."""
        warnings.warn(
            "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
            UserWarning,
            stacklevel=2,
        )
        return self.as_write()

    @property
    def rotor_speed_controller(self) -> SensorTimeSeriesList:
        from ._sensor_time_series import SensorTimeSeries, SensorTimeSeriesList

        return SensorTimeSeriesList(
            [
                item.rotor_speed_controller
                for item in self.data
                if isinstance(item.rotor_speed_controller, SensorTimeSeries)
            ]
        )

    @property
    def rpm_low_speed_shaft(self) -> SensorTimeSeriesList:
        from ._sensor_time_series import SensorTimeSeries, SensorTimeSeriesList

        return SensorTimeSeriesList(
            [item.rpm_low_speed_shaft for item in self.data if isinstance(item.rpm_low_speed_shaft, SensorTimeSeries)]
        )

    @property
    def wind_turbine(self) -> WindTurbineList:
        from ._wind_turbine import WindTurbine, WindTurbineList

        return WindTurbineList([item.wind_turbine for item in self.data if isinstance(item.wind_turbine, WindTurbine)])

as_apply()

Convert these read versions of primitive nullable to the writing versions.

Source code in examples/wind_turbine/data_classes/_rotor.py
def as_apply(self) -> RotorWriteList:
    """Convert these read versions of primitive nullable to the writing versions."""
    warnings.warn(
        "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
        UserWarning,
        stacklevel=2,
    )
    return self.as_write()

as_write()

Convert these read versions of rotor to the writing versions.

Source code in examples/wind_turbine/data_classes/_rotor.py
def as_write(self) -> RotorWriteList:
    """Convert these read versions of rotor to the writing versions."""
    return RotorWriteList([node.as_write() for node in self.data])

RotorWrite

Bases: DomainModelWrite

This represents the writing version of rotor.

It is used to when data is sent to CDF.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the rotor.

required
data_record

The data record of the rotor node.

required
rotor_speed_controller

The rotor speed controller field.

required
rpm_low_speed_shaft

The rpm low speed shaft field.

required
Source code in examples/wind_turbine/data_classes/_rotor.py
class RotorWrite(DomainModelWrite):
    """This represents the writing version of rotor.

    It is used to when data is sent to CDF.

    Args:
        space: The space where the node is located.
        external_id: The external id of the rotor.
        data_record: The data record of the rotor node.
        rotor_speed_controller: The rotor speed controller field.
        rpm_low_speed_shaft: The rpm low speed shaft field.
    """

    _view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "Rotor", "1")

    space: str = DEFAULT_INSTANCE_SPACE
    node_type: Union[dm.DirectRelationReference, dm.NodeId, tuple[str, str], None] = None
    rotor_speed_controller: Union[SensorTimeSeriesWrite, str, dm.NodeId, None] = Field(default=None, repr=False)
    rpm_low_speed_shaft: Union[SensorTimeSeriesWrite, str, dm.NodeId, None] = Field(default=None, repr=False)

    @field_validator("rotor_speed_controller", "rpm_low_speed_shaft", mode="before")
    def as_node_id(cls, value: Any) -> Any:
        if isinstance(value, dm.DirectRelationReference):
            return dm.NodeId(value.space, value.external_id)
        elif isinstance(value, tuple) and len(value) == 2 and all(isinstance(item, str) for item in value):
            return dm.NodeId(value[0], value[1])
        elif isinstance(value, list):
            return [cls.as_node_id(item) for item in value]
        return value

    def _to_instances_write(
        self,
        cache: set[tuple[str, str]],
        write_none: bool = False,
        allow_version_increase: bool = False,
    ) -> ResourcesWrite:
        resources = ResourcesWrite()
        if self.as_tuple_id() in cache:
            return resources

        properties: dict[str, Any] = {}

        if self.rotor_speed_controller is not None:
            properties["rotor_speed_controller"] = {
                "space": (
                    self.space if isinstance(self.rotor_speed_controller, str) else self.rotor_speed_controller.space
                ),
                "externalId": (
                    self.rotor_speed_controller
                    if isinstance(self.rotor_speed_controller, str)
                    else self.rotor_speed_controller.external_id
                ),
            }

        if self.rpm_low_speed_shaft is not None:
            properties["rpm_low_speed_shaft"] = {
                "space": self.space if isinstance(self.rpm_low_speed_shaft, str) else self.rpm_low_speed_shaft.space,
                "externalId": (
                    self.rpm_low_speed_shaft
                    if isinstance(self.rpm_low_speed_shaft, str)
                    else self.rpm_low_speed_shaft.external_id
                ),
            }

        if properties:
            this_node = dm.NodeApply(
                space=self.space,
                external_id=self.external_id,
                existing_version=None if allow_version_increase else self.data_record.existing_version,
                type=as_direct_relation_reference(self.node_type),
                sources=[
                    dm.NodeOrEdgeData(
                        source=self._view_id,
                        properties=properties,
                    )
                ],
            )
            resources.nodes.append(this_node)
            cache.add(self.as_tuple_id())

        if isinstance(self.rotor_speed_controller, DomainModelWrite):
            other_resources = self.rotor_speed_controller._to_instances_write(cache)
            resources.extend(other_resources)

        if isinstance(self.rpm_low_speed_shaft, DomainModelWrite):
            other_resources = self.rpm_low_speed_shaft._to_instances_write(cache)
            resources.extend(other_resources)

        return resources

RotorWriteList

Bases: DomainModelWriteList[RotorWrite]

List of rotors in the writing version.

Source code in examples/wind_turbine/data_classes/_rotor.py
class RotorWriteList(DomainModelWriteList[RotorWrite]):
    """List of rotors in the writing version."""

    _INSTANCE = RotorWrite

    @property
    def rotor_speed_controller(self) -> SensorTimeSeriesWriteList:
        from ._sensor_time_series import SensorTimeSeriesWrite, SensorTimeSeriesWriteList

        return SensorTimeSeriesWriteList(
            [
                item.rotor_speed_controller
                for item in self.data
                if isinstance(item.rotor_speed_controller, SensorTimeSeriesWrite)
            ]
        )

    @property
    def rpm_low_speed_shaft(self) -> SensorTimeSeriesWriteList:
        from ._sensor_time_series import SensorTimeSeriesWrite, SensorTimeSeriesWriteList

        return SensorTimeSeriesWriteList(
            [
                item.rpm_low_speed_shaft
                for item in self.data
                if isinstance(item.rpm_low_speed_shaft, SensorTimeSeriesWrite)
            ]
        )

SensorPosition

Bases: DomainModel

This represents the reading version of sensor position.

It is used to when data is retrieved from CDF.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the sensor position.

required
data_record

The data record of the sensor position node.

required
blade

The blade field.

required
edgewise_bend_mom_crosstalk_corrected

The edgewise bend mom crosstalk corrected field.

required
edgewise_bend_mom_offset

The edgewise bend mom offset field.

required
edgewise_bend_mom_offset_crosstalk_corrected

The edgewise bend mom offset crosstalk corrected field.

required
edgewisewise_bend_mom

The edgewisewise bend mom field.

required
flapwise_bend_mom

The flapwise bend mom field.

required
flapwise_bend_mom_crosstalk_corrected

The flapwise bend mom crosstalk corrected field.

required
flapwise_bend_mom_offset

The flapwise bend mom offset field.

required
flapwise_bend_mom_offset_crosstalk_corrected

The flapwise bend mom offset crosstalk corrected field.

required
position

The position field.

required
Source code in examples/wind_turbine/data_classes/_sensor_position.py
class SensorPosition(DomainModel):
    """This represents the reading version of sensor position.

    It is used to when data is retrieved from CDF.

    Args:
        space: The space where the node is located.
        external_id: The external id of the sensor position.
        data_record: The data record of the sensor position node.
        blade: The blade field.
        edgewise_bend_mom_crosstalk_corrected: The edgewise bend mom crosstalk corrected field.
        edgewise_bend_mom_offset: The edgewise bend mom offset field.
        edgewise_bend_mom_offset_crosstalk_corrected: The edgewise bend mom offset crosstalk corrected field.
        edgewisewise_bend_mom: The edgewisewise bend mom field.
        flapwise_bend_mom: The flapwise bend mom field.
        flapwise_bend_mom_crosstalk_corrected: The flapwise bend mom crosstalk corrected field.
        flapwise_bend_mom_offset: The flapwise bend mom offset field.
        flapwise_bend_mom_offset_crosstalk_corrected: The flapwise bend mom offset crosstalk corrected field.
        position: The position field.
    """

    _view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "SensorPosition", "1")

    space: str = DEFAULT_INSTANCE_SPACE
    node_type: Union[dm.DirectRelationReference, None] = None
    blade: Union[Blade, str, dm.NodeId, None] = Field(default=None, repr=False)
    edgewise_bend_mom_crosstalk_corrected: Union[SensorTimeSeries, str, dm.NodeId, None] = Field(
        default=None, repr=False
    )
    edgewise_bend_mom_offset: Union[SensorTimeSeries, str, dm.NodeId, None] = Field(default=None, repr=False)
    edgewise_bend_mom_offset_crosstalk_corrected: Union[SensorTimeSeries, str, dm.NodeId, None] = Field(
        default=None, repr=False
    )
    edgewisewise_bend_mom: Union[SensorTimeSeries, str, dm.NodeId, None] = Field(default=None, repr=False)
    flapwise_bend_mom: Union[SensorTimeSeries, str, dm.NodeId, None] = Field(default=None, repr=False)
    flapwise_bend_mom_crosstalk_corrected: Union[SensorTimeSeries, str, dm.NodeId, None] = Field(
        default=None, repr=False
    )
    flapwise_bend_mom_offset: Union[SensorTimeSeries, str, dm.NodeId, None] = Field(default=None, repr=False)
    flapwise_bend_mom_offset_crosstalk_corrected: Union[SensorTimeSeries, str, dm.NodeId, None] = Field(
        default=None, repr=False
    )
    position: Optional[float] = None

    def as_write(self) -> SensorPositionWrite:
        """Convert this read version of sensor position to the writing version."""
        return SensorPositionWrite(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecordWrite(existing_version=self.data_record.version),
            blade=self.blade.as_write() if isinstance(self.blade, DomainModel) else self.blade,
            edgewise_bend_mom_crosstalk_corrected=(
                self.edgewise_bend_mom_crosstalk_corrected.as_write()
                if isinstance(self.edgewise_bend_mom_crosstalk_corrected, DomainModel)
                else self.edgewise_bend_mom_crosstalk_corrected
            ),
            edgewise_bend_mom_offset=(
                self.edgewise_bend_mom_offset.as_write()
                if isinstance(self.edgewise_bend_mom_offset, DomainModel)
                else self.edgewise_bend_mom_offset
            ),
            edgewise_bend_mom_offset_crosstalk_corrected=(
                self.edgewise_bend_mom_offset_crosstalk_corrected.as_write()
                if isinstance(self.edgewise_bend_mom_offset_crosstalk_corrected, DomainModel)
                else self.edgewise_bend_mom_offset_crosstalk_corrected
            ),
            edgewisewise_bend_mom=(
                self.edgewisewise_bend_mom.as_write()
                if isinstance(self.edgewisewise_bend_mom, DomainModel)
                else self.edgewisewise_bend_mom
            ),
            flapwise_bend_mom=(
                self.flapwise_bend_mom.as_write()
                if isinstance(self.flapwise_bend_mom, DomainModel)
                else self.flapwise_bend_mom
            ),
            flapwise_bend_mom_crosstalk_corrected=(
                self.flapwise_bend_mom_crosstalk_corrected.as_write()
                if isinstance(self.flapwise_bend_mom_crosstalk_corrected, DomainModel)
                else self.flapwise_bend_mom_crosstalk_corrected
            ),
            flapwise_bend_mom_offset=(
                self.flapwise_bend_mom_offset.as_write()
                if isinstance(self.flapwise_bend_mom_offset, DomainModel)
                else self.flapwise_bend_mom_offset
            ),
            flapwise_bend_mom_offset_crosstalk_corrected=(
                self.flapwise_bend_mom_offset_crosstalk_corrected.as_write()
                if isinstance(self.flapwise_bend_mom_offset_crosstalk_corrected, DomainModel)
                else self.flapwise_bend_mom_offset_crosstalk_corrected
            ),
            position=self.position,
        )

    def as_apply(self) -> SensorPositionWrite:
        """Convert this read version of sensor position to the writing version."""
        warnings.warn(
            "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
            UserWarning,
            stacklevel=2,
        )
        return self.as_write()

    @classmethod
    def _update_connections(
        cls,
        instances: dict[dm.NodeId | str, SensorPosition],  # type: ignore[override]
        nodes_by_id: dict[dm.NodeId | str, DomainModel],
        edges_by_source_node: dict[dm.NodeId, list[dm.Edge | DomainRelation]],
    ) -> None:
        from ._blade import Blade
        from ._sensor_time_series import SensorTimeSeries

        for instance in instances.values():
            if (
                isinstance(instance.blade, (dm.NodeId, str))
                and (blade := nodes_by_id.get(instance.blade))
                and isinstance(blade, Blade)
            ):
                instance.blade = blade
            if (
                isinstance(instance.edgewise_bend_mom_crosstalk_corrected, (dm.NodeId, str))
                and (
                    edgewise_bend_mom_crosstalk_corrected := nodes_by_id.get(
                        instance.edgewise_bend_mom_crosstalk_corrected
                    )
                )
                and isinstance(edgewise_bend_mom_crosstalk_corrected, SensorTimeSeries)
            ):
                instance.edgewise_bend_mom_crosstalk_corrected = edgewise_bend_mom_crosstalk_corrected
            if (
                isinstance(instance.edgewise_bend_mom_offset, (dm.NodeId, str))
                and (edgewise_bend_mom_offset := nodes_by_id.get(instance.edgewise_bend_mom_offset))
                and isinstance(edgewise_bend_mom_offset, SensorTimeSeries)
            ):
                instance.edgewise_bend_mom_offset = edgewise_bend_mom_offset
            if (
                isinstance(instance.edgewise_bend_mom_offset_crosstalk_corrected, (dm.NodeId, str))
                and (
                    edgewise_bend_mom_offset_crosstalk_corrected := nodes_by_id.get(
                        instance.edgewise_bend_mom_offset_crosstalk_corrected
                    )
                )
                and isinstance(edgewise_bend_mom_offset_crosstalk_corrected, SensorTimeSeries)
            ):
                instance.edgewise_bend_mom_offset_crosstalk_corrected = edgewise_bend_mom_offset_crosstalk_corrected
            if (
                isinstance(instance.edgewisewise_bend_mom, (dm.NodeId, str))
                and (edgewisewise_bend_mom := nodes_by_id.get(instance.edgewisewise_bend_mom))
                and isinstance(edgewisewise_bend_mom, SensorTimeSeries)
            ):
                instance.edgewisewise_bend_mom = edgewisewise_bend_mom
            if (
                isinstance(instance.flapwise_bend_mom, (dm.NodeId, str))
                and (flapwise_bend_mom := nodes_by_id.get(instance.flapwise_bend_mom))
                and isinstance(flapwise_bend_mom, SensorTimeSeries)
            ):
                instance.flapwise_bend_mom = flapwise_bend_mom
            if (
                isinstance(instance.flapwise_bend_mom_crosstalk_corrected, (dm.NodeId, str))
                and (
                    flapwise_bend_mom_crosstalk_corrected := nodes_by_id.get(
                        instance.flapwise_bend_mom_crosstalk_corrected
                    )
                )
                and isinstance(flapwise_bend_mom_crosstalk_corrected, SensorTimeSeries)
            ):
                instance.flapwise_bend_mom_crosstalk_corrected = flapwise_bend_mom_crosstalk_corrected
            if (
                isinstance(instance.flapwise_bend_mom_offset, (dm.NodeId, str))
                and (flapwise_bend_mom_offset := nodes_by_id.get(instance.flapwise_bend_mom_offset))
                and isinstance(flapwise_bend_mom_offset, SensorTimeSeries)
            ):
                instance.flapwise_bend_mom_offset = flapwise_bend_mom_offset
            if (
                isinstance(instance.flapwise_bend_mom_offset_crosstalk_corrected, (dm.NodeId, str))
                and (
                    flapwise_bend_mom_offset_crosstalk_corrected := nodes_by_id.get(
                        instance.flapwise_bend_mom_offset_crosstalk_corrected
                    )
                )
                and isinstance(flapwise_bend_mom_offset_crosstalk_corrected, SensorTimeSeries)
            ):
                instance.flapwise_bend_mom_offset_crosstalk_corrected = flapwise_bend_mom_offset_crosstalk_corrected

as_apply()

Convert this read version of sensor position to the writing version.

Source code in examples/wind_turbine/data_classes/_sensor_position.py
def as_apply(self) -> SensorPositionWrite:
    """Convert this read version of sensor position to the writing version."""
    warnings.warn(
        "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
        UserWarning,
        stacklevel=2,
    )
    return self.as_write()

as_write()

Convert this read version of sensor position to the writing version.

Source code in examples/wind_turbine/data_classes/_sensor_position.py
def as_write(self) -> SensorPositionWrite:
    """Convert this read version of sensor position to the writing version."""
    return SensorPositionWrite(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecordWrite(existing_version=self.data_record.version),
        blade=self.blade.as_write() if isinstance(self.blade, DomainModel) else self.blade,
        edgewise_bend_mom_crosstalk_corrected=(
            self.edgewise_bend_mom_crosstalk_corrected.as_write()
            if isinstance(self.edgewise_bend_mom_crosstalk_corrected, DomainModel)
            else self.edgewise_bend_mom_crosstalk_corrected
        ),
        edgewise_bend_mom_offset=(
            self.edgewise_bend_mom_offset.as_write()
            if isinstance(self.edgewise_bend_mom_offset, DomainModel)
            else self.edgewise_bend_mom_offset
        ),
        edgewise_bend_mom_offset_crosstalk_corrected=(
            self.edgewise_bend_mom_offset_crosstalk_corrected.as_write()
            if isinstance(self.edgewise_bend_mom_offset_crosstalk_corrected, DomainModel)
            else self.edgewise_bend_mom_offset_crosstalk_corrected
        ),
        edgewisewise_bend_mom=(
            self.edgewisewise_bend_mom.as_write()
            if isinstance(self.edgewisewise_bend_mom, DomainModel)
            else self.edgewisewise_bend_mom
        ),
        flapwise_bend_mom=(
            self.flapwise_bend_mom.as_write()
            if isinstance(self.flapwise_bend_mom, DomainModel)
            else self.flapwise_bend_mom
        ),
        flapwise_bend_mom_crosstalk_corrected=(
            self.flapwise_bend_mom_crosstalk_corrected.as_write()
            if isinstance(self.flapwise_bend_mom_crosstalk_corrected, DomainModel)
            else self.flapwise_bend_mom_crosstalk_corrected
        ),
        flapwise_bend_mom_offset=(
            self.flapwise_bend_mom_offset.as_write()
            if isinstance(self.flapwise_bend_mom_offset, DomainModel)
            else self.flapwise_bend_mom_offset
        ),
        flapwise_bend_mom_offset_crosstalk_corrected=(
            self.flapwise_bend_mom_offset_crosstalk_corrected.as_write()
            if isinstance(self.flapwise_bend_mom_offset_crosstalk_corrected, DomainModel)
            else self.flapwise_bend_mom_offset_crosstalk_corrected
        ),
        position=self.position,
    )

SensorPositionGraphQL

Bases: GraphQLCore

This represents the reading version of sensor position, used when data is retrieved from CDF using GraphQL.

It is used when retrieving data from CDF using GraphQL.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the sensor position.

required
data_record

The data record of the sensor position node.

required
blade

The blade field.

required
edgewise_bend_mom_crosstalk_corrected

The edgewise bend mom crosstalk corrected field.

required
edgewise_bend_mom_offset

The edgewise bend mom offset field.

required
edgewise_bend_mom_offset_crosstalk_corrected

The edgewise bend mom offset crosstalk corrected field.

required
edgewisewise_bend_mom

The edgewisewise bend mom field.

required
flapwise_bend_mom

The flapwise bend mom field.

required
flapwise_bend_mom_crosstalk_corrected

The flapwise bend mom crosstalk corrected field.

required
flapwise_bend_mom_offset

The flapwise bend mom offset field.

required
flapwise_bend_mom_offset_crosstalk_corrected

The flapwise bend mom offset crosstalk corrected field.

required
position

The position field.

required
Source code in examples/wind_turbine/data_classes/_sensor_position.py
class SensorPositionGraphQL(GraphQLCore):
    """This represents the reading version of sensor position, used
    when data is retrieved from CDF using GraphQL.

    It is used when retrieving data from CDF using GraphQL.

    Args:
        space: The space where the node is located.
        external_id: The external id of the sensor position.
        data_record: The data record of the sensor position node.
        blade: The blade field.
        edgewise_bend_mom_crosstalk_corrected: The edgewise bend mom crosstalk corrected field.
        edgewise_bend_mom_offset: The edgewise bend mom offset field.
        edgewise_bend_mom_offset_crosstalk_corrected: The edgewise bend mom offset crosstalk corrected field.
        edgewisewise_bend_mom: The edgewisewise bend mom field.
        flapwise_bend_mom: The flapwise bend mom field.
        flapwise_bend_mom_crosstalk_corrected: The flapwise bend mom crosstalk corrected field.
        flapwise_bend_mom_offset: The flapwise bend mom offset field.
        flapwise_bend_mom_offset_crosstalk_corrected: The flapwise bend mom offset crosstalk corrected field.
        position: The position field.
    """

    view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "SensorPosition", "1")
    blade: Optional[BladeGraphQL] = Field(default=None, repr=False)
    edgewise_bend_mom_crosstalk_corrected: Optional[SensorTimeSeriesGraphQL] = Field(default=None, repr=False)
    edgewise_bend_mom_offset: Optional[SensorTimeSeriesGraphQL] = Field(default=None, repr=False)
    edgewise_bend_mom_offset_crosstalk_corrected: Optional[SensorTimeSeriesGraphQL] = Field(default=None, repr=False)
    edgewisewise_bend_mom: Optional[SensorTimeSeriesGraphQL] = Field(default=None, repr=False)
    flapwise_bend_mom: Optional[SensorTimeSeriesGraphQL] = Field(default=None, repr=False)
    flapwise_bend_mom_crosstalk_corrected: Optional[SensorTimeSeriesGraphQL] = Field(default=None, repr=False)
    flapwise_bend_mom_offset: Optional[SensorTimeSeriesGraphQL] = Field(default=None, repr=False)
    flapwise_bend_mom_offset_crosstalk_corrected: Optional[SensorTimeSeriesGraphQL] = Field(default=None, repr=False)
    position: Optional[float] = None

    @model_validator(mode="before")
    def parse_data_record(cls, values: Any) -> Any:
        if not isinstance(values, dict):
            return values
        if "lastUpdatedTime" in values or "createdTime" in values:
            values["dataRecord"] = DataRecordGraphQL(
                created_time=values.pop("createdTime", None),
                last_updated_time=values.pop("lastUpdatedTime", None),
            )
        return values

    @field_validator(
        "blade",
        "edgewise_bend_mom_crosstalk_corrected",
        "edgewise_bend_mom_offset",
        "edgewise_bend_mom_offset_crosstalk_corrected",
        "edgewisewise_bend_mom",
        "flapwise_bend_mom",
        "flapwise_bend_mom_crosstalk_corrected",
        "flapwise_bend_mom_offset",
        "flapwise_bend_mom_offset_crosstalk_corrected",
        mode="before",
    )
    def parse_graphql(cls, value: Any) -> Any:
        if not isinstance(value, dict):
            return value
        if "items" in value:
            return value["items"]
        return value

    # We do the ignore argument type as we let pydantic handle the type checking
    @no_type_check
    def as_read(self) -> SensorPosition:
        """Convert this GraphQL format of sensor position to the reading format."""
        if self.data_record is None:
            raise ValueError("This object cannot be converted to a read format because it lacks a data record.")
        return SensorPosition(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecord(
                version=0,
                last_updated_time=self.data_record.last_updated_time,
                created_time=self.data_record.created_time,
            ),
            blade=self.blade.as_read() if isinstance(self.blade, GraphQLCore) else self.blade,
            edgewise_bend_mom_crosstalk_corrected=(
                self.edgewise_bend_mom_crosstalk_corrected.as_read()
                if isinstance(self.edgewise_bend_mom_crosstalk_corrected, GraphQLCore)
                else self.edgewise_bend_mom_crosstalk_corrected
            ),
            edgewise_bend_mom_offset=(
                self.edgewise_bend_mom_offset.as_read()
                if isinstance(self.edgewise_bend_mom_offset, GraphQLCore)
                else self.edgewise_bend_mom_offset
            ),
            edgewise_bend_mom_offset_crosstalk_corrected=(
                self.edgewise_bend_mom_offset_crosstalk_corrected.as_read()
                if isinstance(self.edgewise_bend_mom_offset_crosstalk_corrected, GraphQLCore)
                else self.edgewise_bend_mom_offset_crosstalk_corrected
            ),
            edgewisewise_bend_mom=(
                self.edgewisewise_bend_mom.as_read()
                if isinstance(self.edgewisewise_bend_mom, GraphQLCore)
                else self.edgewisewise_bend_mom
            ),
            flapwise_bend_mom=(
                self.flapwise_bend_mom.as_read()
                if isinstance(self.flapwise_bend_mom, GraphQLCore)
                else self.flapwise_bend_mom
            ),
            flapwise_bend_mom_crosstalk_corrected=(
                self.flapwise_bend_mom_crosstalk_corrected.as_read()
                if isinstance(self.flapwise_bend_mom_crosstalk_corrected, GraphQLCore)
                else self.flapwise_bend_mom_crosstalk_corrected
            ),
            flapwise_bend_mom_offset=(
                self.flapwise_bend_mom_offset.as_read()
                if isinstance(self.flapwise_bend_mom_offset, GraphQLCore)
                else self.flapwise_bend_mom_offset
            ),
            flapwise_bend_mom_offset_crosstalk_corrected=(
                self.flapwise_bend_mom_offset_crosstalk_corrected.as_read()
                if isinstance(self.flapwise_bend_mom_offset_crosstalk_corrected, GraphQLCore)
                else self.flapwise_bend_mom_offset_crosstalk_corrected
            ),
            position=self.position,
        )

    # We do the ignore argument type as we let pydantic handle the type checking
    @no_type_check
    def as_write(self) -> SensorPositionWrite:
        """Convert this GraphQL format of sensor position to the writing format."""
        return SensorPositionWrite(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecordWrite(existing_version=0),
            blade=self.blade.as_write() if isinstance(self.blade, GraphQLCore) else self.blade,
            edgewise_bend_mom_crosstalk_corrected=(
                self.edgewise_bend_mom_crosstalk_corrected.as_write()
                if isinstance(self.edgewise_bend_mom_crosstalk_corrected, GraphQLCore)
                else self.edgewise_bend_mom_crosstalk_corrected
            ),
            edgewise_bend_mom_offset=(
                self.edgewise_bend_mom_offset.as_write()
                if isinstance(self.edgewise_bend_mom_offset, GraphQLCore)
                else self.edgewise_bend_mom_offset
            ),
            edgewise_bend_mom_offset_crosstalk_corrected=(
                self.edgewise_bend_mom_offset_crosstalk_corrected.as_write()
                if isinstance(self.edgewise_bend_mom_offset_crosstalk_corrected, GraphQLCore)
                else self.edgewise_bend_mom_offset_crosstalk_corrected
            ),
            edgewisewise_bend_mom=(
                self.edgewisewise_bend_mom.as_write()
                if isinstance(self.edgewisewise_bend_mom, GraphQLCore)
                else self.edgewisewise_bend_mom
            ),
            flapwise_bend_mom=(
                self.flapwise_bend_mom.as_write()
                if isinstance(self.flapwise_bend_mom, GraphQLCore)
                else self.flapwise_bend_mom
            ),
            flapwise_bend_mom_crosstalk_corrected=(
                self.flapwise_bend_mom_crosstalk_corrected.as_write()
                if isinstance(self.flapwise_bend_mom_crosstalk_corrected, GraphQLCore)
                else self.flapwise_bend_mom_crosstalk_corrected
            ),
            flapwise_bend_mom_offset=(
                self.flapwise_bend_mom_offset.as_write()
                if isinstance(self.flapwise_bend_mom_offset, GraphQLCore)
                else self.flapwise_bend_mom_offset
            ),
            flapwise_bend_mom_offset_crosstalk_corrected=(
                self.flapwise_bend_mom_offset_crosstalk_corrected.as_write()
                if isinstance(self.flapwise_bend_mom_offset_crosstalk_corrected, GraphQLCore)
                else self.flapwise_bend_mom_offset_crosstalk_corrected
            ),
            position=self.position,
        )

as_read()

Convert this GraphQL format of sensor position to the reading format.

Source code in examples/wind_turbine/data_classes/_sensor_position.py
@no_type_check
def as_read(self) -> SensorPosition:
    """Convert this GraphQL format of sensor position to the reading format."""
    if self.data_record is None:
        raise ValueError("This object cannot be converted to a read format because it lacks a data record.")
    return SensorPosition(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecord(
            version=0,
            last_updated_time=self.data_record.last_updated_time,
            created_time=self.data_record.created_time,
        ),
        blade=self.blade.as_read() if isinstance(self.blade, GraphQLCore) else self.blade,
        edgewise_bend_mom_crosstalk_corrected=(
            self.edgewise_bend_mom_crosstalk_corrected.as_read()
            if isinstance(self.edgewise_bend_mom_crosstalk_corrected, GraphQLCore)
            else self.edgewise_bend_mom_crosstalk_corrected
        ),
        edgewise_bend_mom_offset=(
            self.edgewise_bend_mom_offset.as_read()
            if isinstance(self.edgewise_bend_mom_offset, GraphQLCore)
            else self.edgewise_bend_mom_offset
        ),
        edgewise_bend_mom_offset_crosstalk_corrected=(
            self.edgewise_bend_mom_offset_crosstalk_corrected.as_read()
            if isinstance(self.edgewise_bend_mom_offset_crosstalk_corrected, GraphQLCore)
            else self.edgewise_bend_mom_offset_crosstalk_corrected
        ),
        edgewisewise_bend_mom=(
            self.edgewisewise_bend_mom.as_read()
            if isinstance(self.edgewisewise_bend_mom, GraphQLCore)
            else self.edgewisewise_bend_mom
        ),
        flapwise_bend_mom=(
            self.flapwise_bend_mom.as_read()
            if isinstance(self.flapwise_bend_mom, GraphQLCore)
            else self.flapwise_bend_mom
        ),
        flapwise_bend_mom_crosstalk_corrected=(
            self.flapwise_bend_mom_crosstalk_corrected.as_read()
            if isinstance(self.flapwise_bend_mom_crosstalk_corrected, GraphQLCore)
            else self.flapwise_bend_mom_crosstalk_corrected
        ),
        flapwise_bend_mom_offset=(
            self.flapwise_bend_mom_offset.as_read()
            if isinstance(self.flapwise_bend_mom_offset, GraphQLCore)
            else self.flapwise_bend_mom_offset
        ),
        flapwise_bend_mom_offset_crosstalk_corrected=(
            self.flapwise_bend_mom_offset_crosstalk_corrected.as_read()
            if isinstance(self.flapwise_bend_mom_offset_crosstalk_corrected, GraphQLCore)
            else self.flapwise_bend_mom_offset_crosstalk_corrected
        ),
        position=self.position,
    )

as_write()

Convert this GraphQL format of sensor position to the writing format.

Source code in examples/wind_turbine/data_classes/_sensor_position.py
@no_type_check
def as_write(self) -> SensorPositionWrite:
    """Convert this GraphQL format of sensor position to the writing format."""
    return SensorPositionWrite(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecordWrite(existing_version=0),
        blade=self.blade.as_write() if isinstance(self.blade, GraphQLCore) else self.blade,
        edgewise_bend_mom_crosstalk_corrected=(
            self.edgewise_bend_mom_crosstalk_corrected.as_write()
            if isinstance(self.edgewise_bend_mom_crosstalk_corrected, GraphQLCore)
            else self.edgewise_bend_mom_crosstalk_corrected
        ),
        edgewise_bend_mom_offset=(
            self.edgewise_bend_mom_offset.as_write()
            if isinstance(self.edgewise_bend_mom_offset, GraphQLCore)
            else self.edgewise_bend_mom_offset
        ),
        edgewise_bend_mom_offset_crosstalk_corrected=(
            self.edgewise_bend_mom_offset_crosstalk_corrected.as_write()
            if isinstance(self.edgewise_bend_mom_offset_crosstalk_corrected, GraphQLCore)
            else self.edgewise_bend_mom_offset_crosstalk_corrected
        ),
        edgewisewise_bend_mom=(
            self.edgewisewise_bend_mom.as_write()
            if isinstance(self.edgewisewise_bend_mom, GraphQLCore)
            else self.edgewisewise_bend_mom
        ),
        flapwise_bend_mom=(
            self.flapwise_bend_mom.as_write()
            if isinstance(self.flapwise_bend_mom, GraphQLCore)
            else self.flapwise_bend_mom
        ),
        flapwise_bend_mom_crosstalk_corrected=(
            self.flapwise_bend_mom_crosstalk_corrected.as_write()
            if isinstance(self.flapwise_bend_mom_crosstalk_corrected, GraphQLCore)
            else self.flapwise_bend_mom_crosstalk_corrected
        ),
        flapwise_bend_mom_offset=(
            self.flapwise_bend_mom_offset.as_write()
            if isinstance(self.flapwise_bend_mom_offset, GraphQLCore)
            else self.flapwise_bend_mom_offset
        ),
        flapwise_bend_mom_offset_crosstalk_corrected=(
            self.flapwise_bend_mom_offset_crosstalk_corrected.as_write()
            if isinstance(self.flapwise_bend_mom_offset_crosstalk_corrected, GraphQLCore)
            else self.flapwise_bend_mom_offset_crosstalk_corrected
        ),
        position=self.position,
    )

SensorPositionList

Bases: DomainModelList[SensorPosition]

List of sensor positions in the read version.

Source code in examples/wind_turbine/data_classes/_sensor_position.py
class SensorPositionList(DomainModelList[SensorPosition]):
    """List of sensor positions in the read version."""

    _INSTANCE = SensorPosition

    def as_write(self) -> SensorPositionWriteList:
        """Convert these read versions of sensor position to the writing versions."""
        return SensorPositionWriteList([node.as_write() for node in self.data])

    def as_apply(self) -> SensorPositionWriteList:
        """Convert these read versions of primitive nullable to the writing versions."""
        warnings.warn(
            "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
            UserWarning,
            stacklevel=2,
        )
        return self.as_write()

    @property
    def blade(self) -> BladeList:
        from ._blade import Blade, BladeList

        return BladeList([item.blade for item in self.data if isinstance(item.blade, Blade)])

    @property
    def edgewise_bend_mom_crosstalk_corrected(self) -> SensorTimeSeriesList:
        from ._sensor_time_series import SensorTimeSeries, SensorTimeSeriesList

        return SensorTimeSeriesList(
            [
                item.edgewise_bend_mom_crosstalk_corrected
                for item in self.data
                if isinstance(item.edgewise_bend_mom_crosstalk_corrected, SensorTimeSeries)
            ]
        )

    @property
    def edgewise_bend_mom_offset(self) -> SensorTimeSeriesList:
        from ._sensor_time_series import SensorTimeSeries, SensorTimeSeriesList

        return SensorTimeSeriesList(
            [
                item.edgewise_bend_mom_offset
                for item in self.data
                if isinstance(item.edgewise_bend_mom_offset, SensorTimeSeries)
            ]
        )

    @property
    def edgewise_bend_mom_offset_crosstalk_corrected(self) -> SensorTimeSeriesList:
        from ._sensor_time_series import SensorTimeSeries, SensorTimeSeriesList

        return SensorTimeSeriesList(
            [
                item.edgewise_bend_mom_offset_crosstalk_corrected
                for item in self.data
                if isinstance(item.edgewise_bend_mom_offset_crosstalk_corrected, SensorTimeSeries)
            ]
        )

    @property
    def edgewisewise_bend_mom(self) -> SensorTimeSeriesList:
        from ._sensor_time_series import SensorTimeSeries, SensorTimeSeriesList

        return SensorTimeSeriesList(
            [
                item.edgewisewise_bend_mom
                for item in self.data
                if isinstance(item.edgewisewise_bend_mom, SensorTimeSeries)
            ]
        )

    @property
    def flapwise_bend_mom(self) -> SensorTimeSeriesList:
        from ._sensor_time_series import SensorTimeSeries, SensorTimeSeriesList

        return SensorTimeSeriesList(
            [item.flapwise_bend_mom for item in self.data if isinstance(item.flapwise_bend_mom, SensorTimeSeries)]
        )

    @property
    def flapwise_bend_mom_crosstalk_corrected(self) -> SensorTimeSeriesList:
        from ._sensor_time_series import SensorTimeSeries, SensorTimeSeriesList

        return SensorTimeSeriesList(
            [
                item.flapwise_bend_mom_crosstalk_corrected
                for item in self.data
                if isinstance(item.flapwise_bend_mom_crosstalk_corrected, SensorTimeSeries)
            ]
        )

    @property
    def flapwise_bend_mom_offset(self) -> SensorTimeSeriesList:
        from ._sensor_time_series import SensorTimeSeries, SensorTimeSeriesList

        return SensorTimeSeriesList(
            [
                item.flapwise_bend_mom_offset
                for item in self.data
                if isinstance(item.flapwise_bend_mom_offset, SensorTimeSeries)
            ]
        )

    @property
    def flapwise_bend_mom_offset_crosstalk_corrected(self) -> SensorTimeSeriesList:
        from ._sensor_time_series import SensorTimeSeries, SensorTimeSeriesList

        return SensorTimeSeriesList(
            [
                item.flapwise_bend_mom_offset_crosstalk_corrected
                for item in self.data
                if isinstance(item.flapwise_bend_mom_offset_crosstalk_corrected, SensorTimeSeries)
            ]
        )

as_apply()

Convert these read versions of primitive nullable to the writing versions.

Source code in examples/wind_turbine/data_classes/_sensor_position.py
def as_apply(self) -> SensorPositionWriteList:
    """Convert these read versions of primitive nullable to the writing versions."""
    warnings.warn(
        "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
        UserWarning,
        stacklevel=2,
    )
    return self.as_write()

as_write()

Convert these read versions of sensor position to the writing versions.

Source code in examples/wind_turbine/data_classes/_sensor_position.py
def as_write(self) -> SensorPositionWriteList:
    """Convert these read versions of sensor position to the writing versions."""
    return SensorPositionWriteList([node.as_write() for node in self.data])

SensorPositionWrite

Bases: DomainModelWrite

This represents the writing version of sensor position.

It is used to when data is sent to CDF.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the sensor position.

required
data_record

The data record of the sensor position node.

required
blade

The blade field.

required
edgewise_bend_mom_crosstalk_corrected

The edgewise bend mom crosstalk corrected field.

required
edgewise_bend_mom_offset

The edgewise bend mom offset field.

required
edgewise_bend_mom_offset_crosstalk_corrected

The edgewise bend mom offset crosstalk corrected field.

required
edgewisewise_bend_mom

The edgewisewise bend mom field.

required
flapwise_bend_mom

The flapwise bend mom field.

required
flapwise_bend_mom_crosstalk_corrected

The flapwise bend mom crosstalk corrected field.

required
flapwise_bend_mom_offset

The flapwise bend mom offset field.

required
flapwise_bend_mom_offset_crosstalk_corrected

The flapwise bend mom offset crosstalk corrected field.

required
position

The position field.

required
Source code in examples/wind_turbine/data_classes/_sensor_position.py
class SensorPositionWrite(DomainModelWrite):
    """This represents the writing version of sensor position.

    It is used to when data is sent to CDF.

    Args:
        space: The space where the node is located.
        external_id: The external id of the sensor position.
        data_record: The data record of the sensor position node.
        blade: The blade field.
        edgewise_bend_mom_crosstalk_corrected: The edgewise bend mom crosstalk corrected field.
        edgewise_bend_mom_offset: The edgewise bend mom offset field.
        edgewise_bend_mom_offset_crosstalk_corrected: The edgewise bend mom offset crosstalk corrected field.
        edgewisewise_bend_mom: The edgewisewise bend mom field.
        flapwise_bend_mom: The flapwise bend mom field.
        flapwise_bend_mom_crosstalk_corrected: The flapwise bend mom crosstalk corrected field.
        flapwise_bend_mom_offset: The flapwise bend mom offset field.
        flapwise_bend_mom_offset_crosstalk_corrected: The flapwise bend mom offset crosstalk corrected field.
        position: The position field.
    """

    _view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "SensorPosition", "1")

    space: str = DEFAULT_INSTANCE_SPACE
    node_type: Union[dm.DirectRelationReference, dm.NodeId, tuple[str, str], None] = None
    blade: Union[BladeWrite, str, dm.NodeId, None] = Field(default=None, repr=False)
    edgewise_bend_mom_crosstalk_corrected: Union[SensorTimeSeriesWrite, str, dm.NodeId, None] = Field(
        default=None, repr=False
    )
    edgewise_bend_mom_offset: Union[SensorTimeSeriesWrite, str, dm.NodeId, None] = Field(default=None, repr=False)
    edgewise_bend_mom_offset_crosstalk_corrected: Union[SensorTimeSeriesWrite, str, dm.NodeId, None] = Field(
        default=None, repr=False
    )
    edgewisewise_bend_mom: Union[SensorTimeSeriesWrite, str, dm.NodeId, None] = Field(default=None, repr=False)
    flapwise_bend_mom: Union[SensorTimeSeriesWrite, str, dm.NodeId, None] = Field(default=None, repr=False)
    flapwise_bend_mom_crosstalk_corrected: Union[SensorTimeSeriesWrite, str, dm.NodeId, None] = Field(
        default=None, repr=False
    )
    flapwise_bend_mom_offset: Union[SensorTimeSeriesWrite, str, dm.NodeId, None] = Field(default=None, repr=False)
    flapwise_bend_mom_offset_crosstalk_corrected: Union[SensorTimeSeriesWrite, str, dm.NodeId, None] = Field(
        default=None, repr=False
    )
    position: Optional[float] = None

    @field_validator(
        "blade",
        "edgewise_bend_mom_crosstalk_corrected",
        "edgewise_bend_mom_offset",
        "edgewise_bend_mom_offset_crosstalk_corrected",
        "edgewisewise_bend_mom",
        "flapwise_bend_mom",
        "flapwise_bend_mom_crosstalk_corrected",
        "flapwise_bend_mom_offset",
        "flapwise_bend_mom_offset_crosstalk_corrected",
        mode="before",
    )
    def as_node_id(cls, value: Any) -> Any:
        if isinstance(value, dm.DirectRelationReference):
            return dm.NodeId(value.space, value.external_id)
        elif isinstance(value, tuple) and len(value) == 2 and all(isinstance(item, str) for item in value):
            return dm.NodeId(value[0], value[1])
        elif isinstance(value, list):
            return [cls.as_node_id(item) for item in value]
        return value

    def _to_instances_write(
        self,
        cache: set[tuple[str, str]],
        write_none: bool = False,
        allow_version_increase: bool = False,
    ) -> ResourcesWrite:
        resources = ResourcesWrite()
        if self.as_tuple_id() in cache:
            return resources

        properties: dict[str, Any] = {}

        if self.blade is not None:
            properties["blade"] = {
                "space": self.space if isinstance(self.blade, str) else self.blade.space,
                "externalId": self.blade if isinstance(self.blade, str) else self.blade.external_id,
            }

        if self.edgewise_bend_mom_crosstalk_corrected is not None:
            properties["edgewise_bend_mom_crosstalk_corrected"] = {
                "space": (
                    self.space
                    if isinstance(self.edgewise_bend_mom_crosstalk_corrected, str)
                    else self.edgewise_bend_mom_crosstalk_corrected.space
                ),
                "externalId": (
                    self.edgewise_bend_mom_crosstalk_corrected
                    if isinstance(self.edgewise_bend_mom_crosstalk_corrected, str)
                    else self.edgewise_bend_mom_crosstalk_corrected.external_id
                ),
            }

        if self.edgewise_bend_mom_offset is not None:
            properties["edgewise_bend_mom_offset"] = {
                "space": (
                    self.space
                    if isinstance(self.edgewise_bend_mom_offset, str)
                    else self.edgewise_bend_mom_offset.space
                ),
                "externalId": (
                    self.edgewise_bend_mom_offset
                    if isinstance(self.edgewise_bend_mom_offset, str)
                    else self.edgewise_bend_mom_offset.external_id
                ),
            }

        if self.edgewise_bend_mom_offset_crosstalk_corrected is not None:
            properties["edgewise_bend_mom_offset_crosstalk_corrected"] = {
                "space": (
                    self.space
                    if isinstance(self.edgewise_bend_mom_offset_crosstalk_corrected, str)
                    else self.edgewise_bend_mom_offset_crosstalk_corrected.space
                ),
                "externalId": (
                    self.edgewise_bend_mom_offset_crosstalk_corrected
                    if isinstance(self.edgewise_bend_mom_offset_crosstalk_corrected, str)
                    else self.edgewise_bend_mom_offset_crosstalk_corrected.external_id
                ),
            }

        if self.edgewisewise_bend_mom is not None:
            properties["edgewisewise_bend_mom"] = {
                "space": (
                    self.space if isinstance(self.edgewisewise_bend_mom, str) else self.edgewisewise_bend_mom.space
                ),
                "externalId": (
                    self.edgewisewise_bend_mom
                    if isinstance(self.edgewisewise_bend_mom, str)
                    else self.edgewisewise_bend_mom.external_id
                ),
            }

        if self.flapwise_bend_mom is not None:
            properties["flapwise_bend_mom"] = {
                "space": self.space if isinstance(self.flapwise_bend_mom, str) else self.flapwise_bend_mom.space,
                "externalId": (
                    self.flapwise_bend_mom
                    if isinstance(self.flapwise_bend_mom, str)
                    else self.flapwise_bend_mom.external_id
                ),
            }

        if self.flapwise_bend_mom_crosstalk_corrected is not None:
            properties["flapwise_bend_mom_crosstalk_corrected"] = {
                "space": (
                    self.space
                    if isinstance(self.flapwise_bend_mom_crosstalk_corrected, str)
                    else self.flapwise_bend_mom_crosstalk_corrected.space
                ),
                "externalId": (
                    self.flapwise_bend_mom_crosstalk_corrected
                    if isinstance(self.flapwise_bend_mom_crosstalk_corrected, str)
                    else self.flapwise_bend_mom_crosstalk_corrected.external_id
                ),
            }

        if self.flapwise_bend_mom_offset is not None:
            properties["flapwise_bend_mom_offset"] = {
                "space": (
                    self.space
                    if isinstance(self.flapwise_bend_mom_offset, str)
                    else self.flapwise_bend_mom_offset.space
                ),
                "externalId": (
                    self.flapwise_bend_mom_offset
                    if isinstance(self.flapwise_bend_mom_offset, str)
                    else self.flapwise_bend_mom_offset.external_id
                ),
            }

        if self.flapwise_bend_mom_offset_crosstalk_corrected is not None:
            properties["flapwise_bend_mom_offset_crosstalk_corrected"] = {
                "space": (
                    self.space
                    if isinstance(self.flapwise_bend_mom_offset_crosstalk_corrected, str)
                    else self.flapwise_bend_mom_offset_crosstalk_corrected.space
                ),
                "externalId": (
                    self.flapwise_bend_mom_offset_crosstalk_corrected
                    if isinstance(self.flapwise_bend_mom_offset_crosstalk_corrected, str)
                    else self.flapwise_bend_mom_offset_crosstalk_corrected.external_id
                ),
            }

        if self.position is not None or write_none:
            properties["position"] = self.position

        if properties:
            this_node = dm.NodeApply(
                space=self.space,
                external_id=self.external_id,
                existing_version=None if allow_version_increase else self.data_record.existing_version,
                type=as_direct_relation_reference(self.node_type),
                sources=[
                    dm.NodeOrEdgeData(
                        source=self._view_id,
                        properties=properties,
                    )
                ],
            )
            resources.nodes.append(this_node)
            cache.add(self.as_tuple_id())

        if isinstance(self.blade, DomainModelWrite):
            other_resources = self.blade._to_instances_write(cache)
            resources.extend(other_resources)

        if isinstance(self.edgewise_bend_mom_crosstalk_corrected, DomainModelWrite):
            other_resources = self.edgewise_bend_mom_crosstalk_corrected._to_instances_write(cache)
            resources.extend(other_resources)

        if isinstance(self.edgewise_bend_mom_offset, DomainModelWrite):
            other_resources = self.edgewise_bend_mom_offset._to_instances_write(cache)
            resources.extend(other_resources)

        if isinstance(self.edgewise_bend_mom_offset_crosstalk_corrected, DomainModelWrite):
            other_resources = self.edgewise_bend_mom_offset_crosstalk_corrected._to_instances_write(cache)
            resources.extend(other_resources)

        if isinstance(self.edgewisewise_bend_mom, DomainModelWrite):
            other_resources = self.edgewisewise_bend_mom._to_instances_write(cache)
            resources.extend(other_resources)

        if isinstance(self.flapwise_bend_mom, DomainModelWrite):
            other_resources = self.flapwise_bend_mom._to_instances_write(cache)
            resources.extend(other_resources)

        if isinstance(self.flapwise_bend_mom_crosstalk_corrected, DomainModelWrite):
            other_resources = self.flapwise_bend_mom_crosstalk_corrected._to_instances_write(cache)
            resources.extend(other_resources)

        if isinstance(self.flapwise_bend_mom_offset, DomainModelWrite):
            other_resources = self.flapwise_bend_mom_offset._to_instances_write(cache)
            resources.extend(other_resources)

        if isinstance(self.flapwise_bend_mom_offset_crosstalk_corrected, DomainModelWrite):
            other_resources = self.flapwise_bend_mom_offset_crosstalk_corrected._to_instances_write(cache)
            resources.extend(other_resources)

        return resources

SensorPositionWriteList

Bases: DomainModelWriteList[SensorPositionWrite]

List of sensor positions in the writing version.

Source code in examples/wind_turbine/data_classes/_sensor_position.py
class SensorPositionWriteList(DomainModelWriteList[SensorPositionWrite]):
    """List of sensor positions in the writing version."""

    _INSTANCE = SensorPositionWrite

    @property
    def blade(self) -> BladeWriteList:
        from ._blade import BladeWrite, BladeWriteList

        return BladeWriteList([item.blade for item in self.data if isinstance(item.blade, BladeWrite)])

    @property
    def edgewise_bend_mom_crosstalk_corrected(self) -> SensorTimeSeriesWriteList:
        from ._sensor_time_series import SensorTimeSeriesWrite, SensorTimeSeriesWriteList

        return SensorTimeSeriesWriteList(
            [
                item.edgewise_bend_mom_crosstalk_corrected
                for item in self.data
                if isinstance(item.edgewise_bend_mom_crosstalk_corrected, SensorTimeSeriesWrite)
            ]
        )

    @property
    def edgewise_bend_mom_offset(self) -> SensorTimeSeriesWriteList:
        from ._sensor_time_series import SensorTimeSeriesWrite, SensorTimeSeriesWriteList

        return SensorTimeSeriesWriteList(
            [
                item.edgewise_bend_mom_offset
                for item in self.data
                if isinstance(item.edgewise_bend_mom_offset, SensorTimeSeriesWrite)
            ]
        )

    @property
    def edgewise_bend_mom_offset_crosstalk_corrected(self) -> SensorTimeSeriesWriteList:
        from ._sensor_time_series import SensorTimeSeriesWrite, SensorTimeSeriesWriteList

        return SensorTimeSeriesWriteList(
            [
                item.edgewise_bend_mom_offset_crosstalk_corrected
                for item in self.data
                if isinstance(item.edgewise_bend_mom_offset_crosstalk_corrected, SensorTimeSeriesWrite)
            ]
        )

    @property
    def edgewisewise_bend_mom(self) -> SensorTimeSeriesWriteList:
        from ._sensor_time_series import SensorTimeSeriesWrite, SensorTimeSeriesWriteList

        return SensorTimeSeriesWriteList(
            [
                item.edgewisewise_bend_mom
                for item in self.data
                if isinstance(item.edgewisewise_bend_mom, SensorTimeSeriesWrite)
            ]
        )

    @property
    def flapwise_bend_mom(self) -> SensorTimeSeriesWriteList:
        from ._sensor_time_series import SensorTimeSeriesWrite, SensorTimeSeriesWriteList

        return SensorTimeSeriesWriteList(
            [item.flapwise_bend_mom for item in self.data if isinstance(item.flapwise_bend_mom, SensorTimeSeriesWrite)]
        )

    @property
    def flapwise_bend_mom_crosstalk_corrected(self) -> SensorTimeSeriesWriteList:
        from ._sensor_time_series import SensorTimeSeriesWrite, SensorTimeSeriesWriteList

        return SensorTimeSeriesWriteList(
            [
                item.flapwise_bend_mom_crosstalk_corrected
                for item in self.data
                if isinstance(item.flapwise_bend_mom_crosstalk_corrected, SensorTimeSeriesWrite)
            ]
        )

    @property
    def flapwise_bend_mom_offset(self) -> SensorTimeSeriesWriteList:
        from ._sensor_time_series import SensorTimeSeriesWrite, SensorTimeSeriesWriteList

        return SensorTimeSeriesWriteList(
            [
                item.flapwise_bend_mom_offset
                for item in self.data
                if isinstance(item.flapwise_bend_mom_offset, SensorTimeSeriesWrite)
            ]
        )

    @property
    def flapwise_bend_mom_offset_crosstalk_corrected(self) -> SensorTimeSeriesWriteList:
        from ._sensor_time_series import SensorTimeSeriesWrite, SensorTimeSeriesWriteList

        return SensorTimeSeriesWriteList(
            [
                item.flapwise_bend_mom_offset_crosstalk_corrected
                for item in self.data
                if isinstance(item.flapwise_bend_mom_offset_crosstalk_corrected, SensorTimeSeriesWrite)
            ]
        )

SensorTimeSeries

Bases: DomainModel

This represents the reading version of sensor time series.

It is used to when data is retrieved from CDF.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the sensor time series.

required
data_record

The data record of the sensor time series node.

required
aliases

Alternative names for the node

required
concept_id

The concept ID of the time series.

required
description

Description of the instance

required
is_step

Specifies whether the time series is a step time series or not.

required
name

Name of the instance

required
source_unit

The unit specified in the source system.

required
standard_name

The standard name of the time series.

required
type_

Specifies the data type of the data points.

required
Source code in examples/wind_turbine/data_classes/_sensor_time_series.py
class SensorTimeSeries(DomainModel):
    """This represents the reading version of sensor time series.

    It is used to when data is retrieved from CDF.

    Args:
        space: The space where the node is located.
        external_id: The external id of the sensor time series.
        data_record: The data record of the sensor time series node.
        aliases: Alternative names for the node
        concept_id: The concept ID of the time series.
        description: Description of the instance
        is_step: Specifies whether the time series is a step time series or not.
        name: Name of the instance
        source_unit: The unit specified in the source system.
        standard_name: The standard name of the time series.
        type_: Specifies the data type of the data points.
    """

    _view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "SensorTimeSeries", "1")

    space: str = DEFAULT_INSTANCE_SPACE
    node_type: Union[dm.DirectRelationReference, None] = None
    aliases: Optional[list[str]] = None
    concept_id: Optional[str] = Field(None, alias="conceptId")
    description: Optional[str] = None
    is_step: bool = Field(alias="isStep")
    name: Optional[str] = None
    source_unit: Optional[str] = Field(None, alias="sourceUnit")
    standard_name: Optional[str] = Field(None, alias="standardName")
    type_: Literal["numeric", "string"] = Field(alias="type")

    def as_write(self) -> SensorTimeSeriesWrite:
        """Convert this read version of sensor time series to the writing version."""
        return SensorTimeSeriesWrite(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecordWrite(existing_version=self.data_record.version),
            aliases=self.aliases,
            concept_id=self.concept_id,
            description=self.description,
            is_step=self.is_step,
            name=self.name,
            source_unit=self.source_unit,
            standard_name=self.standard_name,
            type_=self.type_,
        )

    def as_apply(self) -> SensorTimeSeriesWrite:
        """Convert this read version of sensor time series to the writing version."""
        warnings.warn(
            "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
            UserWarning,
            stacklevel=2,
        )
        return self.as_write()

as_apply()

Convert this read version of sensor time series to the writing version.

Source code in examples/wind_turbine/data_classes/_sensor_time_series.py
def as_apply(self) -> SensorTimeSeriesWrite:
    """Convert this read version of sensor time series to the writing version."""
    warnings.warn(
        "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
        UserWarning,
        stacklevel=2,
    )
    return self.as_write()

as_write()

Convert this read version of sensor time series to the writing version.

Source code in examples/wind_turbine/data_classes/_sensor_time_series.py
def as_write(self) -> SensorTimeSeriesWrite:
    """Convert this read version of sensor time series to the writing version."""
    return SensorTimeSeriesWrite(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecordWrite(existing_version=self.data_record.version),
        aliases=self.aliases,
        concept_id=self.concept_id,
        description=self.description,
        is_step=self.is_step,
        name=self.name,
        source_unit=self.source_unit,
        standard_name=self.standard_name,
        type_=self.type_,
    )

SensorTimeSeriesGraphQL

Bases: GraphQLCore

This represents the reading version of sensor time series, used when data is retrieved from CDF using GraphQL.

It is used when retrieving data from CDF using GraphQL.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the sensor time series.

required
data_record

The data record of the sensor time series node.

required
aliases

Alternative names for the node

required
concept_id

The concept ID of the time series.

required
description

Description of the instance

required
is_step

Specifies whether the time series is a step time series or not.

required
name

Name of the instance

required
source_unit

The unit specified in the source system.

required
standard_name

The standard name of the time series.

required
type_

Specifies the data type of the data points.

required
Source code in examples/wind_turbine/data_classes/_sensor_time_series.py
class SensorTimeSeriesGraphQL(GraphQLCore):
    """This represents the reading version of sensor time series, used
    when data is retrieved from CDF using GraphQL.

    It is used when retrieving data from CDF using GraphQL.

    Args:
        space: The space where the node is located.
        external_id: The external id of the sensor time series.
        data_record: The data record of the sensor time series node.
        aliases: Alternative names for the node
        concept_id: The concept ID of the time series.
        description: Description of the instance
        is_step: Specifies whether the time series is a step time series or not.
        name: Name of the instance
        source_unit: The unit specified in the source system.
        standard_name: The standard name of the time series.
        type_: Specifies the data type of the data points.
    """

    view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "SensorTimeSeries", "1")
    aliases: Optional[list[str]] = None
    concept_id: Optional[str] = Field(None, alias="conceptId")
    description: Optional[str] = None
    is_step: Optional[bool] = Field(None, alias="isStep")
    name: Optional[str] = None
    source_unit: Optional[str] = Field(None, alias="sourceUnit")
    standard_name: Optional[str] = Field(None, alias="standardName")
    type_: Optional[Literal["numeric", "string"]] = Field(None, alias="type")

    @model_validator(mode="before")
    def parse_data_record(cls, values: Any) -> Any:
        if not isinstance(values, dict):
            return values
        if "lastUpdatedTime" in values or "createdTime" in values:
            values["dataRecord"] = DataRecordGraphQL(
                created_time=values.pop("createdTime", None),
                last_updated_time=values.pop("lastUpdatedTime", None),
            )
        return values

    # We do the ignore argument type as we let pydantic handle the type checking
    @no_type_check
    def as_read(self) -> SensorTimeSeries:
        """Convert this GraphQL format of sensor time series to the reading format."""
        if self.data_record is None:
            raise ValueError("This object cannot be converted to a read format because it lacks a data record.")
        return SensorTimeSeries(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecord(
                version=0,
                last_updated_time=self.data_record.last_updated_time,
                created_time=self.data_record.created_time,
            ),
            aliases=self.aliases,
            concept_id=self.concept_id,
            description=self.description,
            is_step=self.is_step,
            name=self.name,
            source_unit=self.source_unit,
            standard_name=self.standard_name,
            type_=self.type_,
        )

    # We do the ignore argument type as we let pydantic handle the type checking
    @no_type_check
    def as_write(self) -> SensorTimeSeriesWrite:
        """Convert this GraphQL format of sensor time series to the writing format."""
        return SensorTimeSeriesWrite(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecordWrite(existing_version=0),
            aliases=self.aliases,
            concept_id=self.concept_id,
            description=self.description,
            is_step=self.is_step,
            name=self.name,
            source_unit=self.source_unit,
            standard_name=self.standard_name,
            type_=self.type_,
        )

as_read()

Convert this GraphQL format of sensor time series to the reading format.

Source code in examples/wind_turbine/data_classes/_sensor_time_series.py
@no_type_check
def as_read(self) -> SensorTimeSeries:
    """Convert this GraphQL format of sensor time series to the reading format."""
    if self.data_record is None:
        raise ValueError("This object cannot be converted to a read format because it lacks a data record.")
    return SensorTimeSeries(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecord(
            version=0,
            last_updated_time=self.data_record.last_updated_time,
            created_time=self.data_record.created_time,
        ),
        aliases=self.aliases,
        concept_id=self.concept_id,
        description=self.description,
        is_step=self.is_step,
        name=self.name,
        source_unit=self.source_unit,
        standard_name=self.standard_name,
        type_=self.type_,
    )

as_write()

Convert this GraphQL format of sensor time series to the writing format.

Source code in examples/wind_turbine/data_classes/_sensor_time_series.py
@no_type_check
def as_write(self) -> SensorTimeSeriesWrite:
    """Convert this GraphQL format of sensor time series to the writing format."""
    return SensorTimeSeriesWrite(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecordWrite(existing_version=0),
        aliases=self.aliases,
        concept_id=self.concept_id,
        description=self.description,
        is_step=self.is_step,
        name=self.name,
        source_unit=self.source_unit,
        standard_name=self.standard_name,
        type_=self.type_,
    )

SensorTimeSeriesList

Bases: DomainModelList[SensorTimeSeries]

List of sensor time series in the read version.

Source code in examples/wind_turbine/data_classes/_sensor_time_series.py
class SensorTimeSeriesList(DomainModelList[SensorTimeSeries]):
    """List of sensor time series in the read version."""

    _INSTANCE = SensorTimeSeries

    def as_write(self) -> SensorTimeSeriesWriteList:
        """Convert these read versions of sensor time series to the writing versions."""
        return SensorTimeSeriesWriteList([node.as_write() for node in self.data])

    def as_apply(self) -> SensorTimeSeriesWriteList:
        """Convert these read versions of primitive nullable to the writing versions."""
        warnings.warn(
            "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
            UserWarning,
            stacklevel=2,
        )
        return self.as_write()

as_apply()

Convert these read versions of primitive nullable to the writing versions.

Source code in examples/wind_turbine/data_classes/_sensor_time_series.py
def as_apply(self) -> SensorTimeSeriesWriteList:
    """Convert these read versions of primitive nullable to the writing versions."""
    warnings.warn(
        "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
        UserWarning,
        stacklevel=2,
    )
    return self.as_write()

as_write()

Convert these read versions of sensor time series to the writing versions.

Source code in examples/wind_turbine/data_classes/_sensor_time_series.py
def as_write(self) -> SensorTimeSeriesWriteList:
    """Convert these read versions of sensor time series to the writing versions."""
    return SensorTimeSeriesWriteList([node.as_write() for node in self.data])

SensorTimeSeriesWrite

Bases: DomainModelWrite

This represents the writing version of sensor time series.

It is used to when data is sent to CDF.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the sensor time series.

required
data_record

The data record of the sensor time series node.

required
aliases

Alternative names for the node

required
concept_id

The concept ID of the time series.

required
description

Description of the instance

required
is_step

Specifies whether the time series is a step time series or not.

required
name

Name of the instance

required
source_unit

The unit specified in the source system.

required
standard_name

The standard name of the time series.

required
type_

Specifies the data type of the data points.

required
Source code in examples/wind_turbine/data_classes/_sensor_time_series.py
class SensorTimeSeriesWrite(DomainModelWrite):
    """This represents the writing version of sensor time series.

    It is used to when data is sent to CDF.

    Args:
        space: The space where the node is located.
        external_id: The external id of the sensor time series.
        data_record: The data record of the sensor time series node.
        aliases: Alternative names for the node
        concept_id: The concept ID of the time series.
        description: Description of the instance
        is_step: Specifies whether the time series is a step time series or not.
        name: Name of the instance
        source_unit: The unit specified in the source system.
        standard_name: The standard name of the time series.
        type_: Specifies the data type of the data points.
    """

    _view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "SensorTimeSeries", "1")

    space: str = DEFAULT_INSTANCE_SPACE
    node_type: Union[dm.DirectRelationReference, dm.NodeId, tuple[str, str], None] = None
    aliases: Optional[list[str]] = None
    concept_id: Optional[str] = Field(None, alias="conceptId")
    description: Optional[str] = None
    is_step: bool = Field(alias="isStep")
    name: Optional[str] = None
    source_unit: Optional[str] = Field(None, alias="sourceUnit")
    standard_name: Optional[str] = Field(None, alias="standardName")
    type_: Literal["numeric", "string"] = Field(alias="type")

    def _to_instances_write(
        self,
        cache: set[tuple[str, str]],
        write_none: bool = False,
        allow_version_increase: bool = False,
    ) -> ResourcesWrite:
        resources = ResourcesWrite()
        if self.as_tuple_id() in cache:
            return resources

        properties: dict[str, Any] = {}

        if self.aliases is not None or write_none:
            properties["aliases"] = self.aliases

        if self.concept_id is not None or write_none:
            properties["conceptId"] = self.concept_id

        if self.description is not None or write_none:
            properties["description"] = self.description

        if self.is_step is not None:
            properties["isStep"] = self.is_step

        if self.name is not None or write_none:
            properties["name"] = self.name

        if self.source_unit is not None or write_none:
            properties["sourceUnit"] = self.source_unit

        if self.standard_name is not None or write_none:
            properties["standardName"] = self.standard_name

        if self.type_ is not None:
            properties["type"] = self.type_

        if properties:
            this_node = dm.NodeApply(
                space=self.space,
                external_id=self.external_id,
                existing_version=None if allow_version_increase else self.data_record.existing_version,
                type=as_direct_relation_reference(self.node_type),
                sources=[
                    dm.NodeOrEdgeData(
                        source=self._view_id,
                        properties=properties,
                    )
                ],
            )
            resources.nodes.append(this_node)
            cache.add(self.as_tuple_id())

        return resources

SensorTimeSeriesWriteList

Bases: DomainModelWriteList[SensorTimeSeriesWrite]

List of sensor time series in the writing version.

Source code in examples/wind_turbine/data_classes/_sensor_time_series.py
class SensorTimeSeriesWriteList(DomainModelWriteList[SensorTimeSeriesWrite]):
    """List of sensor time series in the writing version."""

    _INSTANCE = SensorTimeSeriesWrite

SolarPanel

Bases: GeneratingUnit

This represents the reading version of solar panel.

It is used to when data is retrieved from CDF.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the solar panel.

required
data_record

The data record of the solar panel node.

required
capacity

The capacity field.

required
description

Description of the instance

required
efficiency

The efficiency field.

required
name

Name of the instance

required
orientation

The orientation field.

required
Source code in examples/wind_turbine/data_classes/_solar_panel.py
class SolarPanel(GeneratingUnit):
    """This represents the reading version of solar panel.

    It is used to when data is retrieved from CDF.

    Args:
        space: The space where the node is located.
        external_id: The external id of the solar panel.
        data_record: The data record of the solar panel node.
        capacity: The capacity field.
        description: Description of the instance
        efficiency: The efficiency field.
        name: Name of the instance
        orientation: The orientation field.
    """

    _view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "SolarPanel", "1")

    node_type: Union[dm.DirectRelationReference, None] = None
    efficiency: Union[SensorTimeSeries, str, dm.NodeId, None] = Field(default=None, repr=False)
    orientation: Union[SensorTimeSeries, str, dm.NodeId, None] = Field(default=None, repr=False)

    def as_write(self) -> SolarPanelWrite:
        """Convert this read version of solar panel to the writing version."""
        return SolarPanelWrite(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecordWrite(existing_version=self.data_record.version),
            capacity=self.capacity,
            description=self.description,
            efficiency=self.efficiency.as_write() if isinstance(self.efficiency, DomainModel) else self.efficiency,
            name=self.name,
            orientation=self.orientation.as_write() if isinstance(self.orientation, DomainModel) else self.orientation,
        )

    def as_apply(self) -> SolarPanelWrite:
        """Convert this read version of solar panel to the writing version."""
        warnings.warn(
            "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
            UserWarning,
            stacklevel=2,
        )
        return self.as_write()

    @classmethod
    def _update_connections(
        cls,
        instances: dict[dm.NodeId | str, SolarPanel],  # type: ignore[override]
        nodes_by_id: dict[dm.NodeId | str, DomainModel],
        edges_by_source_node: dict[dm.NodeId, list[dm.Edge | DomainRelation]],
    ) -> None:
        from ._sensor_time_series import SensorTimeSeries

        for instance in instances.values():
            if (
                isinstance(instance.efficiency, (dm.NodeId, str))
                and (efficiency := nodes_by_id.get(instance.efficiency))
                and isinstance(efficiency, SensorTimeSeries)
            ):
                instance.efficiency = efficiency
            if (
                isinstance(instance.orientation, (dm.NodeId, str))
                and (orientation := nodes_by_id.get(instance.orientation))
                and isinstance(orientation, SensorTimeSeries)
            ):
                instance.orientation = orientation

as_apply()

Convert this read version of solar panel to the writing version.

Source code in examples/wind_turbine/data_classes/_solar_panel.py
def as_apply(self) -> SolarPanelWrite:
    """Convert this read version of solar panel to the writing version."""
    warnings.warn(
        "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
        UserWarning,
        stacklevel=2,
    )
    return self.as_write()

as_write()

Convert this read version of solar panel to the writing version.

Source code in examples/wind_turbine/data_classes/_solar_panel.py
def as_write(self) -> SolarPanelWrite:
    """Convert this read version of solar panel to the writing version."""
    return SolarPanelWrite(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecordWrite(existing_version=self.data_record.version),
        capacity=self.capacity,
        description=self.description,
        efficiency=self.efficiency.as_write() if isinstance(self.efficiency, DomainModel) else self.efficiency,
        name=self.name,
        orientation=self.orientation.as_write() if isinstance(self.orientation, DomainModel) else self.orientation,
    )

SolarPanelGraphQL

Bases: GraphQLCore

This represents the reading version of solar panel, used when data is retrieved from CDF using GraphQL.

It is used when retrieving data from CDF using GraphQL.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the solar panel.

required
data_record

The data record of the solar panel node.

required
capacity

The capacity field.

required
description

Description of the instance

required
efficiency

The efficiency field.

required
name

Name of the instance

required
orientation

The orientation field.

required
Source code in examples/wind_turbine/data_classes/_solar_panel.py
class SolarPanelGraphQL(GraphQLCore):
    """This represents the reading version of solar panel, used
    when data is retrieved from CDF using GraphQL.

    It is used when retrieving data from CDF using GraphQL.

    Args:
        space: The space where the node is located.
        external_id: The external id of the solar panel.
        data_record: The data record of the solar panel node.
        capacity: The capacity field.
        description: Description of the instance
        efficiency: The efficiency field.
        name: Name of the instance
        orientation: The orientation field.
    """

    view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "SolarPanel", "1")
    capacity: Optional[float] = None
    description: Optional[str] = None
    efficiency: Optional[SensorTimeSeriesGraphQL] = Field(default=None, repr=False)
    name: Optional[str] = None
    orientation: Optional[SensorTimeSeriesGraphQL] = Field(default=None, repr=False)

    @model_validator(mode="before")
    def parse_data_record(cls, values: Any) -> Any:
        if not isinstance(values, dict):
            return values
        if "lastUpdatedTime" in values or "createdTime" in values:
            values["dataRecord"] = DataRecordGraphQL(
                created_time=values.pop("createdTime", None),
                last_updated_time=values.pop("lastUpdatedTime", None),
            )
        return values

    @field_validator("efficiency", "orientation", mode="before")
    def parse_graphql(cls, value: Any) -> Any:
        if not isinstance(value, dict):
            return value
        if "items" in value:
            return value["items"]
        return value

    # We do the ignore argument type as we let pydantic handle the type checking
    @no_type_check
    def as_read(self) -> SolarPanel:
        """Convert this GraphQL format of solar panel to the reading format."""
        if self.data_record is None:
            raise ValueError("This object cannot be converted to a read format because it lacks a data record.")
        return SolarPanel(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecord(
                version=0,
                last_updated_time=self.data_record.last_updated_time,
                created_time=self.data_record.created_time,
            ),
            capacity=self.capacity,
            description=self.description,
            efficiency=self.efficiency.as_read() if isinstance(self.efficiency, GraphQLCore) else self.efficiency,
            name=self.name,
            orientation=self.orientation.as_read() if isinstance(self.orientation, GraphQLCore) else self.orientation,
        )

    # We do the ignore argument type as we let pydantic handle the type checking
    @no_type_check
    def as_write(self) -> SolarPanelWrite:
        """Convert this GraphQL format of solar panel to the writing format."""
        return SolarPanelWrite(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecordWrite(existing_version=0),
            capacity=self.capacity,
            description=self.description,
            efficiency=self.efficiency.as_write() if isinstance(self.efficiency, GraphQLCore) else self.efficiency,
            name=self.name,
            orientation=self.orientation.as_write() if isinstance(self.orientation, GraphQLCore) else self.orientation,
        )

as_read()

Convert this GraphQL format of solar panel to the reading format.

Source code in examples/wind_turbine/data_classes/_solar_panel.py
@no_type_check
def as_read(self) -> SolarPanel:
    """Convert this GraphQL format of solar panel to the reading format."""
    if self.data_record is None:
        raise ValueError("This object cannot be converted to a read format because it lacks a data record.")
    return SolarPanel(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecord(
            version=0,
            last_updated_time=self.data_record.last_updated_time,
            created_time=self.data_record.created_time,
        ),
        capacity=self.capacity,
        description=self.description,
        efficiency=self.efficiency.as_read() if isinstance(self.efficiency, GraphQLCore) else self.efficiency,
        name=self.name,
        orientation=self.orientation.as_read() if isinstance(self.orientation, GraphQLCore) else self.orientation,
    )

as_write()

Convert this GraphQL format of solar panel to the writing format.

Source code in examples/wind_turbine/data_classes/_solar_panel.py
@no_type_check
def as_write(self) -> SolarPanelWrite:
    """Convert this GraphQL format of solar panel to the writing format."""
    return SolarPanelWrite(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecordWrite(existing_version=0),
        capacity=self.capacity,
        description=self.description,
        efficiency=self.efficiency.as_write() if isinstance(self.efficiency, GraphQLCore) else self.efficiency,
        name=self.name,
        orientation=self.orientation.as_write() if isinstance(self.orientation, GraphQLCore) else self.orientation,
    )

SolarPanelList

Bases: DomainModelList[SolarPanel]

List of solar panels in the read version.

Source code in examples/wind_turbine/data_classes/_solar_panel.py
class SolarPanelList(DomainModelList[SolarPanel]):
    """List of solar panels in the read version."""

    _INSTANCE = SolarPanel

    def as_write(self) -> SolarPanelWriteList:
        """Convert these read versions of solar panel to the writing versions."""
        return SolarPanelWriteList([node.as_write() for node in self.data])

    def as_apply(self) -> SolarPanelWriteList:
        """Convert these read versions of primitive nullable to the writing versions."""
        warnings.warn(
            "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
            UserWarning,
            stacklevel=2,
        )
        return self.as_write()

    @property
    def efficiency(self) -> SensorTimeSeriesList:
        from ._sensor_time_series import SensorTimeSeries, SensorTimeSeriesList

        return SensorTimeSeriesList(
            [item.efficiency for item in self.data if isinstance(item.efficiency, SensorTimeSeries)]
        )

    @property
    def orientation(self) -> SensorTimeSeriesList:
        from ._sensor_time_series import SensorTimeSeries, SensorTimeSeriesList

        return SensorTimeSeriesList(
            [item.orientation for item in self.data if isinstance(item.orientation, SensorTimeSeries)]
        )

as_apply()

Convert these read versions of primitive nullable to the writing versions.

Source code in examples/wind_turbine/data_classes/_solar_panel.py
def as_apply(self) -> SolarPanelWriteList:
    """Convert these read versions of primitive nullable to the writing versions."""
    warnings.warn(
        "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
        UserWarning,
        stacklevel=2,
    )
    return self.as_write()

as_write()

Convert these read versions of solar panel to the writing versions.

Source code in examples/wind_turbine/data_classes/_solar_panel.py
def as_write(self) -> SolarPanelWriteList:
    """Convert these read versions of solar panel to the writing versions."""
    return SolarPanelWriteList([node.as_write() for node in self.data])

SolarPanelWrite

Bases: GeneratingUnitWrite

This represents the writing version of solar panel.

It is used to when data is sent to CDF.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the solar panel.

required
data_record

The data record of the solar panel node.

required
capacity

The capacity field.

required
description

Description of the instance

required
efficiency

The efficiency field.

required
name

Name of the instance

required
orientation

The orientation field.

required
Source code in examples/wind_turbine/data_classes/_solar_panel.py
class SolarPanelWrite(GeneratingUnitWrite):
    """This represents the writing version of solar panel.

    It is used to when data is sent to CDF.

    Args:
        space: The space where the node is located.
        external_id: The external id of the solar panel.
        data_record: The data record of the solar panel node.
        capacity: The capacity field.
        description: Description of the instance
        efficiency: The efficiency field.
        name: Name of the instance
        orientation: The orientation field.
    """

    _view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "SolarPanel", "1")

    node_type: Union[dm.DirectRelationReference, dm.NodeId, tuple[str, str], None] = None
    efficiency: Union[SensorTimeSeriesWrite, str, dm.NodeId, None] = Field(default=None, repr=False)
    orientation: Union[SensorTimeSeriesWrite, str, dm.NodeId, None] = Field(default=None, repr=False)

    @field_validator("efficiency", "orientation", mode="before")
    def as_node_id(cls, value: Any) -> Any:
        if isinstance(value, dm.DirectRelationReference):
            return dm.NodeId(value.space, value.external_id)
        elif isinstance(value, tuple) and len(value) == 2 and all(isinstance(item, str) for item in value):
            return dm.NodeId(value[0], value[1])
        elif isinstance(value, list):
            return [cls.as_node_id(item) for item in value]
        return value

    def _to_instances_write(
        self,
        cache: set[tuple[str, str]],
        write_none: bool = False,
        allow_version_increase: bool = False,
    ) -> ResourcesWrite:
        resources = ResourcesWrite()
        if self.as_tuple_id() in cache:
            return resources

        properties: dict[str, Any] = {}

        if self.capacity is not None or write_none:
            properties["capacity"] = self.capacity

        if self.description is not None or write_none:
            properties["description"] = self.description

        if self.efficiency is not None:
            properties["efficiency"] = {
                "space": self.space if isinstance(self.efficiency, str) else self.efficiency.space,
                "externalId": self.efficiency if isinstance(self.efficiency, str) else self.efficiency.external_id,
            }

        if self.name is not None or write_none:
            properties["name"] = self.name

        if self.orientation is not None:
            properties["orientation"] = {
                "space": self.space if isinstance(self.orientation, str) else self.orientation.space,
                "externalId": self.orientation if isinstance(self.orientation, str) else self.orientation.external_id,
            }

        if properties:
            this_node = dm.NodeApply(
                space=self.space,
                external_id=self.external_id,
                existing_version=None if allow_version_increase else self.data_record.existing_version,
                type=as_direct_relation_reference(self.node_type),
                sources=[
                    dm.NodeOrEdgeData(
                        source=self._view_id,
                        properties=properties,
                    )
                ],
            )
            resources.nodes.append(this_node)
            cache.add(self.as_tuple_id())

        if isinstance(self.efficiency, DomainModelWrite):
            other_resources = self.efficiency._to_instances_write(cache)
            resources.extend(other_resources)

        if isinstance(self.orientation, DomainModelWrite):
            other_resources = self.orientation._to_instances_write(cache)
            resources.extend(other_resources)

        return resources

SolarPanelWriteList

Bases: DomainModelWriteList[SolarPanelWrite]

List of solar panels in the writing version.

Source code in examples/wind_turbine/data_classes/_solar_panel.py
class SolarPanelWriteList(DomainModelWriteList[SolarPanelWrite]):
    """List of solar panels in the writing version."""

    _INSTANCE = SolarPanelWrite

    @property
    def efficiency(self) -> SensorTimeSeriesWriteList:
        from ._sensor_time_series import SensorTimeSeriesWrite, SensorTimeSeriesWriteList

        return SensorTimeSeriesWriteList(
            [item.efficiency for item in self.data if isinstance(item.efficiency, SensorTimeSeriesWrite)]
        )

    @property
    def orientation(self) -> SensorTimeSeriesWriteList:
        from ._sensor_time_series import SensorTimeSeriesWrite, SensorTimeSeriesWriteList

        return SensorTimeSeriesWriteList(
            [item.orientation for item in self.data if isinstance(item.orientation, SensorTimeSeriesWrite)]
        )

WindTurbine

Bases: GeneratingUnit

This represents the reading version of wind turbine.

It is used to when data is retrieved from CDF.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the wind turbine.

required
data_record

The data record of the wind turbine node.

required
blades

The blade field.

required
capacity

The capacity field.

required
datasheets

The datasheet field.

required
description

Description of the instance

required
metmast

The metmast field.

required
nacelle

The nacelle field.

required
name

Name of the instance

required
power_curve

The power curve field.

required
rotor

The rotor field.

required
windfarm

The windfarm field.

required
Source code in examples/wind_turbine/data_classes/_wind_turbine.py
class WindTurbine(GeneratingUnit):
    """This represents the reading version of wind turbine.

    It is used to when data is retrieved from CDF.

    Args:
        space: The space where the node is located.
        external_id: The external id of the wind turbine.
        data_record: The data record of the wind turbine node.
        blades: The blade field.
        capacity: The capacity field.
        datasheets: The datasheet field.
        description: Description of the instance
        metmast: The metmast field.
        nacelle: The nacelle field.
        name: Name of the instance
        power_curve: The power curve field.
        rotor: The rotor field.
        windfarm: The windfarm field.
    """

    _view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "WindTurbine", "1")

    node_type: Union[dm.DirectRelationReference, None] = None
    blades: Optional[list[Union[Blade, str, dm.NodeId]]] = Field(default=None, repr=False)
    datasheets: Optional[list[Union[DataSheet, str, dm.NodeId]]] = Field(default=None, repr=False)
    metmast: Optional[list[Distance]] = Field(default=None, repr=False)
    nacelle: Union[Nacelle, str, dm.NodeId, None] = Field(default=None, repr=False)
    power_curve: Union[SequenceRead, str, None] = Field(None, alias="powerCurve")
    rotor: Union[Rotor, str, dm.NodeId, None] = Field(default=None, repr=False)
    windfarm: Optional[str] = None

    def as_write(self) -> WindTurbineWrite:
        """Convert this read version of wind turbine to the writing version."""
        return WindTurbineWrite(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecordWrite(existing_version=self.data_record.version),
            blades=[blade.as_write() if isinstance(blade, DomainModel) else blade for blade in self.blades or []],
            capacity=self.capacity,
            datasheets=[
                datasheet.as_write() if isinstance(datasheet, DomainModel) else datasheet
                for datasheet in self.datasheets or []
            ],
            description=self.description,
            metmast=[metmast.as_write() for metmast in self.metmast or []],
            nacelle=self.nacelle.as_write() if isinstance(self.nacelle, DomainModel) else self.nacelle,
            name=self.name,
            power_curve=(
                self.power_curve.as_write() if isinstance(self.power_curve, CogniteSequence) else self.power_curve
            ),
            rotor=self.rotor.as_write() if isinstance(self.rotor, DomainModel) else self.rotor,
            windfarm=self.windfarm,
        )

    def as_apply(self) -> WindTurbineWrite:
        """Convert this read version of wind turbine to the writing version."""
        warnings.warn(
            "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
            UserWarning,
            stacklevel=2,
        )
        return self.as_write()

    @classmethod
    def _update_connections(
        cls,
        instances: dict[dm.NodeId | str, WindTurbine],  # type: ignore[override]
        nodes_by_id: dict[dm.NodeId | str, DomainModel],
        edges_by_source_node: dict[dm.NodeId, list[dm.Edge | DomainRelation]],
    ) -> None:
        from ._blade import Blade
        from ._data_sheet import DataSheet
        from ._distance import Distance
        from ._nacelle import Nacelle
        from ._rotor import Rotor

        for instance in instances.values():
            if (
                isinstance(instance.nacelle, (dm.NodeId, str))
                and (nacelle := nodes_by_id.get(instance.nacelle))
                and isinstance(nacelle, Nacelle)
            ):
                instance.nacelle = nacelle
            if (
                isinstance(instance.rotor, (dm.NodeId, str))
                and (rotor := nodes_by_id.get(instance.rotor))
                and isinstance(rotor, Rotor)
            ):
                instance.rotor = rotor
            if instance.blades:
                new_blades: list[Blade | str | dm.NodeId] = []
                for relation in instance.blades:
                    if isinstance(relation, Blade):
                        new_blades.append(relation)
                    elif (other := nodes_by_id.get(relation)) and isinstance(other, Blade):
                        new_blades.append(other)
                    else:
                        new_blades.append(relation)
                instance.blades = new_blades
            if instance.datasheets:
                new_datasheets: list[DataSheet | str | dm.NodeId] = []
                for relation in instance.datasheets:
                    if isinstance(relation, DataSheet):
                        new_datasheets.append(relation)
                    elif (other := nodes_by_id.get(relation)) and isinstance(other, DataSheet):
                        new_datasheets.append(other)
                    else:
                        new_datasheets.append(relation)
                instance.datasheets = new_datasheets
            if edges := edges_by_source_node.get(instance.as_id()):
                metmast: list[Distance] = []
                for edge in edges:
                    value: DomainModel | DomainRelation | str | dm.NodeId
                    if isinstance(edge, DomainRelation):
                        value = edge
                    else:
                        other_end: dm.DirectRelationReference = (
                            edge.end_node
                            if edge.start_node.space == instance.space
                            and edge.start_node.external_id == instance.external_id
                            else edge.start_node
                        )
                        destination: dm.NodeId | str = (
                            as_node_id(other_end)
                            if other_end.space != DEFAULT_INSTANCE_SPACE
                            else other_end.external_id
                        )
                        if destination in nodes_by_id:
                            value = nodes_by_id[destination]
                        else:
                            value = destination
                    edge_type = edge.edge_type if isinstance(edge, DomainRelation) else edge.type

                    if edge_type == dm.DirectRelationReference("sp_pygen_power_enterprise", "Distance") and isinstance(
                        value, Distance
                    ):
                        metmast.append(value)
                        if end_node := nodes_by_id.get(as_pygen_node_id(value.end_node)):
                            value.end_node = end_node  # type: ignore[assignment]

                instance.metmast = metmast

as_apply()

Convert this read version of wind turbine to the writing version.

Source code in examples/wind_turbine/data_classes/_wind_turbine.py
def as_apply(self) -> WindTurbineWrite:
    """Convert this read version of wind turbine to the writing version."""
    warnings.warn(
        "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
        UserWarning,
        stacklevel=2,
    )
    return self.as_write()

as_write()

Convert this read version of wind turbine to the writing version.

Source code in examples/wind_turbine/data_classes/_wind_turbine.py
def as_write(self) -> WindTurbineWrite:
    """Convert this read version of wind turbine to the writing version."""
    return WindTurbineWrite(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecordWrite(existing_version=self.data_record.version),
        blades=[blade.as_write() if isinstance(blade, DomainModel) else blade for blade in self.blades or []],
        capacity=self.capacity,
        datasheets=[
            datasheet.as_write() if isinstance(datasheet, DomainModel) else datasheet
            for datasheet in self.datasheets or []
        ],
        description=self.description,
        metmast=[metmast.as_write() for metmast in self.metmast or []],
        nacelle=self.nacelle.as_write() if isinstance(self.nacelle, DomainModel) else self.nacelle,
        name=self.name,
        power_curve=(
            self.power_curve.as_write() if isinstance(self.power_curve, CogniteSequence) else self.power_curve
        ),
        rotor=self.rotor.as_write() if isinstance(self.rotor, DomainModel) else self.rotor,
        windfarm=self.windfarm,
    )

WindTurbineGraphQL

Bases: GraphQLCore

This represents the reading version of wind turbine, used when data is retrieved from CDF using GraphQL.

It is used when retrieving data from CDF using GraphQL.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the wind turbine.

required
data_record

The data record of the wind turbine node.

required
blades

The blade field.

required
capacity

The capacity field.

required
datasheets

The datasheet field.

required
description

Description of the instance

required
metmast

The metmast field.

required
nacelle

The nacelle field.

required
name

Name of the instance

required
power_curve

The power curve field.

required
rotor

The rotor field.

required
windfarm

The windfarm field.

required
Source code in examples/wind_turbine/data_classes/_wind_turbine.py
class WindTurbineGraphQL(GraphQLCore):
    """This represents the reading version of wind turbine, used
    when data is retrieved from CDF using GraphQL.

    It is used when retrieving data from CDF using GraphQL.

    Args:
        space: The space where the node is located.
        external_id: The external id of the wind turbine.
        data_record: The data record of the wind turbine node.
        blades: The blade field.
        capacity: The capacity field.
        datasheets: The datasheet field.
        description: Description of the instance
        metmast: The metmast field.
        nacelle: The nacelle field.
        name: Name of the instance
        power_curve: The power curve field.
        rotor: The rotor field.
        windfarm: The windfarm field.
    """

    view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "WindTurbine", "1")
    blades: Optional[list[BladeGraphQL]] = Field(default=None, repr=False)
    capacity: Optional[float] = None
    datasheets: Optional[list[DataSheetGraphQL]] = Field(default=None, repr=False)
    description: Optional[str] = None
    metmast: Optional[list[DistanceGraphQL]] = Field(default=None, repr=False)
    nacelle: Optional[NacelleGraphQL] = Field(default=None, repr=False)
    name: Optional[str] = None
    power_curve: Optional[SequenceGraphQL] = Field(None, alias="powerCurve")
    rotor: Optional[RotorGraphQL] = Field(default=None, repr=False)
    windfarm: Optional[str] = None

    @model_validator(mode="before")
    def parse_data_record(cls, values: Any) -> Any:
        if not isinstance(values, dict):
            return values
        if "lastUpdatedTime" in values or "createdTime" in values:
            values["dataRecord"] = DataRecordGraphQL(
                created_time=values.pop("createdTime", None),
                last_updated_time=values.pop("lastUpdatedTime", None),
            )
        return values

    @field_validator("blades", "datasheets", "metmast", "nacelle", "rotor", mode="before")
    def parse_graphql(cls, value: Any) -> Any:
        if not isinstance(value, dict):
            return value
        if "items" in value:
            return value["items"]
        return value

    # We do the ignore argument type as we let pydantic handle the type checking
    @no_type_check
    def as_read(self) -> WindTurbine:
        """Convert this GraphQL format of wind turbine to the reading format."""
        if self.data_record is None:
            raise ValueError("This object cannot be converted to a read format because it lacks a data record.")
        return WindTurbine(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecord(
                version=0,
                last_updated_time=self.data_record.last_updated_time,
                created_time=self.data_record.created_time,
            ),
            blades=[blade.as_read() for blade in self.blades or []],
            capacity=self.capacity,
            datasheets=[datasheet.as_read() for datasheet in self.datasheets or []],
            description=self.description,
            metmast=[metmast.as_read() for metmast in self.metmast or []],
            nacelle=self.nacelle.as_read() if isinstance(self.nacelle, GraphQLCore) else self.nacelle,
            name=self.name,
            power_curve=self.power_curve.as_read() if self.power_curve else None,
            rotor=self.rotor.as_read() if isinstance(self.rotor, GraphQLCore) else self.rotor,
            windfarm=self.windfarm,
        )

    # We do the ignore argument type as we let pydantic handle the type checking
    @no_type_check
    def as_write(self) -> WindTurbineWrite:
        """Convert this GraphQL format of wind turbine to the writing format."""
        return WindTurbineWrite(
            space=self.space,
            external_id=self.external_id,
            data_record=DataRecordWrite(existing_version=0),
            blades=[blade.as_write() for blade in self.blades or []],
            capacity=self.capacity,
            datasheets=[datasheet.as_write() for datasheet in self.datasheets or []],
            description=self.description,
            metmast=[metmast.as_write() for metmast in self.metmast or []],
            nacelle=self.nacelle.as_write() if isinstance(self.nacelle, GraphQLCore) else self.nacelle,
            name=self.name,
            power_curve=self.power_curve.as_write() if self.power_curve else None,
            rotor=self.rotor.as_write() if isinstance(self.rotor, GraphQLCore) else self.rotor,
            windfarm=self.windfarm,
        )

as_read()

Convert this GraphQL format of wind turbine to the reading format.

Source code in examples/wind_turbine/data_classes/_wind_turbine.py
@no_type_check
def as_read(self) -> WindTurbine:
    """Convert this GraphQL format of wind turbine to the reading format."""
    if self.data_record is None:
        raise ValueError("This object cannot be converted to a read format because it lacks a data record.")
    return WindTurbine(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecord(
            version=0,
            last_updated_time=self.data_record.last_updated_time,
            created_time=self.data_record.created_time,
        ),
        blades=[blade.as_read() for blade in self.blades or []],
        capacity=self.capacity,
        datasheets=[datasheet.as_read() for datasheet in self.datasheets or []],
        description=self.description,
        metmast=[metmast.as_read() for metmast in self.metmast or []],
        nacelle=self.nacelle.as_read() if isinstance(self.nacelle, GraphQLCore) else self.nacelle,
        name=self.name,
        power_curve=self.power_curve.as_read() if self.power_curve else None,
        rotor=self.rotor.as_read() if isinstance(self.rotor, GraphQLCore) else self.rotor,
        windfarm=self.windfarm,
    )

as_write()

Convert this GraphQL format of wind turbine to the writing format.

Source code in examples/wind_turbine/data_classes/_wind_turbine.py
@no_type_check
def as_write(self) -> WindTurbineWrite:
    """Convert this GraphQL format of wind turbine to the writing format."""
    return WindTurbineWrite(
        space=self.space,
        external_id=self.external_id,
        data_record=DataRecordWrite(existing_version=0),
        blades=[blade.as_write() for blade in self.blades or []],
        capacity=self.capacity,
        datasheets=[datasheet.as_write() for datasheet in self.datasheets or []],
        description=self.description,
        metmast=[metmast.as_write() for metmast in self.metmast or []],
        nacelle=self.nacelle.as_write() if isinstance(self.nacelle, GraphQLCore) else self.nacelle,
        name=self.name,
        power_curve=self.power_curve.as_write() if self.power_curve else None,
        rotor=self.rotor.as_write() if isinstance(self.rotor, GraphQLCore) else self.rotor,
        windfarm=self.windfarm,
    )

WindTurbineList

Bases: DomainModelList[WindTurbine]

List of wind turbines in the read version.

Source code in examples/wind_turbine/data_classes/_wind_turbine.py
class WindTurbineList(DomainModelList[WindTurbine]):
    """List of wind turbines in the read version."""

    _INSTANCE = WindTurbine

    def as_write(self) -> WindTurbineWriteList:
        """Convert these read versions of wind turbine to the writing versions."""
        return WindTurbineWriteList([node.as_write() for node in self.data])

    def as_apply(self) -> WindTurbineWriteList:
        """Convert these read versions of primitive nullable to the writing versions."""
        warnings.warn(
            "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
            UserWarning,
            stacklevel=2,
        )
        return self.as_write()

    @property
    def blades(self) -> BladeList:
        from ._blade import Blade, BladeList

        return BladeList([item for items in self.data for item in items.blades or [] if isinstance(item, Blade)])

    @property
    def datasheets(self) -> DataSheetList:
        from ._data_sheet import DataSheet, DataSheetList

        return DataSheetList(
            [item for items in self.data for item in items.datasheets or [] if isinstance(item, DataSheet)]
        )

    @property
    def metmast(self) -> DistanceList:
        from ._distance import Distance, DistanceList

        return DistanceList([item for items in self.data for item in items.metmast or [] if isinstance(item, Distance)])

    @property
    def nacelle(self) -> NacelleList:
        from ._nacelle import Nacelle, NacelleList

        return NacelleList([item.nacelle for item in self.data if isinstance(item.nacelle, Nacelle)])

    @property
    def rotor(self) -> RotorList:
        from ._rotor import Rotor, RotorList

        return RotorList([item.rotor for item in self.data if isinstance(item.rotor, Rotor)])

as_apply()

Convert these read versions of primitive nullable to the writing versions.

Source code in examples/wind_turbine/data_classes/_wind_turbine.py
def as_apply(self) -> WindTurbineWriteList:
    """Convert these read versions of primitive nullable to the writing versions."""
    warnings.warn(
        "as_apply is deprecated and will be removed in v1.0. Use as_write instead.",
        UserWarning,
        stacklevel=2,
    )
    return self.as_write()

as_write()

Convert these read versions of wind turbine to the writing versions.

Source code in examples/wind_turbine/data_classes/_wind_turbine.py
def as_write(self) -> WindTurbineWriteList:
    """Convert these read versions of wind turbine to the writing versions."""
    return WindTurbineWriteList([node.as_write() for node in self.data])

WindTurbineWrite

Bases: GeneratingUnitWrite

This represents the writing version of wind turbine.

It is used to when data is sent to CDF.

Parameters:

Name Type Description Default
space

The space where the node is located.

required
external_id

The external id of the wind turbine.

required
data_record

The data record of the wind turbine node.

required
blades

The blade field.

required
capacity

The capacity field.

required
datasheets

The datasheet field.

required
description

Description of the instance

required
metmast

The metmast field.

required
nacelle

The nacelle field.

required
name

Name of the instance

required
power_curve

The power curve field.

required
rotor

The rotor field.

required
windfarm

The windfarm field.

required
Source code in examples/wind_turbine/data_classes/_wind_turbine.py
class WindTurbineWrite(GeneratingUnitWrite):
    """This represents the writing version of wind turbine.

    It is used to when data is sent to CDF.

    Args:
        space: The space where the node is located.
        external_id: The external id of the wind turbine.
        data_record: The data record of the wind turbine node.
        blades: The blade field.
        capacity: The capacity field.
        datasheets: The datasheet field.
        description: Description of the instance
        metmast: The metmast field.
        nacelle: The nacelle field.
        name: Name of the instance
        power_curve: The power curve field.
        rotor: The rotor field.
        windfarm: The windfarm field.
    """

    _view_id: ClassVar[dm.ViewId] = dm.ViewId("sp_pygen_power", "WindTurbine", "1")

    node_type: Union[dm.DirectRelationReference, dm.NodeId, tuple[str, str], None] = None
    blades: Optional[list[Union[BladeWrite, str, dm.NodeId]]] = Field(default=None, repr=False)
    datasheets: Optional[list[Union[DataSheetWrite, str, dm.NodeId]]] = Field(default=None, repr=False)
    metmast: Optional[list[DistanceWrite]] = Field(default=None, repr=False)
    nacelle: Union[NacelleWrite, str, dm.NodeId, None] = Field(default=None, repr=False)
    power_curve: Union[SequenceWrite, str, None] = Field(None, alias="powerCurve")
    rotor: Union[RotorWrite, str, dm.NodeId, None] = Field(default=None, repr=False)
    windfarm: Optional[str] = None

    @field_validator("blades", "datasheets", "metmast", "nacelle", "rotor", mode="before")
    def as_node_id(cls, value: Any) -> Any:
        if isinstance(value, dm.DirectRelationReference):
            return dm.NodeId(value.space, value.external_id)
        elif isinstance(value, tuple) and len(value) == 2 and all(isinstance(item, str) for item in value):
            return dm.NodeId(value[0], value[1])
        elif isinstance(value, list):
            return [cls.as_node_id(item) for item in value]
        return value

    def _to_instances_write(
        self,
        cache: set[tuple[str, str]],
        write_none: bool = False,
        allow_version_increase: bool = False,
    ) -> ResourcesWrite:
        resources = ResourcesWrite()
        if self.as_tuple_id() in cache:
            return resources

        properties: dict[str, Any] = {}

        if self.blades is not None:
            properties["blades"] = [
                {
                    "space": self.space if isinstance(blade, str) else blade.space,
                    "externalId": blade if isinstance(blade, str) else blade.external_id,
                }
                for blade in self.blades or []
            ]

        if self.capacity is not None or write_none:
            properties["capacity"] = self.capacity

        if self.datasheets is not None:
            properties["datasheets"] = [
                {
                    "space": self.space if isinstance(datasheet, str) else datasheet.space,
                    "externalId": datasheet if isinstance(datasheet, str) else datasheet.external_id,
                }
                for datasheet in self.datasheets or []
            ]

        if self.description is not None or write_none:
            properties["description"] = self.description

        if self.nacelle is not None:
            properties["nacelle"] = {
                "space": self.space if isinstance(self.nacelle, str) else self.nacelle.space,
                "externalId": self.nacelle if isinstance(self.nacelle, str) else self.nacelle.external_id,
            }

        if self.name is not None or write_none:
            properties["name"] = self.name

        if self.power_curve is not None or write_none:
            properties["powerCurve"] = (
                self.power_curve
                if isinstance(self.power_curve, str) or self.power_curve is None
                else self.power_curve.external_id
            )

        if self.rotor is not None:
            properties["rotor"] = {
                "space": self.space if isinstance(self.rotor, str) else self.rotor.space,
                "externalId": self.rotor if isinstance(self.rotor, str) else self.rotor.external_id,
            }

        if self.windfarm is not None or write_none:
            properties["windfarm"] = self.windfarm

        if properties:
            this_node = dm.NodeApply(
                space=self.space,
                external_id=self.external_id,
                existing_version=None if allow_version_increase else self.data_record.existing_version,
                type=as_direct_relation_reference(self.node_type),
                sources=[
                    dm.NodeOrEdgeData(
                        source=self._view_id,
                        properties=properties,
                    )
                ],
            )
            resources.nodes.append(this_node)
            cache.add(self.as_tuple_id())

        for metmast in self.metmast or []:
            if isinstance(metmast, DomainRelationWrite):
                other_resources = metmast._to_instances_write(
                    cache,
                    self,
                    dm.DirectRelationReference("sp_pygen_power_enterprise", "Distance"),
                )
                resources.extend(other_resources)

        if isinstance(self.nacelle, DomainModelWrite):
            other_resources = self.nacelle._to_instances_write(cache)
            resources.extend(other_resources)

        if isinstance(self.rotor, DomainModelWrite):
            other_resources = self.rotor._to_instances_write(cache)
            resources.extend(other_resources)

        for blade in self.blades or []:
            if isinstance(blade, DomainModelWrite):
                other_resources = blade._to_instances_write(cache)
                resources.extend(other_resources)

        for datasheet in self.datasheets or []:
            if isinstance(datasheet, DomainModelWrite):
                other_resources = datasheet._to_instances_write(cache)
                resources.extend(other_resources)

        if isinstance(self.power_curve, CogniteSequenceWrite):
            resources.sequences.append(self.power_curve)

        return resources

WindTurbineWriteList

Bases: DomainModelWriteList[WindTurbineWrite]

List of wind turbines in the writing version.

Source code in examples/wind_turbine/data_classes/_wind_turbine.py
class WindTurbineWriteList(DomainModelWriteList[WindTurbineWrite]):
    """List of wind turbines in the writing version."""

    _INSTANCE = WindTurbineWrite

    @property
    def blades(self) -> BladeWriteList:
        from ._blade import BladeWrite, BladeWriteList

        return BladeWriteList(
            [item for items in self.data for item in items.blades or [] if isinstance(item, BladeWrite)]
        )

    @property
    def datasheets(self) -> DataSheetWriteList:
        from ._data_sheet import DataSheetWrite, DataSheetWriteList

        return DataSheetWriteList(
            [item for items in self.data for item in items.datasheets or [] if isinstance(item, DataSheetWrite)]
        )

    @property
    def metmast(self) -> DistanceWriteList:
        from ._distance import DistanceWrite, DistanceWriteList

        return DistanceWriteList(
            [item for items in self.data for item in items.metmast or [] if isinstance(item, DistanceWrite)]
        )

    @property
    def nacelle(self) -> NacelleWriteList:
        from ._nacelle import NacelleWrite, NacelleWriteList

        return NacelleWriteList([item.nacelle for item in self.data if isinstance(item.nacelle, NacelleWrite)])

    @property
    def rotor(self) -> RotorWriteList:
        from ._rotor import RotorWrite, RotorWriteList

        return RotorWriteList([item.rotor for item in self.data if isinstance(item.rotor, RotorWrite)])