forked from starkit/wsynphot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_cache_filters.py
61 lines (51 loc) · 2.33 KB
/
test_cache_filters.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import pytest
import os, re
import pandas.testing as pdt
import wsynphot
from wsynphot.io import cache_filters as cf
DATA_PATH = os.path.join(wsynphot.__path__[0], 'io', 'tests', 'data')
CACHE_DIR = os.path.join(DATA_PATH, 'filters', 'SVO')
@pytest.fixture
def sample_table():
from astropy.table import Table
table = Table()
table['a'] = [1.56, 2.34, 3.78, 4.71]
table['b'] = [0.1, 0.2, 0.4, 0.5]
return table
def test_cache_as_votable(sample_table):
sample_votable_path = os.path.join(DATA_PATH, 'sample_table.vot')
cf.cache_as_votable(sample_table, sample_votable_path)
# Convert back cached votable to a dataframe "data" and compare it
data = cf.df_from_votable(sample_votable_path)
pdt.assert_frame_equal(sample_table.to_pandas(), data)
@pytest.mark.parametrize(('test_filter_id'),
['Keck/NIRC2.Kp', 'Keck/LWS/SiC'])
def test_download_transmission_data(test_filter_id):
cf.download_transmission_data(test_filter_id, CACHE_DIR)
facility, instrument, filter_name = re.split('/|\.', test_filter_id)
# Check whether filter votable get stored in appropriate directory
assert os.path.exists(os.path.join(CACHE_DIR, facility, instrument,
'{0}.vot'.format(filter_name)))
def test_load_filter_index():
data = cf.load_filter_index(CACHE_DIR)
assert data.empty == False
assert 'filterID' in data.columns
def test_IOError_in_load_filter_index():
# When no filter index found in passed cache directory
pytest.raises(IOError, cf.load_filter_index, DATA_PATH)
@pytest.mark.parametrize(('test_filter_id'),
['HST/NICMOS1.F113N', 'HST/ACS_HRC.F250W'])
def test_load_transmission_data(test_filter_id):
data = cf.load_transmission_data(test_filter_id, CACHE_DIR)
assert data.empty == False
assert (data['Wavelength'] > 0).all() == True
assert ((data['Transmission'] >= 0) &
(data['Transmission'] <= 1)).all() == True
def test_IOError_in_load_transmission_data():
# 'Spitzer/IRAC.I2' exists in filter index but not in cache
pytest.raises(IOError, cf.load_transmission_data, 'Spitzer/IRAC.I2',
CACHE_DIR)
def test_ValueError_in_load_transmission_data():
# 'no/such.filter' is a dummy filter id which doesn't exist
pytest.raises(ValueError, cf.load_transmission_data, 'no/such.filter',
CACHE_DIR)