From afd94c940a809c43d6463e83f809f3c66d29b797 Mon Sep 17 00:00:00 2001 From: Tomas Stolker Date: Tue, 13 Apr 2021 13:33:03 +0200 Subject: [PATCH] Set detector type of filter to photon counting if not found in the SVO header --- species/analysis/emission_line.py | 7 ++++--- species/analysis/photometry.py | 2 +- species/data/filters.py | 24 +++++++++++++++--------- species/read/read_model.py | 5 +++++ 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/species/analysis/emission_line.py b/species/analysis/emission_line.py index aa634b94..5f56e41a 100644 --- a/species/analysis/emission_line.py +++ b/species/analysis/emission_line.py @@ -209,9 +209,10 @@ def fit_gaussian(self, Minimum number of live points (see https://johannesbuchner.github.io/UltraNest/issues.html). bounds : dict(str, tuple(float, float)), None - The boundaries that are used for the uniform priors. Conservative prior boundaries will - be estimated from the spectrum if the argument is set to ``None`` or if any of the - required parameters is missing in the ``bounds`` dictionary. + The boundaries that are used for the uniform priors of the 3 Gaussian parameters + (``gauss_amplitude``, ``gauss_mean``, and ``gauss_sigma``). Conservative prior + boundaries will be estimated from the spectrum if the argument is set to ``None`` + or if any of the required parameters is missing in the ``bounds`` dictionary. output : str Path that is used for the output files from ``UltraNest``. plot_filename : str diff --git a/species/analysis/photometry.py b/species/analysis/photometry.py index 5d199224..a03b0ba4 100644 --- a/species/analysis/photometry.py +++ b/species/analysis/photometry.py @@ -200,7 +200,7 @@ def spectrum_to_flux(self, integrand1 = transmission[indices]*flux[indices] integrand2 = transmission[indices] - if self.det_type == 'photon': + elif self.det_type == 'photon': # Photon counting detector integrand1 = wavelength[indices]*transmission[indices]*flux[indices] integrand2 = wavelength[indices]*transmission[indices] diff --git a/species/data/filters.py b/species/data/filters.py index e76742bd..28c164ca 100644 --- a/species/data/filters.py +++ b/species/data/filters.py @@ -3,14 +3,14 @@ """ import os -import warnings import urllib.request +import warnings from typing import Optional, Tuple -from astropy.io.votable import parse_single_table import numpy as np +from astropy.io.votable import parse_single_table from typeguard import typechecked @@ -44,7 +44,7 @@ def download_filter(filter_id: str) -> Tuple[Optional[np.ndarray], wavelength, transmission, _, _ = np.loadtxt('VisAO_rp_filter_curve.dat', unpack=True) # Not sure if energy- or photon-counting detector - det_type = 'energy' + det_type = 'photon' os.remove('VisAO_rp_filter_curve.dat') @@ -55,7 +55,7 @@ def download_filter(filter_id: str) -> Tuple[Optional[np.ndarray], wavelength, transmission, _, _ = np.loadtxt('VisAO_ip_filter_curve.dat', unpack=True) # Not sure if energy- or photon-counting detector - det_type = 'energy' + det_type = 'photon' os.remove('VisAO_ip_filter_curve.dat') @@ -66,11 +66,11 @@ def download_filter(filter_id: str) -> Tuple[Optional[np.ndarray], wavelength, transmission, _, _ = np.loadtxt('VisAO_zp_filter_curve.dat', unpack=True) # Not sure if energy- or photon-counting detector - det_type = 'energy' + det_type = 'photon' os.remove('VisAO_zp_filter_curve.dat') - elif filter_id == 'LCO/VisAO.Ys' or filter_id == 'Magellan/VisAO.Ys': + elif filter_id in ['LCO/VisAO.Ys', 'Magellan/VisAO.Ys']: url = 'https://xwcl.science/magao/visao/VisAO_Ys_filter_curve.dat' urllib.request.urlretrieve(url, 'VisAO_Ys_filter_curve.dat') @@ -81,7 +81,7 @@ def download_filter(filter_id: str) -> Tuple[Optional[np.ndarray], transmission = transmission[:-7] # Not sure if energy- or photon-counting detector - det_type = 'energy' + det_type = 'photon' os.remove('VisAO_Ys_filter_curve.dat') @@ -91,7 +91,7 @@ def download_filter(filter_id: str) -> Tuple[Optional[np.ndarray], wavelength, transmission = np.loadtxt('alma_band6.dat', unpack=True) - det_type = 'energy' + det_type = 'photon' os.remove('alma_band6.dat') @@ -101,7 +101,7 @@ def download_filter(filter_id: str) -> Tuple[Optional[np.ndarray], wavelength, transmission = np.loadtxt('alma_band7.dat', unpack=True) - det_type = 'energy' + det_type = 'photon' os.remove('alma_band7.dat') @@ -144,6 +144,12 @@ def download_filter(filter_id: str) -> Tuple[Optional[np.ndarray], elif int(det_type) == 1: det_type = 'photon' + else: + det_type = 'photon' + + warnings.warn(f'Detector type ({det_type}) not recognized. Setting detector type ' + f'to photon-counting detector.') + wavelength *= 1e-4 # (um) os.remove('filter.xml') diff --git a/species/read/read_model.py b/species/read/read_model.py index 5ab70c57..f58ea918 100644 --- a/species/read/read_model.py +++ b/species/read/read_model.py @@ -62,7 +62,12 @@ def __init__(self, if self.filter_name is not None: transmission = read_filter.ReadFilter(self.filter_name) + self.wavel_range = transmission.wavelength_range() + self.mean_wavelength = transmission.mean_wavelength() + + else: + self.mean_wavelength = None config_file = os.path.join(os.getcwd(), 'species_config.ini')