mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-04-19 13:20:03 +02:00
frame reading for cluster file
This commit is contained in:
parent
e77b615293
commit
17f8d28019
@ -10,31 +10,35 @@ configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
|
||||
set(SPHINX_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||
set(SPHINX_BUILD ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
set(SPHINX_SOURCE_FILES
|
||||
src/index.rst
|
||||
src/Installation.rst
|
||||
src/Requirements.rst
|
||||
src/NDArray.rst
|
||||
src/NDView.rst
|
||||
src/File.rst
|
||||
src/Frame.rst
|
||||
src/Dtype.rst
|
||||
src/ClusterFinder.rst
|
||||
src/Pedestal.rst
|
||||
src/RawFile.rst
|
||||
src/RawSubFile.rst
|
||||
src/RawMasterFile.rst
|
||||
src/VarClusterFinder.rst
|
||||
src/pyVarClusterFinder.rst
|
||||
src/pyFile.rst
|
||||
src/pyCtbRawFile.rst
|
||||
src/pyRawFile.rst
|
||||
src/pyRawMasterFile.rst
|
||||
)
|
||||
|
||||
file(GLOB SPHINX_SOURCE_FILES CONFIGURE_DEPENDS "src/*.rst")
|
||||
# set(SPHINX_SOURCE_FILES
|
||||
# src/index.rst
|
||||
# src/Installation.rst
|
||||
# src/Requirements.rst
|
||||
# src/NDArray.rst
|
||||
# src/NDView.rst
|
||||
# src/File.rst
|
||||
# src/Frame.rst
|
||||
# src/Dtype.rst
|
||||
# src/ClusterFinder.rst
|
||||
# src/ClusterFile.rst
|
||||
# src/Pedestal.rst
|
||||
# src/RawFile.rst
|
||||
# src/RawSubFile.rst
|
||||
# src/RawMasterFile.rst
|
||||
# src/VarClusterFinder.rst
|
||||
# src/pyVarClusterFinder.rst
|
||||
# src/pyFile.rst
|
||||
# src/pyCtbRawFile.rst
|
||||
# src/pyRawFile.rst
|
||||
# src/pyRawMasterFile.rst
|
||||
# )
|
||||
|
||||
foreach(filename ${SPHINX_SOURCE_FILES})
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${filename}
|
||||
"${SPHINX_BUILD}/${filename}")
|
||||
get_filename_component(fname ${filename} NAME)
|
||||
message(STATUS "Copying ${filename} to ${SPHINX_BUILD}/src/${fname}")
|
||||
configure_file(${filename} "${SPHINX_BUILD}/src/${fname}")
|
||||
endforeach(filename ${SPHINX_SOURCE_FILES})
|
||||
|
||||
configure_file(
|
||||
|
7
docs/src/ClusterFile.rst
Normal file
7
docs/src/ClusterFile.rst
Normal file
@ -0,0 +1,7 @@
|
||||
ClusterFile
|
||||
=============
|
||||
|
||||
.. doxygenclass:: aare::ClusterFile
|
||||
:members:
|
||||
:undoc-members:
|
||||
:private-members:
|
@ -20,21 +20,12 @@ AARE
|
||||
|
||||
pyFile
|
||||
pyCtbRawFile
|
||||
pyClusterFile
|
||||
pyRawFile
|
||||
pyRawMasterFile
|
||||
pyVarClusterFinder
|
||||
|
||||
|
||||
.. toctree::
|
||||
:caption: Python API
|
||||
:maxdepth: 1
|
||||
|
||||
pyFile
|
||||
pyCtbRawFile
|
||||
pyRawMasterFile
|
||||
pyVarClusterFinder
|
||||
|
||||
|
||||
.. toctree::
|
||||
:caption: C++ API
|
||||
:maxdepth: 1
|
||||
@ -45,6 +36,7 @@ AARE
|
||||
File
|
||||
Dtype
|
||||
ClusterFinder
|
||||
ClusterFile
|
||||
Pedestal
|
||||
RawFile
|
||||
RawSubFile
|
||||
|
11
docs/src/pyClusterFile.rst
Normal file
11
docs/src/pyClusterFile.rst
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
ClusterFile
|
||||
============
|
||||
|
||||
.. py:currentmodule:: aare
|
||||
|
||||
.. autoclass:: ClusterFile
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
:inherited-members:
|
@ -38,6 +38,8 @@ struct ClusterAnalysis {
|
||||
double etay;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class ClusterFile {
|
||||
FILE *fp{};
|
||||
uint32_t m_num_left{};
|
||||
@ -46,6 +48,7 @@ class ClusterFile {
|
||||
public:
|
||||
ClusterFile(const std::filesystem::path &fname, size_t chunk_size = 1000);
|
||||
std::vector<Cluster> read_clusters(size_t n_clusters);
|
||||
std::vector<Cluster> read_frame(int32_t &out_fnum);
|
||||
std::vector<Cluster>
|
||||
read_cluster_with_cut(size_t n_clusters, double *noise_map, int nx, int ny);
|
||||
|
||||
|
@ -6,8 +6,10 @@ from aare import ClusterFile
|
||||
|
||||
base = Path('~/data/aare_test_data/clusters').expanduser()
|
||||
|
||||
# f = ClusterFile(base / 'beam_En700eV_-40deg_300V_10us_d0_f0_100.clust')
|
||||
f = ClusterFile(base / 'single_frame_97_clustrers.clust')
|
||||
|
||||
f = ClusterFile(base / 'beam_En700eV_-40deg_300V_10us_d0_f0_100.clust')
|
||||
# f = ClusterFile(base / 'single_frame_97_clustrers.clust')
|
||||
|
||||
|
||||
for i in range(10):
|
||||
fn, cl = f.read_frame()
|
||||
print(fn, cl.size)
|
||||
|
@ -24,6 +24,12 @@ void define_cluster_file_io_bindings(py::module &m) {
|
||||
auto* vec = new std::vector<Cluster>(self.read_clusters(n_clusters));
|
||||
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",
|
||||
[](ClusterFile &self, size_t n_clusters, py::array_t<double> noise_map, int nx, int ny) {
|
||||
auto view = make_view_2d(noise_map);
|
||||
|
@ -13,14 +13,9 @@ std::vector<Cluster> ClusterFile::read_clusters(size_t n_clusters) {
|
||||
std::vector<Cluster> clusters(n_clusters);
|
||||
|
||||
int32_t iframe = 0; // frame number needs to be 4 bytes!
|
||||
|
||||
size_t nph_read = 0;
|
||||
|
||||
// uint32_t nn = *n_left;
|
||||
uint32_t nn = m_num_left;
|
||||
// uint32_t nph = *n_left; // number of clusters in frame needs to be 4
|
||||
// bytes!
|
||||
uint32_t nph = m_num_left;
|
||||
uint32_t nph = m_num_left; // number of clusters in frame needs to be 4
|
||||
|
||||
auto buf = reinterpret_cast<Cluster *>(clusters.data());
|
||||
// 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;
|
||||
}
|
||||
|
||||
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,
|
||||
double *noise_map,
|
||||
int nx, int ny) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user