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

New tutorials: Using synphot for synthetic photometry #384

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
69 changes: 69 additions & 0 deletions tutorials/synphot/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
5 changes: 5 additions & 0 deletions tutorials/synphot/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
synphot
astropy
astroquery
numpy
matplotlib
202 changes: 202 additions & 0 deletions tutorials/synphot/skymodel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
import os
import json
import requests

import astropy.units as u
from astropy.io import fits


def get_atmospheric_transmittance(airmass=1.0, pwv_mode='pwv', season=0,
time=0, pwv=3.5, msolflux=130.0,
incl_moon='Y', moon_sun_sep=90.0,
moon_target_sep=45.0, moon_alt=45.0,
moon_earth_dist=1.0, incl_starlight='Y',
incl_zodiacal='Y',
ecl_lon=135.0, ecl_lat=90.0,
incl_loweratm='Y', incl_upperatm='Y',
incl_airglow='Y', incl_therm='N',
therm_t1=0.0, therm_e1=0.0,
therm_t2=0.0, therm_e2=0.0, therm_t3=0.0,
therm_e3=0.0, vacair='vac', wmin=300.0,
wmax=2000.0,
wgrid_mode='fixed_wavelength_step',
wdelta=0.1, wres=20000, lsf_type='none',
lsf_gauss_fwhm=5.0, lsf_boxcar_fwhm=5.0,
observatory='paranal'):
"""
Returns the model atmospheric transmittance curve queried from the SkyCalc
Sky Model Calculator. The default parameters used here are the default
parameters provided by SkyCalc:
http://www.eso.org/observing/etc/doc/skycalc/skycalc_defaults.txt

Parameters
----------
airmass: float (range [1.0,3.0])
Airmass. Alt and airmass are coupled through the plane parallel
approximation airmass=sec(z), z being the zenith distance
z=90°−Alt
pwv_mode: str
options: ['pwv','season'] (default is 'pwv')
season: int
Time of year if not in pwv mode.
options: [0,1,2,3,4,5,6] (default is 0)
(0 = all year, 1 = dec/jan, 2 = feb/mar...)
time: int
Period of night. options: [0,1,2,3] (default is 0)
(0 = all year, 1, 2, 3 = third of night)
pwv: float
Precipitable Water Vapor (default is 3.5).
options: [-1.0,0.5,1.0,1.5,2.5,3.5,5.0,7.5,10.0,20.0]
msolflux: float
Monthly Averaged Solar Flux, s.f.u float > 0 (default is 130.0)
incl_moon: str
Flag for inclusion of scattered moonlight. options = ['Y', 'N']
(default is 'Y')
Moon coordinate constraints: |z – zmoon| ≤ ρ ≤ |z + zmoon| where
ρ=moon/target separation, z=90°−target altitude and
zmoon=90°−moon altitude.
moon_sun_sep: float
Degrees of separation between Sun and Moon as seen from Earth
(i.e. the "moon phase").
options: [0.0,360.0] (default is 90.0)
moon_target_sep: float
Moon-Target Separation ( ρ )
Degrees in range [0.0,180.0] (defualt is 45.0)
# degrees float range [-90.0,90.0] Moon Altitude over Horizon
moon_alt: float
Moon Altitude over Horizon. Degrees in range [-90.0,90.0]
(default is 45.0)
moon_earth_dist: float
Moon-Earth Distance (mean=1) in range [0.91,1.08]
(default is 1.0)
incl_starlight: str
Flag for inclusion of scattered starlight.
options: ['Y', 'N'] (default is 'Y')
incl_zodiacal: str
Flag for inclusion of zodiacal light.
options: ['Y', 'N'] (default is 'Y')
ecl_lon: float
Heliocentric ecliptic in degree range [-180.0,180.0].
(default is 135.0)
ecl_lat: float
Ecliptic latitude in degree range [-90.0,90.0].
(default is 90.0)

incl_loweratm: str
Flag for inclusion of molecular emission of lower atmosphere.
options: ['Y', 'N'] (default is 'Y')
incl_upperatm: str
Flag for inclusion of molecular emission of upper atmosphere.
options: ['Y', 'N'] (default is 'Y')
incl_airglow: str
Flag for inclusion of airglow continuum (residual continuum)
options: ['Y', 'N'] (default is 'Y')

incl_therm: str
Flag for inclusion of instrumental thermal radiation.
options: ['Y', 'N'] (default is 'N')
Note: This radiance component represents an instrumental effect.
The emission is provided relative to the other model components.
To obtain the correct absolute flux, an instrumental response curve
must be applied to the resulting model spectrum.
See section 6.2.4 in the SkyCalc documentation at
http://localhost/observing/etc/doc/skycalc/
The_Cerro_Paranal_Advanced_Sky_Model.pdf
therm_t1, therm_t2, therm_t3 : float
Temperature in K (default is 0.0)
therm_e1, therm_e2, therm_e3: float
In range [0,1] (default is 0.0)

vacair: str
In regards to the wavelength grid.
options: ['vac', 'air] (default is 'vac')
wmin: float
Minimum wavelength (nm) in the wavelength grid.
Must be in range [300.0,30000.0] and < wmax
(default is 300.0)
wmax: float
Maximum wavelength (nm) in the wavelength grid.
Must be in range [300.0,30000.0] and > wmin
(default is 2000.0)
wgrid_mode: str
Mode of the wavelength grid.
options: ['fixed_spectral_resolution','fixed_wavelength_step', 'user']
(default is 'fixed_wavelength_step')
wdelta: float
Wavelength sampling step dlam in range [0,30000.0] (nm/step)
(default is 0.1)
wres: int
lam/dlam where dlam is wavelength step.
In range [0,1.0e6] (default is 20000)
wgrid_user: list of floats
default is [500.0, 510.0, 520.0, 530.0, 540.0, 550.0]

lsf_type: str
Line spread function type for convolution.
options: ['none','Gaussian','Boxcar'] (default is 'none')
lsf_gauss_fwhm: float
Gaussian full-width half-max for line spread function wavelength bins.
Range > 0.0 (default is 5.0)
lsf_boxcar_fwhm: float
Boxcar full-width half-max for line spread function wavelength bins.
Range > 0.0 (default is 5.0)

observatory: str
Observatory where observation takes place.
Options are 'paranal', 'lasilla', 'armazones' (default is 'paranal')

Returns
-------
trans_waves, transmission: tuple of arrays of floats
'trans_waves' is an array of wavelengths in angstroms (float),
'transmission' is an array of fractional atmospheric
transmittance (float).

"""

