Function data¶
Defines models for cost functions
- class infrasys.function_data.XYCoords(x: float, y: float)¶
Named tuple used to define (x,y) coordinates.
Create new instance of XYCoords(x, y)
- x: float¶
Alias for field number 0
- y: float¶
Alias for field number 1
- pydantic model infrasys.function_data.FunctionData¶
BaseClass of FunctionData
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
Show JSON schema
{ "title": "FunctionData", "description": "BaseClass of FunctionData", "type": "object", "properties": { "uuid": { "format": "uuid", "title": "Uuid", "type": "string" } }, "additionalProperties": false }
- Config:
str_strip_whitespace: bool = True
validate_assignment: bool = True
validate_default: bool = True
extra: str = forbid
use_enum_values: bool = False
arbitrary_types_allowed: bool = True
populate_by_name: bool = True
- Fields:
- pydantic model infrasys.function_data.LinearFunctionData¶
Data representation for linear cost function.
Used to represent linear cost functions of the form
\[f(x) = mx + c,\]where \(m\) is the proportional term and \(c\) is the constant term.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
Show JSON schema
{ "title": "LinearFunctionData", "description": "Data representation for linear cost function.\n\nUsed to represent linear cost functions of the form\n\n.. math:: f(x) = mx + c,\n\nwhere :math:`m` is the proportional term and :math:`c` is the constant term.", "type": "object", "properties": { "uuid": { "format": "uuid", "title": "Uuid", "type": "string" }, "proportional_term": { "description": "the proportional term in the represented function.", "title": "Proportional Term", "type": "number" }, "constant_term": { "description": "the constant term in the represented function.", "title": "Constant Term", "type": "number" } }, "additionalProperties": false, "required": [ "proportional_term", "constant_term" ] }
- Config:
str_strip_whitespace: bool = True
validate_assignment: bool = True
validate_default: bool = True
extra: str = forbid
use_enum_values: bool = False
arbitrary_types_allowed: bool = True
populate_by_name: bool = True
- Fields:
- field constant_term: Annotated[float, FieldInfo(annotation=NoneType, required=True, description='the constant term in the represented function.')] [Required]¶
the constant term in the represented function.
- field proportional_term: Annotated[Quantity | float, FieldInfo(annotation=NoneType, required=True, description='the proportional term in the represented function.')] [Required]¶
the proportional term in the represented function.
- pydantic model infrasys.function_data.QuadraticFunctionData¶
Data representation for quadratic cost function.
Used to represent quadratic of cost functions of the form
\[f(x) = ax^2 + bx + c,\]where \(a\) is the quadratic term, \(b\) is the proportional term and \(c\) is the constant term.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
Show JSON schema
{ "title": "QuadraticFunctionData", "description": "Data representation for quadratic cost function.\n\nUsed to represent quadratic of cost functions of the form\n\n.. math:: f(x) = ax^2 + bx + c,\n\nwhere :math:`a` is the quadratic term, :math:`b` is the proportional term and :math:`c` is the\nconstant term.", "type": "object", "properties": { "uuid": { "format": "uuid", "title": "Uuid", "type": "string" }, "quadratic_term": { "description": "the quadratic term in the represented function.", "title": "Quadratic Term", "type": "number" }, "proportional_term": { "description": "the proportional term in the represented function.", "title": "Proportional Term", "type": "number" }, "constant_term": { "description": "the constant term in the represented function.", "title": "Constant Term", "type": "number" } }, "additionalProperties": false, "required": [ "quadratic_term", "proportional_term", "constant_term" ] }
- Config:
str_strip_whitespace: bool = True
validate_assignment: bool = True
validate_default: bool = True
extra: str = forbid
use_enum_values: bool = False
arbitrary_types_allowed: bool = True
populate_by_name: bool = True
- Fields:
- field constant_term: Annotated[float, FieldInfo(annotation=NoneType, required=True, description='the constant term in the represented function.')] [Required]¶
the constant term in the represented function.
- field proportional_term: Annotated[float, FieldInfo(annotation=NoneType, required=True, description='the proportional term in the represented function.')] [Required]¶
the proportional term in the represented function.
- field quadratic_term: Annotated[float, FieldInfo(annotation=NoneType, required=True, description='the quadratic term in the represented function.')] [Required]¶
the quadratic term in the represented function.
- infrasys.function_data.validate_piecewise_linear_x(points: List[XYCoords]) List[XYCoords] ¶
Validates the x data for PiecewiseLinearData class
X data is checked to ensure there is at least two values of x, which is the minimum required to generate a cost curve, and is given in ascending order (e.g. [1, 2, 3], not [1, 3, 2]).
- infrasys.function_data.validate_piecewise_step_x(x_coords: List[float]) List[float] ¶
Validates the x data for PiecewiseStepData class
X data is checked to ensure there is at least two values of x, which is the minimum required to generate a cost curve, and is given in ascending order (e.g. [1, 2, 3], not [1, 3, 2]).
- Parameters:
x_coords (List[float]) – List of x data for cost function.
- Returns:
x_coords – List of x data for cost function after successful validation.
- Return type:
List[float]
- pydantic model infrasys.function_data.PiecewiseLinearData¶
Data representation for piecewise linear cost function.
Used to represent linear data as a series of points: two points define one segment, three points define two segments, etc. The curve starts at the first point given, not the origin. Principally used for the representation of cost functions where the points store quantities (x, y), such as (MW, USD/h).
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
Show JSON schema
{ "title": "PiecewiseLinearData", "description": "Data representation for piecewise linear cost function.\n\nUsed to represent linear data as a series of points: two points define one segment, three\npoints define two segments, etc. The curve starts at the first point given, not the origin.\nPrincipally used for the representation of cost functions where the points store quantities (x,\ny), such as (MW, USD/h).", "type": "object", "properties": { "uuid": { "format": "uuid", "title": "Uuid", "type": "string" }, "points": { "description": "list of (x,y) points that define the function.", "items": { "$ref": "#/$defs/XYCoords" }, "title": "Points", "type": "array" } }, "$defs": { "XYCoords": { "maxItems": 2, "minItems": 2, "prefixItems": [ { "title": "X", "type": "number" }, { "title": "Y", "type": "number" } ], "type": "array" } }, "additionalProperties": false, "required": [ "points" ] }
- Config:
str_strip_whitespace: bool = True
validate_assignment: bool = True
validate_default: bool = True
extra: str = forbid
use_enum_values: bool = False
arbitrary_types_allowed: bool = True
populate_by_name: bool = True
- Fields:
- field points: Annotated[List[XYCoords], AfterValidator(func=validate_piecewise_linear_x), FieldInfo(annotation=NoneType, required=True, description='list of (x,y) points that define the function.')] [Required]¶
list of (x,y) points that define the function.
- Constraints:
func = <function validate_piecewise_linear_x at 0x7fc7dd4a9120>
- pydantic model infrasys.function_data.PiecewiseStepData¶
Data representation for piecewise step cost function.
Used to represent a step function as a series of endpoint x-coordinates and segment y-coordinates: two x-coordinates and one y-coordinate defines a single segment, three x-coordinates and two y-coordinates define two segments, etc.
This can be useful to represent the derivative of a
PiecewiseLinearData
, where the y-coordinates of this step function represent the slopes of that piecewise linear function. Principally used for the representation of cost functions where the points store quantities (x, \(dy/dx\)), such as (MW, USD/MWh).Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
Show JSON schema
{ "title": "PiecewiseStepData", "description": "Data representation for piecewise step cost function.\n\nUsed to represent a step function as a series of endpoint x-coordinates and segment\ny-coordinates: two x-coordinates and one y-coordinate defines a single segment, three\nx-coordinates and two y-coordinates define two segments, etc.\n\nThis can be useful to represent the derivative of a :class:`PiecewiseLinearData`, where the\ny-coordinates of this step function represent the slopes of that piecewise linear function.\nPrincipally used for the representation of cost functions where the points store quantities (x,\n:math:`dy/dx`), such as (MW, USD/MWh).", "type": "object", "properties": { "uuid": { "format": "uuid", "title": "Uuid", "type": "string" }, "x_coords": { "description": "the x-coordinates of the endpoints of the segments.", "items": { "type": "number" }, "title": "X Coords", "type": "array" }, "y_coords": { "description": "The y-coordinates of the segments: `y_coords[1]` is the y-value between `x_coords[0]` and `x_coords[1]`, etc. Must have one fewer elements than `x_coords`.", "items": { "type": "number" }, "title": "Y Coords", "type": "array" } }, "additionalProperties": false, "required": [ "x_coords", "y_coords" ] }
- Config:
str_strip_whitespace: bool = True
validate_assignment: bool = True
validate_default: bool = True
extra: str = forbid
use_enum_values: bool = False
arbitrary_types_allowed: bool = True
populate_by_name: bool = True
- Fields:
- Validators:
validate_piecewise_xy
»all fields
- field x_coords: Annotated[List[float], FieldInfo(annotation=NoneType, required=True, description='the x-coordinates of the endpoints of the segments.')] [Required]¶
the x-coordinates of the endpoints of the segments.
- Validated by:
- field y_coords: Annotated[List[float], FieldInfo(annotation=NoneType, required=True, description='The y-coordinates of the segments: `y_coords[1]` is the y-value between `x_coords[0]` and `x_coords[1]`, etc. Must have one fewer elements than `x_coords`.')] [Required]¶
The y-coordinates of the segments: y_coords[1] is the y-value between x_coords[0] and x_coords[1], etc. Must have one fewer elements than x_coords.
- Validated by:
- validator validate_piecewise_xy » all fields¶
Method to validate the x and y data for PiecewiseStepData class
Model validator used to validate given data for the
PiecewiseStepData
. Calls validate_piecewise_step_x to check if x_coords is valid, then checks if the length of y_coords is exactly one less than x_coords, which is necessary to define the cost functions correctly.