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
fieldImpl.cc
Go to the documentation of this file.
1// -*- lsst-C++ -*-
2#include <cstring>
3#include "lsst/meas/extensions/psfex/Field.hh"
4#undef PI
5#include "lsst/geom/Point.h"
7
8extern "C" {
9 #include "globals.h"
10}
11
12namespace lsst { namespace meas { namespace extensions { namespace psfex {
13
14Field::Field(std::string const& ident) :
15 impl(NULL), _isInitialized(false)
16{
17 QCALLOC(impl, fieldstruct, 1);
18 impl->next = 0;
19
20 strcpy(impl->catname, ident.c_str());
21 impl->rcatname = impl->catname;
22#if 0
23 strncpy(impl->rtcatname, impl->rcatname, sizeof(impl->rtcatname) - 1);
24 strncpy(impl->ident, "??", sizeof(impl->ident) - 1);
25#elif 1
26 if (!(impl->rcatname = strrchr(impl->catname, '/'))) {
27 impl->rcatname = impl->catname;
28 } else {
29 ++impl->rcatname;
30 }
31
32 strncpy(impl->rtcatname, impl->rcatname, sizeof(impl->rtcatname) - 1);
33 {
34 char *pstr=strrchr(impl->rtcatname, '.');
35 if (pstr) {
36 *pstr = '\0';
37 }
38 }
39
40 strncpy(impl->ident, "??", sizeof(impl->ident) - 1);
41#endif
42
43 impl->ndet = 0;
44 impl->psf = NULL;
45 impl->wcs = NULL;
46
47 _finalize();
48}
49
51{
52 for (int i = 0; i != impl->next; ++i) {
53 free(impl->wcs[i]); // psfex's wcs isn't quite the same as ours ...
54 impl->wcs[i] = NULL; // ... so don't let psfex free it
55 }
56 field_end(impl);
57 impl = NULL;
58}
59
60/************************************************************************************************************/
61
62void
63Field::_finalize(bool force)
64{
65 if (force || !_isInitialized) {
66 field_init_finalize(impl);
67 _isInitialized = true;
68 }
69}
70
71/************************************************************************************************************/
72
74Field::getPsfs() const
75{
76 if (_psfs.empty()) {
77 _psfs.reserve(impl->next);
78 for (int i = 0; i != impl->next; ++i) {
79 _psfs.push_back(Psf(impl->psf[i]));
80 }
81 }
82
83 return _psfs;
84}
85
86void
87Field::addExt(lsst::afw::geom::SkyWcs const& wcs_,
88 int const naxis1, int const naxis2,
89 int const nobj)
90{
91 QREALLOC(impl->psf, psfstruct *, impl->next + 1);
92 impl->psf[impl->next] = 0;
93 QREALLOC(impl->wcs, wcsstruct *, impl->next + 1);
94 impl->wcs[impl->next] = 0;
95 /*
96 * We're going to fake psfex's wcsstruct object. We only need enough of it for field_locate
97 */
98 QMALLOC(impl->wcs[impl->next], wcsstruct, 1);
99 wcsstruct *wcs = impl->wcs[impl->next];
100
101 wcs->naxis = 2;
102 wcs->naxisn[0] = naxis1;
103 wcs->naxisn[1] = naxis2;
104
105 auto const crval = wcs_.getSkyOrigin();
106 // crpix using the FITS standard = pixel origin using the LSST standard + 1
107 auto const crpix = wcs_.getPixelOrigin() + geom::Extent2D(1, 1);
108 auto const cdMatrix = wcs_.getCdMatrix();
109 std::string const cunit("DEG");
111 try {
112 metadata = wcs_.getFitsMetadata();
113 } catch (pex::exceptions::RuntimeError &) {
114 metadata = wcs_.getTanWcs(wcs_.getPixelOrigin())->getFitsMetadata();
115 }
116 for (int i = 0; i != wcs->naxis; ++i) {
117 auto ifits = i + 1;
118 auto ctype = metadata->getAsString("CTYPE" + std::to_string(ifits));
119 strncpy(wcs->ctype[i], ctype.c_str(), ctype.size() + 1);
120 strncpy(wcs->cunit[i], cunit.c_str(), cunit.size() + 1);
121 wcs->crpix[i] = crpix[i];
122 wcs->crval[i] = crval[i].asDegrees();
123 wcs->cdelt[i] = 1.0; // scale is in the CD matrix (is this even needed?)
124 wcs->crder[i] = 0;
125 wcs->csyer[i] = 0;
126 }
127 for (int i = 0, k = 0; i < 2; ++i) {
128 for (int j = 0; j < 2; ++j, ++k) {
129 wcs->cd[k] = cdMatrix(i, j);
130 }
131 }
132 wcs->lng = 0;
133 wcs->lat = 1;
134 wcs->equinox = 2000;
135
136 auto center = wcs_.pixelToSky(geom::Point2D(0.5*naxis1, 0.5*naxis2));
137 wcs->wcsscalepos[0] = center.getLongitude().asDegrees();
138 wcs->wcsscalepos[1] = center.getLatitude().asDegrees();
139
140 double maxradius = 0.0; // Maximum distance to wcsscalepos
141 for (int x = 0; x <= 1; ++x) {
142 for (int y = 0; y <= 1; ++y) {
143 geom::Point2D point(x*naxis1, y*naxis2); // Corner
144 double const radius = center.separation(wcs_.pixelToSky(point)).asDegrees();
145 if (radius > maxradius) {
146 maxradius = radius;
147 }
148 }
149 }
150 wcs->wcsmaxradius = maxradius;
151
152 impl->ndet += nobj;
153
154 ++impl->next;
155}
156
157}}}}
T c_str(T... args)
A 2-dimensional celestial WCS that transform pixels to ICRS RA/Dec, using the LSST standard for pixel...
Definition SkyWcs.h:118
lsst::geom::SpherePoint pixelToSky(lsst::geom::Point2D const &pixel) const
Compute sky position(s) from pixel position(s)
Definition SkyWcs.h:334
std::shared_ptr< SkyWcs > getTanWcs(lsst::geom::Point2D const &pixel) const
Get a local TAN WCS approximation to this WCS at the specified pixel position.
Definition SkyWcs.cc:216
Eigen::Matrix2d getCdMatrix(lsst::geom::Point2D const &pixel) const
Get the 2x2 CD matrix at the specified pixel position.
Definition SkyWcs.cc:208
lsst::geom::Point2D getPixelOrigin() const
Get the pixel origin, in pixels, using the LSST convention.
Definition SkyWcs.h:215
lsst::geom::SpherePoint getSkyOrigin() const
Get the sky origin, the celestial fiducial point.
Definition SkyWcs.cc:197
std::shared_ptr< daf::base::PropertyList > getFitsMetadata(bool precise=false) const
Return the WCS as FITS WCS metadata.
Definition SkyWcs.cc:267
constexpr double asDegrees() const noexcept
Return an Angle's value in degrees.
Definition Angle.h:176
Angle getLongitude() const noexcept
The longitude of this point.
Extent< double, 2 > Extent2D
Definition Extent.h:400
Point< double, 2 > Point2D
Definition Point.h:324
T strcpy(T... args)
T strncpy(T... args)
T strrchr(T... args)
~Field() noexcept=default
Definition fieldImpl.cc:50
T to_string(T... args)