Better handling of FITS records
This commit is contained in:
+40
-7
@@ -4,6 +4,7 @@
|
|||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
#include <wcslib/wcshdr.h>
|
#include <wcslib/wcshdr.h>
|
||||||
#include <wcslib/wcsfix.h>
|
#include <wcslib/wcsfix.h>
|
||||||
|
#include "pcl/FITSHeaderKeyword.h"
|
||||||
|
|
||||||
static const QVector<QByteArray> noEditableKey = {"SIMPLE", "BITPIX", "NAXIS", "NAXIS1", "NAXIS2", "NAXIS3", "EXTEND", "BZERO", "BSCALE"};
|
static const QVector<QByteArray> noEditableKey = {"SIMPLE", "BITPIX", "NAXIS", "NAXIS1", "NAXIS2", "NAXIS3", "EXTEND", "BZERO", "BSCALE"};
|
||||||
|
|
||||||
@@ -12,6 +13,44 @@ bool FITSRecord::editable() const
|
|||||||
return noEditableKey.count(key);
|
return noEditableKey.count(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FITSRecord::FITSRecord(const QByteArray &key, const QVariant &value, const QByteArray &comment) :
|
||||||
|
key(key), value(value), comment(comment)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
FITSRecord::FITSRecord(const pcl::FITSHeaderKeyword &record)
|
||||||
|
{
|
||||||
|
key = record.name.c_str();
|
||||||
|
comment = record.comment.c_str();
|
||||||
|
|
||||||
|
QString string = record.value.c_str();
|
||||||
|
if(string.startsWith('\'') && string.endsWith('\''))
|
||||||
|
{
|
||||||
|
string.chop(1);
|
||||||
|
string.remove(0, 1);
|
||||||
|
}
|
||||||
|
bool isint;
|
||||||
|
bool isdouble;
|
||||||
|
double vald = string.toDouble(&isdouble);
|
||||||
|
long long vall = string.toLongLong(&isint);
|
||||||
|
if(isint)
|
||||||
|
value = vall;
|
||||||
|
else if(isdouble)
|
||||||
|
value = vald;
|
||||||
|
else if(string == "T" || string == "F")
|
||||||
|
value = string == "T";
|
||||||
|
else
|
||||||
|
value = string;
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray FITSRecord::valueToByteArray() const
|
||||||
|
{
|
||||||
|
if(value.type() == QVariant::Bool)
|
||||||
|
return value.toBool() ? "T" : "F";
|
||||||
|
else
|
||||||
|
return value.toString().toLatin1();
|
||||||
|
}
|
||||||
|
|
||||||
ImageInfo::ImageInfo(QWidget *parent) : QTreeWidget(parent)
|
ImageInfo::ImageInfo(QWidget *parent) : QTreeWidget(parent)
|
||||||
{
|
{
|
||||||
setColumnCount(3);
|
setColumnCount(3);
|
||||||
@@ -86,16 +125,10 @@ WCSData::WCSData(int width, int height, const QVector<FITSRecord> &header) :
|
|||||||
{
|
{
|
||||||
if(record.key.startsWith("PV"))continue;
|
if(record.key.startsWith("PV"))continue;
|
||||||
|
|
||||||
QByteArray value = record.value.toString().toLatin1();
|
|
||||||
if(value.startsWith('\'') && value.endsWith('\''))
|
|
||||||
{
|
|
||||||
value.chop(1);
|
|
||||||
value = value.remove(0, 1);
|
|
||||||
}
|
|
||||||
QByteArray rec;
|
QByteArray rec;
|
||||||
rec.append(record.key.leftJustified(8, ' '));
|
rec.append(record.key.leftJustified(8, ' '));
|
||||||
rec.append("= ");
|
rec.append("= ");
|
||||||
rec.append(value);
|
rec.append(record.value.toString().toLatin1());
|
||||||
rec.append(" / ");
|
rec.append(" / ");
|
||||||
rec.append(record.comment);
|
rec.append(record.comment);
|
||||||
str.append(rec.leftJustified(80, ' ', true));
|
str.append(rec.leftJustified(80, ' ', true));
|
||||||
|
|||||||
@@ -5,12 +5,17 @@
|
|||||||
#include <wcslib/wcs.h>
|
#include <wcslib/wcs.h>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
namespace pcl { class FITSHeaderKeyword; }
|
||||||
|
|
||||||
struct FITSRecord
|
struct FITSRecord
|
||||||
{
|
{
|
||||||
QByteArray key;
|
QByteArray key;
|
||||||
QVariant value;
|
QVariant value;
|
||||||
QByteArray comment;
|
QByteArray comment;
|
||||||
bool editable() const;
|
bool editable() const;
|
||||||
|
FITSRecord(const QByteArray &key, const QVariant &value, const QByteArray &comment);
|
||||||
|
FITSRecord(const pcl::FITSHeaderKeyword &record);
|
||||||
|
QByteArray valueToByteArray() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SkyPoint
|
class SkyPoint
|
||||||
|
|||||||
+7
-5
@@ -161,10 +161,12 @@ int loadFITSHeader(fitsfile *file, ImageInfoData &info)
|
|||||||
var = vald;
|
var = vald;
|
||||||
else if(status == VALUE_UNDEFINED)
|
else if(status == VALUE_UNDEFINED)
|
||||||
var = QVariant();
|
var = QVariant();
|
||||||
|
else if(string == "T" || string == "F")
|
||||||
|
var = string == "T";
|
||||||
else
|
else
|
||||||
var = strval;
|
var = string;
|
||||||
status = 0;
|
status = 0;
|
||||||
info.fitsHeader.append({key, var, comm});
|
info.fitsHeader.append(FITSRecord(key, var, comm));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -324,7 +326,7 @@ bool loadXISF(const QString &path, ImageInfoData &info, RawImage **image)
|
|||||||
auto fitskeywords = xisf.ReadFITSKeywords();
|
auto fitskeywords = xisf.ReadFITSKeywords();
|
||||||
for(auto fits : fitskeywords)
|
for(auto fits : fitskeywords)
|
||||||
{
|
{
|
||||||
info.fitsHeader.append({fits.name.c_str(), fits.value.IsNumeral() ? QVariant(fits.value.ToDouble()) : QVariant(fits.value.c_str()), fits.comment.c_str()});
|
info.fitsHeader.append(fits);
|
||||||
}
|
}
|
||||||
info.wcs = std::make_shared<WCSData>(xisf.ImageInfo().width, xisf.ImageInfo().height, info.fitsHeader);
|
info.wcs = std::make_shared<WCSData>(xisf.ImageInfo().width, xisf.ImageInfo().height, info.fitsHeader);
|
||||||
if(!info.wcs->valid())info.wcs.reset();
|
if(!info.wcs->valid())info.wcs.reset();
|
||||||
@@ -500,7 +502,7 @@ bool readXISFHeader(const QString &path, ImageInfoData &info)
|
|||||||
auto fitskeywords = xisf.ReadFITSKeywords();
|
auto fitskeywords = xisf.ReadFITSKeywords();
|
||||||
for(auto fits : fitskeywords)
|
for(auto fits : fitskeywords)
|
||||||
{
|
{
|
||||||
info.fitsHeader.append({fits.name.c_str(), fits.value.IsNumeral() ? QVariant(fits.value.ToDouble()) : QVariant(fits.value.c_str()), fits.comment.c_str()});
|
info.fitsHeader.append(fits);
|
||||||
}
|
}
|
||||||
info.wcs = std::make_shared<WCSData>(xisf.ImageInfo().width, xisf.ImageInfo().height, info.fitsHeader);
|
info.wcs = std::make_shared<WCSData>(xisf.ImageInfo().width, xisf.ImageInfo().height, info.fitsHeader);
|
||||||
if(!info.wcs->valid())info.wcs.reset();
|
if(!info.wcs->valid())info.wcs.reset();
|
||||||
@@ -626,7 +628,7 @@ void ConvertRunable::run()
|
|||||||
pcl::FITSKeywordArray fitskeywords;
|
pcl::FITSKeywordArray fitskeywords;
|
||||||
for(auto &record : imageinfo.fitsHeader)
|
for(auto &record : imageinfo.fitsHeader)
|
||||||
{
|
{
|
||||||
pcl::FITSHeaderKeyword key(pcl::IsoString(record.key.data()), pcl::IsoString(record.value.toString().toLatin1().data()), pcl::IsoString(record.comment.data()));
|
pcl::FITSHeaderKeyword key(pcl::IsoString(record.key.data()), pcl::IsoString(record.valueToByteArray().data()), pcl::IsoString(record.comment.data()));
|
||||||
fitskeywords.Append(key);
|
fitskeywords.Append(key);
|
||||||
}
|
}
|
||||||
pcl::XISFWriter xisf;
|
pcl::XISFWriter xisf;
|
||||||
|
|||||||
Reference in New Issue
Block a user