Skip to content

Commit

Permalink
Added another tutorial, "synphot-model-spec"
Browse files Browse the repository at this point in the history
  • Loading branch information
tcjansen committed Aug 9, 2019
1 parent f2cfd5a commit c3c4c8a
Show file tree
Hide file tree
Showing 5 changed files with 1,298 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"metadata": {},
"source": [
"## Summary\n",
"<a href=\"https://synphot.readthedocs.io/en/latest/index.html\">`synphot`</a> is an astropy-affiliated package for creating synthetic photometry in Python. In this tutorial we will show how to use `synphot` to predict the photometric fluxes of a galaxy observed by SDSS. In particular, we will:\n",
"<a href=\"https://synphot.readthedocs.io/en/latest/index.html\"><tt>synphot</tt></a> is an astropy-affiliated package for creating synthetic photometry in Python. In this tutorial we will show how to use <tt>synphot</tt> to predict the photometric fluxes of a galaxy observed by SDSS. In particular, we will:\n",
"<ol>\n",
"<li><a href=\"#sdss\">Get the observed spectrum of our target from SDSS</a></li>\n",
"<li><a href=\"#source_spectrum\">Construct a source spectrum object</a></li>\n",
Expand All @@ -54,7 +54,7 @@
},
{
"cell_type": "code",
"execution_count": 47,
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -93,12 +93,12 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"To download the spectrum, first set the coordinates for the object using <a href=\"https://docs.astropy.org/en/stable/api/astropy.coordinates.SkyCoord.html\" target=\"_blank\">`astropy.coordinates.SkyCoord`</a>:"
"To download the spectrum, first set the coordinates for the object using <a href=\"https://docs.astropy.org/en/stable/api/astropy.coordinates.SkyCoord.html\" target=\"_blank\"><tt>astropy.coordinates.SkyCoord</tt></a>:"
]
},
{
"cell_type": "code",
"execution_count": 31,
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -111,23 +111,14 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Then use these coordinates with <a href=\"https://astroquery.readthedocs.io/en/latest/sdss/sdss.html\">`astroquery.sdss`</a> to get a .fits file of the spectrum observed by SDSS:"
"Then use these coordinates with <a href=\"https://astroquery.readthedocs.io/en/latest/sdss/sdss.html\"><tt>astroquery.sdss</tt></a> to get a .fits file of the spectrum observed by SDSS:"
]
},
{
"cell_type": "code",
"execution_count": 32,
"execution_count": 18,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/tiffanyjansen/anaconda3/lib/python3.7/site-packages/astroquery/sdss/core.py:856: VisibleDeprecationWarning: Reading unicode strings without specifying the encoding argument is deprecated. Set the encoding, use None for the system default.\n",
" comments='#'))\n"
]
}
],
"outputs": [],
"source": [
"spectrum_fits = SDSS.get_spectra(coordinates=coords)\n",
"data = spectrum_fits[0][1].data"
Expand All @@ -142,7 +133,7 @@
},
{
"cell_type": "code",
"execution_count": 33,
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -162,12 +153,12 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"To do synthetic photometry with `synphot`, you must first make an object out of your target's spectrum with <a href=\"https://synphot.readthedocs.io/en/latest/synphot/spectrum.html#arrays\">`synphot.spectrum.SourceSpectrum`</a>. Since we are constructing the source spectrum from arrays of data, we specify that the model type is Empirical1D and pass in the arrays (e.g. <code>points=wavelengths</code> and <code>lookup_table=flux</code>):"
"To do synthetic photometry with <tt>synphot</tt>, you must first make an object out of your target's spectrum with <a href=\"https://synphot.readthedocs.io/en/latest/synphot/spectrum.html#arrays\"><tt>synphot.spectrum.SourceSpectrum</tt></a>. Since we are constructing the source spectrum from arrays of data, we specify that the model type is Empirical1D and pass in the arrays (e.g. <code>points=wavelengths</code> and <code>lookup_table=flux</code>):"
]
},
{
"cell_type": "code",
"execution_count": 34,
"execution_count": 20,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -202,26 +193,26 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Next we want to model the effect of observing this object through the SDSS bandpasses. Similar to how we made the spectral data into a synphot object, we will also need to construct bandpass objects so that the two can be easily convolved using `synphot`."
"Next we want to model the effect of observing this object through the SDSS bandpasses. Similar to how we made the spectral data into a synphot object, we will also need to construct bandpass objects so that the two can be easily convolved using <tt>synphot</tt>."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To obtain the filter transmission functions of the SDSS bandpasses, we use <a href=\"https://docs.astropy.org/en/stable/api/astropy.utils.data.download_file.html\" target=\"_blank\">`astropy.utils.data.download_file`</a> to download the transmission file from the <a href=\"http://svo2.cab.inta-csic.es/theory/fps/index.php?mode=voservice\">Spanish Virtual Observatory</a> filter database. These transmission functions include the effect of the CCD's quantum efficiency on the spectrum."
"To obtain the filter transmission functions of the SDSS bandpasses, we use <a href=\"https://docs.astropy.org/en/stable/api/astropy.utils.data.download_file.html\" target=\"_blank\"><tt>astropy.utils.data.download_file</tt></a> to download the transmission file from the <a href=\"http://svo2.cab.inta-csic.es/theory/fps/index.php?mode=voservice\">Spanish Virtual Observatory</a> filter database. These transmission functions include the effect of the CCD's quantum efficiency on the spectrum."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To construct a bandpass from a file, use `synphot.spectrum`'s <a href=\"https://synphot.readthedocs.io/en/latest/synphot/spectrum.html\">SpectralElement</a> with its <a href=\"https://synphot.readthedocs.io/en/latest/api/synphot.spectrum.SourceSpectrum.html#synphot.spectrum.SourceSpectrum.from_file\" target=\"_blank\">from_file</a> method:"
"To construct a bandpass from a file, use <tt>synphot.spectrum</tt>'s <a href=\"https://synphot.readthedocs.io/en/latest/synphot/spectrum.html\"><tt>SpectralElement</tt></a> with its <a href=\"https://synphot.readthedocs.io/en/latest/api/synphot.spectrum.SourceSpectrum.html#synphot.spectrum.SourceSpectrum.from_file\" target=\"_blank\"><tt>from_file</tt></a> method:"
]
},
{
"cell_type": "code",
"execution_count": 35,
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -249,7 +240,7 @@
},
{
"cell_type": "code",
"execution_count": 36,
"execution_count": 22,
"metadata": {},
"outputs": [
{
Expand All @@ -258,7 +249,7 @@
"(0, 0.5)"
]
},
"execution_count": 36,
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
},
Expand Down Expand Up @@ -303,12 +294,12 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"We can then model the observation by convolving the object's spectrum with the filter transmission functions using <a href=\"https://synphot.readthedocs.io/en/latest/synphot/observation.html\">`synphot.observation`</a>:"
"We can then model the observation by convolving the object's spectrum with the filter transmission functions using <a href=\"https://synphot.readthedocs.io/en/latest/synphot/observation.html\"><tt>synphot.observation</tt></a>:"
]
},
{
"cell_type": "code",
"execution_count": 37,
"execution_count": 23,
"metadata": {},
"outputs": [
{
Expand All @@ -329,12 +320,12 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"We can then use the `synphot.observation` method <a href=\"https://synphot.readthedocs.io/en/latest/api/synphot.observation.Observation.html?highlight=effstim#synphot.observation.Observation.effstim\" target=\"_blank\">`effstim`</a> to calculate the total flux obtained in each band. In order to compare our synthetic fluxes to those measured by SDSS, we need to convert the flux to units compatable with SDSS data. <a href=\"http://www.sdss3.org/dr8/algorithms/magnitudes.php#nmgy\" target=\"_blank\">SDSS uses nanomaggies as a flux unit</a>, which we can convert to with the `astropy.units` methods <a href=\"https://docs.astropy.org/en/stable/api/astropy.units.quantity.Quantity.html#astropy.units.quantity.Quantity.to\" target=\"_blank\">`to`</a> and <a href=\"https://docs.astropy.org/en/stable/api/astropy.units.photometric.zero_point_flux.html?highlight=zero%20point%20flux\" target=\"_blank\">`zero_point_flux`</a> given the zero point of this magnitude scale (3631.1 Jy):"
"We can then use the <tt>synphot.observation</tt> method <a href=\"https://synphot.readthedocs.io/en/latest/api/synphot.observation.Observation.html?highlight=effstim#synphot.observation.Observation.effstim\" target=\"_blank\"><tt>effstim</tt></a> to calculate the total flux obtained in each band. In order to compare our synthetic fluxes to those measured by SDSS, we need to convert the flux to units compatable with SDSS data. <a href=\"http://www.sdss3.org/dr8/algorithms/magnitudes.php#nmgy\" target=\"_blank\">SDSS uses nanomaggies as a flux unit</a>, which we can convert to with the <tt>astropy.units</tt> methods <a href=\"https://docs.astropy.org/en/stable/api/astropy.units.quantity.Quantity.html#astropy.units.quantity.Quantity.to\" target=\"_blank\"><tt>to</tt></a> and <a href=\"https://docs.astropy.org/en/stable/api/astropy.units.photometric.zero_point_flux.html?highlight=zero%20point%20flux\" target=\"_blank\"><tt>zero_point_flux</tt></a> given the zero point of this magnitude scale (3631.1 Jy):"
]
},
{
"cell_type": "code",
"execution_count": 38,
"execution_count": 24,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -362,19 +353,19 @@
"metadata": {},
"source": [
"<a id=\"compare\"></a>\n",
"### 5. How well does `synphot` do?"
"### 5. How well does <tt>synphot</tt> do?"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To compare the g,r,i empirical fluxes to what we predict with `synphot`, we first get the fluxes measured by the SDSS fibers by using <a href=\"https://astroquery.readthedocs.io/en/latest/api/astroquery.sdss.SDSSClass.html#astroquery.sdss.SDSSClass.query_crossid\">`astroquery.sdss.query_crossid`</a> and setting the photoObj to \"fiberFlux_band\". For a full list of photoObj fields, <a href=\"https://skyserver.sdss.org/dr12/en/help/browser/browser.aspx?cmd=description+PhotoObj+V#&&history=description+PhotoObj+V\">see here</a>."
"To compare the g,r,i empirical fluxes to what we predict with <tt>synphot</tt>, we first get the fluxes measured by the SDSS fibers by using <a href=\"https://astroquery.readthedocs.io/en/latest/api/astroquery.sdss.SDSSClass.html#astroquery.sdss.SDSSClass.query_crossid\"><tt>astroquery.sdss.query_crossid</tt></a> and setting the photoObj to \"fiberFlux_band\". For a full list of photoObj fields, <a href=\"https://skyserver.sdss.org/dr12/en/help/browser/browser.aspx?cmd=description+PhotoObj+V#&&history=description+PhotoObj+V\">see here</a>."
]
},
{
"cell_type": "code",
"execution_count": 39,
"execution_count": 25,
"metadata": {},
"outputs": [
{
Expand All @@ -397,7 +388,7 @@
},
{
"cell_type": "code",
"execution_count": 40,
"execution_count": 26,
"metadata": {},
"outputs": [
{
Expand All @@ -408,7 +399,7 @@
" 'i': <Quantity [294.157] nmgy>}"
]
},
"execution_count": 40,
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -421,21 +412,21 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Compare the `synphot` fluxes to the observed fluxes by plotting on a 1-1 line:"
"Compare the <tt>synphot</tt> fluxes to the observed fluxes by plotting on a 1-1 line:"
]
},
{
"cell_type": "code",
"execution_count": 41,
"execution_count": 27,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.legend.Legend at 0xb21695320>"
"<matplotlib.legend.Legend at 0xb1afaad30>"
]
},
"execution_count": 41,
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
},
Expand Down
69 changes: 69 additions & 0 deletions tutorials/notebooks/synphot-model-spec/ccd_QE.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
100, 0.0, 0, 0
309.4560021465238, 70.30747424892068, 16, 40
319.539015188068, 73.11442326755378, 14, 30.35714285714286
329.9917387078021, 75.26541144025542, 15, 35.46666666666667
339.70504127115635, 76.58538173145493, 14, 30.35714285714286
349.7880543127005, 74.70200948669466, 10, 16.1
379.53294278525584, 77.10351031374742, 12, 23.66666666666667
390.00376402070555, 81.79762370567437, 13, 26.153846153846164
399.57293120532483, 84.52897199856781, 16, 41.1875
409.3114413012829, 87.18136275806562, 15, 35.46666666666667
419.59611460365807, 89.04058920481614, 15, 36.26666666666667
429.14136694965316, 91.16038905508852, 10, 17.700000000000003
439.5268703824437, 92.49142617037583, 12, 23
449.97959390217784, 93.66048522401442, 15, 35.46666666666667
459.69289646553193, 94.87582372383835, 14, 30.35714285714285
469.6078592897171, 95.64295584810637, 12, 23.58333333333333
479.8589225486203, 96.56602958452065, 14, 30.35714285714285
489.5638226011066, 97.20551595368505, 16, 41.1875
499.5983596184127, 98.01709917645256, 13, 28.615384615384617
509.9916192150812, 98.32588678561568, 13, 26.153846153846157
519.5607863997005, 98.26189461661147, 16, 41.1875
529.3044672715774, 98.79719418907516, 13, 26.92307692307692
539.8528501458082, 99.10133837554409, 14, 32.85714285714285
549.5997627526343, 99.09379281366604, 12, 22.916666666666668
559.5147255768194, 99.35788747939766, 12, 22
569.9467659928786, 99.30100555139393, 13, 28.000000000000014
579.6807516599077, 99.14661174681237, 12, 22
589.5957144840928, 98.81209183688566, 12, 23.58333333333333
599.9631202011678, 98.74843825078625, 13, 26.153846153846157
609.5600803063503, 98.30855134089073, 15, 35.46666666666667
619.6526962174579, 98.04495971261765, 14, 32.57142857142856
630.0958168676286, 97.9845952175933, 16, 40
639.6746792570956, 97.24513015354478, 16, 40
649.5056169726012, 96.85779131047175, 12, 22.91666666666666
659.840705340184, 96.40002722320364, 16, 40
669.7685951041659, 96.0343576860368, 13, 28.000000000000014
679.5025807711951, 95.87183789174043, 12, 23
689.9637068017972, 95.09275862783217, 16, 41.1875
699.7849493124552, 94.89671912596216, 13, 26.15384615384616
709.5355553306517, 94.49854562993605, 14, 30.357142857142854
719.8346329373718, 94.12126753603376, 14, 30.35714285714285
729.728589484387, 93.52139536672911, 16, 41.1875
739.8843165622885, 92.57268606752402, 13, 26.153846153846164
749.9673296038327, 91.77633907547178, 13, 26.153846153846157
759.6625344514713, 90.30410093890463, 17, 45.88235294117648
769.5904242154533, 88.68846298384065, 13, 29.692307692307693
780.3785430640984, 86.74856762101211, 11, 20.36363636363637
789.5964794185556, 84.85909033073233, 16, 41.1875
799.6067784237425, 82.8540023686008, 13, 26.153846153846164
810.0775996591923, 80.76562301189239, 16, 40
819.6564620486593, 78.18504084960068, 14, 30.35714285714286
829.5234105250274, 75.90628116243079, 14, 30.357142857142854
839.8224881317476, 72.63150730735885, 16, 40
849.6894366081158, 68.93418198711632, 14, 30.357142857142854
859.77244964966, 65.34249453316644, 14, 30.357142857142854
870.0715272563801, 61.79608045048484, 14, 30.35714285714286
879.7176097327907, 58.137992052008144, 15, 36.533333333333346
889.8109643261723, 54.49429826388342, 13, 28.61538461538462
899.9424533919547, 49.879751854580746, 16, 41.1875
909.7313785531205, 45.18326838232029, 12, 24.583333333333332
919.6943557251225, 41.57397461732164, 14, 32.857142857142854
930.065454853568, 36.82027063415269, 16, 40
939.644317243035, 32.80603171503223, 12, 22
949.7273302845791, 28.791792795911775, 12, 22
959.9586229296754, 25.094467475669248, 17, 45.882352941176464
969.6772918024916, 21.397142155426735, 14, 30.357142857142854
979.7603048440358, 18.43928189923271, 14, 30.357142857142854
990.0593824507558, 14.892867816551103, 14, 30.35714285714286
1100.0, 0.0, 0, 0
Empty file.
Loading

0 comments on commit c3c4c8a

Please sign in to comment.