Skip to content

Commit 807645d

Browse files
committed
Added another tutorial, "synphot-model-spec"
1 parent f2cfd5a commit 807645d

File tree

5 files changed

+1303
-38
lines changed

5 files changed

+1303
-38
lines changed

tutorials/notebooks/synphot-measured-spec/synphot-measured-spec.ipynb

+29-38
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"metadata": {},
4343
"source": [
4444
"## Summary\n",
45-
"<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",
45+
"<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",
4646
"<ol>\n",
4747
"<li><a href=\"#sdss\">Get the observed spectrum of our target from SDSS</a></li>\n",
4848
"<li><a href=\"#source_spectrum\">Construct a source spectrum object</a></li>\n",
@@ -54,7 +54,7 @@
5454
},
5555
{
5656
"cell_type": "code",
57-
"execution_count": 47,
57+
"execution_count": 16,
5858
"metadata": {},
5959
"outputs": [],
6060
"source": [
@@ -93,12 +93,12 @@
9393
"cell_type": "markdown",
9494
"metadata": {},
9595
"source": [
96-
"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>:"
96+
"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>:"
9797
]
9898
},
9999
{
100100
"cell_type": "code",
101-
"execution_count": 31,
101+
"execution_count": 17,
102102
"metadata": {},
103103
"outputs": [],
104104
"source": [
@@ -111,23 +111,14 @@
111111
"cell_type": "markdown",
112112
"metadata": {},
113113
"source": [
114-
"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:"
114+
"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:"
115115
]
116116
},
117117
{
118118
"cell_type": "code",
119-
"execution_count": 32,
119+
"execution_count": 18,
120120
"metadata": {},
121-
"outputs": [
122-
{
123-
"name": "stderr",
124-
"output_type": "stream",
125-
"text": [
126-
"/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",
127-
" comments='#'))\n"
128-
]
129-
}
130-
],
121+
"outputs": [],
131122
"source": [
132123
"spectrum_fits = SDSS.get_spectra(coordinates=coords)\n",
133124
"data = spectrum_fits[0][1].data"
@@ -142,7 +133,7 @@
142133
},
143134
{
144135
"cell_type": "code",
145-
"execution_count": 33,
136+
"execution_count": 19,
146137
"metadata": {},
147138
"outputs": [],
148139
"source": [
@@ -162,12 +153,12 @@
162153
"cell_type": "markdown",
163154
"metadata": {},
164155
"source": [
165-
"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>):"
156+
"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>):"
166157
]
167158
},
168159
{
169160
"cell_type": "code",
170-
"execution_count": 34,
161+
"execution_count": 20,
171162
"metadata": {},
172163
"outputs": [
173164
{
@@ -202,26 +193,26 @@
202193
"cell_type": "markdown",
203194
"metadata": {},
204195
"source": [
205-
"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`."
196+
"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>."
206197
]
207198
},
208199
{
209200
"cell_type": "markdown",
210201
"metadata": {},
211202
"source": [
212-
"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."
203+
"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."
213204
]
214205
},
215206
{
216207
"cell_type": "markdown",
217208
"metadata": {},
218209
"source": [
219-
"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:"
210+
"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:"
220211
]
221212
},
222213
{
223214
"cell_type": "code",
224-
"execution_count": 35,
215+
"execution_count": 21,
225216
"metadata": {},
226217
"outputs": [],
227218
"source": [
@@ -249,7 +240,7 @@
249240
},
250241
{
251242
"cell_type": "code",
252-
"execution_count": 36,
243+
"execution_count": 22,
253244
"metadata": {},
254245
"outputs": [
255246
{
@@ -258,7 +249,7 @@
258249
"(0, 0.5)"
259250
]
260251
},
261-
"execution_count": 36,
252+
"execution_count": 22,
262253
"metadata": {},
263254
"output_type": "execute_result"
264255
},
@@ -303,12 +294,12 @@
303294
"cell_type": "markdown",
304295
"metadata": {},
305296
"source": [
306-
"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>:"
297+
"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>:"
307298
]
308299
},
309300
{
310301
"cell_type": "code",
311-
"execution_count": 37,
302+
"execution_count": 23,
312303
"metadata": {},
313304
"outputs": [
314305
{
@@ -329,12 +320,12 @@
329320
"cell_type": "markdown",
330321
"metadata": {},
331322
"source": [
332-
"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):"
323+
"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):"
333324
]
334325
},
335326
{
336327
"cell_type": "code",
337-
"execution_count": 38,
328+
"execution_count": 24,
338329
"metadata": {},
339330
"outputs": [
340331
{
@@ -362,19 +353,19 @@
362353
"metadata": {},
363354
"source": [
364355
"<a id=\"compare\"></a>\n",
365-
"### 5. How well does `synphot` do?"
356+
"### 5. How well does <tt>synphot</tt> do?"
366357
]
367358
},
368359
{
369360
"cell_type": "markdown",
370361
"metadata": {},
371362
"source": [
372-
"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>."
363+
"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>."
373364
]
374365
},
375366
{
376367
"cell_type": "code",
377-
"execution_count": 39,
368+
"execution_count": 25,
378369
"metadata": {},
379370
"outputs": [
380371
{
@@ -397,7 +388,7 @@
397388
},
398389
{
399390
"cell_type": "code",
400-
"execution_count": 40,
391+
"execution_count": 26,
401392
"metadata": {},
402393
"outputs": [
403394
{
@@ -408,7 +399,7 @@
408399
" 'i': <Quantity [294.157] nmgy>}"
409400
]
410401
},
411-
"execution_count": 40,
402+
"execution_count": 26,
412403
"metadata": {},
413404
"output_type": "execute_result"
414405
}
@@ -421,21 +412,21 @@
421412
"cell_type": "markdown",
422413
"metadata": {},
423414
"source": [
424-
"Compare the `synphot` fluxes to the observed fluxes by plotting on a 1-1 line:"
415+
"Compare the <tt>synphot</tt> fluxes to the observed fluxes by plotting on a 1-1 line:"
425416
]
426417
},
427418
{
428419
"cell_type": "code",
429-
"execution_count": 41,
420+
"execution_count": 27,
430421
"metadata": {},
431422
"outputs": [
432423
{
433424
"data": {
434425
"text/plain": [
435-
"<matplotlib.legend.Legend at 0xb21695320>"
426+
"<matplotlib.legend.Legend at 0xb1afaad30>"
436427
]
437428
},
438-
"execution_count": 41,
429+
"execution_count": 27,
439430
"metadata": {},
440431
"output_type": "execute_result"
441432
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
100, 0.0, 0, 0
2+
309.4560021465238, 70.30747424892068, 16, 40
3+
319.539015188068, 73.11442326755378, 14, 30.35714285714286
4+
329.9917387078021, 75.26541144025542, 15, 35.46666666666667
5+
339.70504127115635, 76.58538173145493, 14, 30.35714285714286
6+
349.7880543127005, 74.70200948669466, 10, 16.1
7+
379.53294278525584, 77.10351031374742, 12, 23.66666666666667
8+
390.00376402070555, 81.79762370567437, 13, 26.153846153846164
9+
399.57293120532483, 84.52897199856781, 16, 41.1875
10+
409.3114413012829, 87.18136275806562, 15, 35.46666666666667
11+
419.59611460365807, 89.04058920481614, 15, 36.26666666666667
12+
429.14136694965316, 91.16038905508852, 10, 17.700000000000003
13+
439.5268703824437, 92.49142617037583, 12, 23
14+
449.97959390217784, 93.66048522401442, 15, 35.46666666666667
15+
459.69289646553193, 94.87582372383835, 14, 30.35714285714285
16+
469.6078592897171, 95.64295584810637, 12, 23.58333333333333
17+
479.8589225486203, 96.56602958452065, 14, 30.35714285714285
18+
489.5638226011066, 97.20551595368505, 16, 41.1875
19+
499.5983596184127, 98.01709917645256, 13, 28.615384615384617
20+
509.9916192150812, 98.32588678561568, 13, 26.153846153846157
21+
519.5607863997005, 98.26189461661147, 16, 41.1875
22+
529.3044672715774, 98.79719418907516, 13, 26.92307692307692
23+
539.8528501458082, 99.10133837554409, 14, 32.85714285714285
24+
549.5997627526343, 99.09379281366604, 12, 22.916666666666668
25+
559.5147255768194, 99.35788747939766, 12, 22
26+
569.9467659928786, 99.30100555139393, 13, 28.000000000000014
27+
579.6807516599077, 99.14661174681237, 12, 22
28+
589.5957144840928, 98.81209183688566, 12, 23.58333333333333
29+
599.9631202011678, 98.74843825078625, 13, 26.153846153846157
30+
609.5600803063503, 98.30855134089073, 15, 35.46666666666667
31+
619.6526962174579, 98.04495971261765, 14, 32.57142857142856
32+
630.0958168676286, 97.9845952175933, 16, 40
33+
639.6746792570956, 97.24513015354478, 16, 40
34+
649.5056169726012, 96.85779131047175, 12, 22.91666666666666
35+
659.840705340184, 96.40002722320364, 16, 40
36+
669.7685951041659, 96.0343576860368, 13, 28.000000000000014
37+
679.5025807711951, 95.87183789174043, 12, 23
38+
689.9637068017972, 95.09275862783217, 16, 41.1875
39+
699.7849493124552, 94.89671912596216, 13, 26.15384615384616
40+
709.5355553306517, 94.49854562993605, 14, 30.357142857142854
41+
719.8346329373718, 94.12126753603376, 14, 30.35714285714285
42+
729.728589484387, 93.52139536672911, 16, 41.1875
43+
739.8843165622885, 92.57268606752402, 13, 26.153846153846164
44+
749.9673296038327, 91.77633907547178, 13, 26.153846153846157
45+
759.6625344514713, 90.30410093890463, 17, 45.88235294117648
46+
769.5904242154533, 88.68846298384065, 13, 29.692307692307693
47+
780.3785430640984, 86.74856762101211, 11, 20.36363636363637
48+
789.5964794185556, 84.85909033073233, 16, 41.1875
49+
799.6067784237425, 82.8540023686008, 13, 26.153846153846164
50+
810.0775996591923, 80.76562301189239, 16, 40
51+
819.6564620486593, 78.18504084960068, 14, 30.35714285714286
52+
829.5234105250274, 75.90628116243079, 14, 30.357142857142854
53+
839.8224881317476, 72.63150730735885, 16, 40
54+
849.6894366081158, 68.93418198711632, 14, 30.357142857142854
55+
859.77244964966, 65.34249453316644, 14, 30.357142857142854
56+
870.0715272563801, 61.79608045048484, 14, 30.35714285714286
57+
879.7176097327907, 58.137992052008144, 15, 36.533333333333346
58+
889.8109643261723, 54.49429826388342, 13, 28.61538461538462
59+
899.9424533919547, 49.879751854580746, 16, 41.1875
60+
909.7313785531205, 45.18326838232029, 12, 24.583333333333332
61+
919.6943557251225, 41.57397461732164, 14, 32.857142857142854
62+
930.065454853568, 36.82027063415269, 16, 40
63+
939.644317243035, 32.80603171503223, 12, 22
64+
949.7273302845791, 28.791792795911775, 12, 22
65+
959.9586229296754, 25.094467475669248, 17, 45.882352941176464
66+
969.6772918024916, 21.397142155426735, 14, 30.357142857142854
67+
979.7603048440358, 18.43928189923271, 14, 30.357142857142854
68+
990.0593824507558, 14.892867816551103, 14, 30.35714285714286
69+
1100.0, 0.0, 0, 0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
synphot
2+
matplotlib
3+
numpy
4+
astropy
5+
astroquery

0 commit comments

Comments
 (0)