Refining platesolving
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include "batchprocessing.h"
|
||||
#include <fitsio2.h>
|
||||
#include "libXISF/libxisf.h"
|
||||
#include "solver.h"
|
||||
|
||||
namespace Script
|
||||
{
|
||||
@@ -25,6 +26,8 @@ ScriptEngine::ScriptEngine(BatchProcessing *parent)
|
||||
_jsEngine->globalObject().setProperty("FITSRecordModify", fitsRecordObject);
|
||||
_database->init(QLatin1String("scriptengine"));
|
||||
_semaphore.release(_pool->maxThreadCount());
|
||||
|
||||
_solver = new Solver(this);
|
||||
}
|
||||
|
||||
void ScriptEngine::setParams(const QString &scriptPath, const QList<QPair<QString, QString>> &paths, const QString &outputDir)
|
||||
@@ -46,6 +49,7 @@ const QString &ScriptEngine::outputDir() const
|
||||
|
||||
void ScriptEngine::interrupt()
|
||||
{
|
||||
_solver->abort();
|
||||
_jsEngine->setInterrupted(true);
|
||||
}
|
||||
|
||||
@@ -118,6 +122,25 @@ QJSValue ScriptEngine::getItem(const QStringList &items, const QString &label, i
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ScriptEngine::setStartingSolution(const QJSValue &solution)
|
||||
{
|
||||
if(solution.isObject())
|
||||
{
|
||||
if(solution.hasProperty("ra") && solution.hasProperty("dec") && solution.property("ra").isNumber() && solution.property("dec").isNumber())
|
||||
_solver->setSearchPosition(solution.property("ra").toNumber(), solution.property("dec").toNumber());
|
||||
if(solution.hasProperty("pixscale") && solution.property("pixscale").isNumber())
|
||||
{
|
||||
double scale = solution.property("pixscale").toNumber();
|
||||
_solver->setSearchScale(scale * 0.8, scale * 1.2, SSolver::ScaleUnits::ARCSEC_PER_PIX);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_solver->clearStartingPositionAndScale();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool ScriptEngine::convert(File *file, QString &outpath, const QString &format, const QVariantMap ¶ms, bool async)
|
||||
{
|
||||
QString path;
|
||||
@@ -151,6 +174,86 @@ bool ScriptEngine::convert(File *file, QString &outpath, const QString &format,
|
||||
return true;
|
||||
}
|
||||
|
||||
QJSValue ScriptEngine::solveImage(File *file, bool updateHeader)
|
||||
{
|
||||
QString path = file->absoluteFilePath();
|
||||
QJSValue ret = newObject();
|
||||
|
||||
if(_solver->loadImage(path))
|
||||
{
|
||||
if(_solver->solveImage(true))
|
||||
{
|
||||
auto solution = _solver->getSolution();
|
||||
ret.setProperty("fieldWidth", solution.fieldWidth);
|
||||
ret.setProperty("fieldHeight", solution.fieldHeight);
|
||||
ret.setProperty("ra", solution.ra);
|
||||
ret.setProperty("dec", solution.dec);
|
||||
ret.setProperty("orientation", solution.orientation);
|
||||
ret.setProperty("pixscale", solution.pixscale);
|
||||
ret.setProperty("parity", solution.parity == FITSImage::Parity::POSITIVE);
|
||||
ret.setProperty("raError", solution.raError);
|
||||
ret.setProperty("decError", solution.decError);
|
||||
if(updateHeader)
|
||||
{
|
||||
QString error;
|
||||
if(!_solver->updateHeader(error))
|
||||
logError(error);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logError("Failed to plate solve image " + path);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logError("Failed to load image " + path);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
QJSValue ScriptEngine::extractStars(File *file, bool hfr)
|
||||
{
|
||||
QJSValue ret;
|
||||
QString path = file->absoluteFilePath();
|
||||
if(_solver->loadImage(path))
|
||||
{
|
||||
if(_solver->extractSources(hfr, true))
|
||||
{
|
||||
auto stars = _solver->getStars();
|
||||
ret = newArray(stars.size());
|
||||
int i = 0;
|
||||
for(auto &star : stars)
|
||||
{
|
||||
QJSValue starj = newObject();
|
||||
starj.setProperty("x", star.x);
|
||||
starj.setProperty("y", star.y);
|
||||
starj.setProperty("mag", star.mag);
|
||||
starj.setProperty("flux", star.flux);
|
||||
starj.setProperty("peak", star.peak);
|
||||
starj.setProperty("HFR", star.HFR);
|
||||
starj.setProperty("a", star.a);
|
||||
starj.setProperty("b", star.b);
|
||||
starj.setProperty("theta", star.theta);
|
||||
starj.setProperty("ra", star.ra);
|
||||
starj.setProperty("dec", star.dec);
|
||||
starj.setProperty("numPixels", star.numPixels);
|
||||
ret.setProperty(i++, starj);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logError("Failed to extract sources from " + path);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logError("Failed to load image " + path);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
QJSValue ScriptEngine::newObject()
|
||||
{
|
||||
return _jsEngine->newObject();
|
||||
@@ -579,6 +682,22 @@ QJSValue File::stats()
|
||||
return _stats;
|
||||
}
|
||||
|
||||
QJSValue File::solve(bool updateHeader)
|
||||
{
|
||||
if(_solution.isUndefined() || updateHeader)
|
||||
_solution = _engine->solveImage(this, updateHeader);
|
||||
|
||||
return _solution;
|
||||
}
|
||||
|
||||
QJSValue File::extractStars(bool hfr)
|
||||
{
|
||||
if(_stars.isUndefined())
|
||||
_stars = _engine->extractStars(this, hfr);
|
||||
|
||||
return _stars;
|
||||
}
|
||||
|
||||
ScriptEngineThread::ScriptEngineThread(BatchProcessing *parent) : QObject(parent)
|
||||
{
|
||||
_thread = new QThread();
|
||||
|
||||
Reference in New Issue
Block a user