Association

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

Bases: _abcoll.MutableMapping

Association Base Class

Parameters:version_id (str or None) – Version_Id to use in the name of this association. If None, nothing is added.
Raises:AssociationError – If a item doesn’t match any of the registered associations.
instance

dict-like – The instance is the association data structure. See data below

meta

dict – Information about the association.

data

dict – The association. The format of this data structure is determined by the individual assocations and, if defined, valided against their specified schema.

schema_file

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

registry

AssociationRegistry – The registry this association came from.

asn_name

str – The suggested file name of association

asn_rule

str – The name of the rule

Attributes Summary

DEFAULT_EVALUATE
DEFAULT_FORCE_UNIQUE
DEFAULT_REQUIRE_CONSTRAINT
GLOBAL_CONSTRAINTS
INVALID_VALUES
asn_name
asn_rule
ioregistry
is_valid Check if association is valid
registry

Methods Summary

add(item[, check_constraints]) Add the item to the association
add_constraints(new_constraints) Add a set of constraints to the current constraints.
constraints_to_text()
create(item[, version_id]) Create association if item belongs
dump([format]) Serialize the association
is_item_member(item) Check if item is already a member of this association
items()
keys()
load(serialized[, format, validate]) Marshall a previously serialized association
match_constraint(item, constraint, conditions) Generic constraint checking
match_item(item, constraint, conditions) Use item info to match to the conditions
test_and_set_constraints(item) Test whether the given dictionaries match parameters for
validate(asn) Validate an association against this rule
values()

Attributes Documentation

DEFAULT_EVALUATE = False
DEFAULT_FORCE_UNIQUE = False
DEFAULT_REQUIRE_CONSTRAINT = True
GLOBAL_CONSTRAINTS = {}
INVALID_VALUES = None
asn_name
asn_rule
ioregistry = {'yaml': <class 'jwst.associations.association_io.yaml'>, 'json': <class 'jwst.associations.association_io.json'>}
is_valid

Check if association is valid

registry = None

Methods Documentation

add(item, check_constraints=True)[source]

Add the item to the association

Parameters:
  • item (dict) – The item to add.
  • check_constraints (bool) – If True, see if the item should belong to this association. If False, just add it.
Returns:

2-tuple consisting of: - bool: True if the all constraints are satisfied - [ProcessList[, …]]: List of items to process again.

Return type:

(matches, reprocess_list)

add_constraints(new_constraints)[source]

Add a set of constraints to the current constraints.

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

Create association if item belongs

Parameters:
  • item (dict) – The item to initialize the association with.
  • version_id (str or None) – Version_Id to use in the name of this association. If None, nothing is added.
Returns:

2-tuple consisting of: - association: The association or, if the item does not

this rule, None

  • [ProcessList[, …]]: List of items to process again.

Return type:

(association, reprocess_list)

dump(format='json', **kwargs)[source]

Serialize the association

Parameters:
  • format (str) – The format to use to dump the association into.
  • kwargs (dict) – List of arguments to pass to the registered routines for the current association type.
Returns:

Tuple where the first item is the suggested base name for the file. Second item is the serialization.

Return type:

(name, serialized)

Raises:
is_item_member(item)[source]

Check if item is already a member of this association

Parameters:item (dict) – The item to add.
Returns:is_item_member – True if item is a member.
Return type:bool
items()[source]
keys()[source]
classmethod load(serialized, format=None, validate=True, **kwargs)[source]

Marshall a previously serialized association

Parameters:
  • serialized (object) – The serialized form of the association.
  • format (str or None) – The format to force. If None, try all available.
  • validate (bool) – Validate against the class’ defined schema, if any.
  • kwargs (dict) – Other arguments to pass to the load method
Returns:

Return type:

The Association object

Raises:

AssociationNotValidError – Cannot create or validate the association.

Notes

The serialized object can be in any format supported by the registered I/O routines. For example, for json and yaml formats, the input can be either a string or a file object containing the string.

match_constraint(item, constraint, conditions)[source]

Generic constraint checking

Parameters:
  • item (dict) – The item to retrieve the values from
  • constraint (str) – The name of the constraint
  • conditions (dict) – The conditions structure
Returns:

2-tuple consisting of: - bool: True if the all constraints are satisfied - [ProcessList[, …]]: List of items to process again.

Return type:

(matches, reprocess_list)

match_item(item, constraint, conditions)[source]

Use item info to match to the conditions

Parameters:
  • item (dict) – The item to retrieve the values from
  • constraint (str) – The name of the constraint
  • conditions (dict) – The conditions structure
Returns:

2-tuple consisting of: - bool: True if the all constraints are satisfied - [ProcessList[, …]]: List of items to process again.

Return type:

(matches, reprocess_list)

test_and_set_constraints(item)[source]

Test whether the given dictionaries match parameters for for this association

Parameters:item (dict) – The parameters to check/set for this association. This can be a list of dictionaries.
Returns:2-tuple consisting of: - bool: True if the all constraints are satisfied - [ProcessItem[, …]]: List of items to process again.
Return type:(matches, reprocess_list)

Notes

If a constraint is present, but does not have a value, that constraint is set, and, by definition, matches.

classmethod validate(asn)[source]

Validate an association against this rule

Parameters:asn (Association or association-like) – The association structure to examine
Returns:valid – True if valid. Otherwise the AssociationNotValidError is raised
Return type:bool
Raises:AssociationNotValidError – If there is some reason validation failed.

Notes

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

values()[source]