manoharan-lab / holopy

Hologram processing and light scattering in python
GNU General Public License v3.0
134 stars 50 forks source link

cannot fit a model that contains theory like MieLens/AberratedMieLens #389

Closed weh40 closed 3 years ago

weh40 commented 3 years ago

I am a beginner trying to use Holopy to fit a hologram with lens and/or spherical aberration. As a theory keyword input to Model, ExactModel or AlphaModel (not PerfectLensModel which seems cannot be imported ) along with the scatterer of Sphere, I need to define 4 extra parameters from prior.Uniform/Gaussian, including lens_angle.

The typical codes as follows: """"""""""""""""""""""""""""""""""""""""""""""""""""" import holopy as hp from holopy.scattering import Sphere from holopy.scattering.theory import MieLens, AberratedMieLens from holopy.inference import prior, ExactModel, AlphaModel

x=prior.Uniform(15,30,24) y=prior.Uniform(15,30,22) z=prior.Uniform(10,20) n1=prior.Uniform(0,4,2.0) n2=prior.Uniform(0,4,2.0) n3=prior.Uniform(0,4,2.0) r0=prior.Gaussian(0.5,0.05) beta=prior.Uniform(0.5, 1.5, 1.0)

theory1=MieLens(lens_angle=beta) theory2=AberratedMieLens(spherical_aberration=[n1,n2,n3], lens_angle=1.0) sphere=Sphere(n=1.58,r=r0, center=[x,y,z]) model=AlphaModel(scatterer=sphere, alpha=1.0, theory=theory1) fit_result=hp.fit(data_holo,model) #data_holo from any example hologram in tutorial """""""""""""""""""""""""""""""""""""""""""""""""""""

However, it always gives errors like: """""""""""""""""""""""""""""""""" AttributeError: 'TransformedPrior' objec has no attribute 'reshape' """ when I set prior to lens_angle (theory1)

or """""""""""""""""""""""""""""""""" TypeError: Cannot multiply prior by objects of type <class 'complex'> """ when I set prior to aberration coefficients (theory2).

no matter how I tried.

-- Though the hologram image with fixed spherical aberration/lens_angle values can be forward generated trivially.

I wish to know how can I get it work, and would appreciate if any help/example on fitting a model with lens and aberration.

briandleahy commented 3 years ago

Hi @weh40 -- what version of holopy are you using and how did you install it? I think this is currently fixed on the develop branch.

weh40 commented 3 years ago

Hi @briandleahy> my version should be latest 3.4.0 installed by downloading the github zip package, followed by running the line “python setup.py develop“ under the folder: holopy-develop/ . but the problem is still there. btw I had also used "conda install -c conda-forge holopy".

weh40 commented 3 years ago

@briandleahy> Ah..I see, I should also run another line "python setup.py build_ext --inplace", then it works. Thanks very much for your reminder!

briandleahy commented 3 years ago

Hi @weh40 , did that resolve your problem? If so, I'll close the issue.

weh40 commented 3 years ago

Hi, Yes, please close it.