conornally / starbug2

JWST PSF photometry for complex and crowded fields
GNU General Public License v3.0
4 stars 3 forks source link

Recursion error in photutils #6

Open conornally opened 1 year ago

conornally commented 1 year ago

On presumably bad source fits in the PSF, python breaks with a recursion error:

Traceback (most recent call last): File "/home/conor/.local/bin/starbug2", line 243, in if ncores==1: starbugs=[ fn(fname) for fname in args ] File "/home/conor/.local/bin/starbug2", line 243, in if ncores==1: starbugs=[ fn(fname) for fname in args ] File "/home/conor/.local/bin/starbug2", line 231, in fn sb.photometry() File "/home/conor/dev/starbug2/starbug2/starbug.py", line 443, in photometry _psf_cat=phot(image,init_guesses=init_guesses) File "/home/conor/.local/lib/python3.10/site-packages/photutils/psf/photometry.py", line 290, in call return self.do_photometry(image, mask=mask, init_guesses=init_guesses, File "/home/conor/dev/starbug2/starbug2/routines.py", line 413, in do_photometry cat=super().do_photometry(image, mask=mask, init_guesses=init_guesses, progress_bar=False) File "/home/conor/.local/lib/python3.10/site-packages/photutils/psf/photometry.py", line 432, in do_photometry output_tab, self._residual_image = self.nstar( File "/home/conor/.local/lib/python3.10/site-packages/photutils/psf/photometry.py", line 512, in nstar group_psf = get_grouped_psf_model(self.psf_model, group, File "/home/conor/.local/lib/python3.10/site-packages/photutils/psf/utils.py", line 171, in get_grouped_psf_model group_psf = group_psf + psf_to_add File "/home/conor/.local/lib/python3.10/site-packages/astropy/modeling/core.py", line 55, in return lambda left, right: CompoundModel(oper, left, right, **kwargs) File "/home/conor/.local/lib/python3.10/site-packages/astropy/modeling/core.py", line 3006, in init self._map_parameters() File "/home/conor/.local/lib/python3.10/site-packages/astropy/modeling/core.py", line 3522, in _map_parameters self._make_leaflist() File "/home/conor/.local/lib/python3.10/site-packages/astropy/modeling/core.py", line 3285, in _make_leaflist make_subtree_dict(self, '', tdict, leaflist) File "/home/conor/.local/lib/python3.10/site-packages/astropy/modeling/core.py", line 4050, in make_subtree_dict make_subtree_dict(tree.left, nodepath+'l', tdict, leaflist) File "/home/conor/.local/lib/python3.10/site-packages/astropy/modeling/core.py", line 4050, in make_subtree_dict make_subtree_dict(tree.left, nodepath+'l', tdict, leaflist) File "/home/conor/.local/lib/python3.10/site-packages/astropy/modeling/core.py", line 4050, in make_subtree_dict make_subtree_dict(tree.left, nodepath+'l', tdict, leaflist) [Previous line repeated 980 more times] File "/home/conor/.local/lib/python3.10/site-packages/astropy/modeling/core.py", line 4046, in make_subtree_dict if not hasattr(tree, 'isleaf'): RecursionError: maximum recursion depth exceeded

conornally commented 1 year ago

The recursion is caused by the source groups being fit having more members than the system recursion limit. This is less likely to happen when the CRIT_SEP parameter is lowered. For now i will be printing a warning and overriding the recursion limit manually