Skip to content

Commit

Permalink
Replace hasattr calls with single isinstance check.
Browse files Browse the repository at this point in the history
  • Loading branch information
edennihy committed Oct 10, 2023
1 parent 1080ad2 commit ebaca9c
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions python/lsst/obs/lsst/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,36 +346,32 @@ def addFilter(filter_dict, band, physical_filter):
if filter.physical_filter == "diffuser":
continue

# The SDSS_65mm filters in the grating position should never be used
# with any filter other than "empty", so we skip those as well.
if hasattr(grating, "physical_filter") and filter.physical_filter != "empty":
continue
# If the grating is a FilterDefinition, use the band and alias
# attributes defined in the grating for the new, combined
# FilterDefinition. In addition, filter out any combinations that do
# not use the "empty" filter in combination with a grating that is a
# FitlerDefintion as we should never combine multiple filters in real
# observations.
if isinstance(grating, FilterDefinition):
if filter.physical_filter != "empty":
continue

# FilterDefinition is a frozen dataclass
if hasattr(grating, "physical_filter"):
new_name = FILTER_DELIMITER.join([filter.physical_filter, grating.physical_filter])
else:
new_name = FILTER_DELIMITER.join([filter.physical_filter, grating])

# Also need to update aliases
if hasattr(grating, "physical_filter"):
new_aliases = {FILTER_DELIMITER.join([filter.physical_filter, a]) for a in grating.alias}
else:
new_aliases = {FILTER_DELIMITER.join([a, grating]) for a in filter.alias}

# For gratings set the band to the band of the filter. If an SDSS_65mm
# filter is installed in the grating slot, define the band as the band
# of the SDSS_65mm filter.
if hasattr(grating, "band"):
combo = FilterDefinition(physical_filter=new_name,
band=grating.band,
afw_name=grating.afw_name,
alias=new_aliases)
else:
new_name = FILTER_DELIMITER.join([filter.physical_filter, grating])
new_aliases = {FILTER_DELIMITER.join([a, grating]) for a in filter.alias}

combo = FilterDefinition(physical_filter=new_name,
band=filter.band,
afw_name=filter.afw_name,
alias=new_aliases)

_latiss_filter_and_grating.append(combo)


Expand Down

0 comments on commit ebaca9c

Please sign in to comment.