manoharan-lab / holopy

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

_scsmfo_setup failure with collection of two spheres #340

Closed peteasa closed 4 years ago

peteasa commented 4 years ago

Using latest develop branch. It seems like there is a problem, perhaps with my use of calc_holo that demonstrates a failure in _redirect_stdout. The code works fine with a single Sphere, but fails with multiple. Any idea where this bug is? _redirect_stdout `title = 'Collection' s1 = Sphere(center=(5, 5, 5), n = 1.59, r = .5) s2 = Sphere(center=(4, 4, 5), n = 1.59, r = .5) obj = Spheres([s1, s2])

medium_index = 1.33 illum_wavelen = 0.660 illum_polarization = (1,0) spacing = 0.1 detector = hp.detector_grid(shape = 100, spacing = spacing)

holo = calc_holo(detector, obj, medium_index, illum_wavelen, illum_polarization) Traceback (most recent call last): File "./cgenholgram.py", line 32, in holo = calc_holo(detector, obj, medium_index, illum_wavelen, illum_polarization) File "/home1/pas/Projects/hologram/holopy/holopy/scattering/interface.py", line 208, in calc_holo scatterer.guess, uschema) File "/home1/pas/Projects/hologram/holopy/holopy/scattering/theory/scatteringtheory.py", line 88, in calculate_scattered_field self._calculate_single_color_scattered_field(scatterer, schema)) File "/home1/pas/Projects/hologram/holopy/holopy/scattering/theory/scatteringtheory.py", line 156, in _calculate_single_color_scattered_field field = self._get_field_from(scatterer, schema) File "/home1/pas/Projects/hologram/holopy/holopy/scattering/theory/scatteringtheory.py", line 185, in _get_field_from illum_polarization=schema.illum_polarization) File "/home1/pas/Projects/hologram/holopy/holopy/scattering/theory/multisphere.py", line 215, in _raw_fields amn, lmax = self._scsmfo_setup(scatterer, medium_wavevec=medium_wavevec, medium_index=medium_index) File "/home1/pas/Projects/hologram/holopy/holopy/scattering/theory/multisphere.py", line 195, in _scsmfo_setup self.qeps1, self.qeps2, self.meth, (0,0)) File "/home1/pas/Projects/hologram/holopy/holopy/core/utils.py", line 73, in exit self._redirect_stdout(self.default_stdout) File "/home1/pas/Projects/hologram/holopy/holopy/core/utils.py", line 62, in _redirect_stdout sys.stdout = io.TextIOWrapper(os.fdopen(self.std_out, 'wb')) File "/usr/lib/python3.6/os.py", line 1017, in fdopen return io.open(fd, *args, **kwargs) OSError: [Errno 9] Bad file descriptor `

Peter

barkls commented 4 years ago

Thanks for raising the issue. This is some code that I recently modified in the development branch and it looks like I must have missed something. If you could answer a few questions it could be helpful in diagnosing the problem:

Does the problem occur every time you run the code or only once in a while? What operating system and python version are you using? What do you get if you call sys.stdout.fileno()

In the meantime, if you want to run Multisphere code, you have a couple options. You can use the stable master branch or you can call calc_holo with the theory argument set to `hp.scattering.Multisphere(suppress_fortran_output=False).

peteasa commented 4 years ago

Actually I work round the problem by commenting out _redirect_stdout and it works just fine! I have holopy installed "python setup.py develop --user" so any changes are immediately available.

The problem occurs every time I run my code and also fails in ipython when I cut and paste the appropriate lines out of the HoloPy Documents. I am using Ubuntu 18.04.4 LTS with Python 3.6.9 fileno: 1

Thanks for the theory argument tip... tried that but it did not work for some reason... will stick with my commented out workround!

barkls commented 4 years ago

I think I've fixed the problem in a new branch. It would be great if you could check it out and let me know if it works!

What didn't work about passing in the theory?

peteasa commented 4 years ago

did a pull and got your changes... bug seems to be fixed...

passing the theory did not seem to make any difference. it still crashed with what looked like the same error messages!

Thanks for your help