diff --git a/python/lsst/obs/lsst/script/rewrite_latiss_optics_file.py b/python/lsst/obs/lsst/script/rewrite_latiss_optics_file.py new file mode 100644 index 000000000..b0c36cb1a --- /dev/null +++ b/python/lsst/obs/lsst/script/rewrite_latiss_optics_file.py @@ -0,0 +1,82 @@ +# This file is part of obs_lsst. +# +# Developed for the LSST Data Management System. +# This product includes software developed by the LSST Project +# (https://www.lsst.org). +# See the COPYRIGHT file at the top-level directory of this distribution +# for details of code ownership. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +import os +import re +import dateutil.parser + +import numpy as np +import astropy.units as u +from astropy.table import Table, QTable + +import lsst.utils +from lsst.meas.algorithms.simple_curve import DetectorCurve + + +data_dir = lsst.utils.getPackageDir("obs_lsst_data") +subaru_file = "subaru_m1_r_20200219.txt" +valid_start = "1970-01-01T00:00:00" + +filename = os.path.join(data_dir, "latiss", "transmission_optics", subaru_file) + +subaru_data = Table.read(filename, format="ascii") + +wavelength = subaru_data["col1"] +ref = np.mean( + np.array(subaru_data[["col2", "col3", "col4", "col5", "col6"]]).view("f8").reshape((len(subaru_data), 5)), + axis=1, +) + +# Make sure it's sorted by wavelength. +st = np.argsort(wavelength) + +optics_table = QTable( + { + "wavelength": np.array(wavelength[st], dtype=np.float64)*u.nanometer, + "efficiency": ref[st]*u.percent, + } +) + +# Adjust the overall normalization to match AuxTel scans. +optics_table["efficiency"] += 3.5*u.percent + +curve = DetectorCurve.fromTable(optics_table) + +valid_date = dateutil.parser.parse(valid_start) +datestr = ''.join(re.split(r'[:-]', valid_date.isoformat())) + +outfile = os.path.join(data_dir, "latiss", "transmission_optics", datestr + ".ecsv") + +optics_table.meta.update( + { + "CALIBDATE": valid_start, + "INSTRUME": "LATISS", + "OBSTYPE": "transmission_optics", + "TYPE": "transmission_optics", + "CALIBCLS": "lsst.ip.isr.IntermediateOpticsTransmissionCurve", + "SOURCE": subaru_file, + } +) + +optics_table.meta["CALIB_ID"] = ( + f"calibDate={valid_start} filter=None" +) + +curve.writeText(outfile) diff --git a/python/lsst/obs/lsst/script/rewrite_latiss_qe_file.py b/python/lsst/obs/lsst/script/rewrite_latiss_qe_file.py new file mode 100644 index 000000000..ff09a11a2 --- /dev/null +++ b/python/lsst/obs/lsst/script/rewrite_latiss_qe_file.py @@ -0,0 +1,118 @@ +# This file is part of obs_lsst. +# +# Developed for the LSST Data Management System. +# This product includes software developed by the LSST Project +# (https://www.lsst.org). +# See the COPYRIGHT file at the top-level directory of this distribution +# for details of code ownership. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +import astropy.units as u +from astropy.io import fits +from astropy.table import QTable +import re +import os +import dateutil.parser +import numpy + +import lsst.utils +from lsst.meas.algorithms.simple_curve import AmpCurve + +amp_name_map = {'AMP01': 'C10', 'AMP02': 'C11', 'AMP03': 'C12', 'AMP04': 'C13', 'AMP05': 'C14', + 'AMP06': 'C15', 'AMP07': 'C16', 'AMP08': 'C17', 'AMP09': 'C07', 'AMP10': 'C06', + 'AMP11': 'C05', 'AMP12': 'C04', 'AMP13': 'C03', 'AMP14': 'C02', 'AMP15': 'C01', + 'AMP16': 'C00'} + + +def convert_qe_curve(filename): + """Convert a single QE curve from its native FITS format to an + an `astropy.table.QTable` representation. + + Parameters + ---------- + filename : `str` + Full path, including filename for the file to be converted. + + Returns + ------- + table : `astropy.table.QTable` + A QTable object containing the columns that describe this + QE curve. + + Notes + ----- + This function is specific to how the ts8 data are formatted + with a curve per amp. If ther are other formats, a different + converter will be necessary. + """ + with fits.open(filename) as hdu_list: + # qe data is in first extension + data = hdu_list[1].data + wlength = [] + eff = dict() + for row in data: + wlength.append(row['WAVELENGTH']) + for i in range(16): # There are 16 amps + col_name = f'AMP{i+1:02d}' + eff.setdefault(amp_name_map[col_name], []).append(row[col_name]) + out_data = {'amp_name': [], 'wavelength': [], 'efficiency': []} + for k in eff: + amp_names = [k]*len(wlength) + out_data['amp_name'] += amp_names + out_data['wavelength'] += wlength + out_data['efficiency'] += eff[k] + + out_data['amp_name'] = numpy.array(out_data['amp_name']) + out_data['wavelength'] = numpy.array(out_data['wavelength'])*u.nanometer + out_data['efficiency'] = numpy.array(out_data['efficiency'])*u.percent + + return QTable(out_data) + + +data_dir = lsst.utils.getPackageDir("obs_lsst_data") +raft_name = "rxx" +detector_name = "s00" +raft_detector = raft_name + "_" + detector_name +detector_id = 0 +fits_file = "ITL-3800C-068_QE.fits" +valid_start = "1970-01-01T00:00:00" + +filename = os.path.join(data_dir, "latiss", "transmission_sensor", raft_detector, fits_file) + +curve_table = convert_qe_curve(filename) +curve = AmpCurve.fromTable(curve_table) + +valid_date = dateutil.parser.parse(valid_start) +datestr = ''.join(re.split(r'[:-]', valid_date.isoformat())) + +outfile = os.path.join(data_dir, "latiss", "transmission_sensor", raft_detector, datestr + ".ecsv") + +curve_table.meta.update( + { + "CALIBDATE": valid_start, + "INSTRUME": "LATISS", + "OBSTYPE": "transmission_sensor", + "TYPE": "transmission_sensor", + "DETECTOR": detector_id, + "CALIBCLS": "lsst.ip.isr.IntermediateSensorTransmissionCurve", + "SOURCE": fits_file, + } +) + +curve_table.meta["CALIB_ID"] = ( + f"raftName={raft_name} detectorName={detector_name} " + f"detector={detector_id} calibDate={valid_start} " + f"ccd={detector_id} ccdnum={detector_id} filter=None") + +curve.writeText(outfile)