diff --git a/RELEASE.md b/RELEASE.md index bbc29f87..e8b90b5f 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -17,8 +17,8 @@ is set, gaps between modules. Gap positions follow detector coordinates before any ROI. Gap pixels receive a fill value or, with ``split_counts``, half of the neighbouring double size pixel. -- ``RawFile`` and ``File`` (through ``FileConfig::gap_pixels``, in Python - the ``gap_pixels`` argument) insert gap pixels while frames are +- ``RawFile`` takes a ``GapPixels`` configuration, in Python the + ``gap_pixels`` argument, and inserts gap pixels while frames are assembled. ``rows()``, ``cols()`` and every returned frame then include the gaps, for the full frame and for each ROI. diff --git a/docs/src/File.rst b/docs/src/File.rst index 0fa1ddc4..784a2722 100644 --- a/docs/src/File.rst +++ b/docs/src/File.rst @@ -1,11 +1,6 @@ File ============= -``File`` opens ``.json`` and ``.raw`` master files, ``.npy`` files and -Jungfrau ``.dat`` files behind one interface. ``FileConfig::gap_pixels`` -inserts :doc:`gap pixels ` when reading raw files; other file -types reject a set value with ``std::invalid_argument``. - .. doxygenclass:: aare::File :members: diff --git a/docs/src/GapPixels.rst b/docs/src/GapPixels.rst index 6fa00722..f5169e7a 100644 --- a/docs/src/GapPixels.rst +++ b/docs/src/GapPixels.rst @@ -72,11 +72,12 @@ chip gap of 2. Reading files ------------- -Pass a ``GapPixels`` to :cpp:class:`aare::RawFile` or set -``FileConfig::gap_pixels`` for :cpp:class:`aare::File`. Frame sizes, +Pass a ``GapPixels`` to :cpp:class:`aare::RawFile`. Frame sizes, ``rows()``, ``cols()`` and ``bytes_per_frame()`` then include the gaps. Module data is scattered into the gapped frame while it is assembled, so no -extra frame sized buffer is needed. Headers are unchanged. +extra frame sized buffer is needed. Headers are unchanged. The generic +:cpp:class:`aare::File` does not insert gap pixels; use ``RawFile`` or +apply ``insert_gap_pixels`` to the frames it returns. .. code-block:: cpp diff --git a/docs/src/python/file/pyFile.rst b/docs/src/python/file/pyFile.rst index 28d5e783..5c180d06 100644 --- a/docs/src/python/file/pyFile.rst +++ b/docs/src/python/file/pyFile.rst @@ -4,12 +4,6 @@ File .. py:currentmodule:: aare -``File`` opens raw master files, ``.npy`` files and Jungfrau ``.dat`` files -behind one interface. ``gap_pixels`` inserts -:doc:`gap pixels ` when reading raw files; pass ``True`` for -the defaults or a ``GapPixels``. Other file types raise ``ValueError`` when -it is set. - .. autoclass:: File :members: :undoc-members: diff --git a/docs/src/python/file/pyGapPixels.rst b/docs/src/python/file/pyGapPixels.rst index 4dde32c7..903f46d2 100644 --- a/docs/src/python/file/pyGapPixels.rst +++ b/docs/src/python/file/pyGapPixels.rst @@ -62,14 +62,15 @@ same dtype. Pass ``roi`` when the image covers part of the detector. Reading files ------------- -``RawFile`` and ``File`` take ``gap_pixels``: ``True`` for the defaults or -a ``GapPixels``. Frame shapes, ``rows`` and ``cols`` then include the gaps. +``RawFile`` takes ``gap_pixels``: ``True`` for the defaults or a +``GapPixels``. Frame shapes, ``rows`` and ``cols`` then include the gaps. Only Jungfrau and Eiger raw files are supported; other detector types raise -``ValueError``. +``ValueError``. The generic ``File`` does not insert gap pixels; use +``RawFile`` or apply ``insert_gap_pixels`` to the frames it returns. .. code-block:: python - from aare import File, GapPixels, ModuleGaps, RawFile + from aare import GapPixels, ModuleGaps, RawFile # defaults: chip gaps of 2 filled with 0 with RawFile("run_master_0.json", gap_pixels=True) as f: @@ -77,8 +78,8 @@ Only Jungfrau and Eiger raw files are supported; other detector types raise # module gaps as in the slsDetectorPackage GUI, counts split at chip edges gaps = GapPixels(module_gaps=ModuleGaps(8, 36), split_counts=True, seed=1) - with File("run_master_0.json", gap_pixels=gaps) as f: - image = f.read_frame() + with RawFile("run_master_0.json", gap_pixels=gaps) as f: + header, image = f.read_frame() .. autoclass:: GapPixels :members: diff --git a/include/aare/FileInterface.hpp b/include/aare/FileInterface.hpp index 3219ca4f..87ca3dbf 100644 --- a/include/aare/FileInterface.hpp +++ b/include/aare/FileInterface.hpp @@ -2,11 +2,9 @@ #pragma once #include "aare/Dtype.hpp" #include "aare/Frame.hpp" -#include "aare/GapPixels.hpp" #include "aare/defs.hpp" #include -#include #include namespace aare { @@ -17,7 +15,6 @@ namespace aare { * rows: number of rows in the file * cols: number of columns in the file * geometry: geometry of the file - * gap_pixels: insert gap pixels when reading raw files */ struct FileConfig { aare::Dtype dtype{typeid(uint16_t)}; @@ -27,8 +24,7 @@ struct FileConfig { return dtype == other.dtype && rows == other.rows && cols == other.cols && geometry == other.geometry && detector_type == other.detector_type && - max_frames_per_file == other.max_frames_per_file && - gap_pixels == other.gap_pixels; + max_frames_per_file == other.max_frames_per_file; } bool operator!=(const FileConfig &other) const { return !(*this == other); } @@ -38,10 +34,6 @@ struct FileConfig { DetectorType detector_type{DetectorType::Unknown}; int max_frames_per_file{}; size_t total_frames{}; - - /// @brief Insert gap pixels into every frame. Only RawFile supports - /// this; other readers reject a set value. - std::optional gap_pixels{}; // std::string to_string() const { // return "{ dtype: " + dtype.to_string() + // ", rows: " + std::to_string(rows) + diff --git a/python/src/file.hpp b/python/src/file.hpp index 3814832b..96960d91 100644 --- a/python/src/file.hpp +++ b/python/src/file.hpp @@ -3,7 +3,6 @@ #include "aare/CtbRawFile.hpp" #include "aare/File.hpp" #include "aare/Frame.hpp" -#include "aare/GapPixels.hpp" #include "aare/ROI.hpp" #include "aare/RawFile.hpp" #include "aare/RawMasterFile.hpp" @@ -30,37 +29,13 @@ void define_file_io_bindings(py::module &m) { debug, roundRNumber, detType, version, packetMask); py::class_(m, "File") - .def(py::init([](const std::filesystem::path &fname, - const std::string &mode, - std::optional gap_pixels) { - FileConfig cfg; - cfg.gap_pixels = std::move(gap_pixels); - return File(fname, mode, cfg); - }), - py::arg("fname"), py::arg("mode") = "r", - py::arg("gap_pixels") = py::none()) - .def(py::init([](const std::filesystem::path &fname, - const std::string &mode, bool gap_pixels) { - FileConfig cfg; - if (gap_pixels) { - cfg.gap_pixels = GapPixels{}; - } - return File(fname, mode, cfg); - }), - py::arg("fname"), py::arg("mode") = "r", - py::arg("gap_pixels") = false, R"( - Open a file for reading. - - Parameters - ---------- - fname : path - Master file (.json, .raw), .npy or .dat file. - mode : str - Only "r" is supported. - gap_pixels : bool or GapPixels - Insert gap pixels when reading raw files. True uses the - default GapPixels configuration. - )") + .def(py::init([](const std::filesystem::path &fname) { + return File(fname, "r", {}); + })) + .def(py::init( + [](const std::filesystem::path &fname, const std::string &mode) { + return File(fname, mode, {}); + })) .def(py::init()) diff --git a/python/tests/test_RawFile.py b/python/tests/test_RawFile.py index a4c9395e..f4b24ef3 100644 --- a/python/tests/test_RawFile.py +++ b/python/tests/test_RawFile.py @@ -544,16 +544,15 @@ def test_raw_file_gap_pixels(tmp_path, layout): with RawFile(master_path, gap_pixels=True) as reader: assert reader.gap_pixels == GapPixels() + assert (reader.rows(), reader.cols()) == insert_gap_pixels(expected).shape _, image = reader.read_frame() assert (image == insert_gap_pixels(expected)).all() - with File(master_path, gap_pixels=True) as reader: - assert (reader.rows, reader.cols) == insert_gap_pixels(expected).shape - assert (reader.read_frame() == insert_gap_pixels(expected)).all() - module_gaps = GapPixels(module_gaps=ModuleGaps(8, 36)) - with File(master_path, gap_pixels=module_gaps) as reader: - assert (reader.read_frame() == insert_gap_pixels(expected, module_gaps)).all() + with RawFile(master_path, gap_pixels=module_gaps) as reader: + assert (reader.rows(), reader.cols()) == insert_gap_pixels(expected, module_gaps).shape + _, image = reader.read_frame() + assert (image == insert_gap_pixels(expected, module_gaps)).all() def test_raw_file_gap_pixels_split_counts(tmp_path): @@ -570,8 +569,6 @@ def test_raw_file_gap_pixels_unsupported_detector(tmp_path): RawFile(master_path) with pytest.raises(ValueError): RawFile(master_path, gap_pixels=True) - with pytest.raises(ValueError): - File(master_path, gap_pixels=True) @pytest.mark.withdata diff --git a/src/File.cpp b/src/File.cpp index de71660b..53cc158c 100644 --- a/src/File.cpp +++ b/src/File.cpp @@ -23,12 +23,10 @@ File::File(const std::filesystem::path &fname, const std::string &mode, // Assuming we are pointing at a master file? // TODO! How do we read raw files directly? if (fname.extension() == ".raw" || fname.extension() == ".json") { - file_impl = std::make_unique(fname, mode, cfg.gap_pixels); - } else if (cfg.gap_pixels) { - throw std::invalid_argument(fmt::format( - "Gap pixels are only supported for raw files, cannot open '{}'", - fname.string())); + // file_impl = new RawFile(fname, mode, cfg); + file_impl = std::make_unique(fname, mode); } else if (fname.extension() == ".npy") { + // file_impl = new NumpyFile(fname, mode, cfg); file_impl = std::make_unique(fname, mode, cfg); } else if (fname.extension() == ".dat") { file_impl = std::make_unique(fname);