Skip to content

Commit

Permalink
Added tutorial for comparing data with a grid of model spectra, added…
Browse files Browse the repository at this point in the history
… create_param_format fucntion to plot_util
  • Loading branch information
tomasstolker committed May 7, 2024
1 parent d258d3b commit fe28b8e
Show file tree
Hide file tree
Showing 7 changed files with 665 additions and 55 deletions.
1 change: 1 addition & 0 deletions docs/tutorials.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This page contains a list of tutorials which highlight some of the functionaliti
:maxdepth: 1

tutorials/fitting_model_spectra.ipynb
tutorials/grid_comparison.ipynb
tutorials/atmospheric_retrieval.ipynb
tutorials/emission_line.ipynb
tutorials/flux_calibration.ipynb
Expand Down
29 changes: 19 additions & 10 deletions docs/tutorials/fitting_model_spectra.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,15 @@
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"[cosmos.home:03394] shmem: mmap: an error occurred while determining whether or not /var/folders/4y/qx08nc451nn_ggz7r2vngb140000gn/T//ompi.cosmos.501/jf.0/527958016/sm_segment.cosmos.501.1f780000.0 could be created.\n"
]
}
],
"source": [
"import urllib.request\n",
"from species import SpeciesInit\n",
Expand Down Expand Up @@ -80,18 +88,19 @@
"output_type": "stream",
"text": [
"==============\n",
"species v0.7.4\n",
"species v0.8.3\n",
"==============\n",
"\n",
"Working folder: /Users/tomasstolker/applications/species/docs/tutorials\n",
"\n",
"Creating species_config.ini... [DONE]\n",
"Creating species_database.hdf5... [DONE]\n",
"Creating data folder... [DONE]\n",
"\n",
"Configuration settings:\n",
" - Database: /Users/tomasstolker/applications/species/docs/tutorials/species_database.hdf5\n",
" - Data folder: /Users/tomasstolker/applications/species/docs/tutorials/data\n",
" - Magnitude of Vega: 0.03\n",
"Creating species_database.hdf5... [DONE]\n",
"Creating data folder... [DONE]\n",
"\n",
"Multiprocessing: mpi4py installed\n",
"Process number 1 out of 1...\n"
Expand All @@ -100,7 +109,7 @@
{
"data": {
"text/plain": [
"<species.core.species_init.SpeciesInit at 0x197597ad0>"
"<species.core.species_init.SpeciesInit at 0x190bccb10>"
]
},
"execution_count": 3,
Expand All @@ -127,7 +136,7 @@
{
"data": {
"text/plain": [
"('betapicb_gpi_h.dat', <http.client.HTTPMessage at 0x1972d68d0>)"
"('betapicb_gpi_h.dat', <http.client.HTTPMessage at 0x1951b42d0>)"
]
},
"execution_count": 4,
Expand All @@ -136,13 +145,13 @@
}
],
"source": [
"urllib.request.urlretrieve('https://home.strw.leidenuniv.nl/~stolker/species/BetaPictorisb_2018-09-22.fits',\n",
"urllib.request.urlretrieve('https://home.strw.leidenuniv.nl/~stolker/species/spectra/BetaPictorisb_2018-09-22.fits',\n",
" 'BetaPictorisb_2018-09-22.fits')\n",
"urllib.request.urlretrieve('https://home.strw.leidenuniv.nl/~stolker/species/betapicb_gpi_y.dat',\n",
"urllib.request.urlretrieve('https://home.strw.leidenuniv.nl/~stolker/species/spectra/betapicb_gpi_y.dat',\n",
" 'betapicb_gpi_y.dat')\n",
"urllib.request.urlretrieve('https://home.strw.leidenuniv.nl/~stolker/species/betapicb_gpi_j.dat',\n",
"urllib.request.urlretrieve('https://home.strw.leidenuniv.nl/~stolker/species/spectra/betapicb_gpi_j.dat',\n",
" 'betapicb_gpi_j.dat')\n",
"urllib.request.urlretrieve('https://home.strw.leidenuniv.nl/~stolker/species/betapicb_gpi_h.dat',\n",
"urllib.request.urlretrieve('https://home.strw.leidenuniv.nl/~stolker/species/spectra/betapicb_gpi_h.dat',\n",
" 'betapicb_gpi_h.dat')"
]
},
Expand Down
565 changes: 565 additions & 0 deletions docs/tutorials/grid_comparison.ipynb

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions species/data/companion_data/companion_spectra.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@
"Delorme et al. 2017, A&A, 608, 79"
]
},
"HD 206893 c": {
"GRAVITY": [
"HD206893C_GRAVITYK_fluxcal_spectrum.fits",
"HD206893C_GRAVITYK_fluxcal_spectrum.fits",
500.0,
"2023A&A...671L...5H"
]
},
"HIP 65426 B": {
"SPHERE_YJH": [
"hip65426b_sphere_yjh.dat",
Expand Down
5 changes: 4 additions & 1 deletion species/plot/plot_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from species.read.read_model import ReadModel
from species.read.read_object import ReadObject
from species.util.dust_util import ism_extinction
from species.util.plot_util import create_model_label, update_labels
from species.util.plot_util import create_model_label, create_param_format, update_labels
from species.util.spec_util import smooth_spectrum


Expand Down Expand Up @@ -1218,12 +1218,15 @@ def plot_model_spectra(
leg_param = model_param.copy()
leg_param.append("radius")

param_fmt = create_param_format(param_fmt=None)

label_text = create_model_label(
model_param=param_select,
model_name=model_name,
inc_model_name=False,
object_type="planet",
leg_param=leg_param,
param_fmt=param_fmt,
)

label_text = (
Expand Down
45 changes: 2 additions & 43 deletions species/plot/plot_spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from species.read.read_filter import ReadFilter
from species.util.core_util import print_section
from species.util.data_util import convert_units
from species.util.plot_util import create_model_label
from species.util.plot_util import create_model_label, create_param_format


@typechecked
Expand Down Expand Up @@ -216,48 +216,7 @@ def plot_spectrum(
if leg_param is None:
leg_param = []

if param_fmt is None:
param_fmt = {}

# Add missing parameter formats

param_add = ["teff", "disk_teff", "disk_radius"]

for param_item in param_add:
if param_item not in param_fmt:
param_fmt[param_item] = ".0f"

param_add = [
"radius",
"logg",
"feh",
"metallicity",
"fsed",
"log_kzz",
"distance",
"parallax",
"mass",
"ism_ext",
"lognorm_ext",
"powerlaw_ext",
"log_flux_scaling",
]

for param_item in param_add:
if param_item not in param_fmt:
param_fmt[param_item] = ".1f"

param_add = ["co", "c_o_ratio", "ad_index", "luminosity"]

for param_item in param_add:
if param_item not in param_fmt:
param_fmt[param_item] = ".2f"

param_add = ["flux_scaling", "flux_offset"]

for param_item in param_add:
if param_item not in param_fmt:
param_fmt[param_item] = ".2e"
param_fmt = create_param_format(param_fmt)

if residuals is not None and filters is not None:
fig = plt.figure(figsize=figsize)
Expand Down
67 changes: 66 additions & 1 deletion species/util/plot_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,7 @@ def create_model_label(
leg_param: List[str],
param_fmt: Dict[str, str],
) -> str:
""" "
""""
Function for creating a label that includes the parameters of a
model spectrum. The label is used in the legend of a SED plot.
Expand Down Expand Up @@ -1586,3 +1586,68 @@ def create_model_label(
label += f"{par_label[param_idx]} = {value} {par_unit[param_idx]}"

return label


def create_param_format(param_fmt: Optional[Dict[str, str]]) -> Dict[str, str]:
""""
Function for creating a dictionary with parameter formats
that are used in the legend of a plot.
Parameters
----------
param_fmt : dict(str, str), None
Dictionary with formats that will be used for the model
parameter. The parameters are included in the ``legend``
when plotting the model spectra. Default formats are
used if the argument of ``param_fmt`` is set to ``None``.
Returns
-------
dict(str, str)
Output dictionary with parameter formats.
"""

if param_fmt is None:
param_fmt = {}

# Add missing parameter formats

param_add = ["teff", "disk_teff", "disk_radius"]

for param_item in param_add:
if param_item not in param_fmt:
param_fmt[param_item] = ".0f"

param_add = [
"radius",
"logg",
"feh",
"metallicity",
"fsed",
"log_kzz",
"distance",
"parallax",
"mass",
"ism_ext",
"lognorm_ext",
"powerlaw_ext",
"log_flux_scaling",
]

for param_item in param_add:
if param_item not in param_fmt:
param_fmt[param_item] = ".1f"

param_add = ["co", "c_o_ratio", "ad_index", "luminosity"]

for param_item in param_add:
if param_item not in param_fmt:
param_fmt[param_item] = ".2f"

param_add = ["flux_scaling", "flux_offset"]

for param_item in param_add:
if param_item not in param_fmt:
param_fmt[param_item] = ".2e"

return param_fmt

3 comments on commit fe28b8e

@gabrielastro
Copy link

Choose a reason for hiding this comment

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

About species/data/companion_data/companion_spectra.json: add to the bibcode 2023A&A...671L...5H the first author's name? I guess this could be done for all entries, for users' convenience… On the list of very minor things :).

@tomasstolker
Copy link
Owner Author

Choose a reason for hiding this comment

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

Yeah I want to change it consistently to bibcodes so this is a very small start 😉

@gabrielastro
Copy link

@gabrielastro gabrielastro commented on fe28b8e May 13, 2024

Choose a reason for hiding this comment

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

But with the author(s)'(s) name(s) too for convenience? Otherwise it can be a fun test-your-literature-knowledge guessing game 💡 😉

Please sign in to comment.