pyrk.db.database module

class pyrk.db.database.Database(filepath='pyrk.h5', mode='w', title='PyRKDatabase')[source]

Bases: object

The Database class handles operations on the pyrk simulation backend and provides utilities for interacting with it.

add_group(groupname, grouptitle, path_to_group='/')[source]

Creates a new group in the file

Parameters:
  • groupname (str) – name of the group to add
  • grouptitle (str) – metadata to store in plain english, a title
  • path_to_group (str) – the database path, starts with ‘/’
add_row(table, row_dict)[source]

Adds a row to the table and flushes the table

Parameters:
  • table – handle to the table where the row will reside
  • row_dict (dictionary of row keys and values) – metadata to store in plain english, a title
add_table(groupname, tablename, description, tabletitle)[source]

Creates a new table All groupnames must be directly under root

Parameters:
  • groupname (str) – name of the group to add
  • tablename (str) – name of the table to add
  • description (str) – metadata for the table
  • tabletitle (str) – metadata to store in plain english, a title
close_db()[source]

Closes all currently open handles to the database.

delete_db()[source]

If the database exists, delete it

get_table(groupname, tablename)[source]

Returns the table handle for a table within a group

Parameters:
  • groupname (str) – name of the group
  • tablename (str) – name of the table in the group
Returns:

the path to the table in the group

Return type:

str

get_tablepath(groupname, tablename)[source]

Compiles the string for a table within a group

Parameters:
  • groupname (str) – name of the group
  • tablename (str) – name of the table in the group
Returns:

the path to the table in the group

Return type:

str

group_exists(path_to_group, groupname)[source]

Checks whether the group exsts, with that name, at that path

Parameters:
  • groupname (str) – name of the group to add
  • path_to_group (str) – the database path, starts with ‘/’
Returns:

returns the group

Return type:

pytables Group object

make_groups()[source]

For each group in groups, add group to the db.

make_tables()[source]

For each table in tables, add table to the db.

open_db()[source]

Returns a handle to the open db

record_all()[source]

For each row sent by current recorders, add the row.

register_recorder(groupname, tablename, recorder, timeseries=False)[source]

Register an entity that wants to represent itself in the Database

Parameters:
  • groupname (str) – name of the group to add
  • path_to_group (str) – the database path, starts with ‘/’
  • recorder (function object) – a function pointer that returns a table row
  • timeseries (bool) – should this be recorded each timestep?
set_up_groups()[source]

We know what groups need to exist for a PyRK simulation. This is their info.

Returns:groups that define the simulation in PyRK
set_up_tables()[source]

We know what tables need to exist for a PyRK simulation. This is their info.

Returns:tables that define the simulation in PyRK
pyrk.db.database.nostderr()[source]

This context manager catches standard error output. It is used mostly to catch the unnecessary fileclosed warnings from pytables.