Q3D / q3dfit

Python software for fitting integral field spectroscopic data
GNU General Public License v3.0
10 stars 3 forks source link

Empty arrays cause break in multicore fitting #26

Open kykyelric opened 2 months ago

kykyelric commented 2 months ago

I noticed while fitting MIRI data that when the iflux/weights/qsotemplate that are fed into lmfit in contfit.py are empty, all the fits in the core break and an entire section of spaxels do not get fit. Is there a way to prevent the fit of the specific spaxel with empty iflux/weights/qsotemplate from happening so that the rest in the core do not break?

Traceback (most recent call last):
  File "/home/kydan/anaconda3/envs/q3d_dev2/lib/python3.9/site-packages/q3dfit/q3df_helperFunctions.py", line 226, in <module>
    q3df_multiCore(rank, size, inobj, cols, rows, onefit, quiet)
  File "/home/kydan/anaconda3/envs/q3d_dev2/lib/python3.9/site-packages/q3dfit/q3df_helperFunctions.py", line 173, in q3df_multiCore
    execute_fitloop(nspax_thisCore, colarr, rowarr, cube, q3di,
  File "/home/kydan/anaconda3/envs/q3d_dev2/lib/python3.9/site-packages/q3dfit/q3df_helperFunctions.py", line 63, in execute_fitloop
    fitloop(ispax, colarr, rowarr, cube, q3di, linelist, specConv,
  File "/home/kydan/anaconda3/envs/q3d_dev2/lib/python3.9/site-packages/q3dfit/fitloop.py", line 264, in fitloop
    q3do = fitspec(cube.wave, flux, err, dq, q3do_init.zstar,
  File "/home/kydan/anaconda3/envs/q3d_dev2/lib/python3.9/site-packages/q3dfit/fitspec.py", line 311, in fitspec
    fcncontfit(gdlambda.astype(usetype),
  File "/home/kydan/anaconda3/envs/q3d_dev2/lib/python3.9/site-packages/q3dfit/contfit.py", line 203, in fitqsohost
    result = ymod.fit(iflux, params, weights=np.sqrt(iweight),
  File "/home/kydan/anaconda3/envs/q3d_dev2/lib/python3.9/site-packages/lmfit/model.py", line 1103, in fit
    output.fit(data=data, weights=weights)
  File "/home/kydan/anaconda3/envs/q3d_dev2/lib/python3.9/site-packages/lmfit/model.py", line 1467, in fit
    _ret = self.minimize(method=self.method)
  File "/home/kydan/anaconda3/envs/q3d_dev2/lib/python3.9/site-packages/lmfit/minimizer.py", line 2345, in minimize
    return function(**kwargs)
  File "/home/kydan/anaconda3/envs/q3d_dev2/lib/python3.9/site-packages/lmfit/minimizer.py", line 1541, in least_squares
    ret = least_squares(self.__residual, start_vals,
  File "/home/kydan/anaconda3/envs/q3d_dev2/lib/python3.9/site-packages/scipy/optimize/_lsq/least_squares.py", line 820, in least_squares
    raise ValueError("`x0` is infeasible.")
kykyelric commented 2 months ago

This seems to be resolved by setting nocrash=True in the execute_fitloop function within q3df_helperFunctions.py. Not sure if this is a permanent solution or not.

drupke commented 2 months ago

Thanks for finding that fix. I've re-opened this so I will remember to go in and track this down and ensure that indeed this is a permanent rather than temporary solution.