Skip to content

Commit

Permalink
Merge branch 'develop' into shippable
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-neal committed May 21, 2018
2 parents d23c512 + e6478a9 commit c578dbd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -30,7 +30,7 @@ install:

script:
- pytest --cov=spectrum_overload --cov-report term-missing --durations 10 -W error
- coverage xml
- coverage xml -i

after_success:
- coveralls
Expand Down
12 changes: 6 additions & 6 deletions requirements.txt
@@ -1,9 +1,9 @@
numpy==1.14.0
matplotlib==2.1.2
astropy==3.0
scipy==1.0.0
numpy==1.14.3
matplotlib==2.2.2
astropy==3.0.2
scipy==1.1.0
pyastronomy==0.12.0
hypothesis==3.45.2
pytest==3.4.0
hypothesis==3.56.9
pytest==3.5.1
pytest-cov==2.5.1
python-coveralls==2.9.1
29 changes: 24 additions & 5 deletions spectrum_overload/spectrum.py
Expand Up @@ -74,7 +74,7 @@ def __init__(self, *,
self.length_check()
self.calibrated = calibrated
if header is None:
self.header: Dict[str, Any] = {}
self.header = {} # type: Dict[str, Any]
else:
self.header = header # Access header with a dictionary call.
self.interp_method = interp_method
Expand Down Expand Up @@ -245,6 +245,11 @@ def add_noise(self, snr: Union[float, int]) -> None:
# Add normal distributed noise at the SNR level.
self.flux += np.random.normal(0, sigma)

def add_noise_sigma(self, sigma):
"""Add Gaussian noise with given sigma."""
# Add normal distributed noise with given sigma.
self.flux += np.random.normal(0, sigma)

def plot(self, axis=None, **kwargs) -> None:
"""Plot spectrum with matplotlib."""
if axis is None:
Expand Down Expand Up @@ -460,7 +465,7 @@ def interpolate1d_to(self, reference: Union[ndarray, str, 'Spectrum', List[int],
" {}".format(type(reference)))

def spline_interpolate_to(self, reference: Union[ndarray, str, 'Spectrum', List[int], List[float]], w: None = None, bbox: Optional[Any] = None, k: int = 3,
ext: int = 0, check_finite: bool = False, bounds_error: bool = False) -> None:
ext: int = 0, check_finite: bool = True, bounds_error: bool = False) -> None:
r"""Interpolate wavelength solution using scipy's
InterpolatedUnivariateSpline.
Expand Down Expand Up @@ -504,7 +509,7 @@ def spline_interpolate_to(self, reference: Union[ndarray, str, 'Spectrum', List[
but may result in problems (crashes, non-termination
or non-sensical results) if the inputs do contain
infinities or NaNs.
Default is False.
Default is True.
Raises:
-------
Expand All @@ -524,7 +529,7 @@ def spline_interpolate_to(self, reference: Union[ndarray, str, 'Spectrum', List[
interp_spline = InterpolatedUnivariateSpline(self.xaxis, self.flux,
w=w, bbox=bbox, k=k,
ext=ext,
check_finite=False)
check_finite=check_finite)

# interp_function = interp1d(self.xaxis, self.flux, kind=kind,
# fill_value=fill_value,
Expand Down Expand Up @@ -621,6 +626,20 @@ def normalize(self, method: str = "scalar", degree: Optional[int] = None, **kwar
s.header["normalized"] = "{0} with degree {1}".format(method, degree)
return s

def instrument_broaden(self, R, **pya_kwargs):
"""Broaden spectrum by instrumental resolution R.
Uses the pyastronomy instrBroadGaussFast function.
:param R:
:param pya_kwargs: kwarg parameters for pyasl.instrBroadGaussFast()
:return s: broadened spectrum
"""
s = self.copy()
new_flux = pyasl.instrBroadGaussFast(s.xaxis, s.flux, 50000, **pya_kwargs)
s.flux = new_flux
return s

# ######################################################
# Overloading Operators
# Based on code from pyspeckit.
Expand Down Expand Up @@ -656,7 +675,7 @@ def _interp_other():
raise ValueError("The xaxis do not overlap so cannot be interpolated")
else:
other_copy = other.copy()
other_copy.spline_interpolate_to(self)
other_copy.spline_interpolate_to(self, check_finite=True)
other_flux = other_copy.flux
return other_flux

Expand Down

0 comments on commit c578dbd

Please sign in to comment.