ShOpt.jl
ShOpt.jl: A Julia Package for Empirical Point Spread Function Characterization of JWST NIRCam Data - Published in JOSS (2024)
Science Score: 98.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 8 DOI reference(s) in README and JOSS metadata -
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
✓JOSS paper metadata
Published in Journal of Open Source Software
Keywords
Scientific Fields
Repository
[Astronomical Journal 2024] Efficient Point-spread Function Modeling with ShOpt.jl: A PSF Benchmarking Study with JWST NIRCam Imaging
Basic Info
- Host: GitHub
- Owner: EdwardBerman
- License: mit
- Language: Julia
- Default Branch: main
- Homepage: https://edwardberman.github.io/shopt/
- Size: 184 MB
Statistics
- Stars: 23
- Watchers: 2
- Forks: 2
- Open Issues: 1
- Releases: 8
Topics
Metadata Files
README.md
Table of Contents
- About
- Inputs and Outputs
- Running
- Program Architecture
- How Can I Contribute?
- Config / YAML Information
- Known Issues
- Contributors
- Further Acknowledgements
About

Shear Optimization with ShOpt.jl, a julia library for empirical point spread function characterizations. We aim to improve upon the current state of Point Spread Function Modeling by using Julia to leverage performance gains, use a different mathematical formulation than the literature to provide more robust analytic and pixel grid fits, improve the diagnostic plots, and add features such as wavelets and shapelets. At this projects conclusion we will compare to existing software such as PIFF and PSFex. Work done under McCleary's Group.
We release the related benchmarking code at https://github.com/mcclearyj/cweb_psf
Start by Cloning This Repository. Then see TutorialNotebook.ipynb or follow along the rest of this README.md to get started! Note that the commands in the tutorial notebook are meant to give a sense of procedure and can be executed with the Julia REPL itself.
Who Should Use
Users looking for empirical point spread function characterization software tailored for the data coming from the James Webb Space Telescope, or on a dataset with the similar characteristics. For example, the point spread function spans 100s of pixels because of the pixel scale of your camera, the point spread function is not well approximated by an analytic profile, or the point spread function varies alot across the field of view. For any of these reasons, you should consider using ShOpt.jl. ShOpt.jl is not a single function package, and we would encourage the user to explore the full functionality of ShOpt.jl in the sample config to tailor the software to their needs.
JWST Data is now publicly available at: https://cosmos.astro.caltech.edu/page/cosmosweb-dr. ShOpt was evaluated across all of the wavelengths in the 30mas pixel scale at this link.
Analytic Profile Fits
ShOpt.jl's analytic profile fitting takes inspiration from a number of algorithms outside of astronomy, notably SE-Sync, an algorithm that solves the robotic mapping problem by considering the manifold properties of the data. With sufficiently clean data, the SE-Sync algorithm will descend to a global minimum constrained to the manifold $SE(d)^n / SE(d)$. Following suit, we are able to put a constraint on the solutions we obtain to $[s, g1, g2]$ to a manifold. The solution space to $[s, g1, g2]$ is constrained to the manifold $$B2(r) \times \mathbb{R}{+}$$. The existence of the constraint on shear is well known; nevertheless, the parameter estimation task is usually framed as an unconstrained problem.
Path to $[s, g1, g2]$ in $B2(r) \times \mathbb{R}+$

Pixel Grid Fits
PCA Mode
We used the first n weights of a Principal Component Analysis and use that to construct our PSF in addition to a smoothing kernel to account for aliasing
Autoencoder Mode
For doing Pixel Grid Fits we use an autoencoder model to reconstruct the Star
PCA mode
```Julia
function pcaimage(image, ncomponents)
#Load img Matrix
imgmatrix = image
# Perform PCA
M = fit(PCA, img_matrix; maxoutdim=ncomponents)
# Transform the image into the PCA space
transformed = MultivariateStats.transform(M, img_matrix)
# Reconstruct the image
reconstructed = reconstruct(M, transformed)
# Reshape the image back to its original shape
reconstructedimage = reshape(reconstructed, size(imgmatrix)...)
end
`Autoencoder mode`
Julia
Encoder
encoder = Chain(
Dense(r*c, 128, leakyrelu),
Dense(128, 64, leakyrelu),
Dense(64, 32, leakyrelu),
)
Decoder
decoder = Chain(
Dense(32, 64, leakyrelu),
Dense(64, 128, leakyrelu),
Dense(128, r*c, tanh),
)
Full autoencoder
autoencoder = Chain(encoder, decoder)
x_hat = autoencoder(x)
loss(x) = mse(autoencoder(x), x)
Define the optimizer
optimizer = ADAM()
```
Interpolation Across the Field of View
[s, g1, g2] are all interpolated across the field of view. Each Pixel is also given an interpolation across the field of view for an nth degree polynomial in (u,v), where n is supplied by the user
The plot on the left shows the average cutout of all stars in a supplied catalog. The plot in the middle shows the average point spread function model for each star. The plot on the right shows the average normalized error between the observed star cutouts and the point spread function model.
Inputs and Outputs
Currently, the inputs are JWST Point Spread Functions source catalogs. The current outputs are images of these Point Spread Functions, Learned Analytic Fits, Learned Pixel Grid Fits, Residual Maps, Loss versus iteration charts, and p-value statisitcs. Not all functionality is working in its current state. Planned functionality for more Shear checkplots.
Inputs
| Image | Description |
|-----------------------------------|------------------------------------|
|
| Star Taken From Input Catalog |
| shopt.yml | Config File for Tunable Parameters |
| * starcat.fits | Star Catalog to take vignets from |
Outputs
| Image | Description |
|----------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------|
| summary.shopt | Fits File containing summary statistics and information to reconstruct the PSF |
|
| Pixel Grid Fit for the Star Above |
|
| Residual Map for Above Model and Fit |
|
| s varying across the field of view |
|
| g1 varying across the field of view |
|
| g2 varying across the field of view |
|
| Histogram for learned profiles for each star in an analytic fit with their residuals |
|
| Same data recorded as a scatterplot with and without outliers removed and with error bars |
NB: This is not a comprehensive list, only a few cechkplots are presented. See the shopt.yml to configure which plots you want to see and save!
Running
Command
To run shopt.jl
First use Source Extractor to create a catalog for ShOpt to accept and save this catalog in the appropriate directory
Run julia shopt.jl [configdir] [outdir] [catalog]
There is also a shell script that runs this command so that the user may call shopt from a larger program they are running
Dependencies
Not all of these will be strictly necessary depending on the checkplots you produce, but for full functionality of ShOpt the following are necessary. Source Extractor (or Source Extractor ++) is also not a strict dependency, but in practice one will inevitably install to generate a catalog.
| Julia | Python | Binaries | Julia | Julia | |------------------|------------|----------|----------------|----------------| | Plots | matplotlib | SEx | ProgressBars | BenchmarkTools | | ForwardDiff | astropy | | UnicodePlots | Measures | | LinearAlgebra | numpy | | CSV | Dates | | Random | | | FFTW | YAML | | Distributions | | | Images | CairoMakie | | SpecialFunctions | | | ImageFiltering | Flux | | Optim | | | DataFrames | QuadGK | | IterativeSolvers | | | PyCall | Statistics |
Set Up
Start by cloning this repository. There are future plans to release ShOpt onto a julia package repository, but for now the user needs these files contents.
The dependencies can be installed in the Julia REPL. For example:
julia
import Pkg; Pkg.add("PyCall")
We also provide dependencies.jl, which you can run to download all of the Julia libraries automatically by reading in the imports.txt file. Simply run julia dependencies.jl in the command line. For the three python requirements, you can similarly run python dependenciesPy.py. We also have a project enviornment for the Julia packages in the folder shopt_env. It would be straightforward to add the line activate("shopt_env") to the first line of shopt.jl to read in this environment. Note that Pycall would have to be built within this environment in some of the next steps.
For some functionality we need to use wrappers for Python code, such as reading in fits files or converting (x,y) -> (u,v). Thus, we need to use certain Python libraries. Thankfully, the setup for this is still pretty straightfoward. We use PyCall to run these snippets.
There are four different methods to get Julia and Python to interopt nicely. We provide all of them as some of these methods play better with different systems.
First install the required Python libraries via pip (which is what dependenciesPy.py does). Now, for method 1, invoke the following in the julia REPL:
julia
using PyCall
ENV["PYTHON"] = "/path_desired_python_directory/python_executable"; import Pkg; Pkg.build("PyCall")
pyimport("astropy")
It is important that the command pyimport("astropy") should be run after re-loading the Julia REPL.
Method 2. If you have a Conda Enviornment setup, you may find it easier to run
julia
using PyCall
pyimport_conda("astropy", "ap") #ap is my choice of name and astropy is what I am importing from my conda Enviornment
Method 3. julia also has a way of working with conda directly. Note that julia will create its own conda enviornment to read from.
julia
using Conda
Conda.add("astropy", :my_env) #my conda enviornment is named my_env
You may also do using Conda; Conda.add("astropy", "/path/to/directory") or using Conda; Conda.add("astropy", "/path/to/directory"; channel="anaconda")
Method 4. On the off chance that none of these works, a final method may look like the following
julia
using PyCall
run(`$(PyCall.python) -m pip install --upgrade cython`)
run(`$(PyCall.python) -m pip install astropy`)
After the file contents are downloaded the user can run julia shopt.jl [configdir] [outdir] [catalog] as stated above. Alternatively, they can run the shellscript that calls shopt in whatever program they are working with to create their catalog. For example, in a julia program you may use run(`./runshopt.sh [configdir] [outdir] [catalog]`)
Multithreading
Before running, we recommend that users run export JULIA_NUM_THREADS=4 on Unix machines set JULIA_NUM_THREADS=4 . By default Julia will run the program on a single thread, but the polynomial interpolation step is inherently parallelizable. The program is set to use all of threads available to it. You may do more than 4, just be cautious about what your system can provide and when you start getting dimminishing returns.
Testing
To test that everything works, running the dependencies.jl should test that everything is installed correctly in addition to downloading. Running
julia
pyimport("astropy")
pyimport("matplotlib")
pyimport("numpy")
in the Julia REPL should ensure that Julia and Python are interopping correctly.
Additionally, in the Julia REPL, we may write
julia
using Base.Threads
nthreads()
to make sure we are using 4 or more threads. The TutorialNotebook.ipynb will walk you through and test all of the functionality of the program.
Program Architecture
TutorialNotebook.ipynb
Run ShOpt inside of a Jupyter Notebook and learn both how to run the program and how to reconstruct the PSF
shopt.jl
A runner script for all functions in this software
dataPreprocessing.jl
A wrapper for python code to handle fits files and dedicated file to deal with data cleaning
dataOutprocessing.jl
Convert data into a summary.shopt file. Access this data with reader.jl. Produces some additional python plots.
reader.jl
Get Point Spread Functions at an arbitrary (u,v) by reading in a summary.shopt file
plot.jl
A dedicated file to handle all plotting
radialProfiles.jl
Contains analytic profiles such as a Gaussian Fit and a kolmogorov fit
analyticLBFGS.jl
Provides the necessary arguments (cost function and gradient) to the optimize function for analytic fits
pixelGridAutoencoder.jl
Houses the function defining the autoencoder and other machine learning functions supplied to Flux's training call
interpolate.jl
For Point Spread Functions that vary across the Field of View, interpolate.jl will fit a nth degree polynomial in u and v to show how each of the pixel grid parameters change across the (u,v) plane
outliers.jl
Contains functions for identifying and removing outliers from a list
powerSpectrum.jl
Computes the power spectra for a circle of radius k, called iteratively to plot P(k) / k
kaisserSquires.jl
Computes the Kaisser-Squires array to be plotted
runshopt.sh
A shell script for running Shopt. Available so that users can run a terminal command in whatever program they are writing to run shopt.
LICENSE
MIT LICENSE
README.md
User guide, Dependencies, etc.
index.md
For official website
_config.yml
Also for official website
imports.txt
List of Julia Libraries used in the program
packages.txt
List of Python Libraries used in the program
dependencies.jl
Download all of the imports from imports.txt automatically
dependenciesPy.py
Download all of the imports from packages.txt automatically
Config / YAML Information
saveYaml
- Set true if you want to save the YAML to the output directory for future reference, set to false otherwise
NNparams
- epochs
- Set the Maximum Number of training epochs should the model never reach the minimum gradient of the loss function. Set to 1000 by default
- minGradientPixel
- A stopping gradient of the loss function for a pixel grid fit. Set to 1e-6 by default
AnalyticFitParams
- minGradientAnalyticModel
- A stopping gradient of the loss function for an analytic profile fit for input star vignets from a catalog. Set to 1e-6 by default
- minGradientAnalyticLearned
- A stopping gradient of the loss function for an analytic profile fit for stars learned by a pixel grid fit. Set to 1e-6 by default
- analyticFitStampSize
- The box size for the subset of your stamp (see stamp size) you wish to use for analytic profile fitting. Ensure to specify this to be smaller than the stamp size of the vignets themselves. Set to 64 by default, therefore fitting an analytic profile to the middle 64 x 64 pixels of the stamp.
dataProcessing
- SnRPercentile
- Supply a float that represents the percentile below which stars will be filtered by on the basis of signal to noise ratio. Set to 0.33 by default
- sUpperBound
- Stars fit with an analytic profile are filtered out if their s exceeds this upper bound. Set to 1 by default
- sLowerBound
- Stars fit with an analytic profile are filtered out if their s falls beneath this lower bound. Set to 0.075 by default
plots - Set true to plot and save a given figure, false otherwise
polynomialDegree
- The degree of the polynomial used to interpolate each pixel in the stamp across the field of view. Set to 3 by default
stampSize
- The size of the vignet for which use wish to fit. Used interpolation for oversampling and a simple crop for undersampling. Set to 131 by default to fit and interpolate 131 x 131 pixels
training_ratio
- Before doing a polynomial interpolation, the remaining stars will be divided into training and validation stars based off of this float. Set to 0.8 by default, indicating 80% training stars 20% validation stars
CommentsOnRun - This is Where You Can Leave Comments or Notes To Self on the Run! Could be very useful if you save the yaml file with each run
How to Contribute
Do one of the following: + Contact berman.ed@northeastern.edu + Fork this repository or submit a pull request
If you would like to report an issue or problem please raise an issue on this repository. If you would like to seek support, again see berman.ed@northeastern.edu .
Known Issues and Enhancements
- We are working on more configurability in the YAML for a smoother user experience, however, everything in this repository is functional and ready to work out of the box
- We are working on a chisq pixel grid fit mode. Right now the gain value g is hardcoded for chi square pixel grid fits
Contributors
- Edward Berman
- Jacqueline McCleary
With help from collaborators at COSMOS-Web: The JWST Cosmic Origins Survey
Further Acknowledgements
- The Northeastern Cosmology Group for Their Continued Support and Guidance
- The Northeastern Physics Department and Northeastern Undergraduate Research and Fellowships, for making this project possible with funding from the Northeastern Physics Research Co-Op Fellowship and PEAK Ascent Award respectively
- David Rosen, who gave valuable input in the early stages of this project and during his course Math 7223, Riemannian Optimization
- The COSMOS Web Collaboration for providing data from the James Webb Space Telescope and internal feedback
Cite
Citation for the Astronomical Journal (AJ) :
@article{berman2024efficientpsfmodelingshoptjl,
doi = {10.3847/1538-3881/ad6a0f},
url = {https://dx.doi.org/10.3847/1538-3881/ad6a0f},
year = {2024},
month = {sep},
publisher = {The American Astronomical Society},
volume = {168},
number = {4},
pages = {174},
author = {Edward M. Berman and Jacqueline E. McCleary and Anton M. Koekemoer and Maximilien Franco and Nicole E. Drakos and Daizhong Liu and James W. Nightingale and Marko Shuntov and Diana Scognamiglio and Richard Massey and Guillaume Mahler and Henry Joy McCracken and Brant E. Robertson and Andreas L. Faisst and Caitlin M. Casey and Jeyhan S. Kartaltepe and COSMOS-Web: The JWST Cosmic Origins Survey},
title = {Efficient Point-spread Function Modeling with ShOpt.jl: A Point-spread Function Benchmarking Study with JWST NIRCam Imaging},
journal = {The Astronomical Journal},
abstract = {With their high angular resolutions of 30–100 mas, large fields of view, and complex optical systems, imagers on next-generation optical/near-infrared space observatories, such as the Near-Infrared Camera (NIRCam) on the James Webb Space Telescope, present new opportunities for science and also new challenges for empirical point-spread function (PSF) characterization. In this context, we introduce ShOpt, a new PSF fitting tool developed in Julia and designed to bridge the advanced features of PSFs in the full field of view (PIFF) with the computational efficiency of PSF Extractor (PSFEx). Along with ShOpt, we propose a suite of nonparametric statistics suitable for evaluating PSF fit quality in space-based imaging. Our study benchmarks ShOpt against the established PSF fitters PSFEx and PIFF using real and simulated COSMOS-Web Survey imaging. We assess their respective PSF model fidelity with our proposed diagnostic statistics and investigate their computational efficiencies, focusing on their processing speed relative to the complexity and size of the PSF models. We find that ShOpt can already achieve PSF model fidelity comparable to PSFEx and PIFF while maintaining competitive processing speeds, constructing PSF models for large NIRCam mosaics within minutes.}
}
Citation for the Journal of Open Source Software (JOSS) paper:
@article{Berman2024, doi = {10.21105/joss.06144}, url = {https://doi.org/10.21105/joss.06144}, year = {2024}, publisher = {The Open Journal}, volume = {9}, number = {100}, pages = {6144}, author = {Edward Berman and Jacqueline McCleary}, title = {ShOpt.jl: A Julia Package for Empirical Point Spread Function Characterization of JWST NIRCam Data}, journal = {Journal of Open Source Software} }
Owner
- Name: Edward Berman
- Login: EdwardBerman
- Kind: user
- Location: Boston, MA
- Company: McCleary's Group / COSMOS Web
- Website: https://linktr.ee/bermanEdward
- Repositories: 28
- Profile: https://github.com/EdwardBerman
Astrophysicist @northeastern McCleary's Group, @ COSMOS-Web: The JWST Cosmic Origins Survey, @GammaTauAI
JOSS Publication
ShOpt.jl: A Julia Package for Empirical Point Spread Function Characterization of JWST NIRCam Data
Tags
JWST Deep Learning Point Spread FunctionCitation (CITATION.cff)
cff-version: 1.2.0
message: "If you use this software in your work, please cite it using these metadata."
title: "ShOpt.jl: A Julia Package for Empirical Point Spread Function Characterization of JWST NIRCam Data"
authors:
- family-names: Berman
given-names: Edward
- family-names: McCleary
given-names: Jacqueline
year: 2023
version: 1.0.0
doi: 10.5281/zenodo.1234567 # Replace with the actual DOI if available
repository-code: "https://github.com/EdwardBerman/shopt" # Replace with your repository URL
GitHub Events
Total
- Watch event: 2
- Push event: 3
Last Year
- Watch event: 2
- Push event: 3
Committers
Last synced: 7 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| EdwardBerman | 1****9@g****m | 565 |
| mcclearyj | j****w@g****m | 9 |
| Dan F-M | f****y@g****m | 1 |
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 11
- Total pull requests: 1
- Average time to close issues: 22 days
- Average time to close pull requests: 2 minutes
- Total issue authors: 5
- Total pull request authors: 1
- Average comments per issue: 2.0
- Average comments per pull request: 0.0
- Merged pull requests: 1
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 1
- Average time to close issues: N/A
- Average time to close pull requests: 2 minutes
- Issue authors: 0
- Pull request authors: 1
- Average comments per issue: 0
- Average comments per pull request: 0.0
- Merged pull requests: 1
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- EdwardBerman (3)
- aymgal (3)
- kevinmicha (2)
- jpierel14 (1)
- mcclearyj (1)
Pull Request Authors
- dfm (2)
