Skip to content

Commit

Permalink
Merge pull request #12 from elliesch/master
Browse files Browse the repository at this point in the history
More Efficient Template Storage and Added Templates and Standards
  • Loading branch information
kelle authored Jul 13, 2017
2 parents b69a2b0 + f243e28 commit 68adeb8
Show file tree
Hide file tree
Showing 22 changed files with 326 additions and 39 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ python:
script:
- pytest

install:
- pip install matplotlib
- pip install astropy

matrix:
allow_failures:
- python: 2.7.0
- python: 2.7.0
43 changes: 32 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@
Home for qualitative spectral typing GUI that follows the Cruz Method as proposed in <Cruz et al. (2017)>.
Currently this GUI spectral types L field, L beta and L gamma brown dwarfs.
This code is written in Python 3.6, and does not yet have functionality for Python 2.



### Usage
## Usage

This code currently requires this directory tree to run properly:

```
├── TypeFinder.py
├── new_types
├── new_types/
│   └── saves selected spectral type image here
├── spectra
│   └── nir
│   ├── store nir spectra here
│   └── store full nir templates here
└── templates
   └── store Cruz 2017 band-by-band templates here
├── spectra/
│   └── nir/
│   ├── store NIR spectra here
│   └── store NIR spectral standards (Table 9, Cruz et al. 2017) here
└── templates/
   └── store Cruz2017_Templates.hdf5 here
```

To run many spectra consecutively, the following wrapper can be helpful.
It will print out the file name and wait for the user to press enter before continuing.
Expand All @@ -32,15 +34,31 @@ for file in range(len(lines)):
...: input("Press Enter to continue...")

```

If you have the Cruz 2017 templates in ascii format, you can [download](.../blob/master/templates/Cruz2017_Templates.hdf5) the hdf5 file from this repository.
You can also save an hdf5 file the first time you run Ultracool Typing Kit.

```python
from TypeFinder import*
typing_kit("spectra/nir/somespectra", make_templates=True)

