webbpsf icon indicating copy to clipboard operation
webbpsf copied to clipboard

Issues with poppy dependency?

Open abiglee7 opened this issue 2 years ago • 1 comments

Hello again! I am still trying to run this notebook on OPDs (https://webbpsf.readthedocs.io/en/latest/jwst_measured_opds.html) but I am now getting a new error when I run the command psf = nrc.calc_psf(fov_pixels=101). I am unsure of whether this is a bug or if I am using the wrong version of a package. For reference I have both the current developer version of poppy and webbpsf. Any help would be very appreciated, thank you!

ValueError                                Traceback (most recent call last)
<ipython-input-6-4ada06fac4cb> in <module>
      5 nrc.detector_position = (1024,1024)
      6 nrc.load_wss_opd_by_date('2022-07-01T00:00:00',plot=False)
----> 7 psf = nrc.calc_psf(fov_pixels=101)

~/src/webbpsf/webbpsf/webbpsf_core.py in calc_psf(self, outfile, source, nlambda, monochromatic, fov_arcsec, fov_pixels, oversample, detector_oversample, fft_oversample, overwrite, display, save_intermediates, return_intermediates, normalize, add_distortion, crop_psf)
   1049 
   1050         # Run poppy calc_psf
-> 1051         psf = SpaceTelescopeInstrument.calc_psf(self, outfile=outfile, source=source, nlambda=nlambda,
   1052                                                 monochromatic=monochromatic, fov_arcsec=fov_arcsec,
   1053                                                 fov_pixels=fov_pixels, oversample=oversample,

~/anaconda3/lib/python3.8/site-packages/poppy/tests/src/poppy/poppy/instrument.py in calc_psf(self, outfile, source, nlambda, monochromatic, fov_arcsec, fov_pixels, oversample, detector_oversample, fft_oversample, overwrite, display, save_intermediates, return_intermediates, normalize)
    245 
    246         # ----- compute weights for each wavelength based on source spectrum
--> 247         wavelens, weights = self._get_weights(source=source, nlambda=local_options['nlambda'],
    248                                               monochromatic=local_options['monochromatic'])
    249 

~/anaconda3/lib/python3.8/site-packages/poppy/tests/src/poppy/poppy/instrument.py in _get_weights(self, source, nlambda, monochromatic, verbose)
    919                     f"with width {deltawave.to(units.micron):.2f}")
    920                 box = SpectralElement(Box1D, amplitude=1, x_0=wave, width=deltawave) * band
--> 921                 if box.tpeak() == 0:
    922                     # watch out for pathological cases with no overlap (happens with MIRI FND at high nlambda)
    923                     result = 0.0

~/anaconda3/lib/python3.8/site-packages/synphot/spectrum.py in tpeak(self, wavelengths)
   1768 
   1769         """
-> 1770         x = self._validate_wavelengths(wavelengths)
   1771         return self(x).max()
   1772 

~/anaconda3/lib/python3.8/site-packages/synphot/spectrum.py in _validate_wavelengths(self, wave)
    340         """Validate wavelengths for sampling."""
    341         if wave is None:
--> 342             if self.waveset is None:
    343                 raise exceptions.SynphotError(
    344                     'self.waveset is undefined; '

~/anaconda3/lib/python3.8/site-packages/synphot/spectrum.py in waveset(self)
    318     def waveset(self):
    319         """Optimal wavelengths for sampling the spectrum or bandpass."""
--> 320         w = get_waveset(self.model)
    321         if w is not None:
    322             utils.validate_wavelengths(w)

~/anaconda3/lib/python3.8/site-packages/synphot/models.py in get_waveset(model)
    895         waveset = _model_tree_evaluate_sampleset_compat(model)
    896     else:
--> 897         waveset = _model_tree_evaluate_sampleset(model)
    898 
    899     return waveset

~/anaconda3/lib/python3.8/site-packages/synphot/models.py in _model_tree_evaluate_sampleset(root)
    808     # Combine sampleset from both models.
    809     else:
--> 810         w1 = _model_tree_evaluate_sampleset(model1)
    811         w2 = _model_tree_evaluate_sampleset(model2)
    812         w = merge_wavelengths(w1, w2)

~/anaconda3/lib/python3.8/site-packages/synphot/models.py in _model_tree_evaluate_sampleset(root)
    782     # Not a CompoundModel, grab sampleset and be done.
    783     if not hasattr(root, 'op'):
--> 784         return _get_sampleset(root)
    785 
    786     model1 = root.left

~/anaconda3/lib/python3.8/site-packages/synphot/models.py in _get_sampleset(model)
    775     w = None
    776     if isinstance(model, Model) and hasattr(model, 'sampleset'):
--> 777         w = model.sampleset()
    778     return w
    779 

~/anaconda3/lib/python3.8/site-packages/synphot/models.py in sampleset(self, step, minimal)
    216 
    217         """
--> 218         w1, w2 = self.bounding_box
    219 
    220         if self._n_models == 1:

ValueError: not enough values to unpack (expected 2, got 1)

abiglee7 avatar Aug 26 '22 18:08 abiglee7

Hi @abiglee7 , I have the same notebook running on my environment, for reference these are the versions of my packages. It may be your syphot installation (?). synphot 1.1.1 pypi_0 pypi webbpsf 0.1.dev1904+gce6ca96.d20220823 pypi_0 pypi poppy 1.0.3 pypi_0 pypi

I have had the same issue before and it usually happens after I've uninstall and reinstall webbpsf a couple of times with the new brach. For me, doing a new, clean conda environment again (py3.8), installing this webbpsf branch worked for me.

Thanks!

obi-wan76 avatar Sep 03 '22 16:09 obi-wan76

@abiglee7 wanted to check in and see if you've been able to make any progress on this, or if you might need additional debugging help still? Cheers.

mperrin avatar Sep 14 '22 20:09 mperrin

Hi @obi-wan76, thank you so much! Upgrading synphot from 1.0.1 to 1.1.1 solved the bug. I appreciate your help!

abiglee7 avatar Sep 26 '22 19:09 abiglee7