Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem with the exemple? #35

Open
Teusia opened this issue Mar 31, 2021 · 3 comments
Open

problem with the exemple? #35

Teusia opened this issue Mar 31, 2021 · 3 comments

Comments

@Teusia
Copy link

Teusia commented Mar 31, 2021

Hello @astromam and @avigan ,

I am trying to learn how to use your library using the code in the example repertory (simple_zelda_analysis.py).
however something is not working, I get this error message:

TypeError: only size-1 arrays can be converted to Python scalars
The above exception was the direct cause of the following exception:

Traceback (most recent call last):

  File "~\simulations\python\pyZELDA\examples\simple_zelda_analysis.py", line 39, in <module>
    basis, coeff, opd_zern = ztools.zernike_expand(opd_map.mean(axis=0), 20)

  File "~\anaconda3\envs\poppystable\lib\site-packages\pyzelda-1.1-py3.8.egg\pyzelda\ztools.py", line 688, in zernike_expand
    reconstructed_opd[i] += coeffs_tmp[z] * basis[z, :, :]

ValueError: setting an array element with a sequence.

This is happening in function zernike_expand in the ztools.py.
I have been at it all morning I actually do not see how this can work:
reconstructed_opd[i] is a float
coeffs_tmp[z] is a float
basis[z, :, :] is a 2 dimensional array

So multiplying a float by an array is fine but trying to add an array into a single numpy array element will not work.
After investigation I think the culprit is line 39 of simple_zelda_analysis.py :

basis, coeff, opd_zern = ztools.zernike_expand(opd_map.mean(axis=0), 20)

The the script works for me if i remove that .mean. Can you confirm that this is the way to go please?
I suspect that this was made this way in cases where opd_map actually has three dimension ? (why would it though?)
I put there after the entire script that works for me with both datasets you provide.
I left #FIXME comment where I changed something, the original lines are commented and the following line is the one that fixes the problem for me.

import matplotlib.pyplot as plt
import numpy as np

import pyzelda.zelda as zelda
import pyzelda.ztools as ztools
import pyzelda.utils.aperture as aperture

from pathlib import Path

# path = Path('/Users/mndiaye/Dropbox/python/zelda/pyZELDA/')
# path = Path('/Users/avigan/Work/GitHub/pyZELDA/data/')
# path = Path('D:/Programmes/GitHub/pyZELDA/')
path = Path('../data')

wave = 1.642e-6

# internal data
# clear_pupil_files = ['SPHERE_CLEAR_PUPIL_CUBE1_NDIT=3', 'SPHERE_CLEAR_PUPIL_CUBE1_NDIT=3']
# zelda_pupil_files = ['SPHERE_ZELDA_PUPIL_CUBE1_NDIT=3', 'SPHERE_ZELDA_PUPIL_CUBE2_NDIT=3']

# dark_file  = 'SPHERE_BACKGROUND'
# pupil_tel  = False

# on-sky data
clear_pupil_files = ['SPHERE_GEN_IRDIS057_0002']
zelda_pupil_files = ['SPHERE_GEN_IRDIS057_0001']
dark_file  = 'SPHERE_GEN_IRDIS057_0003'
pupil_tel  = True

# ZELDA analysis
z = zelda.Sensor('SPHERE-IRDIS', pupil_telescope=pupil_tel)

clear_pupil, zelda_pupil, center = z.read_files(path, clear_pupil_files, zelda_pupil_files, dark_file,
                                                collapse_clear=True, collapse_zelda=True)

opd_map = z.analyze(clear_pupil, zelda_pupil, wave=wave)

# decomposition on Zernike polynomials
#FIXME
# basis, coeff, opd_zern = ztools.zernike_expand(opd_map.mean(axis=0), 20)
basis, coeff, opd_zern = ztools.zernike_expand(opd_map, 20)

# plot
fig = plt.figure(0, figsize=(16, 4))
plt.clf()

ax = fig.add_subplot(141)
ax.imshow(clear_pupil.mean(axis=0), aspect='equal', vmin=0, vmax=15000, origin='lower')
ax.set_title('Clear pupil')

ax = fig.add_subplot(142)
ax.imshow(zelda_pupil.mean(axis=0), aspect='equal', vmin=0, vmax=15000, origin='lower')
ax.set_title('ZELDA pupil')

ax = fig.add_subplot(143)
#FIXME
# ax.imshow(opd_map.mean(axis=0), aspect='equal', vmin=-150, vmax=150, cmap='magma', origin='lower')
ax.imshow(opd_map, aspect='equal', cmap='magma', origin='lower')
ax.set_title('OPD map')

ax = fig.add_subplot(144)
#FIXME
# cax = ax.imshow(opd_zern.mean(axis=0), aspect='equal', vmin=-150, vmax=150, cmap='magma', origin='lower')
cax = ax.imshow(opd_zern[0], aspect='equal', cmap='magma', origin='lower')
ax.set_title('Zernike projected OPD map')

cbar = fig.colorbar(cax)
cbar.set_label('OPD [nm]')

plt.tight_layout()
plt.show()

Cheers,
Anne-Laure

@avigan
Copy link
Owner

avigan commented Mar 31, 2021

Hello @Teusia!

I confirm that the example is not fully up-to-date with respect to the code. I will try to solve the issue with the next official release of pyZELDA.

Solving the issue by removing the .mean() call is fine. pyZELDA can work either with single images or with cubes of images (i.e. sequences). I suppose that a previous example data set must have included an image cube, instead of a single image in the current version, which is why a mean was required to display the image with imshow().

@Teusia
Copy link
Author

Teusia commented Apr 1, 2021

Hello @avigan ,

Thank you for your answer, then I'll keep learning without the .mean.
However you might want to have a close look at the image cube case because in the example set the 'internal data' has 'SPHERE_CLEAR_PUPIL_CUBE1_NDIT=3' and 'SPHERE_ZELDA_PUPIL_CUBE2_NDIT=3' who contains more than one image according to DS9. At least on my machine the .mean does not work there either with the ztools.zernike_expand.

Should I close the issue or let it open as a reminder?
Cheers,
@alcheffot

@avigan
Copy link
Owner

avigan commented Apr 1, 2021

Leave it open, I will close it when the example works again ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants