Skip to content

transform_model

Parent model for the transforms.

TransformModel #

Bases: BaseModel

Pydantic model used to represent a transformation.

The model_dump method is overwritten to exclude the name field.

Attributes:

Name Type Description
name str

Name of the transformation.

Source code in src/careamics/config/transformations/transform_model.py
class TransformModel(BaseModel):
    """
    Pydantic model used to represent a transformation.

    The `model_dump` method is overwritten to exclude the name field.

    Attributes
    ----------
    name : str
        Name of the transformation.
    """

    model_config = ConfigDict(
        extra="forbid",  # throw errors if the parameters are not properly passed
    )

    name: str

    def model_dump(self, **kwargs) -> Dict[str, Any]:
        """
        Return the model as a dictionary.

        Parameters
        ----------
        **kwargs
            Pydantic BaseMode model_dump method keyword arguments.

        Returns
        -------
        Dict[str, Any]
            Dictionary representation of the model.
        """
        model_dict = super().model_dump(**kwargs)

        # remove the name field
        model_dict.pop("name")

        return model_dict

model_dump(**kwargs) #

Return the model as a dictionary.

Parameters:

Name Type Description Default
**kwargs

Pydantic BaseMode model_dump method keyword arguments.

{}

Returns:

Type Description
Dict[str, Any]

Dictionary representation of the model.

Source code in src/careamics/config/transformations/transform_model.py
def model_dump(self, **kwargs) -> Dict[str, Any]:
    """
    Return the model as a dictionary.

    Parameters
    ----------
    **kwargs
        Pydantic BaseMode model_dump method keyword arguments.

    Returns
    -------
    Dict[str, Any]
        Dictionary representation of the model.
    """
    model_dict = super().model_dump(**kwargs)

    # remove the name field
    model_dict.pop("name")

    return model_dict