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

It would be nice to compare opd_expand() to a fitting function #143

Open
douglase opened this issue Jan 28, 2016 · 0 comments
Open

It would be nice to compare opd_expand() to a fitting function #143

douglase opened this issue Jan 28, 2016 · 0 comments

Comments

@douglase
Copy link
Contributor

I have code for fitting zernike's with scipy optimizers to noisy data. I will put something together to compare that to the simpler decomposing function that already exists in POPPY (

poppy/poppy/zernike.py

Lines 455 to 512 in b6eed44

def opd_expand(opd, aperture=None, nterms=15, basis=zernike_basis,
**kwargs):
"""Given a wavefront OPD map, return the list of coefficients in a
given basis set (by default, Zernikes) that best fit the OPD map.
Parameters
----------
opd : 2D numpy.ndarray
The wavefront OPD map to expand in terms of the requested basis.
Must be square.
aperture : 2D numpy.ndarray, optional
ndarray giving the aperture mask to use
(1.0 where light passes, 0.0 where it is blocked).
If not explicitly specified, all finite points in the `opd`
array (i.e. not NaNs) are assumed to define the pupil aperture.
nterms : int
Number of terms to use. (Default: 15)
basis : callable, optional
Callable (e.g. a function) that generates a sequence
of basis arrays given arguments `nterms`, `npix`, and `outside`.
Default is `poppy.zernike.zernike_basis`.
Additional keyword arguments to this function are passed
through to the `basis` callable.
Note: Recovering coefficients used to generate synthetic/test data
depends greatly on the sampling (as one might expect). Generating
test data using zernike_basis with npix=256 and passing the result
through opd_expand reproduces the input coefficients within <0.1%.
Returns
-------
coeffs : list
List of coefficients (of length `nterms`) from which the
input OPD map can be constructed in the given basis.
(No additional unit conversions are performed. If the input
wavefront is in waves, coeffs will be in waves.)
"""
if aperture is None:
_log.warn("No aperture supplied - "
"using the finite (non-NaN) part of the OPD map as a guess.")
aperture = np.isfinite(opd).astype(np.float)
basis_set = basis(
nterms=nterms,
npix=opd.shape[0],
outside=np.nan,
**kwargs
)
wgood = np.where((aperture != 0.0) & np.isfinite(basis_set[1]))
ngood = (wgood[0]).size
coeffs = [(opd * b)[wgood].sum() / ngood
for b in basis_set]
return coeffs
)

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

No branches or pull requests

2 participants