Skip to content

Commit

Permalink
Merge branch 'tickets/PIPE2D-1475'
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertLuptonTheGood committed Jun 19, 2024
2 parents 7cc4efc + e6252cd commit a2cd593
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion python/pfs/drp/stella/coaddSpectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,38 @@
__all__ = ("CoaddSpectraConfig", "CoaddSpectraTask")


class SetWithNaN:
"""A subset of set which includes at most one NaN, despite the fact that NaN != NaN"""

def __init__(self, iterable):
"""Construct a set from iterable with at most one NaN"""
self.__set = set()
sawNaN = False

for x in iterable:
if np.isnan(x):
if not sawNaN:
self.__set.add(x)
sawNaN = True
else:
self.add(x)

def add(self, val):
if np.isnan(val) and np.isnan(list(self)).any():
return

self.__set.add(val)

def __len__(self):
return self.__set.__len__()

def __repr__(self):
return self.__set.__repr__()

def pop(self):
return self.__set.pop()


class CoaddSpectraConnections(
PipelineTaskConnections,
dimensions=("instrument", "skymap", "tract", "patch"),
Expand Down Expand Up @@ -289,7 +321,7 @@ def getTarget(self, target: Target, pfsConfigList: List[PfsConfig]) -> Target:
for ff, flux in zip(pfsConfig.filterNames[0], pfsConfig.fiberFlux[0]):
fiberFlux[ff].append(flux)
for ff in fiberFlux:
flux = set(fiberFlux[ff])
flux = SetWithNaN(fiberFlux[ff])
if len(flux) > 1:
self.log.warn("Multiple %s flux for target %s (%s); using average" % (ff, target, flux))
flux = np.average(np.array(fiberFlux[ff]))
Expand Down

0 comments on commit a2cd593

Please sign in to comment.