-
Notifications
You must be signed in to change notification settings - Fork 1
Cleaning up finished tutorials and updating README files #8
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
Open
miguelglezb
wants to merge
1
commit into
main
Choose a base branch
from
a3d/oct_state
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)" | ||
| ] | ||
| }, | ||
| { | ||
| "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 | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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()