LSST Applications g042eb84c57+730a74494b,g04e9c324dd+8c5ae1fdc5,g134cb467dc+1f1e3e7524,g199a45376c+0ba108daf9,g1fd858c14a+fa7d31856b,g210f2d0738+f66ac109ec,g262e1987ae+83a3acc0e5,g29ae962dfc+d856a2cb1f,g2cef7863aa+aef1011c0b,g35bb328faa+8c5ae1fdc5,g3fd5ace14f+a1e0c9f713,g47891489e3+0d594cb711,g4d44eb3520+c57ec8f3ed,g4d7b6aa1c5+f66ac109ec,g53246c7159+8c5ae1fdc5,g56a1a4eaf3+fd7ad03fde,g64539dfbff+f66ac109ec,g67b6fd64d1+0d594cb711,g67fd3c3899+f66ac109ec,g6985122a63+0d594cb711,g74acd417e5+3098891321,g786e29fd12+668abc6043,g81db2e9a8d+98e2ab9f28,g87389fa792+8856018cbb,g89139ef638+0d594cb711,g8d7436a09f+80fda9ce03,g8ea07a8fe4+760ca7c3fc,g90f42f885a+033b1d468d,g97be763408+a8a29bda4b,g99822b682c+e3ec3c61f9,g9d5c6a246b+0d5dac0c3d,ga41d0fce20+9243b26dd2,gbf99507273+8c5ae1fdc5,gd7ef33dd92+0d594cb711,gdab6d2f7ff+3098891321,ge410e46f29+0d594cb711,geaed405ab2+c4bbc419c6,gf9a733ac38+8c5ae1fdc5,w.2025.38
LSST Data Management Base Package
Loading...
Searching...
No Matches
lsst.afw.display._write_fits Namespace Reference

Functions

None _add_wcs (str wcs_name, PropertyList ps, int x0=0, int y0=0)
 
None writeFitsImage (str|int|io.BytesIO file, lsst.afw.image.Image|lsst.afw.image.Mask data, lsst.afw.geom.SkyWcs|None wcs=None, str title="", PropertySet|None metadata=None)
 

Function Documentation

◆ _add_wcs()

None lsst.afw.display._write_fits._add_wcs ( str wcs_name,
PropertyList ps,
int x0 = 0,
int y0 = 0 )
protected

Definition at line 37 of file _write_fits.py.

37def _add_wcs(wcs_name: str, ps: PropertyList, x0: int = 0, y0: int = 0) -> None:
38 ps.setInt(f"CRVAL1{wcs_name}", x0, "(output) Column pixel of Reference Pixel")
39 ps.setInt(f"CRVAL2{wcs_name}", y0, "(output) Row pixel of Reference Pixel")
40 ps.setDouble(f"CRPIX1{wcs_name}", 1.0, "Column Pixel Coordinate of Reference")
41 ps.setDouble(f"CRPIX2{wcs_name}", 1.0, "Row Pixel Coordinate of Reference")
42 ps.setString(f"CTYPE1{wcs_name}", "LINEAR", "Type of projection")
43 ps.setString(f"CTYPE1{wcs_name}", "LINEAR", "Type of projection")
44 ps.setString(f"CUNIT1{wcs_name}", "PIXEL", "Column unit")
45 ps.setString(f"CUNIT2{wcs_name}", "PIXEL", "Row unit")
46
47

◆ writeFitsImage()

None lsst.afw.display._write_fits.writeFitsImage ( str | int | io.BytesIO file,
lsst.afw.image.Image | lsst.afw.image.Mask data,
lsst.afw.geom.SkyWcs | None wcs = None,
str title = "",
PropertySet | None metadata = None )
Write a simple FITS file with no extensions.

Parameters
----------
file : `str` or `int`
    Path to a file or a file descriptor.
data : `lsst.afw.Image` or `lsst.afw.Mask`
    Data to be displayed.
wcs : `lsst.afw.geom.SkyWcs` or `None`, optional
    WCS to be written to header to FITS file.
title : `str`, optional
    If defined, the value to be stored in the ``OBJECT`` header.
    Overrides any value found in ``metadata``.
metadata : `lsst.daf.base.PropertySet` or `None`, optional
    Additional information to be written to FITS header.

Definition at line 48 of file _write_fits.py.

54) -> None:
55 """Write a simple FITS file with no extensions.
56
57 Parameters
58 ----------
59 file : `str` or `int`
60 Path to a file or a file descriptor.
61 data : `lsst.afw.Image` or `lsst.afw.Mask`
62 Data to be displayed.
63 wcs : `lsst.afw.geom.SkyWcs` or `None`, optional
64 WCS to be written to header to FITS file.
65 title : `str`, optional
66 If defined, the value to be stored in the ``OBJECT`` header.
67 Overrides any value found in ``metadata``.
68 metadata : `lsst.daf.base.PropertySet` or `None`, optional
69 Additional information to be written to FITS header.
70 """
71 ps = PropertyList()
72
73 # Seed with the external metadata, stripping wcs keywords.
74 if metadata:
76 ps.update(metadata)
77
78 # Write WcsB, so that pixel (0,0) is correctly labelled (but ignoring XY0)
79 _add_wcs("B", ps)
80
81 if not wcs:
82 _add_wcs("", ps) # Works around a ds9 bug that WCSA/B is ignored if no WCS is present.
83 else:
84 shift = Extent2D(-data.getX0(), -data.getY0())
85 if wcs.hasFitsApproximation():
86 wcs = wcs.getFitsApproximation()
87 new_wcs = wcs.copyAtShiftedPixelOrigin(shift)
88 wcs_metadata = new_wcs.getFitsMetadata()
89 ps.update(wcs_metadata)
90
91 if title:
92 ps.set("OBJECT", title, "Image being displayed")
93
94 if isinstance(file, str):
95 data.writeFits(file, metadata=ps)
96 else:
98 data.writeFits(manager=mem, metadata=ps)
99 if isinstance(file, int):
100 # Duplicate to prevent a double close, assuming the caller
101 # will close the file descriptor they passed in.
102 with os.fdopen(os.dup(file), "wb") as fh:
103 fh.write(mem.getData())
104 elif isinstance(file, subprocess.Popen):
105 file.communicate(input=mem.getData())
106 else:
107 # Try the write() method directly.
108 file.write(mem.getData())
Lifetime-management for memory that goes into FITS memory files.
Definition fits.h:125
void stripWcsMetadata(daf::base::PropertySet &metadata)
Definition wcsUtils.cc:215