Skip to content

Commit

Permalink
Corrected files for Issue MPoL-dev#61
Browse files Browse the repository at this point in the history
Fixed issues causing improper building with the docs.
Collaborators: @trq5014, @hgrzy, @RCF42
  • Loading branch information
Tyler Quinn authored and Tyler Quinn committed Jun 11, 2021
1 parent f1a4a11 commit 65a2194
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 56 deletions.
3 changes: 2 additions & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ help:

NOTEBOOKS := tutorials/PyTorch.ipynb tutorials/gridder.ipynb tutorials/optimization.ipynb tutorials/crossvalidation.ipynb tutorials/initializedirtyimage.ipynb tutorials/HD143006_Tut_P1.ipynb
CHARTS := _static/mmd/build/SimpleNet.svg _static/mmd/build/ImageCube.svg _static/mmd/build/BaseCube.svg _static/mmd/build/SkyModel.svg

PLOTS := tutorials/robust_0.png tutorials/robust_1.0.png tutorials/robust_-1.0.png tutorials/uniform.png
clean:
rm -rf _build
rm -rf ${NOTEBOOKS}
rm -rf tutorials/.ipynb_checkpoints
rm -rf tutorials/runs
rm -rf ${CHARTS}
rm -rf _static/baselines/build/baselines.csv
rm -rf ${PLOTS}

tutorials/%.ipynb: tutorials/%.py ${CHARTS}
jupytext --to ipynb --execute $<
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ If you'd like to help build the MPoL package, please check out the :ref:`develop
tutorials/crossvalidation
tutorials/gpu_setup.rst
tutorials/initializedirtyimage
tutoriala/HD143006_Tut_P1
tutorials/HD143006_Tut_P1

.. toctree::
:hidden:
Expand Down
78 changes: 24 additions & 54 deletions docs/tutorials/HD143006_Tut_P1.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
#!/usr/bin/env python
# coding: utf-8

# # HD143006 Tutorial
# ## Part 1
# -*- coding: utf-8 -*-
# ---
# jupyter:
# jupytext:
# text_representation:
# extension: .py
# format_name: light
# format_version: '1.5'
# jupytext_version: 1.11.2
# kernelspec:
# display_name: Python 3
# language: python
# name: python3
# ---

# + nbsphinx="hidden"
# %matplotlib inline

# + nbsphinx="hidden"
# %run notebook_setup
# -
# # HD143006 Tutorial Part 1
# ### Introduction to Regularized Maximum Likelihood (RML) Imaging
#
#
Expand All @@ -14,10 +31,7 @@
#
# *You can either download these two files (HD143006_continuum.fits and HD143006_continuum.npz) directly to your working directory, or use astropy to download them during run time.*
#
#

# In[3]:

#

from astropy.io import fits
import matplotlib.pyplot as plt
Expand All @@ -38,79 +52,53 @@
pkgname='mpol',
)


# Now that we have the files, let us examine the fits image created by the DSHARP team using the CLEAN algorithm.

# In[4]:


# opening the fits file
dfits = fits.open(fname_F)

# printing out the header info
dfits.info()

# getting the data from the fits file and closing the fits file
clean_fits = dfits[0].data
dfits.close()

# plotting the clean fits
plt.imshow(np.squeeze(clean_fits), origin='lower')

#limit the x and y axes so that we only plot the disk
plt.xlim(left=1250, right=1750)
plt.ylim(top=1750, bottom=1250)


# This is the image produced by the CLEAN algorithm used by the DSHARP team. We will compare this with the image produced using RML through MPoL. While in this tutorial we will only be creating an MPoL Gridder object and plotting the dirty image, **Part 2** of the tutorial will cover the optimization loop of the model for image quality improvements.
#
# To create the dirty image, we will use the extracted visibilities from the npz file and the MPoL Gridder and Coordinates packages.
#

# In[5]:


# load extracted visibilities from npz file
dnpz = np.load(fname_EV)
uu = dnpz['uu']
vv = dnpz['vv']
weight = dnpz['weight']
data = dnpz['data']


# Let's quickly plot the U,V visibilities as seen in the [Cross Validation Tutorial](https://mpol-dev.github.io/MPoL/tutorials/crossvalidation.html) and the [Visread docs](https://mpol-dev.github.io/visread/tutorials/introduction_to_casatools.html#Get-the-baselines).

# In[6]:


fig, ax = plt.subplots(nrows=1)
ax.scatter(uu,vv, s=.5, rasterized=True, linewidths=0.0, c='k')
ax.scatter(-uu,-vv, s=.5, rasterized=True, linewidths=0.0, c='k')
ax.set_xlabel(r"$u$ [k$\lambda$]")
ax.set_ylabel(r"$v$ [k$\lambda$]")
ax.set_title(r'$U$, $V$ Visibilities')


