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

tickets/DM-28474: Update to latest master #21

Merged
merged 63 commits into from
Feb 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
88bad3a
added deconvolution coadd method
pmelchior Oct 20, 2020
eedafae
removed experimental diff_kernels option from Observation.match; mino…
pmelchior Oct 26, 2020
5088f69
deconv image compute in Observation.match
pmelchior Oct 26, 2020
640ea03
implemented build_detection_image for multi Obs init
pmelchior Oct 29, 2020
ba3bc09
modularizing the init methods (#216)
pmelchior Oct 30, 2020
1ae5dc9
deconv init for MultiComponentSource; half of #207
pmelchior Oct 31, 2020
f173d42
prerender image for LowResObservation
pmelchior Nov 2, 2020
e5117aa
Merge branch 'master' into deconv-init
pmelchior Nov 5, 2020
2a65c9e
created CompactExtendedSource; overhaul to initSource
pmelchior Nov 5, 2020
ee145a4
added SNR for source class decisions
pmelchior Nov 5, 2020
4be3f4f
moved SNR to measure, made it model-based
pmelchior Nov 6, 2020
a701c42
added option to initialize from observed image (as default)
pmelchior Nov 12, 2020
f8918af
init spectrum of ExtendedSource from deconv coadd
pmelchior Nov 19, 2020
a43d83b
added moment measurement
pmelchior Nov 19, 2020
fd3b613
reduced morph step size for more stability
pmelchior Nov 19, 2020
29b5971
defined prerender image in case of no PSF
pmelchior Nov 19, 2020
68c44c3
measure accepts model; moments work in 3D
pmelchior Nov 19, 2020
063a951
snr also works with convolved obs
pmelchior Nov 19, 2020
626fd36
forced origin=0 for Frame.bbox (#219)
pmelchior Nov 19, 2020
cac28c1
create shifted WCS for model_frame (#219)
pmelchior Nov 19, 2020
292996a
replaced resampling module with Frame methods (closes #219)
pmelchior Nov 20, 2020
a45219c
no camelCase; min boxsize 21 pixels; various consistency changes
pmelchior Dec 4, 2020
494c982
added noise injection; removed frame_offset: now treated in model fra…
pmelchior Dec 4, 2020
94bd744
box resizing (first part of #177)
pmelchior Dec 4, 2020
237db03
follow changes throughout codebase
pmelchior Dec 4, 2020
df8907a
switched to NAdam as default optimization scheme
pmelchior Dec 4, 2020
8a800f7
notebook updates
pmelchior Dec 4, 2020
1f4fa97
temporarily silenced one test
pmelchior Dec 7, 2020
e6a898b
fixed zero-weight noise image; run linear spectrum solver for regress…
pmelchior Dec 7, 2020
85285a0
prerender switch for inits; code for 0 weights
pmelchior Dec 9, 2020
dd20ea7
only catch expected exception in `init_source`
pmelchior Dec 17, 2020
279242e
only top-level headings in tutorial TOC
pmelchior Dec 17, 2020
b42255b
best defaults: convolved, amsgrad, set_spectrum
pmelchior Dec 17, 2020
1f66557
made prerender data by-request
pmelchior Dec 18, 2020
e393f63
minimum spectrum step size to resurrect source with spectrum=0
pmelchior Dec 18, 2020
1aedc4b
box shrinking (closes #177)
pmelchior Dec 18, 2020
2eadde9
set_spectra option in init_all_sources
pmelchior Dec 18, 2020
ef646d8
added NullSource to avoid exceptions/errors in regression tests
pmelchior Dec 18, 2020
5ac6ac5
prerender image only set for default Observation
pmelchior Dec 18, 2020
cd77502
fixed minimum spectrum step for multiple observation
pmelchior Dec 18, 2020
85317b6
morphology inits -> source; StarletSource can transform any source
pmelchior Dec 18, 2020
3e4d1da
switched to PSF SNR to speed up initialization
pmelchior Dec 19, 2020
4910857
merged master; fixes to docs
pmelchior Dec 19, 2020
da68fb9
cleaned up namespace
pmelchior Dec 19, 2020
3e4a3a9
added Starlet to default import
pmelchior Dec 20, 2020
76e3128
changed from code review
pmelchior Jan 8, 2021
77cb81c
more fixes from code review: LRO test re-enabled
pmelchior Jan 13, 2021
58de4af
fixed excessive model frame sizes
pmelchior Jan 13, 2021
7d22e23
error propagation formula for prerender sigma
pmelchior Jan 13, 2021
8f462eb
Merge pull request #227 from pmelchior/deconv-init
pmelchior Jan 14, 2021
ac91e24
Observation is a Frame (#220)
pmelchior Dec 23, 2020
8073972
removed prerender; introduced Renderer
pmelchior Dec 24, 2020
1a9d339
added ResolutionRenderer; minor fix in log_norm (closes #220)
pmelchior Dec 24, 2020
c0ed38b
last comments from code review; fixed #229
pmelchior Jan 19, 2021
262a13a
Merge pull request #228 from pmelchior/renderer
pmelchior Jan 20, 2021
2d6364a
Store whether or not the source was an edge source
Jan 25, 2021
24cc44a
Fix bug in real convolutions:
Jan 25, 2021
a386704
Refactor Component.model_to_frame to accept bbox
Jan 26, 2021
f117faf
Remove edge detection and update model_to_box
Jan 28, 2021
db70837
Remove reference to edge_distance
Jan 28, 2021
585452c
Remove edge_distance from testing
Jan 28, 2021
8bf1ebb
Merge pull request #230 from pmelchior/bug-fixes
fred3m Jan 28, 2021
d9adfa2
Merge remote-tracking branch 'upstream/master' into tickets/DM-28474
Jan 28, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
111 changes: 82 additions & 29 deletions docs/0-quickstart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,20 @@
"data = np.load(\"../data/hsc_cosmos_35.npz\")\n",
"images = data[\"images\"]\n",
"filters = data[\"filters\"]\n",
"catalog = data[\"catalog\"]\n",
"centers = [(src['y'], src['x']) for src in data[\"catalog\"]] # Note: y/x convention!\n",
"weights = 1/data[\"variance\"]\n",
"psfs = scarlet.ImagePSF(data[\"psfs\"])"
"psf = scarlet.ImagePSF(data[\"psfs\"])"
]
},
{
"cell_type": "raw",
"metadata": {
"raw_mimetype": "text/restructuredtext"
},
"source": [
".. warning::\n",
"\n",
" Coordinates in *scarlet* are given in the C/numpy notation (y,x) as opposed to the more conventional mathematical (x,y) ordering."
]
},
{
Expand Down Expand Up @@ -97,7 +108,7 @@
"source": [
".. note::\n",
"\n",
" It is crictical to realize that there are two frames: one for model that reconstructs the scene on the sky, and one for any observation of the scene. They may be identical, but mostly they are not, in which case the observation is an information-reduced rendering of the model. The loss of information could be in terms of signal-to-noise ratio, spatial resolution, PSF blurring, spectral coverage, or all of the above."
" It is critical to realize that there are two frames: one for model that represents the scene on the sky, and one for any observation of that scene. The frames may be identical, but usually they are not, in which case the observation is compared to a degraded rendering of the model. The degradation could be in terms of spatial resolution, PSF blurring, spectral coverage, or all of the above. If the model frame and the observation frame are the same, no attempt can be made to recover information lost by the degradation."
]
},
{
Expand Down Expand Up @@ -131,12 +142,12 @@
"source": [
"model_frame = scarlet.Frame(\n",
" images.shape,\n",
" psfs=model_psf,\n",
" psf=model_psf,\n",
" channels=filters)\n",
"\n",
"observation = scarlet.Observation(\n",
" images, \n",
" psfs=psfs, \n",
" psf=psf,\n",
" weights=weights, \n",
" channels=filters).match(model_frame)"
]
Expand Down Expand Up @@ -168,8 +179,7 @@
"metadata": {},
"outputs": [],
"source": [
"sky_coords = [[src['y'], src['x']] for src in catalog] # y/x!\n",
"scarlet.display.show_observation(observation, norm=norm, sky_coords=sky_coords, show_psf=True)\n",
"scarlet.display.show_observation(observation, norm=norm, sky_coords=centers, show_psf=True)\n",
"plt.show()"
]
},
Expand All @@ -180,17 +190,6 @@
"Since we use a trivial `wcs` in this `Observation`, all coordinates are already in image pixels, otherwise RA/Dec pairs are expected as sky coordinates. Also:"
]
},
{
"cell_type": "raw",
"metadata": {
"raw_mimetype": "text/restructuredtext"
},
"source": [
".. warning::\n",
"\n",
" Coordinates in *scarlet* are given in the C/numpy notation (y,x) as opposed to the more conventional mathematical (x,y) ordering."
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -201,10 +200,40 @@
"\n",
"* `RandomSource` fits per-band amplitude and non-parametric morphology starting from uniform random draws for both.\n",
"* `PointSource` fits centers and per-band amplitude using the observed PSF model.\n",
"* `ExtendedSource` fits per-band amplitude and a non-parametric morphology (which is constrained to be monotonically decreasing from the center).\n",
"* `ExtendedSource` fits per-band amplitude and a non-parametric morphology (which is constrained to be monotonically decreasing from the center). It has a `compact` option, which initializes the source with the shape of a point source.\n",
"* `ExtendedSource(K=2)` splits an `ExtendedSource` into `K` components that are initially radially separated and stacked on top of each other like a pyramid.\n",
"\n",
"In our example, we assume *prior* knowledge that object 0 is a star, and object 1 should be modeled with two components. Everything else is assumed a single-component galaxy. **We generally recommend `ExtendedSource` as default** if additional information about the source is not available."
"We can use a robust initialization scheme, that starts by attempting to model every source with 2 components. If these components don't have enough signal-to-noise, it will fall back to 1 component. If that fails, it will work with a `compact` component. If cannot do even that, it will report the source number in `skipped`:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sources, skipped = scarlet.initialization.init_all_sources(model_frame, \n",
" centers, \n",
" observation, \n",
" max_components=2, \n",
" min_snr=50,\n",
" thresh=1,\n",
" fallback=True,\n",
" silent=True,\n",
" set_spectra=True\n",
" )\n",
"\n",
"for k, src in enumerate(sources):\n",
" print (f\"{k}: {src.__class__.__name__}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can see that this method chooses multiple (here 2) extended components for the first three sources, a single extended component for sources 3 and 5, and compact ones for the rest.\n",
"\n",
"If we know something about the scene, we might want to customize the modeling. Let's assume that we know that object 0 is a star. We could just replace that source with a `PointSource`, but for clarity we rebuild the entire source list, making one change for source 0 and accepting everything else from the default initialization above:"
]
},
{
Expand All @@ -214,22 +243,45 @@
"outputs": [],
"source": [
"sources = []\n",
"for k,src in enumerate(catalog):\n",
"for k,center in enumerate(centers):\n",
" if k == 0:\n",
" new_source = scarlet.PointSource(model_frame, (src['y'], src['x']), observation)\n",
" elif k == 1:\n",
" new_source = scarlet.ExtendedSource(model_frame, (src['y'], src['x']), observation, K=2)\n",
" new_source = scarlet.PointSource(model_frame, center, observation)\n",
" elif k in [1, 2]:\n",
" new_source = scarlet.ExtendedSource(model_frame, center, observation, K=2)\n",
" elif k in [3, 5]:\n",
" new_source = scarlet.ExtendedSource(model_frame, center, observation, K=1)\n",
" else:\n",
" new_source = scarlet.ExtendedSource(model_frame, (src['y'], src['x']), observation, compact=True)\n",
" sources.append(new_source)"
" new_source = scarlet.ExtendedSource(model_frame, center, observation, compact=True)\n",
" sources.append(new_source)\n",
" \n",
"for k, src in enumerate(sources):\n",
" print (f\"{k}: {src.__class__.__name__}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"These source are initialized independently, and their spectra, i.e. the amplitudes in every channel, assume that they are isolated.\n",
"We can make another sweep and determine their spectra so that their superposition best matches the observation. Above, this was done for use by the option `set_specta=True`. But we can call the linear solver directly:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"scarlet.initialization.set_spectra_to_match(sources, observation)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create and Fit Model\n",
"The `Blend` class represents the sources as a tree and has the machinery to fit all of the sources to the given images. In this example the code is set to run for a maximum of 200 iterations, but will end early if the likelihood and all of the constraints converge."
"\n",
"The `Blend` class holds the list of sources and has the machinery to fit them to the given images. In this example the code is set to run for a maximum of 100 iterations, but will end early if the likelihood and all of the constraints converge."
]
},
{
Expand Down Expand Up @@ -304,6 +356,7 @@
"source": [
"### View Source Models\n",
"\n",
"\n",
"We will now inspect the model for each source, in its original frame and in its observed frame by leveraging the `show_sources` method:"
]
},
Expand Down Expand Up @@ -425,10 +478,10 @@
"# add two sources at their approximate locations\n",
"model_frame_ = sources_[0].frame\n",
"yx = (14., 44.)\n",
"new_source = scarlet.ExtendedSource(model_frame_, yx, observation, shifting=True)\n",
"new_source = scarlet.ExtendedSource(model_frame_, yx, observation, compact=True, shifting=True)\n",
"sources_.append(new_source)\n",
"yx = (42., 9.)\n",
"new_source = scarlet.ExtendedSource(model_frame_, yx, observation, shifting=True)\n",
"new_source = scarlet.ExtendedSource(model_frame_, yx, observation, compact=True, shifting=True)\n",
"sources_.append(new_source)\n",
"\n",
"# generate a new Blend instance\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/1-concepts.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Source 0 is a `PointSource`, parameterized by a spectrum and a center, as we have seen above. Source 1 has multiple components (each with a spectrum and an image morphology), the rest have a single spectrum and image morphology.\n",
"Source 0 is a `PointSource`, parameterized by a spectrum and a center, as we have seen above. Source 1 has multiple components (each with a spectrum and an image morphology), others have a single spectrum and image morphology.\n",
"\n",
"`Parameter` is a souped up `numpy` array. It has a value and a name, as well as additonal attributes that store a `prior` and `constraint` that were enforced during optimization; the typical `step` size during optimization; an estimate of the standard deviate `std`; and whether the parameter was held `fixed`:"
]
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorials/display.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
"catalog = data[\"catalog\"]\n",
"filters = data[\"filters\"]\n",
"weights = 1/data[\"variance\"]\n",
"psfs = scarlet.ImagePSF(data[\"psfs\"])\n",
"psf = scarlet.ImagePSF(data[\"psfs\"])\n",
"\n",
"observation = scarlet.Observation(\n",
" images, \n",
" psfs=psfs, \n",
" psf=psf, \n",
" weights=weights, \n",
" channels=filters)\n",
"\n",
Expand Down