add_data: Adding Spectra or Photometry to the BDNYC Database

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.

  1. unum
  2. name
  3. ra
  4. dec
  5. sptype
  6. standard (Yes or No)
  7. rng          (opt, nir, or mir)
  8. res          (high, med, or low)
  9. instr        (telescope + instrument of spectrum)
  10. date
  11. ord_filt    (order number if res=high, filter if res=med or low)
  12. fitsname  (with full path)
  13. survey     (of photometry)
  14. band_1   (name of band, e.g. J)
  15. val_1       (flux value of photometry)
  16. err_1       (error flux value of photometry)
  17. band_2   (ditto, for a second band)
  18. val_2
  19. err_2
  20. band_3    (ditto, for a third band)
  21. val_3
  22. err_3

Using upload.txt
To upload a spectrum, the required columns are:

1.   unum
7.   rng
8.   res
9.   instr
10. date
11. ord_filt
12. fitsname

To upload photometry, the required columns are:

1.   unum
7.   rng
13. survey
14. band_1
15. val_1

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!

Uploading data

*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:
> bdnyc.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:

bdnyc.add_data(overwrite=False)

Leave a Reply

Your email address will not be published. Required fields are marked *