コード例 #1
0
 def test_no_wl_truncation(self, mock_no_alpha_grid, mock_instrument,
                           tmpdir_factory):
     tmpdir = tmpdir_factory.mktemp("hdf5tests")
     outfile = tmpdir.join("test_no_instrument.hdf5")
     creator = HDF5Creator(mock_no_alpha_grid,
                           filename=outfile,
                           instrument=None,
                           wl_range=None)
     np.testing.assert_array_almost_equal_nulp(creator.wl_final,
                                               mock_no_alpha_grid.wl[1:-1])
コード例 #2
0
 def test_invalid_wavelengths(self, wl_range, mock_no_alpha_grid,
                              mock_instrument, tmpdir_factory):
     tmpdir = tmpdir_factory.mktemp("hdf5tests")
     outfile = tmpdir.join("test_no_instrument.hdf5")
     with pytest.raises(ValueError):
         HDF5Creator(
             mock_no_alpha_grid,
             filename=outfile,
             instrument=mock_instrument,
             wl_range=wl_range,
         )
コード例 #3
0
def mock_creator(mock_no_alpha_grid, mock_instrument, tmpdir_factory,
                 grid_points):
    ranges = np.vstack([np.min(grid_points, 0), np.max(grid_points, 0)]).T
    tmpdir = tmpdir_factory.mktemp("hdf5tests")
    outfile = tmpdir.join("test_grid.hdf5")
    creator = HDF5Creator(
        mock_no_alpha_grid,
        filename=outfile,
        instrument=mock_instrument,
        wl_range=(2e4, 3e4),
        ranges=ranges,
    )
    yield creator
コード例 #4
0
 def test_no_instrument(self, mock_no_alpha_grid, tmpdir_factory,
                        grid_points):
     ranges = np.vstack([np.min(grid_points, 0), np.max(grid_points, 0)]).T
     tmpdir = tmpdir_factory.mktemp("hdf5tests")
     outfile = tmpdir.join("test_no_instrument.hdf5")
     creator = HDF5Creator(
         mock_no_alpha_grid,
         filename=outfile,
         instrument=None,
         wl_range=(2e4, 3e4),
         ranges=ranges,
     )
     creator.process_grid()
コード例 #5
0
 def test_no_par_truncation(self, mock_no_alpha_grid, mock_instrument,
                            tmpdir_factory):
     tmpdir = tmpdir_factory.mktemp("hdf5tests")
     outfile = tmpdir.join("test_no_instrument.hdf5")
     creator = HDF5Creator(
         mock_no_alpha_grid,
         filename=outfile,
         instrument=mock_instrument,
         ranges=None,
     )
     for cpars, gpars in zip(creator.points,
                             np.asarray(mock_no_alpha_grid.points).T):
         np.testing.assert_allclose(cpars, np.unique(gpars))
コード例 #6
0
 def test_par_truncation(self, grid_points, mock_no_alpha_grid,
                         mock_instrument, tmpdir_factory):
     tmpdir = tmpdir_factory.mktemp("hdf5tests")
     outfile = tmpdir.join("test.hdf5")
     ranges = [(6000, 6200), (4.0, 5.0), (-1.0, 0.0)]
     creator = HDF5Creator(
         mock_no_alpha_grid,
         filename=outfile,
         instrument=mock_instrument,
         ranges=ranges,
     )
     for cpars, gpars in zip(creator.points, grid_points.T):
         np.testing.assert_allclose(cpars, np.unique(gpars))
コード例 #7
0
 def test_wavelength_truncation(self, wl_range, wl_expected,
                                mock_no_alpha_grid, mock_instrument,
                                tmpdir_factory):
     tmpdir = tmpdir_factory.mktemp("hdf5tests")
     outfile = tmpdir.join("test_no_instrument.hdf5")
     creator = HDF5Creator(
         mock_no_alpha_grid,
         filename=outfile,
         instrument=mock_instrument,
         wl_range=wl_range,
     )
     np.testing.assert_array_almost_equal_nulp(creator.wl_final[0],
                                               wl_expected[0], 3)
     np.testing.assert_array_almost_equal_nulp(creator.wl_final[-1],
                                               wl_expected[-1], 3)
コード例 #8
0
                 name="CRIRES",
                 FWHM=fwhm,
                 wl_range=Starfish.grid["wl_range"]):
        super().__init__(name=name, FWHM=FWHM, wl_range=wl_range)
        # Sets the FWHM and wl_range


# In[ ]:

mygrid = BTSETTL(norm=False, air=False, base=Starfish.grid["btsettle_raw"]
                 )  # Disable normalization to solar boloametic flux.
instrument = CRIRES_50k()
# HDF5Creator(GridInterface, filename, Instrument, ranges=None, key_name='t{0:.0f}g{1:.1f}', vsinis=None)
# Specify hdf5_path in config.yaml file.
creator = HDF5Creator(mygrid,
                      Starfish.grid["btsettle_hdf5_path"],
                      instrument,
                      ranges=Starfish.grid["parrange"])

