Updating FITS header

This commit is contained in:
2024-09-30 21:19:23 +02:00
parent a43f12565d
commit da1aa4c6fc
8 changed files with 92 additions and 26 deletions
+8 -2
View File
@@ -281,6 +281,7 @@ SkyPointScale WCSDataT::getRaDecScale() const
double scaleY = haverSine(ret.point, pointY) * 3600.0; double scaleY = haverSine(ret.point, pointY) * 3600.0;
ret.scaleLow = std::min(scaleX, scaleY); ret.scaleLow = std::min(scaleX, scaleY);
ret.scaleHigh = std::max(scaleX, scaleY); ret.scaleHigh = std::max(scaleX, scaleY);
ret.scaleValid = true;
return ret; return ret;
} }
@@ -413,16 +414,21 @@ SkyPointScale ImageInfoData::getCenterRaDec() const
if(!std::isnan(scale)) if(!std::isnan(scale))
{ {
ret.scaleLow = ret.scaleHigh = scale; ret.scaleLow = ret.scaleHigh = scale;
ret.scaleValid = true;
} }
else if(!(std::isnan(focalLen) || std::isnan(pixSizeX) || std::isnan(pixSizeY))) 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. 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.scaleLow = std::min(pixSizeX * binX / focalLen * r, pixSizeY * binY / focalLen * r);
ret.scaleHigh = std::max(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; if(ret.scaleValid)
ret.scaleHigh *= 1.2; {
ret.scaleLow *= 0.8;
ret.scaleHigh *= 1.2;
}
return ret; return ret;
} }
+1
View File
@@ -42,6 +42,7 @@ struct SkyPointScale
{ {
SkyPoint point; SkyPoint point;
//arcsec per pixel //arcsec per pixel
bool scaleValid = false;
double scaleLow = 0.0; double scaleLow = 0.0;
double scaleHigh = 10000.0; double scaleHigh = 10000.0;
}; };
+31 -3
View File
@@ -1,5 +1,6 @@
#include "platesolving.h" #include "platesolving.h"
#include <QSettings> #include <QSettings>
#include <QMessageBox>
#include "ui_platesolving.h" #include "ui_platesolving.h"
#include "solver.h" #include "solver.h"
#include "imageringlist.h" #include "imageringlist.h"
@@ -33,6 +34,8 @@ PlateSolving::PlateSolving(QWidget *parent)
connect(_ui->extractButton, &QPushButton::clicked, this, &PlateSolving::extract); connect(_ui->extractButton, &QPushButton::clicked, this, &PlateSolving::extract);
connect(_ui->solveButton, &QPushButton::clicked, this, &PlateSolving::solve); connect(_ui->solveButton, &QPushButton::clicked, this, &PlateSolving::solve);
connect(_ui->settingsButton, &QPushButton::clicked, this, &PlateSolving::settings); 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::solvingDone, this, &PlateSolving::solvingDone);
connect(_solver, &Solver::extractionDone, this, &PlateSolving::extractionDone); connect(_solver, &Solver::extractionDone, this, &PlateSolving::extractionDone);
connect(_solver, &Solver::logOutput, [this](const QString &log){ _ui->log->appendPlainText(log); }); 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())); _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) void PlateSolving::imageLoaded(Image *image)
{ {
if(image && image->rawImage()) if(image && image->rawImage())
@@ -153,11 +168,24 @@ void PlateSolving::imageLoaded(Image *image)
{ {
_ui->raStart->setValue(pointScale.point.RAHour()); _ui->raStart->setValue(pointScale.point.RAHour());
_ui->decStart->setValue(pointScale.point.DEC()); _ui->decStart->setValue(pointScale.point.DEC());
_ui->usePosition->setChecked(true);
}
else
{
_ui->usePosition->setChecked(false);
} }
_ui->scaleUnit->setCurrentIndex(2); if(pointScale.scaleValid)
_ui->fovLow->setValue(pointScale.scaleLow); {
_ui->fovHigh->setValue(pointScale.scaleHigh); _ui->scaleUnit->setCurrentIndex(2);
_ui->fovLow->setValue(pointScale.scaleLow);
_ui->fovHigh->setValue(pointScale.scaleHigh);
_ui->usePosition->setChecked(true);
}
else
{
_ui->useScale->setChecked(false);
}
} }
} }
+2
View File
@@ -28,6 +28,8 @@ public slots:
void extractionDone(); void extractionDone();
void solve(); void solve();
void solvingDone(); void solvingDone();
void abort();
void updateHeader();
void imageLoaded(Image *image); void imageLoaded(Image *image);
void settings(); void settings();
private: private:
+27 -13
View File
@@ -309,6 +309,27 @@
</item> </item>
<item> <item>
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="1">
<widget class="QPushButton" name="settingsButton">
<property name="text">
<string>Settings</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QPushButton" name="extractButton">
<property name="text">
<string>Extract</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QPushButton" name="solveButton">
<property name="text">
<string>Solve</string>
</property>
</widget>
</item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QCheckBox" name="withHFR"> <widget class="QCheckBox" name="withHFR">
<property name="text"> <property name="text">
@@ -316,24 +337,17 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0"> <item row="4" column="0">
<widget class="QPushButton" name="extractButton"> <widget class="QPushButton" name="abortButton">
<property name="text"> <property name="text">
<string>Extract</string> <string>Abort</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="4" column="1">
<widget class="QPushButton" name="solveButton"> <widget class="QPushButton" name="updateButton">
<property name="text"> <property name="text">
<string>Solve</string> <string>Update FITS header</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="settingsButton">
<property name="text">
<string>Settings</string>
</property> </property>
</widget> </widget>
</item> </item>
+7 -2
View File
@@ -350,7 +350,7 @@ bool File::modifyFITSRecords(const FITSRecordModify *modify)
_fitsKeywordsLoaded = false; _fitsKeywordsLoaded = false;
_fitsKeywords.clear(); _fitsKeywords.clear();
if(QRegularExpression("fits?", QRegularExpression::CaseInsensitiveOption).match(suffix()).hasMatch()) if(QRegularExpression("(fits?|fz|fts)", QRegularExpression::CaseInsensitiveOption).match(suffix()).hasMatch())
{ {
fitsfile *file; fitsfile *file;
int status = 0; int status = 0;
@@ -472,7 +472,7 @@ bool File::modifyFITSRecords(const FITSRecordModify *modify)
return status == 0; return status == 0;
} }
else if(suffix() == "xisf") else if(suffix().toLower() == "xisf")
{ {
try try
{ {
@@ -493,6 +493,11 @@ bool File::modifyFITSRecords(const FITSRecordModify *modify)
modifyXISF.save(out.absoluteFilePath().toLocal8Bit().toStdString()); modifyXISF.save(out.absoluteFilePath().toLocal8Bit().toStdString());
modifyXISF.close(); modifyXISF.close();
std::filesystem::rename(out.filesystemAbsoluteFilePath(), in.filesystemAbsoluteFilePath()); std::filesystem::rename(out.filesystemAbsoluteFilePath(), in.filesystemAbsoluteFilePath());
return true;
}
catch(std::filesystem::filesystem_error &err)
{
return false;
} }
catch(LibXISF::Error &err) catch(LibXISF::Error &err)
{ {
+14 -5
View File
@@ -109,6 +109,11 @@ bool Solver::extractSources(bool hfr)
return false; return false;
} }
void Solver::abort()
{
_solver->abort();
}
const FITSImage::Solution& Solver::getSolution() const const FITSImage::Solution& Solver::getSolution() const
{ {
return _solver->getSolution(); return _solver->getSolution();
@@ -137,13 +142,15 @@ QString Solver::errorMessage() const
return _error; 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(); 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; double rotationDeg = 360.0 - solution.orientation;
if(rotationDeg > 360)rotationDeg -= 360; 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("CTYPE2", "DEC--TAN", QByteArray("first parameter DEC, projection TANgential"));
modify.updateKeyword("RADESYS", "ICRS", QByteArray("International Celestial Reference System")); modify.updateKeyword("RADESYS", "ICRS", QByteArray("International Celestial Reference System"));
modify.updateKeyword("EQUINOX", 2000, QByteArray("Equinox of coordinates")); 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) void Solver::setParameters(Parameters::ParametersProfile profile)
+2 -1
View File
@@ -25,12 +25,13 @@ public:
bool loadImage(std::shared_ptr<RawImage> &image, const QString &path); bool loadImage(std::shared_ptr<RawImage> &image, const QString &path);
bool solveImage(); bool solveImage();
bool extractSources(bool hfr); bool extractSources(bool hfr);
void abort();
const FITSImage::Solution& getSolution() const; const FITSImage::Solution& getSolution() const;
const QList<FITSImage::Star>& getStars() const; const QList<FITSImage::Star>& getStars() const;
double getHFR() const; double getHFR() const;
QString errorMessage() const; QString errorMessage() const;
void updateHeader(); bool updateHeader(QString &error);
void setParameters(SSolver::Parameters::ParametersProfile profile); void setParameters(SSolver::Parameters::ParametersProfile profile);
void setParameters(const SSolver::Parameters &parameters); void setParameters(const SSolver::Parameters &parameters);
void setSearchScale(double fovLow, double fowHigh, ScaleUnits units); void setSearchScale(double fovLow, double fowHigh, ScaleUnits units);