Starfish-develop / Starfish

Tools for Flexible Spectroscopic Inference
https://starfish.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
69 stars 22 forks source link

gridtools - parameter assertion error #76

Open jason-neal opened 7 years ago

jason-neal commented 7 years ago

I am trying to do the first WASP14 tutorial but have not been able to generate the hdf5 data yet.

I setup config file like the docs as shown .

# YAML configuration script

name: example_wasp14

data:
  grid_name: "PHOENIX"
  files: ["data/WASP14/WASP14-2009-06-14.hdf5"]
  instruments : ["TRES"]
  orders: [22]

outdir : output/

plotdir : plots/

# The parameters defining your raw spectral library live here.
grid:
  raw_path: "/home/jneal/Phd/data/fullphoenix/phoenix.astro.physik.uni-goettingen.de/HiResFITS/PHOENIX-ACES-AGSS-COND-2011/"
  hdf5_path: "libraries/PHOENIX_TRES_test.hdf5"
  parname: ["temp", "logg"]
  key_name: "t{0:.0f}g{1:.1f}" # Specifies how the params are stored
  # in the HDF5 file
  parrange: [[2300, 3700], [4.0, 5.5]]
  wl_range: [6300, 6360]
  buffer: 50. # AA

But when I try to run the HDF5Creator code from the docs I get an Assertion Error.

import Starfish
from Starfish.grid_tools import PHOENIXGridInterfaceNoAlpha as PHOENIX
from Starfish.grid_tools import HDF5Creator, TRES
mygrid = PHOENIX()
instrument = TRES()
creator = HDF5Creator(mygrid, Starfish.grid["hdf5_path"], instrument,
ranges=Starfish.grid["parrange"])
creator.process_grid()
FFT grid stretches from 6250.000000000003 to 6409.999999999997
wl_FFT dv is 0.23127228225041102 km/s
Total of 60 files to process.
Processing [ 2300.     4.]
Traceback (most recent call last):
  File "hdf5_create.py", line 14, in <module>
    creator.process_grid()
  File "/home/jneal/Phd/Codes/Repos/Starfish/Starfish/grid_tools.py", line 786, in process_grid
    fl, header = self.process_flux(param)
  File "/home/jneal/Phd/Codes/Repos/Starfish/Starfish/grid_tools.py", line 722, in process_flux
    flux, header = self.GridInterface.load_flux(parameters)
  File "/home/jneal/Phd/Codes/Repos/Starfish/Starfish/grid_tools.py", line 232, in load_flux
    self.check_params(parameters) # Check to make sure that the keys are
  File "/home/jneal/Phd/Codes/Repos/Starfish/Starfish/grid_tools.py", line 147, in check_params
    assert len(parameters) == len(self.param_names)
AssertionError

If I print out Starfish.grid I get {'hdf5_path': 'libraries/PHOENIX_TRES_test.hdf5', 'buffer': 50.0, 'key_name': 't{0:.0f}g{1:.1f}', 'parrange': [[2300, 3700], [4.0, 5.5]], 'parname': ['temp', 'logg'], 'raw_path': '/home/jneal/Phd/data/fullphoenix/phoenix.astro.physik.uni-goettingen.de/HiResFITS/PHOENIX-ACES-AGSS-COND-2011/', 'wl_range': [6300, 6360]}

I assume that these are the parameters that it is counting.

How can I resolve this issue so that I can continue on with the tutorial?

gully commented 7 years ago

It looks like you're trying to fit with just two parameters-- Temperature and surface gravity, and excluding metallicity. The PHOENIXGridInterfaceNoAlpha expects 3 parameters. In order to achieve your desired outcome you can choose to:

One might object to the first solution due to a desire to fix metallicity, however fixing metallicity can be achieved through priors or other hacks (see related issues on "fixlogg"). The second solution is more satisfying, but requires some subtle spot-checking of code. I'm happy to consult on any Pull Requests though-- we welcome and encourage first time contributors! In fact I just implemented an unrelated model grid with just 2 parameters, so it is doable. Best of luck, and thank you for your contribution.

ps, if you don't object, I might rename this issue something along the lines of "Support for Phoenix Models with fixed metallicity", since that will assist others in finding this issue if they have similar problems.

jason-neal commented 7 years ago

Ah thank you. As I mentioned I was trying to run the tutorial, following the instructions to the letter.

The instructions are to copy the config file and only change the name and the path to the model files. The config file was updated to a 2 parameter model version, which seems to be the cause of the failure. I will add a PR to update some of the tutorial once I am finished. I found the suitable parameters from the config file for the tutorial in your starfish demos.

I was not trying to fix the logg, but I am actually more interested in the mixture model type which I see that is currently an open issue. I have high resolution NIR spectra of stars with brown dwarf companions with flux ratios estimated <1%. At the moment I am trying to see if I can detect anything of the companion when combining phoenix models, or get an upper limit on the flux ratio. I have currenty looking at using Starfish for the gridtools component at the moment as it looks alot nicer than my code to retrive all the phoenix models.

gully commented 7 years ago

There is experimental code to do inference on binaries here, but it's basically untested, and has known bugs. I'll be revamping this code eventually, so I invite you to subscribe to the GitHub notifications for the relevant issues for the most up to date information. Good luck!

iancze commented 7 years ago

Your project to detect brown dwarf companions sounds very interesting. However, I just want to sound a note of caution about trying to detect their spectra by direct fitting with synthetic models, especially if you think their expected fluxes are less than 1%. While this should in principle be possible, I think you will be limited by the inaccuracies in the synthetic spectra. Suppose one has a single star, but tries to fit it with a binary model. I think that in many cases, one could get a better fit using a two component model, since (especially with varying v_z) the spectrum of the second star could be used to fill in some of the inadequacies of the synthetic spectrum of the primary star. If this is the case for a single star, then in the case that you actually do have two stars I think it would be hard to conclusively demonstrate that you have correctly detected the flux of the secondary. If you had multiple epochs with known velocity changes, then you might be able to use this information as a check, but I still think this will be a difficult thing to do.

I am glad to hear that you have found the grid_tools file to be useful, this was one of the main motivations for making Starfish a public repository of "tools for spectroscopic inference," since sometimes people just need a few routines to apply to their own work.