find_unum: How to Quickly Find a U-number in the Database

The unique identifier of a target in the BDNYC database is its U-number. U-numbers are (almost) completely randomly assigned, and so there is no way of knowing a target’s U-number a priori. Kelle’s Access database is the only place where you can get a target’s U-number… until now.

The method find_unum in the BDNYC database is a quick way to find the U-number of a target. The method, of course, can be used only for targets that already exist in the database.

How you can use find_unum

You can find a U-number by right ascension (ra), declination, and/or any known name. The method gives you the flexibility to enter only one of these if you prefer, and it will print in your terminal the attributes of all targets matching your input.

Let’s look at an example. You need to find the U-number of a target with ra = 10 11 00.2. This is how you do it:

> bdnyc.find_unum(ra=’10 11 00.2′)

The output will be:

—–Potential match 1: —–
[‘unum’, ‘U10885’]
[‘index’, 286]
[‘name’, ‘TVLM 263-71765’]
[‘sptype’, ‘M7.5’]
[‘ra’, ’10 11 00.2′]
[‘dec’, ‘+42 45 03’]
[‘standard’, ‘No’]

Alternatively, instead of ’10 11 00.2′, you could enter ’10 11′, and the method will you give back all targets that have ra starting with ’10 11′.

If you prefer to get the method’s output not as a terminal print-out but as an object, then set the parameter dump as True. The output will be a Python list.

This is the complete method:

bdnyc.find_unum(ra=None, dec=None, name=None, dump=False)



BDNYC Database Documentation

Now that the database infrastructure is more complete, I have generated the Sphinx documentation for all the database code. You can find it at

To have a full understanding of the database, you need both the Sphinx documentation and the Python Database Structure diagram, which is shared in Google Drive.

show_data: Quickly See What Data Exists in the BDNYC Database

In the BDNYC database code, I added a new method called show_data. Its purpose is to show you all and any kind of data that exists in the database for a specific target. The method is part of the module, under the BDNYCData class.

The only input it needs is the U-number of the target. So, for example, if you want to know what data exists for target U10276, type:

> bdnyc.show_data(‘U10276’)

assuming that bdnyc is where you loaded the database using the pickle.load(f) command. The method will automatically check whether the target exists in the database, and if it does, it will print out a list of rows, each one describing a piece of data for the target in question. For the case of U10276, you will get the following in your terminal:

[‘unum’, ‘U10276’]
[‘index’, 74]
[‘name’, ‘sd0423’]
[‘sptype’, ‘T0’]
[‘ra’, ’04 23 48.6′]
[‘dec’, ‘-04 14 04.0’]
[‘standard’, ‘Yes’]
[0, ‘opt’, ‘med’, ‘CT 4m’, ‘2002jan25’]
[1, ‘nir’, ‘high’, ‘NIRSPEC’, ‘2006jan10’]
[2, ‘nir’, ‘high’, ‘NIRSPEC’, ‘2005dec11’]
[3, ‘nir’, ‘high’, ‘NIRSPEC’, ‘2001oct09’]
[4, ‘nir’, ‘med’, ‘NIRSPEC’, ‘0000xxx00’]
[5, ‘nir’, ‘low’, ‘IRTF SpeX Prism’, ‘2003sep17’]
[6, ‘nir’, ‘phot’, ‘2MASS’, [‘H’, ‘K’, ‘J’]]

From this, you can see that there are five spectra in the database: one optical-medium resolution, three nir-high resolution, one nir-medium resolution, and one nir-low resolution. You also see that there is nir-photometry for this target for the J, H, and K bands.

Note that the second row gives you the index corresponding to this target in the database. This number is the same result that you would get if you used the method bdnyc.match_unum(unum).

One last thing, to make this output code-friendly, I added the option to give you the output as a list object —as opposed to just a terminal print-out— which you can then easily manipulate with your code. To do this, type:

> x = bdnyc.show_data(‘U10276’, dump=True)

And x will hold the list result shown above. Once you can see what data exists for a target, it becomes much easier to access the actual spectrum or photometry you want.

This is the complete method:

    bdnyc.show_data(unum, dump=True)

New Database Method: res_initializer()

While working on the database dump (putting all of Kelle’s data into the Python database), I wrote a new method to take care of 2 issues with the database. In it’s old state, we needed (and wanted) to have the resolution level of the structures (i.e. high, med, low, phot) initialized as empty dictionaries if no data exists. This was not the case, however. As a result, the dateList() method was no longer working, since it required this to be true. Also, having this level initialized makes the database dump (and any future dumps) easier. And so, this new method was born.

Remember, a method is a function attached to an object. In this case, the method is attached to our Python database. If you named the database bdnyc, then you can call the res_initializer() method with the command:
>>> bdnyc.res_initializer()              # No inputs are needed.

It’s simple–the method loops through all existing targets and adds these empty dictionaries if necessary. I also changed the addTarget method so that when you add a new target to the database, it will automatically run this method for you, unless you explicitly set init=False (if you’re adding multiple targets to the database, you can just wait until you put all of them in before running the initializer method).

If you are worried that I changed how you input new data into the database, don’t be: you can still follow Vivienne’s instructions on how to add data to the database, no changes necessary.

How to add data to the database

Here are some guidelines for inputting data into the BDNYC database!

Part 1: Opening database

This should be done in the directory in which you have the database stored.

>>> import pickle
>>> import BDNYC
>>> f=open(‘BDNYCData.txt’,’rb’)
>>> bdnyc=pickle.load(f)
>>> f.close()

IMPORTANT: BDNYC and bdnyc are not the same thing.  Throughout this tutorial I use both BDNYC and bdnyc.  Make sure to keep track of which is which when using these commands.

Part 2: Create a dictionary that holds your data

The first thing you need to do is check whether the target is already in the database.  You do this by checking whether the u number exists in the database. (Inside the parentheses goes your u-number in single quotes. Ex. ‘U12140’):

>>> bdnyc.matchUNum(‘unum’)

If the target exists in the database, it will output the target index.  You will need this index when inputting the data. Continue reading

Entering data into the database

This last week I’ve been getting familiar with our new python database by way of entering in the data I reduced last semester. So far I’ve input one night of data observed in September 2008 on the NIRSPEC spectrograph on Keck II. I have two more nights of data to input (11 or 12 objects), but it should go quickly!