Array Lists¶
SimStack II provides a specialized way to handle collections of arrays (typically numpy arrays) through the ArrayList and ArrayStorage models.
ArrayStorage¶
ArrayStorage is the model used to store an individual array. It handles compression and serialization of the array data.
Key Features:
Compression: Array data is automatically compressed before being stored in the database.
Shape Preservation: Automatically stores and restores the shape of the array.
Property Access: Use the
arrayproperty to get or set the numpy array directly.
Usage:
import numpy as np
from simstack.models.array_storage import ArrayStorage
storage = ArrayStorage(name="my_array")
storage.array = np.random.rand(10, 10)
ArrayList¶
ArrayList is a top-level Model that stores a collection of ArrayStorage objects. Like FileListModel, it inherits from ObjectListMixin, providing a familiar list-like interface.
Usage:
from simstack.models.array_list import ArrayList
from simstack.models.array_storage import ArrayStorage
import numpy as np
array_list = ArrayList()
storage = ArrayStorage(name="first")
storage.array = np.zeros((5, 5))
array_list.append(storage)
API Reference¶
- class simstack.models.array_list.ArrayList(*, elements: list[ObjectId] = <factory>, id: ObjectId = <factory>)[source]¶
Bases:
Model,ObjectListMixin[ArrayStorage]- async custom_model_dump(**kwargs) Dict[str, Any]¶
Custom model dump method to handle the conversion of model instances to dictionaries. This method recursively traverses dictionaries and lists to convert any nested model instances to their dictionary representation.
- Parameters:
self – The model instance
kwargs – Additional keyword arguments
- Returns:
A dictionary representation of the model instance
- elements: list[ObjectId] = <odmantic.field.FieldProxy object>¶
- classmethod from_dict(data: dict, **kwargs) Any¶
Create an instance of the model from a dictionary. Handles nested models and enum values.
- classmethod from_model(model: Model, **kwargs) Model¶
- id: ObjectId = <odmantic.field.FieldProxy object>¶
- classmethod json_schema()¶
Generates a JSON schema for the given class and its fields, but eliminates all fields which are models, embedded models, or references to models.
- Parameters:
cls
- Returns:
- model_config = {'arbitrary_types_allowed': False, 'collection': None, 'extra': None, 'indexes': None, 'json_schema_extra': None, 'parse_doc_with_default_factories': False, 'str_strip_whitespace': False, 'title': None, 'validate_assignment': True, 'validate_default': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- classmethod ui_make_title(ui_schema: Dict[str, Any], field: str, title: str) dict¶
Adds a title to the JSON schema.
- Parameters:
cls – The class to which the JSON schema belongs
ui_schema – The original ui_schema schema
title – Title to be added
- Returns:
Modified JSON schema with title
- classmethod ui_schema()¶
Generates a UI schema that uses GenericForm for fields with ui_schema function. Also preserves any existing UI schema configurations from the class.
- Parameters:
cls – The model class to generate UI schema for
- Returns:
The generated UI schema
- Return type:
dict
- class simstack.models.array_storage.ArrayStorage(*, name: str | None, shape: str | None = None, field_name: str | None = None, data_json: str | None = None, id: ObjectId = <factory>)[source]¶
Bases:
BytesB64Mixin,Model- property array¶
Property getter for array
- async custom_model_dump(**kwargs) Dict[str, Any]¶
Custom model dump method to handle the conversion of model instances to dictionaries. This method recursively traverses dictionaries and lists to convert any nested model instances to their dictionary representation.
- Parameters:
self – The model instance
kwargs – Additional keyword arguments
- Returns:
A dictionary representation of the model instance
- data_json: str | None = <odmantic.field.FieldProxy object>¶
- field_name: str | None = <odmantic.field.FieldProxy object>¶
- classmethod from_dict(data: dict, **kwargs) Any¶
Create an instance of the model from a dictionary. Handles nested models and enum values.
- classmethod from_model(model: Model, **kwargs) Model¶
- id: ObjectId = <odmantic.field.FieldProxy object>¶
- classmethod json_schema()¶
Generates a JSON schema for the given class and its fields, but eliminates all fields which are models, embedded models, or references to models.
- Parameters:
cls
- Returns:
- make_column_defs_instance(table_name=None, max_recursion_level=1, drop_id=True, current_level=0, visited=None, field_prefix='')[source]¶
- make_table_entries(max_recursion_level=1, drop_id=True, current_level=0, visited=None, field_prefix='')[source]¶
- model_config = {'arbitrary_types_allowed': False, 'collection': None, 'extra': None, 'indexes': None, 'json_encoders': {<class 'bytes'>: <function BytesB64Mixin.<lambda>>}, 'json_schema_extra': None, 'parse_doc_with_default_factories': False, 'str_strip_whitespace': False, 'title': None, 'validate_assignment': True, 'validate_default': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- name: str | None = <odmantic.field.FieldProxy object>¶
- shape: str | None = <odmantic.field.FieldProxy object>¶
- classmethod ui_make_title(ui_schema: Dict[str, Any], field: str, title: str) dict¶
Adds a title to the JSON schema.
- Parameters:
cls – The class to which the JSON schema belongs
ui_schema – The original ui_schema schema
title – Title to be added
- Returns:
Modified JSON schema with title