perwin / pyimfit

Python wrapper for astronomical image-fitting code Imfit (https://github.com/perwin/imfit)
GNU General Public License v3.0
34 stars 4 forks source link

Issue with fitting >=3 components: bug in description.py? #9

Closed zychen-astro closed 2 months ago

zychen-astro commented 2 months ago

Hello Peter,

In descriptions.py:

def functionSetIndices(self): """ Get the indices in the full parameters list corresponding to the starts of individual function sets/blocks. Returns

indices : list of int """ indices = [0] for i in range(self.nFunctionSets - 1): functionsThisSet = self._functionSets[i].functionList() indices.append(len(functionsThisSet)) return indices

In each iteration it appends len(functionsThisSet) to list indices. So if there are >=3 function sets, with with len(functionsThisSet)=1, the indices will be [0,1,1,...], which does not seem to be correct. This leads the additional components not to be fitted, and sometimes also significantly impact the results for the first two components.

Previously, I modified the relevant code to be: indices.append(indices[-1]+len(functionsThisSet)) and found it working. This issue still exists in v1.0.

Could you please confirm this?

Thank you, Zuyi

perwin commented 2 months ago

Hi Zuyi,

Thanks for bringing this to my attention -- I'll take a look and get back to you as soon as possible.

perwin commented 2 months ago

Hi Zuyi,

My apologies for not getting back to you on this. I've gone ahead and implemented your fix (and added a unit test for it), and am working on generating an updated version to include it.

Thanks again for noticing this, and for suggesting the fix!

perwin commented 2 months ago

Latest release (v1.0.2, propagated to PyPI and conda) should fix this -- if you can, test it and let me know if it works for you.

zychen-astro commented 2 months ago

Hi Peter, thank you for the fix. I have update to v1.0.2 and verified that it works!