Package ComboCode :: Package cc :: Package data :: Module Radio :: Class Radio
[hide private]
[frames] | no frames]

Class Radio

source code


Environment with several tools to load and save a database for Radio data.

Instance Methods [hide private]
new empty dictionary

__init__(self, db_name='radio_data.db', db_path=None)
Initializing an instance of Radio.
source code
 
parseFolder(self)
Parse the db folder and add filenames to recognized transitions.
source code
 
addStar(self, star_name)
Add a new star to the database.
source code
 
addData(self, star_name, filename, trans)
Add a new file to the database with given transition definition.
source code
 
removeData(self, star_name, filename='', trans='')
Remove filenames or transition definitions from the database for a given star_name.
source code
 
checkFolder(self)
Check which radio datafiles are not included in the db present in its folder.
source code
 
convertOldDb(self)
Convert an existing Radio database from the old format: db[star][trans] = list to the new format: db[trans][trans][filename] = fit dict
source code
dict
filterContents(self, star_name='')
Filter out the fit results from the contents of the database, eg for printing purposes.
source code
 
fitLP(self, star_name='', filename='', trans='', replace=0, **kwargs)
Fit the data line profiles with a soft parabola or a Gaussian according to LPTools.fitLP() (see that method for further details).
source code

Inherited from cc.tools.io.Database.Database: __delitem__, __setitem__, addChangedKey, getChangedKeys, getDeletedKeys, pop, popitem, read, setdefault, sync, update

Inherited from cc.tools.io.Database.Database (private): _open

Inherited from dict: __cmp__, __contains__, __eq__, __ge__, __getattribute__, __getitem__, __gt__, __iter__, __le__, __len__, __lt__, __ne__, __new__, __repr__, __sizeof__, clear, copy, fromkeys, get, has_key, items, iteritems, iterkeys, itervalues, keys, values, viewitems, viewkeys, viewvalues

Inherited from object: __delattr__, __format__, __reduce__, __reduce_ex__, __setattr__, __str__, __subclasshook__

Class Variables [hide private]

Inherited from dict: __hash__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, db_name='radio_data.db', db_path=None)
(Constructor)

source code 

Initializing an instance of Radio.

Inherits from the Database class and adds a bit of functionality for the particular case of radio data.

Initializing this object returns a Database() class that can contain radio data in the given path. If no db is already present, a new one is created from scratch at given location.

The name of the database is radio_data.db by default. Can be changed if needed, but ComboCode does not work with this other name.

If nothing more is requested, a new database is essentially empty.

The option to parse the content of the target folder is available: This will add entries to the database for the stars in the folder and the 'simple' molecules and transitions.

Once a db is created, you can perform several methods on the database specific to radio data management.

Examples: For data located in dradio in Path.dat >>> from cc.data import Radio >>> db = Radio.Radio() >>> db.sync()

This will create a database, automatically search your data folder for data files that the script can recognize, and save them in the database. The final command ( .sync() ) will then save the database to your hard disk in the same folder, under 'radio_data.db'. Later when you run Radio.Radio() again, it will load that same database that still contains all those datafiles and TRANSITION references.

The database is structured per star_name and per transition definition. So for instance, you will find the file whya_co32_APEX.fits in a dict under db['whya']['TRANSITION=12C16O 0 3 0 0 0 2 0 0 APEX 0.0'] where you will find dict([('whya_co32_APEX.fits',None)])

The None refers to the value of the dictionary entry for that file. This is replaced by the fit results of the line when >>> db.fitLP(filename='whya_co32_Maercker_new_JCMT.fits') is ran. The method redoes the fit by default, regardless of there being an entry for it already. Any required fitting parameters can be passed along to the function (see LPTools.fitLP()). CC loads fit results from the database.

If multiple data files are available for the same star, the same transition and the same telescope, the multiple data files will also be contained in this dict. Note that the transition definition is quite specific: 1 space between entries, and 11 entries total. It is identical to the input in your combocode inputfile (excluding the final number n_quad, which is model input and has nothing to do with your data).

Lastly, you can do multiple things with this database. >>> db.addData(star_name='whya', trans='TRANSITION=12C16O 0 3 0 0 0 2 0 0 JCMT 0.0', filename='whya_co32_Maercker_new_JCMT.fits') will add a new entry to the database if it is not there. This is useful for those molecules/filenames which have not been automatically found by the parseFolder method, because with this method you can still add them whichever way you want.

