LSST Applications g04e9c324dd+8c5ae1fdc5,g134cb467dc+b203dec576,g18429d2f64+358861cd2c,g199a45376c+0ba108daf9,g1fd858c14a+dd066899e3,g262e1987ae+ebfced1d55,g29ae962dfc+72fd90588e,g2cef7863aa+aef1011c0b,g35bb328faa+8c5ae1fdc5,g3fd5ace14f+b668f15bc5,g4595892280+3897dae354,g47891489e3+abcf9c3559,g4d44eb3520+fb4ddce128,g53246c7159+8c5ae1fdc5,g67b6fd64d1+abcf9c3559,g67fd3c3899+1f72b5a9f7,g74acd417e5+cb6b47f07b,g786e29fd12+668abc6043,g87389fa792+8856018cbb,g89139ef638+abcf9c3559,g8d7436a09f+bcf525d20c,g8ea07a8fe4+9f5ccc88ac,g90f42f885a+6054cc57f1,g97be763408+06f794da49,g9dd6db0277+1f72b5a9f7,ga681d05dcb+7e36ad54cd,gabf8522325+735880ea63,gac2eed3f23+abcf9c3559,gb89ab40317+abcf9c3559,gbf99507273+8c5ae1fdc5,gd8ff7fe66e+1f72b5a9f7,gdab6d2f7ff+cb6b47f07b,gdc713202bf+1f72b5a9f7,gdfd2d52018+8225f2b331,ge365c994fd+375fc21c71,ge410e46f29+abcf9c3559,geaed405ab2+562b3308c0,gf9a733ac38+8c5ae1fdc5,w.2025.35
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