satdump/plugins/firstparty_support/old/off2pro/module_off2pro.cpp

97 lines
3.6 KiB
C++
Raw Permalink Normal View History

2024-09-29 18:19:19 +02:00
#include "module_off2pro.h"
#include "common/utils.h"
2024-09-29 18:19:19 +02:00
#include "logger.h"
2025-07-23 12:21:02 +02:00
#include "products/dataset.h"
2024-09-29 18:19:19 +02:00
#include "../file_utils/file_utils.h"
#include "../nc2pro/sc3/sc3_olci.h"
#include "../nc2pro/sc3/sc3_slstr.h"
2024-09-29 18:19:19 +02:00
#include "../nc2pro/jpss/jpss_viirs.h"
2024-12-06 19:45:48 +01:00
2025-08-11 12:22:29 +02:00
#include "../../procfile.h"
2024-09-29 18:19:19 +02:00
namespace off2pro
{
Off2ProModule::Off2ProModule(std::string input_file, std::string output_file_hint, nlohmann::json parameters) : ProcessingModule(input_file, output_file_hint, parameters) {}
2024-09-29 18:19:19 +02:00
void Off2ProModule::process()
{
std::string source_off_file = d_input_file;
std::string pro_output_file = d_output_file_hint.substr(0, d_output_file_hint.rfind('/')) + "/";
2025-08-12 13:42:31 +02:00
auto info = satdump::firstparty::identifyFirstPartyProductFile(source_off_file);
2025-08-11 12:22:29 +02:00
2025-08-12 13:42:31 +02:00
auto products = satdump::firstparty::processFirstPartyProductFile(info, source_off_file);
2025-08-11 12:22:29 +02:00
products->save(pro_output_file);
d_output_file = pro_output_file + "/product.cbor";
#if 0 // TODOREWORK
2024-09-29 18:19:19 +02:00
filesize = getFilesize(source_off_file);
2024-12-12 22:51:48 -05:00
std::filesystem::path source_off_path(source_off_file);
2024-09-29 18:19:19 +02:00
2024-10-04 15:54:15 +02:00
std::vector<std::string> product_paths;
2024-09-29 18:19:19 +02:00
// Perhaps a zip?
if (satdump::file_is_zip(source_off_file))
{
std::string eum_id = satdump::try_get_eumetsat_id(source_off_file);
// Sentinel-3 OCLI
if (eum_id.find("SEN3") != std::string::npos && eum_id.find("OL_1_EF") != std::string::npos)
2024-09-29 18:19:19 +02:00
nc2pro::process_sc3_ocli(source_off_file, pro_output_file, &progress);
2024-10-04 15:54:15 +02:00
else if (eum_id.find("SEN3") != std::string::npos && eum_id.find("SL_1_RBT") != std::string::npos)
nc2pro::process_sc3_slstr(source_off_file, pro_output_file, product_paths, &progress);
2024-09-29 18:19:19 +02:00
else
logger->error("Unknown EUMETSAT file type! " + eum_id);
}
2024-12-12 22:51:48 -05:00
else if (source_off_path.extension() == ".nc")
{
std::string prefix = source_off_path.stem().string().substr(0, 14);
std::string prefix2 = source_off_path.stem().string().substr(0, 5);
2025-07-25 22:56:19 +02:00
if (prefix2 == "VNP02")
nc2pro::process_jpss_viirs(source_off_file, pro_output_file, &progress);
2024-12-12 22:51:48 -05:00
else
logger->error("Unknown .nc file type!");
}
2024-09-29 18:19:19 +02:00
2025-07-16 12:56:24 +02:00
if (/*std::filesystem::exists(pro_output_file + "/product.cbor") ||*/ product_paths.size() > 0)
2024-09-29 18:19:19 +02:00
{
// Products dataset
2025-03-14 11:12:18 +01:00
satdump::products::DataSet dataset;
2024-09-29 18:19:19 +02:00
dataset.satellite_name = "Generic Product (Data Store / Archive)";
dataset.timestamp = time(0); // avg_overflowless(avhrr_reader.timestamps);
2024-10-04 15:54:15 +02:00
if (product_paths.size() == 0)
dataset.products_list.push_back(".");
else
dataset.products_list = product_paths;
2024-09-29 18:19:19 +02:00
dataset.save(d_output_file_hint.substr(0, d_output_file_hint.rfind('/')));
2025-07-16 12:56:24 +02:00
d_output_file = pro_output_file + "/dataset.json";
}
else if (std::filesystem::exists(pro_output_file + "/product.cbor"))
{
d_output_file = pro_output_file + "/product.cbor";
2024-09-29 18:19:19 +02:00
}
2025-08-11 12:22:29 +02:00
#endif
2024-09-29 18:19:19 +02:00
}
void Off2ProModule::drawUI(bool window)
{
ImGui::Begin("Data Format To Products", NULL, window ? 0 : NOWINDOW_FLAGS);
ImGui::ProgressBar(progress);
ImGui::End();
}
std::string Off2ProModule::getID() { return "off2pro"; }
2024-09-29 18:19:19 +02:00
std::shared_ptr<satdump::pipeline::ProcessingModule> Off2ProModule::getInstance(std::string input_file, std::string output_file_hint, nlohmann::json parameters)
2024-09-29 18:19:19 +02:00
{
return std::make_shared<Off2ProModule>(input_file, output_file_hint, parameters);
}
} // namespace off2pro