LSST Applications g0265f82a02+c6dfa2ddaf,g1162b98a3f+ffe7eabc7e,g2079a07aa2+1b2e822518,g2bbee38e9b+c6dfa2ddaf,g337abbeb29+c6dfa2ddaf,g36da64cc00+ea84795170,g3ddfee87b4+955a963fd8,g50ff169b8f+2eb0e556e8,g52b1c1532d+90ebb246c7,g555ede804d+955a963fd8,g591dd9f2cf+bac198a2cb,g5ec818987f+420292cfeb,g858d7b2824+d6c9a0a3b8,g876c692160+aabc49a3c3,g8a8a8dda67+90ebb246c7,g8cdfe0ae6a+4fd9e222a8,g99cad8db69+e6cd765486,g9ddcbc5298+a1346535a5,ga1e77700b3+df8f93165b,ga8c6da7877+acd47f83f4,gae46bcf261+c6dfa2ddaf,gb0e22166c9+8634eb87fb,gb3f2274832+12c8382528,gba4ed39666+1ac82b564f,gbb8dafda3b+0574160a1f,gbeb006f7da+dea2fbb49f,gc28159a63d+c6dfa2ddaf,gc86a011abf+d6c9a0a3b8,gcf0d15dbbd+955a963fd8,gdaeeff99f8+1cafcb7cd4,gdc0c513512+d6c9a0a3b8,ge79ae78c31+c6dfa2ddaf,geb67518f79+ba1859f325,gee10cc3b42+90ebb246c7,gf1cff7945b+d6c9a0a3b8,w.2024.13
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | Static Protected Attributes | List of all members
lsst.daf.base.propertyContainer.propertyContainerContinued.PropertySet Class Reference

Public Member Functions

 from_mapping (cls, metadata)
 
 get (self, name, default=None)
 
 getArray (self, name)
 
 getScalar (self, name)
 
 set (self, name, value)
 
 add (self, name, value)
 
 update (self, addition)
 
 toDict (self)
 
 __eq__ (self, other)
 
 __copy__ (self)
 
 __deepcopy__ (self, memo)
 
 __contains__ (self, name)
 
 __setitem__ (self, name, value)
 
 __getitem__ (self, name)
 
 __delitem__ (self, name)
 
 __str__ (self)
 
 __len__ (self)
 
 __iter__ (self)
 
 keys (self)
 
 items (self)
 
 values (self)
 
 pop (self, name, default=None)
 
 __reduce__ (self)
 
NestedMetadataDict get_dict (self, str key)
 
None set_dict (self, str key, NestedMetadataDict value)
 

Protected Attributes

 _typeMenu
 

Static Protected Attributes

dict _typeMenu
 

Detailed Description

Definition at line 445 of file propertyContainerContinued.py.

Member Function Documentation

◆ __contains__()

lsst.daf.base.propertyContainer.propertyContainerContinued.PropertySet.__contains__ ( self,
name )
Determines if the name is found at the top level hierarchy
of the container.

