Skip to content

Commit

Permalink
Add proper error if the central wavelengths aren't specified
Browse files Browse the repository at this point in the history
  • Loading branch information
kboone committed Sep 17, 2019
1 parent 3ca8fe3 commit 8f9e428
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
8 changes: 4 additions & 4 deletions avocado/astronomical_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pandas as pd
from scipy.optimize import minimize

from .instruments import band_central_wavelengths, get_band_plot_color
from .instruments import get_band_central_wavelength, get_band_plot_color
from .utils import logger

class AstronomicalObject():
Expand Down Expand Up @@ -68,7 +68,7 @@ def bands(self):
"""
unsorted_bands = np.unique(self.observations['band'])
sorted_bands = np.array(sorted(unsorted_bands,
key=band_central_wavelengths.get))
key=get_band_central_wavelength))
return sorted_bands

def subtract_background(self):
Expand Down Expand Up @@ -171,7 +171,7 @@ def fit_gaussian_process(self, fix_scale=False, verbose=False,
fluxes = gp_observations['flux']
flux_errors = gp_observations['flux_error']

wavelengths = gp_observations['band'].map(band_central_wavelengths)
wavelengths = gp_observations['band'].map(get_band_central_wavelength)
times = gp_observations['time']

# Use the highest signal-to-noise observation to estimate the scale. We
Expand Down Expand Up @@ -301,7 +301,7 @@ def predict_gaussian_process(self, bands, times, uncertainties=True,

for band in bands:
wavelengths = (
np.ones(len(times)) * band_central_wavelengths[band]
np.ones(len(times)) * get_band_central_wavelength(band)
)
pred_x_data = np.vstack([times, wavelengths]).T
if uncertainties:
Expand Down
4 changes: 2 additions & 2 deletions avocado/augment.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from .astronomical_object import AstronomicalObject
from .dataset import Dataset
from .instruments import band_central_wavelengths
from .instruments import get_band_central_wavelength
from .utils import settings, logger

class Augmentor():
Expand Down Expand Up @@ -330,7 +330,7 @@ def _resample_light_curve(self, reference_object, augmented_metadata):
reference_redshift = reference_object.metadata['host_specz']
redshift_scale = (1 + new_redshift) / (1 + reference_redshift)

new_wavelengths = np.array([band_central_wavelengths[i] for i in
new_wavelengths = np.array([get_band_central_wavelength(i) for i in
observations['band']])
eval_wavelengths = new_wavelengths / redshift_scale
pred_x_data = np.vstack([observations['reference_time'],
Expand Down
21 changes: 21 additions & 0 deletions avocado/instruments.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
This module is used to define properties of various instruments. This should
eventually be split out into some kind of configuration file setup.
"""
from .utils import AvocadoException

# Central wavelengths for each band.
band_central_wavelengths = {
'lsstu': 3671.,
'lsstg': 4827.,
Expand All @@ -23,6 +25,25 @@
'lssty': 'goldenrod',
}

def get_band_central_wavelength(band):
"""Return the central wavelength for a given band.
If the band does not yet have a color assigned to it, an AvocadoException
is raised.
Parameters
----------
band : str
The name of the band to use.
"""
if band in band_central_wavelengths:
return band_central_wavelengths[band]
else:
raise AvocadoException(
"Central wavelength unknown for band %s. Add it to "
"avocado.instruments.band_central_wavelengths." % band
)

def get_band_plot_color(band):
"""Return the plot color for a given band.
Expand Down

0 comments on commit 8f9e428

Please sign in to comment.