I figured the safest way to upload data to the database is to use an ascii file where you can enter the data as rows and columns, and then have the BDNYC code read the file and upload it for you. The method add_data does just that. This method is part of the BDNYC.py module, under the BDNYCData class.
The upload.txt file
The idea of the ascii file, which I call upload.txt, is that you can enter one row per data set, with some pre-determined columns that you fill up to identify the target and the data itself. Having such a setup allows you to upload as many data sets as you want simultaneously and also to check for accuracy before uploading.
The file upload.txt is located in the same folder as the database files, so make sure you include it in your github pull. It is tab-delimited, and the columns are explained in detail in the comment lines of the file. The complete list of columns in the order in which they are in upload.txt is shown below. Most are self-explanatory.
- standard (Yes or No)
- rng (opt, nir, or mir)
- res (high, med, or low)
- instr (telescope + instrument of spectrum)
- ord_filt (order number if res=high, filter if res=med or low)
- fitsname (with full path)
- survey (of photometry)
- band_1 (name of band, e.g. J)
- val_1 (flux value of photometry)
- err_1 (error flux value of photometry)
- band_2 (ditto, for a second band)
- band_3 (ditto, for a third band)
To upload a spectrum, the required columns are:
To upload photometry, the required columns are:
You can leave err_1 blank if you do not have it. Note that you can enter up to three bands in the same row. And also note that you can enter both photometry AND one spectrum for the same target simultaneously in one row.
The other target attributes (name, ra, dec, sptype, standard) are only necessary if you are trying to upload data for a target that does not exist in the database. The method add_data will automatically create a new Target instance for your target and then add your data to it. Brilliant!
*Note: To use add_data, you need to have the module astrotools installed on your computer.
Here is an example. Suppose that I have a spectrum that I want to add to a target that already exists in the database. The row that I need to add to upload.txt is:
U40003› › › › › › nir› low› IRTF SpeX Prism› 2011dec08› /Users/alejo/U40003.fits
Note that I need to include empty tabs (›) for the columns I am skipping. Also note, however, that I do not need to add extra tabs after fitsname, since I am not uploading any photometry data.
The next step is just to run add_data:
If I have data that I want to overwrite, just set the overwrite input parameter in add_data to True.
If you forget to include something in upload.txt or if something is in the wrong order or format, add_data will let you know.
This is the complete method: