Skip to content

Instantly share code, notes, and snippets.

@pllim
Created March 15, 2018 17:10
Show Gist options
  • Save pllim/2fbd40ab12d5b3902f3d21f9a516ddbe to your computer and use it in GitHub Desktop.
Save pllim/2fbd40ab12d5b3902f3d21f9a516ddbe to your computer and use it in GitHub Desktop.
PySynphot Issue 81
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## PySynphot"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.9.10a\n"
]
}
],
"source": [
"import os\n",
"\n",
"import pysynphot as S\n",
"\n",
"print(S.__version__)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"vega_file = os.path.join(\n",
" os.environ['PYSYN_CDBS'], 'calspec', 'alpha_lyr_stis_005.fits')\n",
"vega = S.FileSpectrum(vega_file)\n",
"vega.convert('flam')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"8.690799495318716e-09\n",
"5.042382531851877e-10\n"
]
}
],
"source": [
"extinct = S.Extinction(0.7, 'mwavg')\n",
"sp1 = vega * extinct\n",
"print(max(vega.flux))\n",
"print(max(sp1.flux))"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"5026.7534\n",
"6182.906704101562\n"
]
}
],
"source": [
"sp2 = sp1.redshift(0.23)\n",
"sp2.convert('flam')\n",
"print(sp1.wave[sp1.flux == max(sp1.flux)][0])\n",
"print(sp2.wave[sp2.flux == max(sp2.flux)][0])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## synphot"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This package is a replacement for the non-instrument specific part of PySynphot. It uses Astropy models and understand Astropy units. See http://astropy.org .\n",
"\n",
"Full package documentation is at http://synphot.readthedocs.io/en/latest/ . Conversion guide is at http://synphot.readthedocs.io/en/latest/synphot/from_pysyn_iraf.html ."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.1\n"
]
}
],
"source": [
"import synphot\n",
"from synphot import SourceSpectrum, ReddeningLaw\n",
"\n",
"print(synphot.__version__)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"vega = SourceSpectrum.from_file(vega_file)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"8.690800079591554e-09 FLAM\n",
"5.042381294202286e-10 FLAM\n"
]
}
],
"source": [
"extinct = ReddeningLaw.from_extinction_model('mwavg').extinction_curve(0.7)\n",
"sp1 = vega * extinct\n",
"sp1_flux = sp1(sp1.waveset, flux_unit='flam')\n",
"sp1_maxflux = max(sp1_flux)\n",
"print(max(vega(vega.waveset, flux_unit='flam')))\n",
"print(sp1_maxflux)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"5026.75341796875 Angstrom\n",
"6182.906704101562 Angstrom\n"
]
}
],
"source": [
"sp2 = SourceSpectrum(sp1.model, z=0.23)\n",
"sp2_flux = sp2(sp2.waveset, flux_unit='flam')\n",
"sp2_maxflux = max(sp2_flux)\n",
"print(sp1.waveset[sp1_flux == sp1_maxflux][0])\n",
"print(sp2.waveset[sp2_flux == sp2_maxflux][0])"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.6.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
@pllim
Copy link
Author

pllim commented Mar 15, 2018

Don't leave comments here. I won't get notified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment