From e904fcd2e8285fa30dfd6d2008cf11bf176e22e8 Mon Sep 17 00:00:00 2001 From: Aang23 Date: Fri, 1 Apr 2022 12:51:36 +0200 Subject: [PATCH] Merge PROBA Decoders. Cleanup still to be done --- pipelines/Proba.json | 7 +- plugins/proba_support/main.cpp | 8 +- .../proba/instruments/chris/chris_reader.cpp | 43 +--- .../proba/instruments/chris/chris_reader.h | 8 +- .../instruments/chris/module_proba_chris.cpp | 119 ---------- .../instruments/chris/module_proba_chris.h | 27 --- .../proba/instruments/hrc/hrc_reader.cpp | 16 +- .../proba/instruments/hrc/hrc_reader.h | 6 +- .../instruments/hrc/module_proba_hrc.cpp | 116 --------- .../proba/instruments/hrc/module_proba_hrc.h | 27 --- .../instruments/swap/module_proba_swap.cpp | 115 --------- .../instruments/swap/module_proba_swap.h | 27 --- .../proba/instruments/swap/swap_reader.h | 4 +- .../proba/module_proba_instruments.cpp | 224 ++++++++++++++++++ .../proba/module_proba_instruments.h | 49 ++++ 15 files changed, 307 insertions(+), 489 deletions(-) delete mode 100644 plugins/proba_support/proba/instruments/chris/module_proba_chris.cpp delete mode 100644 plugins/proba_support/proba/instruments/chris/module_proba_chris.h delete mode 100644 plugins/proba_support/proba/instruments/hrc/module_proba_hrc.cpp delete mode 100644 plugins/proba_support/proba/instruments/hrc/module_proba_hrc.h delete mode 100644 plugins/proba_support/proba/instruments/swap/module_proba_swap.cpp delete mode 100644 plugins/proba_support/proba/instruments/swap/module_proba_swap.h create mode 100644 plugins/proba_support/proba/module_proba_instruments.cpp create mode 100644 plugins/proba_support/proba/module_proba_instruments.h diff --git a/pipelines/Proba.json b/pipelines/Proba.json index 5d2ad6526..ffffb3f5a 100644 --- a/pipelines/Proba.json +++ b/pipelines/Proba.json @@ -42,7 +42,8 @@ } }, "products": { - "proba_chris": { + "proba_instruments": { + "satellite": "proba1", "composites_low": { "RGB-080502": { "channels": [ @@ -179,7 +180,9 @@ } }, "products": { - "proba_swap": {} + "proba_instruments": { + "satellite": "proba2" + } } } }, diff --git a/plugins/proba_support/main.cpp b/plugins/proba_support/main.cpp index 91af5e275..f7fbb8ac6 100644 --- a/plugins/proba_support/main.cpp +++ b/plugins/proba_support/main.cpp @@ -2,9 +2,7 @@ #include "logger.h" #include "core/module.h" -#include "proba/instruments/swap/module_proba_swap.h" -#include "proba/instruments/chris/module_proba_chris.h" -#include "proba/instruments/hrc/module_proba_hrc.h" +#include "proba/module_proba_instruments.h" class ProbaSupport : public satdump::Plugin { @@ -21,9 +19,7 @@ public: static void registerPluginsHandler(const RegisterModulesEvent &evt) { - REGISTER_MODULE_EXTERNAL(evt.modules_registry, proba::swap::ProbaSWAPDecoderModule); - REGISTER_MODULE_EXTERNAL(evt.modules_registry, proba::chris::ProbaCHRISDecoderModule); - REGISTER_MODULE_EXTERNAL(evt.modules_registry, proba::hrc::ProbaHRCDecoderModule); + REGISTER_MODULE_EXTERNAL(evt.modules_registry, proba::instruments::PROBAInstrumentsDecoderModule); } }; diff --git a/plugins/proba_support/proba/instruments/chris/chris_reader.cpp b/plugins/proba_support/proba/instruments/chris/chris_reader.cpp index a263b836d..95ab23e5c 100644 --- a/plugins/proba_support/proba/instruments/chris/chris_reader.cpp +++ b/plugins/proba_support/proba/instruments/chris/chris_reader.cpp @@ -4,6 +4,7 @@ #include #include "logger.h" #include "common/image/composite.h" +#include "common/utils.h" #define ALL_MODE 2 #define WATER_MODE 3 @@ -11,26 +12,6 @@ #define CHLOROPHYL_MODE 3 #define LAND_ALL_MODE 100 // Never seen yet... -#define WRITE_IMAGE_LOCAL(image, path) \ - image.save_png(std::string(path).c_str()); \ - all_images.push_back(path); - -template ::value_type> -T most_common(InputIt begin, InputIt end) -{ - std::map counts; - for (InputIt it = begin; it != end; ++it) - { - if (counts.find(*it) != counts.end()) - ++counts[*it]; - else - counts[*it] = 1; - } - return std::max_element(counts.begin(), counts.end(), [](const std::pair &pair1, const std::pair &pair2) - { return pair1.second < pair2.second; }) - ->first; -} - namespace proba { namespace chris @@ -41,7 +22,7 @@ namespace proba output_folder = outputfolder; } - CHRISImageParser::CHRISImageParser(int &count, std::string &outputfolder, std::vector &a_images) : count_ref(count), all_images(a_images) + CHRISImageParser::CHRISImageParser(int &count, std::string &outputfolder) : count_ref(count) { tempChannelBuffer = new unsigned short[748 * 12096]; mode = 0; @@ -64,10 +45,10 @@ namespace proba int tx_mode = (packet.payload[2] & 0b00000011) << 2 | packet.payload[3] >> 6; - //logger->info("CH " << channel_marker ); - //logger->info("CNT " << count_marker ); - //logger->info("MODE " << mode_marker ); - //logger->info("TMD " << tx_mode ); + // logger->info("CH " << channel_marker ); + // logger->info("CNT " << count_marker ); + // logger->info("MODE " << mode_marker ); + // logger->info("TMD " << tx_mode ); int posb = 16; @@ -162,13 +143,13 @@ namespace proba int channel_marker = (packet.payload[8 - 6] % (int)pow(2, 3)) << 1 | packet.payload[9 - 6] >> 7; - //logger->info("CH " << channel_marker ); + // logger->info("CH " << channel_marker ); // Start new image if (imageParsers.find(channel_marker) == imageParsers.end()) { logger->info("Found new CHRIS image! Marker " + std::to_string(channel_marker)); - imageParsers.insert(std::pair>(channel_marker, std::make_shared(count, output_folder, all_images))); + imageParsers.insert(std::pair>(channel_marker, std::make_shared(count, output_folder))); imageParsers[channel_marker]->composites_all = composites_all; imageParsers[channel_marker]->composites_low = composites_low; } @@ -182,8 +163,8 @@ namespace proba { logger->info("Finished CHRIS image! Saving as CHRIS-" + std::to_string(count_ref) + ".png. Mode " + getModeName(mode)); image::Image img = image::Image(tempChannelBuffer, current_width, current_height, 1); - img.normalize(); - WRITE_IMAGE_LOCAL(img, output_folder + "/CHRIS-" + std::to_string(count_ref) + ".png"); + // img.normalize(); + img.save_png(output_folder + "/CHRIS-" + std::to_string(count_ref) + ".png"); if (mode == ALL_MODE) writeAllCompos(img); @@ -231,7 +212,7 @@ namespace proba expression, compositeDef); - WRITE_IMAGE_LOCAL(compositeImage, output_folder + "/" + name + ".png"); + compositeImage.save_png(output_folder + "/" + name + ".png"); } } @@ -263,7 +244,7 @@ namespace proba expression, compositeDef); - WRITE_IMAGE_LOCAL(compositeImage, output_folder + "/" + name + ".png"); + compositeImage.save_png(output_folder + "/" + name + ".png"); } } diff --git a/plugins/proba_support/proba/instruments/chris/chris_reader.h b/plugins/proba_support/proba/instruments/chris/chris_reader.h index 8d76bf957..70ccbd836 100644 --- a/plugins/proba_support/proba/instruments/chris/chris_reader.h +++ b/plugins/proba_support/proba/instruments/chris/chris_reader.h @@ -23,15 +23,13 @@ namespace proba int frame_count; std::string output_folder; - std::vector &all_images; - private: void writeHighResCompos(image::Image &img); void writeAllCompos(image::Image &img); std::string getModeName(int mode); public: - CHRISImageParser(int &count, std::string &outputfolder, std::vector &a_images); + CHRISImageParser(int &count, std::string &outputfolder); ~CHRISImageParser(); void save(); void work(ccsds::CCSDSPacket &packet, int &ch); @@ -43,16 +41,16 @@ namespace proba class CHRISReader { private: - int count; std::map> imageParsers; std::string output_folder; public: - std::vector all_images; CHRISReader(std::string &outputfolder); void work(ccsds::CCSDSPacket &packet); void save(); + int count; + nlohmann::json composites_all; nlohmann::json composites_low; }; diff --git a/plugins/proba_support/proba/instruments/chris/module_proba_chris.cpp b/plugins/proba_support/proba/instruments/chris/module_proba_chris.cpp deleted file mode 100644 index 606edea79..000000000 --- a/plugins/proba_support/proba/instruments/chris/module_proba_chris.cpp +++ /dev/null @@ -1,119 +0,0 @@ -#include "module_proba_chris.h" -#include -#include "chris_reader.h" -#include "common/ccsds/ccsds_1_0_proba/demuxer.h" -#include "common/ccsds/ccsds_1_0_proba/vcdu.h" -#include "logger.h" -#include -#include "imgui/imgui.h" - -// Return filesize -size_t getFilesize(std::string filepath); - -namespace proba -{ - namespace chris - { - ProbaCHRISDecoderModule::ProbaCHRISDecoderModule(std::string input_file, std::string output_file_hint, nlohmann::json parameters) : ProcessingModule(input_file, output_file_hint, parameters) - { - } - - void ProbaCHRISDecoderModule::process() - { - filesize = getFilesize(d_input_file); - std::ifstream data_in(d_input_file, std::ios::binary); - - std::string directory = d_output_file_hint.substr(0, d_output_file_hint.rfind('/')) + "/CHRIS"; - - if (!std::filesystem::exists(directory)) - std::filesystem::create_directory(directory); - - logger->info("Using input frames " + d_input_file); - logger->info("Decoding to " + directory); - - time_t lastTime = 0; - - uint8_t buffer[1279]; - - // CCSDS Demuxer - ccsds::ccsds_1_0_proba::Demuxer ccsdsDemuxer(1103, false); - - CHRISReader chris_reader(directory); - - chris_reader.composites_all = d_parameters["composites_all"]; - chris_reader.composites_low = d_parameters["composites_low"]; - - logger->info("Demultiplexing and deframing..."); - - while (!data_in.eof()) - { - // Read buffer - data_in.read((char *)buffer, 1279); - - int vcid = ccsds::ccsds_1_0_proba::parseVCDU(buffer).vcid; - - if (vcid == 1) - { - std::vector pkts = ccsdsDemuxer.work(buffer); - - if (pkts.size() > 0) - { - for (ccsds::CCSDSPacket pkt : pkts) - { - if (pkt.header.apid == 2047) - continue; - - if (pkt.header.apid == 0) - { - int mode_marker = pkt.payload[9] & 0x03; - if (mode_marker != 1) - chris_reader.work(pkt); - - //if (pkt.payload.size() >= 11538) - // data_out.write((char *)pkt.payload.data(), 11538); - } - } - } - } - - progress = data_in.tellg(); - - if (time(NULL) % 10 == 0 && lastTime != time(NULL)) - { - lastTime = time(NULL); - logger->info("Progress " + std::to_string(round(((float)progress / (float)filesize) * 1000.0f) / 10.0f) + "%"); - } - } - - data_in.close(); - - chris_reader.save(); - - d_output_files = chris_reader.all_images; - } - - void ProbaCHRISDecoderModule::drawUI(bool window) - { - ImGui::Begin("Proba-1 CHRIS Decoder", NULL, window ? NULL : NOWINDOW_FLAGS); - - ImGui::ProgressBar((float)progress / (float)filesize, ImVec2(ImGui::GetWindowWidth() - 10, 20 * ui_scale)); - - ImGui::End(); - } - - std::string ProbaCHRISDecoderModule::getID() - { - return "proba_chris"; - } - - std::vector ProbaCHRISDecoderModule::getParameters() - { - return {}; - } - - std::shared_ptr ProbaCHRISDecoderModule::getInstance(std::string input_file, std::string output_file_hint, nlohmann::json parameters) - { - return std::make_shared(input_file, output_file_hint, parameters); - } - } // namespace chris -} // namespace proba \ No newline at end of file diff --git a/plugins/proba_support/proba/instruments/chris/module_proba_chris.h b/plugins/proba_support/proba/instruments/chris/module_proba_chris.h deleted file mode 100644 index 414a37617..000000000 --- a/plugins/proba_support/proba/instruments/chris/module_proba_chris.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include "core/module.h" - -namespace proba -{ - namespace chris - { - class ProbaCHRISDecoderModule : public ProcessingModule - { - protected: - std::atomic filesize; - std::atomic progress; - - public: - ProbaCHRISDecoderModule(std::string input_file, std::string output_file_hint, nlohmann::json parameters); - void process(); - void drawUI(bool window); - - public: - static std::string getID(); - virtual std::string getIDM() { return getID(); }; - static std::vector getParameters(); - static std::shared_ptr getInstance(std::string input_file, std::string output_file_hint, nlohmann::json parameters); - }; - } // namespace avhrr -} // namespace noaa \ No newline at end of file diff --git a/plugins/proba_support/proba/instruments/hrc/hrc_reader.cpp b/plugins/proba_support/proba/instruments/hrc/hrc_reader.cpp index d05bac60d..fbe153ab0 100644 --- a/plugins/proba_support/proba/instruments/hrc/hrc_reader.cpp +++ b/plugins/proba_support/proba/instruments/hrc/hrc_reader.cpp @@ -1,11 +1,5 @@ #include "hrc_reader.h" -#include -#include -#include - -#define WRITE_IMAGE_LOCAL(image, path) \ - image.save_png(std::string(path).c_str()); \ - all_images.push_back(path); +#include "logger.h" namespace proba { @@ -75,14 +69,14 @@ namespace proba { if (frame_count != 0) { - std::cout << "Finished HRC image! Saving as HRC-" + std::to_string(count) + ".png" << std::endl; + logger->info("Finished HRC image! Saving as HRC-" + std::to_string(count) + ".png"); image::Image img = image::Image(tempChannelBuffer, 1072, 1072, 1); + img.save_png(output_folder + "/HRC-" + std::to_string(count) + ".png"); img.normalize(); - WRITE_IMAGE_LOCAL(img, output_folder + "/HRC-" + std::to_string(count) + ".png"); img.equalize(); - WRITE_IMAGE_LOCAL(img, output_folder + "/HRC-" + std::to_string(count) + "-EQU.png"); + img.save_png(output_folder + "/HRC-" + std::to_string(count) + "-EQU.png"); - std::fill(&tempChannelBuffer[0], &tempChannelBuffer[748 * 12096], 0); + std::fill(&tempChannelBuffer[0], &tempChannelBuffer[74800 * 12096], 0); count++; } } diff --git a/plugins/proba_support/proba/instruments/hrc/hrc_reader.h b/plugins/proba_support/proba/instruments/hrc/hrc_reader.h index 9f85f8cc1..79849dd1a 100644 --- a/plugins/proba_support/proba/instruments/hrc/hrc_reader.h +++ b/plugins/proba_support/proba/instruments/hrc/hrc_reader.h @@ -13,14 +13,16 @@ namespace proba { private: unsigned short *tempChannelBuffer; - int count; + int frame_count; std::string output_folder; public: - std::vector all_images; HRCReader(std::string &outputfolder); ~HRCReader(); + + int count; + void save(); void work(ccsds::CCSDSPacket &packet); }; diff --git a/plugins/proba_support/proba/instruments/hrc/module_proba_hrc.cpp b/plugins/proba_support/proba/instruments/hrc/module_proba_hrc.cpp deleted file mode 100644 index 656c01080..000000000 --- a/plugins/proba_support/proba/instruments/hrc/module_proba_hrc.cpp +++ /dev/null @@ -1,116 +0,0 @@ -#include "module_proba_hrc.h" -#include -#include "hrc_reader.h" -#include "common/ccsds/ccsds_1_0_proba/demuxer.h" -#include "common/ccsds/ccsds_1_0_proba/vcdu.h" -#include "logger.h" -#include -#include "imgui/imgui.h" - -// Return filesize -size_t getFilesize(std::string filepath); - -namespace proba -{ - namespace hrc - { - ProbaHRCDecoderModule::ProbaHRCDecoderModule(std::string input_file, std::string output_file_hint, nlohmann::json parameters) : ProcessingModule(input_file, output_file_hint, parameters) - { - } - - void ProbaHRCDecoderModule::process() - { - filesize = getFilesize(d_input_file); - std::ifstream data_in(d_input_file, std::ios::binary); - - std::string directory = d_output_file_hint.substr(0, d_output_file_hint.rfind('/')) + "/HRC"; - - if (!std::filesystem::exists(directory)) - std::filesystem::create_directory(directory); - - logger->info("Using input frames " + d_input_file); - logger->info("Decoding to " + directory); - - time_t lastTime = 0; - - uint8_t buffer[1279]; - - // CCSDS Demuxer - ccsds::ccsds_1_0_proba::Demuxer ccsdsDemuxer(1103, false); - - HRCReader hrc_reader(directory); - - logger->info("Demultiplexing and deframing..."); - - while (!data_in.eof()) - { - // Read buffer - data_in.read((char *)buffer, 1279); - - int vcid = ccsds::ccsds_1_0_proba::parseVCDU(buffer).vcid; - - if (vcid == 1) - { - std::vector pkts = ccsdsDemuxer.work(buffer); - - if (pkts.size() > 0) - { - for (ccsds::CCSDSPacket pkt : pkts) - { - if (pkt.header.apid == 2047) - continue; - - if (pkt.header.apid == 0) - { - int mode_marker = pkt.payload[9] & 0x03; - if (mode_marker == 1) - hrc_reader.work(pkt); - - //if (pkt.payload.size() >= 11538) - // data_out.write((char *)pkt.payload.data(), 11538); - } - } - } - } - - progress = data_in.tellg(); - - if (time(NULL) % 10 == 0 && lastTime != time(NULL)) - { - lastTime = time(NULL); - logger->info("Progress " + std::to_string(round(((float)progress / (float)filesize) * 1000.0f) / 10.0f) + "%"); - } - } - - data_in.close(); - - hrc_reader.save(); - - d_output_files = hrc_reader.all_images; - } - - void ProbaHRCDecoderModule::drawUI(bool window) - { - ImGui::Begin("Proba-1 HRC Decoder", NULL, window ? NULL : NOWINDOW_FLAGS); - - ImGui::ProgressBar((float)progress / (float)filesize, ImVec2(ImGui::GetWindowWidth() - 10, 20 * ui_scale)); - - ImGui::End(); - } - - std::string ProbaHRCDecoderModule::getID() - { - return "proba_hrc"; - } - - std::vector ProbaHRCDecoderModule::getParameters() - { - return {}; - } - - std::shared_ptr ProbaHRCDecoderModule::getInstance(std::string input_file, std::string output_file_hint, nlohmann::json parameters) - { - return std::make_shared(input_file, output_file_hint, parameters); - } - } // namespace hrc -} // namespace proba \ No newline at end of file diff --git a/plugins/proba_support/proba/instruments/hrc/module_proba_hrc.h b/plugins/proba_support/proba/instruments/hrc/module_proba_hrc.h deleted file mode 100644 index cd7fd93fc..000000000 --- a/plugins/proba_support/proba/instruments/hrc/module_proba_hrc.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include "core/module.h" - -namespace proba -{ - namespace hrc - { - class ProbaHRCDecoderModule : public ProcessingModule - { - protected: - std::atomic filesize; - std::atomic progress; - - public: - ProbaHRCDecoderModule(std::string input_file, std::string output_file_hint, nlohmann::json parameters); - void process(); - void drawUI(bool window); - - public: - static std::string getID(); - virtual std::string getIDM() { return getID(); }; - static std::vector getParameters(); - static std::shared_ptr getInstance(std::string input_file, std::string output_file_hint, nlohmann::json parameters); - }; - } // namespace hrc -} // namespace proba \ No newline at end of file diff --git a/plugins/proba_support/proba/instruments/swap/module_proba_swap.cpp b/plugins/proba_support/proba/instruments/swap/module_proba_swap.cpp deleted file mode 100644 index 5955bcd8f..000000000 --- a/plugins/proba_support/proba/instruments/swap/module_proba_swap.cpp +++ /dev/null @@ -1,115 +0,0 @@ -#include "module_proba_swap.h" -#include -#include "swap_reader.h" -#include "common/ccsds/ccsds_1_0_proba/demuxer.h" -#include "common/ccsds/ccsds_1_0_proba/vcdu.h" -#include "logger.h" -#include -#include "imgui/imgui.h" - -#define WRITE_IMAGE_LOCAL(image, path) \ - image.save_png(std::string(path).c_str()); \ - all_images.push_back(path); - -// Return filesize -size_t getFilesize(std::string filepath); - -namespace proba -{ - namespace swap - { - ProbaSWAPDecoderModule::ProbaSWAPDecoderModule(std::string input_file, std::string output_file_hint, nlohmann::json parameters) : ProcessingModule(input_file, output_file_hint, parameters) - { - } - - void ProbaSWAPDecoderModule::process() - { - filesize = getFilesize(d_input_file); - std::ifstream data_in(d_input_file, std::ios::binary); - - std::string directory = d_output_file_hint.substr(0, d_output_file_hint.rfind('/')) + "/SWAP"; - - if (!std::filesystem::exists(directory)) - std::filesystem::create_directory(directory); - - logger->info("Using input frames " + d_input_file); - logger->info("Decoding to " + directory); - - time_t lastTime = 0; - - uint8_t buffer[1279]; - - // CCSDS Demuxer - ccsds::ccsds_1_0_proba::Demuxer ccsdsDemuxer(1103, false); - - SWAPReader swap_reader(directory); - - logger->info("Demultiplexing and deframing..."); - - while (!data_in.eof()) - { - // Read buffer - data_in.read((char *)buffer, 1279); - - int vcid = ccsds::ccsds_1_0_proba::parseVCDU(buffer).vcid; - - if (vcid == 3) - { - std::vector pkts = ccsdsDemuxer.work(buffer); - - if (pkts.size() > 0) - { - for (ccsds::CCSDSPacket pkt : pkts) - { - if (pkt.header.apid == 2047) - continue; - - if (pkt.header.apid == 20) - { - swap_reader.work(pkt); - } - } - } - } - - progress = data_in.tellg(); - - if (time(NULL) % 10 == 0 && lastTime != time(NULL)) - { - lastTime = time(NULL); - logger->info("Progress " + std::to_string(round(((float)progress / (float)filesize) * 1000.0f) / 10.0f) + "%"); - } - } - - data_in.close(); - - swap_reader.save(); - - d_output_files = swap_reader.all_images; - } - - void ProbaSWAPDecoderModule::drawUI(bool window) - { - ImGui::Begin("Proba-2 SWAP Decoder", NULL, window ? NULL : NOWINDOW_FLAGS); - - ImGui::ProgressBar((float)progress / (float)filesize, ImVec2(ImGui::GetWindowWidth() - 10, 20 * ui_scale)); - - ImGui::End(); - } - - std::string ProbaSWAPDecoderModule::getID() - { - return "proba_swap"; - } - - std::vector ProbaSWAPDecoderModule::getParameters() - { - return {}; - } - - std::shared_ptr ProbaSWAPDecoderModule::getInstance(std::string input_file, std::string output_file_hint, nlohmann::json parameters) - { - return std::make_shared(input_file, output_file_hint, parameters); - } - } // namespace swap -} // namespace proba \ No newline at end of file diff --git a/plugins/proba_support/proba/instruments/swap/module_proba_swap.h b/plugins/proba_support/proba/instruments/swap/module_proba_swap.h deleted file mode 100644 index 2240f8834..000000000 --- a/plugins/proba_support/proba/instruments/swap/module_proba_swap.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include "core/module.h" - -namespace proba -{ - namespace swap - { - class ProbaSWAPDecoderModule : public ProcessingModule - { - protected: - std::atomic filesize; - std::atomic progress; - - public: - ProbaSWAPDecoderModule(std::string input_file, std::string output_file_hint, nlohmann::json parameters); - void process(); - void drawUI(bool window); - - public: - static std::string getID(); - virtual std::string getIDM() { return getID(); }; - static std::vector getParameters(); - static std::shared_ptr getInstance(std::string input_file, std::string output_file_hint, nlohmann::json parameters); - }; - } // namespace avhrr -} // namespace noaa \ No newline at end of file diff --git a/plugins/proba_support/proba/instruments/swap/swap_reader.h b/plugins/proba_support/proba/instruments/swap/swap_reader.h index 5d151bc52..287f5759a 100644 --- a/plugins/proba_support/proba/instruments/swap/swap_reader.h +++ b/plugins/proba_support/proba/instruments/swap/swap_reader.h @@ -11,13 +11,15 @@ namespace proba class SWAPReader { private: - int count; std::map>>> currentOuts; std::string output_folder; public: std::vector all_images; SWAPReader(std::string &outputfolder); + + int count; + void work(ccsds::CCSDSPacket &packet); void save(); }; diff --git a/plugins/proba_support/proba/module_proba_instruments.cpp b/plugins/proba_support/proba/module_proba_instruments.cpp new file mode 100644 index 000000000..241091701 --- /dev/null +++ b/plugins/proba_support/proba/module_proba_instruments.cpp @@ -0,0 +1,224 @@ +#include "module_proba_instruments.h" +#include +#include "common/ccsds/ccsds_1_0_proba/vcdu.h" +#include "logger.h" +#include +#include "imgui/imgui.h" +#include "common/utils.h" +#include "common/image/bowtie.h" +#include "common/ccsds/ccsds_1_0_proba/demuxer.h" +#include "products/products.h" + +namespace proba +{ + namespace instruments + { + PROBAInstrumentsDecoderModule::PROBAInstrumentsDecoderModule(std::string input_file, std::string output_file_hint, nlohmann::json parameters) + : ProcessingModule(input_file, output_file_hint, parameters) + { + if (parameters["satellite"] == "proba1") + d_satellite = PROBA_1; + else if (parameters["satellite"] == "proba2") + d_satellite = PROBA_2; + else if (parameters["satellite"] == "probaV") + d_satellite = PROBA_V; + else + throw std::runtime_error("Proba Instruments Decoder : Proba satellite \"" + parameters["satellite"].get() + "\" is not valid!"); + + // Init readers + if (d_satellite == PROBA_1) + { + std::string chris_directory = d_output_file_hint.substr(0, d_output_file_hint.rfind('/')) + "/CHRIS"; + std::string hrc_directory = d_output_file_hint.substr(0, d_output_file_hint.rfind('/')) + "/HRC"; + + if (!std::filesystem::exists(chris_directory)) + std::filesystem::create_directory(chris_directory); + if (!std::filesystem::exists(hrc_directory)) + std::filesystem::create_directory(hrc_directory); + + chris_reader = std::make_unique(chris_directory); + hrc_reader = std::make_unique(hrc_directory); + + chris_reader->composites_all = d_parameters["composites_all"]; + chris_reader->composites_low = d_parameters["composites_low"]; + } + else if (d_satellite == PROBA_2) + { + std::string swap_directory = d_output_file_hint.substr(0, d_output_file_hint.rfind('/')) + "/SWAP"; + + if (!std::filesystem::exists(swap_directory)) + std::filesystem::create_directory(swap_directory); + + swap_reader = std::make_unique(swap_directory); + } + } + + void PROBAInstrumentsDecoderModule::process() + { + filesize = getFilesize(d_input_file); + std::ifstream data_in(d_input_file, std::ios::binary); + + logger->info("Using input frames " + d_input_file); + + time_t lastTime = 0; + uint8_t cadu[1279]; + + // Demuxers + ccsds::ccsds_1_0_proba::Demuxer demuxer_vcid1(1103, false); + ccsds::ccsds_1_0_proba::Demuxer demuxer_vcid3(1103, false); + + while (!data_in.eof()) + { + // Read buffer + data_in.read((char *)&cadu, 1279); + + // Parse this transport frame + ccsds::ccsds_1_0_proba::VCDU vcdu = ccsds::ccsds_1_0_proba::parseVCDU(cadu); + + if (vcdu.vcid == 1) // Replay VCID + { + std::vector ccsdsFrames = demuxer_vcid1.work(cadu); + for (ccsds::CCSDSPacket &pkt : ccsdsFrames) + { + if (d_satellite == PROBA_1) + { + if (pkt.header.apid == 0) + { + int mode_marker = pkt.payload[9] & 0x03; + if (mode_marker == 1) + hrc_reader->work(pkt); + else + chris_reader->work(pkt); + } + } + } + } + else if (vcdu.vcid == 3) // SWAP VCID + { + std::vector ccsdsFrames = demuxer_vcid3.work(cadu); + for (ccsds::CCSDSPacket &pkt : ccsdsFrames) + { + if (d_satellite == PROBA_2) + if (pkt.header.apid == 20) + swap_reader->work(pkt); + } + } + + progress = data_in.tellg(); + if (time(NULL) % 10 == 0 && lastTime != time(NULL)) + { + lastTime = time(NULL); + logger->info("Progress " + std::to_string(round(((float)progress / (float)filesize) * 1000.0f) / 10.0f) + "%"); + } + } + + data_in.close(); + + // CHRIS + if (d_satellite == PROBA_1) + { + chris_status = SAVING; + + logger->info("----------- CHRIS"); + logger->info("Images : {:d}", chris_reader->count); + + chris_reader->save(); + + chris_status = DONE; + } + + // HRC + if (d_satellite == PROBA_1) + { + hrc_status = SAVING; + + logger->info("----------- HRC"); + logger->info("Images : {:d}", hrc_reader->count); + + hrc_reader->save(); + + hrc_status = DONE; + } + + // HRC + if (d_satellite == PROBA_2) + { + swap_status = SAVING; + + logger->info("----------- SWAP"); + logger->info("Images : {:d}", swap_reader->count); + + swap_reader->save(); + + swap_status = DONE; + } + } + + void PROBAInstrumentsDecoderModule::drawUI(bool window) + { + ImGui::Begin("Proba Instruments Decoder", NULL, window ? NULL : NOWINDOW_FLAGS); + + if (ImGui::BeginTable("##probainstrumentstable", 3, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg)) + { + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); + ImGui::Text("Instrument"); + ImGui::TableSetColumnIndex(1); + ImGui::Text("Images / Frames"); + ImGui::TableSetColumnIndex(2); + ImGui::Text("Status"); + + if (d_satellite == PROBA_1) + { + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); + ImGui::Text("CHRIS"); + ImGui::TableSetColumnIndex(1); + ImGui::TextColored(ImColor(0, 255, 0), "%d", chris_reader->count); + ImGui::TableSetColumnIndex(2); + drawStatus(chris_status); + + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); + ImGui::Text("HRC"); + ImGui::TableSetColumnIndex(1); + ImGui::TextColored(ImColor(0, 255, 0), "%d", hrc_reader->count); + ImGui::TableSetColumnIndex(2); + drawStatus(hrc_status); + } + + if (d_satellite == PROBA_2) + { + ImGui::TableNextRow(); + ImGui::TableSetColumnIndex(0); + ImGui::Text("SWAP"); + ImGui::TableSetColumnIndex(1); + ImGui::TextColored(ImColor(0, 255, 0), "%d", swap_reader->count); + ImGui::TableSetColumnIndex(2); + drawStatus(swap_status); + } + + ImGui::EndTable(); + } + + ImGui::ProgressBar((float)progress / (float)filesize, ImVec2(ImGui::GetWindowWidth() - 10, 20 * ui_scale)); + + ImGui::End(); + } + + std::string PROBAInstrumentsDecoderModule::getID() + { + return "proba_instruments"; + } + + std::vector PROBAInstrumentsDecoderModule::getParameters() + { + return {}; + } + + std::shared_ptr PROBAInstrumentsDecoderModule::getInstance(std::string input_file, std::string output_file_hint, nlohmann::json parameters) + { + return std::make_shared(input_file, output_file_hint, parameters); + } + } // namespace amsu +} // namespace metop \ No newline at end of file diff --git a/plugins/proba_support/proba/module_proba_instruments.h b/plugins/proba_support/proba/module_proba_instruments.h new file mode 100644 index 000000000..64ce4b6c2 --- /dev/null +++ b/plugins/proba_support/proba/module_proba_instruments.h @@ -0,0 +1,49 @@ +#pragma once + +#include "core/module.h" +#include "instruments/chris/chris_reader.h" +#include "instruments/hrc/hrc_reader.h" +#include "instruments/swap/swap_reader.h" + +namespace proba +{ + namespace instruments + { + class PROBAInstrumentsDecoderModule : public ProcessingModule + { + protected: + enum proba_sat_t + { + PROBA_1, + PROBA_2, + PROBA_V, + }; + + proba_sat_t d_satellite; + + std::atomic filesize; + std::atomic progress; + + // Readers + std::unique_ptr chris_reader; + std::unique_ptr hrc_reader; + std::unique_ptr swap_reader; + + // Statuses + instrument_status_t chris_status = DECODING; + instrument_status_t hrc_status = DECODING; + instrument_status_t swap_status = DECODING; + + public: + PROBAInstrumentsDecoderModule(std::string input_file, std::string output_file_hint, nlohmann::json parameters); + void process(); + void drawUI(bool window); + + public: + static std::string getID(); + virtual std::string getIDM() { return getID(); }; + static std::vector getParameters(); + static std::shared_ptr getInstance(std::string input_file, std::string output_file_hint, nlohmann::json parameters); + }; + } // namespace amsu +} // namespace metop \ No newline at end of file