Compare commits
3 Commits
bb7e5182af
...
32f91d7b2f
| Author | SHA1 | Date | |
|---|---|---|---|
| 32f91d7b2f | |||
| 69fbad34b6 | |||
| e026042604 |
+1
-1
Submodule libXISF updated: fa39440b9e...c6581e1122
+34
-9
@@ -608,7 +608,7 @@ bool File::modifyFITSRecords(const FITSRecordModify *modify)
|
|||||||
_fitsKeywordsLoaded = false;
|
_fitsKeywordsLoaded = false;
|
||||||
_fitsKeywords.clear();
|
_fitsKeywords.clear();
|
||||||
|
|
||||||
if(QRegularExpression("(fits?|fz|fts)", QRegularExpression::CaseInsensitiveOption).match(suffix()).hasMatch())
|
if(isFITS(suffix()))
|
||||||
{
|
{
|
||||||
fitsfile *file;
|
fitsfile *file;
|
||||||
int status = 0;
|
int status = 0;
|
||||||
@@ -625,16 +625,22 @@ bool File::modifyFITSRecords(const FITSRecordModify *modify)
|
|||||||
int naxis;
|
int naxis;
|
||||||
long naxes[3] = {0};
|
long naxes[3] = {0};
|
||||||
int type = -1;
|
int type = -1;
|
||||||
|
std::vector<int> imageIdxs;
|
||||||
for(int i=1; i <= num; i++)
|
for(int i=1; i <= num; i++)
|
||||||
{
|
{
|
||||||
fits_movabs_hdu(file, i, IMAGE_HDU, &status);
|
fits_movabs_hdu(file, i, IMAGE_HDU, &status);
|
||||||
fits_get_hdu_type(file, &type, &status);
|
fits_get_hdu_type(file, &type, &status);
|
||||||
fits_get_img_param(file, 3, &imgtype, &naxis, naxes, &status);
|
if(type == IMAGE_HDU)
|
||||||
if(type == IMAGE_HDU && naxis >= 2 && naxis <= 3 && status == 0)
|
{
|
||||||
break;
|
fits_get_img_param(file, 3, &imgtype, &naxis, naxes, &status);
|
||||||
if(i == num)return false;
|
if(naxis >= 2 && naxis <= 3)imageIdxs.push_back(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(modify->_imageIdx >= imageIdxs.size())return false;
|
||||||
|
fits_movabs_hdu(file, imageIdxs[modify->_imageIdx], &type, &status);
|
||||||
|
fits_get_img_param(file, 3, &imgtype, &naxis, naxes, &status);
|
||||||
|
|
||||||
for(auto &remove : modify->_remove)
|
for(auto &remove : modify->_remove)
|
||||||
{
|
{
|
||||||
int status = 0;//we ignore errors from here
|
int status = 0;//we ignore errors from here
|
||||||
@@ -731,7 +737,7 @@ bool File::modifyFITSRecords(const FITSRecordModify *modify)
|
|||||||
|
|
||||||
return status == 0;
|
return status == 0;
|
||||||
}
|
}
|
||||||
else if(suffix().toLower() == "xisf")
|
else if(isXISF(suffix()))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -742,13 +748,16 @@ bool File::modifyFITSRecords(const FITSRecordModify *modify)
|
|||||||
qDebug() << "modify" << in << out;
|
qDebug() << "modify" << in << out;
|
||||||
|
|
||||||
for(auto &remove : modify->_remove)
|
for(auto &remove : modify->_remove)
|
||||||
modifyXISF.removeFITSKeyword(0, remove.toStdString());
|
modifyXISF.removeFITSKeyword(modify->_imageIdx, remove.toStdString());
|
||||||
|
|
||||||
for(auto &record : modify->_update)
|
for(auto &record : modify->_update)
|
||||||
modifyXISF.updateFITSKeyword(0, {record.key.toStdString(), record.value.toString().toStdString(), record.comment.toStdString()}, true);
|
modifyXISF.updateFITSKeyword(modify->_imageIdx, {record.key.toStdString(), record.value.toString().toStdString(), record.comment.toStdString()}, true);
|
||||||
|
|
||||||
for(auto &record : modify->_add)
|
for(auto &record : modify->_add)
|
||||||
modifyXISF.addFITSKeyword(0, {record.key.toStdString(), record.value.toString().toStdString(), record.comment.toStdString()});
|
modifyXISF.addFITSKeyword(modify->_imageIdx, {record.key.toStdString(), record.value.toString().toStdString(), record.comment.toStdString()});
|
||||||
|
|
||||||
|
for(auto &property : modify->_property)
|
||||||
|
modifyXISF.updateProperty(modify->_imageIdx, property);
|
||||||
|
|
||||||
modifyXISF.save(out.toLocal8Bit().toStdString());
|
modifyXISF.save(out.toLocal8Bit().toStdString());
|
||||||
modifyXISF.close();
|
modifyXISF.close();
|
||||||
@@ -757,6 +766,7 @@ bool File::modifyFITSRecords(const FITSRecordModify *modify)
|
|||||||
}
|
}
|
||||||
catch(std::filesystem::filesystem_error &err)
|
catch(std::filesystem::filesystem_error &err)
|
||||||
{
|
{
|
||||||
|
if(_engine)_engine->newMessage("Failed to modify file " + _path + " " + err.what(), true);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
catch(LibXISF::Error &err)
|
catch(LibXISF::Error &err)
|
||||||
@@ -926,6 +936,21 @@ void FITSRecordModify::addKeyword(const QString &key, const QVariant &value, con
|
|||||||
_update.append({key.toLatin1(), value, comment.toLatin1()});
|
_update.append({key.toLatin1(), value, comment.toLatin1()});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FITSRecordModify::updateProperty(const QString &id, const LibXISF::Variant &value)
|
||||||
|
{
|
||||||
|
_property.append(LibXISF::Property(id.toStdString(), value));
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t FITSRecordModify::imageIndex() const
|
||||||
|
{
|
||||||
|
return _imageIdx;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FITSRecordModify::setImageIndex(uint32_t idx)
|
||||||
|
{
|
||||||
|
_imageIdx = idx;
|
||||||
|
}
|
||||||
|
|
||||||
bool TextFile::open(const QString &path, const QString &mode)
|
bool TextFile::open(const QString &path, const QString &mode)
|
||||||
{
|
{
|
||||||
_fr.setFileName(path);
|
_fr.setFileName(path);
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include <QSemaphore>
|
#include <QSemaphore>
|
||||||
#include "database.h"
|
#include "database.h"
|
||||||
#include "imageinfodata.h"
|
#include "imageinfodata.h"
|
||||||
|
#include "libxisf.h"
|
||||||
|
|
||||||
class BatchProcessing;
|
class BatchProcessing;
|
||||||
class Solver;
|
class Solver;
|
||||||
@@ -140,6 +141,8 @@ class FITSRecordModify : public QObject
|
|||||||
QStringList _remove;
|
QStringList _remove;
|
||||||
QVector<FITSRecord> _update;
|
QVector<FITSRecord> _update;
|
||||||
QVector<FITSRecord> _add;
|
QVector<FITSRecord> _add;
|
||||||
|
QVector<LibXISF::Property> _property;
|
||||||
|
uint32_t _imageIdx = 0;
|
||||||
|
|
||||||
friend class File;
|
friend class File;
|
||||||
public:
|
public:
|
||||||
@@ -147,6 +150,10 @@ public:
|
|||||||
Q_INVOKABLE void removeKeyword(const QString &key);
|
Q_INVOKABLE void removeKeyword(const QString &key);
|
||||||
Q_INVOKABLE void updateKeyword(const QString &key, const QVariant &value, const QString &comment = QString());
|
Q_INVOKABLE void updateKeyword(const QString &key, const QVariant &value, const QString &comment = QString());
|
||||||
Q_INVOKABLE void addKeyword(const QString &key, const QVariant &value, const QString &comment = QString());
|
Q_INVOKABLE void addKeyword(const QString &key, const QVariant &value, const QString &comment = QString());
|
||||||
|
Q_PROPERTY(uint32_t imageIndex READ imageIndex WRITE setImageIndex);
|
||||||
|
void updateProperty(const QString &id, const LibXISF::Variant &value);
|
||||||
|
uint32_t imageIndex() const;
|
||||||
|
void setImageIndex(uint32_t idx);
|
||||||
};
|
};
|
||||||
|
|
||||||
class TextFile : public QObject
|
class TextFile : public QObject
|
||||||
|
|||||||
@@ -186,6 +186,19 @@ bool Solver::updateHeader(QString &error)
|
|||||||
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"));
|
||||||
|
|
||||||
|
LibXISF::F64Matrix matrix(2, 2);
|
||||||
|
matrix(0, 0) = std::cos(rotationRad) * cdeltx;
|
||||||
|
matrix(0, 1) =-std::sin(rotationRad) * cdelty;
|
||||||
|
matrix(1, 0) = std::sin(rotationRad) * cdeltx;
|
||||||
|
matrix(1, 1) = std::cos(rotationRad) * cdelty;
|
||||||
|
|
||||||
|
modify.updateProperty("PCL:AstrometricSolution:ReferenceCelestialCoordinates", LibXISF::F64Vector({solution.ra, solution.dec}));
|
||||||
|
modify.updateProperty("PCL:AstrometricSolution:ReferenceImageCoordinates", LibXISF::F64Vector({_stats.width / 2.0, _stats.height / 2.0}));
|
||||||
|
modify.updateProperty("PCL:AstrometricSolution:LinearTransformationMatrix", LibXISF::F64Matrix(matrix));
|
||||||
|
modify.updateProperty("PCL:AstrometricSolution:ProjectionSystem", LibXISF::String("Gnomonic"));
|
||||||
|
modify.updateProperty("PCL:AstrometricSolution:ReferenceNativeCoordinates", LibXISF::F64Vector({0, 90}));
|
||||||
|
|
||||||
bool ret = file.modifyFITSRecords(&modify);
|
bool ret = file.modifyFITSRecords(&modify);
|
||||||
if(!ret)error = tr("Failed to update file header");
|
if(!ret)error = tr("Failed to update file header");
|
||||||
else emit headerUpdated(_path);
|
else emit headerUpdated(_path);
|
||||||
|
|||||||
Reference in New Issue
Block a user