Skip to content
Open
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
286 changes: 286 additions & 0 deletions tutorials/0-introduction/data_containers_cubing.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,286 @@
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tutorial for cubing should go on the 2-science-data/ dir

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps there should be two (or more) tutorials: one for basic stuff (explaining how to read a datacube, what are wavelength, intensity, and variance, how to make simple plots...), and another one on creating a cube from a set of RSS, which may contain advanced stuff such as registration or ADR.

In any case, why do we use a standard star instead of a galaxy?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PabloCorcho noted.

@paranoya is there a fits file in the repository data that contains a galaxy?

"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# PyKOALA Cubing "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Table of contents:\n",
"\n",
"1. [Importing class](#importing-class)\n",
"2. [Organising data](#organising-data)\n",
"3. [KOALA cubing](#KOALA-cubing)\n",
" - [`Cubing` methods](#cubing-methods)\n",
" - [Rows and columns](#rows-and-columns)\n",
" - [`rss_intensity`](#rss_intensity)\n",
" - [`rss_variance`](#rss_variance)\n",
" - [`get_centre_of_mass`](#get_centre_of_mass)\n",
" - [`get_integrated_light_frac`](#get_integrated_light_frac)\n",
"4. [Plotting cube data](#plotting-cube-data)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Importing class"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from matplotlib import pyplot as plt\n",
"import numpy as np\n",
"import os\n",
"from astropy import units as u\n",
"from pykoala.corrections.astrometry import AstrometryCorrection\n",
"\n",
"# Pykoala modules\n",
"\n",
"from pykoala.cubing import build_wcs, CubeInterpolator, CubeStacking\n",
"from pykoala.instruments.koala_ifu import koala_rss\n",
"from pykoala.corrections.astrometry import find_centroid_in_dc\n",
"from pykoala.corrections.astrometry import AstrometryCorrection"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Organising data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# List of RSS objects\n",
"\n",
"std_star_rss = []\n",
"data_path = '../data/koala/'\n",
"grating = '385R'\n",
"\n",
"for i in [28, 29, 30]:\n",
" filename = os.path.join(data_path, grating, f\"27feb200{i}red.fits\")\n",
" rss = koala_rss(filename)\n",
" std_star_rss.append(rss)\n",
"\n",
"star_name = rss.info['name'].split(' ')[0]\n",
"print(\"Star name: \", star_name)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n",
"astrom_corr = AstrometryCorrection()\n",
"\n",
"offsets, fig = astrom_corr.register_centroids(std_star_rss, object_name=star_name,\n",
" qc_plot=True, centroider='gauss')\n",
"for offset in offsets:\n",
" print(\"Offset (ra, dec) in arcsec: \", offset[0].to('arcsec'), offset[1].to('arcsec'))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## `KOALA` cubing"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"datacube_shape = (std_star_rss[0].wavelength.size, 40, 60)\n",
"ref_position = (std_star_rss[0].wavelength[0], np.mean(std_star_rss[0].info['fib_ra']), np.mean(std_star_rss[0].info['fib_dec'])) # (deg, deg)\n",
"spatial_pixel_size = 1.0 << u.arcsec\n",
"spectral_pixel_size = std_star_rss[0].wavelength[1] - std_star_rss[0].wavelength[0] # (angstrom)\n",
"\n",
"print(f\"Creating a WCS with\\n position: {ref_position}\\n Spatial pixel size: {spatial_pixel_size}\\n Spectral pixel size: {spectral_pixel_size}\")\n",
"\n",
"wcs = build_wcs(datacube_shape=datacube_shape,\n",
" reference_position=ref_position,\n",
" spatial_pix_size=spatial_pixel_size,\n",
" spectra_pix_size=spectral_pixel_size,\n",
" )"
]
Comment on lines +111 to +123
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we could also suggest the use of build_wcs_from_rss

},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"interpolator = CubeInterpolator(rss_set=std_star_rss)\n",
"cube = interpolator.build_cube()\n",
"white_image = np.nanmean(cube.intensity, axis=0)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since cubes have a method cube.get_white_image it might be worth using that here instead

]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### `Cubing` methods"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Rows and columns"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(f\"Number of spaxel columns: {cube.n_cols}\")\n",
"print(f\"Number of spaxel rows: {cube.n_rows}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### `rss_intensity`"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth explaining the meaning of this variable

]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(f\"Intensity data: \\n\\n {cube.rss_intensity}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### `rss_variance`"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(f\"Intensity data: \\n\\n {cube.rss_variance}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### `get_centre_of_mass`"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(f\"Center of mass of the data cube: \\n\\n {cube.get_centre_of_mass()}\")"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I would explain that the com is per wavelength unit

]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Plotting cube data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"datacube_shape = (std_star_rss[0].wavelength.size, 40, 60)\n",
"ref_position = (std_star_rss[0].wavelength[0], np.mean(std_star_rss[0].info['fib_ra']), np.mean(std_star_rss[0].info['fib_dec'])) # (deg, deg)\n",
"spatial_pixel_size = 1.0 << u.arcsec\n",
"spectral_pixel_size = std_star_rss[0].wavelength[1] - std_star_rss[0].wavelength[0] # (angstrom)\n",
"\n",
"print(f\"Creating a WCS with\\n position: {ref_position}\\n Spatial pixel size: {spatial_pixel_size}\\n Spectral pixel size: {spectral_pixel_size}\")\n",
"\n",
"wcs = build_wcs(datacube_shape=datacube_shape,\n",
" reference_position=ref_position,\n",
" spatial_pix_size=spatial_pixel_size,\n",
" spectra_pix_size=spectral_pixel_size,\n",
" )"
]
},
Comment on lines +215 to +234
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated cell?

{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n",
"pos_com = find_centroid_in_dc(cube, centroider='com', com_power=1.)\n",
"pos_com_3 = find_centroid_in_dc(cube, centroider='com', com_power=3.)\n",
"pos_gauss = find_centroid_in_dc(cube, centroider='gauss')"
]
},
{
Comment on lines +236 to +247
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a new section where the use of this method is explained?

"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n",
"fig = plt.figure()\n",
"ax = fig.add_subplot(111, projection=wcs.celestial)\n",
"mappable = ax.imshow(np.log10(white_image.value), vmin=-2)\n",
"fig.set_size_inches(18.5, 10.5)\n",
"plt.colorbar(mappable)\n",
"ax.scatter(pos_com.ra, pos_com.dec, marker='*', ec='r', transform=ax.get_transform('world'))\n",
"ax.scatter(pos_com_3.ra, pos_com_3.dec, marker='*', ec='lime', transform=ax.get_transform('world'))\n",
"ax.scatter(pos_gauss.ra, pos_gauss.dec, marker='+', ec='k', transform=ax.get_transform('world'))\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "venv_koala",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading