Skip to content

Commit

Permalink
Fixed an unexpected error when dealing with high-z quasar in AGN-host…
Browse files Browse the repository at this point in the history
… decomposition procedure.
  • Loading branch information
WenkeRen committed Jul 10, 2024
1 parent 9e790d3 commit 5e431d4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/pyqsofit/HostDecomp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
12 changes: 7 additions & 5 deletions src/pyqsofit/PyQSOFit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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:
Expand Down

0 comments on commit 5e431d4

Please sign in to comment.