Re: [XNAT Discussion] impossible to connect to XNAT Desktop Client with admin admin

29 views
Skip to first unread message
Message has been deleted

Rick Herrick

unread,
Apr 15, 2024, 11:30:25 AMApr 15
to xnat_di...@googlegroups.com

The desktop client only uploads DICOM resources to XNAT, not NIFTI or any other non-DICOM resources. If you’ve created a DICOM experiment, you can add NIFTI resources to it through the XNAT web UI or via script, but not through the desktop client.

 

From: xnat_di...@googlegroups.com <xnat_di...@googlegroups.com> on behalf of Albertina Ripanu <albertin...@gmail.com>
Date: Monday, April 15, 2024 at 10:24
AM
To: xnat_discussion <xnat_di...@googlegroups.com>
Subject: [XNAT Discussion] impossible to connect to XNAT Desktop Client with admin admin

You don't often get email from albertin...@gmail.com. Learn why this is important

Basically, I have installed the  XNAT ML Docker-Compose Release using ubuntu. I have loged in with admin and password admin to the server . But i need to upload nii.gz files worth of aproximately 4gb and I saw that I can upload them using Xnat Desktop Client.  I try to add and create resource file...but I can not pass the resource as it doesn t give any message if it has been created or not. Whaat is the issue. 

PS C:\new> python .\check.py
Successfully connected to XNAT!
Subject '1' already exists.
Experiment 'experiment' already exists.
An error occurred while connecting to XNAT: in /projects/darwin/subjects/1/experiments/experiment

 

Code 

import os

from pyxnat import Interface

 

# Set up the connection parameters

server_url = 'http://localhost:80'

username = 'admin'

password = 'admin'

project_id = 'darwin'

resource_name ='NIFTI'

try:

    # Attempt to establish a connection to XNAT

    interface = Interface(server=server_url, user=username, password=password)

 

    # Check if the connection was successful by fetching a project list

    project_list = interface.select.projects().get()

 

    # If we can retrieve projects, the connection is successful

    if project_list:

        print("Successfully connected to XNAT!")

    else:

        print("Connection to XNAT failed.")

 

    # Select the project

    project = interface.select.project(project_id)

 

    # Check if the project exists

    if not project.exists():

        # If the project doesn't exist, create it

        project.create()

        print(f"Project '{project_id}' created successfully.")

   

    subject_id = str(1)  # Convert the loop index to a string for subject ID

    subject = project.subject(subject_id)

 

        # Check if the subject already exists

    if not subject.exists():

            # If the subject doesn't exist, create it

        subject.create()

        print(f"Subject '{subject_id}' created successfully.")

    else:

        print(f"Subject '{subject_id}' already exists.")

 

        # Create an experiment named 'experiment' for the subject (PET session data)

    experiment_label = 'experiment'

    experiment = subject.experiment(experiment_label)

 

        # Check if the experiment already exists

    if not experiment.exists():

            # If the experiment doesn't exist, create it

        experiment.create(experiments='xnat:petSessionData')

        print(f"Experiment '{experiment_label}' created for subject '{subject_id}'.")

    else:

        print(f"Experiment '{experiment_label}' already exists.")

 

        # Select the resource within the experiment

    resource = experiment.resource(resource_name)

 

        # Check if the resource exists; create if it doesn't

    if not resource.exists():

        resource.create()

        print(f"Resource '{resource_name}' created for experiment '{experiment_label}'.")

    else:

        print(f"Resource  '{resource_name}' already exists.")

 

        # Define paths to the NIfTI files for this subject

    ceT1_file_path = f'data/crossmoda2022_etz_{subject_id}_ceT1.nii.gz'

    label_file_path = f'data/crossmoda2022_etz_{subject_id}_Label.nii.gz'

    if os.path.exists(ceT1_file_path):

        print("checked")

       

        # Upload ceT1 file as a resource to the experiment

    if os.path.exists(ceT1_file_path):

            # Insert the ceT1 file into the experiment's 'NIFTI' resource

        experiment.resource('NIFTI').file(f'{subject_id}_ceT1.nii.gz').insert(

            ceT1_file_path,

            content='T1',

            format='NIFTI',

            tags='ceT1'

        )

        print(f"ceT1 NIfTI file uploaded for subject '{subject_id}'.")

 

        # Upload Label file as a resource to the experiment

    if os.path.exists(label_file_path):

            # Insert the Label file into the experiment's 'NIFTI' resource

        experiment.resource('NIFTI').file(f'{subject_id}_Label.nii.gz').insert(

            label_file_path,

            content='Label',

            format='NIFTI',

            tags='Label'

        )

        print(f"Label NIfTI file uploaded for subject '{subject_id}'.")

 

except Exception as e:

    print(f"An error occurred while connecting to XNAT: {e}")

--
You received this message because you are subscribed to the Google Groups "xnat_discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xnat_discussi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/xnat_discussion/59c22582-a48c-47ca-92d2-1f5df269f7dan%40googlegroups.com.

Albertina Ripanu

unread,
Apr 15, 2024, 1:35:34 PMApr 15
to xnat_di...@googlegroups.com
Apparently it was an error with the fact that I call the experiment and “experiment”. I saw that I have added them to resources but how do you manage them being in resources , for future machine learning purposes? 
And I noticed that If I do a scan and then add a folder , I can add there NiFti too. Is that ok ? Is there any way I can add more scans and folders and NiFTI through coding , rather manually as I have over 200 files to add as they represent different clients . 

Rick Herrick

unread,
Apr 15, 2024, 2:00:09 PMApr 15
to xnat_di...@googlegroups.com

ALL XNAT-managed data is stored in resources, including DICOM data. The ML implementation actually uses NIFTI resources directly rather than DICOM anyway, so you’re actually fine in your current state.

 

The one difference is that NIFTI resources are usually associated with the scan from which the NIFTI was generated rather than with the experiment itself. If you upload a DICOM session with the desktop client and inspect it, you’ll see that the resulting experiment has X scans corresponding to the series in the original DICOM study. Each of those scans has an associated resource labeled DICOM. There’s a container image for generating NIFTI from DICOM in XNAT (here, but I can’t find the regular documentation on using it) that takes the DICOM from each scan as an input and generates NIFTI data into a resource labeled NIFTI.

 

So yes: adding a NIFTI folder on each scan and pushing that data into that resource is precisely what you should do. You can definitely script this as well. Just walk your data, create an experiment for each study, create a scan on that experiment for each series, create a NIFTI resource on each scan, then push the NIFTI data for the scan to that resource.

 

Reply all
Reply to author
Forward
0 new messages