# As you can see, there are very few visibilites > 7,000 ($k\lambda$), and a very dense region of visibilities between -2000 and 2000 ($k\lambda$). This indicates outliers at the higher frequencies while the bulk of our data stems from these lower frequencies.

# To create the MPoL Gridder object, we need a `cell_size` and the number of pixels in the width of our image, `npix`. You can read more about these properties in the [GridCoords] (https://mpol-dev.github.io/MPoL/api.html#mpol.coordinates.GridCoords) API Documentation. In the fits header we see our image is 3000x3000 pixels, so `npix=3000`. Getting our cell size in terms of arcseconds is a bit more tricky. Our fits image has a header called `CDELT1` which is the scaling in degrees. To get this into arcseconds we multiply by 3600. We save this as `cdelt_scaling`. `cdelt_scaling` can be negative, and cell_size must be positive so we will take the absolute value of this.

# In[7]:


# opening the fits file
dfits = fits.open(fname_F)

cdelt_scaling = dfits[0].header['CDELT1'] * 3600 # scaling [arcsec]
cell_size = abs(cdelt_scaling) # [arcsec]

#close fits file
dfits.close()


# In[8]:


from mpol import gridding, coordinates

# creating Gridder object
Expand All @@ -124,25 +112,17 @@
data_im=data.imag
)


# We now have everything we need to get the MPoL dirty image. Here we are using [Gridder.get_dirty_image()](../api.rst#mpol.gridding.Gridder.get_dirty_image) to average the visibilities to the grid defined by gridder and from there we get our dirty image and dirty beam. There are different ways to average the visibilities, called weighting, and here we use Uniform and Briggs weighting to find and produce a dirty image that resembles the CLEAN image. More info on the weighting can be read in the [CASA documentation](https://casa.nrao.edu/casadocs-devel/stable/imaging/synthesis-imaging/data-weighting). For the Briggs weighting, we will use three different values for the `robust` variable. This dictates how aggresive our weight scaling is towards image resolution or image sensitivity.
#
# *Note: when `robust=-2.0` the result is similar to that of the Uniform scale*

# In[ ]:


img, beam = gridder.get_dirty_image(weighting='uniform')
img1, beam1 = gridder.get_dirty_image(weighting="briggs", robust=1.0, unit="Jy/arcsec^2")
img2, beam2 = gridder.get_dirty_image(weighting="briggs", robust=0.0, unit="Jy/arcsec^2")
img3, beam3 = gridder.get_dirty_image(weighting="briggs", robust=-1.0, unit="Jy/arcsec^2")


# Great! Now let's make a plotting function to show us the MPoL image. If you have read through other MPoL tutorials, then this code should look familiar. We are going to plot all four of the different weightings, so creating a plotting function simplifies our code a lot.

# In[ ]:


def plot(img, savename="image.png", imtitle="image"):
kw = {"origin": "lower", "extent": gridder.coords.img_ext}
fig, ax = plt.subplots(ncols=1)
Expand All @@ -156,20 +136,12 @@ def plot(img, savename="image.png", imtitle="image"):
plt.ylim(bottom=-.75, top=.75)
return ax


# In[ ]:


plot(img, savename="uniform.png", imtitle="uniform")
plot(img1, savename="robust_1.0.png", imtitle="robust_1.0")
plot(img2, savename="robust_0.png", imtitle="robust_0")
plot(img3, savename="robust_-1.0.png", imtitle="robust_-1.0")


# Below we plot the DSHARP CLEAN image alongside the MPoL RML Dirty Image weighted with the Briggs scale and `robust=0.0` for comparison.

# In[ ]:

# Below we plot the DSHARP CLEAN image alongside the MPoL RML Dirty Image weighted with the Briggs scale and `robust=0.0` for comparison.

kw = {"origin": "lower", "extent": gridder.coords.img_ext}
fig, ax = plt.subplots(ncols = 2)
Expand All @@ -179,14 +151,12 @@ def plot(img, savename="image.png", imtitle="image"):
ax[0].set_ylim(bottom=-.75, top=.75)
ax[0].set_xlabel(r"$\Delta \alpha \cos \delta$ [${}^{\prime\prime}$]")
ax[0].set_ylabel(r"$\Delta \delta$ [${}^{\prime\prime}$]")

ax[1].imshow(np.squeeze(img2), **kw)
ax[1].set_title('MPoL RML Dirty Image')
ax[1].set_xlim(left=-.75, right=.75)
ax[1].set_ylim(bottom=-.75, top=.75)
ax[1].set_xlabel(r"$\Delta \alpha \cos \delta$ [${}^{\prime\prime}$]")
ax[1].set_ylabel(r"$\Delta \delta$ [${}^{\prime\prime}$]")

plt.tight_layout()


Expand Down

0 comments on commit 65a2194

Please sign in to comment.