Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gridtools - parameter assertion error #76

Open
jason-neal opened this issue Apr 4, 2017 · 4 comments
Open

gridtools - parameter assertion error #76

jason-neal opened this issue Apr 4, 2017 · 4 comments

Comments

@jason-neal
Copy link
Collaborator

jason-neal commented Apr 4, 2017

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
Copy link
Collaborator

gully commented Apr 4, 2017

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:

  • Alter your grid search to include metallicity
  • Implement a custom GridInterface class that supports only 2 parameters-- temperature and surface gravity, which could be called, e.g. PHOENIXGridInterfaceNoAlphaNoFeH

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
Copy link
Collaborator Author

jason-neal commented Apr 4, 2017

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
Copy link
Collaborator

gully commented Apr 6, 2017

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
Copy link
Collaborator

iancze commented Jun 1, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants