mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-04-23 07:10:03 +02:00
added support for old old moench files
This commit is contained in:
parent
8bf9ac55ce
commit
0df8e4bb7d
@ -1,6 +1,6 @@
|
||||
package:
|
||||
name: aare
|
||||
version: 2024.11.26.dev0 #TODO! how to not duplicate this?
|
||||
version: 2024.11.27.dev0 #TODO! how to not duplicate this?
|
||||
|
||||
|
||||
source:
|
||||
|
@ -14,6 +14,7 @@ namespace aare {
|
||||
* @brief Implementation used in RawMasterFile to parse the file name
|
||||
*/
|
||||
class RawFileNameComponents {
|
||||
bool m_old_scheme{false};
|
||||
std::filesystem::path m_base_path{};
|
||||
std::string m_base_name{};
|
||||
std::string m_ext{};
|
||||
@ -35,6 +36,7 @@ class RawFileNameComponents {
|
||||
const std::string &base_name() const;
|
||||
const std::string &ext() const;
|
||||
int file_index() const;
|
||||
void set_old_scheme(bool old_scheme);
|
||||
};
|
||||
|
||||
class ScanParameters {
|
||||
@ -88,7 +90,7 @@ class RawMasterFile {
|
||||
size_t m_pixels_x{};
|
||||
size_t m_bitdepth{};
|
||||
|
||||
xy m_geometry;
|
||||
xy m_geometry{};
|
||||
|
||||
size_t m_max_frames_per_file{};
|
||||
// uint32_t m_adc_mask{}; // TODO! implement reading
|
||||
|
@ -4,7 +4,7 @@ build-backend = "scikit_build_core.build"
|
||||
|
||||
[project]
|
||||
name = "aare"
|
||||
version = "2024.11.26.dev0"
|
||||
version = "2024.11.27.dev0"
|
||||
|
||||
|
||||
[tool.scikit-build]
|
||||
|
@ -17,6 +17,9 @@ RawFile::RawFile(const std::filesystem::path &fname, const std::string &mode)
|
||||
n_subfiles = find_number_of_subfiles(); // f0,f1...fn
|
||||
n_subfile_parts =
|
||||
m_master.geometry().col * m_master.geometry().row; // d0,d1...dn
|
||||
|
||||
|
||||
|
||||
find_geometry();
|
||||
update_geometry_with_roi();
|
||||
|
||||
|
@ -37,11 +37,24 @@ std::filesystem::path RawFileNameComponents::master_fname() const {
|
||||
}
|
||||
|
||||
std::filesystem::path RawFileNameComponents::data_fname(size_t mod_id,
|
||||
size_t file_id) const {
|
||||
return m_base_path / fmt::format("{}_d{}_f{}_{}.raw", m_base_name, mod_id,
|
||||
size_t file_id
|
||||
) const {
|
||||
|
||||
|
||||
|
||||
std::string fmt = "{}_d{}_f{}_{}.raw";
|
||||
//Before version X we used to name the data files f000000000000
|
||||
if (m_old_scheme) {
|
||||
fmt = "{}_d{}_f{:012}_{}.raw";
|
||||
}
|
||||
return m_base_path / fmt::format(fmt, m_base_name, mod_id,
|
||||
file_id, m_file_index);
|
||||
}
|
||||
|
||||
void RawFileNameComponents::set_old_scheme(bool old_scheme) {
|
||||
m_old_scheme = old_scheme;
|
||||
}
|
||||
|
||||
const std::filesystem::path &RawFileNameComponents::base_path() const {
|
||||
return m_base_path;
|
||||
}
|
||||
@ -314,10 +327,22 @@ void RawMasterFile::parse_raw(const std::filesystem::path &fpath) {
|
||||
// do the actual parsing
|
||||
if (key == "Version") {
|
||||
m_version = value;
|
||||
|
||||
//TODO!: How old versions can we handle?
|
||||
auto v = std::stod(value);
|
||||
|
||||
//TODO! figure out exactly when we did the change
|
||||
//This enables padding of f to 12 digits
|
||||
if (v<4.0)
|
||||
m_fnc.set_old_scheme(true);
|
||||
|
||||
} else if (key == "TimeStamp") {
|
||||
|
||||
} else if (key == "Detector Type") {
|
||||
m_type = StringTo<DetectorType>(value);
|
||||
if(m_type==DetectorType::Moench){
|
||||
m_type = DetectorType::Moench03_old;
|
||||
}
|
||||
} else if (key == "Timing Mode") {
|
||||
m_timing_mode = StringTo<TimingMode>(value);
|
||||
} else if (key == "Image Size") {
|
||||
@ -352,6 +377,12 @@ void RawMasterFile::parse_raw(const std::filesystem::path &fpath) {
|
||||
pos = value.find(',');
|
||||
m_pixels_x = std::stoi(value.substr(1, pos));
|
||||
m_pixels_y = std::stoi(value.substr(pos + 1));
|
||||
}else if(key == "row"){
|
||||
pos = value.find('p');
|
||||
m_pixels_y = std::stoi(value.substr(0, pos));
|
||||
}else if(key == "col"){
|
||||
pos = value.find('p');
|
||||
m_pixels_x = std::stoi(value.substr(0, pos));
|
||||
} else if (key == "Total Frames") {
|
||||
m_total_frames_expected = std::stoi(value);
|
||||
} else if (key == "Dynamic Range") {
|
||||
@ -360,6 +391,9 @@ void RawMasterFile::parse_raw(const std::filesystem::path &fpath) {
|
||||
m_quad = std::stoi(value);
|
||||
} else if (key == "Max Frames Per File") {
|
||||
m_max_frames_per_file = std::stoi(value);
|
||||
}else if(key == "Max. Frames Per File"){
|
||||
//Version 3.0 way of writing it
|
||||
m_max_frames_per_file = std::stoi(value);
|
||||
} else if (key == "Geometry") {
|
||||
pos = value.find(',');
|
||||
m_geometry = {
|
||||
@ -368,5 +402,19 @@ void RawMasterFile::parse_raw(const std::filesystem::path &fpath) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (m_pixels_x == 400 && m_pixels_y == 400) {
|
||||
m_type = DetectorType::Moench03_old;
|
||||
}
|
||||
|
||||
|
||||
//TODO! Look for d0, d1...dn and update geometry
|
||||
if(m_geometry.col == 0 && m_geometry.row == 0){
|
||||
m_geometry = {1,1};
|
||||
fmt::print("Warning: No geometry found in master file. Assuming 1x1\n");
|
||||
}
|
||||
|
||||
//TODO! Read files and find actual frames
|
||||
if(m_frames_in_file==0)
|
||||
m_frames_in_file = m_total_frames_expected;
|
||||
}
|
||||
} // namespace aare
|
@ -31,6 +31,16 @@ TEST_CASE("Construction of master file name and data files"){
|
||||
REQUIRE(m.data_fname(1, 1) == "test_d1_f1_1.raw");
|
||||
}
|
||||
|
||||
TEST_CASE("Construction of master file name and data files using old scheme"){
|
||||
RawFileNameComponents m("test_master_1.raw");
|
||||
m.set_old_scheme(true);
|
||||
REQUIRE(m.master_fname() == "test_master_1.raw");
|
||||
REQUIRE(m.data_fname(0, 0) == "test_d0_f000000000000_1.raw");
|
||||
REQUIRE(m.data_fname(1, 0) == "test_d1_f000000000000_1.raw");
|
||||
REQUIRE(m.data_fname(0, 1) == "test_d0_f000000000001_1.raw");
|
||||
REQUIRE(m.data_fname(1, 1) == "test_d1_f000000000001_1.raw");
|
||||
}
|
||||
|
||||
TEST_CASE("Master file name does not fit pattern"){
|
||||
REQUIRE_THROWS(RawFileNameComponents("somefile.json"));
|
||||
REQUIRE_THROWS(RawFileNameComponents("another_test_d0_f0_1.raw"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user