ConnectTool
 All Classes Namespaces Files Functions Variables Pages
Classes | Functions | Variables
module_db Namespace Reference

Classes

class  DBError
 Error returned by module_db. More...
 

Functions

def row2dict
 Classic SQLite routine for transforming a row of tuple into a dictionnary. More...
 
def open_db
 Connect to Output DB. More...
 
def column_list
 Compute list of all db columns. More...
 
def init_db
 Initialise output database file. More...
 
def print_element
 Print a database element in a string. More...
 
def print_optional_argument
 Print some optional arguments of add/update/find_element. More...
 
def print_database
 Print the entire table as a list of strings. More...
 
def find_element
 Find an element in a table. More...
 
def datetime2output
 Look for the corresponding output around a given date (depending on h_accuracy). More...
 
def add_element
 Add an element in a table. More...
 
def update_element
 Update an element in a table through its ID. More...
 
def reinit_element
 Put a row to the default values. More...
 
def delete_element
 Delete an element in a table through its ID. More...
 
def build_db
 Build the Output database for all simulations available. More...
 

Variables

tuple database_path = os.path.join('dir.output','output.db')
 
string database_table = 'simulation'
 
dictionary operation_mode_ids = {'SCIENCE': 0, 'FORECAST': 1, 'EXTENDED': 2}
 

Function Documentation

def module_db.add_element (   table_name,
  connector,
  cursor,
  kwargs 
)

Add an element in a table.

If found 0 corresponding element, just add it.
If found 1 corresponding element, put all columns to default values before updating.
If found more than 1 corresponding element, raise DBError.

Here is the call graph for this function:

Here is the caller graph for this function:

def module_db.build_db (   folder,
  db_file,
  verbose_in,
  fid 
)

Build the Output database for all simulations available.

Verbose = 0 or False: no verbose
Verbose = 1 or True: some basic
Verbose > 1: more verbose
Will look into folder/dir.output/SCIENCE|FORECAST
Exclude the following folders/files:

  • .gitkeep
  • .gitignore
  • *.old
  • *.mpeg
  • *.mp4

Here is the call graph for this function:

def module_db.column_list ( )

Compute list of all db columns.

Returns
item_names: column names
item_types: column types
item_defaults: column default values

Here is the caller graph for this function:

def module_db.datetime2output (   table_name,
  connector,
  cursor,
  orderby = None,
  ordercol = None,
  kwargs 
)

Look for the corresponding output around a given date (depending on h_accuracy).

Look at corresponding outputs in [datetime_in-h_accuracy,datetime_in+h_accuracy].

Returns
Corresponding and nearest in date element of the database.
def module_db.delete_element (   table_name,
  connector,
  cursor,
  element_id 
)

Delete an element in a table through its ID.

Here is the caller graph for this function:

def module_db.find_element (   table_name,
  connector,
  cursor,
  orderby = None,
  ordercol = None,
  kwargs 
)

Find an element in a table.

Orderby and ordercol:

  • orderby = None: not ordering in results output
  • orderby = ASC: ascending ordering around ordercol attribute
  • orderby = DESC: descending ordering around ordercol attribute

Here is the caller graph for this function:

def module_db.init_db (   db_file,
  verbose_in,
  fid 
)

Initialise output database file.

If already exists, replace it. Old db kept into .old.
Table: simulation
Attributes:

  • id
  • dirname
  • modification_date
  • valid
  • operation_mode
  • operation_mode_id
  • scraft
  • heliospheric_model
  • coronal_model
  • reference_time
  • magnetogram_type
  • date
  • file_connectivity
  • file_footpoint
  • file_fieldline
  • file_parameter
  • file_hcs
  • file_visible_disk
  • file_coronal_hole
  • file_flare
  • file_xflare
  • file_cme
  • background_mag
  • background_euv171
  • background_euv193
  • layer_frame
  • layer_subpoint
  • layer_connectivity
  • layer_visible_disk
  • layer_hcs
  • layer_coronal_hole
  • layer_flare
  • layer_xflare
  • layer_cme
  • layer_qslmap
  • layer_polarity
  • final_legend_mag
  • final_legend_euv171
  • final_legend_euv193
  • final_nolegend_mag
  • final_nolegend_euv171
  • final_nolegend_euv193
  • magnetic_data
  • map_euv171
  • map_euv193
  • solar_wind_speed

Verbose = 0 or False: no verbose
Verbose = 1 or True: some basic
Verbose > 1: more verbose

Here is the call graph for this function:

Here is the caller graph for this function:

def module_db.open_db (   db_path,
  fid,
  verbose = 1 
)

Connect to Output DB.

If does not exist, initialise it.

Here is the call graph for this function:

Here is the caller graph for this function:

def module_db.print_database (   table_name,
  cursor 
)

Print the entire table as a list of strings.

Here is the call graph for this function:

def module_db.print_element (   db_element)

Print a database element in a string.

ID id: scraft, heliospheric_model, coronal_model, reference_time, magnetogram_type, operation_mode, date

Returns
String

Here is the caller graph for this function:

def module_db.print_optional_argument (   kwargs)

Print some optional arguments of add/update/find_element.

scraft: , heliospheric_model: , coronal_model: , reference_time: , magnetogram_type: , operation_mode: , date:

Returns
String

Here is the caller graph for this function:

def module_db.reinit_element (   table_name,
  connector,
  cursor,
  element_id 
)

Put a row to the default values.

Here is the call graph for this function:

Here is the caller graph for this function:

def module_db.row2dict (   cursor,
  row 
)

Classic SQLite routine for transforming a row of tuple into a dictionnary.

Usage: conn comes from sqlite3.connect(db_file)
conn.row_factory = row2dict
IN FACT NO NEED FOR IT!!!
Just call conn.row_factory = sqlite3.Row

def module_db.update_element (   table_name,
  connector,
  cursor,
  element_id,
  kwargs 
)

Update an element in a table through its ID.

Here is the caller graph for this function:

Variable Documentation

tuple module_db.database_path = os.path.join('dir.output','output.db')
string module_db.database_table = 'simulation'
dictionary module_db.operation_mode_ids = {'SCIENCE': 0, 'FORECAST': 1, 'EXTENDED': 2}