mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-06 10:00:40 +02:00
updated reading
This commit is contained in:
parent
4b7c5c5950
commit
04146e683c
@ -1,8 +1,20 @@
|
||||
import os
|
||||
import sys
|
||||
import numpy as np
|
||||
sys.path.append(os.path.join(os.getcwd(), 'bin'))
|
||||
from sls_detector import Eiger
|
||||
from sls_detector import ExperimentalDetector
|
||||
|
||||
from _sls_detector.io import read_ctb_file
|
||||
|
||||
d = Eiger()
|
||||
e = ExperimentalDetector()
|
||||
e = ExperimentalDetector()
|
||||
|
||||
# ncols = 192
|
||||
# start = 600
|
||||
# end = 1800
|
||||
# nrows = end-start
|
||||
# data = np.zeros((nrows, ncols))
|
||||
|
||||
# for i in range(nrows):
|
||||
# data[i, :] = read_ctb_file(f'/home/l_frojdh/mythendata/MoKbZr_30kV60mA_1s_200V_thr{start+i}_1.raw', 8, 24)
|
@ -19,7 +19,7 @@ class Detector {
|
||||
Detector(int i)
|
||||
: det(i), multi_detector_id(i) {
|
||||
//Disable output from std::cout
|
||||
std::cout.setstate(std::ios_base::failbit);
|
||||
// std::cout.setstate(std::ios_base::failbit);
|
||||
}
|
||||
|
||||
int getMultiDetectorId() { return multi_detector_id; }
|
||||
|
@ -285,7 +285,9 @@ py::class_<multiSlsDetector> multiDetectorApi(m, "multiDetectorApi");
|
||||
.def("_setReceiverUDPIP", &multiSlsDetector::setReceiverUDPIP)
|
||||
;
|
||||
|
||||
m.def("hej", &hej, "some");
|
||||
py::module io = m.def_submodule("io", "Submodule for io");
|
||||
io.def("read_ctb_file", &read_ctb_file, "some");
|
||||
|
||||
|
||||
#ifdef VERSION_INFO
|
||||
m.attr("__version__") = VERSION_INFO;
|
||||
|
@ -7,6 +7,11 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include <pybind11/numpy.h>
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
namespace py = pybind11;
|
||||
|
||||
template <size_t bit_index0, size_t bit_index1>
|
||||
std::vector<int> ExtractBits(const std::vector<uint64_t> &data, int dr = 24) {
|
||||
constexpr int mask0 = (1 << bit_index0);
|
||||
@ -50,11 +55,11 @@ std::vector<int> ExtractBits(const std::vector<uint64_t> &data, int dr = 24) {
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<uint64_t> ReadFile(const std::string &fname, int offset = 8, int dr = 24) {
|
||||
std::vector<uint64_t> ReadFile(const std::string &fname, int offset = 8,
|
||||
int dr = 24) {
|
||||
const int element_size = static_cast<int>(sizeof(uint64_t));
|
||||
const int byte_offset = element_size * offset;
|
||||
const int expected_size = dr * element_size * 32 * 3;
|
||||
|
||||
std::ifstream fs(fname, std::ios::binary | std::ios::ate);
|
||||
if (!fs.is_open()) {
|
||||
throw std::runtime_error("File not found: " + std::string(fname));
|
||||
@ -63,15 +68,18 @@ std::vector<uint64_t> ReadFile(const std::string &fname, int offset = 8, int dr
|
||||
if (data_size != expected_size) {
|
||||
auto diff = data_size - expected_size;
|
||||
std::cout << "WARNING: data size is: " << data_size
|
||||
<< " expected size is: " << expected_size << ", " << std::abs(diff) << " bytes "
|
||||
<< " expected size is: " << expected_size << ", "
|
||||
<< std::abs(diff) << " bytes "
|
||||
<< ((diff < 0) ? "missing" : "too many") << '\n';
|
||||
}
|
||||
std::vector<uint64_t> data(expected_size / element_size);
|
||||
fs.seekg(byte_offset, std::ios::beg);
|
||||
fs.read(reinterpret_cast<char *>(data.data()), data_size);
|
||||
fs.read(reinterpret_cast<char *>(data.data()), expected_size);
|
||||
return data;
|
||||
}
|
||||
|
||||
int hej(){
|
||||
return 5;
|
||||
py::array_t<uint64_t> read_ctb_file(const std::string &fname, int offset = 8,
|
||||
int dr = 24) {
|
||||
auto data = ExtractBits<17, 6>(ReadFile(fname, offset, dr));
|
||||
return py::array(data.size(), data.data());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user