Code Monkey home page Code Monkey logo

Comments (8)

foustoukosg avatar foustoukosg commented on August 21, 2024 1

Hello,

Sure. You can find here the part of my code doing this conversion (saving a session to tiff stacks of 1000 frames)

Yes I thought also that the bin file can be directly used but I did not have the time to change the code so much. What is indeed bizarre is that the Suite2p code is also using the tifffile package to write the frames (if you put the reg_tiff paramater on) as I am using as well. FISSA is reading my frames correctly but not the Suite2P ones

Thanks again a lot for your FISSA code.

Best,
Georgios

` mouseName = #the mouse flag

sessionDate = #the date of the imaging

binFile = PathToBinFile

tiffSavePath = SavePath #final saving path

Lx = 512 # that's my imaging pixel size
Ly = 512

nbytestoread = 2LxLy

file = -1

NumOfFrames = #you need to add here the total number of frames

#I am saving the tiff files to chuncks of 1000 to avoid huge tiff files (my sessions are pretty long)

movie = np.zeros((1000, Ly, Lx), dtype = 'int16')

with open(binFile, 'rb') as binary_file:

      for cframe in range(NumOfFrames):   #NumberOfFrames here is the total number of frames of that session

          bytesToSeek = int(nbytestoread*(cframe)) # I suppose here that you bin file starts directly
          binary_file.seek(bytesToSeek,0)
          buff = binary_file.read(nbytestoread)
          movie[np.mod(cframe,1000),:,:] = np.reshape(np.frombuffer(buff, dtype = np.int16, offset = 0),(Ly,Lx))

          if (np.mod(cframe,1000) == 999):

              file += 1

              fileLen = len(str(file))

              zeros = str(0) * (4-fileLen) + str(file)

              print('Doing frame: ' + str(cframe + 1))

              finalPathToSave =  os.path.join(tiffSavePath, mouseName + '_' + sessionDate + '_' + zeros + '.tif')

              with TiffWriter(finalPathToSave, bigtiff=True) as tif:
                  tif.save(movie, photometric='minisblack')

              movie = np.zeros((1000, Ly, Lx), dtype = 'int16')

     # save the remaining frames after the last multiple of 1000's

      file += 1

      fileLen = len(str(file))

      zeros = str(0) * (4-fileLen) + str(file)

      print('Doing frame: ' + str(cframe + 1))

      finalPathToSave =  os.path.join(tiffSavePath, mouseName + '_' + sessionDate + '_' + zeros + '.tif')

      lastFrames = NumOfFrames - (file + 1)*1000

      movieToEnd = movie[0:lastFrames,:,:]

      with TiffWriter(finalPathToSave, bigtiff=True) as tif:
          tif.save(movieToEnd, photometric='minisblack')

      print('Tiff writing has finished..')`

from fissa.

swkeemink avatar swkeemink commented on August 21, 2024

Hi @foustoukosg ,

Thanks for bringing this to our attention. We are actually working out some bugs with changes in the suite2p code which we have to adjust for (see #147), so might have to do with that. Are you able to run any of our example notebooks?

A couple of questions:

  • What OS are you on, and what do you use to manage your python environment (e.g. conda)?
  • What version of Python and Suite2P are you using?
  • Could you share with us the output of conda env list and pip freeze for your environment?

Sander

from fissa.

foustoukosg avatar foustoukosg commented on August 21, 2024

Hello,

I am using Python 3.7.7 on Windows 10 with Suite2p version installed 0.9.3. I am using Conda for python environment.

Actually I have looked more into the FISSA code and i think i managed to pin out where exactly the problem is coming from. To my understanding the error I get is caused by the way FISSA is reading the tiff stack of the Suite2p registered frames. Especially your function:

image2array

of the datahandler.py

the command:

tifffile.imread(image)

Instead or reading the whole stack of the tiff file (usually for suite2p this is 500 if you put reg_tiff option as true) is reading only the first frame of the stuck. Thus, at the later stage an error is raised by FISSA cause ROIs structure and the data image structure does not match.

Interestingly enough, if i use the data.bin file that is also written by suite2p during registration back to tiff with my own code (using the TiffWritter of the tifffile package) the problem is solved and FISSA seems to be running normally.

I hope this helps a bit more the debugging process and thanks a lot for your open FISSA code.

Best,
Georgios

from fissa.

swkeemink avatar swkeemink commented on August 21, 2024

Excellent, thanks for the help from your side! This will certainly be helpful in debugging and solving this for future users.

I'll leave this issue open until we have fixed this in our own actual code too.

from fissa.

swkeemink avatar swkeemink commented on August 21, 2024

I have reproduced this error, and am working on updating the general suite2p implementation in #150

from fissa.

swkeemink avatar swkeemink commented on August 21, 2024

@foustoukosg , out of interest and usefulness, could you share your code for interacting with the data.bin file?

There should actually be no need to save them as a tiff, you could just interface fissa with the data.bin directly.

from fissa.

swkeemink avatar swkeemink commented on August 21, 2024

This solution also works and is a bit less of a hassle: MouseLand/suite2p#647

I will implement this in the FISSA examples.

Also: many thanks for sharing your code! That will be useful if in the future similar issues might pop up.

from fissa.

swkeemink avatar swkeemink commented on August 21, 2024

Our tif reading implementation is now much more robust thanks to #170 so closing this.

from fissa.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.