# Setup an HDF5 interface in order to allow much quicker reading and writing # than compared to loading FITS files over and over again. from Starfish.grid_tools.instruments import SPEX from Starfish.grid_tools import HDF5Creator creator = HDF5Creator(grid, "F_SPEX_grid.hdf5", instrument=SPEX(), wl_range=(0.9e4, np.inf), ranges=ranges) creator.process_grid() #%% # use the HDF5 Interface to consrtuct the spectral emulator from Starfish.emulator import Emulator emu = Emulator.from_grid("F_SPEX_grid.hdf5") print(emu) #%% # train the emulator (PCA) emu.train(options=dict(maxiter=1e5)) print(emu) # check that it trained properly, the GPs should have smooth lines with small # errors conecting the weights from Starfish.emulator.plotting import plot_emulator plot_emulator(emu) #%%
def mock_emulator(mock_hdf5_interface): yield Emulator.from_grid(mock_hdf5_interface)
def test_creation_from_string(self, mock_hdf5): emu = Emulator.from_grid(mock_hdf5) assert emu._trained is False assert np.allclose(emu._grid_sep, [100, 0.5, 0.5]) # issue 134
# than compared to loading FITS files over and over again. from Starfish.grid_tools.instruments import IGRINS_H_custom from Starfish.grid_tools import HDF5Creator creator = HDF5Creator( grid, "IGRINS_grid.hdf5",instrument=IGRINS_H_custom(), wl_range=(16600, 16700), ranges=ranges) creator.process_grid() #%% from Starfish.emulator import Emulator emu = Emulator.from_grid("IGRINS_grid.hdf5") print(emu) #%% emu.train(options=dict(maxiter=1e5)) print(emu) from Starfish.emulator.plotting import plot_emulator plot_emulator(emu) #%% emu.save("IGRINS_emu.hdf5")