11#include "config-kstars.h"
13#include "fits_debug.h"
14#include "fitssepdetector.h"
22#include <QtConcurrent>
24#ifdef HAVE_STELLARSOLVER
25#include "ekos/auxiliary/stellarsolverprofileeditor.h"
26#include <stellarsolver.h>
58 return QtConcurrent::run(
this, &FITSSEPDetector::findSourcesAndBackground, boundary);
61bool FITSSEPDetector::findSourcesAndBackground(
QRect const &boundary)
63#ifndef HAVE_STELLARSOLVER
69 int maxStarsCount = getValue(
"maxStarsCount", 100000).
toInt();
71 int optionsProfileIndex = getValue(
"optionsProfileIndex", -1).
toInt();
72 Ekos::ProfileGroup group =
static_cast<Ekos::ProfileGroup
>(getValue(
"optionsProfileGroup", 1).
toInt());
74 m_ImageData->getImageBuffer()));
79 case Ekos::AlignProfiles:
82 case Ekos::GuideProfiles:
83 filename =
"SavedGuideProfiles.ini";
85 case Ekos::FocusProfiles:
86 filename =
"SavedFocusProfiles.ini";
88 case Ekos::HFRProfiles:
89 filename =
"SavedHFRProfiles.ini";
95 if(
QFile(savedOptionsProfiles).exists())
96 optionsList = StellarSolver::loadSavedOptionsProfiles(savedOptionsProfiles);
101 case Ekos::AlignProfiles:
102 optionsList = Ekos::getDefaultAlignOptionsProfiles();
104 case Ekos::GuideProfiles:
105 optionsList = Ekos::getDefaultGuideOptionsProfiles();
107 case Ekos::FocusProfiles:
108 optionsList = Ekos::getDefaultFocusOptionsProfiles();
110 case Ekos::HFRProfiles:
111 optionsList = Ekos::getDefaultHFROptionsProfiles();
115 if (optionsProfileIndex >= 0 && optionsList.
count() > optionsProfileIndex)
117 auto params = optionsList[optionsProfileIndex];
118 params.partition = Options::stellarSolverPartition();
119 solver->setParameters(params);
120 qCDebug(KSTARS_FITS) <<
"Sextract with: " << optionsList[optionsProfileIndex].listName;
124 auto params = SSolver::Parameters();
125 params.partition = Options::stellarSolverPartition();
126 solver->setParameters(params);
130 const bool runHFR = group != Ekos::AlignProfiles;
132 solver->setLogLevel(SSolver::LOG_NONE);
133 solver->setSSLogLevel(SSolver::LOG_OFF);
136 solver->extract(runHFR, boundary);
138 solver->extract(runHFR);
140 stars = solver->getStarList();
143 if (stars.
empty() || image.isNull())
146 auto bg = solver->getBackground();
148 skyBG.mean = bg.global;
149 skyBG.sigma = bg.globalrms;
150 skyBG.numPixelsInSkyEstimate = bg.bw * bg.bh;
151 skyBG.setStarsDetected(bg.num_stars_detected);
152 m_ImageData->setSkyBackground(skyBG);
160 std::sort(stars.
begin(), stars.
end(), [](
const FITSImage::Star & star1,
const FITSImage::Star & star2) ->
bool { return star1.HFR > star2.HFR;});
162 std::sort(stars.
begin(), stars.
end(), [](
const FITSImage::Star & star1,
const FITSImage::Star & star2) ->
bool { return star1.flux > star2.flux;});
166 int starCount = qMin(maxStarsCount, stars.
count());
167 starCenters.
reserve(starCount);
168 for (
int i = 0; i < starCount; i++)
170 Edge *oneEdge =
new Edge();
171 oneEdge->x = stars[i].x;
172 oneEdge->y = stars[i].y;
173 oneEdge->val = stars[i].peak;
174 oneEdge->sum = stars[i].flux;
175 oneEdge->HFR = stars[i].HFR;
176 oneEdge->width = stars[i].a;
177 oneEdge->numPixels = stars[i].numPixels;
181 oneEdge->ellipticity = 1 - stars[i].b / stars[i].a;
183 oneEdge->ellipticity = 0;
185 starCenters.
append(oneEdge);
187 m_ImageData->setStarCenters(starCenters);
193void FITSSEPDetector::getFloatBuffer(
float * buffer,
int x,
int y,
int w,
int h, FITSData
const *data)
const
195 auto * rawBuffer =
reinterpret_cast<T
const *
>(data->getImageBuffer());
197 if (buffer ==
nullptr)
200 float * floatPtr = buffer;
205 FITSImage::Statistic
const &stats = data->getStatistics();
207 for (
int y1 = y; y1 < y2; y1++)
209 int offset = y1 * stats.width;
210 for (
int x1 = x; x1 < x2; x1++)
212 *floatPtr++ = rawBuffer[offset + x1];
217SkyBackground::SkyBackground(
double mean_,
double sigma_,
double numPixels_)
219 initialize(mean_, sigma_, numPixels_);
222void SkyBackground::initialize(
double mean_,
double sigma_,
223 double numPixelsInSkyEstimate_,
int numStars_)
227 numPixelsInSkyEstimate = numPixelsInSkyEstimate_;
228 varSky = sigma_ * sigma_;
229 starsDetected = numStars_;
233double SkyBackground::SNR(
double flux,
double numPixels,
double gain)
const
235 if (numPixelsInSkyEstimate <= 0 || gain <= 0)
238 const double numer = flux;
239 const double denom = sqrt( numer / gain + numPixels * varSky * (1 + 1 / numPixelsInSkyEstimate));
242 return numer / denom;
QString filePath(const QString &fileName) const const
void append(QList< T > &&value)
qsizetype count() const const
void reserve(qsizetype size)
bool isValid() const const
QFuture< T > run(Function function,...)
int toInt(bool *ok) const const