I have some astronomical data file (.ser) that have 8 bit BGR (data order) pixel data. 301 frames take up 7 GB of valuable space. I wish to combine some of the frames say ten (10) consecutive frames, pixel colour by pixel colour and save them in a file. I have found mmap and can use it to inspect the first 178 bytes of header information then come the frames. How do I efficiently perform the file operations. The pixels are stored as a single byte (8 bits) and the new file after combination will have two (2) bytes (16 bits) presumably as unsigned int. How can I efficiently index through the input file. Any help pointing me in the correct direction will be appreciated.


This seems to be ok

with open(file_name,"r+b") as f:

mm = mmap.mmap(f.fileno(),0) 
p_f = 10
source_frame_array = bytearray(100)
source_frame_array = mm.read ()


with open(write_file,"r+b") as w:

for n_f in range (0,int(3)):

    for n_p in range (0, p_f):
        n_e = 0
        for n_e in range (0, 5): 
            n_e = n_e+n_e # the work
            w.write(n_e.to_bytes(2,"little")) # plant in file


  • Don''t forget to accept your own answer. Doing so will help others who read this in future. Btw, your post is very badly off-topic on this site; please read softwarerecs.stackexchange.com/help/on-topic You should have asked on stackoverflow.com but I imagine that it's very badly worded wizard sent you here, as discussed in softwarerecs.meta.stackexchange.com/questions/2809/… Aug 30 '19 at 10:05
  • 1
    I realized that accepting my answer was desirable however my code is still undergoing testing as I get control of indexing through the file and intended to finalise the solution when that work is concluded. This simplified version does address the initial problem of manipulating binary files and I see no problem with it. Yes the wizard is probably partially to blame as I thought that I was on stackexchange. Aug 31 '19 at 19:55
  • That @$%£!!! wizard is driving us nuts :-) Btw, when your code is complete, consider codereview.stackexchange.com Aug 31 '19 at 20:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.