Skip to content

Commit

Permalink
Make calibration default to True.
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-neal committed Mar 29, 2017
1 parent 29141ea commit 89108ab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 4 additions & 2 deletions spectrum_overload/Spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
class Spectrum(object):
"""Spectrum class represents and manipulates astronomical spectra."""

def __init__(self, flux=None, xaxis=None, calibrated=False, header=None):
"""Initalise a Spectrum object."""
def __init__(self, flux=None, xaxis=None, calibrated=True, header=None):
"""Initalise a Spectrum object.
Calibrated defaults to True."""
# Some checks before creating class
if isinstance(flux, str):
raise TypeError("Cannot assign {} to the flux attribute".format(
Expand Down
9 changes: 6 additions & 3 deletions spectrum_overload/test/test_Spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ def test_empty_call_is_nones():
assert s.flux is None
assert s.xaxis is None
assert s.header is None
assert s.calibrated is False
assert s.calibrated is True

s2 = Spectrum(calibrated=False)
assert s2.calibrated is False


def test_setters_for_flux_and_xaxis():
Expand Down Expand Up @@ -231,14 +234,14 @@ def test_cant_calibrate_calibrated_spectrum():
def test_calibration_wavlength_only_positive():
# Can't have a wavelenght of zero or negative.
# So raise a SpectrumError before calibrating
s = Spectrum([1, 2, 3, 4], [-4, -3, -2, -1])
s = Spectrum([1, 2, 3, 4], [-4, -3, -2, -1], calibrated=False)
with pytest.raises(SpectrumError):
s.calibrate_with([0, 1, 0]) # y = 0*x**2 + 1*x + 0
assert s.calibrated is False # Check values stay the same
assert np.all(s.flux == np.array([1, 2, 3, 4]))
assert np.all(s.xaxis == np.array([-4, -3, -2, -1]))

s = Spectrum([1, 2, 3, 4], [0, 2, 3, 4])
s = Spectrum([1, 2, 3, 4], [0, 2, 3, 4], calibrated=False)
with pytest.raises(SpectrumError):
s.calibrate_with([0, 1, 0]) # y = 0*x**2 + 1*x + 0
assert s.calibrated is False # Check values stay the same
Expand Down

0 comments on commit 89108ab

Please sign in to comment.