frame reading for cluster file

This commit is contained in:
Erik Fröjdh 2024-11-15 16:13:46 +01:00
parent e77b615293
commit 17f8d28019
8 changed files with 84 additions and 42 deletions

View File

@ -10,31 +10,35 @@ configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
set(SPHINX_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/src) set(SPHINX_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/src)
set(SPHINX_BUILD ${CMAKE_CURRENT_BINARY_DIR}) set(SPHINX_BUILD ${CMAKE_CURRENT_BINARY_DIR})
set(SPHINX_SOURCE_FILES
src/index.rst file(GLOB SPHINX_SOURCE_FILES CONFIGURE_DEPENDS "src/*.rst")
src/Installation.rst # set(SPHINX_SOURCE_FILES
src/Requirements.rst # src/index.rst
src/NDArray.rst # src/Installation.rst
src/NDView.rst # src/Requirements.rst
src/File.rst # src/NDArray.rst
src/Frame.rst # src/NDView.rst
src/Dtype.rst # src/File.rst
src/ClusterFinder.rst # src/Frame.rst
src/Pedestal.rst # src/Dtype.rst
src/RawFile.rst # src/ClusterFinder.rst
src/RawSubFile.rst # src/ClusterFile.rst
src/RawMasterFile.rst # src/Pedestal.rst
src/VarClusterFinder.rst # src/RawFile.rst
src/pyVarClusterFinder.rst # src/RawSubFile.rst
src/pyFile.rst # src/RawMasterFile.rst
src/pyCtbRawFile.rst # src/VarClusterFinder.rst
src/pyRawFile.rst # src/pyVarClusterFinder.rst
src/pyRawMasterFile.rst # src/pyFile.rst
) # src/pyCtbRawFile.rst
# src/pyRawFile.rst
# src/pyRawMasterFile.rst
# )
foreach(filename ${SPHINX_SOURCE_FILES}) foreach(filename ${SPHINX_SOURCE_FILES})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${filename} get_filename_component(fname ${filename} NAME)
"${SPHINX_BUILD}/${filename}") message(STATUS "Copying ${filename} to ${SPHINX_BUILD}/src/${fname}")
configure_file(${filename} "${SPHINX_BUILD}/src/${fname}")
endforeach(filename ${SPHINX_SOURCE_FILES}) endforeach(filename ${SPHINX_SOURCE_FILES})
configure_file( configure_file(

7
docs/src/ClusterFile.rst Normal file
View File

@ -0,0 +1,7 @@
ClusterFile
=============
.. doxygenclass:: aare::ClusterFile
:members:
:undoc-members:
:private-members:

View File

@ -20,21 +20,12 @@ AARE
pyFile pyFile
pyCtbRawFile pyCtbRawFile
pyClusterFile
pyRawFile pyRawFile
pyRawMasterFile pyRawMasterFile
pyVarClusterFinder pyVarClusterFinder
.. toctree::
:caption: Python API
:maxdepth: 1
pyFile
pyCtbRawFile
pyRawMasterFile
pyVarClusterFinder
.. toctree:: .. toctree::
:caption: C++ API :caption: C++ API
:maxdepth: 1 :maxdepth: 1
@ -45,6 +36,7 @@ AARE
File File
Dtype Dtype
ClusterFinder ClusterFinder
ClusterFile
Pedestal Pedestal
RawFile RawFile
RawSubFile RawSubFile

View File

@ -0,0 +1,11 @@
ClusterFile
============
.. py:currentmodule:: aare
.. autoclass:: ClusterFile
:members:
:undoc-members:
:show-inheritance:
:inherited-members:

View File

@ -38,6 +38,8 @@ struct ClusterAnalysis {
double etay; double etay;
}; };
class ClusterFile { class ClusterFile {
FILE *fp{}; FILE *fp{};
uint32_t m_num_left{}; uint32_t m_num_left{};
@ -46,6 +48,7 @@ class ClusterFile {
public: public:
ClusterFile(const std::filesystem::path &fname, size_t chunk_size = 1000); ClusterFile(const std::filesystem::path &fname, size_t chunk_size = 1000);
std::vector<Cluster> read_clusters(size_t n_clusters); std::vector<Cluster> read_clusters(size_t n_clusters);
std::vector<Cluster> read_frame(int32_t &out_fnum);
std::vector<Cluster> std::vector<Cluster>
read_cluster_with_cut(size_t n_clusters, double *noise_map, int nx, int ny); read_cluster_with_cut(size_t n_clusters, double *noise_map, int nx, int ny);

View File

@ -6,8 +6,10 @@ from aare import ClusterFile
base = Path('~/data/aare_test_data/clusters').expanduser() base = Path('~/data/aare_test_data/clusters').expanduser()
# f = ClusterFile(base / 'beam_En700eV_-40deg_300V_10us_d0_f0_100.clust') f = ClusterFile(base / 'beam_En700eV_-40deg_300V_10us_d0_f0_100.clust')
f = ClusterFile(base / 'single_frame_97_clustrers.clust') # f = ClusterFile(base / 'single_frame_97_clustrers.clust')
for i in range(10):
fn, cl = f.read_frame()
print(fn, cl.size)

View File

@ -24,6 +24,12 @@ void define_cluster_file_io_bindings(py::module &m) {
auto* vec = new std::vector<Cluster>(self.read_clusters(n_clusters)); auto* vec = new std::vector<Cluster>(self.read_clusters(n_clusters));
return return_vector(vec); return return_vector(vec);
}) })
.def("read_frame",
[](ClusterFile &self) {
int32_t frame_number;
auto* vec = new std::vector<Cluster>(self.read_frame(frame_number));
return py::make_tuple(frame_number, return_vector(vec));
})
.def("read_cluster_with_cut", .def("read_cluster_with_cut",
[](ClusterFile &self, size_t n_clusters, py::array_t<double> noise_map, int nx, int ny) { [](ClusterFile &self, size_t n_clusters, py::array_t<double> noise_map, int nx, int ny) {
auto view = make_view_2d(noise_map); auto view = make_view_2d(noise_map);

View File

@ -13,14 +13,9 @@ std::vector<Cluster> ClusterFile::read_clusters(size_t n_clusters) {
std::vector<Cluster> clusters(n_clusters); std::vector<Cluster> clusters(n_clusters);
int32_t iframe = 0; // frame number needs to be 4 bytes! int32_t iframe = 0; // frame number needs to be 4 bytes!
size_t nph_read = 0; size_t nph_read = 0;
// uint32_t nn = *n_left;
uint32_t nn = m_num_left; uint32_t nn = m_num_left;
// uint32_t nph = *n_left; // number of clusters in frame needs to be 4 uint32_t nph = m_num_left; // number of clusters in frame needs to be 4
// bytes!
uint32_t nph = m_num_left;
auto buf = reinterpret_cast<Cluster *>(clusters.data()); auto buf = reinterpret_cast<Cluster *>(clusters.data());
// if there are photons left from previous frame read them first // if there are photons left from previous frame read them first
@ -61,6 +56,28 @@ std::vector<Cluster> ClusterFile::read_clusters(size_t n_clusters) {
return clusters; return clusters;
} }
std::vector<Cluster> ClusterFile::read_frame(int32_t &out_fnum) {
if (m_num_left) {
throw std::runtime_error("There are still photons left in the last frame");
}
if (fread(&out_fnum, sizeof(out_fnum), 1, fp) != 1) {
throw std::runtime_error("Could not read frame number");
}
int n_clusters;
if (fread(&n_clusters, sizeof(n_clusters), 1, fp) != 1) {
throw std::runtime_error("Could not read number of clusters");
}
std::vector<Cluster> clusters(n_clusters);
if (fread(clusters.data(), sizeof(Cluster), n_clusters, fp) != n_clusters) {
throw std::runtime_error("Could not read clusters");
}
return clusters;
}
std::vector<Cluster> ClusterFile::read_cluster_with_cut(size_t n_clusters, std::vector<Cluster> ClusterFile::read_cluster_with_cut(size_t n_clusters,
double *noise_map, double *noise_map,
int nx, int ny) { int nx, int ny) {