nuclear-multimessenger-astronomy / nmma

A pythonic library for probing nuclear physics and cosmology with multimessenger analysis
https://nuclear-multimessenger-astronomy.github.io/nmma/
GNU General Public License v3.0
33 stars 58 forks source link

ZTF/LSST KNe simulated detection tutorial #87

Closed bfhealy closed 1 year ago

bfhealy commented 1 year ago

There appears to be a relatively recent tutorial page on simulating ZTF/LSST KNe detections that is excluded from the documentation (https://github.com/nuclear-multimessenger-astronomy/nmma/blob/722b02d10d95bf409da0aee1b01f4add4f32f7e1/doc/gwemopt_light_curves_detection.md) When I run this tutorial, I get stuck on step 5 running BNS light curve generation:

To avoid an error I slightly modify the call to nmma_create_injection such that the argument --injection-file path is ./example_files/sim_events/injections.dat (instead of just ./injections.dat):

nmma_create_injection --prior-file ./priors/Bu2019lm.prior --injection-file ./example_files/sim_events/injections.dat --eos-file  ./example_files/eos/ALF2.dat --binary-type BNS --original-parameters --extension json --aligned-spin --binary-type BNS --filename ./outdir_BNS/Bu2019lm_injection

I also modify the call to light_curve_generation such that the --injection argument file is Bu2019lm_injection.json (instead of injection_Bu2019lm.json):

light_curve_generation --model  Bu2019lm --svd-path ./svdmodels --outdir ./outdir_BNS --label injection_Bu2019lm --dt 0.5 --injection ./outdir_BNS/Bu2019lm_injection.json --injection-detection-limit 24.1,21.7,21.4,20.9,24.5,23.0,23.2,22.6,22.6 --filters u,g,r,i,z,y,J,H,K  --absolute --plot --generation-seed 42

Then I get the following error:

Traceback (most recent call last):
  File "/Users/bhealy/miniforge3/envs/nmma_env_new/bin/light_curve_generation", line 33, in <module>
    sys.exit(load_entry_point('nmma==0.0.8', 'console_scripts', 'light_curve_generation')())
  File "/Users/bhealy/nmma/nmma/em/create_lightcurves.py", line 311, in main
    data = create_light_curve_data(
  File "/Users/bhealy/nmma/nmma/em/injection.py", line 108, in create_light_curve_data
    lbol, mag = light_curve_model.generate_lightcurve(
  File "/Users/bhealy/nmma/nmma/em/model.py", line 289, in generate_lightcurve
    _, lbol, mag = utils.calc_lc(
  File "/Users/bhealy/nmma/nmma/em/utils.py", line 490, in calc_lc
    y_pred, sigma2_pred = gp.predict(
  File "/Users/bhealy/miniforge3/envs/nmma_env_new/lib/python3.8/site-packages/sklearn/gaussian_process/_gpr.py", line 371, in predict
    X = self._validate_data(X, ensure_2d=ensure_2d, dtype=dtype, reset=False)
  File "/Users/bhealy/miniforge3/envs/nmma_env_new/lib/python3.8/site-packages/sklearn/base.py", line 585, in _validate_data
    self._check_n_features(X, reset=reset)
  File "/Users/bhealy/miniforge3/envs/nmma_env_new/lib/python3.8/site-packages/sklearn/base.py", line 400, in _check_n_features
    raise ValueError(
ValueError: X has 4 features, but GaussianProcessRegressor is expecting 2 features as input.

I make similar modifications to the NSBH light curve process, and it fails with a different error:

Traceback (most recent call last):
  File "/Users/bhealy/miniforge3/envs/nmma_env_new/bin/light_curve_generation", line 33, in <module>
    sys.exit(load_entry_point('nmma==0.0.8', 'console_scripts', 'light_curve_generation')())
  File "/Users/bhealy/nmma/nmma/em/create_lightcurves.py", line 311, in main
    data = create_light_curve_data(
  File "/Users/bhealy/nmma/nmma/em/injection.py", line 108, in create_light_curve_data
    lbol, mag = light_curve_model.generate_lightcurve(
  File "/Users/bhealy/nmma/nmma/em/model.py", line 285, in generate_lightcurve
    parameters_list.append(new_parameters[parameter_name])
KeyError: 'KNphi'
mcoughlin commented 1 year ago

@weizmannk can you clarify?

mcoughlin commented 1 year ago

@bfhealy For NSBH, were you using the Bu2019nsbh prior?

bfhealy commented 1 year ago

@mcoughlin Yes, that was the prior I was using for the NSBH injection.

mcoughlin commented 1 year ago

@bfhealy Have the recent changes resolved this?

bfhealy commented 1 year ago

@mcoughlin Yes, I can now run light_curve_generation successfully using this tutorial. I do have to modify the filter names from what's specified in the tutorial (e.g. instead of J,H,K I need to use 2massj,2massh,2massks).

mcoughlin commented 1 year ago

@bfhealy can you submit a quick PR to the docs and then close this?

bfhealy commented 1 year ago

@mcoughlin Will do!