mfile
PROCESS MFILE.DAT IO library
process.core.io.mfile.
Notes: + 12/03/2014: Initial version + 12/03/2014: Added MFILE variable class + 12/03/2014: Added MFILE class for containing all info from file. + 12/03/2014: Added ability to read MFILE.DAT into class + 12/03/2014: Added ability write MFILE.DAT from class + 12/05/2014: Fixed mfile issue with strings in MFILE.DAT with no scans + 16/05/2014: Cleaned up MFileVariable + 19/05/2014: Cleaned up MFile and put some functions outside class. + 12/06/2014: Fixed error handling for "variable not in MFILE" errors + 16/06/2014: Fixed library path error; fix in get_scans + 24/11/2021: Global dictionary variables moved within the functions to avoid cyclic dependencies. This is because the dicts generation script imports, and inspects, process.
Compatible with PROCESS version 286
MFileVariable
Bases: dict
Class for containing a single mfile variable
Source code in process/core/io/mfile.py
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 | |
var_name = var_name
instance-attribute
var_description = var_description
instance-attribute
var_unit = var_unit
instance-attribute
var_flag = var_flag
instance-attribute
latest_scan = 0
instance-attribute
exists
property
set_scan(scan_number, scan_value)
Sets the class attribute self.scan# where # is scan number
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scan_number
|
scan number |
required | |
scan_value
|
value of parameter for scan |
required |
Source code in process/core/io/mfile.py
66 67 68 69 70 71 72 73 74 75 76 77 78 | |
get_scan(scan_number)
Returns the value of a specific scan. For scan = -1 or None the last scan is given.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scan_number
|
scan number to return |
required |
Returns:
| Type | Description |
|---|---|
type
|
[single scan requested] |
Source code in process/core/io/mfile.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
get_scans()
Returns a list of scan values in order of scan number
Returns:
| Type | Description |
|---|---|
[List of all scans for variable]
|
|
Source code in process/core/io/mfile.py
99 100 101 102 103 104 105 106 107 | |
get_number_of_scans()
Function to return the number of scans in the variable class
Source code in process/core/io/mfile.py
109 110 111 | |
MFileErrorClass
Error class for handling missing data from MFILE
Source code in process/core/io/mfile.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
item = item
instance-attribute
get_scan = self.get_error
instance-attribute
get_scans = self.get_error
instance-attribute
set_scan = self.get_error
instance-attribute
get_number_of_scans = self.get_error
instance-attribute
exists
property
get_error(*args, **kwargs)
Source code in process/core/io/mfile.py
128 129 130 131 132 133 134 135 136 137 | |
MFileDataDictionary
Bases: OrderedDict
Class object to act as a dictionary for the data.
Source code in process/core/io/mfile.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
DefaultOrderedDict
Bases: OrderedDict
Source code in process/core/io/mfile.py
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 | |
default_factory = default_factory
instance-attribute
copy()
Source code in process/core/io/mfile.py
184 185 | |
MFile
Class object to store the MFile Objects
Source code in process/core/io/mfile.py
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 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 373 374 375 376 377 378 379 380 381 382 383 384 385 | |
filename = filename
instance-attribute
data = DefaultOrderedDict()
instance-attribute
mfile_lines = []
instance-attribute
mfile_modules = {}
instance-attribute
des_name = []
instance-attribute
current_module = 'Misc'
instance-attribute
get_variables(*variables, scan=-1)
Get a number of variables from a single scan
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*variables
|
str
|
|
()
|
scan
|
int
|
(Default value = -1) |
-1
|
Source code in process/core/io/mfile.py
216 217 218 219 220 221 222 223 224 225 226 | |
get(variable, *, scan=-1)
Get variable data from a given scan
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable
|
str
|
|
required |
scan
|
int
|
(Default value = -1) |
-1
|
Source code in process/core/io/mfile.py
228 229 230 231 232 233 234 235 236 237 238 | |
open_mfile()
Function to open MFILE.DAT
Source code in process/core/io/mfile.py
240 241 242 243 244 245 246 247 248 249 | |
parse_mfile()
Function to parse MFILE.DAT
Source code in process/core/io/mfile.py
251 252 253 254 255 256 | |
add_line(line)
Function to read the line from MFILE and add to the appropriate class or create a new class if it is the first instance of it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
|
required |
Source code in process/core/io/mfile.py
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 | |
add_to_mfile_variable(des, name, value, unit, flag, scan=None)
Function to add value to MFile class for that name/description
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
des
|
|
required | |
name
|
|
required | |
value
|
|
required | |
unit
|
|
required | |
flag
|
|
required | |
scan
|
(Default value = None) |
None
|
Source code in process/core/io/mfile.py
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 | |
write_to_json(keys_to_write=None, scan=-1, verbose=False)
Write MFILE object to JSON file
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
keys_to_write
|
(Default value = None) |
None
|
|
scan
|
(Default value = -1) |
-1
|
|
verbose
|
(Default value = False) |
False
|
Source code in process/core/io/mfile.py
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 373 374 375 376 377 378 379 380 381 382 383 384 385 | |
sort_value(value_words)
Parse value section of a line in MFILE.
value_words is a list of strings, which is then parsed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value_words
|
List[str]
|
value of var in MFILE as list of strings |
required |
value_words
|
list[str]
|
|
required |
Returns:
| Type | Description |
|---|---|
Union[str, float]
|
string or float representation of value list |
Source code in process/core/io/mfile.py
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 | |
sort_brackets(var)
Function to sort bracket madness on variable name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
var
|
|
required |
Source code in process/core/io/mfile.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 | |
clean_line(line)
Cleans an MFILE line into the three parts we care about
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
|
required |
Source code in process/core/io/mfile.py
434 435 436 437 438 439 440 441 442 | |
search_keys(dictionary, variable)
Searches the dictionary keys for matches to the variable name 'variable' in arguments.
Puts everything into lower case before searching.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dictionary
|
dictionary to search in |
required | |
variable
|
variable name to search for |
required |
Returns:
| Type | Description |
|---|---|
|
List of matches to the searched for variable |
Source code in process/core/io/mfile.py
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 | |
search_des(dictionary, description)
Searches the dictionary descriptions for matches to the description 'description' from the arguments.
Puts everything into lower case before searching.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dictionary
|
dictionary to search in |
required | |
variable
|
variable name to search for |
required |
Returns:
| Type | Description |
|---|---|
|
List of matches to the searched for description |
Source code in process/core/io/mfile.py
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 | |
get_unit(variable_desc)
Returns the unit from a variable description if possible, else None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_desc
|
|
required |
Source code in process/core/io/mfile.py
488 489 490 491 492 493 494 495 496 497 498 499 | |
is_number(val)
Check MFILE data entry
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
val
|
|
required |
Source code in process/core/io/mfile.py
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 | |