# Need to change starfish BT-SETTL to change how it handles param_names and points

# Might need own interface as there is hardcoded folder CXXXX2011

# In[ ]:

creator.process_grid()

# # Loading BTSETTL Directly

# In[ ]:

from Starfish.grid_tools import load_BTSettl
コード例 #9
0
                 wl_range=Starfish.grid["wl_range"]):
        super().__init__(name=name, FWHM=FWHM, wl_range=wl_range)
        # Sets the FWHM and wl_range


print(CRIRES_50k())

# Process the grid and save to the hdf5 file.
mygrid = PHOENIX(norm=False,
                 air=False)  # Disable normalization to solar boloametic flux.
instrument = CRIRES_50k()
# HDF5Creator(GridInterface, filename, Instrument, ranges=None, key_name='t{0:.0f}g{1:.1f}', vsinis=None)
# Specify hdf5_path in config.yaml file.
creator = HDF5Creator(
    mygrid,
    "/home/jneal/Phd/Codes/companion_simulations/starfish_tests/libraries/PHOENIX_50k.hdf5",
    instrument,
    ranges=Starfish.grid["parrange"])

creator.process_grid()

mygrid = PHOENIX(norm=False,
                 air=True)  # Disable normalization to solar boloametic flux.
creator = HDF5Creator(
    mygrid,
    "/home/jneal/Phd/Codes/companion_simulations/starfish_tests/libraries/PHOENIX_air.hdf5",
    instrument,
    ranges=Starfish.grid["parrange"])

creator.process_grid()
コード例 #10
0
ranges = [[5700, 8600], [4.0, 6.0], [-0.5, 0.5]]
download_PHOENIX_models(path="PHOENIX", ranges=ranges)

#%%

# Setup a grid interface with the models
from Starfish.grid_tools import PHOENIXGridInterfaceNoAlpha
grid = PHOENIXGridInterfaceNoAlpha(path="PHOENIX")

# 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))
コード例 #11
0
from Starfish.grid_tools import PHOENIXGridInterface, HDF5Creator, TRES

raw_library_path = "../../libraries/raw/PHOENIX/"
mygrid = PHOENIXGridInterface(base=raw_library_path, wl_range=[4700, 5500])

out_path = "../../libraries/" + "PHOENIX_F.hdf5"

instrument = TRES()

# Limit the range of stellar parameters correspondi to an F star
creator = HDF5Creator(mygrid, out_path, instrument,
                        ranges={"temp":(5800, 6500), "logg":(3.5,6.0),
                        "Z":(-1.5,1.0), "alpha":(0.0,0.0)})

creator.process_grid()
#%%

# Setup a grid interface with the models
from Starfish.grid_tools import PHOENIXGridInterfaceNoAlpha

grid = PHOENIXGridInterfaceNoAlpha(path="PHOENIX")

# 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 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)
コード例 #13
0
            "New in v0.3: Using explicit air/vacuum state from Instrument class."
        )
    except AttributeError:
        air = True

    if (Starfish.data["grid_name"] == "PHOENIX") & (len(
            Starfish.grid['parname']) == 3):
        mygrid = eval("Starfish.grid_tools." + Starfish.data["grid_name"] +
                      "GridInterfaceNoAlpha")(air=air)
    else:
        mygrid = eval("Starfish.grid_tools." + Starfish.data["grid_name"] +
                      "GridInterface")(air=air)

    hdf5_path = os.path.expandvars(Starfish.grid["hdf5_path"])
    creator = HDF5Creator(mygrid,
                          hdf5_path,
                          instrument,
                          ranges=Starfish.grid["parrange"])

    creator.process_grid()

if args.plot:

    # Check to make sure the file exists

    import os
    hdf5_path = os.path.expandvars(Starfish.grid["hdf5_path"])
    if not os.path.exists(hdf5_path):
        print(
            "HDF5 file does not yet exist. Please run `grid.py create` first.")
        import sys
        sys.exit()
コード例 #14
0
            "New in v0.3: Using explicit air/vacuum state from Instrument class."
        )
    except AttributeError:
        air = True

    if (Starfish.data["grid_name"] == "PHOENIX") & (len(
            Starfish.grid['parname']) == 3):
        mygrid = eval("Starfish.grid_tools." + Starfish.data["grid_name"] +
                      "GridInterfaceNoAlpha")(air=air)
    else:
        mygrid = eval("Starfish.grid_tools." + Starfish.data["grid_name"] +
                      "GridInterface")(air=air)

    hdf5_path = os.path.expandvars(Starfish.grid["hdf5_path"])
    creator = HDF5Creator(mygrid,
                          hdf5_path,
                          instrument,
                          ranges=Starfish.grid["parrange"])

    creator.process_grid()

if args.plot:

    # Check to make sure the file exists

    import os
    hdf5_path = os.path.expandvars(Starfish.grid["hdf5_path"])
    if not os.path.exists(hdf5_path):
        print(
            "HDF5 file does not yet exist. Please run `grid.py create` first.")
        import sys
        sys.exit()