Skip to content

Commit

Permalink
Fixed UniformTransmission writefits bug
Browse files Browse the repository at this point in the history
  • Loading branch information
pllim committed Aug 12, 2016
1 parent abbfd4b commit af705f9
Showing 1 changed file with 33 additions and 14 deletions.
47 changes: 33 additions & 14 deletions pysynphot/spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,11 +508,11 @@ def writefits(self, filename, clobber=True, trimzero=True,

# Now update the primary header
for key, val in bkeys.items():
hdu.header.update(key, *val)
hdu.header[key] = val

# Make the extension HDU
cols = pyfits.ColDefs([cw, cf])
hdu = pyfits.new_table(cols)
hdu = pyfits.BinTableHDU.from_columns(cols)

# There are some standard keywords that should be added
# to the extension header.
Expand All @@ -527,7 +527,7 @@ def writefits(self, filename, clobber=True, trimzero=True,
pass # Not all spectra have these

for key, val in bkeys.items():
hdu.header.update(key, *val)
hdu.header[key] = val

# Add the header to the list, and write the file
hdulist.append(hdu)
Expand Down Expand Up @@ -2280,7 +2280,7 @@ def writefits(self, filename, clobber=True, trimzero=True,
pass

wave = self.wave
thru = self.throughput
thru = self(wave)

# Add a check for single/double precision clash, so
# that if written out in single precision, the wavelength table
Expand Down Expand Up @@ -2330,11 +2330,11 @@ def writefits(self, filename, clobber=True, trimzero=True,

# Now update the primary header
for key, val in bkeys.items():
hdu.header.update(key, *val)
hdu.header[key] = val

# Make the extension HDU
cols = pyfits.ColDefs([cw, cf])
hdu = pyfits.new_table(cols)
hdu = pyfits.BinTableHDU.from_columns(cols)

# There are also some keys to be written to the extension header
bkeys = dict(expr=(str(self), 'pysyn expression'),
Expand All @@ -2350,7 +2350,7 @@ def writefits(self, filename, clobber=True, trimzero=True,
pass # Not all bandpasses have these

for key, val in bkeys.items():
hdu.header.update(key, *val)
hdu.header[key] = val

# Add the extension to the list, and write to file.
hdulist.append(hdu)
Expand Down Expand Up @@ -2667,15 +2667,27 @@ def __init__(self, value, waveunits='angstrom'):
# It is not for general use.
self._wavetable = N.array([refs._default_waveset[0],
refs._default_waveset[-1]])
self._wave = self.GetWaveSet()

def __str__(self):
return "%g" % self.value
# TODO: Find a less hacky way to do this?
def writefits(self, *args, **kwargs):
"""Write to file using default waveset."""
old_wave = self.wave
self.wave = self._wavetable

# This produced 15 test failures in cos_etc_test.
# def GetWaveSet(self):
# return N.array([_default_waveset[0],_default_waveset[-1]])
#
# wave = property(GetWaveSet,doc="wave for UniformTransmission")
try:
super(UniformTransmission, self).writefits(*args, **kwargs)
finally:
self.wave = old_wave

@property
def wave(self):
"""``waveset`` for uniform transmission."""
return self._wave

@wave.setter
def wave(self, val):
self._wave = val

def GetWaveSet(self):
"""Obtain wavelength set for the spectrum.
Expand All @@ -2689,6 +2701,13 @@ def GetWaveSet(self):
"""
return None

# This produced 15 test failures in cos_etc_test.
# def GetWaveSet(self):
# return N.array([_default_waveset[0],_default_waveset[-1]])

def __str__(self):
return "%g" % self.value

def check_overlap(self, spectrum):
"""Apply special overlap logic for UniformTransmission.
Expand Down

0 comments on commit af705f9

Please sign in to comment.