Skip to content

Commit

Permalink
Switch to using read_element() in set_bandpass_from_filter. Add suppo…
Browse files Browse the repository at this point in the history
…rt for FITS CCD QE files.
  • Loading branch information
talister committed Feb 8, 2024
1 parent a9d4627 commit 5885d41
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 28 deletions.
37 changes: 10 additions & 27 deletions src/etc/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,32 +599,12 @@ def set_bandpass_from_filter(self, filtername):
filename = conf.mapping.get(filtername, None)
if filename is None:
raise ETCError("Filter name {0} is invalid.".format(filtername))
if "LCO_" in filename().upper() and ".csv" in filename().lower():
file_path = pkg_resources.files("etc.data").joinpath(os.path.expandvars(filename()))
source = "LCO iLab format"
header, wavelengths, throughput = self._read_lco_filter_csv(file_path)
elif "http://svo" in filename().lower():
source = "SVO filter service"
header, wavelengths, throughput = specio.read_remote_spec(
filename(), wave_unit=u.AA, flux_unit=units.THROUGHPUT
)
else:
source = "local file"
file_path = pkg_resources.files("etc.data").joinpath(os.path.expandvars(filename()))
warnings.simplefilter("ignore", category=AstropyUserWarning)
header, wavelengths, throughput = specio.read_ascii_spec(
file_path, wave_unit=u.nm, flux_unit=units.THROUGHPUT
)
if throughput.mean() > 1.0:
throughput /= 100.0
header["notes"] = "Divided by 100.0 to convert from percentage"
print("Reading from {} for {}".format(source, filtername))

header["filename"] = filename
header["descrip"] = filename.description
meta = {"header": header, "expr": filtername}
bandpass = read_element(filtername, "spectral_element")
bandpass.meta["expr"] = filtername
bandpass.meta["header"]["descrip"] = filename.description

return SpectralElement(Empirical1D, points=wavelengths, lookup_table=throughput, meta=meta)
return bandpass

def slit_vignette(self, slit_width=1 * u.arcsec):
"""Compute the fraction of light entering the slit of width <slit_width>
Expand Down Expand Up @@ -768,9 +748,12 @@ def __init__(self, name=None, camera_type="CCD", **kwargs):
file_path = os.path.expandvars(ccd_qe)
if not os.path.exists(file_path):
file_path = str(pkg_resources.files("etc.data").joinpath(ccd_qe))
header, wavelengths, throughput = specio.read_ascii_spec(
file_path, wave_unit=u.nm, flux_unit=units.THROUGHPUT
)
if file_path.lower().endswith("fits") or file_path.lower().endswith("fit"):
header, wavelengths, throughput = specio.read_fits_spec(file_path, flux_col="THROUGHPUT")
else:
header, wavelengths, throughput = specio.read_ascii_spec(
file_path, wave_unit=u.nm, flux_unit=units.THROUGHPUT
)
if throughput.mean() > 1.0:
throughput /= 100.0
header["notes"] = "Divided by 100.0 to convert from percentage"
Expand Down
3 changes: 2 additions & 1 deletion src/etc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def read_element(
except KeyError:
# HST/SYNPHOT format ?
header, wavelengths, throughput = specio.read_spec(
file_path, wave_col="WAVELENGTH", flux_col="THROUGHPUT"
file_path, wave_col="WAVELENGTH", flux_col="THROUGHPUT", flux_unit=flux_units
)
else:
header, wavelengths, throughput = specio.read_ascii_spec(
Expand All @@ -117,6 +117,7 @@ def read_element(
# which goes to 3.2 and averages out to ~1.4
throughput /= 100.0
header["notes"] = "Divided by 100.0 to convert from percentage"
# print("Reading from {} for {}".format(source, filtername))
header["source"] = source
header["filename"] = filename
if element_type == "spectrum" or element_type == "radiance":
Expand Down

0 comments on commit 5885d41

Please sign in to comment.