Association

class jwst.associations.association.Association(version_id=None)[source]

Bases: MutableMapping

Association base class.

Parameters:
version_idstr or None

Version ID to use in the name of this association. If None, nothing is added.

Attributes:
instancedict-like

The instance is the association data structure. See data below.

metadict

Information about the association.

datadict

The association. The format of this data structure is determined by the individual associations and, if defined, validated against their specified schema.

schema_filestr

The name of the output schema that an association must adhere to.

Raises:
jwst.associations.exceptions.AssociationError

If an item doesn’t match.

Attributes Summary

DEFAULT_EVALUATE

Default do not evaluate input values.

DEFAULT_FORCE_UNIQUE

Default whether to force constraints to use unique values.

DEFAULT_REQUIRE_CONSTRAINT

Default require that the constraint exists or otherwise can be explicitly checked.

GLOBAL_CONSTRAINT

Global constraints.

INVALID_VALUES

Attribute values that indicate the attribute is not specified.

asn_name

Suggest filename for the association.

asn_rule

Same as rule_name().

is_valid

Check if association is valid.

registry

Registry this rule has been placed in.

Methods Summary

add(item[, check_constraints])

Add the item to the association.

check_and_set_constraints(item)

Check whether the given dictionaries match parameters for this association.

create(item[, version_id])

Create association if item belongs.

dump([fmt])

Serialize the association.

finalize()

Finalize association.

is_item_member(item)

Check if item is already a member of this association.

items()

Provide items of data dictionary.

keys()

Provide keys of data dictionary.

load(serialized[, fmt, validate])

Load a serialized association.

match_constraint(item, conditions)

Match against constraints.

rule_name()

Return rule name.

validate(asn[, error_on_fail])

Validate an association against this rule.

values()

Provide values of data dictionary.

Attributes Documentation

DEFAULT_EVALUATE = False

Default do not evaluate input values.

DEFAULT_FORCE_UNIQUE = False

Default whether to force constraints to use unique values.

DEFAULT_REQUIRE_CONSTRAINT = True

Default require that the constraint exists or otherwise can be explicitly checked.

GLOBAL_CONSTRAINT = None

Global constraints.

INVALID_VALUES: tuple | None = None

Attribute values that indicate the attribute is not specified.

asn_name

Suggest filename for the association.

Returns:
str

Default asn name of ‘unnamed_association’.

asn_rule

Same as rule_name().

is_valid

Check if association is valid.

Returns:
bool

True if association is valid, otherwise False.

registry = None

Registry this rule has been placed in.

Methods Documentation

add(item, check_constraints=True)[source]

Add the item to the association.

Parameters:
itemdict

The item to add.

check_constraintsbool

If True, see if the item should belong to this association. If False, just add it.

Returns:
matchbool

True if the all constraints are satisfied or skipped. This could also be the value of self.constraints['force_match'] when it is set.

reprocesslist of ProcessList

List of items to process again.

check_and_set_constraints(item)[source]

Check whether the given dictionaries match parameters for this association.

Parameters:
itemdict

The parameters to check/set for this association. This can be a list of dictionaries.

Returns:
matchbool

True if the all constraints are satisfied.

reprocesslist of ProcessList

List of items to process again.

classmethod create(item, version_id=None)[source]

Create association if item belongs.

Parameters:
itemdict

The item to initialize the association with.

version_idstr or None

Version ID to use in the name of this association. If None, nothing is added.

Returns:
asnAssociation or None

The association or, if the item does not match this rule, None.

reprocesslist of ProcessList

List of items to process again.

dump(fmt=None, **kwargs)[source]

Serialize the association.

Parameters:
fmtstr

The format to use to dump the association into.

Deprecated since version 2.1: Only JSON format is supported now.

**kwargs

List of arguments to pass to the registered routines for the current association type.

Deprecated since version 2.1: This is completely ignored.

Returns:
asn_filenamestr

Suggested base name for the JSON file. This is taken from the asn_name attribute.

serializedstr

JSON serialization of this association.

Raises:
jwst.associations.exceptions.AssociationNotValidError

If the association does not validate.

finalize()[source]

Finalize association.

Finalize or close off this association. Perform validations, modifications, etc. to ensure that the association is complete.

Returns:
associationslist of Association or None

List of fully-qualified associations that this association represents. None if a complete association cannot be produced.

is_item_member(item)[source]

Check if item is already a member of this association.

Parameters:
itemdict

The item to check.

Returns:
is_item_memberbool

True if item is a member.

items()[source]

Provide items of data dictionary.

Returns:
dict_itemsiter

The items of the data dictionary.

keys()[source]

Provide keys of data dictionary.

Returns:
dict_keysiter

The keys of the data dictionary.

classmethod load(serialized, fmt=None, validate=True, **kwargs)[source]

Load a serialized association.

Parameters:
serializedstr, dict, or file-like

The serialized form of the association.

fmtstr or None

The format to force. If None, try all available.

Deprecated since version 2.1: Only JSON format is supported now.

validatebool

Validate against the class’ defined schema, if any.

**kwargsdict

Other arguments to pass to the load method.

Deprecated since version 2.1: This is completely ignored.

Returns:
associationAssociation

The association.

Raises:
jwst.associations.exceptions.AssociationNotValidError

Cannot create or validate the association.

match_constraint(item, conditions)[source]

Match against constraints.

Parameters:
itemdict

The item to retrieve the values from.

conditionsdict

The conditions structure.

Returns:
matchbool

True if the all constraints are satisfied.

reprocesslist of ProcessList

List of items to process again.

classmethod rule_name()[source]

Return rule name.

Returns:
str

The name of the rule class.

classmethod validate(asn, error_on_fail=True)[source]

Validate an association against this rule.

Parameters:
asnAssociation

The association structure to examine.

error_on_failbool

On validation error, throw exception instead of changing return status.

Returns:
validbool

True if valid. When invalid, an exception is raised if error_on_fail is True, otherwise False.

Raises:
jwst.associations.exceptions.AssociationNotValidError

Validation failed and error_on_fail is True.

Notes

The base method checks against the rule class’ schema (schema_file). If the rule class does not define a schema, a warning is issued in logger but the routine will still return True.

values()[source]

Provide values of data dictionary.

Returns:
dict_valuesiter

The values of the data dictionary.