DataSet Manager API Documentation
Container for experiment metadata and associated data file locations.
A DataSet instance describes a single experiment or dataset in terms of:
- Basic metadata: name, creation date, experiment date/time, device identifier.
- User annotations: free-form notes and a simple time-stamped console log.
- File layout: a mapping from human-readable labels to absolute file paths.
- Optional colour mapping: label-to-colour mapping for consistent plotting.
- Structure type: how files are organised on disk (e.g. flat vs. directory-labelled).
The class does not interpret the contents of the files; it only tracks their
locations and minimal metadata. Filepaths can be:
- Added manually via add_filepath, or
- Auto-populated from a root directory using construct_filepaths(...).
Structure types
"flat": A simple one-level mapping from label -> file path. This is the default and most common mode;construct_filepaths_nrecursivewill scan a single directory and register all supported files using their stem as label."dirlabelled": A directory-labelled mode where each top-level directory becomes a label and contains its own mapping of files. This is handled byconstruct_structured_filepathsand is considered deprecated in favour of the genericconstruct_filepaths."structured": Reserved for legacy/experimental layouts; treated as an allowed but user-managed structure type.
Validation
All paths added to the dataset are checked for:
- Existence on disk.
- Being a file (not a directory).
- Having an extension in the accepted set (xlsx, xls, csv,
txt, dpt, json).
Two DataSet instances are considered equal if all their attributes
(including filepaths, colours, and metadata) match exactly.
Source code in dataset_manager\dataset.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 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 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 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 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 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 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 | |
construct_filepaths_nrecursive(root_dir)
Will generate a flat file set and add it to the current filepaths. This will seek all files and of the giver root_dir and append all dataset files to the filepaths attribute. Note that root_dir should be an absolute path.
Source code in dataset_manager\dataset.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
construct_structured_filepaths(root_dir)
Will generate a dirlabelled file set and add it to the current filepaths. This will seek all files and subdirectories of the giver root_dir and append all dataset files to the filepaths attribute. Note that root_dir should be an absolute path.
Source code in dataset_manager\dataset.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
Bases: JSONEncoder
JSON encoder for DataSet objects and related dataclasses.
This encoder provides two custom behaviours:
datetime.datetimeinstances are serialised to a compact string representation using the format"%Y.%m.%d_%H.%M.%S". This matches the format expected byDataSetand the corresponding JSON decoder.- All other objects are serialised via their
__dict__attribute, which is sufficient for simple container-like classes such asDataSet.
The encoder is intended to be used together with DataSetJSONEncoder to
provide a round-trip-safe JSON representation of datasets.
Source code in dataset_manager\dataset_json_encoder.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | |
Bases: JSONDecoder
Custom JSON decoder that reconstructs DataSet instances from JSON.
This decoder installs an object_hook that:
- Detects dictionaries carrying the expected DataSet fields
(e.g. creation_date, name, device, experiment_date_time,
notes, console, structure_type, filepaths, colours).
- Instantiates a new DataSet using the stored creation date.
- Replays all relevant setters to restore metadata, structure type, paths,
colours, and annotations.
If a JSON object does not match the expected shape, it is returned unchanged,
allowing non-DataSet data to be decoded normally.
Source code in dataset_manager\dataset_json_decoder.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
Small helper class for persisting DataSet instances to and from JSON files.
Responsibilities
save_dataset(dataset, file_name): Serialises aDataSetinstance to disk usingDataSetJSONEncoder. The method checks that the passed object is aDataSetand writes the encoded JSON to the given file path.open_dataset(file_name): Opens a JSON file and deserialises it into aDataSetinstance usingDataSetJSONDecoder.
The manager does not interpret the dataset content; it only handles the
IO and wiring between JSON encoder/decoder and the underlying DataSet
objects.
Source code in dataset_manager\dataset_manager.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
save_dataset(dataset, file_name)
staticmethod
Saves the dataset_manager data into a JSON file
Source code in dataset_manager\dataset_manager.py
29 30 31 32 33 34 35 36 37 38 | |