#include "EleFitsUtils/ProgramOptions.h"
#include "ElementsKernel/ProgramHeaders.h"
#include <boost/program_options.hpp>
#include <map>
#include <string>
#include "EleFitsData/TestColumn.h"
#include "EleFitsData/TestRaster.h"
#include "EleFitsData/TestRecord.h"
#include "EleFits/MefFile.h"
using boost::program_options::options_description;
using boost::program_options::value;
using boost::program_options::variable_value;
static Elements::Logging logger = Elements::Logging::getLogger("EleFitsTutorial");
struct TutoRecords {
};
struct TutoRasters {
};
struct TutoColumns {
};
TutoRecords createRecords();
TutoRasters createRasters();
TutoColumns createColumns();
TutoRecords createRecords() {
logger.info(" Creating records...");
auto complexRecord = Fits::Test::generateRandomRecord<std::complex<double>>("COMPLEX");
return { stringRecord, intRecord, floatRecord, complexRecord };
}
TutoRasters createRasters() {
logger.info(" Creating rasters...");
for (const auto& position : int16Raster2D.domain()) {
int16Raster2D[position] = position[0] + position[1];
}
return { int16Raster2D, int32Raster3D, int64Raster4D };
}
TutoColumns createColumns() {
logger.info(" Creating columns...");
for (long i = 0; i < stringColumn.rowCount(); ++i) {
}
return { stringColumn, int32Column, float32Column };
}
logger.
info(
"Creating a MEF file...");
const auto rasters = createRasters();
logger.info(" Writing image HDUs...");
const auto& image1 = f.assignImageExt("IMAGE1", rasters.int32Raster3D);
const auto& image2 = f.initImageExt<
std::int16_t>(
"IMAGE2", rasters.int16Raster2D.shape());
image2.raster().write(rasters.int16Raster2D);
const auto columns = createColumns();
logger.info(" Writing binary table HDUs...");
const auto& table1 = f.assignBintableExt("TABLE1", columns.stringColumn, columns.int32Column, columns.float32Column);
const auto& table2 = f.initBintableExt(
"TABLE2",
columns.stringColumn.info(),
columns.int32Column.info(),
columns.float32Column.info());
table2.columns().write(columns.stringColumn);
table2.columns().writeSeq(columns.int32Column, columns.float32Column);
(void)image1;
(void)table1;
}
const auto records = createRecords();
logger.info(" Writing records...");
hdu.
header().
writeSeq(records.intRecord, records.floatRecord, records.complexRecord);
}
logger.info("Reading the MEF file...");
logger.info(" Accessing HDUs...");
const auto& primary = f.primary();
const auto primaryIndex = primary.index();
const auto imageName = image2.
readName();
const auto tableIndex = table1.
index();
logger.info() << " Primary index: " << primaryIndex;
logger.info() << " Name of the second extension: " << imageName;
logger.info() << " Index of the 'TABLE1' extension: " << tableIndex;
readRecords(primary);
}
logger.info(" Reading records...");
const auto& thirdRecord = std::get<2>(someRecords);
const auto variantRecords = hdu.
header().
parseSeq<>({
"INT",
"COMPLEX" });
const auto& stringRecord = tutoRecords.stringRecord;
logger.info() << " " << intRecord.keyword << " = " << intRecord.value << " " << intRecord.unit;
logger.info() << " INT value: " << intValue;
logger.info() << " " << thirdRecord.keyword << " = " << thirdRecord.value << " " << thirdRecord.unit;
logger.info() <<
" " << complexRecord.keyword <<
" = " << complexRecord.value.
real() <<
" + "
<< complexRecord.value.imag() << "j " << complexRecord.unit;
logger.info() << " " << stringRecord.keyword << " = " << stringRecord.value << " " << stringRecord.unit;
}
logger.info(" Reading a raster...");
const auto& firstPixel = image[{ 0, 0 }];
const auto& lastPixel = image.at({ -1, -1 });
logger.info() << " First pixel: " << firstPixel;
logger.info() << " Last pixel: " << lastPixel;
}
logger.info(" Reading columns...");
const auto vectorColumn = hdu.
readColumn<
double>(
"VECTOR");
const auto& stringColumn = std::get<0>(byName);
const auto& intColumn = std::get<1>(byIndex);
const auto& firstString = stringColumn(0);
const auto& firstInt = intColumn(0);
const auto& lastFloat = vectorColumn.at(-1, -1);
logger.info() << " First string: " << firstString;
logger.info() << " First int: " << firstInt;
logger.info() << " Last float: " << lastFloat;
}
class EleFitsTutorial : public Elements::Program {
public:
options.positional("output", value<std::string>()->default_value("/tmp/tuto.fits"), "Output file");
return options.asPair();
}
const auto filename = args[
"output"].as<
std::string>();
logger.info() << "---";
logger.info() << "---";
writeMefFile(filename);
logger.info() << "---";
readMefFile(filename);
logger.info() << "---";
logger.info() << "The end!";
logger.info() << "---";
return Elements::ExitCode::OK;
}
};
MAIN_FOR(EleFitsTutorial)