Skip to content

Commit

Permalink
Initial public release
Browse files Browse the repository at this point in the history
  • Loading branch information
andykee committed Jun 13, 2020
0 parents commit 2f56ca1
Show file tree
Hide file tree
Showing 148 changed files with 12,349 additions and 0 deletions.
122 changes: 122 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# PyCharm project settings
.idea/

# VS Code settings
.vscode/

# Sublime Text settings
*.sublime-project
*.sublime-workspace

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# MacOS junk
.DS_Store
*.swp

# LaTeX and Tikz
*.aux
*.log
*.pdf
7 changes: 7 additions & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
python:
version: 3.7
install:
- method: pip
path: .
- requirements: docs/requirements.txt
8 changes: 8 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Changes
=======

v0.1.0
------
Released June 12, 2020

* Initial public release
29 changes: 29 additions & 0 deletions LICENSE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Copyright (c) 2020, California Institute of Technology ("Caltech"). U.S.
Government sponsorship acknowledged.

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 changes: 33 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Lentil
======
Lentil is a Python library for modeling the imaging chain of an optical system.
It was originally developed at NASA's Jet Propulsion Lab by the Wavefront Sensing and
Control group (383E) to provide an easy to use framework for simulating point spread
functions of segmented aperture telescopes.

Lentil provides classes for representing optical elements with a simple interface for
including effects like wavefront error, radiometric properties, and various noise and
aberration sources. Lentil also provides numerical methods for performing Fraunhofer
(far-field) diffraction calculations. The collection of classes provided by Lentil can
be used to simulate imagery for a wide variety of optical systems.

Lentil is still under active development and new features continue to be added. Until
Lentil reaches version 1.0, the API is not guaranteed to be stable, but changes breaking
backwards compatibility will be noted.

Installing
----------
Install and update using `pip`_:

.. code-block:: text
pip install lentil
Links
-----
* Documentation: https://lentil.readthedocs.io/
* Releases: https://pypi.org/project/lentil/
* Code: https://github.com/andykee/lentil/
* Issue tracker: https://github.com/andykee/lentil/issues/

.. _pip: https://pip.pypa.io/en/stable/quickstart/
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
123 changes: 123 additions & 0 deletions docs/_img/python/getting_started.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import numpy as np
import matplotlib.pyplot as plt
import monocle as mo

pm_mask = mo.util.circle(shape=(512, 512), radius=256)
sm_obsc = mo.util.circle(shape=(512, 512), radius=256/3)
sm_obsc_vert = np.zeros((512,512))
sm_obsc_vert[:, 252:258] = 1
sm_obsc_horiz = np.zeros((512, 512))
sm_obsc_horiz[252:258, :] = 1
mask = pm_mask - sm_obsc - sm_obsc_vert - sm_obsc_horiz
mask[np.where(mask < 0)] = 0 # Make the mask binary (0's and 1's)
plt.imshow(mask)
plt.savefig('../../_static/img/quickstart_pupil.png', transparent=True, bbox_inches='tight', dpi=150)
plt.close()

simple_pupil = mo.Pupil(diameter=0.5, focal_length=10, pixelscale=0.5/512, amplitude=mask)
simple_detector = mo.Detector(pixelscale=15e-6, shape=(512, 512))
planes = [simple_pupil, simple_detector]
psf = mo.propagate(planes, wave=550e-9, npix=(128,128))
plt.imshow(psf**0.1)
plt.savefig('../../_static/img/quickstart_psf_550_native.png', transparent=True, bbox_inches='tight', dpi=150)
plt.close()


psf = mo.propagate(planes, wave=np.arange(450e-9,650e-9,10e-9), npix=(128,128), oversample=5, rebin=False)

plt.imshow(psf**0.1)
plt.savefig('../../_static/img/quickstart_psf_broadband_5.png', transparent=True, bbox_inches='tight', dpi=150)


simple_pupil = mo.Pupil(diameter=0.5,
focal_length=10,
pixelscale=0.5/512,
amplitude=mask,
phase=-1400e-9 * mo.zernike.zernike(mask, index=11))
plt.imshow(simple_pupil.phase)
plt.savefig('../../_static/img/quickstart_opd_spherical.png', transparent=True, bbox_inches='tight', dpi=150)
plt.close()

planes = [simple_pupil, simple_detector]
psf = mo.propagate(planes, wave=np.arange(475e-9,485e-9,1e-9), npix=(128,128))
plt.imshow(psf**0.1)
plt.savefig('../../_static/img/quickstart_psf_480_spherical.png', transparent=True, bbox_inches='tight', dpi=150)
plt.close()


qe = mo.radiometry.Spectrum(wave=[400, 600, 1000], value=[0.4, 0.8, 0.05], waveunit='nm', valueunit=None)
gain = mo.detector.Gain(gain=0.0016, saturation_capacity=10000)
simple_detector = mo.FPA(pixelscale=15e-6, shape=(512, 512), qe=qe, gain=gain)
irrad = np.tile(np.arange(512)/511, (512,1)) # gradient spanning [0, 1]
flux = irrad * 15000 # flux spanning [0, 15000] e-
plt.imshow(flux, cmap='gray')
plt.colorbar()
plt.savefig('../../_static/img/quickstart_detector_irradiance.png', transparent=True, bbox_inches='tight', dpi=150)
plt.close()


img = simple_detector.frame(flux, ts=1.5, wave=650, waveunit='nm')
plt.imshow(img, cmap='gray')
plt.colorbar()
plt.savefig('../../_static/img/quickstart_detector_frame.png', transparent=True, bbox_inches='tight', dpi=150)
plt.close()


detector_attrs = {
'qe': qe,
'gain': mo.detector.Gain(gain=2**12/15000, saturation_capacity=15000),
'shot_noise': mo.detector.ShotNoise(),
'read_noise': mo.detector.ReadNoise(50),
'dark_signal': mo.detector.DarkCurrent(500)}

simple_detector = mo.FPA(pixelscale=15e-6, shape=(512, 512), **detector_attrs)
simple_pupil = mo.Pupil(diameter=0.5,
focal_length=10,
pixelscale=0.5/512,
amplitude=mo.util.normalize_power(mask),
phase=-1400e-9 * mo.zernike.zernike(mask, index=11))

src = mo.radiometry.Blackbody.vegamag(wave=np.arange(350, 750),
temp=9500,
mag=8,
band='V')

ir_filter = mo.radiometry.Spectrum(wave=[350, 395, 400, 700, 705, 750], value=[0, 0, 0.8, 0.8, 0, 0])
collecting_area = np.pi*(simple_pupil.diameter/2 - simple_pupil.diameter/6)**2
irradiance = src * ir_filter * collecting_area

fig, ax = plt.subplots(3,1, figsize=[5, 5])

ax[0].plot(src.wave, src.value)
ax[0].grid()
ax[0].set_ylim([40000,80000])
ax[0].set_title('Stellar flux')
ax[0].set_ylabel('ph/s/m^2/λ')

ax[1].plot(ir_filter.wave, ir_filter.value)
ax[1].grid()
ax[1].set_ylim([0,1])
ax[1].set_title('IR filter')
ax[1].set_ylabel('a.u.')

ax[2].plot(irradiance.wave, irradiance.value)
ax[2].grid()
ax[2].set_ylim([0,6000])
ax[2].set_title('Detector irradiance')
ax[2].set_ylabel('ph/s/λ')
ax[2].set_xlabel('Wavelength [nm]')

plt.tight_layout()
plt.savefig('../../_static/img/quickstart_source.png', transparent=True, bbox_inches='tight', dpi=150)
plt.close()


wave = np.arange(350,750,10)
binned_irradiance = irradiance.bin(wave)
planes = [simple_pupil, simple_detector]
psf = mo.propagate(planes, wave=wave*1e-9, weight=binned_irradiance,
npix=(128, 128), flatten=False)
img = simple_detector.frame(psf, ts=1e-4, wave=wave, collect_charge=True)
plt.imshow(img, cmap='gray')
plt.savefig('../../_static/img/quickstart_img.png', transparent=True, bbox_inches='tight', dpi=150)
plt.close()
Loading

0 comments on commit 2f56ca1

Please sign in to comment.