NaN error when processing binned movies

Hi,

I am trying to generate some binned movies for a workshop (to speed up motion correction & reduce disk usage).

I can make an lzw-compressed 2x binned tiff using IMOD (newstack -bi 2 -->mrc followed by mrc2tif -c 5). The gain is also binned using newstack.

I can import the gain and movie into CS 4.7 and everything looks fine, but motion correction fails with this error:

Error occurred while processing J5518/imported/007816666275979851502_lzw_test.tif
Traceback (most recent call last):
  File "/home/exx/cryosparc/cryosparc_worker/cryosparc_compute/jobs/pipeline.py", line 59, in exec
    return self.process(item)
  File "cryosparc_master/cryosparc_compute/jobs/motioncorrection/run_patch.py", line 357, in cryosparc_master.cryosparc_compute.jobs.motioncorrection.run_patch.run_patch_motion_correction_multi.motionworker.process
  File "/home/exx/cryosparc/cryosparc_worker/cryosparc_compute/blobio/mrc.py", line 252, in write_mrc
    ioengine.write_mrc(
RuntimeError: Detected NaN/INF in 1 / 1 particles or frames: /home/exx/processing/cryosparc_projects/francesca/P2/J5519/motioncorrected/007816666275979851502_lzw_test_background.mrc


Marking J5518/imported/007816666275979851502_lzw_test.tif as incomplete and continuing...

Here is the header of the background mrc:

 RO image file on unit   1 : 007816666275979851502_lzw_test_background.mrc     Size=       4097 K

 Number of columns, rows, sections .....    1024    1024       1
 Map mode ..............................    2   (32-bit real)
 Start cols, rows, sects, grid x,y,z ...    0     0     0    1024   1024      1
 Pixel spacing (Angstroms)..............   6.640      6.640      6.640
 Cell angles ...........................   90.000   90.000   90.000
 Fast, medium, slow axes ...............    X    Y    Z
 Origin on x,y,z .......................    0.000       0.000       0.000
 Minimum density .......................    -Infinity
 Maximum density .......................     Infinity
 Mean density ..........................   531.48
 tilt angles (original,current) ........   0.0   0.0   0.0   0.0   0.0   0.0
 Space group,# extra bytes,idtype,lens .        0        0        0        0

Header of movie:

 RO image file on unit   1 : lzw_test.tif     Size=      50227 K

                    This is a TIFF file.

 Number of columns, rows, sections .....    2880    2046      50
 Map mode ..............................    0   (byte)
 Start cols, rows, sects, grid x,y,z ...    0     0     0    2880   2046     50
 Pixel spacing (Angstroms)..............   1.000      1.000      1.000
 Cell angles ...........................   90.000   90.000   90.000
 Fast, medium, slow axes ...............    X    Y    Z
 Origin on x,y,z .......................    0.000       0.000       0.000
 Minimum density .......................   0.0000
 Maximum density .......................   4.0000
 Mean density ..........................   2.0000
 tilt angles (original,current) ........   0.0   0.0   0.0   0.0   0.0   0.0
 Space group,# extra bytes,idtype,lens .        0        0        0        0

     0 Titles :

Header of gain:

 RO image file on unit   1 : bin2_gain.mrc     Size=      23018 K

 Number of columns, rows, sections .....    2880    2046       1
 Map mode ..............................    2   (32-bit real)
 Start cols, rows, sects, grid x,y,z ...    0     0     0    2880   2046      1
 Pixel spacing (Angstroms)..............   2.000      2.000      1.000
 Cell angles ...........................   90.000   90.000   90.000
 Fast, medium, slow axes ...............    X    Y    Z
 Origin on x,y,z .......................    0.000       0.000       0.000
 Minimum density .......................  0.78800
 Maximum density .......................   1.7497
 Mean density ..........................   1.0034
 tilt angles (original,current) ........   0.0   0.0   0.0   0.0   0.0   0.0
 Space group,# extra bytes,idtype,lens .        0        0        0        0

     1 Titles :
NEWSTACK: Images copied                                  9-May-25  14:14:08

If I look at the motion corrected micrograph with relion_display it looks fine, but the outputs are not usable due to this error. What is going on here?

Here are the test stack and gain so the error can be reproduced (Cs=2.7, 300kV, Apix=1.66, dose=58.2):

stack: https://www.dropbox.com/scl/fi/bfl74x7bxlzmu524wt38o/lzw_test.tif?rlkey=t0elv8sixm6137b39ujpv2aez&dl=0

gain: https://www.dropbox.com/scl/fi/cxzlr54579z75z5us01v5/bin2_gain.mrc?rlkey=p23f7o4bbhjfovj4079he2gfx&dl=0

Cheers
Oli