The notebook is available here:

Plotting the spectrum interactivelyΒΆ

# Disable all warnings & logging statements from displaying in output
import warnings, logging

Load the grid you want to use:

from starkit.gridkit import load_grid
from bqplot import pyplot as plt
from ipywidgets import interactive, IntSlider, FloatSlider

grid = load_grid('mygrid.h5')

Create the sliders for each grid parameter and a function to plot spectrum using those parameters:

# Prepare sliders with their min, max from extent values
teff_extent, logg_extent, mh_extent = grid.get_grid_extent()
teff_slider = IntSlider(min=teff_extent[0], max=teff_extent[1], step=1, description='Teff', continuous_update=False)
logg_slider = FloatSlider(min=logg_extent[0], max=logg_extent[1], step=0.1, description='log g', continuous_update=False)
mh_slider = FloatSlider(min=mh_extent[0], max=mh_extent[1], step=0.1, description='[M/H]', continuous_update=False)

# Function to plot spectrum
def plot_spectrum(teff, logg, mh):
    grid.teff = teff
    grid.logg = logg = mh
    wave, flux = grid()

    plt.xlabel('Wavelength (Ang)')

Now bind the both, and display the produced interactive plot:

# Interactively plot by binding sliders with function arguments
interactive_plot = interactive(plot_spectrum, teff=teff_slider, logg=logg_slider, mh=mh_slider)

# Fix height to prevent output from flickering
output = interactive_plot.children[-1]
output.layout.height = '600px'

[ ]: