13#include "common/physics_constants.h"
17#include "common/calibration.h"
18#include "utils/unit_parser.h"
41 class ImageProduct :
public Product
62 std::string channel_name;
66 double wavenumber = -1;
67 std::string calibration_type =
"";
70 std::vector<ImageHolder> images;
72 bool save_as_matrix =
false;
81 contents[
"projection_cfg"] = cfg;
82 if (cfg.contains(
"tle") && cfg[
"tle"].contains(
"name"))
98 cfg[
"timestamps"] = timestamps;
110 auto cfg = contents[
"projection_cfg"];
129 void set_calibration(std::string calibrator, nlohmann::json cfg)
131 contents[
"calibration"] = cfg;
132 contents[
"calibration"][
"calibrator"] = calibrator;
135 std::pair<std::string, nlohmann::json> get_calibration() {
return {contents[
"calibration"][
"calibrator"], contents[
"calibration"]}; }
144 nlohmann::json get_calibration_raw() {
return contents.contains(
"calibration") ? contents[
"calibration"] : nlohmann::json(); }
154 for (
auto &img : images)
155 if (img.abs_index == index)
157 throw satdump_exception(
"Product Channel Index " + std::to_string(index) +
" is not present!");
167 for (
auto &img : images)
168 if (img.channel_name == name)
170 throw satdump_exception(
"Product Channel Name " + name +
" is not present!");
182 for (
auto &img : images)
184 if (img.wavenumber != -1 && best > abs(img.wavenumber - wavenumber))
187 best = abs(img.wavenumber - wavenumber);
191 throw satdump_exception(
"Product Channel Close to Wavelength " + std::to_string(wavenumber) +
" is not present!");
204 if (parseUnitFromString(str, val, UNIT_METER))
205 val = freq_to_wavenumber(SPEED_OF_LIGHT_M_S / val);
206 else if (parseUnitFromString(str, val, UNIT_HERTZ))
207 val = freq_to_wavenumber(val);
209 throw satdump_exception(
"Couldn't parse unit and value from " + str);
221 for (
int i = 0; i < (int)images.size(); i++)
222 if (images[i].channel_name == name)
224 throw satdump_exception(
"Product Channel Name " + name +
" is not present!");
235 auto &i = images[idx];
236 int depth_diff = i.bit_depth - i.image.depth();
238 return i.image.get(0, x, y) << depth_diff;
240 return i.image.get(0, x, y) >> -depth_diff;
250 for (
auto &img : images)
251 if (img.abs_index == index)
253 img.wavenumber = wavenumber;
256 throw satdump_exception(
"Product Channel Index " + std::to_string(index) +
" is not present!");
273 for (
auto &img : images)
274 if (img.abs_index == index)
275 return img.wavenumber;
276 throw satdump_exception(
"Product Channel Index " + std::to_string(index) +
" is not present!");
295 for (
auto &img : images)
296 if (img.abs_index == index)
298 img.calibration_type = type_or_unit;
301 throw satdump_exception(
"Product Channel Index " + std::to_string(index) +
" is not present!");
305 bool d_no_not_save_images =
false;
306 bool d_no_not_load_images =
false;
307 virtual void save(std::string directory);
308 virtual void load(std::string file);
311 virtual ~ImageProduct();
size_t height() const
Returns image height.
Definition image.h:216
size_t width() const
Returns image width.
Definition image.h:210
SatDump image product class.
Definition image_product.h:42
double get_channel_wavenumber(int index)
Get channel wavenumber.
Definition image_product.h:271
void set_channel_unit(int index, std::string type_or_unit)
Set channel calibration unit.
Definition image_product.h:292
bool has_calibration()
Check if calibration info is present.
Definition image_product.h:141
ImageHolder & get_channel_image_by_unitstr(std::string str)
Get image channel by unit string. Returns the closest one.
Definition image_product.h:200
virtual void load(std::string file)
Load the product. This should refer to the product.cbor file.
Definition image_product.cpp:79
void set_channel_wavenumber(int index, double wavenumber)
Set channel wavenumber.
Definition image_product.h:248
int get_raw_channel_val(int idx, int x, int y)
Get raw channel count.
Definition image_product.h:233
double get_channel_frequency(int index)
Get channel frequency.
Definition image_product.h:284
bool has_proj_cfg()
Check if geo projection info is present.
Definition image_product.h:126
void set_channel_frequency(int index, double frequency)
Set channel frequency (internally, wavenumber)
Definition image_product.h:264
ImageHolder & get_channel_image_by_wavenumber(double wavenumber)
Get image channel by wavenumber. Returns the closest one.
Definition image_product.h:178
int get_channel_image_idx(std::string name)
Get image channel raw ID by name.
Definition image_product.h:219
ImageHolder & get_channel_image(std::string name)
Get image channel by name.
Definition image_product.h:165
void set_proj_cfg_tle_timestamps(nlohmann::json cfg, nlohmann::json tle, nlohmann::json timestamps)
Set geo projection config in the product, with a TLE and timestamps.
Definition image_product.h:95
ImageHolder & get_channel_image(int index)
Get image channel by absolute ID.
Definition image_product.h:152
virtual void save(std::string directory)
Save the product. Depending on the type this will save a product.cbor and other files in the same dir...
Definition image_product.cpp:18
nlohmann::json get_proj_cfg(int channel)
Get geo projection config in the product, if present.
Definition image_product.h:107
void set_proj_cfg(nlohmann::json cfg)
Set geo projection config in the product.
Definition image_product.h:79
double get_product_timestamp()
Get the product timestamp.
Definition product.h:63
void set_product_source(std::string source)
Set product source, optional. This is meant to contextualize where this product is from,...
Definition product.h:69
void set_product_timestamp(double timestamp)
Set product timestamp, optional. This is usually the rough creation time / acquisition time.
Definition product.h:51
bool has_product_source()
Check if a product source is present.
Definition product.h:75
bool has_product_timestamp()
Check if a product timestamp is present.
Definition product.h:57
Core Product implementation.
Math/Statistics functions.
Struct holding both the image and some metadata.
Definition image_product.h:59