• NILEARN - WHY THIS CODE THROWS AN ERROR?????

    From =?UTF-8?B?16DXqteZINep15jXqNef?=@21:1/5 to All on Fri Jul 8 16:06:09 2022
    fullcode:



    import nilearn.plotting as plot
    import os,gzip,io
    import nibabel as nib
    path="C:/users/administrator/desktop/nii" path2="C:/users/administrator/desktop/nii/out/"
    for i in os.listdir(path):
    if(".nii.gz" in i):
    pass
    else:

    if(".nii" in i):
    img = nib.load(path+"/"+i)
    data = img.get_fdata()
    print(data)
    import imageio
    X=0
    for s in data:
    import numpy
    aleph=numpy.array(s,dtype=numpy.int8)
    X=X+1
    plot.plot_img(aleph)

    imageio.imwrite("C:\\users\\administrator\\desktop\\nii\\"+i +str(X)+'.jpg', s)






    error:
    Data given cannot be loaded because it is not compatible with nibabel
    format
    <https://netanel.ml>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From MRAB@21:1/5 to All on Fri Jul 8 21:47:38 2022
    On 08/07/2022 14:06, נתי שטרן wrote:
    fullcode:



    import nilearn.plotting as plot
    import os,gzip,io
    import nibabel as nib
    path="C:/users/administrator/desktop/nii" path2="C:/users/administrator/desktop/nii/out/"
    for i in os.listdir(path):
    if(".nii.gz" in i):
    pass
    else:

    if(".nii" in i):
    img = nib.load(path+"/"+i)
    data = img.get_fdata()
    print(data)
    import imageio
    X=0
    for s in data:
    import numpy
    aleph=numpy.array(s,dtype=numpy.int8)
    X=X+1
    plot.plot_img(aleph)

    imageio.imwrite("C:\\users\\administrator\\desktop\\nii\\"+i +str(X)+'.jpg', s)






    error:
    Data given cannot be loaded because it is not compatible with nibabel
    format
    <https://netanel.ml>

    What's the complete traceback?

    It might help you to identify the problem if you add messages to tell
    you what it's doing, e.g. what file it's about to load.

    Apparently, one of the files is not compatible with nibabel.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Avi Gross@21:1/5 to All on Fri Jul 8 22:20:39 2022
    Nati Stern has asked several questions here, often about relatively technical uses of python code that many of us have never used and still is not providing more exact info that tends to be needed before anyone can even think of diagnosing the problem.

    I have learned to stay away from some such questioners. But I am wondering if some people (others too) think this forum is a generalized help desk staffed by College Professors with nothing else to do.

    Many questions are best handled locally where people can look over your shoulder or use the same software and may have some fluency in your native language. And sometimes you need to do more investigating on your own, and perhaps tell us what you tried
    and why it was not useful, or we end up making endless suggestions and being told we are not working on your real issue and so on.

    The code below is just babel or maybe babble. Something nested in a loop had a problem. Why not try something drastic and look at the  files and PICK ONE and use it step by step and see when it fails?

    It looks like the code wants to ask for all files then ignore some. 

    Why you would import numpy repeatedly in a loop is beyond me! LOL!

    But which command line failed? My GUESS is:

    data = img.get_fdata()


    If so, did you try to see the current value of the filename you call "i" in the loop and see what name was loaded in what looks like a file ending in .nii in this code:

    img = nib.load(path+"/"+i)


    You need to proceed step by step and see if any previous steps failed. 
    But what is possible is you got a file with .nii in middle of the name that does not end in .gz, or is not in the format needed.
    Good luck,
    אבי גרוס

    -----Original Message-----
    From: MRAB <python@mrabarnett.plus.com>
    To: python-list@python.org
    Sent: Fri, Jul 8, 2022 4:47 pm
    Subject: Re: NILEARN - WHY THIS CODE THROWS AN ERROR?????

    On 08/07/2022 14:06, נתי שטרן wrote:
    fullcode:



    import nilearn.plotting as plot
    import os,gzip,io
    import nibabel as nib
    path="C:/users/administrator/desktop/nii" path2="C:/users/administrator/desktop/nii/out/"
    for i in os.listdir(path):
          if(".nii.gz" in i):
              pass
          else:

              if(".nii" in i):
                  img = nib.load(path+"/"+i)
                  data = img.get_fdata()
                  print(data)
                  import imageio
                  X=0
                  for s in data:
                      import numpy
                      aleph=numpy.array(s,dtype=numpy.int8)
                      X=X+1
                      plot.plot_img(aleph)

                      imageio.imwrite("C:\\users\\administrator\\desktop\\nii\\"+i
    +str(X)+'.jpg', s)






    error:
    Data given cannot be loaded because it is not compatible with nibabel
    format
    <https://netanel.ml>

    What's the complete traceback?

    It might help you to identify the problem if you add messages to tell
    you what it's doing, e.g. what file it's about to load.

    Apparently, one of the files is not compatible with nibabel.
    --
    https://mail.python.org/mailman/listinfo/python-list

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris Angelico@21:1/5 to MRAB on Sat Jul 9 10:58:29 2022
    On Sat, 9 Jul 2022 at 10:57, MRAB <python@mrabarnett.plus.com> wrote:

    On 08/07/2022 23:20, Avi Gross via Python-list wrote:
    Nati Stern has asked several questions here, often about relatively technical uses of python code that many of us have never used and still is not providing more exact info that tends to be needed before anyone can even think of diagnosing the
    problem.

    I have learned to stay away from some such questioners. But I am wondering if some people (others too) think this forum is a generalized help desk staffed by College Professors with nothing else to do.

    Many questions are best handled locally where people can look over your shoulder or use the same software and may have some fluency in your native language. And sometimes you need to do more investigating on your own, and perhaps tell us what you
    tried and why it was not useful, or we end up making endless suggestions and being told we are not working on your real issue and so on.

    The code below is just babel or maybe babble. Something nested in a loop had a problem. Why not try something drastic and look at the files and PICK ONE and use it step by step and see when it fails?

    It looks like the code wants to ask for all files then ignore some.

    Why you would import numpy repeatedly in a loop is beyond me! LOL!

    But which command line failed? My GUESS is:

    data = img.get_fdata()


    If so, did you try to see the current value of the filename you call "i" in the loop and see what name was loaded in what looks like a file ending in .nii in this code:

    img = nib.load(path+"/"+i)


    You need to proceed step by step and see if any previous steps failed.
    But what is possible is you got a file with .nii in middle of the name that does not end in .gz, or is not in the format needed.

    Indeed, it writes JPEG files whose filename contains the original
    filename (with the ".nii") into the same folder, so if it has already
    been run and produced an output file, the next time it's run, it'll trip itself up.

    All this would've been clear to the OP if it had printed messages as it
    went.

    Or if the OP had renamed them all to "shrubbery" along the way.

    ChrisA

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From MRAB@21:1/5 to Avi Gross via Python-list on Sat Jul 9 01:51:44 2022
    On 08/07/2022 23:20, Avi Gross via Python-list wrote:
    Nati Stern has asked several questions here, often about relatively technical uses of python code that many of us have never used and still is not providing more exact info that tends to be needed before anyone can even think of diagnosing the
    problem.

    I have learned to stay away from some such questioners. But I am wondering if some people (others too) think this forum is a generalized help desk staffed by College Professors with nothing else to do.

    Many questions are best handled locally where people can look over your shoulder or use the same software and may have some fluency in your native language. And sometimes you need to do more investigating on your own, and perhaps tell us what you
    tried and why it was not useful, or we end up making endless suggestions and being told we are not working on your real issue and so on.

    The code below is just babel or maybe babble. Something nested in a loop had a problem. Why not try something drastic and look at the  files and PICK ONE and use it step by step and see when it fails?

    It looks like the code wants to ask for all files then ignore some.

    Why you would import numpy repeatedly in a loop is beyond me! LOL!

    But which command line failed? My GUESS is:

    data = img.get_fdata()


    If so, did you try to see the current value of the filename you call "i" in the loop and see what name was loaded in what looks like a file ending in .nii in this code:

    img = nib.load(path+"/"+i)


    You need to proceed step by step and see if any previous steps failed.
    But what is possible is you got a file with .nii in middle of the name that does not end in .gz, or is not in the format needed.

    Indeed, it writes JPEG files whose filename contains the original
    filename (with the ".nii") into the same folder, so if it has already
    been run and produced an output file, the next time it's run, it'll trip
    itself up.

    All this would've been clear to the OP if it had printed messages as it
    went.

    Good luck,
    אבי גרוס

    -----Original Message-----
    From: MRAB <python@mrabarnett.plus.com>
    To: python-list@python.org
    Sent: Fri, Jul 8, 2022 4:47 pm
    Subject: Re: NILEARN - WHY THIS CODE THROWS AN ERROR?????

    On 08/07/2022 14:06, נתי שטרן wrote:
    fullcode:



    import nilearn.plotting as plot
    import os,gzip,io
    import nibabel as nib
    path="C:/users/administrator/desktop/nii"
    path2="C:/users/administrator/desktop/nii/out/"
    for i in os.listdir(path):
          if(".nii.gz" in i):
              pass
          else:

              if(".nii" in i):
                  img = nib.load(path+"/"+i)
                  data = img.get_fdata()
                  print(data)
                  import imageio
                  X=0
                  for s in data:
                      import numpy
                      aleph=numpy.array(s,dtype=numpy.int8)
                      X=X+1
                      plot.plot_img(aleph)

                      imageio.imwrite("C:\\users\\administrator\\desktop\\nii\\"+i
    +str(X)+'.jpg', s)






    error:
    Data given cannot be loaded because it is not compatible with nibabel
    format
    <https://netanel.ml>

    What's the complete traceback?

    It might help you to identify the problem if you add messages to tell
    you what it's doing, e.g. what file it's about to load.

    Apparently, one of the files is not compatible with nibabel.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)