-
Notifications
You must be signed in to change notification settings - Fork 4
Tentative structure for a binary output file #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
I forgot to mention that this change should not affect anyone who is not deliberately opting in, as the only change in existing code is a new function in |
|
Hi Dan, Grant, Saving to file the full readout as it comes out of the NEXYS board is surely a sensible thing to do, and I pushed a small modification to the development branch The rest of your comment points to a more fundamental discussion that we should have had before we started working on this, namely what we expect the DAQ to do. I guess it is never too late, so I'll try and get the ball rolling. In my experience there are at least three things that DAQs typically do:
I think we all agree about 1).
An additional benefit of being able to do some decoding on the DAQ side is that you have a way to verify that the data are not corrupted, which, if I understand, we have no other way at the moment. Finally: if we go for 2) at some point in the future, it is in our interest to have the packets that we multicast over the network to be as small as possible, so again, this would push in the direction of decoding and serving hits instead of full frames. Personal summary: I would be in favor of keeping the decoding code in the astropix-python repository so that we have the maximum flexibility in terms of writing HW tests and we have a way to make some sanity check on a readout by readout basis as we acquire data. Even in this scheme of things we might have situations in which we might want to acquire a readout and write it to file without even looking at it. But if we move the stuff to a different repo, then that is all we can do. It goes without saying, I can be convinced otherwise. There is another thing that I'd like to throw in, namely how we keep track about what files contain and what exactly we put in the header. At this point I just grabbed whatever you guys were writing in the log files, but I think we should make sure we have all we need in it. Do we have a way of making a shapshot of the HW just before the test begins? How do we keep track of the versions of the data formats that, I am sure, will evolve with time? Finally (switching gears): comment 3. points to a topic that we were very naive about, namely the subtleties of the data decoding 😄 We will look in details at the file that Grant provided, but in the meantime could you point us to any specific resource clarifying what we should expect, and (if at all possible) separating the features of the protocol you guys have put in place from the idiosyncrasies of the hardware? (i.e., for the edge cases that Grant pointed out are we really talking about complexities of the data flow that are there by design, or glitches of the HW and/or communication problems?) |
|
Hi Luca! Thanks for the thoughtful response. I think maybe the aspect I am missing that is the crux of any disagreement that may arise, is why does having the decoding code in a separate repository preclude us from being flexible with decoding data as we readout? I was thinking of treating your decoding as a git submodule of astropix-python, which (should?) still give us the ability to write HW tests etc, but allows other projects to also check-out the decoding tool, such as ComPair and A-STEP. From my limited experience with submodules on BurstCube, it was incredibly valuable for developing the instrument FSW in a compartmentalized way from Goddard's larger Central Flight Software (cFS). Maybe you have some good arguments against this that I am missing though! Returning back to your earlier points: AstroPixReadout write() function: I think the stripping of the trailing 0xff padding makes sense. Keeping them would blow up the files too much I believe. Point 1: From a debugging perspective always being able to write raw out I think is useful, but like you point out for 2) and 3), being able to write somewhat decoded data helps with live testing and evaluation. I think your new write functionality gives us the raw write option, while your current system gives us a path forward towards 2 and 3 (and is likely what we will use the majority of time). I like the raw data because sometimes processing data too early can mask issues such as the ones Grant pointed out, but I believe your method already catches decoding errors from what I recall reading through, and shouldn't be an issue. Point 2: We absolutely want this at some point, especially for A-STEP. The way we will be getting data is through Ethernet Via Telemetry (EVTM) link with the sounding rocket's transceiver system, and a UDP connection is exactly what we want (and hence why having as much of this being set-up agnostic as possible is very attractive to me, as the astep-fw branch has diverged greatly from the astropix-python branch and its limited single-chip running capabilities. Point 3: Completely agree with this as well! Header Info: This is a good thing to start thinking about. Right now I believe the file attempts to take the settings that are supposedly included in the configuration write to the chip and includes them in the header, and I think all of the settings are likely worth keeping. We may also want to include a list of activated pixels, which will make it very easier to determine if the data we see makes sense at all. Other things that can be potentially included are things such as the loaded firmware version on the FPGA running the test (this is a supported FPGA register command in astep-fw which I think is also in astropix-python?). Maybe overkill, but maybe a git branch/commit # would be nice to include. In terms of what is ACTUALLY running on the AstroPix chip, the only way to determine this is to use the shift register interface to read out the loaded configuration. What this means, is that we are only ever looking at what was LAST loaded onto the chip, and not what currently is configured. Loading an identical configuration twice would give some peace of mind that what is sent out of the shift register is what currently runs the chip, but in a noisy system it may not be certain. This is a capability I also haven't spent much time using, but it is likely a very powerful tool for debugging both for astropix v4 as well as ASTEP. We may need to write some code to get the SROUT to functionally work, as it is not something that is currently done in the beam_test.py I'll let @grant-sommer tackle the final question about data decoding subtleties, as he knows more than I do! I think one issue we all share is that this has been a rapid development project and there is little documentation that fully explains what is supposed to be happening on the chips. I think I personally still don't understand how heartbeat bytes can be skipped, but if there is anything we don't fully understand Grant can hopefully work with Nicolas to discern more. |
|
Hi everyone, First of all, @lucabaldini, I think this looks very nice. Regarding the number of IDLE bytes ("BC"), you typically see two when you start reading from the chip. This happens because the chip's SPI interface is clocked by the SPI master in the DAQ. The data isn't immediately available because, it has to be transferred from an asynchronous FIFO to an FSM and then to the SPI arbiter which needs few clock cycles. While the chip is preparing the data, it sends out two IDLE bytes. After these 16 spi clock cycles, data is ready and the chip can start transmitting. As the data is being read, the chip uses the clock cycles to fetch new data, allowing multiple data words to be transmitted without IDLE bytes in between or just one. The "line break" shown by @grant-sommer is due to the fact that the firmware reads a certain number of bytes which is not synchronized to beginning or ending of dataframes coming from the chip, so it might just stop reading in the middle of a frame. Let me know if anything needs further clarification! |
…outs (instead of hits) to file.
|
Update after all the discussions that we have---I now have a better understanding of how the data transfer work, and I propose not to make the decoding the main point of this pull request, not to interfere with the work that Grant is doing on that side of things. The main thing that this is doing is really to implement something along the lines of The basic structure for the file is
We provide data structures to write and read back all the relevant objects. Note that there are several things going on when writing buffers to disk, namely strip all the padding bytes Additionally, we provide facilities to convert a .apx file to .cvs (this involves some decoding, but the thing can be improved upon and integrated with Grant's code later on.) This is all opt-in, i.e., none of the existing code should be affected (cross your fingers). A few top-level questions:
More detailed questions a. do all the magic things (magic word, frame header, etc) make sense? |
|
Short summary of the discussion on May 22, 2025:
|
|
Ok, I think this is now ready to be merged. I moved pretty much everything on the astropix-analysis repo, and all is left is:
The changes should not affect anybody who is not deliberately trying to use the new stuff. |
This pull request adds the machinery for writing hit data into binary format for AstroPix4. It includes:
core/fmt.py, a python module with all the relevant classes (this is a replacement for decode.py);tests/test_fmt.pywith all the unit tests for the new code;apx4_read.py, a stripped-down version ofbeam_test.pyusing the new facilities.The new data structures include a class for an event readout and one for the hits within it. Within the data-taking loop, the two are intended to interoperate like
Note that, compared to the old code, we are now assigning a timestamp to the readout based on the time on the host machine.
The basic format of the output file looks like:
%APXDF);Facilities for reading and converting binary files are provided, e.g.,
The easiest way to look at the new stuff is probably through the unit tests. A sample data file, along with the correponding .csv version is included into
tests/data.I'd like to start the bikeshedding on this :-)