LSST Applications g180d380827+107df2c2fa,g2079a07aa2+86d27d4dc4,g2305ad1205+27ad5d03fa,g2bbee38e9b+c6a8a0fb72,g337abbeb29+c6a8a0fb72,g33d1c0ed96+c6a8a0fb72,g3a166c0a6a+c6a8a0fb72,g3d1719c13e+cc4c7597ef,g487adcacf7+4b0be3ae0a,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+14d443d837,g62aa8f1a4b+588cc723a1,g674612935b+7a21c67e12,g858d7b2824+cc4c7597ef,g991b906543+cc4c7597ef,g99cad8db69+b90e8bab37,g9c22b2923f+e2510deafe,g9ddcbc5298+9a081db1e4,g9fbc5161f1+1dc7c5428e,ga1e77700b3+03d07e1c1f,gb0e22166c9+60f28cb32d,gb23b769143+cc4c7597ef,gba4ed39666+c2a2e4ac27,gbb8dafda3b+52e28152d7,gbd998247f1+585e252eca,gbeadb96d05+a322446fe6,gc120e1dc64+6a70fcc921,gc28159a63d+c6a8a0fb72,gc3e9b769f7+48c1343504,gcf0d15dbbd+7a21c67e12,gdaeeff99f8+f9a426f77a,ge6526c86ff+9349653ccd,ge79ae78c31+c6a8a0fb72,gee10cc3b42+585e252eca,w.2024.18
LSST Data Management Base Package
Loading...
Searching...
No Matches
psfImpl.cc
Go to the documentation of this file.
1// -*- lsst-C++ -*-
2#include "boost/format.hpp"
4#include "lsst/meas/extensions/psfex/psf.hh"
5#include "ndarray.h"
6
7#define RETURN_IMAGE_FIELD(NAME, CNAME, SIZE) \
8 ndarray::Array<float,2,2> \
9 NAME() const \
10 { \
11 ndarray::Array<float,2,2>::Index shape = ndarray::makeVector(SIZE[0], SIZE[1]); \
12 ndarray::Array<float,2,2>::Index strides = ndarray::makeVector(1, SIZE[0]); \
13 \
14 return ndarray::external(impl->CNAME, shape, strides); \
15 }
16
17namespace lsst { namespace meas { namespace extensions { namespace psfex {
18
19Context::Context(std::vector<std::string> const& names,
22 bool pcexflag
23 )
24{
25 _names = names;
26 int const ndim = names.size();
27 int const ngroup = group.size();
28
30 for (int i = 0; i != ndim; ++i) {
31 cnames[i] = names[i].c_str();
32 }
33
34 impl = context_init(const_cast<char **>(&cnames[0]),
35 const_cast<int *>(&group[0]),
36 ndim,
37 const_cast<int *>(&degree[0]),
38 ngroup, (pcexflag ? 1 : 0));
39 _pc_vectors.resize(impl->npc);
40}
41
42Context::~Context() {
43 context_end(impl);
44}
45
46std::vector<double> & Context::getPc(int const i) const
47{
48 if (i < 0 || i >= impl->npc) {
50 s1 << "Index " << i << " is out of range 0.." << impl->npc - 1;
51 throw std::out_of_range(s1.str());
52 }
53 if (_pc_vectors[i].empty()) {
54 _pc_vectors[i].reserve(impl->npc);
55 for (int j = 0; j != impl->npc; ++j) {
56 _pc_vectors[i][j] = impl->pc[i*impl->npc + j];
57 }
58 }
59 return _pc_vectors[i];
60}
61
62/************************************************************************************************************/
63
64void Sample::setVig(ndarray::Array<float,2,2> const& img)
65{
66 int const w = img.getSize<0>(), h = img.getSize<1>();
67
68 if (_vigsize[0]*_vigsize[1] != w*h) {
70 str(boost::format("Expected %dx%d array, but was passed %dx%d")
71 % _vigsize[0] % _vigsize[1] % w % h));
72 }
73
74 ndarray::Array<float,1,1> flattened = ndarray::flatten<1>(img);
75 std::copy(flattened.begin(), flattened.end(), impl->vig);
76}
77
78RETURN_IMAGE_FIELD(Sample::getVig, vig, _vigsize)
79RETURN_IMAGE_FIELD(Sample::getVigResi, vigresi, _vigsize)
80RETURN_IMAGE_FIELD(Sample::getVigChi, vigchi, _vigsize)
81RETURN_IMAGE_FIELD(Sample::getVigWeight, vigweight, _vigsize)
82
83/************************************************************************************************************/
84
85Set::Set(Context &c) {
86 impl = init_set(c.impl);
87 impl->nsample = impl->nsamplemax = 0;
88}
89Set::~Set() {
90 end_set(impl);
91}
92
93Sample
94Set::newSample()
95{
96 if (impl->nsample >= impl->nsamplemax) {
97 if (impl->nsamplemax == 0) {
98 malloc_samples(impl, LSAMPLE_DEFSIZE);
99 } else {
100 realloc_samples(impl, (int)(1.62*impl->nsamplemax + 1));
101 }
102 }
103 return Sample(impl->sample[impl->nsample], _recentroid, impl->vigsize);
104}
105
106void
107Set::trimMemory() const
108{
109 setstruct *mutable_impl = const_cast<setstruct *>(impl);
110 realloc_samples(mutable_impl, impl->nsample);
111}
112
113void
114Set::finiSample(Sample const& sample)
115{
116 ++impl->nsample;
117 make_weights(impl, sample.impl);
118 if (sample._recentroid) {
119 recenter_sample(sample.impl, impl, sample._fluxrad);
120 }
121}
122
123/************************************************************************************************************/
124
125Psf::~Psf() {
126#if 0 // we don't own impl
127 psf_end(impl);
128#endif
129}
130
131void
132Psf::build(double x, double y,
133 std::vector<double> const& other)
134{
135 if (!impl->contextoffset) { // we never set context{offset,scale}
136 throw std::out_of_range("psf.contextoffset not set (probably no valid stars) so I can't index it");
137 }
138
139 std::vector<double> pos(2);
140 pos[0] = x; pos[1] = y;
141
142 pos.insert(pos.end(), other.begin(), other.end());
143
144 for (unsigned int i = 0; i != pos.size(); ++i) {
145 pos[i] = (pos[i] - impl->contextoffset[i])/impl->contextscale[i];
146 }
147
148 psf_build(impl, &pos[0]);
149}
150
151RETURN_IMAGE_FIELD(Psf::getLoc, loc, impl->size)
152RETURN_IMAGE_FIELD(Psf::getResi, resi, impl->size)
153
154}}}}
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition Exception.h:48
int y
Definition SpanSet.cc:48
T begin(T... args)
Reports attempts to exceed implementation-defined length limits for some classes.
Definition Runtime.h:76
T copy(T... args)
T end(T... args)
#define RETURN_IMAGE_FIELD(NAME, CNAME, SIZE)
Definition psfImpl.cc:7
double w
Definition CoaddPsf.cc:69
table::Key< int > ndim
Definition PsfexPsf.cc:325
table::Key< int > ngroup
Definition PsfexPsf.cc:326
table::Key< table::Array< int > > degree
Definition PsfexPsf.cc:360
table::Key< table::Array< int > > group
Definition PsfexPsf.cc:359
T str(T... args)