>>> db.removeData(star_name='whya',                          trans='TRANSITION=12C16O 0 3 0 0 0 2 0 0 JCMT 0.0')
removes a whole transition from the database. Alternatively
>>> db.removeData(star_name='whya',                          filename='whya_co32_Maercker_new_JCMT.fits')
removes a single filename from the database. (does not delete the file)

And if you want to know which datafiles in your data folder are not yet in the database (so you know which you have to add manually): >>> db.checkFolder() prints them out for you.

Remember, every time you add or remove data or do a parseFolder(), you have to save the contents of your database in python to the hard disk by doing: >>> db.sync()

As long as you don't do this, the hard disk version of the datafile will remain unchanged.

Parameters:
  • db_name (str) - The name of the database. The default only is used by ComboCode.

    (default: radio_data.db)

  • db_path (str) - The path to the db if not the default dradio in Path.dat

    (default: None)

Returns:
new empty dictionary

Overrides: object.__init__

parseFolder(self)

source code 

Parse the db folder and add filenames to recognized transitions.

Includes:

  • CO and its isotopologues
  • SiO and its isotopologues
  • SiS and its isotopologues
  • H2O and pH2O, and their isotopologues
  • SO2 and SO
  • CS
  • PO and PN
  • H2CO

Particularly excludes: (because no naming convention/too complex)

  • CN
  • HCN and its isotopologues
  • HCO+

addStar(self, star_name)

source code 

Add a new star to the database. A check is ran to see if the requested star is known in ~/ComboCode/usr/Star.dat.

Parameters:
  • star_name (str) - The name of the star (from Star.dat)

addData(self, star_name, filename, trans)

source code 

Add a new file to the database with given transition definition. If the transition is already present in the database for this particular star, the filename is added to the dictionary for that transition.

A single transition for a star can thus have multiple filenames associated with it!

Note that this method does NOT automatically sync (ie save changes to the hard disk) the database. That must be done through an additional flag to avoid excess overhead.

The transition definition is checked for correctness: single spaces between entries in the defintion, and a total of 11 entries: 1 molecule (shorthand) 8 quantum numbers, 1 offset

The fit is not done here. Instead the filename key is added to the transition's dictionary with value None.

Parameters:
  • star_name (str) - The name of the star for which to add the data.
  • filename (str) - The filename of the radio data to be added. Must be in the db folder! Only the filename is used. Any folder path is cut.
  • trans (str) - The transition definition. Must be in the correct format!

removeData(self, star_name, filename='', trans='')

source code 

Remove filenames or transition definitions from the database for a given star_name. Either filename or trans must be given.

Parameters:
  • star_name (str) - Name of the star for which data or trans is removed
  • filename (str) - data filename to be removed. If empty string, a transition definition must be given (ie remove everything for a given transition definition)

    (default: '')

  • trans (str) - Transition definition to be removed. Irrelevant if a filename is also given (latter takes precedence)

    (default: '')

filterContents(self, star_name='')

source code 

Filter out the fit results from the contents of the database, eg for printing purposes.

If star_name is given, only the star will be printed. Otherwise the full database is printed.

Parameters:
  • star_name (str) - The requested star. Default is to print all of them

    (default: '')

Returns: dict
The dictionary with just the relevant contents (trans and file names)

fitLP(self, star_name='', filename='', trans='', replace=0, **kwargs)

source code 

Fit the data line profiles with a soft parabola or a Gaussian according to LPTools.fitLP() (see that method for further details).

Input keywords require one of these:

  • no keys: all lines in db are fitted
  • star_name: All lines for star are fitted
  • star_name, trans: all lines for transition of star are fitted
  • star_name, filename: only this filename is fitted

The fit is NOT redone by default, if there is an entry in db already. You can force a replacement fit by turning replace on.

Note that this method does NOT automatically sync (ie save changes to the hard disk) the database. That must be done through an additional flag to avoid excess overhead.

Parameters:
  • star_name (str) - The name of the star for which to add the data. If not given, all files in db are fitted.

    (default: '')

  • filename (str) - The filename of the radio data to be fitted. Must be in the db folder! Only the filename is used. Any folder path is cut.

    (default: '')

  • trans (str) - The transition definition. Must be in the correct format!

    (default: '')

  • replace (bool) - Replace existing fits with a new one. If off, only lines that have not been fitted yet are added.

    (default: 0)

  • kwargs (dict) - Any additional keywords that are passed on to LPTools.fitLP()