node¤
Node objects in the hierarchical tree.
Dataset
¤
Dataset(
*,
name: str,
parent: Group | None,
read_only: bool,
shape: ShapeLike = (0,),
dtype: DTypeLike = float,
buffer: Buffer | None = None,
offset: SupportsIndex = 0,
strides: ShapeLike | None = None,
order: Literal["K", "A", "C", "F"] | None = None,
data: ArrayLike | None = None,
**metadata: Any,
)
Bases: NDArrayOperatorsMixin, Sequence[Any]
A Dataset functions as a numpy ndarray with Metadata.
Warning
Do not instantiate directly. Create a new Dataset using the create_dataset method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
A name to associate with this Dataset. |
required |
parent
|
Group | None
|
required | |
read_only
|
bool
|
Whether the Dataset is initialised in read-only mode. |
required |
shape
|
ShapeLike
|
See numpy ndarray. Only used if |
(0,)
|
dtype
|
DTypeLike
|
float
|
|
buffer
|
Buffer | None
|
See numpy ndarray. Only used if |
None
|
offset
|
SupportsIndex
|
See numpy ndarray. Only used if |
0
|
strides
|
ShapeLike | None
|
See numpy ndarray. Only used if |
None
|
order
|
Literal['K', 'A', 'C', 'F'] | None
|
None
|
|
data
|
ArrayLike | None
|
None
|
|
metadata
|
Any
|
{}
|
Source code in src/msl/io/node.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
data
property
¤
ndarray — The data of the Dataset.
Tip
You do not have to call this attribute to access the underlying numpy ndarray. You can directly call any ndarray attribute from the Dataset instance.
For example,
>>> dataset
<Dataset '/my_data' shape=(4, 3) dtype='<f8' (0 metadata)>
>>> dataset.data
array([[ 0., 1., 2.],
[ 3., 4., 5.],
[ 6., 7., 8.],
[ 9., 10., 11.]])
>>> dataset.size
12
>>> dataset.tolist()
[[0.0, 1.0, 2.0], [3.0, 4.0, 5.0], [6.0, 7.0, 8.0], [9.0, 10.0, 11.0]]
>>> dataset.mean(axis=0)
array([4.5, 5.5, 6.5])
>>> dataset[::2]
array([[0., 1., 2.],
[6., 7., 8.]])
read_only
property
writable
¤
read_only: bool
bool — Whether the Dataset is in read-only mode.
This is equivalent to setting the WRITEABLE property in numpy.ndarray.setflags.
add_metadata
¤
add_metadata(**metadata: Any) -> None
Add metadata to the Dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata
|
Any
|
{}
|
Source code in src/msl/io/node.py
197 198 199 200 201 202 203 204 | |
copy
¤
Create a copy of this Dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
read_only
|
bool | None
|
Whether the copy should be created in read-only mode. If |
None
|
Returns:
| Type | Description |
|---|---|
Dataset
|
A copy of this Dataset. |
Source code in src/msl/io/node.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
DatasetLogging
¤
DatasetLogging(
*,
name: str,
parent: Group | None,
attributes: Sequence[str],
level: str | int = NOTSET,
logger: Logger | None = None,
date_fmt: str | None = None,
**kwargs: Any,
)
Bases: Dataset
A Dataset that handles logging records.
Warning
Do not instantiate directly. Create a new DatasetLogging using create_dataset_logging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
A name to associate with the Dataset. |
required |
parent
|
Group | None
|
The parent to the |
required |
attributes
|
Sequence[str]
|
The attribute names to include in the Dataset for each logging record. |
required |
level
|
str | int
|
The logging level to use. |
NOTSET
|
logger
|
Logger | None
|
None
|
|
date_fmt
|
str | None
|
The datetime format code
to use to represent the asctime attribute (only if
asctime is included as one of the |
None
|
kwargs
|
Any
|
All additional keyword arguments are passed to Dataset.
The default behaviour is to append every logging record
to the Dataset. This guarantees that the size of the
Dataset is equal to the number of logging records
that were added to it. However, this behaviour can decrease performance if many
logging records are added often because a copy of the data in the
Dataset is created for each logging record
that is added. You can improve performance by specifying an initial size of the
Dataset by including a |
{}
|
Source code in src/msl/io/node.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | |
attributes
property
¤
tuple[str, ...] — The attribute names that are logged.
add_filter
¤
add_filter(log_filter: Filter) -> None
Add a logging filter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
log_filter
|
Filter
|
required |
Source code in src/msl/io/node.py
405 406 407 408 409 410 411 | |
remove_empty_rows
¤
remove_empty_rows() -> None
Remove empty rows from the Dataset.
If the DatasetLogging object was initialized with a shape or a size
keyword argument then the size of the Dataset is always greater than or equal to
the number of logging records that were added to it. Calling this method will remove the
rows in the Dataset that were not from a logging record.
Source code in src/msl/io/node.py
437 438 439 440 441 442 443 444 445 446 447 448 | |
remove_filter
¤
remove_filter(log_filter: Filter) -> None
Remove a logging filter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
log_filter
|
Filter
|
required |
Source code in src/msl/io/node.py
450 451 452 453 454 455 456 | |
remove_handler
¤
remove_handler() -> None
Remove this class's Handler from the associated Logger.
After calling this method logging records are no longer added to the Dataset.
Source code in src/msl/io/node.py
458 459 460 461 462 463 464 465 | |
set_logger
¤
set_logger(logger: Logger) -> None
Add this class's Handler to a Logger.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logger
|
Logger
|
required |
Source code in src/msl/io/node.py
467 468 469 470 471 472 473 474 475 476 477 478 479 | |
Group
¤
Bases: FreezableMap['Dataset | Group']
A Group can contain sub-Groups and/or Datasets.
Warning
Do not instantiate directly. Create a new Group using create_group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
required | |
parent
|
Group | None
|
The parent to this Group. |
required |
read_only
|
bool
|
Whether the Group is initialised in read-only mode. |
required |
metadata
|
Any
|
{}
|
Source code in src/msl/io/node.py
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | |
add_dataset
¤
Add a Dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
required | |
dataset
|
Dataset
|
required |
Source code in src/msl/io/node.py
828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 | |
add_dataset_logging
¤
add_dataset_logging(
name: str, dataset_logging: DatasetLogging
) -> None
Add a DatasetLogging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the new DatasetLogging to add. Automatically creates the ancestor Groups if they do not exist. |
required |
dataset_logging
|
DatasetLogging
|
The DatasetLogging to add. The data and Metadata are copied. |
required |
Source code in src/msl/io/node.py
890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 | |
add_group
¤
Add a Group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
required | |
group
|
Group
|
required |
Source code in src/msl/io/node.py
757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 | |
add_metadata
¤
add_metadata(**metadata: Any) -> None
Add metadata to the Group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata
|
Any
|
{}
|
Source code in src/msl/io/node.py
616 617 618 619 620 621 622 623 | |
ancestors
¤
Yield all ancestor (parent) Groups of this Group.
Yields:
| Type | Description |
|---|---|
Group
|
The ancestors of this Group. |
Source code in src/msl/io/node.py
746 747 748 749 750 751 752 753 754 755 | |
create_dataset
¤
Create a new Dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
required | |
read_only
|
bool | None
|
None
|
|
kwargs
|
Any
|
All additional keyword arguments are passed to Dataset. |
{}
|
Returns:
| Type | Description |
|---|---|
Dataset
|
The new Dataset that was created. |
Source code in src/msl/io/node.py
844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 | |
create_dataset_logging
¤
create_dataset_logging(
name: str,
*,
level: str | int = "INFO",
attributes: Sequence[str] | None = None,
logger: Logger | None = None,
date_fmt: str | None = None,
**kwargs: Any,
) -> DatasetLogging
Create a Dataset that handles logging records.
See here for an example.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
required | |
level
|
str | int
|
The logging level to use. |
'INFO'
|
attributes
|
Sequence[str] | None
|
The attribute names to include in the
Dataset for each logging record.
If |
None
|
logger
|
Logger | None
|
The Logger that the DatasetLogging object
will be associated with. If |
None
|
date_fmt
|
str | None
|
The datetime format code
to use to represent the asctime attribute in.
If |
None
|
kwargs
|
Any
|
All additional keyword arguments are passed to Dataset.
The default behaviour is to append every logging record
to the Dataset. This guarantees that the size of the
Dataset is equal to the number of
logging records that were added to it. However, this behaviour
can decrease performance if many logging records are
added often because a copy of the data in the Dataset is
created for each logging record that is added. You can improve
performance by specifying an initial size of the Dataset
by including a |
{}
|
Returns:
| Type | Description |
|---|---|
DatasetLogging
|
The DatasetLogging that was created. |
Source code in src/msl/io/node.py
914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 | |
create_group
¤
Create a new Group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
required | |
read_only
|
bool | None
|
None
|
|
metadata
|
Any
|
{}
|
Returns:
| Type | Description |
|---|---|
Group
|
The new Group that was created. |
Source code in src/msl/io/node.py
784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 | |
datasets
¤
datasets(
*,
exclude: str | None = None,
include: str | None = None,
flags: int = 0,
) -> Iterator[Dataset]
Yield the Datasets in this Group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exclude
|
str | None
|
None
|
|
include
|
str | None
|
None
|
|
flags
|
int
|
Regular-expression flags that are passed to re.compile. |
0
|
Yields:
| Type | Description |
|---|---|
Dataset
|
The filtered Datasets based on the |
Source code in src/msl/io/node.py
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 | |
descendants
¤
Yield all descendant (children) Groups of this Group.
Yields:
| Type | Description |
|---|---|
Group
|
The descendants of this Group. |
Source code in src/msl/io/node.py
736 737 738 739 740 741 742 743 744 | |
groups
¤
groups(
*,
exclude: str | None = None,
include: str | None = None,
flags: int = 0,
) -> Iterator[Group]
Yield the sub-Groups of this Group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exclude
|
str | None
|
None
|
|
include
|
str | None
|
None
|
|
flags
|
int
|
Regular-expression flags that are passed to re.compile. |
0
|
Yields:
| Type | Description |
|---|---|
Group
|
The filtered sub-Groups based on the |
Source code in src/msl/io/node.py
708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 | |
is_dataset
staticmethod
¤
Check if an object is an instance of Dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
object
|
The object to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether |
Source code in src/msl/io/node.py
644 645 646 647 648 649 650 651 652 653 654 | |
is_dataset_logging
staticmethod
¤
Check if an object is an instance of DatasetLogging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
object
|
The object to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether |
Source code in src/msl/io/node.py
656 657 658 659 660 661 662 663 664 665 666 | |
is_group
staticmethod
¤
Check if an object is an instance of Group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
object
|
The object to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether |
Source code in src/msl/io/node.py
668 669 670 671 672 673 674 675 676 677 678 | |
remove
¤
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
required |
Returns:
| Type | Description |
|---|---|
Dataset | Group | None
|
Source code in src/msl/io/node.py
1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 | |
require_dataset
¤
Require that a Dataset exists.
If the Dataset exists it will be returned, otherwise it is created then returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
required | |
read_only
|
bool | None
|
None
|
|
kwargs
|
Any
|
All additional keyword arguments are passed to Dataset. |
{}
|
Returns:
| Type | Description |
|---|---|
Dataset
|
The Dataset that was created or that already existed. |
Source code in src/msl/io/node.py
862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 | |
require_dataset_logging
¤
require_dataset_logging(
name: str,
*,
level: str | int = "INFO",
attributes: Sequence[str] | None = None,
logger: Logger | None = None,
date_fmt: str | None = None,
**kwargs: Any,
) -> DatasetLogging
Require that a Dataset exists for handling logging records.
If the DatasetLogging exists it will be returned otherwise it is created and then returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
required | |
level
|
str | int
|
The logging level to use. |
'INFO'
|
attributes
|
Sequence[str] | None
|
The attribute names to include in the
Dataset for each logging record.
If |
None
|
logger
|
Logger | None
|
The Logger that the DatasetLogging object
will be associated with. If |
None
|
date_fmt
|
str | None
|
The datetime format code
to use to represent the asctime attribute in.
If |
None
|
kwargs
|
Any
|
All additional keyword arguments are passed to Dataset.
The default behaviour is to append every logging record
to the Dataset. This guarantees that the size of the
Dataset is equal to the number of
logging records that were added to it. However, this behaviour
can decrease performance if many logging records are
added often because a copy of the data in the Dataset is
created for each logging record that is added. You can improve
performance by specifying an initial size of the Dataset
by including a |
{}
|
Returns:
| Type | Description |
|---|---|
DatasetLogging
|
The DatasetLogging that was created or that already existed. |
Source code in src/msl/io/node.py
975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 | |
require_group
¤
Require that a Group exists.
If the Group exists it will be returned otherwise it is created then returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
required | |
read_only
|
bool | None
|
None
|
|
metadata
|
Any
|
{}
|
Returns:
| Type | Description |
|---|---|
Group
|
The required Group that was created or that already existed. |
Source code in src/msl/io/node.py
802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 | |