LSST Applications g0fba68d861+5616995c1c,g1ebb85f214+2420ccdea7,g1fd858c14a+44c57a1f81,g21d47ad084+8e51fce9ac,g262e1987ae+1a7d68eb3b,g2cef7863aa+3bd8df3d95,g35bb328faa+fcb1d3bbc8,g36ff55ed5b+2420ccdea7,g47891489e3+5c6313fe9a,g53246c7159+fcb1d3bbc8,g646c943bdb+dbb9921566,g67b6fd64d1+5c6313fe9a,g6bd32b75b5+2420ccdea7,g74acd417e5+37fc0c974d,g786e29fd12+cf7ec2a62a,g86c591e316+6e13bcb9e9,g87389fa792+1e0a283bba,g89139ef638+5c6313fe9a,g90f42f885a+fce05a46d3,g9125e01d80+fcb1d3bbc8,g93e38de9ac+5345a64125,g95a1e89356+47d08a1cc6,g97be763408+bba861c665,ga9e4eb89a6+85210110a1,gb0b61e0e8e+1f27f70249,gb58c049af0+f03b321e39,gb89ab40317+5c6313fe9a,gc4e39d7843+4e09c98c3d,gd16ba4ae74+5402bcf54a,gd8ff7fe66e+2420ccdea7,gd9a9a58781+fcb1d3bbc8,gdab6d2f7ff+37fc0c974d,gde280f09ee+604b327636,ge278dab8ac+50e2446c94,ge410e46f29+5c6313fe9a,gef3c2e6661+6b480e0fb7,gf67bdafdda+5c6313fe9a,gffca2db377+fcb1d3bbc8,v29.2.0.rc1
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)