get_data: Get Data of a Target in the Database

In a previous post, I explained the utility of the show_data method to visualize a target’s data on the BDNYC database. To get the actual data, you need to use the get_data method. This method is part of the BDNYC.py module, under the BDNYCData class.

As previously shown, show_data displays one row for each piece of data that exists for a target. These rows start with an id number.

To get the data detailed in one of those rows, use get_data, entering as parameters the U-number of the target and the id number of the piece of data.

Here is an example. Suppose I need a NIR-low resolution spectrum for U40003.

Step 1:
> bdnyc.show_data(‘U40003’)

Output:
[‘unum’, ‘U40003’]
[‘index’, 99]
[‘name’, ‘2M2148+4003’]
[‘sptype’, ‘L6’]
[‘ra’, ’21 48 16.33′]
[‘dec’, ‘+40 03 59.4’]
[‘standard’, ‘No’]
[0, ‘opt’, ‘med’, ‘Subaru FOCAS’, ‘2007aug20’, ‘RIZ’]
[1, ‘nir’, ‘high’, ‘NIRSPEC’, ‘2008sep16’, 49]
[2, ‘nir’, ‘med’, ‘IRTF SpeX xdisp’, ‘2005sep09’, ‘JHK’]
[3, ‘nir’, ‘med’, ‘IRTF SpeX xdisp’, ‘2006aug20’, ‘JHK’]
[4, ‘nir’, ‘low’, ‘IRTF SpeX Prism’, ‘2005sep09’, ‘JHK’]
[5, ‘nir’, ‘phot’, ‘2MASS’, [‘H’, ‘K’, ‘J’]]

Step 2:
> x = bdnyc.get_data(unum=’U40003′, ids=4)

Output:
x will hold the NIR-low resolution spectrum as a typical spectrum numpy array (wl in position 0, flux in position 1, error values in position 2).

There are a couple of flexible things that get_data can also do. These are with automation in mind, that is, if you want to write code to automatically use get_data for more than one target.

First, the input parameter ids can be a list of numbers (e.g. [0,1,4]). In this case, you will get a list of spectra. Note that the id numbers should be in ascending order, if not, get_data will give back to you the data sets rearranged in ascending id order anyway.

Second, you can include in the output the identifiers of the data you just got. To do this, set the input parameter header as True. In this case, the output will be a Python list with the data set as element zero and the data identifiers as element one. This is what it would look like:

Input:
> bdnyc.get_data(‘U40003’, ids=4, headers=True)

Output:
[array([[6.49e-01, 6.51e-01,…, 2.55e+00, 2.56e+00],
[  3.01e-16, -4.30e-16,…, 4.88e-15, 5.12e-15],
[  4.80e-16, 7.27e-16, …, 2.28e-16, 2.47e-16]],
dtype=float32),
[4, ‘nir’, ‘low’, ‘IRTF SpeX Prism’, ‘2005sep09’, ‘JHK’]]

The final input parameter to explain is errors. This is simply to tell get_data to include the spectrum flux error values if available.

This is the complete method:

    get_data(unum, ids, errors=True, header=False)

Leave a Reply

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