from matplotlib.ticker import MultipleLocator from Starfish.emulator import PCAGrid, WeightEmulator f = open(args.input) cfg = yaml.load(f) f.close() #Load individual samples and then concatenate them base = cfg["outdir"] #samples = np.array([np.load(base + "samples_w{}.npy".format(i)) for i in range(5)]) #Instead, use the optimized parameters. params = np.load(base + "params.npy") pcagrid = PCAGrid.from_cfg(cfg) temps = np.unique(pcagrid.gparams[:,0]) loggs = np.unique(pcagrid.gparams[:,1]) Zs = np.unique(pcagrid.gparams[:,2]) points = {"temp":temps, "logg":loggs, "Z":Zs} nts = len(temps) nls = len(loggs) nzs = len(Zs) int_temps = np.linspace(temps[0], temps[-1], num=40) int_loggs = np.linspace(loggs[0], loggs[-1], num=40) int_Zs = np.linspace(Zs[0], Zs[-1], num=40) def explore(weight_index):
import yaml f = open(args.input) cfg = yaml.load(f) f.close() import numpy as np import matplotlib.pyplot as plt from matplotlib.ticker import FormatStrFormatter as FSF from matplotlib.ticker import MaxNLocator from matplotlib.ticker import MultipleLocator from Starfish.config.grid_tools import HDF5Interface from Starfish.emulator import PCAGrid pcagrid = PCAGrid.from_cfg(cfg) ind = pcagrid.ind #Make sure that we can get the same indices from the main grid. grid = HDF5Interface(cfg["grid"], ranges=cfg["ranges"]) wl = grid.wl[ind] temps = np.unique(pcagrid.gparams[:, 0]) loggs = np.unique(pcagrid.gparams[:, 1]) Zs = np.unique(pcagrid.gparams[:, 2]) points = {"temp": temps, "logg": loggs, "Z": Zs} base = cfg['outdir'] # Plot the eigenspectra for i, comp in enumerate(pcagrid.pcomps):
''' Take an HDF5 file and downsize it to a PCA grid, write out to HDF5. ''' import argparse parser = argparse.ArgumentParser(prog="create_PCA.py", description="Decompose the spectra into eigenspectra.") parser.add_argument("input", help="*.yaml file specifying parameters.") args = parser.parse_args() import yaml from Starfish.emulator import PCAGrid f = open(args.input) cfg = yaml.load(f) f.close() pca = PCAGrid.from_cfg(cfg) pca.write(cfg["PCA_grid"])