Skip to content
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

Minor updates after MNRAS accepted the paper #52

Merged
merged 7 commits into from
Feb 6, 2024
Merged
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
6 changes: 3 additions & 3 deletions .github/workflows/nirdust_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@master
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version}}
- name: Install pandoc
Expand All @@ -29,7 +29,7 @@ jobs:
- name: Test with tox
run: tox -r
- name: Test Coverage
if: ${{ matrix.python-version == '3.8' }}
if: ${{ matrix.python-version == '3.11' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
Expand Down
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
[![Coverage Status](https://coveralls.io/repos/github/Gaiana/nirdust/badge.svg?branch=main)](https://coveralls.io/github/Gaiana/nirdust?branch=main)
[![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/release/python-370/)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![arXiv](https://img.shields.io/badge/arXiv-2401.01888-b31b1b.svg)](https://arxiv.org/abs/2401.01888)


NIRDust is a python package that uses K-band (2.2 micrometers) spectra to
Expand Down Expand Up @@ -60,7 +61,33 @@ Or, for the develovepment instalation clone this repository and then inside the
$ pip install -e .
```

Authors: Gaia Gaspar, José Alacoria, Juan B. Cabral & Martin Chalela
## Citation

If you use *NIRDust* in a scientific publication, we would appreciate citations to the following paper:

> Gaspar, Gaia and Chalela, Martín and Cabral, Juan and Alacoria, José and Mast, Damián and Díaz, Rubén J (2024).
> NIRDust: probing hot dust emission around type 2 AGN using K-band spectra. 10.1093/mnras/stae008

### Bibtex

```bibtex
@article{10.1093/mnras/stae008,
author = {Gaspar, Gaia and Chalela, Martín and Cabral, Juan and Alacoria, José and Mast, Damián and Díaz, Rubén J},
title = "{nirdust: probing hot dust emission around type 2 AGN using K-band spectra}",
journal = {Monthly Notices of the Royal Astronomical Society},
volume = {528},
number = {2},
pages = {2952-2963},
year = {2024},
month = {01},
issn = {0035-8711},
doi = {10.1093/mnras/stae008},
url = {https://doi.org/10.1093/mnras/stae008},
eprint = {https://academic.oup.com/mnras/article-pdf/528/2/2952/56541590/stae008.pdf},
}
```

Full-text: [https://arxiv.org/abs/1912.09585](https://arxiv.org/abs/2401.01888)



Expand Down
2 changes: 1 addition & 1 deletion docs/source/api.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
NIRDust API Reference
API Reference
=====================

.. automodule:: nirdust
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@


html_theme_options = {
"logotext1": "Nirdust", # white, semi-bold
"logotext1": "NIRDust", # white, semi-bold
"logotext2": "", # orange, light
"logotext3": ":docs", # white, light
"astropy_project_menubar": False,
Expand Down
4 changes: 2 additions & 2 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ User Documentation
------------------

.. toctree::
:maxdepth: 1
:maxdepth: 2

installation
tutorials/index
api
tutorials/NGC5128.ipynb
licence


Expand Down
2 changes: 1 addition & 1 deletion docs/source/tutorials/NGC5128.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Example of Nirdust application\n",
"## Example of NIRDust application\n",
"The example imputs are two Flamingos-2 (Gemini South) $K_{long}$ band longslit spectra of NGC 5128 (Centaurus A) a Seyfert 2 galaxy.\n",
"\n",
"The spectra correspond to:\n",
Expand Down
26 changes: 26 additions & 0 deletions docs/source/tutorials/fit_blackbody.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Fitting a BlackBody model"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"work in progress..."
]
}
],
"metadata": {
"language_info": {
"name": "python"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
15 changes: 15 additions & 0 deletions docs/source/tutorials/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Tutorials
=========

The following page contains a collection of tutorials and practical examples
on how to use NIRDust. From reading your spectra from a file, to modelling the
hot dust emission and visualizing the results.


.. toctree::
:maxdepth: 2

reading_spectra.ipynb
preprocessing.ipynb
fit_blackbody.ipynb
NGC5128.ipynb
43 changes: 43 additions & 0 deletions docs/source/tutorials/preprocessing.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Preprocessing utilities"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"work in progress..."
]
}
],
"metadata": {
"interpreter": {
"hash": "dfefad9444caa34b651035342248c936eda24540a2756afa4fe280ef294fff37"
},
"kernelspec": {
"display_name": "Python 3.8.10 64-bit ('nirdust': virtualenv)",
"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.8.10"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
119 changes: 119 additions & 0 deletions docs/source/tutorials/reading_spectra.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Reading Spectra"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"NIRDust provides easy and quick functionalities to read your spectra. If you have your data in FITS format or just a common text ASCII file, you can use one of the following functions. If you don't have your data in any of these formats, by the end of this tutorial you can see how to load your data to create a NirdustSpectrum object directly."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Reading from a FITS file"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's say you have your spectra in a FITS file. This format, in most cases, comes with a header and a science extension. The science extension stores the flux intesity of the spectrum and the respective pixel axis. The header has the information to transform the pixel axis into a spectral axis. The manual input of the redshift of the galaxy, which isn't included in most headers, is necesary to get the spectral axis in rest frame. The following code shows the easiest way to read a spectrum:"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"NirdustSpectrum(z=0.00183, spectral_length=1751, spectral_range=[18889.58-25106.71] Angstrom)"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import nirdust as nd\n",
"\n",
"nuclear_spectrum = nd.read_fits(\"nuclear_spectrum.fits\", z=0.00183)\n",
"\n",
"# Show some information\n",
"nuclear_spectrum"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If your FITS file has multiple extensions, the automatic detection of the science extension may fail. In such cases, you can manually indicate the correct extension by passing the parameter ``extension=1`` to the function (if 1 is the correct number)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Reading from an ASCII file"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The function ``read_table`` can be used to read directly from a text file and supports multiple formats. In this case the file should contain these two columns: wavelength [A] and flux [arbitrary units]. If you have multiple columns you should indicate which columns correspond to the spectrum data. For a list of supported formats see [this link](https://docs.astropy.org/en/stable/io/ascii/index.html#supported-formats)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"spectrum = nd.read_table(\"file_name.csv\", wavelength_column=2, flux_column=4, format=\"csv\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"interpreter": {
"hash": "dfefad9444caa34b651035342248c936eda24540a2756afa4fe280ef294fff37"
},
"kernelspec": {
"display_name": "Python 3.8.10 64-bit ('nirdust': virtualenv)",
"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.8.10"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
4 changes: 1 addition & 3 deletions nirdust/bbody.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ def negative_gaussian_log_likelihood(
diff = target_spectrum.flux.value - prediction

loglike = np.sum(
-0.5 * np.log(2.0 * np.pi)
- np.log(noise)
- diff**2 / (2.0 * noise**2)
-0.5 * np.log(2.0 * np.pi) - np.log(noise) - diff**2 / (2.0 * noise**2)
)
return -loglike

Expand Down
20 changes: 9 additions & 11 deletions nirdust/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ def match_spectral_axes(
else:
second_sp = _rescale(second_sp, reference_sp=first_sp)

else:
# they have the same dispersion, is that equivalent
# to equal spectral_axis?
pass
# else:
# # they have the same dispersion, is that equivalent
# # to equal spectral_axis?
# pass

if clean:
first_sp, second_sp = _clean_and_match(first_sp, second_sp)
Expand Down Expand Up @@ -190,13 +190,11 @@ def line_spectrum(

Return
------
out: flux axis, list, list
Returns in the first element a flux axis of the same lenght as the
original spectrum containing the fitted lines. In the second position,
returns the intervals where those lines were finded determined by
3-sigma values around the center of the line. In the third position
returns an array with the quality of the fitting for each line (not yet
implemented).
out: NirdustSpectrum, Quantity
Returns in the first element a NirdustSpectrum of the same lenght as
the original spectrum containing the fitted lines. In the 2nd position,
returns the intervals where those lines were found determined by
3-sigma values around the center of the line.
"""
# values in correct units
window = u.Quantity(window, u.AA)
Expand Down
13 changes: 7 additions & 6 deletions tests/test_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,14 @@ def test_line_spectrum(NGC4945_continuum_rest_frame):
z=0,
).compute_noise(23000, 24000)

lines = preprocessing.line_spectrum(snth_line_spectrum, 5, window=80)[
0
].flux

all_zeros = any(lines)
line_nd_spectrum, line_intervals = preprocessing.line_spectrum(
snth_line_spectrum,
noise_factor=5,
window=80,
)

assert all_zeros is True
assert isinstance(line_nd_spectrum, core.NirdustSpectrum)
assert isinstance(line_intervals, u.Quantity)


def test_spectral_dispersion(NGC4945_continuum_rest_frame):
Expand Down
7 changes: 5 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
[tox]
envlist = py38, py39, py310, style, docstyle, check-manifest, make-docs, coverage
envlist = py{38,39,310,311,312}, style, docstyle, check-manifest, make-docs, coverage

[gh-actions]
python =
3.8: py38, style, coverage, docstyle, check-manifest, make-docs
3.8: py38
3.9: py39
3.10: py310
3.11: py311, style, coverage, docstyle, check-manifest, make-docs
3.12: py312


[testenv]
usedevelop = True
Expand Down