rugnux and the viewer read SMV and gzipped miniCBF
Two more of the formats deposited data actually arrives in, found by processing a
corpus of it: every PETRA III EMBL set is .cbf.gz, and NSRRC and the whole ADSC
Quantum era are SMV. Both were previously "no native input".
SMV is an ASCII "KEY=value;" block between braces, then the pixels - no container,
no compression, nothing to decode by offset - so reader/SMV.{h,cpp} and
JFJochSMVReader are a smaller job than the marCCD pair they sit beside, and need no
new dependency at all. Two things the format does not give us, both said out loud
rather than papered over:
* It states no saturation value, so overloads are judged on the 16-bit container
alone. That can only fail to call a pixel saturated, never condemn a good one,
but a CCD at the top of its range does saturate, so the reader warns once.
* Its beam centre is in MILLIMETRES and which of X/Y is the fast direction is a
convention rather than a rule. Measured on one ALS ADSC sweep the file's value is
TRANSPOSED: as stated it indexes 2/60 frames, and the run's own beam-centre
measurement (which adopts the right one automatically) indexes 60/60. Swapping it
here would fit that writer and might break another, so the header is read as the
format defines it and the measurement stays the arbiter. Revisit with a second
vendor's SMV in hand.
.cbf.gz needed only Slurp() in MiniCBF.cpp, through which every read already passes:
it sniffs the two-byte gzip magic - not the file name - and takes a zlib path when it
is there, leaving the plain path free of zlib's buffer copy. zlib-ng is already in the
build, so this is a link line, not a dependency. The sweep template grew a suffix,
because ".cbf" and ".cbf.gz" are separate sweeps and std::filesystem cannot split the
double extension on its own.
The viewer's single cbf_reader becomes three, dispatched by CanRead() in the same
order as rugnux. Dispatch is by CONTENT in both: ".img" is used by miniCBF, marCCD
AND SMV depending on the writer, and a PDB detector label has now been wrong about
the format four times, so an extension decides nothing.
Measured, de novo, no flags: 9fcg (1800 gzipped frames) gives P4 and a cell 0.06%
from the deposited one at 1.37 A against a deposited 1.54; 6oel (ADSC SMV) gives
F4132 - 96 operations, the most a protein space group can have - and a cell 0.05%
out, 100% indexed. Tests cover both formats and the transposed-beam-centre case with
fixtures written byte for byte, so they need no external data.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
a1889c45e9
commit
2ab8c55dfa
15 files changed
+867
-27
No files matched your search
@@ -9,6 +9,7 @@
|
||||
#include "../reader/JFJochHDF5Reader.h"
|
||||
#include "../reader/JFJochCBFReader.h"
|
||||
#include "../reader/JFJochMarCCDReader.h"
|
||||
#include "../reader/JFJochSMVReader.h"
|
||||
#include "../reader/MiniCBF.h"
|
||||
#include "../compression/JFJochCompressor.h"
|
||||
|
||||
@@ -4291,3 +4292,118 @@ TEST_CASE("JFJochMarCCDReader_Geometry", "[HDF5][Full]") {
|
||||
remove("marccdplain_001.tif");
|
||||
}
|
||||
}
|
||||
|
||||
// SMV: an ASCII "KEY=value;" block between braces, then the pixels. The fixtures are written by
|
||||
// hand here, as for marCCD, because the layout is what the reader has to cope with.
|
||||
namespace {
|
||||
struct SMVFields {
|
||||
int nx = 24, ny = 16;
|
||||
double pixel_mm = 0.1;
|
||||
double distance_mm = 250.0;
|
||||
double osc_start = 5.0, osc_range = 0.2;
|
||||
double wavelength = 0.9998;
|
||||
double beam_x_mm = 1.2, beam_y_mm = 0.8;
|
||||
std::string byte_order = "little_endian";
|
||||
bool write_header = true;
|
||||
};
|
||||
|
||||
void WriteSMVFrame(const std::string &name, const SMVFields &f) {
|
||||
std::ostringstream h;
|
||||
h << "{\n";
|
||||
if (f.write_header) {
|
||||
h << "HEADER_BYTES= 512;\nDIM=2;\nBYTE_ORDER=" << f.byte_order << ";\n"
|
||||
<< "TYPE=unsigned_short;\nSIZE1=" << f.nx << ";\nSIZE2=" << f.ny << ";\n"
|
||||
<< "PIXEL_SIZE=" << f.pixel_mm << ";\nDISTANCE=" << f.distance_mm << ";\n"
|
||||
<< "OSC_START=" << f.osc_start << ";\nOSC_RANGE=" << f.osc_range << ";\n"
|
||||
<< "WAVELENGTH=" << f.wavelength << ";\n"
|
||||
<< "BEAM_CENTER_X=" << f.beam_x_mm << ";\nBEAM_CENTER_Y=" << f.beam_y_mm << ";\n";
|
||||
} else {
|
||||
h << "SOMETHING_ELSE=1;\n"; // a brace block that is not an image header
|
||||
}
|
||||
h << "}\n";
|
||||
std::string head = h.str();
|
||||
head.resize(512, '\f'); // pad to HEADER_BYTES, as every writer does
|
||||
std::ofstream out(name, std::ios::binary);
|
||||
out.write(head.data(), static_cast<std::streamsize>(head.size()));
|
||||
const std::vector<char> pixels(static_cast<size_t>(f.nx) * f.ny * 2, 0);
|
||||
out.write(pixels.data(), static_cast<std::streamsize>(pixels.size()));
|
||||
}
|
||||
|
||||
void WriteSMVSweep(const std::string &prefix, const std::string &suffix, SMVFields f = {}) {
|
||||
for (int frame = 1; frame <= 2; frame++) {
|
||||
f.osc_start = 5.0 + (frame - 1) * 0.2;
|
||||
std::ostringstream name;
|
||||
name << prefix << std::setfill('0') << std::setw(3) << frame << suffix;
|
||||
WriteSMVFrame(name.str(), f);
|
||||
}
|
||||
}
|
||||
|
||||
void RemoveSMVSweep(const std::string &prefix, const std::string &suffix) {
|
||||
for (int frame = 1; frame <= 2; frame++) {
|
||||
std::ostringstream name;
|
||||
name << prefix << std::setfill('0') << std::setw(3) << frame << suffix;
|
||||
remove(name.str().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("JFJochSMVReader_Geometry", "[HDF5][Full]") {
|
||||
SECTION("the header's geometry reaches the experiment in the units the rest of the code uses") {
|
||||
WriteSMVSweep("smv_", ".img");
|
||||
REQUIRE(JFJochSMVReader::CanRead("smv_001.img"));
|
||||
JFJochSMVReader reader;
|
||||
REQUIRE_NOTHROW(reader.ReadFiles("smv_001.img"));
|
||||
CHECK(reader.GetNumberOfImages() == 2);
|
||||
const auto x = reader.GetDataset()->experiment;
|
||||
CHECK(x.GetDetectorDistance_mm() == Catch::Approx(250.0));
|
||||
CHECK(x.GetPixelSize_mm() == Catch::Approx(0.1));
|
||||
CHECK(x.GetWavelength_A() == Catch::Approx(0.9998).epsilon(1e-4));
|
||||
// The file states the beam centre in MILLIMETRES; the rest of the code wants pixels.
|
||||
CHECK(x.GetBeamX_pxl() == Catch::Approx(12.0));
|
||||
CHECK(x.GetBeamY_pxl() == Catch::Approx(8.0));
|
||||
REQUIRE(x.GetGoniometer().has_value());
|
||||
CHECK(x.GetGoniometer()->GetStart_deg() == Catch::Approx(5.0));
|
||||
CHECK(x.GetGoniometer()->GetIncrement_deg() == Catch::Approx(0.2));
|
||||
reader.Close();
|
||||
RemoveSMVSweep("smv_", ".img");
|
||||
}
|
||||
|
||||
SECTION("a brace block that is not an image header is refused") {
|
||||
SMVFields f; f.write_header = false;
|
||||
WriteSMVFrame("smvbare_001.img", f);
|
||||
CHECK_FALSE(JFJochSMVReader::CanRead("smvbare_001.img"));
|
||||
remove("smvbare_001.img");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("JFJochCBFReader_GzippedSweep", "[HDF5][Full]") {
|
||||
// EMBL Hamburg writes .cbf.gz by default. The reader decompresses in place, so a gzipped sweep
|
||||
// opens exactly as a plain one does and needs no conversion step.
|
||||
const int64_t nx = 24, ny = 16;
|
||||
WriteMiniCBFSweep("cbfgz", "# Oscillation_axis OMEGA\n", nx, ny);
|
||||
for (int frame = 1; frame <= 2; frame++) {
|
||||
std::ostringstream name;
|
||||
name << "cbfgz_" << std::setfill('0') << std::setw(4) << frame << ".cbf";
|
||||
// gzip the frame in place, so the directory holds only the .cbf.gz form
|
||||
const std::string cmd = "gzip -f " + name.str();
|
||||
REQUIRE(std::system(cmd.c_str()) == 0);
|
||||
}
|
||||
REQUIRE(JFJochCBFReader::CanRead("cbfgz_0001.cbf.gz"));
|
||||
JFJochCBFReader reader;
|
||||
REQUIRE_NOTHROW(reader.ReadFiles("cbfgz_0001.cbf.gz"));
|
||||
CHECK(reader.GetNumberOfImages() == 2);
|
||||
const auto x = reader.GetDataset()->experiment;
|
||||
CHECK(x.GetDetectorDistance_mm() == Catch::Approx(331.61));
|
||||
CHECK(x.GetBeamX_pxl() == Catch::Approx(12.0));
|
||||
CHECK(x.GetWavelength_A() == Catch::Approx(0.96864).epsilon(1e-5));
|
||||
JFJochReaderRawImage image;
|
||||
REQUIRE(reader.ReadRawImage(0, image));
|
||||
CHECK(image.image.GetWidth() == nx);
|
||||
CHECK(image.image.GetHeight() == ny);
|
||||
reader.Close();
|
||||
for (int frame = 1; frame <= 2; frame++) {
|
||||
std::ostringstream name;
|
||||
name << "cbfgz_" << std::setfill('0') << std::setw(4) << frame << ".cbf.gz";
|
||||
remove(name.str().c_str());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user