Writers¤
The following Writers are available
- HDF5Writer — HDF5 file format
- JSONWriter — JSON file format
HDF5Writer
¤
Bases: Writer
Writer for the HDF5 file format.
You can use this Writer as a context manager, for example,
with HDF5Writer("my_file.h5") as root:
root.create_dataset("dset", data=[1, 2, 3])
This will automatically write root to the specified file when the with
block exits.
Info
This Writer requires the h5py package to be installed.
Source code in src/msl/io/base.py
75 76 77 78 79 80 81 82 83 84 | |
write
¤
write(
file: PathLike | WriteLike | None = None,
root: Group | None = None,
**kwargs: Any,
) -> None
Write to a HDF5 file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
PathLike | WriteLike | None
|
The file to write a root to. If |
None
|
root
|
Group | None
|
Write |
None
|
kwargs
|
Any
|
All additional keyword arguments are passed to h5py.File. |
{}
|
Source code in src/msl/io/writers/hdf5.py
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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
JSONWriter
¤
Bases: Writer
Writer for a JSON file format.
You can use this Writer as a context manager, for example,
with JSONWriter("my_file.json") as root:
root.update_context_kwargs(indent=4)
dset = root.create_dataset("dset", data=[1, 2, 3])
This will automatically write root to the specified file using four spaces as the indentation
level (instead of the default value of two spaces) when the with block exits.
Source code in src/msl/io/base.py
75 76 77 78 79 80 81 82 83 84 | |
write
¤
write(
file: PathLike | WriteLike | None = None,
root: Group | None = None,
**kwargs: Any,
) -> None
Write to a JSON file.
The first line in the output file contains a description that the file was created by the
JSONWriter. It begins with a # and contains a version number.
Version 1.0 specifications:
-
Use the dtype and data keys to uniquely identify a JSON object as a Dataset.
-
If a Metadata key has a value that is a Metadata object then the key becomes the name of a Group and the value becomes Metadata of that Group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
PathLike | WriteLike | None
|
The file to write a root to. If |
None
|
root
|
Group | None
|
Write |
None
|
kwargs
|
Any
|
{}
|
Source code in src/msl/io/writers/json_.py
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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |