-
Notifications
You must be signed in to change notification settings - Fork 15
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
"Simple" example using romanisim-make-image for docs #57
Open
bmorris3
wants to merge
2
commits into
spacetelescope:main
Choose a base branch
from
bmorris3:make-img-docs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,3 +80,87 @@ modeling. | |
location of the center of the WFI array or the | ||
telescope boresight, when the ``--boresight`` argument | ||
is specified. | ||
|
||
|
||
Example | ||
======= | ||
|
||
Let's put the pieces together. Below, we create a synthetic catalog of bright | ||
stars centered on the center of M13, observed with SCA 1 in the F087 filter. | ||
Though we create 10,000 stars, only 86 will ultimately fall on SCA 1. | ||
In this Python example, we synthesize images of those stars with ``romanisim`` via | ||
the `~romanisim.image.simulate` function, and plot the results | ||
with ``matplotlib``. | ||
|
||
.. code-block:: python | ||
|
||
from copy import deepcopy | ||
|
||
import asdf | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
from astropy.coordinates import SkyCoord | ||
from astropy.visualization import simple_norm | ||
from galsim import UniformDeviate | ||
|
||
from romanisim import persistence, wcs | ||
from romanisim.catalog import make_stars | ||
from romanisim.image import simulate | ||
from romanisim.parameters import default_parameters_dictionary | ||
|
||
# use the coordinate of M13 as the center of the detector: | ||
coord = SkyCoord.from_name("M13") | ||
|
||
# choose an SCA to simulate: | ||
sca = 1 | ||
filt = 'F087' | ||
seed = 0 | ||
|
||
# save the star catalog here: | ||
catalog_path = 'small-synthetic-catalog.ecsv' | ||
|
||
# write out the result to ASDF: | ||
output_path = 'small-synthetic-image.asdf' | ||
|
||
# generate a stellar catalog: | ||
cat = make_stars( | ||
coord=coord, | ||
n=10_000, | ||
radius=0.7, | ||
bandpasses=[filt], | ||
faintmag=18, | ||
rng=UniformDeviate(seed=seed) | ||
) | ||
cat.write(catalog_path, overwrite=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is vestigial? |
||
|
||
# prepare inputs for the `romanisim.image.simulate` method: | ||
metadata = deepcopy(default_parameters_dictionary) | ||
metadata['instrument']['detector'] = f'WFI{sca:02d}' | ||
metadata['instrument']['optical_element'] = filt | ||
metadata['exposure']['ma_table_number'] = 1 | ||
wcs.fill_in_parameters( | ||
metadata, coord, boresight=False | ||
) | ||
|
||
# run the simulation: | ||
im, simcatobj = simulate( | ||
metadata, cat, webbpsf=True, level=2, | ||
persistence=persistence.Persistence(), | ||
rng=UniformDeviate(seed), usecrds=False | ||
) | ||
|
||
asdf_file = asdf.AsdfFile() | ||
romanisimdict = {'simcatobj': simcatobj} | ||
asdf_file.tree = {'roman': im, 'romanisim': romanisimdict} | ||
Comment on lines
+152
to
+154
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you could drop this, and show im['data'] below instead of asdf_file.tree['roman']['data']. |
||
|
||
# plot a portion of the resulting rate image: | ||
fig, ax = plt.subplots() | ||
image = np.array(asdf_file.tree['roman']['data']) | ||
norm = simple_norm(image, 'asinh', asinh_a=1e-4) | ||
ax.imshow(image, norm=norm) | ||
|
||
ax.set( | ||
xlim=[2900, 3150], | ||
ylim=[3300, 3550] | ||
) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is vestigial?