11 #include "Eigen/Dense"
16 #include "unsupported/Eigen/CXX11/Tensor"
18 int main(
int argc,
char** argv) {
31 const int atms_scanpos = 96;
32 const int atms_numchannels = 22;
33 const int crtm_numlevels = 101;
34 const int crtm_numlayers = 100;
35 const int atms_initlines = 66;
42 f, {NewDimensionScale<int>(
"ScanPosition", atms_scanpos, atms_scanpos, atms_scanpos),
43 NewDimensionScale<int>(
"ScanLine", atms_initlines, -1, 11),
44 NewDimensionScale<int>(
"Level", crtm_numlevels, crtm_numlevels, crtm_numlevels),
45 NewDimensionScale<int>(
"Layer", crtm_numlayers, crtm_numlayers, crtm_numlayers),
46 NewDimensionScale<int>(
"Channel", atms_numchannels, atms_numchannels,
56 auto params_double =
params;
57 params_double.setFillValue<
double>(-999);
58 auto params_float =
params;
59 params_float.setFillValue<
float>(-999);
61 params_int.setFillValue<
int>(-999);
68 Eigen::ArrayXi eScanPos(atms_scanpos);
69 eScanPos.setLinSpaced(1, atms_scanpos);
70 og.all_dims["ScanPosition"].writeWithEigenRegular(eScanPos);
72 Eigen::ArrayXi eScanLine(atms_initlines);
73 eScanLine.setLinSpaced(1, atms_initlines);
74 og.all_dims["ScanLine"].writeWithEigenRegular(eScanLine);
76 std::array<int, atms_numchannels> vChannel{ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,
78 og.all_dims["Channel"].write<int>(vChannel);
83 std::array<std::string, atms_numchannels> vCentrFreq{
84 "23.8",
"31.4",
"50.3",
"51.76",
"52.8",
"53.596",
"54.40",
"54.94",
85 "55.50",
"57.29034",
"57.29034",
"57.29034",
"57.29034",
"57.29034",
"57.29034",
"88.20",
86 "165.5",
"183.31",
"183.31",
"183.31",
"183.31",
"183.31"};
87 og.vars.createWithScales<std::string>(
"CenterFreq@MetaData", {
og.vars[
"Channel"]},
params)
88 .write<std::string>(vCentrFreq)
89 .atts.add<std::string>(
"long_name", std::string(
"Center frequency of instrument channel"))
90 .add(
"units", std::string(
"GHz"));
92 std::array<int, atms_numchannels> vPol{0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1};
93 og.vars.createWithScales<
int>(
"MetaData/Polarization", {
og.vars[
"Channel"]}, params_int)
95 .atts.add<std::string>(
"long_name", std::string(
"Polarization of instrument channel"))
96 .add<int>(
"valid_range", {0, 6});
103 Eigen::ArrayXXf eLat(atms_initlines, atms_scanpos);
104 Eigen::ArrayXXf eLon(atms_initlines, atms_scanpos);
107 Eigen::Tensor<float, 3, Eigen::RowMajor> eBTs(atms_initlines, atms_scanpos, atms_numchannels);
108 for (
int i = 0; i < atms_initlines; ++i)
109 for (
int j = 0; j < atms_scanpos; ++j) {
110 eLat(i, j) =
static_cast<float>(i) / 2.f;
111 eLon(i, j) = (
static_cast<float>(j) / 2.f) + (
static_cast<float>(i) / 6.f);
112 for (
int k = 0; k < atms_numchannels; ++k) {
113 const float degtorad = 3.141592654f / 180.f;
115 150 + (150 * sin(degtorad *
static_cast<float>(i))) +
116 (100 * cos(degtorad *
static_cast<float>(15 + (4 * j) + (8 * k)))) +
117 (15 * sin(2 * degtorad *
static_cast<float>(i)) * cos(4 * degtorad *
static_cast<float>(j)));
122 .createWithScales<
float>(
"Latitude@MetaData", {
og.vars[
"ScanLine"],
og.vars[
"ScanPosition"]},
124 .writeWithEigenRegular(eLat)
125 .atts.add<std::string>(
"long_name", std::string(
"Latitude"))
126 .add<std::string>(
"units", std::string(
"degrees_north"))
127 .add<float>(
"valid_range", {-90, 90});
130 .createWithScales<
float>(
"Longitude@MetaData", {
og.vars[
"ScanLine"],
og.vars[
"ScanPosition"]},
132 .writeWithEigenRegular(eLon)
133 .atts.add<std::string>(
"long_name", std::string(
"Longitude"))
134 .add<std::string>(
"units", std::string(
"degrees_east"))
135 .add<float>(
"valid_range", {-360, 360});
139 .createWithScales<
float>(
"ObsValue/Inst_Brightness_Temperature_Uncorrected",
140 {
og.vars[
"ScanLine"],
og.vars[
"ScanPosition"],
og.vars[
"Channel"]},
142 .writeWithEigenTensor(eBTs)
143 .atts.add<std::string>(
"long_name", std::string(
"Raw instrument brightness temperature"))
144 .add<std::string>(
"units", std::string(
"K"))
145 .add<float>(
"valid_range", {120, 500})
147 .add<std::string>(
"coordinates", std::string(
"Longitude Latitude Channel"));
150 Expects(!
og.vars[
"ScanLine"].getDimensionScaleName().empty());
151 Expects(
og.vars[
"ObsValue/Inst_Brightness_Temperature_Uncorrected"].isDimensionScaleAttached(
152 0,
og.vars[
"ScanLine"]));
153 }
catch (
const std::exception& e) {
Definitions for setting up backends with file and memory I/O.
Interfaces for ioda::ObsGroup and related classes.
static ObsGroup generate(Group &emptyGroup, const NewDimensionScales_t &fundamentalDims, std::shared_ptr< const detail::DataLayoutPolicy > layout=nullptr)
Create an empty ObsGroup and populate it with the fundamental dimensions.
Common preprocessor definitions used throughout IODA.
IODA_DL Group constructFromCmdLine(int argc, char **argv, const std::string &defaultFilename)
This is a wrapper function around the constructBackend function for creating a backend based on comma...
IODA_DL void unwind_exception_stack(const std::exception &e, std::ostream &out=std::cerr, int level=0)
Convenience function for unwinding an exception stack.
int main(int argc, char **argv)
Used to specify Variable creation-time properties.