bgc_data_processing.parsers
¶
Parsing tools to determine date ranges.
TomlParser(filepath, check_types=True)
¶
Parsing class for config.toml.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath |
Path | str
|
Path to the config file. |
required |
check_types |
bool
|
Whether to check types or not., by default True |
True
|
Source code in src/bgc_data_processing/parsers.py
41 42 43 44 45 46 47 |
|
filepath = Path(filepath)
instance-attribute
¶
raise_if_wrong_type_below(keys)
¶
Verify types for all variables 'below' keys level.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys |
list[str]
|
'Root' level which to start checking types after |
required |
Raises:
Type | Description |
---|---|
TypeError
|
if self._elements is not a dictionnary. |
Source code in src/bgc_data_processing/parsers.py
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 |
|
raise_if_wrong_type(keys)
¶
Raise a TypeError if the variable type is none of the specified types.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys |
list[str]
|
List path to the variable: ["VAR1", "VAR2", "VAR3"] is the path to the variable VAR1.VAR2.VAR3 in the toml. |
required |
Raises:
Type | Description |
---|---|
TypeError
|
If the variable doesn't match any of the required types. |
Source code in src/bgc_data_processing/parsers.py
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 |
|
ConfigParser(filepath, check_types=True, dates_vars_keys=None, dirs_vars_keys=None, existing_directory='raise')
¶
Bases: TomlParser
Class to parse toml config scripts.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath |
Path | str
|
Path to the file. |
required |
check_types |
bool
|
Whether to check types or not., by default True |
True
|
dates_vars_keys |
list[str | list[str]] | None
|
Keys to variable defining dates., by default None |
None
|
dirs_vars_keys |
list[str | list[str]] | None
|
Keys to variable defining directories., by default None |
None
|
existing_directory |
str
|
Behavior for directory creation, 'raise' raises an error if the directory exists and is not empty, 'merge' will keep the directory as is but might replace its content when savong file and 'clean' will erase the directory if it exists. |
'raise'
|
Source code in src/bgc_data_processing/parsers.py
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 |
|
dates_vars_keys = []
instance-attribute
¶
dirs_vars_keys: list[list[str]] = []
instance-attribute
¶
existing_dir_behavior = existing_directory
instance-attribute
¶
parse()
¶
Parse the elements to verify types, convert dates and create directries.
Returns:
Type | Description |
---|---|
dict
|
Transformed dictionnary |
Source code in src/bgc_data_processing/parsers.py
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 |
|
get(keys)
¶
Get a variable by giving the list of keys to reach the variable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys |
list[str]
|
Keys to the variable. |
required |
Returns:
Type | Description |
---|---|
Any
|
The desired variable. |
Source code in src/bgc_data_processing/parsers.py
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 |
|
__getitem__(__k)
¶
Return self._elements[__k].
Parameters:
Name | Type | Description | Default |
---|---|---|---|
__k |
str
|
Key |
required |
Returns:
Type | Description |
---|---|
Any
|
Value associated to __k. |
Source code in src/bgc_data_processing/parsers.py
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 |
|
__repr__()
¶
Represent the object as a string.
Returns:
Type | Description |
---|---|
str
|
self._elements.repr() |
Source code in src/bgc_data_processing/parsers.py
438 439 440 441 442 443 444 445 446 |
|
DefaultTemplatesParser
¶
Bases: TomlParser
Parser for variables.toml to create Template Variables.
variables: dict[str, TemplateVar]
property
¶
Return the dictionnary with all created variables.
Returns:
Type | Description |
---|---|
dict[str, TemplateVar]
|
Dictionnary mapping variables names to variables templates. |
to_list()
¶
Return the variable ensemble as a list.
Returns:
Type | Description |
---|---|
list[TemplateVar]
|
LIst of all templates. |
Source code in src/bgc_data_processing/parsers.py
452 453 454 455 456 457 458 459 460 |
|
__getitem__(__k)
¶
Return self.variables[__k].
Parameters:
Name | Type | Description | Default |
---|---|---|---|
__k |
str
|
Variable name as defined in variables.toml. |
required |
Returns:
Type | Description |
---|---|
TemplateVar
|
Template Variable associated to __k. |
Source code in src/bgc_data_processing/parsers.py
462 463 464 465 466 467 468 469 470 471 472 473 474 475 |
|
WaterMassesParser
¶
Bases: TomlParser
Parser for water_masses.toml to create WaterMass objects.
variables: dict[str, WaterMass]
property
¶
Return the dictionnary with all created WaterMass.
Returns:
Type | Description |
---|---|
dict[str, WaterMass]
|
Dictionnary mapping WaterMass acronyms to WaterMass. |
__getitem__(__k)
¶
Return self.variables[__k].
Parameters:
Name | Type | Description | Default |
---|---|---|---|
__k |
str
|
WaterMass acronym as defined in water_masses.toml. |
required |
Returns:
Type | Description |
---|---|
WaterMass
|
WaterMass associated to __k. |
Source code in src/bgc_data_processing/parsers.py
533 534 535 536 537 538 539 540 541 542 543 544 545 546 |
|
directory_check(get_variable)
¶
Use as decorator to create directories only when needed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
get_variable |
Callable
|
get of getitem function. |
required |
Returns:
Type | Description |
---|---|
Callable
|
Wrapper function. |
Raises:
Type | Description |
---|---|
IsADirectoryError
|
If the directory exists |
Source code in src/bgc_data_processing/parsers.py
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 |
|