base¤
Reader
¤
Abstract base class for a Reader.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
ReadLike | str
|
The file to read. |
required |
Source code in src/msl/io/base.py
160 161 162 163 164 165 166 167 | |
can_read
abstractmethod
staticmethod
¤
Whether this Reader can read the file specified by file.
You must override this method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
ReadLike | str
|
The file to check whether the Reader can read it. |
required |
kwargs
|
Any
|
Keyword arguments that the Reader class may need
when checking if it can read the |
{}
|
Returns:
| Type | Description |
|---|---|
bool
|
Either |
Source code in src/msl/io/base.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
read
abstractmethod
¤
read(**kwargs: Any) -> None
Read the file.
The file to read can be accessed by the file property.
You must override this method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kwargs
|
Any
|
Keyword arguments that the Reader class may need when reading the file. |
{}
|
Source code in src/msl/io/base.py
195 196 197 198 199 200 201 202 203 204 205 206 | |
Root
¤
Bases: Group
The root Group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
PathLike | ReadLike | WriteLike | None
|
The file object to associate with the Root. |
required |
metadata
|
Any
|
All keyword arguments are used as Metadata. |
{}
|
Source code in src/msl/io/base.py
34 35 36 37 38 39 40 41 42 43 44 45 46 | |
tree
¤
Returns a string representation of the tree structure.
Shows all Groups and Datasets that are in Root.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indent
|
int
|
The amount of indentation to add for each recursive level. |
2
|
Returns:
| Type | Description |
|---|---|
str
|
The tree structure. |
Source code in src/msl/io/base.py
58 59 60 61 62 63 64 65 66 67 68 69 | |
Writer
¤
Abstract base class for a Writer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
PathLike | WriteLike | None
|
The file to write the data to. Can also be specified in the write method. |
None
|
metadata
|
Any
|
All keyword arguments are used as Metadata. |
{}
|
Source code in src/msl/io/base.py
75 76 77 78 79 80 81 82 83 84 | |
file
property
¤
save
¤
save(
file: PathLike | WriteLike | None = None,
*,
root: Group | None = None,
**kwargs: Any,
) -> None
Alias for write.
Source code in src/msl/io/base.py
136 137 138 139 140 141 142 143 144 | |
set_root
¤
set_root(root: Group) -> None
Set a new Root for the Writer.
Info
This will clear the Metadata of the Writer
and all Groups and Datasets that the
Writer currently contains. The file that was specified when
the Writer was created does not change.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
Group
|
The new |
required |
Source code in src/msl/io/base.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
update_context_kwargs
¤
update_context_kwargs(**kwargs: Any) -> None
Update the keyword arguments when used as a context manager.
When a Writer is used as a context manager the write method is automatically called when exiting the context manager. You can specify the keyword arguments that will be passed to the write method by calling update_context_kwargs with the appropriate keyword arguments before the context manager exits. You may call this method multiple times.
Source code in src/msl/io/base.py
109 110 111 112 113 114 115 116 117 118 119 120 | |
write
abstractmethod
¤
write(
file: PathLike | WriteLike | None = None,
root: Group | None = None,
**kwargs: Any,
) -> None
Write to a file.
You must override this method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
PathLike | WriteLike | None
|
The file to write the |
None
|
root
|
Group | None
|
Write the |
None
|
kwargs
|
Any
|
Keyword arguments to use when writing the file. |
{}
|
Source code in src/msl/io/base.py
122 123 124 125 126 127 128 129 130 131 132 133 134 | |
read
¤
Read a file that has a Reader implemented.
See the Overview for an example.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
PathLike | ReadLike
|
The file to read. |
required |
kwargs
|
Any
|
{}
|
Returns:
| Type | Description |
|---|---|
Reader
|
The data from the file. |
Source code in src/msl/io/base.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | |