Model Records API
Description
A model record is a record that belongs to a specific Model, a specific Experiment, Season and Site.
It is defined by the following properties:
| Property | Type | Description |
|---|---|---|
id |
UUID |
The unique identifier of the model record. |
timestamp |
datetime |
The timestamp of the record. |
collection_date |
date |
The collection date of the record. |
model_name |
string |
The name of the associated model. |
model_id |
UUID |
The ID of the associated model. |
model_data |
dict |
The data associated with the model record. |
dataset_id |
UUID |
The ID of the associated dataset. |
dataset_name |
string |
The name of the associated dataset. |
experiment_name |
string |
The name of the associated experiment. |
experiment_id |
UUID |
The ID of the associated experiment. |
season_name |
string |
The name of the associated season. |
season_id |
UUID |
The ID of the associated season. |
site_name |
string |
The name of the associated site. |
site_id |
UUID |
The ID of the associated site. |
record_file |
string |
The file path for the record data in the object storage. |
record_info |
dict |
Additional information about the record. |
A model record is uniquely identified within a model by its timestamp, model_name, dataset_name, experiment_name, season_name, and site_name. There will be no two model records with the same timestamp and belonging to the same model, dataset, experiment, season and site.
Module
This module defines the ModelRecord class, which represents a record of a model, including metadata, associations to datasets and experiments, and file handling capabilities.
It includes methods for creating, retrieving, updating, and deleting model records, as well as methods for checking existence, searching, and managing file handling for records.
This module includes the following methods:
exists: Check if a model record with the given parameters exists.create: Create a new model record.get_by_id: Retrieve a model record by its ID.get_all: Retrieve all model records.search: Search for model records based on various criteria.update: Update the details of a model record.delete: Delete a model record.refresh: Refresh the model record's data from the database.get_info: Get the additional information of the model record.set_info: Set the additional information of the model record.- File handling methods from FileHandlerMixin for managing record files.
ModelRecord
Bases: APIBase, FileHandlerMixin
Represents a record of a model, including metadata, associations to datasets and experiments, and file handling capabilities.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
Optional[ID]
|
The unique identifier of the model record. |
timestamp |
Optional[datetime]
|
The timestamp of the record. |
collection_date |
Optional[date]
|
The collection date of the record. |
dataset_id |
Optional[ID]
|
The ID of the associated dataset. |
dataset_name |
Optional[str]
|
The name of the associated dataset. |
model_id |
Optional[ID]
|
The ID of the associated model. |
model_name |
Optional[str]
|
The name of the associated model. |
model_data |
Optional[dict]
|
The data content of the model record. |
experiment_id |
Optional[ID]
|
The ID of the associated experiment. |
experiment_name |
Optional[str] = None |
|
season_id |
Optional[ID]
|
Optional[ID] = None |
season_name |
Optional[str]
|
Optional[str] = None |
site_id |
Optional[ID]
|
Optional[ID] = None |
site_name |
Optional[str]
|
Optional[str] = None |
record_file |
Optional[str]
|
Optional[str] = None |
record_info |
Optional[dict]
|
Optional[dict] = None |
Source code in gemini/api/model_record.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 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 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 386 387 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 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 | |
__repr__()
Return a detailed string representation of the ModelRecord object.
Source code in gemini/api/model_record.py
__str__()
Return a string representation of the ModelRecord object.
Source code in gemini/api/model_record.py
create(timestamp=datetime.now(), collection_date=None, dataset_name=None, model_name=None, model_data=None, experiment_name=None, site_name=None, season_name=None, record_file=None, record_info=None, insert_on_create=True)
classmethod
Create a new model record.
Examples:
>>> model_record = ModelRecord.create(
... timestamp=datetime.now(),
... collection_date=date.today(),
... dataset_name="example_dataset",
... model_name="example_model",
... model_data={"key": "value"},
... experiment_name="example_experiment",
... site_name="example_site",
... season_name="example_season",
... record_file="path/to/record_file.txt",
... record_info={"info_key": "info_value"},
... insert_on_create=True
... )
>>> print(model_record)
ModelRecord(id=UUID(...), timestamp=2023-10-01 12:00:00, model_name=example_model, model_data={...}, dataset_name=example_dataset, experiment_name=example_experiment, site_name=example_site, season_name=example_season)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timestamp
|
datetime
|
The timestamp of the model record. Defaults to the current time. |
now()
|
collection_date
|
date
|
The collection date of the model record. Defaults to the timestamp's date. |
None
|
dataset_name
|
str
|
The name of the associated dataset. Required. |
None
|
model_name
|
str
|
The name of the associated model. Required. |
None
|
model_data
|
dict
|
The data content of the model record. Defaults to an empty dictionary |
None
|
experiment_name
|
str
|
The name of the associated experiment. Optional. |
None
|
site_name
|
str
|
The name of the associated site. Optional. |
None
|
season_name
|
str
|
The name of the associated season. Optional. |
None
|
record_file
|
str
|
The file path of the model record. Optional. |
None
|
record_info
|
dict
|
Additional information about the model record. Defaults to an empty dictionary. |
None
|
insert_on_create
|
bool
|
Whether to insert the record into the database upon creation. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
Optional[ModelRecord]
|
Optional["ModelRecord"]: The created model record, or None if an error occurred. |
Source code in gemini/api/model_record.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 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 | |
create_file_uri(record)
classmethod
Create a file URI for the given model record.
Examples:
>>> record = ModelRecord(
... timestamp=datetime.now(),
... collection_date=date.today(),
... dataset_name="example_dataset",
... model_name="example_model",
... model_data={"key": "value"},
... experiment_name="example_experiment",
... site_name="example_site",
... season_name="example_season",
... record_file="path/to/record_file.txt",
... record_info={"info_key": "info_value"}
... )
>>> file_uri = ModelRecord.create_file_uri(record)
>>> print(file_uri)
model_data/example_experiment/example_model/example_dataset/2023-10-01/example_site/example_season/1700000000000.txt
Returns:
| Type | Description |
|---|---|
Optional[str]
|
Optional[str]: The file URI, or None if creation failed. |
Source code in gemini/api/model_record.py
delete()
Delete the model record.
Examples:
>>> model_record = ModelRecord.get_by_id(UUID('...'))
>>> deleted = model_record.delete()
>>> print(deleted)
True
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the model record was deleted, False otherwise. |
Source code in gemini/api/model_record.py
exists(timestamp, model_name, dataset_name, experiment_name, season_name, site_name)
classmethod
Check if a model record with the given parameters exists.
Examples:
>>> ModelRecord.exists(
... timestamp=datetime.now(),
... model_name="example_model",
... dataset_name="example_dataset",
... experiment_name="example_experiment",
... season_name="example_season",
... site_name="example_site"
... )
True
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timestamp
|
datetime
|
The timestamp of the model record. |
required |
model_name
|
str
|
The name of the model. |
required |
dataset_name
|
str
|
The name of the dataset. |
required |
experiment_name
|
str
|
The name of the experiment. |
required |
season_name
|
str
|
The name of the season. |
required |
site_name
|
str
|
The name of the site. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the model record exists, False otherwise. |
Source code in gemini/api/model_record.py
filter(model_names=None, dataset_names=None, start_timestamp=None, end_timestamp=None, experiment_names=None, site_names=None, season_names=None)
classmethod
Filter model records based on custom logic.
Examples:
>>> for record in ModelRecord.filter(
... model_names=["example_model"],
... dataset_names=["example_dataset"],
... start_timestamp=datetime(2023, 1, 1),
... end_timestamp=datetime(2023, 12, 31),
... experiment_names=["example_experiment"],
... site_names=["example_site"],
... season_names=["example_season"]
... ):
... print(record)
ModelRecord(id=UUID(...), timestamp=2023-10-01 12:00:00, model_name=example_model, model_data={...}, dataset_name=example_dataset, experiment_name=example_experiment, site_name=example_site, season_name=example_season)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_names
|
List[str]
|
List of model names to filter by. Optional. |
None
|
dataset_names
|
List[str]
|
List of dataset names to filter by. Optional. |
None
|
start_timestamp
|
datetime
|
Start timestamp for filtering. Optional. |
None
|
end_timestamp
|
datetime
|
End timestamp for filtering. Optional. |
None
|
experiment_names
|
List[str]
|
List of experiment names to filter by. Optional. |
None
|
site_names
|
List[str]
|
List of site names to filter by. Optional. |
None
|
season_names
|
List[str]
|
List of season names to filter by. Optional. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
Optional[List["ModelRecord"]]: List of filtered model records, or None if not found. |
Source code in gemini/api/model_record.py
get(timestamp, model_name, dataset_name, experiment_name=None, season_name=None, site_name=None)
classmethod
Retrieve model records based on provided parameters.
Examples:
>>> model_record = ModelRecord.get(
... timestamp=datetime.now(),
... model_name="example_model",
... dataset_name="example_dataset",
... experiment_name="example_experiment",
... season_name="example_season"
... site_name="example_site"
... )
>>> print(model_record)
ModelRecord(id=UUID(...), timestamp=2023-10-01 12:00:00, model_name=example_model, model_data={...}, dataset_name=example_dataset, experiment_name=example_experiment, site_name=example_site, season_name=example_season)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timestamp
|
datetime
|
The timestamp of the model record. |
required |
model_name
|
str
|
The name of the model. |
required |
dataset_name
|
str
|
The name of the dataset. |
required |
experiment_name
|
str
|
The name of the experiment. Optional. |
None
|
season_name
|
str
|
The name of the season. Optional. |
None
|
site_name
|
str
|
The name of the site. Optional. |
None
|
Returns:
| Type | Description |
|---|---|
Optional[ModelRecord]
|
Optional[List["ModelRecord"]]: List of matching model records, or None if not found. |
Source code in gemini/api/model_record.py
get_all(limit=100)
classmethod
Retrieve all model records, up to a specified limit.
Examples:
>>> model_records = ModelRecord.get_all(limit=10)
>>> for record in model_records:
... print(record)
ModelRecord(id=UUID(...), timestamp=2023-10-01 12:00:00, model_name=example_model, model_data={...}, dataset_name=example_dataset, experiment_name=example_experiment, site_name=example_site, season_name=example_season)
ModelRecord(id=UUID(...), timestamp=2023-10-02 12:00:00, model_name=example_model2, model_data={...}, dataset_name=example_dataset2, experiment_name=example_experiment2, site_name=example_site2, season_name=example_season2)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
limit
|
int
|
The maximum number of model records to retrieve. Defaults to 100. |
100
|
Returns:
| Type | Description |
|---|---|
Optional[List[ModelRecord]]
|
Optional[List["ModelRecord"]]: List of model records, or None if not found. |
Source code in gemini/api/model_record.py
get_by_id(id)
classmethod
Retrieve a model record by its ID
Examples:
>>> model_record = ModelRecord.get_by_id(UUID('...'))
>>> print(model_record)
ModelRecord(id=UUID(...), timestamp=2023-10-01 12:00:00, model_name=example_model, model_data={...}, dataset_name=example_dataset, experiment_name=example_experiment, site_name=example_site, season_name=example_season)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
UUID | int | str
|
The unique identifier of the model record. |
required |
Returns:
| Type | Description |
|---|---|
Optional[ModelRecord]
|
Optional["ModelRecord"]: The model record, or None if not found. |
Source code in gemini/api/model_record.py
get_info()
Get the additional information of the model record.
Examples:
>>> model_record = ModelRecord.get_by_id(UUID('...'))
>>> record_info = model_record.get_info()
>>> print(record_info)
{'info_key': 'info_value'}
Returns:
| Type | Description |
|---|---|
Optional[dict]
|
Optional[dict]: The model record's info, or None if not found. |
Source code in gemini/api/model_record.py
insert(records)
classmethod
Insert a list of model records into the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
records
|
List[ModelRecord]
|
List of model records to insert. |
required |
Returns:
| Type | Description |
|---|---|
tuple[bool, List[str]]
|
tuple[bool, List[str]]: Success status and list of inserted record IDs. |
Source code in gemini/api/model_record.py
process_record(record)
classmethod
Process a model record (custom logic).
This method handles the file upload to the storage provider and updates the record's file URI.
Examples:
>>> record = ModelRecord(
... timestamp=datetime.now(),
... collection_date=date.today(),
... dataset_name="example_dataset",
... model_name="example_model",
... model_data={"key": "value"},
... experiment_name="example_experiment",
... site_name="example_site",
... season_name="example_season",
... record_file="path/to/record_file.txt",
... record_info={"info_key": "info_value"}
... )
>>> processed_record = ModelRecord.process_record(record)
>>> print(processed_record)
ModelRecord(id=UUID(...), timestamp=2023-10-01 12:00:00, model_name=example_model, model_data={...}, dataset_name=example_dataset, experiment_name=example_experiment, site_name=example_site, season_name=example_season)
Args: record (ModelRecord): The model record to process.
Returns:
| Name | Type | Description |
|---|---|---|
ModelRecord |
ModelRecord
|
The processed model record. |
Source code in gemini/api/model_record.py
refresh()
Refresh the model record's data from the database. It is rarely called by the user as it is automatically called on access.
Examples:
>>> model_record = ModelRecord.get_by_id(UUID('...'))
>>> refreshed_record = model_record.refresh()
>>> print(refreshed_record)
ModelRecord(id=UUID(...), timestamp=2023-10-01 12:00:00, model_name=example_model, model_data={...}, dataset_name=example_dataset, experiment_name=example_experiment, site_name=example_site, season_name=example_season)
Returns:
| Type | Description |
|---|---|
Optional[ModelRecord]
|
Optional["ModelRecord"]: The refreshed model record, or None if an error occurred. |
Source code in gemini/api/model_record.py
search(model_name=None, model_data=None, dataset_name=None, experiment_name=None, site_name=None, season_name=None, collection_date=None, record_info=None)
classmethod
Search for model records based on various criteria.
Examples:
>>> for record in ModelRecord.search(
... model_name="example_model",
... dataset_name="example_dataset",
... experiment_name="example_experiment",
... site_name="example_site",
... season_name="example_season",
... collection_date=date.today(),
... record_info={"info_key": "info_value"}
... ):
... print(record)
ModelRecord(id=UUID(...), timestamp=2023-10-01 12:00:00, model_name=example_model, model_data={...}, dataset_name=example_dataset, experiment_name=example_experiment, site_name=example_site, season_name=example_season)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
The name of the model. Optional. |
None
|
model_data
|
dict
|
The data content of the model record. Optional. |
None
|
dataset_name
|
str
|
The name of the associated dataset. Optional. |
None
|
experiment_name
|
str
|
The name of the associated experiment. Optional. |
None
|
site_name
|
str
|
The name of the associated site. Optional. |
None
|
season_name
|
str
|
The name of the associated season. Optional. |
None
|
collection_date
|
date
|
The collection date of the model record. Optional. |
None
|
record_info
|
dict
|
Additional information about the model record. Optional. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
Optional[List["ModelRecord"]]: List of matching model records, or None if not found. |
Source code in gemini/api/model_record.py
set_info(record_info)
Set the additional information of the model record.
Examples:
>>> model_record = ModelRecord.get_by_id(UUID('...'))
>>> record_info = model_record.get_info()
>>> print(record_info)
{'info_key': 'info_value'}
Returns:
| Type | Description |
|---|---|
Optional[ModelRecord]
|
Optional["ModelRecord"]: The updated model record, or None if an error occurred. |
Source code in gemini/api/model_record.py
update(model_data=None, record_info=None)
Update the details of the model record.
Examples:
>>> model_record = ModelRecord.get_by_id(UUID('...'))
>>> updated_record = model_record.update(
... model_data={"new_key": "new_value"},
... record_info={"new_info_key": "new_info_value"}
... )
>>> print(updated_record)
ModelRecord(id=UUID(...), timestamp=2023-10-01 12:00:00, model_name=example_model, model_data={...}, dataset_name=example_dataset, experiment_name=example_experiment, site_name=example_site, season_name=example_season)
Returns:
| Type | Description |
|---|---|
Optional[ModelRecord]
|
Optional["ModelRecord"]: The updated model record, or None if an error occurred. |