linopy.constraints.Constraint

linopy.constraints.Constraint#

class linopy.constraints.Constraint(data, model, name='', skip_broadcast=False)#

Constraint backed by an xarray Dataset.

Supports setters, xarray operations via conwrap, and from_rule construction.

__init__(data, model, name='', skip_broadcast=False)#

Methods

__init__(data, model[, name, skip_broadcast])

active_labels()

Active constraint labels in build order, without building the CSR.

assign([variables])

Wrapper for the xarray Dataset.assign function for linopy.Constraint

assign_attrs(*args, **kwargs)

Wrapper for the xarray DataWithCoords.assign_attrs function for linopy.Constraint

assign_coords([coords])

Wrapper for the xarray DataWithCoords.assign_coords function for linopy.Constraint

assign_multiindex_safe(**fields)

Wrapper for the xarray assign_multiindex_safe function for linopy.Constraint

broadcast_like(other[, exclude])

Wrapper for the xarray Dataset.broadcast_like function for linopy.Constraint

chunk([chunks, name_prefix, token, lock, ...])

Wrapper for the xarray Dataset.chunk function for linopy.Constraint

drop_isel([indexers])

Wrapper for the xarray Dataset.drop_isel function for linopy.Constraint

drop_sel([labels, errors])

Wrapper for the xarray Dataset.drop_sel function for linopy.Constraint

expand_dims([dim, axis, ...])

Wrapper for the xarray Dataset.expand_dims function for linopy.Constraint

freeze()

Convert to an immutable Constraint.

from_rule(model, rule, coords)

Create a constraint from a rule and a set of coordinates.

has_variable(variable)

Check if the constraint references any of the given variable labels.

isel([indexers, drop, missing_dims])

Wrapper for the xarray Dataset.isel function for linopy.Constraint

iterate_slices([slice_size, slice_dims])

Generate slices of an xarray Dataset or DataArray with a specified soft maximum size.

mutable()

Return self (already mutable).

print([display_max_rows, display_max_terms])

Print the linear expression.

reindex([indexers, method, tolerance, copy, ...])

Wrapper for the xarray Dataset.reindex function for linopy.Constraint with default arguments: {'fill_value': {'labels': -1, 'rhs': nan, 'coeffs': 0, 'vars': -1, 'sign': '='}}

reindex_like(other[, method, tolerance, ...])

Wrapper for the xarray Dataset.reindex_like function for linopy.Constraint with default arguments: {'fill_value': {'labels': -1, 'rhs': nan, 'coeffs': 0, 'vars': -1, 'sign': '='}}

rename([name_dict])

Wrapper for the xarray Dataset.rename function for linopy.Constraint

rename_dims([dims_dict])

Wrapper for the xarray Dataset.rename_dims function for linopy.Constraint

roll([shifts, roll_coords])

Wrapper for the xarray Dataset.roll function for linopy.Constraint

sanitize_infinities()

Mask out rows with invalid infinite RHS values.

sanitize_missings()

Mask out rows where all variables are missing (-1).

sanitize_zeros()

Remove terms with zero or near-zero coefficients.

sel([indexers, method, tolerance, drop])

Wrapper for the xarray Dataset.sel function for linopy.Constraint

set_index([indexes, append])

Wrapper for the xarray Dataset.set_index function for linopy.Constraint

shift([shifts, fill_value])

Wrapper for the xarray Dataset.shift function for linopy.Constraint

stack([dim, create_index, index_cls])

Wrapper for the xarray Dataset.stack function for linopy.Constraint

swap_dims([dims_dict])

Wrapper for the xarray Dataset.swap_dims function for linopy.Constraint

to_matrix(label_index)

Construct a CSR matrix for this constraint.

to_matrix_with_rhs(label_index)

Return (csr, con_labels, b, sense) in one pass.

to_netcdf_ds()

Return a Dataset representation suitable for netcdf serialization.

to_polars()

Convert the constraint to a polars DataFrame.

unstack([dim, fill_value, sparse])

Wrapper for the xarray Dataset.unstack function for linopy.Constraint

Attributes

attrs

Get the attributes of the constraint.

coeffs

Get the LHS coefficients DataArray.

coord_dims

coord_names

Get the names of the coordinates.

coord_sizes

coords

Get the coordinates of the constraint.

data

Get the underlying xarray Dataset representation.

dims

Get the dimensions of the constraint.

dual

Get the dual values DataArray.

flat

Convert the constraint to a pandas DataFrame.

indexes

Get the indexes of the constraint.

is_assigned

Whether the constraint has been assigned labels by the model.

labels

Get the labels DataArray.

lhs

Get the left-hand-side linear expression of the constraint.

loc

mask

Get the mask of the constraint.

model

Get the model reference.

name

Get the constraint name.

ncons

Get the number of active constraints (non-masked, with at least one valid variable).

ndim

Get the number of dimensions of the constraint.

nterm

Get the number of terms in the constraint.

range

Return the range of the constraint.

rhs

Get the RHS DataArray.

shape

Get the shape of the constraint.

sign

Get the constraint sign DataArray.

size

Get the size of the constraint.

sizes

Get the sizes of the constraint.

term_dim

Return the term dimension of the constraint.

type

Get the type string of the constraint.

vars

Get the LHS variable labels DataArray.