bd-j / prospector

Python code for Stellar Population Inference from Spectra and SEDs
http://prospect.readthedocs.io
MIT License
153 stars 71 forks source link

Custom tabulated IMF using imf_filename FSPS parameter #312

Closed tHarvey303 closed 6 months ago

tHarvey303 commented 6 months ago

I've been trying to implement a custom piecewise power-law IMF in Prospector, using option '5' from FSPS. By default this loads the imf from your FSPS directory/data/imf.dat, but it should be possible to override the imf.dat filename in order to have multiple custom IMFs. I'm not sure if I'm doing something wrong, but when I pass in 'imf_filename' as a fixed parameter in my model parameter dictionary, it doesn't seem to be being used. It is set below in the code snippet.

model_params['imf_filename'] = {'isfree':False}
model_params['imf_type']['init'] = 5
model_params['imf_filename']['init'] = 'imf_hot_45k.dat'

When the code is run it shows up in the list of fixed parameters the code prints, so I had assumed it was working.

  ...
  nebemlineinspec: [ True] 
  add_dust_emission: [ True] 
  duste_umin: [1.] 
  duste_qpah: [4.] 
  duste_gamma: [0.001] 
  add_igm_absorption: [ True] 
  imf_filename: ['imf_hot_45k.dat'] 

However it didn't produce the results I was expecting, and on closer inspection when I removed the default imf.dat file from the fsps folder and attempted to run the code, it crashed as it couldn't find imf.dat and therefore was not recognizing the custom path. Does Prospector support this fsps option, or am I doing something wrong? I'm using version 1.2.0 of Prospector, and version 0.4.2 of python fsps.

Thanks in advance!

bd-j commented 6 months ago

Hi @tHarvey303

This functionality has not been explicitly preserved or tested in python-FSPS. Indeed, checking the python-fsps docs it does not appear that imf_filename is one of the available parameters: https://python-fsps.readthedocs.io/en/latest/stellarpop_api/#fsps.StellarPopulation, so it is not getting passed from prospector to python-FSPS.

You might try opening an issue on the python-FSPS repo, but I'm not sure if it can be promptly addressed. A more clunky solution is to just replace $SPS_HOME/data/imf.dat with tour own tabulated file, but I understand this could be less than ideal if you are working in parallel with a grid of different IMFs.

tHarvey303 commented 6 months ago

Thanks @bd-j. It's probably not a feature many people have tried using. For now I've already switched to doing what you suggest, which isn't too much more painful as I was only trying to test a few different IMF models, which can be run consecutively. I might flag it to the python-FSPS team so it is on their radar, but it definitely isn't a particularly urgent issue.