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.
Convert the constraint to a polars DataFrame.
unstack([dim, fill_value, sparse])Wrapper for the xarray Dataset.unstack function for linopy.Constraint
Attributes
attrsGet the attributes of the constraint.
Get the LHS coefficients DataArray.
coord_dimscoord_namesGet the names of the coordinates.
coord_sizescoordsGet the coordinates of the constraint.
dataGet the underlying xarray Dataset representation.
dimsGet the dimensions of the constraint.
Get the dual values DataArray.
flatConvert the constraint to a pandas DataFrame.
indexesGet the indexes of the constraint.
is_assignedWhether the constraint has been assigned labels by the model.
labelsGet the labels DataArray.
Get the left-hand-side linear expression of the constraint.
locmaskGet the mask of the constraint.
modelGet the model reference.
nameGet the constraint name.
nconsGet the number of active constraints (non-masked, with at least one valid variable).
ndimGet the number of dimensions of the constraint.
ntermGet the number of terms in the constraint.
rangeReturn the range of the constraint.
Get the RHS DataArray.
shapeGet the shape of the constraint.
Get the constraint sign DataArray.
sizeGet the size of the constraint.
sizesGet the sizes of the constraint.
term_dimReturn the term dimension of the constraint.
typeGet the type string of the constraint.
Get the LHS variable labels DataArray.