From da1aa4c6fc6499046cf2794699486228bc0ff83a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Poizl?= Date: Mon, 30 Sep 2024 21:19:23 +0200 Subject: [PATCH] Updating FITS header --- imageinfo.cpp | 10 ++++++++-- imageinfo.h | 1 + platesolving.cpp | 34 +++++++++++++++++++++++++++++++--- platesolving.h | 2 ++ platesolving.ui | 40 +++++++++++++++++++++++++++------------- scriptengine.cpp | 9 +++++++-- solver.cpp | 19 ++++++++++++++----- solver.h | 3 ++- 8 files changed, 92 insertions(+), 26 deletions(-) diff --git a/imageinfo.cpp b/imageinfo.cpp index 3b85921..8efed53 100644 --- a/imageinfo.cpp +++ b/imageinfo.cpp @@ -281,6 +281,7 @@ SkyPointScale WCSDataT::getRaDecScale() const double scaleY = haverSine(ret.point, pointY) * 3600.0; ret.scaleLow = std::min(scaleX, scaleY); ret.scaleHigh = std::max(scaleX, scaleY); + ret.scaleValid = true; return ret; } @@ -413,16 +414,21 @@ SkyPointScale ImageInfoData::getCenterRaDec() const if(!std::isnan(scale)) { ret.scaleLow = ret.scaleHigh = scale; + ret.scaleValid = true; } else if(!(std::isnan(focalLen) || std::isnan(pixSizeX) || std::isnan(pixSizeY))) { const double r = 206.2648097656; // (180 * 3600) / (1000 * pi) magic number to convert pixel size to focal length ratio to arcsec. ret.scaleLow = std::min(pixSizeX * binX / focalLen * r, pixSizeY * binY / focalLen * r); ret.scaleHigh = std::max(pixSizeX * binX / focalLen * r, pixSizeY * binY / focalLen * r); + ret.scaleValid = true; } } - ret.scaleLow *= 0.8; - ret.scaleHigh *= 1.2; + if(ret.scaleValid) + { + ret.scaleLow *= 0.8; + ret.scaleHigh *= 1.2; + } return ret; } diff --git a/imageinfo.h b/imageinfo.h index 3439f28..cca16a7 100644 --- a/imageinfo.h +++ b/imageinfo.h @@ -42,6 +42,7 @@ struct SkyPointScale { SkyPoint point; //arcsec per pixel + bool scaleValid = false; double scaleLow = 0.0; double scaleHigh = 10000.0; }; diff --git a/platesolving.cpp b/platesolving.cpp index e4407c0..107a785 100644 --- a/platesolving.cpp +++ b/platesolving.cpp @@ -1,5 +1,6 @@ #include "platesolving.h" #include +#include #include "ui_platesolving.h" #include "solver.h" #include "imageringlist.h" @@ -33,6 +34,8 @@ PlateSolving::PlateSolving(QWidget *parent) connect(_ui->extractButton, &QPushButton::clicked, this, &PlateSolving::extract); connect(_ui->solveButton, &QPushButton::clicked, this, &PlateSolving::solve); connect(_ui->settingsButton, &QPushButton::clicked, this, &PlateSolving::settings); + connect(_ui->abortButton, &QPushButton::clicked, this, &PlateSolving::abort); + connect(_ui->updateButton, &QPushButton::clicked, this, &PlateSolving::updateHeader); connect(_solver, &Solver::solvingDone, this, &PlateSolving::solvingDone); connect(_solver, &Solver::extractionDone, this, &PlateSolving::extractionDone); connect(_solver, &Solver::logOutput, [this](const QString &log){ _ui->log->appendPlainText(log); }); @@ -132,6 +135,18 @@ void PlateSolving::solvingDone() _ui->log->appendPlainText(QString("Solving finished in %1 ms").arg(_solvingTime.elapsed())); } +void PlateSolving::abort() +{ + _solver->abort(); +} + +void PlateSolving::updateHeader() +{ + QString error; + if(!_solver->updateHeader(error)) + QMessageBox::warning(this, tr("Header update failed"), error); +} + void PlateSolving::imageLoaded(Image *image) { if(image && image->rawImage()) @@ -153,11 +168,24 @@ void PlateSolving::imageLoaded(Image *image) { _ui->raStart->setValue(pointScale.point.RAHour()); _ui->decStart->setValue(pointScale.point.DEC()); + _ui->usePosition->setChecked(true); + } + else + { + _ui->usePosition->setChecked(false); } - _ui->scaleUnit->setCurrentIndex(2); - _ui->fovLow->setValue(pointScale.scaleLow); - _ui->fovHigh->setValue(pointScale.scaleHigh); + if(pointScale.scaleValid) + { + _ui->scaleUnit->setCurrentIndex(2); + _ui->fovLow->setValue(pointScale.scaleLow); + _ui->fovHigh->setValue(pointScale.scaleHigh); + _ui->usePosition->setChecked(true); + } + else + { + _ui->useScale->setChecked(false); + } } } diff --git a/platesolving.h b/platesolving.h index 7cd0306..b74a2fe 100644 --- a/platesolving.h +++ b/platesolving.h @@ -28,6 +28,8 @@ public slots: void extractionDone(); void solve(); void solvingDone(); + void abort(); + void updateHeader(); void imageLoaded(Image *image); void settings(); private: diff --git a/platesolving.ui b/platesolving.ui index 9209a5e..a016514 100644 --- a/platesolving.ui +++ b/platesolving.ui @@ -309,6 +309,27 @@ + + + + Settings + + + + + + + Extract + + + + + + + Solve + + + @@ -316,24 +337,17 @@ - - + + - Extract + Abort - - + + - Solve - - - - - - - Settings + Update FITS header diff --git a/scriptengine.cpp b/scriptengine.cpp index 437efbd..5d3f7b5 100644 --- a/scriptengine.cpp +++ b/scriptengine.cpp @@ -350,7 +350,7 @@ bool File::modifyFITSRecords(const FITSRecordModify *modify) _fitsKeywordsLoaded = false; _fitsKeywords.clear(); - if(QRegularExpression("fits?", QRegularExpression::CaseInsensitiveOption).match(suffix()).hasMatch()) + if(QRegularExpression("(fits?|fz|fts)", QRegularExpression::CaseInsensitiveOption).match(suffix()).hasMatch()) { fitsfile *file; int status = 0; @@ -472,7 +472,7 @@ bool File::modifyFITSRecords(const FITSRecordModify *modify) return status == 0; } - else if(suffix() == "xisf") + else if(suffix().toLower() == "xisf") { try { @@ -493,6 +493,11 @@ bool File::modifyFITSRecords(const FITSRecordModify *modify) modifyXISF.save(out.absoluteFilePath().toLocal8Bit().toStdString()); modifyXISF.close(); std::filesystem::rename(out.filesystemAbsoluteFilePath(), in.filesystemAbsoluteFilePath()); + return true; + } + catch(std::filesystem::filesystem_error &err) + { + return false; } catch(LibXISF::Error &err) { diff --git a/solver.cpp b/solver.cpp index a92a13c..7933c65 100644 --- a/solver.cpp +++ b/solver.cpp @@ -109,6 +109,11 @@ bool Solver::extractSources(bool hfr) return false; } +void Solver::abort() +{ + _solver->abort(); +} + const FITSImage::Solution& Solver::getSolution() const { return _solver->getSolution(); @@ -137,13 +142,15 @@ QString Solver::errorMessage() const return _error; } -void Solver::updateHeader() +bool Solver::updateHeader(QString &error) { - if(!_solver->solvingDone())return; + if(!_solver->solvingDone()) + { + error = tr("Solving is not finished"); + return false; + } FITSImage::Solution solution = getSolution(); - qDebug() << "RA" << solution.ra << "DEC" << solution.dec << "Orient" << solution.orientation << "field wxh" << solution.fieldWidth << solution.fieldHeight << solution.pixscale; - qDebug() << "error" << solution.raError << solution.decError; double rotationDeg = 360.0 - solution.orientation; if(rotationDeg > 360)rotationDeg -= 360; @@ -170,7 +177,9 @@ void Solver::updateHeader() modify.updateKeyword("CTYPE2", "DEC--TAN", QByteArray("first parameter DEC, projection TANgential")); modify.updateKeyword("RADESYS", "ICRS", QByteArray("International Celestial Reference System")); modify.updateKeyword("EQUINOX", 2000, QByteArray("Equinox of coordinates")); - file.modifyFITSRecords(&modify); + bool ret = file.modifyFITSRecords(&modify); + if(!ret)error = tr("Failed to update file header"); + return ret; } void Solver::setParameters(Parameters::ParametersProfile profile) diff --git a/solver.h b/solver.h index eadc709..8ff5859 100644 --- a/solver.h +++ b/solver.h @@ -25,12 +25,13 @@ public: bool loadImage(std::shared_ptr &image, const QString &path); bool solveImage(); bool extractSources(bool hfr); + void abort(); const FITSImage::Solution& getSolution() const; const QList& getStars() const; double getHFR() const; QString errorMessage() const; - void updateHeader(); + bool updateHeader(QString &error); void setParameters(SSolver::Parameters::ParametersProfile profile); void setParameters(const SSolver::Parameters ¶meters); void setSearchScale(double fovLow, double fowHigh, ScaleUnits units);