diff --git a/satdump_cfg.json b/satdump_cfg.json index 56a6680ea..8d3f6e49b 100644 --- a/satdump_cfg.json +++ b/satdump_cfg.json @@ -292,7 +292,15 @@ }, "sem": { "handler": "radiation_handler", - "name": "SEM" + "name": "SEM", + "radiation_maps": { + "ch1": { + "channel": 1, + "radius": 5, + "min": 0, + "max": 255 + } + } }, "ocm_oc2": { "handler": "image_handler", diff --git a/src-core/products/processor/radiation_processor.cpp b/src-core/products/processor/radiation_processor.cpp new file mode 100644 index 000000000..7632b849f --- /dev/null +++ b/src-core/products/processor/radiation_processor.cpp @@ -0,0 +1,42 @@ +#include "processor.h" + +#include "logger.h" +#include "../radiation_products.h" +#include "core/config.h" + +namespace satdump +{ + void process_radiation_products(Products *products, std::string product_path) + { + RadiationProducts *rad_products = (RadiationProducts *)products; + + // Get instrument settings + nlohmann::ordered_json instrument_viewer_settings; + if (config::main_cfg["viewer"]["instruments"].contains(products->instrument_name)) + instrument_viewer_settings = config::main_cfg["viewer"]["instruments"][products->instrument_name]; + else + logger->error("Unknown instrument : {:s}!", products->instrument_name); + + // TMP + if (instrument_viewer_settings.contains("radiation_maps")) + { + for (nlohmann::detail::iteration_proxy_value> compo : instrument_viewer_settings["radiation_maps"].items()) + { + // rgb_presets.push_back({compo.key(), compo.value().get()}); + std::string initial_name = compo.key(); + std::replace(initial_name.begin(), initial_name.end(), ' ', '_'); + std::replace(initial_name.begin(), initial_name.end(), '/', '_'); + + RadiationMapCfg cfg = compo.value().get(); + image::Image rad_map = satdump::make_radiation_map(*rad_products, cfg); + + std::string name = products->instrument_name + + "_map_" + + initial_name + ".png"; + + logger->info("Saving " + product_path + "/" + name); + rad_map.save_png(product_path + "/" + name); + } + } + } +} \ No newline at end of file diff --git a/src-core/products/processor/radiation_processor.h b/src-core/products/processor/radiation_processor.h new file mode 100644 index 000000000..885d5a39f --- /dev/null +++ b/src-core/products/processor/radiation_processor.h @@ -0,0 +1,8 @@ +#pragma once + +#include "../products.h" + +namespace satdump +{ + void process_radiation_products(Products *products, std::string product_path); +} \ No newline at end of file diff --git a/src-core/products/products.cpp b/src-core/products/products.cpp index 7c4af1a9b..f98a18dd7 100644 --- a/src-core/products/products.cpp +++ b/src-core/products/products.cpp @@ -6,6 +6,7 @@ #include "radiation_products.h" #include "core/plugin.h" #include "processor/image_processor.h" +#include "processor/radiation_processor.h" namespace satdump { @@ -74,6 +75,7 @@ namespace satdump { products_loaders.clear(); products_loaders.emplace("image", RegisteredProducts{PRODUCTS_LOADER_FUN(ImageProducts), process_image_products}); + products_loaders.emplace("radiation", RegisteredProducts{PRODUCTS_LOADER_FUN(RadiationProducts), process_radiation_products}); // Plugins! eventBus->fire_event({products_loaders}); diff --git a/src-core/products/radiation_products.cpp b/src-core/products/radiation_products.cpp index a2975a624..0f550cf15 100644 --- a/src-core/products/radiation_products.cpp +++ b/src-core/products/radiation_products.cpp @@ -1,6 +1,7 @@ #include "radiation_products.h" #include "logger.h" #include "common/tracking/tracking.h" +#include "resources.h" namespace satdump { @@ -21,10 +22,15 @@ namespace satdump channel_counts = contents["counts"].get>>(); } - void make_radiation_map(RadiationProducts &products, int channel, image::Image &initial_map, int radius, image::Image color_lut, int min, int max) + image::Image make_radiation_map(RadiationProducts &products, RadiationMapCfg cfg, float *progress) { - int img_x = initial_map.width(); - int img_y = initial_map.height(); + image::Image map; + map.load_jpeg(resources::getResourcePath("maps/nasa.jpg").c_str()); + image::Image color_lut = image::LUT_jet(); + + int img_x = map.width(); + int img_y = map.height(); + int channel = cfg.channel - 1; int lut_size = color_lut.width(); std::vector timestamps = products.get_timestamps(channel); @@ -33,7 +39,7 @@ namespace satdump for (int samplec = 0; samplec < (int)products.channel_counts[channel].size(); samplec++) { - int value = (double(products.channel_counts[channel][samplec] - min) / max) * lut_size; + int value = (double(products.channel_counts[channel][samplec] - cfg.min) / cfg.max) * lut_size; // logger->info("{:d} {:d}", products.channel_counts[channel][samplec], value); @@ -50,7 +56,12 @@ namespace satdump uint16_t color[] = {color_lut.channel(0)[value], color_lut.channel(1)[value], color_lut.channel(2)[value]}; - initial_map.draw_circle(image_x, image_y, radius, color, true); + map.draw_circle(image_x, image_y, cfg.radius, color, true); + + if (progress != nullptr) + *progress = float(samplec) / float(products.channel_counts[channel].size()); } + + return map; } } \ No newline at end of file diff --git a/src-core/products/radiation_products.h b/src-core/products/radiation_products.h index 13017332f..11fb4e728 100644 --- a/src-core/products/radiation_products.h +++ b/src-core/products/radiation_products.h @@ -54,5 +54,30 @@ namespace satdump virtual void load(std::string file); }; - void make_radiation_map(RadiationProducts &products, int channel, image::Image &map, int radius, image::Image color_lut, int min, int max); + // Map handling + struct RadiationMapCfg + { + int channel; + int radius; + int min; + int max; + }; + + inline void to_json(nlohmann::json &j, const RadiationMapCfg &v) + { + j["channel"] = v.channel; + j["radius"] = v.radius; + j["min"] = v.min; + j["max"] = v.max; + } + + inline void from_json(const nlohmann::json &j, RadiationMapCfg &v) + { + v.channel = j["channel"].get(); + v.radius = j["radius"].get(); + v.min = j["min"].get(); + v.max = j["max"].get(); + } + + image::Image make_radiation_map(RadiationProducts &products, RadiationMapCfg cfg, float *progress = nullptr); } \ No newline at end of file diff --git a/src-interface/viewer/radiation_handler.cpp b/src-interface/viewer/radiation_handler.cpp index af4c1ae05..f14c0342a 100644 --- a/src-interface/viewer/radiation_handler.cpp +++ b/src-interface/viewer/radiation_handler.cpp @@ -20,9 +20,13 @@ namespace satdump { if (selected_visualization_id == 0) { - image::Image map; - map.load_jpeg(resources::getResourcePath("maps/nasa.jpg").c_str()); - make_radiation_map(*products, select_channel_image_id, map, 5, image::LUT_jet(), map_min, map_max); + + RadiationMapCfg cfg; + cfg.channel = select_channel_image_id + 1; + cfg.radius = 5; + cfg.min = map_min; + cfg.max = map_max; + image::Image map = make_radiation_map(*products, cfg); image_view.update(map); } else if (selected_visualization_id == 1) diff --git a/src-testing/main.cpp b/src-testing/main.cpp index 4ec8ac325..3525b8cae 100644 --- a/src-testing/main.cpp +++ b/src-testing/main.cpp @@ -43,9 +43,9 @@ int main(int argc, char *argv[]) satdump::registerProducts(); - // satdump::process_dataset("metop_ahrpt_new/dataset.json"); + satdump::process_dataset("metop_ahrpt_new/dataset.json"); // satdump::process_dataset("jpss_bb_test/dataset.json"); - satdump::process_dataset("m22_proj_test1/dataset.json"); + // satdump::process_dataset("m22_proj_test1/dataset.json"); /* satdump::ImageProducts img_pro;