From 5e431d4f707b54bedfa03dcdcadd57e9d0067a24 Mon Sep 17 00:00:00 2001 From: Wenke Date: Wed, 10 Jul 2024 18:09:28 +0900 Subject: [PATCH] Fixed an unexpected error when dealing with high-z quasar in AGN-host decomposition procedure. --- src/pyqsofit/HostDecomp.py | 6 ++++++ src/pyqsofit/PyQSOFit.py | 12 +++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/pyqsofit/HostDecomp.py b/src/pyqsofit/HostDecomp.py index 6314ee8..a4ca7a8 100644 --- a/src/pyqsofit/HostDecomp.py +++ b/src/pyqsofit/HostDecomp.py @@ -296,6 +296,9 @@ def __init__(self, wave, flux, err, n_gal, n_qso, path, host_type='PCA', qso_typ wave_min = np.max([np.min(wave), np.min(self.qso_tmp.wave_qso), np.min(self.gal_tmp.wave_gal)]) wave_max = np.min([np.max(wave), np.max(self.qso_tmp.wave_qso), np.max(self.gal_tmp.wave_gal)]) ind_data = np.where((wave > wave_min) & (wave < wave_max), True, False) + if np.sum(ind_data)/len(ind_data) < 0.5: + raise ValueError('The templates used for decomposition can only cover less than 50% of the original data. ' + 'Please check the settings and consider close the decomposition function.') self.wave, self.flux, self.err = wave[ind_data], flux[ind_data], err[ind_data] if na_mask == True: @@ -388,6 +391,9 @@ def __init__(self, wave, flux, err, n_gal, n_qso, path, host_type='PCA', qso_typ wave_min = np.max([np.min(wave), np.min(self.qso_tmp.wave_qso), np.min(self.gal_tmp.wave_gal)]) wave_max = np.min([np.max(wave), np.max(self.qso_tmp.wave_qso), np.max(self.gal_tmp.wave_gal)]) ind_data = np.where((wave > wave_min) & (wave < wave_max), True, False) + if np.sum(ind_data)/len(ind_data) < 0.5: + raise ValueError('The templates used for decomposition can only cover less than 50% of the original data. ' + 'Please check the settings and consider close the decomposition function.') self.wave, self.flux, self.err = wave[ind_data], flux[ind_data], err[ind_data] if na_mask == True: diff --git a/src/pyqsofit/PyQSOFit.py b/src/pyqsofit/PyQSOFit.py index 59635c6..35c523d 100644 --- a/src/pyqsofit/PyQSOFit.py +++ b/src/pyqsofit/PyQSOFit.py @@ -768,6 +768,13 @@ def _CalculateSN(self, wave, flux, alter=True): def decompose_host_qso(self, wave, flux, err, path): """Decompose the host galaxy from QSO""" + # Initialize default values + self.host = np.zeros(len(wave)) + self.decomposed = False + self.host_result = np.array([]) + self.host_result_type = np.array([]) + self.host_result_name = np.array([]) + if self.host_prior is True: prior_fitter = Prior_decomp(self.wave, self.flux, self.err, self.npca_gal, self.npca_qso, path, host_type=self.host_type, qso_type=self.qso_type, @@ -786,11 +793,6 @@ def decompose_host_qso(self, wave, flux, err, path): host_spec = datacube[1, :] - datacube[4, :] if np.sum(np.where(datacube[3, :] < 0, True, False) | np.where(datacube[4, :] < 0, True, False)) > 0.1 * \ datacube.shape[1] or np.median(datacube[3, :]) < 0.01 * flux_level or np.median(host_spec) < 0: - self.host = np.zeros(len(wave)) - self.decomposed = False - self.host_result = np.array([]) - self.host_result_type = np.array([]) - self.host_result_name = np.array([]) if self.verbose: print('Got negative host galaxy / QSO flux over 10% of coverage, decomposition is not applied!') else: