Once your BDNYC development environment is all setup, adding spectra to the database is relatively simple and all done through Terminal.
Open Terminal and then launch iPython from the command line with
Next, import the BDdb module and load the actual database with:
db = BDdb.get_db('/Users/your_computer/Dropbox/BDNYCdb/BDNYC.db')
Now you're all set to start adding spectra. There are two types of files that we typically use for spectra: ascii files and FITS files.
Adding ASCII Files
Ascii files are just text files with two or three columns of data, which should always be the wavelength, flux and (if three columns) the uncertainty values at each point. Adding this data is super simple:
So how do you find the source_id for your object? Just use the
identify() function. For example, say my object is '2MASS J00361617+1821104'. I would search by the first four digits of the object name, in this case:
This may return a number of different sources, all with '0036' appearing somewhere in their name, so I would then visually inspect to find the source I'm looking for. In this case, the source_id is 86.
The file path and the source_id are the only required information to provide to add this type of data though the more columns you can complete the better! The values of the optional columns can just be entered in the function as arguments, e.g.
telescope_id=6. The other columns include:
||Units of the wavelength axis, e.g. 'um' for microns, 'A' for angstroms
||Units of the flux axis, e.g. 'erg/s/cm2/A', 'W/m2/A', 'Jy', etc.
||For high resolution data only, e.g. 58, 59, 60, etc.
||The id from the PUBLICATIONS table that corresponds to the paper where the data was first published.
||The date of the observations as YYYY-MM-DD
||The id from the INSTRUMENTS table that corresponds to the instrument used to record the spectrum.
||The id from the TELESCOPES table that corresponds to the telescope used to record the spectrum.
||The id from the MODES table that corresponds to the instrument mode used to record the spectrum.
||The airmass at the time the spectrum was recorded, which is any value between 0 and 2.
||Comments about the spectrum that a future user of the data might need to know!
So as an example, if I want to add a NIR spectrum to the database taken with the SpeX Prism instrument on the NASA IRTF, my code should look like:
db.add_ascii('/Users/Joe/Desktop/NIR_spectra/2m0036_nir.txt', 86, telescope_id=7, instrument_id=6, mode_id=1, airmass=1.0263, obs_date='2013-01-17)
Note: the order of the optional arguments does not matter!
How do you know the telescope_id, instrument_id, mode_id, or publication_id? You can browse these tables in Terminal by running the table name as a method on the database instance or by searching the table with some keyword.
db.instruments() will show you every instrument_id and name. But
db.instruments('SpeX') will return only those records that have 'spex' in the name.
The naming convention for publications is the first four letters of the first author's last name and then the two digit year. So I could try
db.publications('Kirk01') to find Kirkpatrick et al. 2001 or just
db.publications('Kirk') to see all Kirkpatrick first author publications.
Otherwise, just launch the SQLite Database Browser and load the appropriate table.
All the other values should be in the ascii filename (e.g. 2m0036_2013may02_58.txt might be the object name, obs_date and wavelength_order) or in the ascii file itself above the data columns. Sometimes you might just know the correct information and can add it where possible. Otherwise you can always just leave these blank.
Add FITS Files
Adding spectra in FITS files works exactly the same way but with a little more automation.
Just like adding an ascii file above, you simply do:
The automation comes in since many FITS files have a metadata "header" with common keys like 'OBS_DATE', 'TELESCOP', 'INSTRUME', etc., which BDdb automatically tries to pull out and insert into our new spectrum record.
However, you can still fill in blanks and/or override the automation by simply adding in the optional arguments as we did above with
OOPS! Don't panic!
If anything gets entered incorrectly, remember that you can always just open up the SQLite Database Browser, navigate to the record you just added in the SPECTRA table, and double-click the cells you need to edit.
Or you can just select the row of your erroneous record and click the Delete Record button, and then try adding the spectrum again.