Skip to content

Commit

Permalink
Update comcam manual defects script to create manual defects.
Browse files Browse the repository at this point in the history
  • Loading branch information
erykoff committed Jan 29, 2025
1 parent 4e142b7 commit b9578bf
Showing 1 changed file with 68 additions and 23 deletions.
91 changes: 68 additions & 23 deletions python/lsst/obs/lsst/script/write_comcam_manual_defects.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,81 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

from lsst.daf.butler import Butler
from lsst.ip.isr import Defects
import lsst.obs.lsst as ol
import re
import os
import dateutil.parser
from lsst.ip.isr import Defects
from lsst.geom import Box2I, Point2I, Extent2I
import lsst.utils
from lsst.obs.lsst import LsstComCam

# Read and put new manual defects into the butler.
# We have to use embargo_old because
# this is where the CP needed for defects are.
camera_name = 'LSSTComCam'
butler = Butler('/repo/embargo_old', writeable=True)
collection_output = 'LSSTComCam/calib/DM-47365/addManualDefects/manualDefects.20241121c/run'
butler.registry.registerRun(collection_output)

cc = ol.LsstComCam
camera = cc.getCamera()
camera = LsstComCam().getCamera()

directory = lsst.utils.getPackageDir("obs_lsst_data")
data_root = lsst.utils.getPackageDir("obs_lsst_data")

valid_start = "2024-10-20T00:00:00"
valid_date = dateutil.parser.parse(valid_start)
datestr = "".join(re.split(r"[:-]", valid_date.isoformat()))

for det in camera:
detId = det.getId()
detName = det.getName()
print("Building manual defects from detector ", det.getName(), det.getId())
name = det.getName()
raft, sensor = name.split("_")

out_path = os.path.join(data_root, "comCam", "manual_defects", name.lower())
os.makedirs(out_path, exist_ok=True)
out_file = os.path.join(out_path, f"{datestr}.ecsv")

if os.path.isfile(out_file):
os.remove(out_file)

box_xywh = []

# Define the manual defects from DM-47365.
if det.getId() == 1:
# Phosphorescence.
box_xywh.extend(
(
(0, 1300, 350, 2695),
(3650, 3600, 417, 395),
),
)
elif det.getId() == 4:
# Unmasked dark column.
box_xywh.extend(
(
(3400, 2000, 15, 2000),
),
)
elif det.getId() == 5:
# High CTI amp edges.
box_xywh.extend(
(
(500, 0, 10, 2000),
(1008, 0, 15, 2000),
(1522, 0, 10, 2000),
(2031, 0, 10, 2000),
),
)

bboxes = [
Box2I(corner=Point2I(x, y), dimensions=Extent2I(w, h))
for x, y, w, h in box_xywh
]

manualDefectsPath = os.path.join(directory, "comCam", "manual_defects", detName.lower())
defects = Defects(bboxes)

# This is only valid for LSSTComCam which has a single raft
manual_defects = \
Defects.readText(manualDefectsPath+'/20241020T000000.ecsv')
defects.updateMetadata(
OBSTYPE="manual_defects",
camera=camera,
detector=det,
setCalibId=True,
setCalibInfo=True,
CALIBDATE=valid_start,
INSTRUME="ComCam",
CALIB_ID=(f"raftName={raft} detectorName={name} "
f"detector={det.getId()} calibDate={valid_start}"),
)

butler.put(manual_defects, "manual_defects",
instrument="LSSTComCam", detector=detId,
run=collection_output)
defects.writeText(out_file)

0 comments on commit b9578bf

Please sign in to comment.