LSST Applications g013ef56533+d2224463a4,g199a45376c+0ba108daf9,g19c4beb06c+9f335b2115,g1fd858c14a+2459ca3e43,g210f2d0738+2d3d333a78,g262e1987ae+abbb004f04,g2825c19fe3+eedc38578d,g29ae962dfc+0cb55f06ef,g2cef7863aa+aef1011c0b,g35bb328faa+8c5ae1fdc5,g3fd5ace14f+19c3a54948,g47891489e3+501a489530,g4cdb532a89+a047e97985,g511e8cfd20+ce1f47b6d6,g53246c7159+8c5ae1fdc5,g54cd7ddccb+890c8e1e5d,g5fd55ab2c7+951cc3f256,g64539dfbff+2d3d333a78,g67b6fd64d1+501a489530,g67fd3c3899+2d3d333a78,g74acd417e5+0ea5dee12c,g786e29fd12+668abc6043,g87389fa792+8856018cbb,g89139ef638+501a489530,g8d7436a09f+5ea4c44d25,g8ea07a8fe4+81eaaadc04,g90f42f885a+34c0557caf,g9486f8a5af+165c016931,g97be763408+d5e351dcc8,gbf99507273+8c5ae1fdc5,gc2a301910b+2d3d333a78,gca7fc764a6+501a489530,gce8aa8abaa+8c5ae1fdc5,gd7ef33dd92+501a489530,gdab6d2f7ff+0ea5dee12c,ge410e46f29+501a489530,geaed405ab2+e3b4b2a692,gf9a733ac38+8c5ae1fdc5,w.2025.41
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