mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-04 03:50:41 +02:00
MH02 1-4 counters
This commit is contained in:
parent
cbfd1f0b6c
commit
b2e5c71f9c
@ -27,6 +27,8 @@ public:
|
||||
|
||||
size_t image_size_in_bytes() const;
|
||||
size_t frames_in_file() const;
|
||||
|
||||
RawMasterFile master() const;
|
||||
private:
|
||||
void find_subfiles();
|
||||
size_t sub_file_index(size_t frame_index) const {
|
||||
|
@ -5,7 +5,11 @@
|
||||
|
||||
namespace aare {
|
||||
|
||||
NDArray<size_t, 2> GenerateMoench03PixelMap();
|
||||
NDArray<size_t, 2> GenerateMoench05PixelMap();
|
||||
NDArray<ssize_t, 2> GenerateMoench03PixelMap();
|
||||
NDArray<ssize_t, 2> GenerateMoench05PixelMap();
|
||||
|
||||
NDArray<ssize_t, 2>GenerateMH02SingleCounterPixelMap();
|
||||
NDArray<ssize_t, 3> GenerateMH02FourCounterPixelMap();
|
||||
|
||||
|
||||
} // namespace aare
|
@ -65,9 +65,11 @@ class RawMasterFile {
|
||||
//TODO! should these be bool?
|
||||
uint8_t m_analog_flag{};
|
||||
uint8_t m_digital_flag{};
|
||||
uint8_t m_transceiver_flag{};
|
||||
|
||||
std::optional<size_t> m_analog_samples;
|
||||
std::optional<size_t> m_digital_samples;
|
||||
std::optional<size_t> m_transceiver_samples;
|
||||
std::optional<size_t> m_number_of_rows;
|
||||
std::optional<uint8_t> m_quad;
|
||||
|
||||
@ -93,6 +95,7 @@ class RawMasterFile {
|
||||
|
||||
std::optional<size_t> analog_samples() const;
|
||||
std::optional<size_t> digital_samples() const;
|
||||
std::optional<size_t> transceiver_samples() const;
|
||||
std::optional<size_t> number_of_rows() const;
|
||||
std::optional<uint8_t> quad() const;
|
||||
private:
|
||||
|
@ -74,7 +74,7 @@ class SubFile {
|
||||
size_t n_frames{};
|
||||
int m_sub_file_index_{};
|
||||
DetectorType m_detector_type;
|
||||
std::optional<NDArray<size_t, 2>> pixel_map;
|
||||
std::optional<NDArray<ssize_t, 2>> pixel_map;
|
||||
};
|
||||
|
||||
} // namespace aare
|
@ -36,6 +36,7 @@ class CtbRawFile(_aare.CtbRawFile):
|
||||
if frame_index is not None:
|
||||
self.seek(frame_index)
|
||||
|
||||
|
||||
header, data = super().read_frame()
|
||||
if header.shape == (1,):
|
||||
header = header[0]
|
||||
@ -47,6 +48,8 @@ class CtbRawFile(_aare.CtbRawFile):
|
||||
return header, *res
|
||||
else:
|
||||
return header, res
|
||||
else:
|
||||
return header, data
|
||||
|
||||
def read_n(self, n_frames:int) -> tuple:
|
||||
"""Read several frames from the file.
|
||||
@ -82,6 +85,13 @@ class CtbRawFile(_aare.CtbRawFile):
|
||||
|
||||
return header, data
|
||||
|
||||
def read(self) -> tuple:
|
||||
"""Read the entire file.
|
||||
|
||||
Returns:
|
||||
tuple: header, data
|
||||
"""
|
||||
return self.read_n(self.frames_in_file)
|
||||
|
||||
def seek(self, frame_index:int) -> None:
|
||||
"""Seek to a specific frame in the file.
|
||||
|
@ -12,4 +12,17 @@ class Moench05Transform:
|
||||
return np.take(data.view(np.uint16), self.pixel_map)
|
||||
|
||||
|
||||
class Matterhorn02Transform:
|
||||
def __init__(self):
|
||||
self.pixel_map = _aare.GenerateMH02FourCounterPixelMap()
|
||||
|
||||
def __call__(self, data):
|
||||
counters = int(data.size / 48**2 / 2)
|
||||
if counters == 1:
|
||||
return np.take(data.view(np.uint16), self.pixel_map[0])
|
||||
else:
|
||||
return np.take(data.view(np.uint16), self.pixel_map[0:counters])
|
||||
|
||||
#on import generate the pixel maps to avoid doing it every time
|
||||
moench05 = Moench05Transform()
|
||||
matterhorn02 = Matterhorn02Transform()
|
@ -9,6 +9,50 @@ from aare import transform
|
||||
print('transform imported')
|
||||
from pathlib import Path
|
||||
|
||||
import json
|
||||
|
||||
def decode(frames, rawdata):
|
||||
# rawdata = np.fromfile(f, dtype = np.uint16)
|
||||
counters = int((np.shape(rawdata)[0]/frames-56)/(48*48))
|
||||
print('Counters:', counters)
|
||||
rawdata = rawdata.reshape(frames,-1)[:,56:]
|
||||
rawdata = rawdata.reshape(frames,576*counters,4) #Data come in "blocks" of 4 pixels/receiver
|
||||
tr1 = rawdata[:,0:576*counters:2] #Transceiver1
|
||||
tr1=tr1.reshape((frames,48*counters,24))
|
||||
|
||||
tr2 = rawdata[:,1:576*counters:2] #Transceiver2
|
||||
tr2=tr2.reshape((frames,48*counters,24))
|
||||
|
||||
data = np.append(tr1,tr2,axis=2)
|
||||
return data
|
||||
|
||||
def get_Mh02_frames(fname):
|
||||
# this function gives you the data from a file that is not a scan
|
||||
# it returns a (frames,48*counters,48)
|
||||
|
||||
jsonf = open(fname)
|
||||
jsonpar = json.load(jsonf)
|
||||
jsonf.close()
|
||||
|
||||
frames=jsonpar["Frames in File"]
|
||||
print('Frames:', frames)
|
||||
|
||||
rawf = fname.replace('master','d0_f0')
|
||||
rawf = rawf.replace('.json','.raw')
|
||||
|
||||
with open(rawf, 'rb') as f:
|
||||
rawdata = np.fromfile(f, dtype = np.uint16)
|
||||
data = decode(frames, rawdata)
|
||||
print('Data:', np.shape(data))
|
||||
|
||||
return data
|
||||
|
||||
|
||||
#target format
|
||||
# [frame, counter, row, col]
|
||||
# plt.imshow(data[0,0])
|
||||
|
||||
|
||||
# p = Path('/Users/erik/data/aare_test_data/jungfrau/jungfrau_single_master_0.json')
|
||||
|
||||
# f = aare.File(p)
|
||||
@ -18,27 +62,75 @@ from pathlib import Path
|
||||
# im = ax.imshow(frame, cmap='viridis')
|
||||
|
||||
|
||||
fpath = Path('/Users/erik/data/Moench03old/test_034_irradiated_noise_g4_hg_exptime_2000us_master_0.json')
|
||||
# fpath = Path('/Users/erik/data/Moench05/moench05_multifile_master_0.json')
|
||||
# fpath = Path('/Users/erik/data/Moench03old/test_034_irradiated_noise_g4_hg_exptime_2000us_master_0.json')
|
||||
# # fpath = Path('/Users/erik/data/Moench05/moench05_multifile_master_0.json')
|
||||
|
||||
|
||||
# f = aare.CtbRawFile(fpath, transform = transform.moench05)
|
||||
# with CtbRawFile(fpath, transform = transform.moench05) as f:
|
||||
# for header, image in f:
|
||||
# print(f'Frame number: {header["frameNumber"]}')
|
||||
# # f = aare.CtbRawFile(fpath, transform = transform.moench05)
|
||||
# # with CtbRawFile(fpath, transform = transform.moench05) as f:
|
||||
# # for header, image in f:
|
||||
# # print(f'Frame number: {header["frameNumber"]}')
|
||||
|
||||
# m = aare.RawMasterFile(fpath)
|
||||
f = aare.File(fpath)
|
||||
# # m = aare.RawMasterFile(fpath)
|
||||
# f = aare.File(fpath)
|
||||
|
||||
|
||||
|
||||
cf = aare.ClusterFinder((400,400),(3,3))
|
||||
# cf = aare.ClusterFinder((400,400),(3,3))
|
||||
|
||||
for i in range(100):
|
||||
cf.push_pedestal_frame(f.read_frame())
|
||||
# for i in range(100):
|
||||
# cf.push_pedestal_frame(f.read_frame())
|
||||
|
||||
|
||||
f.seek(0)
|
||||
pd = f.read_n(100).mean(axis=0)
|
||||
# f.seek(0)
|
||||
# pd = f.read_n(100).mean(axis=0)
|
||||
|
||||
# clusters = cf.find_clusters_without_threshold(f.read_frame())
|
||||
|
||||
|
||||
|
||||
base = Path('/Users/erik/data/matterhorn/raw')
|
||||
fpath = Path(base / 'scan_15keV_vrf700_vrsh700_th0_master_0.json')
|
||||
f = aare.CtbRawFile(fpath, transform=transform.matterhorn02)
|
||||
f.seek(100)
|
||||
header1, image1 = f.read_frame()
|
||||
|
||||
fpath = Path(base / 'scan_all15keV_vrf500_vrsh700_th0_master_0.json')
|
||||
|
||||
f = aare.CtbRawFile(fpath, transform=transform.matterhorn02)
|
||||
f.seek(100)
|
||||
header4, image4 = f.read_frame()
|
||||
|
||||
# n_counters = image.shape[1] / 48**2 / 2
|
||||
|
||||
# for i in range(100):
|
||||
# header, image = f.read_frame()
|
||||
# print(header['frameNumber'])
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#Data come in "blocks" of 4 pixels/receiver
|
||||
data = get_Mh02_frames(fpath.as_posix())
|
||||
|
||||
# rawi = np.zeros(48*48*4+56, dtype = np.uint16)
|
||||
# for i,v in enumerate(rawi[56:]):
|
||||
# rawi[i+56] = i
|
||||
|
||||
# raw = image.view(np.uint16)
|
||||
|
||||
# pixel_map = decode(1, rawi)
|
||||
# # img = np.take(raw, pixel_map)
|
||||
|
||||
# pm = np.zeros((4, 48,48), dtype = np.int64)
|
||||
# for counter in range(4):
|
||||
# for row in range(48):
|
||||
# for col in range(48):
|
||||
# pm[counter, row, col] = row*48 + col+counter*48*48
|
||||
|
||||
|
||||
f2 = aare.CtbRawFile(fpath, transform=transform.matterhorn02)
|
||||
header, data = f2.read()
|
||||
plt.plot(data[:,0,20,20])
|
||||
|
||||
clusters = cf.find_clusters_without_threshold(f.read_frame())
|
@ -48,6 +48,7 @@ void define_file_io_bindings(py::module &m) {
|
||||
})
|
||||
.def("seek", &CtbRawFile::seek)
|
||||
.def("tell", &CtbRawFile::tell)
|
||||
.def("master", &CtbRawFile::master)
|
||||
.def_property_readonly("image_size_in_bytes", &CtbRawFile::image_size_in_bytes)
|
||||
.def_property_readonly("frames_in_file", &CtbRawFile::frames_in_file);
|
||||
|
||||
@ -167,7 +168,8 @@ void define_file_io_bindings(py::module &m) {
|
||||
.def_property_readonly("bitdepth", &RawMasterFile::bitdepth)
|
||||
.def_property_readonly("analog_samples", &RawMasterFile::analog_samples)
|
||||
.def_property_readonly("digital_samples",
|
||||
&RawMasterFile::digital_samples);
|
||||
&RawMasterFile::digital_samples)
|
||||
.def_property_readonly("transceiver_samples", &RawMasterFile::transceiver_samples);
|
||||
|
||||
// py::class_<ClusterHeader>(m, "ClusterHeader")
|
||||
// .def(py::init<>())
|
||||
|
@ -14,11 +14,19 @@ using namespace::aare;
|
||||
|
||||
void define_pixel_map_bindings(py::module &m) {
|
||||
m.def("GenerateMoench03PixelMap", []() {
|
||||
auto ptr = new NDArray<size_t,2>(GenerateMoench03PixelMap());
|
||||
auto ptr = new NDArray<ssize_t,2>(GenerateMoench03PixelMap());
|
||||
return return_image_data(ptr);
|
||||
})
|
||||
.def("GenerateMoench05PixelMap", []() {
|
||||
auto ptr = new NDArray<size_t,2>(GenerateMoench05PixelMap());
|
||||
auto ptr = new NDArray<ssize_t,2>(GenerateMoench05PixelMap());
|
||||
return return_image_data(ptr);
|
||||
})
|
||||
.def("GenerateMH02SingleCounterPixelMap", []() {
|
||||
auto ptr = new NDArray<ssize_t,2>(GenerateMH02SingleCounterPixelMap());
|
||||
return return_image_data(ptr);
|
||||
})
|
||||
.def("GenerateMH02FourCounterPixelMap", []() {
|
||||
auto ptr = new NDArray<ssize_t,3>(GenerateMH02FourCounterPixelMap());
|
||||
return return_image_data(ptr);
|
||||
});
|
||||
|
||||
|
@ -48,6 +48,8 @@ size_t CtbRawFile::image_size_in_bytes() const { return m_master.image_size_in_b
|
||||
|
||||
size_t CtbRawFile::frames_in_file() const { return m_master.frames_in_file(); }
|
||||
|
||||
RawMasterFile CtbRawFile::master() const { return m_master; }
|
||||
|
||||
void CtbRawFile::find_subfiles() {
|
||||
// we can semi safely assume that there is only one module for CTB
|
||||
while (std::filesystem::exists(m_master.data_fname(0, m_num_subfiles)))
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <array>
|
||||
|
||||
namespace aare {
|
||||
NDArray<size_t, 2> GenerateMoench03PixelMap() {
|
||||
NDArray<ssize_t, 2> GenerateMoench03PixelMap() {
|
||||
std::array<int, 32> const adc_nr = {300, 325, 350, 375, 300, 325, 350, 375,
|
||||
200, 225, 250, 275, 200, 225, 250, 275,
|
||||
100, 125, 150, 175, 100, 125, 150, 175,
|
||||
@ -11,7 +11,7 @@ NDArray<size_t, 2> GenerateMoench03PixelMap() {
|
||||
int const sc_width = 25;
|
||||
int const nadc = 32;
|
||||
int const pixels_per_sc = 5000;
|
||||
NDArray<size_t, 2> order_map({400, 400});
|
||||
NDArray<ssize_t, 2> order_map({400, 400});
|
||||
|
||||
int pixel = 0;
|
||||
for (int i = 0; i != pixels_per_sc; ++i) {
|
||||
@ -30,9 +30,9 @@ NDArray<size_t, 2> GenerateMoench03PixelMap() {
|
||||
return order_map;
|
||||
}
|
||||
|
||||
NDArray<size_t, 2> GenerateMoench05PixelMap() {
|
||||
NDArray<ssize_t, 2> GenerateMoench05PixelMap() {
|
||||
std::array<int, 3> adc_numbers = {9, 13, 1};
|
||||
NDArray<size_t, 2> order_map({160, 150});
|
||||
NDArray<ssize_t, 2> order_map({160, 150});
|
||||
int n_pixel = 0;
|
||||
for (int row = 0; row < 160; row++) {
|
||||
for (int i_col = 0; i_col < 50; i_col++) {
|
||||
@ -52,4 +52,26 @@ NDArray<size_t, 2> GenerateMoench05PixelMap() {
|
||||
return order_map;
|
||||
}
|
||||
|
||||
NDArray<ssize_t, 2>GenerateMH02SingleCounterPixelMap(){
|
||||
NDArray<ssize_t, 2> order_map({48, 48});
|
||||
for(int row = 0; row < 48; row++){
|
||||
for(int col = 0; col < 48; col++){
|
||||
order_map(row, col) = row*48 + col;
|
||||
}
|
||||
}
|
||||
return order_map;
|
||||
}
|
||||
|
||||
NDArray<ssize_t, 3> GenerateMH02FourCounterPixelMap(){
|
||||
NDArray<ssize_t, 3> order_map({4, 48, 48});
|
||||
for (int counter=0; counter<4; counter++){
|
||||
for(int row = 0; row < 48; row++){
|
||||
for(int col = 0; col < 48; col++){
|
||||
order_map(counter, row, col) = counter*48*48 + row*48 + col;
|
||||
}
|
||||
}
|
||||
}
|
||||
return order_map;
|
||||
}
|
||||
|
||||
} // namespace aare
|
@ -109,6 +109,10 @@ std::optional<size_t> RawMasterFile::digital_samples() const {
|
||||
return m_digital_samples;
|
||||
}
|
||||
|
||||
std::optional<size_t> RawMasterFile::transceiver_samples() const {
|
||||
return m_transceiver_samples;
|
||||
}
|
||||
|
||||
void RawMasterFile::parse_json(const std::filesystem::path &fpath) {
|
||||
std::ifstream ifs(fpath);
|
||||
json j;
|
||||
@ -190,6 +194,15 @@ void RawMasterFile::parse_json(const std::filesystem::path &fpath) {
|
||||
// keep the optional empty
|
||||
}
|
||||
|
||||
try{
|
||||
m_transceiver_flag = j.at("Transceiver Flag");
|
||||
if(m_transceiver_flag){
|
||||
m_transceiver_samples = j.at("Transceiver Samples");
|
||||
}
|
||||
}catch (const json::out_of_range &e) {
|
||||
// keep the optional empty
|
||||
}
|
||||
|
||||
// Update detector type for Moench
|
||||
// TODO! How does this work with old .raw master files?
|
||||
#ifdef AARE_VERBOSE
|
||||
|
Loading…
x
Reference in New Issue
Block a user