19 nlohmann::json calib_cfg;
20 std::unordered_map<int, double> wavenumbers;
21 std::unordered_map<int, bool> calib_type_map;
22 std::unordered_map<int, int> new_max_val;
23 std::unordered_map<int, int> product_bit_depth;
25 std::unordered_map<int, std::pair<std::shared_ptr<satdump::projection::VizGeorefSpline2D>, std::unordered_map<int, float>>> lut_for_channels;
31 for (
size_t i = 0; i < d_pro->images.size(); i++)
33 wavenumbers.emplace(d_pro->images[i].abs_index, d_pro->images[i].wavenumber);
34 calib_type_map.emplace(d_pro->images[i].abs_index, d_pro->images[i].calibration_type == CALIBRATION_ID_EMISSIVE_RADIANCE);
36 product_bit_depth.emplace(d_pro->images[i].abs_index, pow(2, d_pro->images[i].bit_depth) - 1);
37 if (!calib_cfg[
"bits_for_calib"][d_pro->images[i].channel_name].is_null())
38 new_max_val.emplace(d_pro->images[i].abs_index, pow(2, calib_cfg[
"bits_for_calib"][d_pro->images[i].channel_name].get<
int>()) - 1);
40 new_max_val.emplace(d_pro->images[i].abs_index, product_bit_depth[d_pro->images[i].abs_index]);
43 for (
size_t i = 0; i < d_pro->images.size(); i++)
47 if (calib_cfg.contains(
"to_complete") && calib_cfg[
"to_complete"].get<
bool>())
49 std::vector<std::pair<int, float>> llut = calib_cfg[d_pro->images[i].channel_name];
50 std::shared_ptr<satdump::projection::VizGeorefSpline2D> spline = std::make_shared<satdump::projection::VizGeorefSpline2D>(1);
54 if (v.second != 0 || is_first)
56 double rp_v[1] = {v.second};
57 spline->add_point(v.first, v.first, rp_v);
63 int s = spline->solve();
65 lut_for_channels.emplace(d_pro->images[i].abs_index,
66 std::pair<std::shared_ptr<satdump::projection::VizGeorefSpline2D>, std::unordered_map<int, float>>{nullptr, std::unordered_map<int, float>()});
68 lut_for_channels.emplace(d_pro->images[i].abs_index,
69 std::pair<std::shared_ptr<satdump::projection::VizGeorefSpline2D>, std::unordered_map<int, float>>{spline, std::unordered_map<int, float>()});
73 std::vector<std::pair<int, float>> llut = calib_cfg[d_pro->images[i].channel_name];
74 std::unordered_map<int, float> flut;
76 flut.emplace(v.first, v.second);
77 lut_for_channels.emplace(d_pro->images[i].abs_index, std::pair<std::shared_ptr<satdump::projection::VizGeorefSpline2D>, std::unordered_map<int, float>>{nullptr, flut});
80 catch (std::exception &)
82 lut_for_channels.emplace(d_pro->images[i].abs_index,
83 std::pair<std::shared_ptr<satdump::projection::VizGeorefSpline2D>, std::unordered_map<int, float>>{nullptr, std::unordered_map<int, float>()});
88 double compute(
int channel,
int ,
int , uint32_t px_val)
90 if (new_max_val[channel] != product_bit_depth[channel])
91 px_val = double(px_val / (
double)product_bit_depth[channel]) * new_max_val[channel];
95 if (calib_type_map[channel] == 0)
97 if (px_val == product_bit_depth[channel])
98 return CALIBRATION_INVALID_VALUE;
99 else if (lut_for_channels[channel].second.count(px_val))
100 return lut_for_channels[channel].second[px_val];
101 else if (lut_for_channels[channel].first)
104 lut_for_channels[channel].first->get_point(px_val, px_val, &point);
108 return CALIBRATION_INVALID_VALUE;
110 else if (calib_type_map[channel])
113 return CALIBRATION_INVALID_VALUE;
114 else if (lut_for_channels[channel].second.count(px_val))
115 return temperature_to_radiance(lut_for_channels[channel].second[px_val], wavenumbers[channel]);
116 else if (lut_for_channels[channel].first)
119 lut_for_channels[channel].first->get_point(px_val, px_val, &point);
120 return temperature_to_radiance(point, wavenumbers[channel]);
123 return CALIBRATION_INVALID_VALUE;
126 return CALIBRATION_INVALID_VALUE;
128 catch (std::exception &)
130 return CALIBRATION_INVALID_VALUE;