Package ComboCode :: Package cc :: Package tools :: Package io :: Module Database
[hide private]
[frames] | no frames]

Module Database

source code

A simple interface to work with a database saved on the hard disk.

Author: Robin Lombaert

Classes [hide private]
  Database
A database class.
Functions [hide private]
 
updateAllDbs(func, db_name, *args, **kwargs)
Update all databases located in any of your modeling folders in cc.path.gastronoom.
source code
 
convertDbKeys(path_input='')
Convert your local databases such that some keywords are shifted around according to their relevance for the different subcodes of GASTRoNOoM.
source code
 
updateDustMCMaxDatabase(filename)
Update dust filenames in MCMax database with the new OPAC_PATH system.
source code
 
convertMCMaxDatabase(path_mcmax)
Convert MCMax database to the dict format.
source code
 
cleanDatabase(db_path)
Remove any db entries with a dictionary that includes the IN_PROGRESS key.
source code
 
coolingDbRetrieval(path_gastronoom, r_outer=None)
Reconstruct a cooling database based on the mline database and the GASTRoNOoM inputfiles.
source code
Database()
addKeyCooling(key, val, db_fn='', db=None)
Add a (key,value) pair to every entry in the cooling database.
source code
Database()
rmKeyCooling(key, val, db_fn='', db=None)
Remove a key from every entry in the cooling database.
source code
Database()
addKeyMline(key, val, db_fn='', db=None, id='')
Add a (key,value) pair to every entry in the mline database.
source code
Database()
rmKeyMline(key, db_fn='', db=None, id='')
Remove a key from every entry in the mline database.
source code
Database()
rmKeySphinx(key, db_fn='', db=None, id='')
Remove a key from the sphinx database entries.
source code
Database()
addKeySphinx(key, val, db_fn='', db=None, id='')
Add a (key,value) pair to every entry of the sphinx database entries.
source code
Database()
rmKeyPacs(key, db_fn='', db=None, id='')
Remove a key from the PACS database entries.
source code
Database()
addKeyPacs(key, val, db_fn='', db=None, id='')
Add a (key,value) pair to every entry of the PACS database entries.
source code
 
replaceSubstring(db, oldss, newss)
Replace a substring of values in database entries, such as the home directory of filenames.
source code
Variables [hide private]
  __package__ = 'ComboCode.cc.tools.io'
Function Details [hide private]

updateAllDbs(func, db_name, *args, **kwargs)

source code 

Update all databases located in any of your modeling folders in cc.path.gastronoom.

Choose the method to run as well as the database to update, and add the args and kwargs for that method.

This method synchronizes the databases, so run with care.

Parameters:
  • func (function) - The method to use for updating a database
  • db_name (str) - Name of the database to be updated

convertDbKeys(path_input='')

source code 

Convert your local databases such that some keywords are shifted around according to their relevance for the different subcodes of GASTRoNOoM.

Moves USE_MASER_IN_SPHINX from sphinx to mline. Sets it to the default value of 1, since it was never changed for mline.

Moves USE_NO_MASER_OPTION, N_FREQ, START_APPROX, USE_FRACTION_LEVEL_CORR, FRACTION_LEVEL_CORR, NUMBER_LEVEL_MAX_CORR from cooling to mline.

Moves WRITE_INTENSITIES, TAU_MAX, TAU_MIN, CHECK_TAU_STEP from cooling to sphinx.

Adds the new keywords N_IMPACT_EXTRA[_RIN/ROUT] to cooling.

Adds the new keywords FRACTION_TAU_STEP, MIN_TAU_STEP to sphinx.

Adds the new keyword FEHLER to mline.

Converts any 'double' notation in str format to the floats, e.g. TAU_MIN='-6d0' becomes TAU_MIN=-6.

Converts all cooling, mline, sphinx and pacs databases found in the GASTRoNOoM home folder.

Can Update ComboCode input files for the maser keywords.

