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

Documenting Briggs residual visualization and removing GriddedResidualConnector #158

Merged
merged 5 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -12,11 +12,11 @@ repos:
- id: detect-private-key
- id: name-tests-test
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 23.1.0
hooks:
- id: black
- repo: https://github.com/PyCQA/isort
rev: 5.8.0
rev: 5.12.0
hooks:
- id: isort
args: []
Expand Down
10 changes: 0 additions & 10 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,6 @@ Training and testing
.. automodule:: mpol.training


Connectors
----------

The objects in the Images and Precomposed modules are focused on bringing some image-plane model to the space of the data, where the similarity of the model visibilities to the data visibilities will be evaluated by a negative log-likelihood loss. In some situations, though, it is useful to have access to the residual visibilities directly. For example, for visualization or debugging purposes.

Connectors are a PyTorch layer to help compute those residual visibilities (on a gridded form).

.. automodule:: mpol.connectors


Cross-validation
----------------

Expand Down
5 changes: 5 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

# Changelog

## v0.1.4

- Removed the `GriddedResidualConnector` class and the `src/connectors.py` module. Moved `index_vis` to `datasets.py`.
- Changed BaseCube, ImageCube, and FourierCube initialization signatures

## v0.1.3

- Added the {func}`mpol.fourier.make_fake_data` routine and the [Mock Data tutorial](ci-tutorials/fakedata.md).
Expand Down
31 changes: 9 additions & 22 deletions docs/ci-tutorials/crossvalidation.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ from astropy.utils.data import download_file
from torch.utils.tensorboard import SummaryWriter

from mpol import (
connectors,
coordinates,
crossval,
datasets,
Expand Down Expand Up @@ -181,46 +180,34 @@ flayer = fourier.FourierCube(coords=coords)
flayer.forward(torch.zeros(dset.nchan, coords.npix, coords.npix))
```

The following plots visualize how we've split up the data. For each $K$-fold, we have the "training" visibilities, the dirty image corresponding to those training visibilities, and the "test" visibilities which will be used to evaluate the predictive ability of the model.
The following plots visualize how we've split up the data. For each $K$-fold, we have the "training" visibilities and the "test" visibilities which will be used to evaluate the predictive ability of the model.

```{code-cell}
fig, ax = plt.subplots(nrows=k, ncols=3, figsize=(6, 10))
fig, ax = plt.subplots(nrows=k, ncols=2, figsize=(4, 10))

for i, (train_subset, test_subset) in enumerate(k_fold_datasets):

rtrain = connectors.GriddedResidualConnector(flayer, train_subset)
rtrain.forward()
rtest = connectors.GriddedResidualConnector(flayer, test_subset)
rtest.forward()
# train_subset and test_subset are `GriddedDataset`s

vis_ext = rtrain.coords.vis_ext
img_ext = rtrain.coords.img_ext

train_mask = rtrain.ground_mask[0]
train_chan = rtrain.sky_cube[0]

test_mask = rtest.ground_mask[0]
test_chan = rtest.sky_cube[0]
train_mask = train_subset.ground_mask[0]
test_mask = test_subset.ground_mask[0]

ax[i, 0].imshow(
train_mask.detach().numpy(),
interpolation="none",
origin="lower",
extent=vis_ext,
extent=coords.vis_ext,
cmap="GnBu",
)

ax[i, 1].imshow(train_chan.detach().numpy(), origin="lower", extent=img_ext)

ax[i, 2].imshow(
test_mask.detach().numpy(), origin="lower", extent=vis_ext, cmap="GnBu"
ax[i, 1].imshow(
test_mask.detach().numpy(), origin="lower", extent=coords.vis_ext, cmap="GnBu"
)

ax[i, 0].set_ylabel("k-fold {:}".format(i))

ax[0, 0].set_title("train mask")
ax[0, 1].set_title("train dirty img.")
ax[0, 2].set_title("test mask")
ax[0, 1].set_title("test mask")

for a in ax.flatten():
a.xaxis.set_ticklabels([])
Expand Down
Loading