```

By default make_templates is false, and this input will raise an exception if Cruz2017_Templates.hdf5 already exists.


---


### 1. Running the Program
On running, this initial window will pop up:
On running, this initial window will pop up, after about 10 seconds:
<img src="https://raw.githubusercontent.com/elliesch/UltracoolTypingKit/master/opengrid.png" width="750">

Your input spectra will be shown in black, over the Cruz et al. (2017) J-H-K band templates shown in red.
The initial grid shows each spectral type band-by-band.




### 2. Selecting a Spectral Type
To view a specific spectral type in more detail, key in the number you would like to see while your mouse is over the grid.
Expand Down Expand Up @@ -68,13 +86,16 @@ This grid shows your selected spectral type bracketed by it's neighboring types,
the entire NIR spectrum at once in the right-hand column, following the same color scheme as the initial grid.
The templates used in for the entire NIR spectrum follow the templates specified in Cruz et al. (2017).




### 3. Saving Selected Spectral Type
Currently the code automatically saves an image of your selection into the new_types folder. We are in the process
of updating it so that you can select whether you would prefer to save or see another type.



### Citation
## Citation
Copyright 2017 Ellianna Schwab and collaborators

If you make use of this code, please cite Cruz et al. (2017) and the zenodo DOI for the code, coming soon!
4 changes: 4 additions & 0 deletions Tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# import the TypeFinder code to this folder
import matplotlib
import astropy
from TypeFinder import *
35 changes: 19 additions & 16 deletions Tests/test_typing_kit.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import unittest
import os
from TypeFinder import *

# class TestData(unittest.TestCase):
#
# def setUp(self):
# '''
# This defines data to test
# '''
# self.data = Data('test_L3.fits')
#
# def test_init(self):
# '''
# This tests that the J-H-K arrays have been sorted properly by checking their boundary conds.
# '''
#
# self.assertTrue([0.87 <= wlength <= 1.39 for wlength in self.data.wavelength_J])
# self.assertTrue([1.41 <= wlength <= 1.89 for wlength in self.data.wavelength_H])
# self.assertTrue([1.91 <= wlength <= 2.39 for wlength in self.data.wavelength_K])
TESTDATA_FILENAME = os.path.join(os.path.dirname(__file__), 'test_L3.fits')

class TestData(unittest.TestCase):

def setUp(self):
'''
This defines data to test
'''
self.data = Data(TESTDATA_FILENAME)

def test_init(self):
'''
This tests that the J-H-K arrays have been sorted properly by checking their boundary conds.
'''

self.assertTrue([0.87 <= wlength <= 1.39 for wlength in self.data.wavelength_J])
self.assertTrue([1.41 <= wlength <= 1.89 for wlength in self.data.wavelength_H])
self.assertTrue([1.91 <= wlength <= 2.39 for wlength in self.data.wavelength_K])


### FUTURE TESTS ###
Expand Down
54 changes: 43 additions & 11 deletions TypeFinder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np
import matplotlib.pyplot as plt
from pylab import *
# from pylab import *
from collections import defaultdict
from astropy.io import fits
from astropy.io import ascii
Expand Down Expand Up @@ -87,27 +87,27 @@ def __init__(self):

for band in ['J', 'H', 'K']:
for spectype in range(9):
band_data = ascii.read("templates/L{}{}_f.txt".format(spectype, band))
field_templates[band][spectype] = Table([band_data['col1'], band_data['col2'], band_data['col4'], band_data['col5']], \
names = ('wavelength', 'flux', 'upper', 'lower'))
field_templates[band][spectype] = Table.read('templates/Cruz2017_Templates.hdf5', \
path='field/L{}{}_template'.format(str(spectype), band))


#Next with beta templates
beta_templates = defaultdict(dict)

for band in ['J', 'H', 'K']:
for spectype in range(2):
band_data = ascii.read("templates/L{}{}_b.txt".format(spectype, band))
beta_templates[band][spectype] = Table([band_data['col1'], band_data['col2'], band_data['col4'], band_data['col5']], \
names = ('wavelength', 'flux', 'upper', 'lower'))
beta_templates[band][spectype]= Table.read('templates/Cruz2017_Templates.hdf5', \
path='beta/L{}{}_template'.format(str(spectype), band))


#Next with gamma templates
gamma_templates = defaultdict(dict)

for band in ['J', 'H', 'K']:
for spectype in range(5):
band_data = ascii.read("templates/L{}{}_g.txt".format(spectype, band))
gamma_templates[band][spectype] = Table([band_data['col1'], band_data['col2'], band_data['col4'], band_data['col5']], \
names = ('wavelength', 'flux', 'upper', 'lower'))
gamma_templates[band][spectype]= Table.read('templates/Cruz2017_Templates.hdf5', \
path='gamma/L{}{}_template'.format(str(spectype), band))


self.gamma_templates = gamma_templates
self.beta_templates = beta_templates
Expand Down Expand Up @@ -411,7 +411,7 @@ def last_bracketed_plot(self, gravity_type):


### Function definition
def typing_kit(file_name) :
def typing_kit(file_name, make_templates=False) :

'''
Ellianna Schwab, Kelle Cruz
Expand All @@ -426,6 +426,38 @@ def typing_kit(file_name) :
'''


##===============
#Optional Section to Translate Templates to HDF5
##===============

if make_templates == True:

#First for field templates
for band in ['J', 'H', 'K']:
for spectype in range(9):
band_data = ascii.read("templates/L{}{}_f.txt".format(spectype, band))
T = Table([band_data['col1'], band_data['col2'], band_data['col4'], band_data['col5']], \
names = ('wavelength', 'flux', 'upper', 'lower'))
T.write('templates/Cruz2017_Templates.hdf5', path='field/L{}{}_template'.format(str(spectype), band), append=True)

#Next with beta templates
for band in ['J', 'H', 'K']:
for spectype in range(2):
band_data = ascii.read("templates/L{}{}_b.txt".format(spectype, band))
T = Table([band_data['col1'], band_data['col2'], band_data['col4'], band_data['col5']], \
names = ('wavelength', 'flux', 'upper', 'lower'))
T.write('templates/Cruz2017_Templates.hdf5', path='beta/L{}{}_template'.format(str(spectype), band), append=True)

#Next with gamma templates
for band in ['J', 'H', 'K']:
for spectype in range(5):
band_data = ascii.read("templates/L{}{}_g.txt".format(spectype, band))
T = Table([band_data['col1'], band_data['col2'], band_data['col4'], band_data['col5']], \
names = ('wavelength', 'flux', 'upper', 'lower'))
T.write('templates/Cruz2017_Templates.hdf5', path='gamma/L{}{}_template'.format(str(spectype), band), append=True)



##===============
#This defines the template arrays
##===============
Expand Down
Binary file added spectra/nir/2M1632.fits
Binary file not shown.
Loading

0 comments on commit 68adeb8

Please sign in to comment.