Пример #1
0
args = parser.parse_args()

import matplotlib.pyplot as plt
import multiprocessing as mp
import numpy as np
import itertools
import Starfish
from Starfish import emulator
from Starfish.grid_tools import HDF5Interface
from Starfish.emulator import PCAGrid, Gprior, Glnprior, Emulator
from Starfish.covariance import Sigma
import os

if args.create:
    myHDF5 = HDF5Interface()
    my_pca = PCAGrid.create(myHDF5)
    my_pca.write()

if args.plot == "reconstruct":
    my_HDF5 = HDF5Interface()
    my_pca = PCAGrid.open()

    recon_fluxes = my_pca.reconstruct_all()

    # we need to apply the same normalization to the synthetic fluxes that we
    # used for the reconstruction
    fluxes = np.empty((my_pca.M, my_pca.npix))
    for i, spec in enumerate(my_HDF5.fluxes):
        fluxes[i, :] = spec

    # Normalize all of the fluxes to an average value of 1
Пример #2
0
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):
Пример #3
0
import matplotlib.pyplot as plt
import multiprocessing as mp
import numpy as np
import itertools
import Starfish
from Starfish import emulator
from Starfish.grid_tools import HDF5Interface
from Starfish.emulator import PCAGrid, Gprior, Glnprior, Emulator
from Starfish.covariance import Sigma
import os


if args.create:
    myHDF5 = HDF5Interface()
    my_pca = PCAGrid.create(myHDF5)
    my_pca.write()

if args.plot == "reconstruct":
    my_HDF5 = HDF5Interface()
    my_pca = PCAGrid.open()

    recon_fluxes = my_pca.reconstruct_all()

    # we need to apply the same normalization to the synthetic fluxes that we
    # used for the reconstruction
    fluxes = np.empty((my_pca.M, my_pca.npix))
    for i, spec in enumerate(my_HDF5.fluxes):
        fluxes[i,:] = spec

    # Normalize all of the fluxes to an average value of 1
Пример #4
0
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):
Пример #5
0
'''
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"])