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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,10 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# Output of tutorials
tutorials/0-introduction/output/*

# Local files
tutorials/0-introduction/plot_check.py
tutorials/data/koala/385R/27feb20030red.fits_miguel.fits
9 changes: 1 addition & 8 deletions tutorials/0-introduction/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@ This directory contains a set of tutorials aiming to get users familiarised with

## Contents

### A guide through DataContainers

The tutorial `data_containers.ipynb` goes through the multiple aspects of `DataContainers`.

### Corrections

The tutorial `corrections.ipynb` explains the current structure of the different corrections that can be applied to `DataContainers`.

### I/O

The tutorial `io.ipynb` provies examples on how informatino (i.e. data, logs, etc) is handled in `pykoala`.
The tutorial `io.ipynb` provies examples on how information (i.e. data, logs, etc) is handled in `pykoala`.
Empty file.
8 changes: 8 additions & 0 deletions tutorials/2-science-data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@ This directory contains a set of tutorials on how to process scientific frames t

## Contents


### RSS

The tutorial `rss_registration.ipynb`, shows how to read/write from/to FITS files with the PyKOALA headers.

### Cubing

The tutorial `cubing.ipynb`, contains the information to convert RSS data into cubes and how to extract the information.
323 changes: 323 additions & 0 deletions tutorials/2-science-data/cubing.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,323 @@
{
"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)"
]
},
{
"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 (star)\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": [
"# List of RSS objects (galaxy)\n",
"\n",
"std_galaxy_rss = []\n",
"\n",
"for i in [34, 35, 36]:\n",
" filename = os.path.join(data_path, grating, f\"27feb200{i}red.fits\")\n",
" rss = koala_rss(filename)\n",
" std_galaxy_rss.append(rss)\n",
"\n",
"galaxy_name = rss.info['name'].split(' ')[0]\n",
"print(\"Galaxy name: \", galaxy_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",
" )"
]
},
{
"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.

A good place to show cube.get_white_image()

]
},
{
"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`"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The spectra data (counts per pixel per second) is stored in this attribute:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(f\"Intensity data: \\n\\n {cube.rss_intensity}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Using the wavelength data we can plot raw spectra:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig, (ax1, ax2) = plt.subplots(2, sharex=True)\n",
"fig.suptitle('Raw spectra examples')\n",
"ax1.plot(cube.wavelength, cube.rss_intensity[0])\n",
"ax2.plot(cube.wavelength, cube.rss_intensity[1])\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### `rss_variance`"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Variance of the intensity"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(f\"Variance data: \\n\\n {cube.rss_variance}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### `get_centre_of_mass`"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The center of mass per wavelength unit is obtained with this method:"
]
},
{
"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()}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
},
{
"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')"
]
},
{
"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