Skip to content

Commit

Permalink
corner-case crash: merging three or more patches
Browse files Browse the repository at this point in the history
  • Loading branch information
moustakas committed Oct 23, 2024
1 parent bdb92a5 commit d9ed1f0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
13 changes: 5 additions & 8 deletions py/fastspecfit/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -970,14 +970,11 @@ def one_spectrum(iobj, specdata, meta, ebv, fastphot,

# use the coadded spectrum to build a robust emission-line mask
LM = LineMasker(emline_table)
try:
pix = LM.build_linemask(
specdata['coadd_wave'], specdata['coadd_flux'],
specdata['coadd_ivar'], specdata['coadd_res'],
uniqueid=specdata['uniqueid'], redshift=specdata['redshift'],
debug_plots=debug_plots)
except:
raise ValueError('########### LINE-MASKING PROBLEM WITH ', specdata['uniqueid'])
pix = LM.build_linemask(
specdata['coadd_wave'], specdata['coadd_flux'],
specdata['coadd_ivar'], specdata['coadd_res'],
uniqueid=specdata['uniqueid'], redshift=specdata['redshift'],
debug_plots=debug_plots)

# Map the pixels belonging to individual emission lines onto the
# original per-camera spectra. This works, but maybe there's a better
Expand Down
10 changes: 6 additions & 4 deletions py/fastspecfit/linemasker.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def _get_contpix(zlinewaves, sigmas, nsigma_factor=2., linemask=None, lya=False)

pix = {'linepix': {}, 'contpix': {}}
if patchMap is not None:
pix.update({'patch_contpix': {}, 'dropped': [], 'merged': []})
pix.update({'patch_contpix': {}, 'dropped': [], 'merged': [], 'merged_from': []})
patchids = list(patchMap.keys())
npatch = len(patchids)

Expand Down Expand Up @@ -177,6 +177,7 @@ def _get_contpix(zlinewaves, sigmas, nsigma_factor=2., linemask=None, lya=False)
del pix['patch_contpix'][patchids[ipatch+1]]
pix['patch_contpix'][newpatchid] = newcontpix
pix['merged'].append(newpatchid)
pix['merged_from'].append([patchid, patchids[ipatch+1]])

if patchMap is not None:
if len(pix['dropped']) > 0:
Expand Down Expand Up @@ -298,8 +299,8 @@ def _fit_patches(continuum_patches, patchMap, linemodel, debug_plots=False,
# In the case that patches have been merged, update the
# continuum_patches table and patchMap dictionary.
if len(pix['merged']) > 0:
for newpatchid in np.atleast_1d(pix['merged']):
oldpatchids = list(newpatchid)
for oldpatchids, newpatchid in zip(np.atleast_1d(pix['merged_from']),
np.atleast_1d(pix['merged'])):
O = np.where(np.isin(continuum_patches['patchid'].value, oldpatchids))[0]

# update continuum_patches
Expand All @@ -316,6 +317,7 @@ def _fit_patches(continuum_patches, patchMap, linemodel, debug_plots=False,
newI.append(patchMap[oldpatchid][1])
newJ.append(patchMap[oldpatchid][2])
del patchMap[oldpatchid]

patchMap[newpatchid] = (np.hstack(newlines), np.hstack(newI), np.hstack(newJ))


Expand Down Expand Up @@ -549,7 +551,7 @@ def _niceline(line):
xx.set_ylim(ymin, ymax)
xx.legend(loc='upper left', fontsize=8, ncols=nlegcol)
xx.set_title(f'Patch {patchid}')
for rem in range(ipatch+1, ncols*nrowspatch):
for rem in range(ipatch+1, ncols*nrows):
ax.flat[rem].axis('off')

if ax.ndim == 1:
Expand Down
2 changes: 1 addition & 1 deletion py/fastspecfit/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
This needs to be in its own file to prevent circular imports with other code.
"""
from desiutil.log import get_logger
from desiutil.log import get_logger, DEBUG

log = get_logger()

0 comments on commit d9ed1f0

Please sign in to comment.