Notes
------
Does not use `PropertySet.exists()`` because that includes support
for "."-delimited names.  This method is consistent with the
items returned from ``__iter__``.

Definition at line 688 of file propertyContainerContinued.py.

688 def __contains__(self, name):
689 """Determines if the name is found at the top level hierarchy
690 of the container.
691
692 Notes
693 ------
694 Does not use `PropertySet.exists()`` because that includes support
695 for "."-delimited names. This method is consistent with the
696 items returned from ``__iter__``.
697 """
698 return name in self.names(topLevelOnly=True)
699

◆ __copy__()

lsst.daf.base.propertyContainer.propertyContainerContinued.PropertySet.__copy__ ( self)

Definition at line 676 of file propertyContainerContinued.py.

676 def __copy__(self):
677 # Copy without having to go through pickle state
678 ps = PropertySet()
679 for itemName in self:
680 ps.copy(itemName, self, itemName)
681 return ps
682

◆ __deepcopy__()

lsst.daf.base.propertyContainer.propertyContainerContinued.PropertySet.__deepcopy__ ( self,
memo )

Definition at line 683 of file propertyContainerContinued.py.

683 def __deepcopy__(self, memo):
684 result = self.deepCopy()
685 memo[id(self)] = result
686 return result
687

◆ __delitem__()

lsst.daf.base.propertyContainer.propertyContainerContinued.PropertySet.__delitem__ ( self,
name )

Definition at line 734 of file propertyContainerContinued.py.

734 def __delitem__(self, name):
735 if self.exists(name):
736 # dot-delimited names should work so cannot use "in".
737 self.remove(name)
738 else:
739 raise KeyError(f"{name} not present in dict")
740

◆ __eq__()

lsst.daf.base.propertyContainer.propertyContainerContinued.PropertySet.__eq__ ( self,
other )

Definition at line 652 of file propertyContainerContinued.py.

652 def __eq__(self, other):
653 if type(self) != type(other):
654 return NotImplemented
655
656 if len(self) != len(other):
657 return False
658
659 for name in self:
660 if (self_typeOf := self.typeOf(name)) != other.typeOf(name):
661 return False
662
663 if (v1 := _propertyContainerGet(self, name, returnStyle=ReturnStyle.AUTO)) != \
664 (v2 := _propertyContainerGet(other, name, returnStyle=ReturnStyle.AUTO)):
665 # It is possible that we have floats that are NaN. When
666 # equating two PropertySets if there are fields with NaN
667 # these should equate equal.
668 if self_typeOf in (_TYPE_MAP["Float"], _TYPE_MAP["Double"]) \
669 and math.isnan(v1) and math.isnan(v2):
670 pass
671 else:
672 return False
673
674 return True
675

◆ __getitem__()

lsst.daf.base.propertyContainer.propertyContainerContinued.PropertySet.__getitem__ ( self,
name )
Returns a scalar item from the container.

Notes
-----
Uses `PropertySet.getScalar` to guarantee that a single value
will be returned.

Definition at line 724 of file propertyContainerContinued.py.

724 def __getitem__(self, name):
725 """Returns a scalar item from the container.
726
727 Notes
728 -----
729 Uses `PropertySet.getScalar` to guarantee that a single value
730 will be returned.
731 """
732 return self.getScalar(name)
733

◆ __iter__()

lsst.daf.base.propertyContainer.propertyContainerContinued.PropertySet.__iter__ ( self)

Definition at line 747 of file propertyContainerContinued.py.

747 def __iter__(self):
748 for n in self.names(topLevelOnly=True):
749 yield n
750

◆ __len__()

lsst.daf.base.propertyContainer.propertyContainerContinued.PropertySet.__len__ ( self)

Definition at line 744 of file propertyContainerContinued.py.

744 def __len__(self):
745 return self.nameCount(topLevelOnly=True)
746

◆ __reduce__()

lsst.daf.base.propertyContainer.propertyContainerContinued.PropertySet.__reduce__ ( self)

Definition at line 789 of file propertyContainerContinued.py.

789 def __reduce__(self):
790 # It would be a bit simpler to use __setstate__ and __getstate__.
791 # However, implementing __setstate__ in Python causes segfaults
792 # because pickle creates a new instance by calling
793 # object.__new__(PropertyList, *args) which bypasses
794 # the pybind11 memory allocation step.
795 return (_makePropertySet, (getPropertySetState(self),))
796

◆ __setitem__()

lsst.daf.base.propertyContainer.propertyContainerContinued.PropertySet.__setitem__ ( self,
name,
value )
Assigns the supplied value to the container.

Parameters
----------
name : `str`
    Name of item to update.
value : Value to assign
    Can be any value supported by the container's ``set()``
    method. `~collections.abc.Mapping` are converted to
    `PropertySet` before assignment.

Notes
-----
Uses `PropertySet.set`, overwriting any previous value.

Definition at line 700 of file propertyContainerContinued.py.

700 def __setitem__(self, name, value):
701 """Assigns the supplied value to the container.
702
703 Parameters
704 ----------
705 name : `str`
706 Name of item to update.
707 value : Value to assign
708 Can be any value supported by the container's ``set()``
709 method. `~collections.abc.Mapping` are converted to
710 `PropertySet` before assignment.
711
712 Notes
713 -----
714 Uses `PropertySet.set`, overwriting any previous value.
715 """
716 if isinstance(value, Mapping):
717 # Create a property set instead
718 ps = PropertySet()
719 for k, v in value.items():
720 ps[k] = v
721 value = ps
722 self.set(name, value)
723

◆ __str__()

lsst.daf.base.propertyContainer.propertyContainerContinued.PropertySet.__str__ ( self)

Definition at line 741 of file propertyContainerContinued.py.

741 def __str__(self):
742 return self.toString()
743

◆ add()

lsst.daf.base.propertyContainer.propertyContainerContinued.PropertySet.add ( self,
name,
value )
Append one or more values to a given item, which need not exist

If the item exists then the new value(s) are appended;
otherwise it is like calling `set`

Parameters
----------
name : `str`
    Name of item
value : any supported type
    Value of item; may be a scalar or array

Notes
-----
If ``value`` is an `lsst.daf.base.PropertySet` or
`lsst.daf.base.PropertyList` then ``value`` replaces
the existing value. Also the item is added as a live
reference, so updating ``value`` will update this container
and vice-versa.

Raises
------
lsst::pex::exceptions::TypeError
    Raised if the type of `value` is incompatible with the existing
    value of the item.

Definition at line 580 of file propertyContainerContinued.py.

580 def add(self, name, value):
581 """Append one or more values to a given item, which need not exist
582
583 If the item exists then the new value(s) are appended;
584 otherwise it is like calling `set`
585
586 Parameters
587 ----------
588 name : `str`
589 Name of item
590 value : any supported type
591 Value of item; may be a scalar or array
592
593 Notes
594 -----
595 If ``value`` is an `lsst.daf.base.PropertySet` or
596 `lsst.daf.base.PropertyList` then ``value`` replaces
597 the existing value. Also the item is added as a live
598 reference, so updating ``value`` will update this container
599 and vice-versa.
600
601 Raises
602 ------
603 lsst::pex::exceptions::TypeError
604 Raised if the type of `value` is incompatible with the existing
605 value of the item.
606 """
607 return _propertyContainerAdd(self, name, value, self._typeMenu)
608

◆ from_mapping()

lsst.daf.base.propertyContainer.propertyContainerContinued.PropertySet.from_mapping ( cls,
metadata )
Create a `PropertySet` from a mapping or dict-like object.

Parameters
----------
metadata : `collections.abc.Mapping`
    Metadata from which to create the `PropertySet`.
    Can be a mapping, a `~dataclasses.dataclass` or anything that
    supports ``toDict()``, ``to_dict()`` or ``dict()`` method.
    It is assumed that the dictionary is expanded recursively by these
    methods or that the Python type can be understood by `PropertySet`.

Returns
-------
ps : `PropertySet`
    The new `PropertySet`.

Definition at line 458 of file propertyContainerContinued.py.

458 def from_mapping(cls, metadata):
459 """Create a `PropertySet` from a mapping or dict-like object.
460
461 Parameters
462 ----------
463 metadata : `collections.abc.Mapping`
464 Metadata from which to create the `PropertySet`.
465 Can be a mapping, a `~dataclasses.dataclass` or anything that
466 supports ``toDict()``, ``to_dict()`` or ``dict()`` method.
467 It is assumed that the dictionary is expanded recursively by these
468 methods or that the Python type can be understood by `PropertySet`.
469
470 Returns
471 -------
472 ps : `PropertySet`
473 The new `PropertySet`.
474 """
475 ps = cls()
476 d = None
477 if isinstance(metadata, Mapping):
478 d = metadata
479 elif dataclasses.is_dataclass(metadata):
480 d = dataclasses.asdict(metadata)
481 else:
482 for attr in ("to_dict", "toDict", "dict"):
483 if hasattr(metadata, attr):
484 d = getattr(metadata, attr)()
485 break
486 if d is None:
487 raise ValueError("Unable to extract mappings from the supplied metadata of type"
488 f" {type(metadata)}")
489 ps.update(d)
490 return ps
491

◆ get()

lsst.daf.base.propertyContainer.propertyContainerContinued.PropertySet.get ( self,
name,
default = None )
Return an item as a scalar, else default.

Identical to `getScalar` except that a default value is returned
if the requested key is not present.  If an array item is requested
the final value in the array will be returned.

Parameters
----------
name : `str`
    Name of item
default : `object`, optional
    Default value to use if the named item is not present.

Returns
-------
value : any type supported by container
    Single value of any type supported by the container, else the
    default value if the requested item is not present in the
    container.  For array items the most recently added value is
    returned.

Definition at line 492 of file propertyContainerContinued.py.

492 def get(self, name, default=None):
493 """Return an item as a scalar, else default.
494
495 Identical to `getScalar` except that a default value is returned
496 if the requested key is not present. If an array item is requested
497 the final value in the array will be returned.
498
499 Parameters
500 ----------
501 name : `str`
502 Name of item
503 default : `object`, optional
504 Default value to use if the named item is not present.
505
506 Returns
507 -------
508 value : any type supported by container
509 Single value of any type supported by the container, else the
510 default value if the requested item is not present in the
511 container. For array items the most recently added value is
512 returned.
513 """
514 try:
515 return _propertyContainerGet(self, name, returnStyle=ReturnStyle.SCALAR)
516 except KeyError:
517 return default
518

◆ get_dict()

NestedMetadataDict lsst.daf.base.propertyContainer.propertyContainerContinued.PropertySet.get_dict ( self,
str key )
Return a possibly-hierarchical nested `dict`.

This implements the `lsst.pipe.base.GetDictMetadata` protocol for
consistency with `lsst.pipe.base.TaskMetadata` and `PropertyList`.

Parameters
----------
key : `str`
    String key associated with the mapping.  May not have a ``.``
    character.

Returns
-------
value : `~collections.abc.Mapping`
    Possibly-nested mapping, with `str` keys and values that are `int`,
    `float`, `str`, `bool`, or another `dict` with the same key and
    value types.  Will be empty if ``key`` does not exist.

Raises
------
TypeError
    Raised if the value associated with this key is not a nested
    dictionary, but does exist.  Note that this behavior is not
    consistent with `PropertyList` (which returns an empty `dict`).

Definition at line 797 of file propertyContainerContinued.py.

797 def get_dict(self, key: str) -> NestedMetadataDict:
798 """Return a possibly-hierarchical nested `dict`.
799
800 This implements the `lsst.pipe.base.GetDictMetadata` protocol for
801 consistency with `lsst.pipe.base.TaskMetadata` and `PropertyList`.
802
803 Parameters
804 ----------
805 key : `str`
806 String key associated with the mapping. May not have a ``.``
807 character.
808
809 Returns
810 -------
811 value : `~collections.abc.Mapping`
812 Possibly-nested mapping, with `str` keys and values that are `int`,
813 `float`, `str`, `bool`, or another `dict` with the same key and
814 value types. Will be empty if ``key`` does not exist.
815
816 Raises
817 ------
818 TypeError
819 Raised if the value associated with this key is not a nested
820 dictionary, but does exist. Note that this behavior is not
821 consistent with `PropertyList` (which returns an empty `dict`).
822 """
823 if self.exists(key):
824 return self.getScalar(key).toDict()
825 else:
826 return {}
827

◆ getArray()

lsst.daf.base.propertyContainer.propertyContainerContinued.PropertySet.getArray ( self,
name )
Return an item as an array if the item is numeric or string

If the item is a `PropertySet`, `PropertyList` or
`lsst.daf.base.PersistablePtr` then return the item as a scalar.

Parameters
----------
name : `str`
    Name of item

Returns
-------
values : `list` of any type supported by container
    The contents of the item, guaranteed to be returned as a `list.`

Raises
------
KeyError
    Raised if the item does not exist.

Definition at line 519 of file propertyContainerContinued.py.

519 def getArray(self, name):
520 """Return an item as an array if the item is numeric or string
521
522 If the item is a `PropertySet`, `PropertyList` or
523 `lsst.daf.base.PersistablePtr` then return the item as a scalar.
524
525 Parameters
526 ----------
527 name : `str`
528 Name of item
529
530 Returns
531 -------
532 values : `list` of any type supported by container
533 The contents of the item, guaranteed to be returned as a `list.`
534
535 Raises
536 ------
537 KeyError
538 Raised if the item does not exist.
539 """
540 return _propertyContainerGet(self, name, returnStyle=ReturnStyle.ARRAY)
541

◆ getScalar()

lsst.daf.base.propertyContainer.propertyContainerContinued.PropertySet.getScalar ( self,
name )
Return an item as a scalar

If the item has more than one value then the last value is returned.

Parameters
----------
name : `str`
    Name of item

Returns
-------
value : scalar item
    Value stored in the item.  If the item refers to an array the
    most recently added value is returned.

Raises
------
KeyError
    Raised if the item does not exist.

Definition at line 542 of file propertyContainerContinued.py.

542 def getScalar(self, name):
543 """Return an item as a scalar
544
545 If the item has more than one value then the last value is returned.
546
547 Parameters
548 ----------
549 name : `str`
550 Name of item
551
552 Returns
553 -------
554 value : scalar item
555 Value stored in the item. If the item refers to an array the
556 most recently added value is returned.
557
558 Raises
559 ------
560 KeyError
561 Raised if the item does not exist.
562 """
563 return _propertyContainerGet(self, name, returnStyle=ReturnStyle.SCALAR)
564

◆ items()

lsst.daf.base.propertyContainer.propertyContainerContinued.PropertySet.items ( self)

Definition at line 754 of file propertyContainerContinued.py.

754 def items(self):
755 return ItemsView(self)
756
std::vector< SchemaItem< Flag > > * items

◆ keys()

lsst.daf.base.propertyContainer.propertyContainerContinued.PropertySet.keys ( self)

Definition at line 751 of file propertyContainerContinued.py.

751 def keys(self):
752 return KeysView(self)
753

◆ pop()

lsst.daf.base.propertyContainer.propertyContainerContinued.PropertySet.pop ( self,
name,
default = None )
Remove the named key and return its value.

Parameters
----------
name : `str`
    Name of the key to remove. Can be hierarchical.
default : Any, optional
    Value to return if the key is not present.

Returns
-------
value : Any
    The value of the item as would be returned using `getScalar()`.

Raises
------
KeyError
    Raised if no default is given and the key is missing.

Definition at line 760 of file propertyContainerContinued.py.

760 def pop(self, name, default=None):
761 """Remove the named key and return its value.
762
763 Parameters
764 ----------
765 name : `str`
766 Name of the key to remove. Can be hierarchical.
767 default : Any, optional
768 Value to return if the key is not present.
769
770 Returns
771 -------
772 value : Any
773 The value of the item as would be returned using `getScalar()`.
774
775 Raises
776 ------
777 KeyError
778 Raised if no default is given and the key is missing.
779 """
780 if self.exists(name):
781 value = self[name]
782 self.remove(name)
783 else:
784 if default is None:
785 raise KeyError(name)
786 value = default
787 return value
788

◆ set()

lsst.daf.base.propertyContainer.propertyContainerContinued.PropertySet.set ( self,
name,
value )
Set the value of an item

If the item already exists it is silently replaced; the types
need not match.

Parameters
----------
name : `str`
    Name of item
value : any supported type
    Value of item; may be a scalar or array

Definition at line 565 of file propertyContainerContinued.py.

565 def set(self, name, value):
566 """Set the value of an item
567
568 If the item already exists it is silently replaced; the types
569 need not match.
570
571 Parameters
572 ----------
573 name : `str`
574 Name of item
575 value : any supported type
576 Value of item; may be a scalar or array
577 """
578 return _propertyContainerSet(self, name, value, self._typeMenu)
579
daf::base::PropertySet * set
Definition fits.cc:931

◆ set_dict()

None lsst.daf.base.propertyContainer.propertyContainerContinued.PropertySet.set_dict ( self,
str key,
NestedMetadataDict value )
Assign a possibly-hierarchical nested `dict`.

This implements the `lsst.pipe.base.SetDictMetadata` protocol for
consistency with `lsst.pipe.base.TaskMetadata` and `PropertyList`.

Parameters
----------
key : `str`
    String key associated with the mapping.  May not have a ``.``
    character.
value : `~collections.abc.Mapping`
    Possibly-nested mapping, with `str` keys and values that are `int`,
    `float`, `str`, `bool`, or another `dict` with the same key and
    value types.   May not have a ``.``
    character.

Definition at line 828 of file propertyContainerContinued.py.

828 def set_dict(self, key: str, value: NestedMetadataDict) -> None:
829 """Assign a possibly-hierarchical nested `dict`.
830
831 This implements the `lsst.pipe.base.SetDictMetadata` protocol for
832 consistency with `lsst.pipe.base.TaskMetadata` and `PropertyList`.
833
834 Parameters
835 ----------
836 key : `str`
837 String key associated with the mapping. May not have a ``.``
838 character.
839 value : `~collections.abc.Mapping`
840 Possibly-nested mapping, with `str` keys and values that are `int`,
841 `float`, `str`, `bool`, or another `dict` with the same key and
842 value types. May not have a ``.``
843 character.
844 """
845 self.set(key, PropertySet.from_mapping(value))
846
847
848@continueClass

◆ toDict()

lsst.daf.base.propertyContainer.propertyContainerContinued.PropertySet.toDict ( self)
Returns a (possibly nested) dictionary with all properties.

Returns
-------
d : `dict`
    Dictionary with all names and values (no comments).

Definition at line 633 of file propertyContainerContinued.py.

633 def toDict(self):
634 """Returns a (possibly nested) dictionary with all properties.
635
636 Returns
637 -------
638 d : `dict`
639 Dictionary with all names and values (no comments).
640 """
641
642 d = {}
643 for name in self.names():
644 v = _propertyContainerGet(self, name, returnStyle=ReturnStyle.AUTO)
645
646 if isinstance(v, PropertySet):
647 d[name] = PropertySet.toDict(v)
648 else:
649 d[name] = v
650 return d
651

◆ update()

lsst.daf.base.propertyContainer.propertyContainerContinued.PropertySet.update ( self,
addition )
Update the current container with the supplied additions.

Parameters
----------
addition : `collections.abc.Mapping` or `PropertySet`
    The content to merge into the current container.

Notes
-----
This is not the same as calling `PropertySet.combine` since the
behavior differs when both mappings contain the same key.  This
method updates by overwriting existing values completely with
the new value.

Definition at line 609 of file propertyContainerContinued.py.

609 def update(self, addition):
610 """Update the current container with the supplied additions.
611
612 Parameters
613 ----------
614 addition : `collections.abc.Mapping` or `PropertySet`
615 The content to merge into the current container.
616
617 Notes
618 -----
619 This is not the same as calling `PropertySet.combine` since the
620 behavior differs when both mappings contain the same key. This
621 method updates by overwriting existing values completely with
622 the new value.
623 """
624 if isinstance(addition, PropertySet):
625 # To support array values we can not use the dict interface
626 # and instead use the copy() method which overwrites
627 for k in addition:
628 self.copy(k, addition, k)
629 else:
630 for k, v in addition.items():
631 self[k] = v
632

◆ values()

lsst.daf.base.propertyContainer.propertyContainerContinued.PropertySet.values ( self)

Definition at line 757 of file propertyContainerContinued.py.

757 def values(self):
758 return ValuesView(self)
759

Member Data Documentation

◆ _typeMenu [1/2]

dict lsst.daf.base.propertyContainer.propertyContainerContinued.PropertySet._typeMenu
staticprotected
Initial value:
= {bool: "Bool",
float: "Double",
str: "String",
DateTime: "DateTime",
PropertySet: "PropertySet",
PropertyList: "PropertySet",
None: "Undef",
}

Definition at line 448 of file propertyContainerContinued.py.

◆ _typeMenu [2/2]

lsst.daf.base.propertyContainer.propertyContainerContinued.PropertySet._typeMenu
protected

Definition at line 578 of file propertyContainerContinued.py.


The documentation for this class was generated from the following file: