Adding platesolving

This commit is contained in:
2024-09-30 18:39:35 +02:00
parent dccb2e88da
commit 32973c54ce
16 changed files with 1075 additions and 210 deletions
+56 -22
View File
@@ -2,7 +2,11 @@
#include <QNetworkReply>
#include <QDebug>
#include <QRegularExpression>
#include <QFileInfo>
#ifdef PLATESOLVER
#include "solver.h"
#endif
// filename arcseconds range
// index-4119.fits 14002000
@@ -135,7 +139,7 @@ static const QMap<QString, QByteArray> md5 = {
{"index-5202-45.fits.zst", "83fe2cff3cf65317f5c1bf7b953519e9"},
{"index-5202-46.fits.zst", "f12f308a3b53d95ffd7bc420700e4f44"},
{"index-5202-47.fits.zst", "608a14303810c9762b25fc68896d2a26"},
{"index-5203-00.fits.zst", "155217faa535550c1d7e499145750bb0"},
{"index-5203-00.fits.zst", "2862efb33765b7bbefb635dcad970298"},
{"index-5203-01.fits.zst", "2cd34cef4b44ad1e770396baccb2a46c"},
{"index-5203-02.fits.zst", "40c9f67282210cc374281cde023c4e71"},
{"index-5203-03.fits.zst", "c8f40e164ec3ce1df92e3a121a127716"},
@@ -368,20 +372,32 @@ void Download::readData()
void Download::finished()
{
QByteArray data = _reply->readAll();
qDebug() << "finished" << data.size();
decompress(data);
if(md5.contains(_reply->url().fileName()))
if(_reply->error() == QNetworkReply::NoError)
{
if(_hash.result().toHex() == md5[_reply->url().fileName()])
qDebug() << "DOWNLOAD OK";
else
qDebug() << "DOWNLOAD BAD";
}
QByteArray data = _reply->readAll();
qDebug() << "finished" << data.size();
decompress(data);
_fw.flush();
_fw.close();
if(md5.contains(_reply->url().fileName()))
{
if(_hash.result().toHex() == md5[_reply->url().fileName()])
qDebug() << "DOWNLOAD OK";
else
{
qDebug() << "DOWNLOAD BAD";
_fw.remove();
return;
}
}
_fw.flush();
_fw.close();
}
else
{
qDebug() << "Failed to perform http request" << _reply->url();
_fw.remove();
}
}
void Download::decompress(QByteArray &data)
@@ -413,7 +429,9 @@ void Download::decompress(QByteArray &data)
HttpDownloader::HttpDownloader(QObject *parent) : QObject(parent)
,_manager(new QNetworkAccessManager(this))
{
_manager->setAutoDeleteReplies(true);
connect(_manager, &QNetworkAccessManager::finished, this, &HttpDownloader::finished);
#ifdef PLATESOLVER
QDir dir(Solver::getTenmonIndexPath());
if(!dir.exists())
{
@@ -422,6 +440,7 @@ HttpDownloader::HttpDownloader(QObject *parent) : QObject(parent)
}
_indexPath = dir.absolutePath();
#endif
}
void HttpDownloader::download(const QUrl &url)
@@ -437,17 +456,17 @@ bool HttpDownloader::downloadIndex(int scale)
return false;
QUrl url("https://nouspiro.space/");
QStringList files = indexFileNames(scale);
if(scale >= 7)
for(auto &file : files)
{
url.setPath(QString("/astrometry/index-%1.fits.zst").arg(4100 + scale));
download(url);
}
else
{
for(int i=0; i<48; i++)
if(QFile::exists(_indexPath + "/" + file))
{
url.setPath(QString("/astrometry/index-%1-%2.fits.zst").arg(5200 + scale).arg(i, 2, 10, QChar('0')));
qDebug() << "File already exists, skipping" << file;
}
else
{
url.setPath("/astrometry/" + file + ".zst");
download(url);
}
}
@@ -460,6 +479,22 @@ void HttpDownloader::abort()
_download->abort();
}
QStringList HttpDownloader::indexFileNames(int scale)
{
QStringList ret;
if(scale >= 7)
{
ret.append(QString("index-%1.fits").arg(4100 + scale));
}
else
{
for(int i=0; i<48; i++)
ret.append(QString("index-%1-%2.fits").arg(5200 + scale).arg(i, 2, 10, QChar('0')));
}
return ret;
}
void HttpDownloader::finished()
{
if(_queue.isEmpty())
@@ -478,7 +513,6 @@ void HttpDownloader::finished()
return;
}
QNetworkRequest request(url);
_download->deleteLater();
_download = new Download(_manager->get(request), _indexPath, this);
connect(_download, &Download::progress, this, &HttpDownloader::updateProgress);
}