params = locals()

if params['observatory'] == 'lasilla':
params['observatory'] = '2400'
elif params['observatory'] == 'paranal':
params['observatory'] = '2640'
elif (params['observatory'] == '3060m' or
params['observatory'] == 'armazones'):
params['observatory'] = '3060'
else:
raise ValueError('Wrong Observatory name, please refer to the '
'skycalc_cli documentation.')

# Use the bit from skycalc_cli which queries from the SkyCalc Sky Model
server = 'http://etimecalret-001.eso.org'
url = server + '/observing/etc/api/skycalc'
response = requests.post(url, data=json.dumps(params))
results = json.loads(response.text)

status = results['status']
tmpdir = results['tmpdir']
tmpurl = server + '/observing/etc/tmp/' + tmpdir + '/skytable.fits'

if status == 'success':
try:
response = requests.get(tmpurl, stream=True)
data = response.content
except requests.exceptions.RequestException as e:
print(e, 'could not retrieve FITS data from server')
else:
print('HTML request failed', results)

# Create a temporary file to write the binary results to
tmp_data_file = './tmp_skycalc_data.fits'

with open(tmp_data_file, 'wb') as f:
f.write(data)

hdu = fits.open(tmp_data_file)
trans_waves = hdu[1].data["LAM"] * u.um # wavelengths
transmission = hdu[1].data["TRANS"]

# Delete the file after reading from it
os.remove(tmp_data_file)

return trans_waves.to(u.angstrom), transmission
Loading