cellpy.readers.sql_dbreader

Contents

cellpy.readers.sql_dbreader#

This module is an example of how to implement a custom database reader for the batch utility in cellpy.

Module Contents#

Classes#

Base

Base class for the database models.

Batch

Model for batch objects in the database.

Cell

Model for cell objects in the database.

RawData

Model for raw data objects in the database.

SQLReader

A custom database reader for the batch utility in cellpy.

Attributes#

DB_FILE_EXCEL

DB_FILE_SQLITE

DB_URI

HEADER_ROW

TABLE_NAME_EXCEL

UNIT_ROW

batch_cell_association_table

hdr_journal

class Base[source]#

Bases: sqlalchemy.orm.DeclarativeBase

Inheritance diagram of cellpy.readers.sql_dbreader.Base

Base class for the database models.

class Batch[source]#

Bases: Base

Inheritance diagram of cellpy.readers.sql_dbreader.Batch

Model for batch objects in the database.

cells: sqlalchemy.orm.Mapped[List[Cell]][source]#
comment: sqlalchemy.orm.Mapped[str | None][source]#
name: sqlalchemy.orm.Mapped[str][source]#
pk: sqlalchemy.orm.Mapped[int][source]#
class Cell[source]#

Bases: Base

Inheritance diagram of cellpy.readers.sql_dbreader.Cell

Model for cell objects in the database.

active_material_mass_fraction: sqlalchemy.orm.Mapped[float | None][source]#
area: sqlalchemy.orm.Mapped[float | None][source]#
argument: sqlalchemy.orm.Mapped[str | None][source]#
batches: sqlalchemy.orm.Mapped[List[Batch] | None][source]#
cell_design: sqlalchemy.orm.Mapped[str | None][source]#
cell_exists: sqlalchemy.orm.Mapped[bool | None][source]#
cell_group: sqlalchemy.orm.Mapped[str | None][source]#
cell_type: sqlalchemy.orm.Mapped[str | None][source]#
cellpy_file_name: sqlalchemy.orm.Mapped[str | None][source]#
channel: sqlalchemy.orm.Mapped[str | None][source]#
comment_cell: sqlalchemy.orm.Mapped[str | None][source]#
comment_general: sqlalchemy.orm.Mapped[str | None][source]#
comment_history: sqlalchemy.orm.Mapped[str | None][source]#
comment_slurry: sqlalchemy.orm.Mapped[str | None][source]#
electrolyte: sqlalchemy.orm.Mapped[str | None][source]#
experiment_type: sqlalchemy.orm.Mapped[str | None][source]#
formation: sqlalchemy.orm.Mapped[str | None][source]#
frozen: sqlalchemy.orm.Mapped[bool | None][source]#
inactive_additive_mass: sqlalchemy.orm.Mapped[float | None][source]#
instrument: sqlalchemy.orm.Mapped[str | None][source]#
label: sqlalchemy.orm.Mapped[str | None][source]#
loading_active: sqlalchemy.orm.Mapped[float | None][source]#
mass_active: sqlalchemy.orm.Mapped[float | None][source]#
mass_total: sqlalchemy.orm.Mapped[float | None][source]#
material_class: sqlalchemy.orm.Mapped[str | None][source]#
material_group_label: sqlalchemy.orm.Mapped[str | None][source]#
material_label: sqlalchemy.orm.Mapped[str | None][source]#
material_pre_processing: sqlalchemy.orm.Mapped[str | None][source]#
material_solvent: sqlalchemy.orm.Mapped[str | None][source]#
material_sub_label: sqlalchemy.orm.Mapped[str | None][source]#
material_surface_processing: sqlalchemy.orm.Mapped[str | None][source]#
name: sqlalchemy.orm.Mapped[str][source]#
nominal_capacity: sqlalchemy.orm.Mapped[float | None][source]#
pasting_thickness: sqlalchemy.orm.Mapped[str | None][source]#
pk: sqlalchemy.orm.Mapped[int][source]#
project: sqlalchemy.orm.Mapped[str | None][source]#
raw_data: sqlalchemy.orm.Mapped[List[RawData]][source]#
schedule: sqlalchemy.orm.Mapped[str | None][source]#
selected: sqlalchemy.orm.Mapped[bool | None][source]#
separator: sqlalchemy.orm.Mapped[str | None][source]#
solvent_solid_ratio: sqlalchemy.orm.Mapped[str | None][source]#
temperature: sqlalchemy.orm.Mapped[float | None][source]#
test_date: sqlalchemy.orm.Mapped[str | None][source]#
class RawData[source]#

Bases: Base

Inheritance diagram of cellpy.readers.sql_dbreader.RawData

Model for raw data objects in the database.

cell: sqlalchemy.orm.Mapped[Cell][source]#
cell_pk: sqlalchemy.orm.Mapped[int][source]#
is_file: sqlalchemy.orm.Mapped[bool][source]#
name: sqlalchemy.orm.Mapped[str][source]#
pk: sqlalchemy.orm.Mapped[int][source]#
class SQLReader(db_connection: str = None, batch: str = None, **kwargs)[source]#

Bases: cellpy.readers.core.BaseDbReader

Inheritance diagram of cellpy.readers.sql_dbreader.SQLReader

A custom database reader for the batch utility in cellpy.

Initialize the SQLReader.

add_batch_object(batch: Batch) None[source]#

Add a batch object to the database.

For this to work, you will have to create a batch object first, then populate it with data (including the cell objects that the batch refers to, see .add_cell_object), and finally add it to the database using this method.

Examples

>>> from cellpy.readers import sql_dbreader
>>> db = sql_dbreader.SQLReader()
>>> db.open_db("my_db.sqlite")
>>> # create a batch object:
>>> batch = sql_dbreader.Batch()
>>> batch.name = "my_batch"
>>> batch.comment = "my_comment"
>>> # add the cells to the batch:
>>> batch.cells = [cell1, cell2, cell3]
>>> db.add_batch_object(batch)
add_cell_object(cell: Cell) None[source]#

Add a cell object to the database.

For this to work, you will have to create a cell object first, then populate it with data, and finally add it to the database using this method.

Examples

>>> from cellpy.readers import sql_dbreader
>>> cell = sql_dbreader.Cell()
>>> cell.name = "my_cell"
>>> cell.label = "my_label"
>>> cell.project = "my_project"
>>> cell.cell_group = "my_cell_group"
>>> # ...and so on...
>>> db = sql_dbreader.SQLReader()
>>> db.open_db("my_db.sqlite")
>>> db.add_cell_object(cell)
Parameters:

cell – cellpy.readers.sql_dbreader.Cell object

Returns:

None

add_raw_data_object(raw_data: RawData) None[source]#
create_db(db_uri: str = DB_URI, echo: bool = False, **kwargs) None[source]#
extract_date_from_cell_name(force=False)[source]#
from_batch(batch_name: str, include_key: bool = False, include_individual_arguments: bool = False) dict[source]#

Get a dictionary with the data from a batch for the journal.

Parameters:
  • batch_name – name of the batch.

  • include_key – include the key (the cell ids).

  • include_individual_arguments – include the individual arguments.

Returns:

dictionary with the data.

Return type:

dict

get_area(pk: int) float[source]#
get_args(pk: int) dict[source]#
get_by_column_label(pk: int, name: str) Any[source]#
get_cell_name(pk: int) str[source]#
get_cell_type(pk: int) str[source]#
get_comment(pk: int) str[source]#
get_experiment_type(pk: int) str[source]#
get_group(pk: int) str[source]#
get_instrument(pk: int) str[source]#
get_label(pk: int) str[source]#
get_loading(pk: int) float[source]#
get_mass(pk: int) float[source]#
get_nom_cap(pk: int) float[source]#
get_total_mass(pk: int) float[source]#
import_cells_from_excel_sqlite(db_path: str = None, echo: bool = False, allow_duplicates: bool = False, allow_updates: bool = True, process_batches=True, clear=False) None[source]#

Import cells from old db to new db.

Parameters:
  • db_path – path to old db (if not provided, it will use the already loaded db if it exists).

  • echo – will echo sql statements (if loading, i.e. if db_path is provided).

  • allow_duplicates – will not import if cell already exists in new db.

  • allow_updates – will update existing cells in new db.

  • process_batches – will process batches (if any) in old db.

  • clear – will clear all rows in new db before importing (asks for confirmation).

Returns:

None

inspect_hd5f_fixed(pk: int) int[source]#
load_excel_sqlite(db_path: str, echo: bool = False) None[source]#

Load an old sqlite cellpy database created from an Excel file.

You can use the cellpy.utils.batch_tools.sqlite_from_excel.run() function to convert an Excel file to a sqlite database.

open_db(db_uri: str = DB_URI, echo: bool = False, **kwargs) None[source]#
select_batch(batch_name: str) List[int][source]#
view_old_excel_sqlite_table_columns() None[source]#

Prints the columns of the old sqlite database.

DB_FILE_EXCEL[source]#
DB_FILE_SQLITE[source]#
DB_URI[source]#
HEADER_ROW[source]#
TABLE_NAME_EXCEL[source]#
UNIT_ROW[source]#
batch_cell_association_table[source]#
hdr_journal[source]#