def MergeSeriesCopy(objWeasel): ui = UserInterfaceTools(objWeasel) imageList = ui.getCheckedImages() if imageList is None: return # Exit function if no images are checked mergedSeries = Image.merge(imageList, series_name='Overwritten_Series', overwrite=True) ui.refreshWeasel() mergedSeries.DisplaySeries()
def main(objWeasel): ui = UserInterfaceTools(objWeasel) # Get all series in the Checkboxes studiesList = ui.getCheckedStudies() if studiesList is None: return # Exit function if no study are checked for study in studiesList: seriesList = study.children # List of series that will be used for T1 Map calculation seriesListTI = [] for series in seriesList: # First, collect all series that belong to T1 calculation. This is because 1 series <=> 1 image/TI if checkT1(series): seriesListTI.append(series) if seriesListTI: mergedSeries = Series.merge(seriesListTI, series_name='All_TIs', overwrite=False) mergedSeries.sort("SliceLocation", "InversionTime") magnitudeSeries = mergedSeries.Magnitude # CONSIDER REFORMAT_SHAPE - 4D such as (256, 256, 5, 10) for eg. ti = magnitudeSeries.InversionTimes magnitude = magnitudeSeries.PixelArray phaseSeries = mergedSeries.Phase if phaseSeries.images: phase = convert_to_pi_range(phaseSeries.PixelArray) complex_data = magnitude * (np.cos(phase) + 1j * np.sin(phase)) # convert magnitude and phase into complex data magnitude_corrected = magnitude_correct(complex_data) inputArray = magnitude_corrected else: inputArray = magnitude mapper = T1(np.transpose(inputArray), ti, multithread=True, parameters=2) pixelArray = mapper.t1_map outputSeries = mergedSeries.new(series_name="T1Map_UKRIN", suffix=FILE_SUFFIX) outputSeries.write(np.transpose(pixelArray)) ui.refreshWeasel()
def main(objWeasel): ui = UserInterfaceTools(objWeasel) seriesList = ui.getCheckedSeries() if seriesList is None: return # Exit function if no series are checked mergedSeries = Series.merge(seriesList, series_name='NewSeries', overwrite=False) ui.refreshWeasel() mergedSeries.DisplaySeries()
def selectXNATPathDownload(self, tree_view_dir=False): if tree_view_dir == False: ui = UserInterfaceTools(self) directory = ui.selectFolder( title="Select the directory where you wish to download") else: directory = self.DICOMfolderPath return directory
def main(objWeasel): ui = UserInterfaceTools(objWeasel) seriesList = ui.getCheckedSeries() if seriesList is None: return # Exit function if no series are checked # Lower and upper threshold from the input window inputDict = {"Lower Threshold": "integer", "Upper Threshold": "integer"} info = "Insert a value between 0 and 100. Upper threshold must be greater than lower threshold" paramList = ui.inputWindow(inputDict, title="Input Parameters", helpText=info) if paramList is None: return # Exit function if the user hits the "Cancel" button low_thresh = paramList[0] high_thresh = paramList[1] index_series = 1 for series in seriesList: newSeries = series.new(suffix=FILE_SUFFIX) index_bar = 0 for image in series.children: newImage = image.new(series=newSeries) index_bar = ui.progressBar(maxNumber=series.numberChildren, index=index_bar, msg="Thresholding and saving image {}", title="Threshold of series " + str(index_series)) pixelArray = image.PixelArray pixelArray = thresholdPixelArray( pixelArray, low_thresh, high_thresh) # NOT WORKING WELL ON NEGATIVE IMAGES newImage.write(pixelArray, series=newSeries) index_series += 1 ui.closeMessageWindow() # Refresh the UI screen ui.refreshWeasel(new_series_name=newSeries.seriesID) newSeries.DisplaySeries()
def main(objWeasel): ui = UserInterfaceTools(objWeasel) seriesList = ui.getCheckedSeries() if seriesList is None: return # Exit function if no series are checked for series in seriesList: newSeries = series.new(suffix=FILE_SUFFIX) pixelArray = series.PixelArray pixelArray = np.square(pixelArray) newSeries.write(pixelArray) ui.refreshWeasel(new_series_name=newSeries.seriesID) newSeries.DisplaySeries()
def main(objWeasel): ui = UserInterfaceTools(objWeasel) # Get all images in the Checkboxes imageList = ui.getCheckedImages() if imageList is None: return # Exit function if no images are checked index_bar = 0 for image in imageList: # Get PixelArray from the corresponding slice pixelArray = image.PixelArray dataset = image.PydicomObject # Apply Invert pixelArray = invertAlgorithm(pixelArray, dataset) # Progress Bar index_bar = ui.progressBar(maxNumber=len(imageList), index=index_bar, msg="Inverting and overwriting image {}", title="Invert checked series ") # Overwrite - write() checks if file already exists so it writes new or overwrite image.write(pixelArray) # Close the progress bar ui.closeMessageWindow() # Refresh the UI screen ui.refreshWeasel(new_series_name=imageList[-1].seriesID) # Display all checked images Image.DisplayImages(imageList)
def selectXNATPathUpload(self, tree_view=False): listPaths = [] ui = UserInterfaceTools(self) if tree_view == True: images = ui.getCheckedImages() for image in images: listPaths.append(image.path) else: directory = ui.selectFolder( title="Select the directory with the files you wish to upload") for root, _, files in os.walk(directory): for filename in files: filepath = os.path.join(root, filename) listPaths.append(filepath) return listPaths
def main(objWeasel): ui = UserInterfaceTools(objWeasel) # Get all series in the Checkboxes seriesList = ui.getCheckedSeries() if seriesList is None: return # Exit function if no series are checked for series in seriesList: seriesPhase = series.Phase seriesReal = series.Real seriesImaginary = series.Imaginary if checkB0(seriesPhase): seriesPhase.sort("SliceLocation", "EchoTime") te = np.unique(seriesPhase.EchoTimes) pixelArray = seriesPhase.PixelArray # (32, 256, 256) reformatShape = (len(te), int(np.shape(pixelArray)[0] / len(te)), np.shape(pixelArray)[1], np.shape(pixelArray)[2]) phase = np.transpose( pixelArray.reshape(reformatShape) ) # (2, 16, 256, 256) => (256, 256, 16, 2) after the np.transpose # Initialise B0 mapping object mapper_B0 = B0(phase, te, unwrap=True) b0map = mapper_B0.b0_map # (256, 256, 16) newSeries = seriesPhase.new(suffix=FILE_SUFFIX) newSeries.write(np.transpose(b0map)) # (16, 256, 256) # Refresh the UI screen ui.refreshWeasel(new_series_name=newSeries.seriesID) # Display series newSeries.DisplaySeries() elif checkB0(seriesReal) and checkB0(seriesImaginary): seriesReal.sort("SliceLocation", "EchoTime") seriesImaginary.sort("SliceLocation", "EchoTime") te = np.unique(seriesReal.EchoTimes) pixelArray = np.arctan2(seriesImaginary.PixelArray, seriesReal.PixelArray) # (32, 256, 256) reformatShape = (len(te), int(np.shape(pixelArray)[0] / len(te)), np.shape(pixelArray)[1], np.shape(pixelArray)[2]) phase = np.transpose( pixelArray.reshape(reformatShape) ) # (2, 16, 256, 256) => (256, 256, 16, 2) after the np.transpose # Initialise B0 mapping object mapper_B0 = B0(phase, te, unwrap=True) b0map = mapper_B0.b0_map # (256, 256, 16) newSeries = seriesReal.new(suffix=FILE_SUFFIX) newSeries.write(np.transpose(b0map)) # (16, 256, 256) # Refresh the UI screen ui.refreshWeasel(new_series_name=newSeries.seriesID) # Display series newSeries.DisplaySeries() else: ui.showMessageWindow( msg= 'The checked series doesn\'t meet the criteria to calculate the B0 Map', title='NOT POSSIBLE TO CALCULATE B0 MAP')
def main(objWeasel): ui = UserInterfaceTools(objWeasel) # Get all series in the Checkboxes seriesList = ui.getCheckedSeries() if seriesList is None: return # Exit function if no series are checked for series in seriesList: seriesMagnitude = series.Magnitude if checkT2Star(seriesMagnitude): if seriesMagnitude.Multiframe: seriesMagnitude.sort("PerFrameFunctionalGroupsSequence.MREchoSequence.EffectiveEchoTime", "PerFrameFunctionalGroupsSequence.FrameContentSequence.InStackPositionNumber") else: seriesMagnitude.sort("EchoTime", "SliceLocation") te = np.unique(seriesMagnitude.EchoTimes) pixelArray = np.transpose(seriesMagnitude.PixelArray) # (256, 256, 60) reformatShape = (np.shape(pixelArray)[0], np.shape(pixelArray)[1], int(np.shape(pixelArray)[2]/len(te)), len(te)) pixelArray = pixelArray.reshape(reformatShape) # (256, 256, 5, 12) # Initialise the loglin mapping object mapper_loglin = T2Star(pixelArray, te, method='loglin') # mapper_2p_exp = T2Star(pixelArray, te, method='2p_exp') # Extract the T2* map from the object t2star_loglin = mapper_loglin.t2star_map # (256, 256, 5) newSeries = seriesMagnitude.new(suffix=FILE_SUFFIX) newSeries.write(np.transpose(t2star_loglin)) # (5, 256, 256) # Refresh the UI screen ui.refreshWeasel(new_series_name=newSeries.seriesID) # Display series newSeries.DisplaySeries() else: ui.showMessageWindow(msg='The checked series doesn\'t meet the criteria to calculate the T2* Map', title='NOT POSSIBLE TO CALCULATE T2* MAP')
def main(objWeasel): ui = UserInterfaceTools(objWeasel) # Get all series in the Checkboxes seriesList = ui.getCheckedSeries() if seriesList is None: return # Exit function if no series are checked for series in seriesList: seriesMagnitude = series.Magnitude if checkT2(seriesMagnitude): seriesMagnitude.sort("EchoTime") seriesMagnitude.sort("SliceLocation") te = np.unique(seriesMagnitude.EchoTimes) pixelArray = np.transpose(seriesMagnitude.PixelArray) reformatShape = (np.shape(pixelArray)[0], np.shape(pixelArray)[1], int(np.shape(pixelArray)[2] / len(te)), len(te)) pixelArray = pixelArray.reshape(reformatShape) mapper = T2(pixelArray, te) t2Map = mapper.t2_map newSeries = seriesMagnitude.new(suffix=FILE_SUFFIX) newSeries.write(np.transpose(t2Map)) # Refresh the UI screen ui.refreshWeasel(new_series_name=newSeries.seriesID) # Display series newSeries.DisplaySeries() else: ui.showMessageWindow( msg= 'The checked series doesn\'t meet the criteria to calculate the T2 Map', title='NOT POSSIBLE TO CALCULATE T2 MAP')
def main(objWeasel): ui = UserInterfaceTools(objWeasel) # Get all series in the Checkboxes seriesList = ui.getCheckedSeries() # If all dimensions are not the same then return error if checkDimensionsMatch(seriesList) is None: return newSeries = seriesList[0].new(suffix=FILE_SUFFIX) nrOfImages = seriesList[0].numberChildren for i in range(nrOfImages): outputArray = seriesList[0].children[i].PixelArray for series in seriesList[1:]: outputArray *= series.children[i].PixelArray newImage = seriesList[0].children[i].new(series=newSeries) newImage.write(outputArray, series=newSeries) # Refresh the UI screen ui.refreshWeasel(new_series_name=newSeries.seriesID) # Display series newSeries.DisplaySeries()
def main(objWeasel): ui = UserInterfaceTools(objWeasel) # In this case, the user introduces the sigma value intended for the gaussian filter inputDict = {"Standard Deviation": "float"} paramList = ui.inputWindow( inputDict, title="Input Parameters for the Gaussian Filter") if paramList is None: return # Exit function if the user hits the "Cancel" button standard_deviation_filter = paramList[0] # Get checked images imageList = ui.getCheckedImages() if imageList is None: return # Exit function if no images are checked # Create new Series where the resulting images will be saved newSeries = Image.newSeriesFrom(imageList, suffix=FILE_SUFFIX) for image in imageList: # Create new image based on the current image newImage = image.new(series=newSeries) # Get PixelArray from the selected images pixelArray = image.PixelArray # Apply Gaussian Filter pixelArray = gaussianFilter(pixelArray, standard_deviation_filter) # Save as individual image into new Series newImage.write(pixelArray, series=newSeries) # Refresh the UI screen ui.refreshWeasel(new_series_name=newSeries.seriesID) # Display resulting image newSeries.DisplaySeries()
def main(objWeasel): ui = UserInterfaceTools(objWeasel) # In this case, the user introduces the sigma value intended for the gaussian filter inputDict = {"Standard Deviation": "float"} paramList = ui.inputWindow( inputDict, title="Input Parameters for the Gaussian Filter") if paramList is None: return # Exit function if the user hits the "Cancel" button standard_deviation_filter = paramList[0] # Get checked series seriesList = ui.getCheckedSeries() if seriesList is None: return # Exit function if no series are checked for series in seriesList: # Create a new Series for each Series checked newSeries = series.new(series_name="GaussianFiltered_" + str(series.seriesID)) # Get series' PixelArray pixelArray = series.PixelArray # Apply Gaussian filter pixelArray = gaussianFilter(pixelArray, standard_deviation_filter) # Save resulting PixelArray into the new Series newSeries.write(pixelArray) # Refresh the UI screen ui.refreshWeasel(new_series_name=newSeries.seriesID) # Display resulting image newSeries.DisplaySeries()
def main(objWeasel): ui = UserInterfaceTools(objWeasel) inputDict = {"DICOM Tag":"string", "Value":"string"} helpMsg = 'The DICOM Tag can be inserted in string or hexadecimal format.\nExample:\n'\ '(0010,0010) => type PatientName or 0x00100010' paramList = ui.inputWindow(inputDict, title="Insert DICOM Tag element to change and its new value", helpText=helpMsg) if paramList is None: return # Exit function if the user hits the "Cancel" button tag = paramList[0] value = paramList[1] imageList = ui.getCheckedImages() if imageList is None: return # Exit function if no images are checked ui.showMessageWindow(msg="Overwriting the checked DICOM files with the typed values", title="Edit DICOM") for image in imageList: image.Item(tag, value) ui.closeMessageWindow() imageList[0].DisplayMetadata()
def main(objWeasel): ui = UserInterfaceTools(objWeasel) # Get all series in the Checkboxes seriesList = ui.getCheckedSeries() # getSelectedStudy() if seriesList is None: return # Exit function if no series are checked # List of series that will be used for T1 Map calculation seriesListTI = [] for series in seriesList: # First, collect all series that belong to T1 calculation. This is because 1 series <=> 1 image/TI if checkT1(series): seriesListTI.append(series) if seriesListTI: mergedSeries = Series.merge(seriesListTI, series_name='All_TIs', overwrite=False) mergedSeries.sort("SliceLocation", "InversionTime") magnitudeSeries = mergedSeries.Magnitude # CONSIDER REFORMAT_SHAPE - 4D such as (256, 256, 5, 10) for eg. ti = magnitudeSeries.InversionTimes magnitude = magnitudeSeries.PixelArray phaseSeries = mergedSeries.Phase if phaseSeries.images: phase = convert_to_pi_range(phaseSeries.PixelArray) complex_data = magnitude * ( np.cos(phase) + 1j * np.sin(phase) ) # convert magnitude and phase into complex data magnitude_corrected = magnitude_correct(complex_data) inputArray = magnitude_corrected else: inputArray = magnitude mapper = T1(np.transpose(inputArray), ti, multithread=True, parameters=2) pixelArray = mapper.t1_map #outputSeries = mergedSeries.new(series_name="T1Map_UKRIN", suffix=FILE_SUFFIX) outputSeries = seriesListTI[0].new(series_name="T1Map_UKRIN", suffix=FILE_SUFFIX) outputSeries.write(np.transpose(pixelArray)) # Refresh Weasel ui.refreshWeasel(new_series_name=outputSeries.seriesID) # Display series outputSeries.DisplaySeries() else: ui.showMessageWindow( msg= 'The checked series doesn\'t meet the criteria to calculate the T1 Map', title='NOT POSSIBLE TO CALCULATE T1 MAP')
def main(objWeasel): ui = UserInterfaceTools(objWeasel) if tools.treeView.isASeriesSelected(objWeasel): seriesList = ui.getSelectedSeries() if seriesList is None: return # Exit function if no series are checked series = seriesList[ 0] # Because the if conditional only gets the last series selected inputDict = {"New Series Name": "string"} paramList = ui.inputWindow(inputDict, title="Please type in the new series name") if paramList is None: return # Exit function if the user hits the "Cancel" button name = str(paramList[0]) # Perform the change series.Item("SeriesDescription", name) # Change it in the TreeView ui.refreshWeasel() else: ui.showMessageWindow(msg="Please select a series to run this script", title="ERROR: Can't rename series")
def main(objWeasel): ui = UserInterfaceTools(objWeasel) # Get the series in the Checkboxes seriesList = ui.getCheckedSeries() if seriesList is None: return # Exit function if no series are checked series = seriesList[0] if checkT1(series): seriesMagnitude = series.Magnitude try: seriesMagnitude.sort("InversionTime") except: seriesMagnitude.sort(0x20051572) seriesMagnitude.sort("SliceLocation") numSlices = seriesMagnitude.NumberOfSlices ti = np.array( seriesMagnitude.InversionTimes) # array of length = 50 or 10 ti = ti.reshape((int(len(ti) / numSlices), numSlices)) # array of size (10, 5) or (10, 1) pixelArray = np.transpose( seriesMagnitude.PixelArray) # (256, 256, 50) or (256, 256, 10) reformatShape = (np.shape(pixelArray)[0], np.shape(pixelArray)[1], numSlices, int(np.shape(pixelArray)[2] / numSlices)) pixelArray = pixelArray.reshape( reformatShape) # (256, 256, 5, 10) or (256, 256, 1, 10) ####################################################### outputArray = [] for zSlice in range(np.shape(pixelArray)[2]): tempImage = ukrinMaps(np.squeeze( pixelArray[:, :, zSlice, :])).T1Map( ti[:, zSlice]) # There's MATLAB version T1MapMolli outputArray.append(np.transpose(tempImage)) outputArray = np.squeeze(np.array(outputArray)) del tempImage ######################################################## outputSeries = series.new(series_name="T1Map_iBEAT", suffix=FILE_SUFFIX) outputSeries.write(outputArray) # Refresh Weasel ui.refreshWeasel(new_series_name=outputSeries.seriesID) # Display series outputSeries.DisplaySeries() else: ui.showMessageWindow( msg= 'The checked series doesn\'t meet the criteria to calculate the T1 Map', title='NOT POSSIBLE TO CALCULATE T1 MAP')
def upload(objWeasel): # Insert Try/Except ui = UserInterfaceTools(objWeasel) credentialsWindow = { "URL": "string,https://test-ukrin.dpuk.org", "Username": "******", "Password": "******" } info = "Please insert the XNAT URL and your XNAT credentials" loginDetails = ui.inputWindow(credentialsWindow, title="XNAT Login", helpText=info) url = loginDetails[0] # https://test-ukrin.dpuk.org username = loginDetails[1] password = loginDetails[2] with xnat.connect(url, user=username, password=password) as session: xnatProjects = [ project.secondary_id for project in session.projects.values() ] projectWindow = {"Project": "dropdownlist"} projectInfo = "URL: " + url + "<p>Select the Project to upload the images from</p>" projectName = ui.inputWindow(projectWindow, title="XNAT Upload", helpText=projectInfo, lists=[xnatProjects]) if projectName: xnatSubjects = [ subject.label for subject in session.projects[ projectName[0]].subjects.values() ] xnatSubjects.insert(0, "Upload at Project Level") subjectWindow = {"Subject": "dropdownlist"} subjectInfo = "URL: " + url + "<p>Project: " + projectName[ 0] + "</p><p>Select the Subject to upload the images from</p>" subjectName = ui.inputWindow(subjectWindow, title="XNAT Upload", helpText=subjectInfo, lists=[xnatSubjects]) if subjectName: if subjectName[0] == "Upload at Project Level": uploadPaths = selectXNATPathUpload(objWeasel) uploadZipFile = zipFiles(uploadPaths) ui.showInformationWindow( "XNAT Upload", "The selected images will be uploaded to the selected project. The upload progress can be checked in the terminal and you may continue using Weasel." ) try: session.services.import_( uploadZipFile, overwrite='none', project=session.projects[projectName[0]].id, content_type='application/zip') except: warnings.warn( 'The zip file being uploaded contains files already present in the selected image session and the upload assistant cannot overwrite or give the option to not overwrite. \n The selected file or folder was pre-archived in the selected XNAT project. \n Please login to the portal and review and/or archive the images.' ) ui.showInformationWindow("XNAT Upload", "Upload completed!") else: xnatExperiments = [ experiment.label for experiment in session.projects[projectName[0]]. subjects[subjectName[0]].experiments.values() ] xnatExperiments.insert(0, "Upload at Subject Level") experimentWindow = {"Experiment": "dropdownlist"} experimentInfo = "URL: " + url + "<p>Project: " + projectName[ 0] + "</p><p>Subject: " + subjectName[ 0] + "</p><p>Select the Experiment to upload the images from</p>" experimentName = ui.inputWindow(experimentWindow, title="XNAT Upload", helpText=experimentInfo, lists=[xnatExperiments]) if experimentName: if experimentName[0] == "Upload at Subject Level": uploadPaths = selectXNATPathUpload(objWeasel) uploadZipFile = zipFiles(uploadPaths) ui.showInformationWindow( "XNAT Upload", "The selected images will be uploaded to the selected subject. The upload progress can be checked in the terminal and you may continue using Weasel." ) try: session.services.import_( uploadZipFile, overwrite='none', project=session.projects[ projectName[0]].id, subject=session.projects[projectName[0]]. subjects[subjectName[0]].id, content_type='application/zip') except: warnings.warn( 'The zip file being uploaded contains files already present in the selected image session and the upload assistant cannot overwrite or give the option to not overwrite. \n The selected file or folder was pre-archived in the selected XNAT project. \n Please login to the portal and review and/or archive the images.' ) ui.showInformationWindow("XNAT Upload", "Upload completed!") else: uploadPaths = selectXNATPathUpload(objWeasel) uploadZipFile = zipFiles(uploadPaths) ui.showInformationWindow( "XNAT Upload", "The selected images will be uploaded to the selected experiment. The upload progress can be checked in the terminal and you may continue using Weasel." ) try: session.services.import_( uploadZipFile, overwrite='none', project=session.projects[ projectName[0]].id, subject=session.projects[projectName[0]]. subjects[subjectName[0]].id, experiment=session.projects[projectName[0]] .subjects[subjectName[0]].experiments[ experimentName[0]].id, content_type='application/zip') except: warnings.warn( 'The zip file being uploaded contains files already present in the selected image session and the upload assistant cannot overwrite or give the option to not overwrite. \n The selected file or folder was pre-archived in the selected XNAT project. \n Please login to the portal and review and/or archive the images.' ) ui.showInformationWindow("XNAT Upload", "Upload completed!") # Curl Command headers = {"Content-Type": "application/json", "Accept": "*/*"} # Update the project's indices for individual_experiment in session.projects[projectName[0]].experiments: curl_url = url + "/xapi/viewer/projects/" + session.projects[ projectName[0]].id + "/experiments/" + individual_experiment response = requests.post(curl_url, headers=headers, auth=(username, password)) # Delete Login Details del loginDetails, url, username, password # Delete ZIP File os.remove(uploadZipFile) session.disconnect()
def download(objWeasel): # Insert Try/Except ui = UserInterfaceTools(objWeasel) credentialsWindow = { "URL": "string,https://test-ukrin.dpuk.org", "Username": "******", "Password": "******" } info = "Please insert the XNAT URL and your XNAT credentials" loginDetails = ui.inputWindow(credentialsWindow, title="XNAT Login", helpText=info) url = loginDetails[0] # https://test-ukrin.dpuk.org username = loginDetails[1] password = loginDetails[2] with xnat.connect(url, user=username, password=password) as session: xnatProjects = [ project.secondary_id for project in session.projects.values() ] projectWindow = {"Project": "dropdownlist"} projectInfo = "URL: " + url + "<p>Select the Project to download the images from</p>" projectName = ui.inputWindow(projectWindow, title="XNAT Download", helpText=projectInfo, lists=[xnatProjects]) if projectName is None: return if projectName: xnatSubjects = [ subject.label for subject in session.projects[ projectName[0]].subjects.values() ] xnatSubjects.insert(0, "All") subjectWindow = {"Subject": "dropdownlist"} subjectInfo = "URL: " + url + "<p>Project: " + projectName[ 0] + "</p><p>Select the Subject to download the images from</p>" subjectName = ui.inputWindow(subjectWindow, title="XNAT Download", helpText=subjectInfo, lists=[xnatSubjects]) if subjectName is None: return if subjectName: if subjectName[0] == "All": dataset = session.projects[projectName[0]] downloadFolder = selectXNATPathDownload(objWeasel) ui.showInformationWindow( "XNAT Download", "The selected images will be downloaded to the root folder of the TreeView. The download progress can be checked in the terminal and you may continue using Weasel." ) dataset.download_dir(downloadFolder) ui.showInformationWindow("XNAT Download", "Download completed!") else: xnatExperiments = [ experiment.label for experiment in session.projects[projectName[0]]. subjects[subjectName[0]].experiments.values() ] xnatExperiments.insert(0, "All") experimentWindow = {"Experiment": "dropdownlist"} experimentInfo = "URL: " + url + "<p>Project: " + projectName[ 0] + "</p><p>Subject: " + subjectName[ 0] + "</p><p>Select the Experiment to download the images from</p>" experimentName = ui.inputWindow(experimentWindow, title="XNAT Download", helpText=experimentInfo, lists=[xnatExperiments]) if experimentName is None: return if experimentName: if experimentName[0] == "All": dataset = session.projects[ projectName[0]].subjects[subjectName[0]] downloadFolder = selectXNATPathDownload(objWeasel) ui.showInformationWindow( "XNAT Download", "The selected images will be downloaded to the root folder of the TreeView. The download progress can be checked in the terminal and you may continue using Weasel." ) dataset.download_dir(downloadFolder) ui.showInformationWindow("XNAT Download", "Download completed!") else: xnatScans = [ scan.series_description for scan in session.projects[projectName[0]]. subjects[subjectName[0]].experiments[ experimentName[0]].scans.values() ] xnatScans.insert(0, "All") scanWindow = {"Scan": "dropdownlist"} scanInfo = "URL: " + url + "<p>Project: " + projectName[ 0] + "</p><p>Subject: " + subjectName[ 0] + "</p><p>Experiment: " + experimentName[ 0] + "</p><p>Select the Scan to download the images from</p>" scanName = ui.inputWindow(scanWindow, title="XNAT Download", helpText=scanInfo, lists=[xnatScans]) if scanName: if scanName[0] == "All": dataset = session.projects[ projectName[0]].subjects[subjectName[ 0]].experiments[experimentName[0]] downloadFolder = selectXNATPathDownload( objWeasel) ui.showInformationWindow( "XNAT Download", "The selected images will be downloaded to the root folder of the TreeView. The download progress can be checked in the terminal and you may continue using Weasel." ) dataset.download_dir(downloadFolder) ui.showInformationWindow( "XNAT Download", "Download completed!") else: dataset = session.projects[ projectName[0]].subjects[ subjectName[0]].experiments[ experimentName[0]].scans[ scanName[0]] downloadFolder = selectXNATPathDownload( objWeasel) ui.showInformationWindow( "XNAT Download", "The selected images will be downloaded to the root folder of the TreeView. The download progress can be checked in the terminal and you may continue using Weasel." ) dataset.download_dir(downloadFolder) ui.showInformationWindow( "XNAT Download", "Download completed!") # Delete Login Details del loginDetails, url, username, password session.disconnect() return