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

light_curve_generation ztf sampling flag causing error (and question regarding lightcurve file structure) #173

Closed tylerbarna closed 1 year ago

tylerbarna commented 1 year ago

Describe the bug I set up a new environment and attempted to use the quickstart injection to generate lightcurves with light_curve_generation with ztf uncertainties

To Reproduce Steps to reproduce the behavior:

  1. Activate a fresh nmma environment
  2. Run quickstart for creating injections
  3. Run the following command: light_curve_generation --injection ./injection.json --label lc_gen --model Me2017 --svd-path ./svdmodels --tmin 0.01 --tmax 14.5 --dt 0.5 --ztf-uncertainties --filters g,r --outdir ./lightcurves
  4. The above should work
  5. Delete lightcurves
  6. Run the following command: light_curve_generation --injection ./injection.json --label lc_gen --model Me2017 --svd-path ./svdmodels --tmin 0.01 --tmax 14.5 --dt 0.5 --ztf-uncertainties --filters g,r --outdir ./lightcurves -- ztf-sampling
  7. The above should break. This is the output I encountered:
    Install afterglowpy if you want to simulate afterglows.
    Install wrapt_timeout_decorator if you want timeout simulations.
    Traceback (most recent call last):
    File "/home/tbarna/anaconda3/envs/nmma_dev/bin/light_curve_generation", line 8, in <module>
    sys.exit(main())
    File "/home/tbarna/anaconda3/envs/nmma_dev/lib/python3.9/site-packages/nmma/em/create_lightcurves.py", line 289, in main
    data = create_light_curve_data(
    File "/home/tbarna/anaconda3/envs/nmma_dev/lib/python3.9/site-packages/nmma/em/injection.py", line 56, in create_light_curve_data
    ztfrevisit = load(f)
    File "/home/tbarna/anaconda3/envs/nmma_dev/lib/python3.9/site-packages/joblib/numpy_pickle.py", line 648, in load
    obj = _unpickle(fobj)
    File "/home/tbarna/anaconda3/envs/nmma_dev/lib/python3.9/site-packages/joblib/numpy_pickle.py", line 577, in _unpickle
    obj = unpickler.load()
    File "/home/tbarna/anaconda3/envs/nmma_dev/lib/python3.9/pickle.py", line 1212, in load
    dispatch[key[0]](self)
    File "/home/tbarna/anaconda3/envs/nmma_dev/lib/python3.9/pickle.py", line 1537, in load_stack_global
    self.append(self.find_class(module, name))
    File "/home/tbarna/anaconda3/envs/nmma_dev/lib/python3.9/pickle.py", line 1581, in find_class
    return _getattribute(sys.modules[module], name)[0]
    File "/home/tbarna/anaconda3/envs/nmma_dev/lib/python3.9/pickle.py", line 331, in _getattribute
    raise AttributeError("Can't get attribute {!r} on {!r}"
    AttributeError: Can't get attribute 'EuclideanDistance' on <module 'sklearn.metrics._dist_metrics' from '/home/tbarna/anaconda3/envs/nmma_dev/lib/python3.9/site-packages/sklearn/metrics/_dist_metrics.cpython-39-x86_64-linux-gnu.so'>

Expected behavior Lightcurve files are generated with columns for time, filter, measurement, and uncertainty. Barring that structure, just that the command outputs lightcurves with uncertainties associated with each measurement

Screenshots In regards to the desired structure of the lightcurve file, this is what I am hoping to generate:

image

Whereas this is the general structure of the lightcurves if I exclude the --ztf-uncertainties flag that causes the error:

image

Platform information:

Additional context I have been trying to recreate prior behaviour I've had with nmma for generating lightcurves with associated uncertainties for each measurement while still imposing specific sampling times. I also noticed that, previously, the lightcurve files would have the filter as a column with each row corresponding to a measurement with an associated filter, but the new style has each filter and their measurements as separate columns. Is there a way to specify the previous structure?

Additional question, do the analysis tools take into account the uncertainty of observations

bfhealy commented 1 year ago

@tylerbarna I experimented with this issue and found that if I install an older version of scikit-learn (<1.2), I can get quickstart light_curve_generation to work. I think this has to do with the version of that package used to generate the .joblib files that are loaded from nmma/em/data when setting --ztf-uncertainties and --ztf-sampling. I don't think this will break other parts of the code, but I'll open a PR and run the tests to make sure.