db
Data handling tools for the ROMI project (plantdb).Link
This module provides a structured API for interacting with a database in the context of the ROMI project.
It defines abstract classes for representing databases (DB), scans (Scan), filesets (Fileset), and individual files (File).
These classes allow for consistent data organization, retrieval, and manipulation.
Key FeaturesLink
- Hierarchical Data Model: Organizes data into a multi-level structure with Databases containing Scans, which in turn contain Filesets of Files.
- Abstract Interfaces: Defines interfaces that must be implemented to interact with actual databases or storage systems.
- Metadata Handling: Provides methods for associating metadata with scans and filesets.
- File Management: Supports file creation, deletion, importing, reading, and writing.
ImplementationLink
The following classes are defined:
- A database
DBcontains a list of scansScandistinguishable by their id. - A
Scanis made of several sets of filesFileset. - A
Filesetis made of a list of filesFile. - A
Filecan be any other data format.
It should be subclassed to implement an actual database interface.
See plantdb.commons.fsdb.core for a concrete implementation.
DB
Link
DB()
Bases: object
Class defining the database object DB.
Abstract class defining the API used to communicate with a database in the ROMI project.
- Reference API commons commons
Source code in plantdb/commons/db.py
61 62 63 64 65 66 | |
connect
Link
connect(login_data=None)
Connect to the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list or dict
|
Use this to access to a |
None
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
68 69 70 71 72 73 74 75 76 77 78 79 80 | |
create_scan
Link
create_scan(id)
Create a new scan object in the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Id of the scan to retrieve |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
114 115 116 117 118 119 120 121 122 123 124 125 126 | |
create_timelapse
Link
Create a new timelapse object in the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Id of the timelapse to create. |
required |
|
dict
|
Metadata for the timelapse. |
None
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
delete_scan
Link
delete_scan(id)
Delete a scan from the DB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Id of the scan to delete |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
128 129 130 131 132 133 134 135 136 137 138 139 140 | |
delete_timelapse
Link
Delete a timelapse container from the DB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Id of the timelapse to delete. |
required |
|
bool
|
Whether to delete member scans recursively. |
False
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
disconnect
Link
disconnect()
Disconnect from the database.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
82 83 84 85 86 87 88 89 | |
get_scan
Link
get_scan(id)
Get a scan saved in the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Id of the scan instance to retrieve. |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
100 101 102 103 104 105 106 107 108 109 110 111 112 | |
get_scans
Link
get_scans()
Get the list of scans saved in the database.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
91 92 93 94 95 96 97 98 | |
get_timelapse
Link
get_timelapse(id)
Get a timelapse container saved in the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Id of the timelapse instance to retrieve. |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
151 152 153 154 155 156 157 158 159 160 161 162 163 | |
get_timelapses
Link
get_timelapses()
Get the list of timelapses saved in the database.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
142 143 144 145 146 147 148 149 | |
DBBusyError
Link
DBBusyError(message)
Bases: OSError
Raises an error if the database is busy.
This error is raised when the database is busy and an operation cannot be done on it.
Source code in plantdb/commons/db.py
817 818 | |
File
Link
Bases: object
Class defining a file File contained in a Fileset.
Abstract class defining the API used to represent a file in the ROMI project.
Attributes:
| Name | Type | Description |
|---|---|---|
db |
DB
|
Database instance where to find the scan, fileset and file. |
scan |
Scan
|
Scan instance containing the fileset and file. |
fileset |
Fileset
|
Fileset instance containing the file. |
id |
str
|
Id of the file instance. |
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Fileset
|
Instance containing the file. |
required |
|
str
|
Id of the file instance. |
required |
Other Parameters:
| Name | Type | Description |
|---|---|---|
ext |
str
|
The extension of the file. |
Source code in plantdb/commons/db.py
643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 | |
get_db
Link
get_db()
Get parent database instance.
Returns:
| Type | Description |
|---|---|
DB
|
The parent database instance. |
Source code in plantdb/commons/db.py
675 676 677 678 679 680 681 682 683 | |
get_fileset
Link
get_fileset()
Get parent fileset.
Returns:
| Type | Description |
|---|---|
Fileset
|
The parent fileset instance. |
Source code in plantdb/commons/db.py
695 696 697 698 699 700 701 702 703 | |
get_id
Link
get_id()
Get file id.
Returns:
| Type | Description |
|---|---|
str
|
The id of the file instance. |
Source code in plantdb/commons/db.py
665 666 667 668 669 670 671 672 673 | |
get_metadata
Link
Get metadata associated with scan.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Metadata key to retrieve (defaults to |
None
|
|
Any
|
The default value to return if the key do not exist in the metadata.
Default is |
None
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 | |
get_scan
Link
get_scan()
Get parent scan instance.
Returns:
| Type | Description |
|---|---|
Scan
|
The parent scan instance. |
Source code in plantdb/commons/db.py
685 686 687 688 689 690 691 692 693 | |
import_file
Link
import_file(path)
Import an existing file to the File object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Path of the file to import |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
741 742 743 744 745 746 747 748 749 750 751 752 753 | |
read
Link
read()
Reads from a file.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
801 802 803 804 805 806 807 808 | |
read_raw
Link
read_raw()
Reads bytes from a file.
Returns:
| Type | Description |
|---|---|
bytearray
|
File buffer |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
771 772 773 774 775 776 777 778 779 780 781 782 783 | |
set_metadata
Link
Get metadata associated with scan.
If value is None, scan metadata is set to data.
If value is not None data is a key and is set to value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str or dict
|
Key or value to set as metadata |
required |
|
any
|
Value to set (default is |
None
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 | |
write
Link
Writes to a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Data to write |
required |
|
str
|
File extension to use |
''
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 | |
write_raw
Link
Writes bytes to a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
bytearray
|
Data to write |
required |
|
str
|
File extension to use |
''
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 | |
Fileset
Link
Bases: object
Class defining a set of files Fileset contained in a Scan.
Abstract class defining the API used to represent a set of files in the ROMI project.
Notes
Files can be 2D images, RGB pictures, text,...
Attributes:
| Name | Type | Description |
|---|---|---|
db |
DB
|
Database instance where to find the scan and fileset. |
scan |
Scan
|
Scan instance containing the fileset. |
id |
int
|
Id of the fileset instance. |
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Scan
|
Scan instance containing the fileset. |
required |
|
str
|
Id of the fileset instance. |
required |
- Reference API commons commons
Source code in plantdb/commons/db.py
494 495 496 497 498 499 500 501 502 503 504 505 506 | |
create_file
Link
create_file(id)
Create a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Id of the new file. |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
597 598 599 600 601 602 603 604 605 606 607 608 609 | |
delete_file
Link
delete_file(file_id)
Delete a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Id of the file to delete. |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
611 612 613 614 615 616 617 618 619 620 621 622 623 | |
get_db
Link
get_db()
Get parent database instance.
Returns:
| Type | Description |
|---|---|
DB
|
The parent database instance. |
Source code in plantdb/commons/db.py
518 519 520 521 522 523 524 525 526 | |
get_file
Link
get_file(id)
Get file with given id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
File instance id. |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
547 548 549 550 551 552 553 554 555 556 557 558 559 | |
get_files
Link
get_files()
Get all files.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
538 539 540 541 542 543 544 545 | |
get_id
Link
get_id()
Get the fileset instance id.
Returns:
| Type | Description |
|---|---|
str
|
The id of the fileset instance. |
Source code in plantdb/commons/db.py
508 509 510 511 512 513 514 515 516 | |
get_metadata
Link
Get metadata associated with scan.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Metadata key to retrieve, default to |
None
|
|
Any
|
The default value to return if the key do not exist in the metadata.
Default is |
None
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 | |
get_scan
Link
get_scan()
Get parent scan instance.
Returns:
| Type | Description |
|---|---|
Scan
|
The parent scan instance. |
Source code in plantdb/commons/db.py
528 529 530 531 532 533 534 535 536 | |
set_metadata
Link
Get metadata associated with scan.
If value is None, scan metadata is set to data.
If value is not None data is a key and is set to value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str or dict
|
Key or value to set as metadata. |
required |
|
any
|
Value to set, default to |
None
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 | |
Scan
Link
Bases: object
Class defining the scan object Scan.
Abstract class defining the API used to represent a scan in the ROMI project.
Attributes:
| Name | Type | Description |
|---|---|---|
db |
DB
|
Database instance where to find the scan. |
id |
int
|
Id of the scan instance. |
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
DB
|
Database instance where to find the scan. |
required |
|
str
|
Id of the scan instance. |
required |
- Reference API commons commons
Source code in plantdb/commons/db.py
343 344 345 346 347 348 349 350 351 352 353 354 | |
create_fileset
Link
create_fileset(id)
Create a fileset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Id of the new fileset. |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
445 446 447 448 449 450 451 452 453 454 455 456 457 | |
delete_fileset
Link
delete_fileset(fileset_id)
Delete a fileset from the DB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Id of the fileset to delete. |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
459 460 461 462 463 464 465 466 467 468 469 470 471 | |
get_db
Link
get_db()
Get parent database instance.
Returns:
| Type | Description |
|---|---|
DB
|
Database instance where to find the scan. |
Source code in plantdb/commons/db.py
366 367 368 369 370 371 372 373 374 | |
get_fileset
Link
get_fileset(id)
Get a fileset with a given id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Id of the fileset to be retrieved. |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
395 396 397 398 399 400 401 402 403 404 405 406 407 | |
get_filesets
Link
get_filesets()
Get all sets of files.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
386 387 388 389 390 391 392 393 | |
get_id
Link
get_id()
Get the scan instance id.
Returns:
| Type | Description |
|---|---|
str
|
Id of the scan instance. |
Source code in plantdb/commons/db.py
356 357 358 359 360 361 362 363 364 | |
get_metadata
Link
Get metadata associated with scan.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Metadata key to retrieve, default to |
None
|
|
Any
|
The default value to return if the key do not exist in the metadata.
Default is |
None
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | |
get_timelapse
Link
get_timelapse()
Get parent timelapse instance if defined, else None.
Returns:
| Type | Description |
|---|---|
TimeLapse | None
|
Parent timelapse instance or None. |
Source code in plantdb/commons/db.py
376 377 378 379 380 381 382 383 384 | |
set_metadata
Link
Get metadata associated with scan.
If value is None, scan metadata is set to data.
If value is not None data is a key and is set to value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str or dict
|
Key or value. |
required |
|
any
|
Value to set, default to |
None
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 | |
TimeLapse
Link
Bases: object
Class defining the timelapse object TimeLapse contained in a DB.
Abstract class defining the API used to represent a timelapse of scans in the ROMI project. A timelapse container groups multiple temporal scans under a shared identifier and metadata.
Attributes:
| Name | Type | Description |
|---|---|---|
db |
DB
|
Database instance where to find the timelapse container. |
id |
str
|
Id of the timelapse instance. |
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
DB
|
Database instance where to find the timelapse. |
required |
|
str
|
Id of the timelapse instance. |
required |
-
Reference API
commons
commons
db
Scanget_timelapse
Source code in plantdb/commons/db.py
212 213 214 215 216 217 218 219 220 221 222 223 | |
create_scan
Link
Create a new member scan in this timelapse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Id of the scan to create. |
required |
|
dict
|
Metadata for the scan. |
None
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
delete_scan
Link
delete_scan(id, **kwargs)
Delete a scan from this timelapse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Id of the scan to delete. |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
297 298 299 300 301 302 303 304 305 306 307 308 309 | |
get_db
Link
get_db()
Get parent database instance.
Returns:
| Type | Description |
|---|---|
DB
|
Database instance where to find the timelapse. |
Source code in plantdb/commons/db.py
235 236 237 238 239 240 241 242 243 | |
get_id
Link
get_id()
Get the timelapse instance id.
Returns:
| Type | Description |
|---|---|
str
|
Id of the timelapse instance. |
Source code in plantdb/commons/db.py
225 226 227 228 229 230 231 232 233 | |
get_metadata
Link
get_metadata(key=None, default=None)
Get metadata associated with the timelapse.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
311 312 313 314 315 316 317 318 | |
get_scan
Link
get_scan(id, **kwargs)
Get a scan belonging to this timelapse with a given id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Id of the scan instance to retrieve. |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
254 255 256 257 258 259 260 261 262 263 264 265 266 | |
get_scans
Link
get_scans(query=None, sort='timelapse.scheduled', **kwargs)
Get the list of scans belonging to this timelapse.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
245 246 247 248 249 250 251 252 | |
list_scan
Link
list_scan(query=None, fuzzy=False, sort='timelapse.scheduled', **kwargs)
Alias for list_scans.
Source code in plantdb/commons/db.py
277 278 279 | |
list_scans
Link
list_scans(query=None, fuzzy=False, sort='timelapse.scheduled', **kwargs)
List scan ids belonging to this timelapse.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
268 269 270 271 272 273 274 275 | |
set_metadata
Link
set_metadata(data, value=None)
Set metadata associated with the timelapse.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Source code in plantdb/commons/db.py
320 321 322 323 324 325 326 327 | |