Parameters:
  • path_input (str) - The location of your ComboCode inputfiles. Use empty string or None if you do not want to update your input- files automatically. Is directly inserted into glob so takes wildcards, eg /Users/robinl/ComboCode/input/*.dat

    (default: '')

updateDustMCMaxDatabase(filename)

source code 

Update dust filenames in MCMax database with the new OPAC_PATH system.

Parameters:
  • filename (str) - The file and path to the MCMax database.

convertMCMaxDatabase(path_mcmax)

source code 

Convert MCMax database to the dict format.

This change was made to speed up the use of the database and makes use of the Database() class.

Parameters:
  • path_mcmax (string) - the name of the MCMac subfolder.

cleanDatabase(db_path)

source code 

Remove any db entries with a dictionary that includes the IN_PROGRESS key.

Works for cooling, mline and sphinx databases.

Parameters:
  • db_path (string) - full path to the database.

coolingDbRetrieval(path_gastronoom, r_outer=None)

source code 

Reconstruct a cooling database based on the mline database and the GASTRoNOoM inputfiles.

Only works if the water MOLECULE convenience keywords, the MOLECULE R_OUTER and/or the MOLECULE ENHANCE_ABUNDANCE_FACTOR keywords were not adapted!

Parameters:
  • path_gastronoom (string) - The path_gastronoom to the output folder
  • r_outer (float) - The outer radius used for the cooling model, regardless of the outer_r_mode parameter.

    (default: None)

addKeyCooling(key, val, db_fn='', db=None)

source code 

Add a (key,value) pair to every entry in the cooling database.

Not added to a particular entry if already present.

Parameters:
  • key (str) - The name of the keyword to be added.
  • val (any) - The default value for the keyword.
  • db_fn (string) - The filename and path of the database. Only required if db is not given.

    (default: '')

  • db (Database()) - The database. Is updated and returned. If not given, a filename is required.

    (default: None)

Returns: Database()
The new database, not yet synchronized.

rmKeyCooling(key, val, db_fn='', db=None)

source code 

Remove a key from every entry in the cooling database.

Parameters:
  • key (str) - The name of the keyword to be removed.
  • db_fn (string) - The filename and path of the database. Only required if db is not given.

    (default: '')

  • db (Database()) - The database. Is updated and returned. If not given, a filename is required.

    (default: None)

Returns: Database()
The new database, not yet synchronized.

addKeyMline(key, val, db_fn='', db=None, id='')

source code 

Add a (key,value) pair to every entry in the mline database.

Not added to a particular entry if already present.

Parameters:
  • key (str) - The keyword to be added
  • val (any) - The default value of the keyword
  • db_fn (string) - The filename and path of the database. Only required if db is not given.

    (default: '')

  • db (Database()) - The database. Is updated and returned. If not given, a filename is required.

    (default: None)

  • id (str) - If the (key,val) pair is only to be added to one cooling id, give that id here. If not given, the pair is added to all ids If id not in db, nothing is done.

    (default: '')

Returns: Database()
The new database, not yet synchronized.

rmKeyMline(key, db_fn='', db=None, id='')

source code 

Remove a key from every entry in the mline database.

Parameters:
  • key (str) - The keyword to be removed
  • db_fn (string) - The filename and path of the database. Only required if db is not given.

    (default: '')

  • db (Database()) - The database. Is updated and returned. If not given, a filename is required.

    (default: None)

  • id (str) - If the key is only to be removed from one cooling id, give that id here. If not given, the key is removed from all ids If id not in db, nothing is done.

    (default: '')

Returns: Database()
The new database, not yet synchronized.

rmKeySphinx(key, db_fn='', db=None, id='')

source code 

Remove a key from the sphinx database entries.

Parameters:
  • key (str) - They keyword to be removed
  • db_fn (string) - The filename and path of the database. Only required if db is not given.

    (default: '')

  • db (Database()) - The database. Is updated and returned. If not given, a filename is required.

    (default: None)

  • id (str) - If the key is only to be removed from one cooling id, give that id here. If not given, the key is removed from all ids If id not in db, nothing is done.

    (default: '')

Returns: Database()
The new database, not yet synchronized.

addKeySphinx(key, val, db_fn='', db=None, id='')

source code 

Add a (key,value) pair to every entry of the sphinx database entries.

Parameters:
  • key (str) - They keyword to be added
  • val (any) - The default value of the keyword
  • db_fn (string) - The filename and path of the database. Only required if db is not given.

    (default: '')

  • db (Database()) - The database. Is updated and returned. If not given, a filename is required.

    (default: None)

  • id (str) - If the (key,val) pair is only to be added to one cooling id, give that id here. If not given, the pair is added to all ids If id not in db, nothing is done.

    (default: '')

Returns: Database()
The new database, not yet synchronized.

rmKeyPacs(key, db_fn='', db=None, id='')

source code 

Remove a key from the PACS database entries.

Parameters:
  • key (str) - They keyword to be removed
  • db_fn (string) - The filename and path of the database. Only required if db is not given.

    (default: '')

  • db (Database()) - The database. Is updated and returned. If not given, a filename is required.

    (default: None)

  • id (str) - If the key is only to be removed from one cooling id, give that id here. Note this is the COOLING ID, not the pacs id. Iteration over all pacs ids is always done. However, if id is given it is cross checked with the cooling id in the entry and only then added. If not given, the key is removed from all pacs ids as well as cooling ids. If cooling id not in db, nothing is done.

    (default: '')

Returns: Database()
The new database, not yet synchronized.

addKeyPacs(key, val, db_fn='', db=None, id='')

source code 

Add a (key,value) pair to every entry of the PACS database entries.

Parameters:
  • key (str) - They keyword to be added
  • val (any) - The default value of the keyword
  • db_fn (string) - The filename and path of the database. Only required if db is not given.

    (default: '')

  • db (Database()) - The database. Is updated and returned. If not given, a filename is required.

    (default: None)

  • id (str) - If the (key,val) pair is only to be added to one pacs id, give that id here. If not given, the pair is added to all ids. If id not in db, nothing is done.

    (default: '')

Returns: Database()
The new database, not yet synchronized.

replaceSubstring(db, oldss, newss)

source code 

Replace a substring of values in database entries, such as the home directory of filenames. This is applied to all strings in the database vals!

This applies to the value of a dictionary (key,value) pair on the second level of the database (the first level being (model_id, dictionary). Does not work for embedded dictionaries in a dictionary, such as the dust_species embedded dictionary in an MCMax database!

The database is not synchronized in this method.

Parameters:
  • db (Database()) - The database (for now only MCMax or cooling)
  • oldss (str) - The old home name (eg /home/mariev/ or /home/)
  • newss (str) - The new home name (efg /Users/robinl/ or /Users/)