Skip to content

Commit

Permalink
working on mangle tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Alan Weaver committed Mar 16, 2016
1 parent 9d8aa7c commit eb6d0fc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
11 changes: 5 additions & 6 deletions pydl/pydlutils/mangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,16 +233,15 @@ def read_mangle_polygons(filename):
containing the header metadata, if any.
"""
import re
with open(filename, universal_newlines=True) as ply:
data = ply.read()
lines = data.split("\n")
with open(filename, 'rU') as ply:
lines = ply.read().split(ply.newlines)
try:
npoly = int(line[0].split()[0])
npoly = int(lines[0].split()[0])
except ValueError:
raise PydlutilsException(("Invalid first line of {0}! " +
"Are you sure this is a Mangle " +
"polygon file?").format(filename))
p_lines = [i for i, l in enumerate(lines) if lines.startswith('polygon')]
p_lines = [i for i, l in enumerate(lines) if l.startswith('polygon')]
header = lines[1:p_lines[0]]
poly = list()
r1 = re.compile(r'polygon\s+(\d+)\s+\(([^)]+)\):')
Expand All @@ -254,7 +253,7 @@ def read_mangle_polygons(filename):
meta = g[1].strip().split(',')
m1 = [m.strip().split()[1] for m in meta]
m0 = [mtypes[m1[i]](m.strip().split()[0]) for i, m in enumerate(meta)]
metad = dict(zip(m2,m1))
metad = dict(zip(m1,m0))
metad['x'] = list()
metad['cm'] = list()
for cap in lines[p+1:p+1+metad['caps']]:
Expand Down
9 changes: 9 additions & 0 deletions pydl/pydlutils/tests/test_mangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import numpy as np
from astropy.tests.helper import raises
from .. import PydlutilsException
from ..mangle import (ManglePolygon, is_cap_used, read_fits_polygons,
read_mangle_polygons, set_use_caps)

Expand All @@ -15,6 +16,7 @@ def setup(self):
self.data_dir = os.path.join(os.path.dirname(__file__), 't')
self.poly_fits = os.path.join(self.data_dir, 'polygon.fits')
self.poly_ply = os.path.join(self.data_dir, 'polygon.ply')
self.bad_ply = os.path.join(self.data_dir, 'median_data.txt')

def teardown(self):
pass
Expand Down Expand Up @@ -58,9 +60,16 @@ def test_read_fits_polygons(self):
assert poly[0].cmminf == 4

def test_read_mangle_polygons(self):
with raises(PydlutilsException):
poly, header = read_mangle_polygons(self.bad_ply)
poly, header = read_mangle_polygons(self.poly_ply)
assert len(header) == 3
assert header[0] == 'pixelization 6s'
assert len(poly) == 4
assert np.allclose(poly[0].CAPS.X[0,:],
np.array([0.0436193873653360, 0.9990482215818578,
0.0]))
assert poly[3].NCAPS == 3

def test_set_use_caps(self):
poly = read_fits_polygons(self.poly_fits, convert=True)
Expand Down

0 comments on commit eb6d0fc

Please sign in to comment.