From 6b04b5e5309a7233f1e0e8279aa93f096d333955 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 8 Apr 2024 16:28:05 +0000 Subject: [PATCH 1/2] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pre-commit/pre-commit-hooks: v4.4.0 → v4.6.0](https://github.com/pre-commit/pre-commit-hooks/compare/v4.4.0...v4.6.0) - [github.com/kynan/nbstripout: 0.6.1 → 0.7.1](https://github.com/kynan/nbstripout/compare/0.6.1...0.7.1) --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5595e828..48c6d932 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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: v4.4.0 + rev: v4.6.0 hooks: - id: trailing-whitespace exclude: '.*\.fits$' @@ -12,7 +12,7 @@ repos: - id: check-yaml - id: check-added-large-files - repo: https://github.com/kynan/nbstripout - rev: 0.6.1 + rev: 0.7.1 hooks: - id: nbstripout args: ["--extra-keys=metadata.kernelspec metadata.language_info.version metadata.toc metadata.language_info.codemirror_mode.version metadata.language_info.pygments_lexer metadata.notify_time metadata.varInspector metadata.colab cell.metadata.colab cell.metadata.colab_type cell.metadata.outputId cell.metadata.id"] From d30f820a072b7a516484a7a84baba125d0aaeb76 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 8 Apr 2024 16:31:46 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../PVDiagramPlotting.ipynb | 86 ++++++------- .../SpectralCubeReprojectExample.ipynb | 114 +++++++++--------- 2 files changed, 100 insertions(+), 100 deletions(-) diff --git a/tutorials/position-velocity-diagrams/PVDiagramPlotting.ipynb b/tutorials/position-velocity-diagrams/PVDiagramPlotting.ipynb index 93b552b6..4b6c3497 100644 --- a/tutorials/position-velocity-diagrams/PVDiagramPlotting.ipynb +++ b/tutorials/position-velocity-diagrams/PVDiagramPlotting.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "ec28e7e2", + "id": "0", "metadata": {}, "source": [ "# Extracting and Plotting Position-Velocity Diagrams\n", @@ -26,7 +26,7 @@ }, { "cell_type": "markdown", - "id": "5b7f1268", + "id": "1", "metadata": {}, "source": [ "### Header material\n", @@ -37,7 +37,7 @@ { "cell_type": "code", "execution_count": null, - "id": "9f9d06e1", + "id": "2", "metadata": {}, "outputs": [], "source": [ @@ -57,7 +57,7 @@ }, { "cell_type": "markdown", - "id": "d44ca9f9", + "id": "3", "metadata": {}, "source": [ "Retrieve and open a cube from astropy-data:" @@ -66,7 +66,7 @@ { "cell_type": "code", "execution_count": null, - "id": "f51a1376", + "id": "4", "metadata": {}, "outputs": [], "source": [ @@ -76,7 +76,7 @@ }, { "cell_type": "markdown", - "id": "b205d98a", + "id": "5", "metadata": {}, "source": [ "We show a single channel from the cube to visualize the data spatially.\n", @@ -86,7 +86,7 @@ { "cell_type": "code", "execution_count": null, - "id": "7b2db3eb", + "id": "6", "metadata": {}, "outputs": [], "source": [ @@ -95,7 +95,7 @@ }, { "cell_type": "markdown", - "id": "9e946c8c", + "id": "7", "metadata": {}, "source": [ "# PV Extraction from Pixel Coordinates\n", @@ -110,7 +110,7 @@ { "cell_type": "code", "execution_count": null, - "id": "7cc19bc3", + "id": "8", "metadata": {}, "outputs": [], "source": [ @@ -119,7 +119,7 @@ }, { "cell_type": "markdown", - "id": "5e83296d", + "id": "9", "metadata": {}, "source": [ "Then we can overplot it on our figure, now with WCS shown. The plotting uses [WCSAxes](https://docs.astropy.org/en/stable/visualization/wcsaxes/index.html)" @@ -128,7 +128,7 @@ { "cell_type": "code", "execution_count": null, - "id": "1b5e2815", + "id": "10", "metadata": {}, "outputs": [], "source": [ @@ -141,7 +141,7 @@ }, { "cell_type": "markdown", - "id": "b0d00e33", + "id": "11", "metadata": {}, "source": [ "`spacing` gives the separation between these points in pixels; we finely sampled by picking one-pixel spacing." @@ -149,7 +149,7 @@ }, { "cell_type": "markdown", - "id": "cea5c40f", + "id": "12", "metadata": {}, "source": [ "We can then extract the pv diagram, specifying the same spacing." @@ -158,7 +158,7 @@ { "cell_type": "code", "execution_count": null, - "id": "99297938", + "id": "13", "metadata": {}, "outputs": [], "source": [ @@ -168,7 +168,7 @@ }, { "cell_type": "markdown", - "id": "65b62bb8", + "id": "14", "metadata": {}, "source": [ "and plot it. `pvdiagram` is a `PrimaryHDU` object, so we need to grab the data separately from the header and convert the header to a WCS object:" @@ -177,7 +177,7 @@ { "cell_type": "code", "execution_count": null, - "id": "9c602ebf", + "id": "15", "metadata": {}, "outputs": [], "source": [ @@ -192,7 +192,7 @@ }, { "cell_type": "markdown", - "id": "e4179ebc", + "id": "16", "metadata": {}, "source": [ "Changing units to the more commonly used km/s and more readable arcminutes can be done with [wcsaxes tools](https://docs.astropy.org/en/stable/visualization/wcsaxes/controlling_axes.html):" @@ -201,7 +201,7 @@ { "cell_type": "code", "execution_count": null, - "id": "9bebb46f", + "id": "17", "metadata": {}, "outputs": [], "source": [ @@ -223,7 +223,7 @@ }, { "cell_type": "markdown", - "id": "ec773f53", + "id": "18", "metadata": {}, "source": [ "We can put all this together:" @@ -232,7 +232,7 @@ { "cell_type": "code", "execution_count": null, - "id": "ea8c2fd2", + "id": "19", "metadata": {}, "outputs": [], "source": [ @@ -245,7 +245,7 @@ { "cell_type": "code", "execution_count": null, - "id": "4a3ba59a", + "id": "20", "metadata": {}, "outputs": [], "source": [ @@ -272,7 +272,7 @@ }, { "cell_type": "markdown", - "id": "f04373b1", + "id": "21", "metadata": {}, "source": [ "# PV Extraction from Sky Coordinates" @@ -280,7 +280,7 @@ }, { "cell_type": "markdown", - "id": "f7643042", + "id": "22", "metadata": {}, "source": [ "We can also make paths by supplying coordinates defined in an `astropy.coordinates.SkyCoord` to `pvextractor.Path`." @@ -289,7 +289,7 @@ { "cell_type": "code", "execution_count": null, - "id": "4f0f1d40", + "id": "23", "metadata": {}, "outputs": [], "source": [ @@ -299,7 +299,7 @@ { "cell_type": "code", "execution_count": null, - "id": "b3299ae2", + "id": "24", "metadata": {}, "outputs": [], "source": [ @@ -308,7 +308,7 @@ }, { "cell_type": "markdown", - "id": "27c2224d", + "id": "25", "metadata": {}, "source": [ "We can plot again; the coordinates will be automatically determined" @@ -317,7 +317,7 @@ { "cell_type": "code", "execution_count": null, - "id": "2d3f42c3", + "id": "26", "metadata": {}, "outputs": [], "source": [ @@ -331,7 +331,7 @@ { "cell_type": "code", "execution_count": null, - "id": "65c46371", + "id": "27", "metadata": {}, "outputs": [], "source": [ @@ -342,7 +342,7 @@ { "cell_type": "code", "execution_count": null, - "id": "cbfa2a87", + "id": "28", "metadata": {}, "outputs": [], "source": [ @@ -369,7 +369,7 @@ }, { "cell_type": "markdown", - "id": "2bca4a13", + "id": "29", "metadata": {}, "source": [ "We can also change the aspect ratio of the PV diagram. The `figsize` parameter controls the figure size, which has some effect, and the `ax.set_aspect` command controls the aspect ratio of the individually displayed pixels" @@ -378,7 +378,7 @@ { "cell_type": "code", "execution_count": null, - "id": "fcf34393", + "id": "30", "metadata": {}, "outputs": [], "source": [ @@ -407,7 +407,7 @@ }, { "cell_type": "markdown", - "id": "e8deae20", + "id": "31", "metadata": {}, "source": [ "## PV Extraction with Spatial Averaging" @@ -415,7 +415,7 @@ }, { "cell_type": "markdown", - "id": "0824ae9d", + "id": "32", "metadata": {}, "source": [ "`pvextractor.Path` allows you to specify a `width` to average over, which specifies a spatial range around the path to average over.\n", @@ -426,7 +426,7 @@ { "cell_type": "code", "execution_count": null, - "id": "91f5420f", + "id": "33", "metadata": {}, "outputs": [], "source": [ @@ -436,7 +436,7 @@ { "cell_type": "code", "execution_count": null, - "id": "bb057443", + "id": "34", "metadata": {}, "outputs": [], "source": [ @@ -445,7 +445,7 @@ }, { "cell_type": "markdown", - "id": "1cf3ccc5", + "id": "35", "metadata": {}, "source": [ "We can plot this path as a set of patches to show where we averaged. The default spacing is 1 pixel,so we plot 1-pixel chunks." @@ -454,7 +454,7 @@ { "cell_type": "code", "execution_count": null, - "id": "9a866a1f", + "id": "36", "metadata": {}, "outputs": [], "source": [ @@ -489,7 +489,7 @@ }, { "cell_type": "markdown", - "id": "d70082ef", + "id": "37", "metadata": {}, "source": [ "We can also have more widely spaced chunks.\n", @@ -500,7 +500,7 @@ { "cell_type": "code", "execution_count": null, - "id": "98faa709", + "id": "38", "metadata": {}, "outputs": [], "source": [ @@ -534,7 +534,7 @@ }, { "cell_type": "markdown", - "id": "c8203c9d", + "id": "39", "metadata": {}, "source": [ "## Saving\n", @@ -545,7 +545,7 @@ { "cell_type": "code", "execution_count": null, - "id": "d59d2ff3", + "id": "40", "metadata": {}, "outputs": [], "source": [ @@ -554,7 +554,7 @@ }, { "cell_type": "markdown", - "id": "560c2f93-ee95-4d60-825a-83ec9f3acba7", + "id": "41", "metadata": {}, "source": [ "We can also save the figure as a png or pdf:" @@ -563,7 +563,7 @@ { "cell_type": "code", "execution_count": null, - "id": "74de9f99-e2fd-411f-9249-a39fa0b35908", + "id": "42", "metadata": {}, "outputs": [], "source": [ diff --git a/tutorials/spectral-cube-reprojection/SpectralCubeReprojectExample.ipynb b/tutorials/spectral-cube-reprojection/SpectralCubeReprojectExample.ipynb index bc7614ce..68685e15 100644 --- a/tutorials/spectral-cube-reprojection/SpectralCubeReprojectExample.ipynb +++ b/tutorials/spectral-cube-reprojection/SpectralCubeReprojectExample.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "b6372d7e", + "id": "0", "metadata": {}, "source": [ "# Cube Reprojection Tutorial\n", @@ -31,7 +31,7 @@ }, { "cell_type": "markdown", - "id": "70381c49", + "id": "1", "metadata": {}, "source": [ "## Index \n", @@ -49,7 +49,7 @@ }, { "cell_type": "markdown", - "id": "48448b34", + "id": "2", "metadata": {}, "source": [ "## Step 1: Download the data\n", @@ -60,7 +60,7 @@ { "cell_type": "code", "execution_count": null, - "id": "32902371", + "id": "3", "metadata": {}, "outputs": [], "source": [ @@ -70,7 +70,7 @@ }, { "cell_type": "markdown", - "id": "4dec821a", + "id": "4", "metadata": {}, "source": [ "We download two example spectral cubes of a point in the Galactic center from a permalink on the ALMA archives.\n", @@ -82,7 +82,7 @@ { "cell_type": "code", "execution_count": null, - "id": "9719f71a", + "id": "5", "metadata": {}, "outputs": [], "source": [ @@ -93,7 +93,7 @@ { "cell_type": "code", "execution_count": null, - "id": "2a1d4dc7", + "id": "6", "metadata": {}, "outputs": [], "source": [ @@ -103,7 +103,7 @@ }, { "cell_type": "markdown", - "id": "d801b283", + "id": "7", "metadata": {}, "source": [ "## Step 2: Load the cubes" @@ -112,7 +112,7 @@ { "cell_type": "code", "execution_count": null, - "id": "fe4ead93", + "id": "8", "metadata": {}, "outputs": [], "source": [ @@ -122,7 +122,7 @@ { "cell_type": "code", "execution_count": null, - "id": "833abd53", + "id": "9", "metadata": {}, "outputs": [], "source": [ @@ -133,7 +133,7 @@ { "cell_type": "code", "execution_count": null, - "id": "04b8ddcd", + "id": "10", "metadata": {}, "outputs": [], "source": [ @@ -143,7 +143,7 @@ }, { "cell_type": "markdown", - "id": "19595c31", + "id": "11", "metadata": {}, "source": [ "The cubes are at different frequencies - 139 and 217 GHz.\n", @@ -155,7 +155,7 @@ }, { "cell_type": "markdown", - "id": "ccc5334f", + "id": "12", "metadata": {}, "source": [ "We use the `find_lines` tool to query [splatalogue](https://splatalogue.online/) with [astroquery](https://astroquery.readthedocs.io/en/latest/splatalogue/splatalogue.html) over the spectral range covered by the cube. It returns a table of matching lines. Note that some line names will be repeated because Splatalogue includes several different databases and most chemical species are present in all of these." @@ -164,7 +164,7 @@ { "cell_type": "code", "execution_count": null, - "id": "fdf8959f", + "id": "13", "metadata": {}, "outputs": [], "source": [ @@ -174,7 +174,7 @@ { "cell_type": "code", "execution_count": null, - "id": "ba4fbb6a", + "id": "14", "metadata": {}, "outputs": [], "source": [ @@ -183,7 +183,7 @@ }, { "cell_type": "markdown", - "id": "8c7234cb", + "id": "15", "metadata": {}, "source": [ "## Step 3: Convert cubes from frequency to velocity\n", @@ -194,7 +194,7 @@ { "cell_type": "code", "execution_count": null, - "id": "9b59615f", + "id": "16", "metadata": {}, "outputs": [], "source": [ @@ -204,7 +204,7 @@ { "cell_type": "code", "execution_count": null, - "id": "86aa822b", + "id": "17", "metadata": {}, "outputs": [], "source": [ @@ -215,7 +215,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a1544293", + "id": "18", "metadata": {}, "outputs": [], "source": [ @@ -225,7 +225,7 @@ }, { "cell_type": "markdown", - "id": "11e7873f", + "id": "19", "metadata": {}, "source": [ "From the shape of the cube, we can see the H2CS cube is narrower in velocity, so we'll use that as the target spectral reprojection. However, the SiO cube is the smaller footprint on the sky." @@ -233,7 +233,7 @@ }, { "cell_type": "markdown", - "id": "cc6f783c", + "id": "20", "metadata": {}, "source": [ "### Create spatial maps of the peak intensity to quickly explore the cubes:\n", @@ -244,7 +244,7 @@ { "cell_type": "code", "execution_count": null, - "id": "bb078eb0", + "id": "21", "metadata": {}, "outputs": [], "source": [ @@ -254,7 +254,7 @@ }, { "cell_type": "markdown", - "id": "b8e96d66", + "id": "22", "metadata": {}, "source": [ "We can do the same thing all on one line (for the other cube this time):" @@ -263,7 +263,7 @@ { "cell_type": "code", "execution_count": null, - "id": "8b035a79", + "id": "23", "metadata": {}, "outputs": [], "source": [ @@ -272,7 +272,7 @@ }, { "cell_type": "markdown", - "id": "98ecf111", + "id": "24", "metadata": {}, "source": [ "# Step 4. Spectral Interpolation\n", @@ -286,7 +286,7 @@ { "cell_type": "code", "execution_count": null, - "id": "e19188f0", + "id": "25", "metadata": {}, "outputs": [], "source": [ @@ -297,7 +297,7 @@ }, { "cell_type": "markdown", - "id": "007fac49", + "id": "26", "metadata": {}, "source": [ "Next, we will reduce `cube2vel` to have the same spectral range as `cube1vel`:" @@ -306,7 +306,7 @@ { "cell_type": "code", "execution_count": null, - "id": "cee190fc", + "id": "27", "metadata": {}, "outputs": [], "source": [ @@ -317,7 +317,7 @@ }, { "cell_type": "markdown", - "id": "385b7042", + "id": "28", "metadata": {}, "source": [ "Note that it is important for the to-be-interpolated cube, in this case `cube2`, to have pixels bounding `cube1`'s spectral axis, but in this case it does not. If the pixel range doesn't overlap perfectly, it may blank out one of the edge pixels. So, to fix this, we add a little buffer:" @@ -326,7 +326,7 @@ { "cell_type": "code", "execution_count": null, - "id": "653d7199", + "id": "29", "metadata": {}, "outputs": [], "source": [ @@ -337,7 +337,7 @@ }, { "cell_type": "markdown", - "id": "c5a0e750", + "id": "30", "metadata": {}, "source": [ "Our H2CS cube (`cube1vel`) has broader channels. We need to first smooth `cube2vel` to the broader channel width before doing the spatial reprojection.\n", @@ -352,7 +352,7 @@ { "cell_type": "code", "execution_count": null, - "id": "c86d7716", + "id": "31", "metadata": {}, "outputs": [], "source": [ @@ -363,7 +363,7 @@ { "cell_type": "code", "execution_count": null, - "id": "35acafb7", + "id": "32", "metadata": {}, "outputs": [], "source": [ @@ -375,7 +375,7 @@ }, { "cell_type": "markdown", - "id": "ffdd178a", + "id": "33", "metadata": {}, "source": [ "We then smooth with the kernel. Note that this is doing 420x420 = 176400 smoothing operations on a length-221 spectrum: it will take a little time" @@ -384,7 +384,7 @@ { "cell_type": "code", "execution_count": null, - "id": "86ada2d7", + "id": "34", "metadata": {}, "outputs": [], "source": [ @@ -393,7 +393,7 @@ }, { "cell_type": "markdown", - "id": "00f6d313", + "id": "35", "metadata": {}, "source": [ "Now that we've done spectral smoothing, we can resample the spectral axis of `cube2vel_smooth` to match `cube1vel` by interpolating `cube2vel_smooth` onto `cube1vel`'s grid:" @@ -402,7 +402,7 @@ { "cell_type": "code", "execution_count": null, - "id": "7655a346", + "id": "36", "metadata": {}, "outputs": [], "source": [ @@ -413,7 +413,7 @@ }, { "cell_type": "markdown", - "id": "2eda47cf", + "id": "37", "metadata": {}, "source": [ "Note that we included the `suppress_smooth_warning=True` argument. That is to hide this warning:\n", @@ -425,7 +425,7 @@ }, { "cell_type": "markdown", - "id": "00926359", + "id": "38", "metadata": {}, "source": [ "# Step 5. Spatial Smoothing" @@ -433,7 +433,7 @@ }, { "cell_type": "markdown", - "id": "14e99bbb", + "id": "39", "metadata": {}, "source": [ "Now that we've done spectral smoothing, we also need to follow a similar procedure of smoothing then resampling for the spatial axes. \n", @@ -444,7 +444,7 @@ { "cell_type": "code", "execution_count": null, - "id": "4f0512f4", + "id": "40", "metadata": {}, "outputs": [], "source": [ @@ -453,7 +453,7 @@ }, { "cell_type": "markdown", - "id": "c93654ca", + "id": "41", "metadata": {}, "source": [ "`cube1` again hase the larger beam, so we'll smooth `cube2` to its resolution" @@ -461,7 +461,7 @@ }, { "cell_type": "markdown", - "id": "e6c4d626", + "id": "42", "metadata": {}, "source": [ "#### Aside: mixed beams \n", @@ -474,7 +474,7 @@ { "cell_type": "code", "execution_count": null, - "id": "b3cd31a7", + "id": "43", "metadata": {}, "outputs": [], "source": [ @@ -485,7 +485,7 @@ }, { "cell_type": "markdown", - "id": "74ff5976", + "id": "44", "metadata": {}, "source": [ "We then convolve:" @@ -494,7 +494,7 @@ { "cell_type": "code", "execution_count": null, - "id": "eaa9f644", + "id": "45", "metadata": {}, "outputs": [], "source": [ @@ -508,7 +508,7 @@ }, { "cell_type": "markdown", - "id": "cdc73378", + "id": "46", "metadata": {}, "source": [ "# Step 6. Reprojection\n", @@ -519,7 +519,7 @@ { "cell_type": "code", "execution_count": null, - "id": "de8b8a48", + "id": "47", "metadata": {}, "outputs": [], "source": [ @@ -529,7 +529,7 @@ }, { "cell_type": "markdown", - "id": "69d8a90b", + "id": "48", "metadata": {}, "source": [ "These two cubes are now on an identical grid, and can be directly compared:" @@ -538,7 +538,7 @@ { "cell_type": "code", "execution_count": null, - "id": "5bd3de8d", + "id": "49", "metadata": {}, "outputs": [], "source": [ @@ -547,7 +547,7 @@ }, { "cell_type": "markdown", - "id": "8cf176f3", + "id": "50", "metadata": {}, "source": [ "These spectra can now be overplotted as they are in the same unit with the same beam." @@ -556,7 +556,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a196eb8b", + "id": "51", "metadata": {}, "outputs": [], "source": [ @@ -566,7 +566,7 @@ }, { "cell_type": "markdown", - "id": "13afd6f7", + "id": "52", "metadata": {}, "source": [ "# Dask\n", @@ -579,7 +579,7 @@ }, { "cell_type": "markdown", - "id": "0934aa4b", + "id": "53", "metadata": {}, "source": [ "We repeat all the operations above using dask. We use a `ProgressBar` so you can see how long it takes. We also suppress warnings to make the output look cleaner (we already saw all the important warnings above)." @@ -588,7 +588,7 @@ { "cell_type": "code", "execution_count": null, - "id": "03e1a267", + "id": "54", "metadata": {}, "outputs": [], "source": [ @@ -599,7 +599,7 @@ { "cell_type": "code", "execution_count": null, - "id": "14d47820", + "id": "55", "metadata": {}, "outputs": [], "source": [ @@ -622,7 +622,7 @@ { "cell_type": "code", "execution_count": null, - "id": "4af66ead", + "id": "56", "metadata": {}, "outputs": [], "source": []