LSST Applications g00d0e8bbd7+edbf708997,g03191d30f7+9ce8016dbd,g1955dfad08+0bd186d245,g199a45376c+5137f08352,g1fd858c14a+a888a50aa2,g262e1987ae+45f9aba685,g29ae962dfc+1c7d47a24f,g2cef7863aa+73c82f25e4,g35bb328faa+edbf708997,g3fd5ace14f+eed17d2c67,g47891489e3+6dc8069a4c,g53246c7159+edbf708997,g64539dfbff+c4107e45b5,g67b6fd64d1+6dc8069a4c,g74acd417e5+f452e9c21a,g786e29fd12+af89c03590,g7ae74a0b1c+a25e60b391,g7aefaa3e3d+2025e9ce17,g7cc15d900a+2d158402f9,g87389fa792+a4172ec7da,g89139ef638+6dc8069a4c,g8d4809ba88+c4107e45b5,g8d7436a09f+e96c132b44,g8ea07a8fe4+db21c37724,g98df359435+aae6d409c1,ga2180abaac+edbf708997,gac66b60396+966efe6077,gb632fb1845+88945a90f8,gbaa8f7a6c5+38b34f4976,gbf99507273+edbf708997,gca7fc764a6+6dc8069a4c,gd7ef33dd92+6dc8069a4c,gda68eeecaf+7d1e613a8d,gdab6d2f7ff+f452e9c21a,gdbb4c4dda9+c4107e45b5,ge410e46f29+6dc8069a4c,ge41e95a9f2+c4107e45b5,geaed405ab2+e194be0d2b,w.2025.47
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:126
void stripWcsMetadata(daf::base::PropertySet &metadata)
Definition wcsUtils.cc:215