pmelchior / scarlet

hyperspectral galaxy modeling and deblending
MIT License
49 stars 22 forks source link

StarletMorphology.update raises UnboundLocalError: local variable 'constraint' referenced before assignment #274

Closed grantmerz closed 1 year ago

grantmerz commented 1 year ago

Hi. I am trying to update a script to work with scarlet version 1.0.1+g7eb3fe0. The previous version was 1.0.1+gfde109a with which the code works fine. The code is adapted from https://pmelchior.github.io/scarlet/tutorials/wavelet_model.html. In broad terms, the code models sources in an image as ExtendedSources and then based on the blend fit residual, changes some sources to StarletSources and remodels and fits the blend. I get this error when running on some of my images.

  File "/home/g4merz/.conda/envs/astrodetnv/lib/python3.9/site-packages/scarlet-1.0.1+g7eb3fe0-py3.9-linux-ppc64le.egg/scarlet/blend.py", line 165, in fit
    proxmin.adaprox(
  File "/home/g4merz/.conda/envs/astrodetnv/lib/python3.9/site-packages/proxmin/algorithms.py", line 368, in adaprox
    callback(*X, it=it)
  File "/home/g4merz/.conda/envs/astrodetnv/lib/python3.9/site-packages/scarlet-1.0.1+g7eb3fe0-py3.9-linux-ppc64le.egg/scarlet/blend.py", line 287, in _callback
    src.update()
  File "/home/g4merz/.conda/envs/astrodetnv/lib/python3.9/site-packages/scarlet-1.0.1+g7eb3fe0-py3.9-linux-ppc64le.egg/scarlet/component.py", line 176, in update
    child.update()
  File "/home/g4merz/.conda/envs/astrodetnv/lib/python3.9/site-packages/scarlet-1.0.1+g7eb3fe0-py3.9-linux-ppc64le.egg/scarlet/morphology.py", line 591, in update
    constraint=constraint,
UnboundLocalError: local variable 'constraint' referenced before assignment

In morphology.py, the update method of the StarletMorphology class is broken when monotonic=False (the default) and self.shrink_box() causes bbox != self.bbox.

https://github.com/pmelchior/scarlet/blob/7eb3fe0b1338a43f31281741fd42f9aeabb866bb/scarlet/morphology.py#L591

pmelchior commented 1 year ago

Thanks for reporting. That was indeed a bug. Should be fixed in the latest master.