Esempio n. 1
0
    def test_Philips_DirStructure(self):
        """ test Philips_utils.Philips_DirStucture """
        # update config file to match local paths
        configFile = join(paths['Philips_dir'], 'scannerConfig.yaml')
        helper_tools.replace_scannerConfig_sessionDir(configFile,
                                                      paths['Philips_funcDir'])

        # create instance of ScannerSettings class from general_utils
        scannerSettings = general_utils.ScannerSettings(paths['Philips_dir'])

        # create instance of Philips_DirStructure for testing
        scannerDirs = Philips_utils.Philips_DirStructure(scannerSettings)

        ### Run through Philips_DirStructure class methods
        scannerDirs.print_currentSeries()
        assert scannerDirs.get_seriesDirs() == ['0001']

        ### Test the waitForSeriesDir function by creating a fake dir
        # threading.timer object to create a new dir after a few sec
        fakeNewSeries = join(paths['Philips_funcDir'], '0TEST')
        t = threading.Timer(1.0, helper_tools.createFakeSeriesDir,
                            [fakeNewSeries])
        t.start()

        scannerDirs.waitForSeriesDir()

        # assuming it didn't crash, cancel the timer function and delete new dir
        t.cancel()
        shutil.rmtree(fakeNewSeries)

        # remove local paths from the config file
        helper_tools.cleanConfigFile(configFile)
Esempio n. 2
0
    def test_Siemens_DirStructure(self):
        # update config file to match local paths
        configFile = join(paths['Siemens_dir'], 'scannerConfig.yaml')
        helper_tools.replace_scannerConfig_baseDir(configFile,
                                                   paths['Siemens_funcDir'])

        # create instace of ScannerSettings class from general_utils
        scannerSettings = general_utils.ScannerSettings(paths['Siemens_dir'])

        # create instance of Philips_DirStructure for testing
        scannerDirs = Siemens_utils.Siemens_DirStructure(scannerSettings)

        ## Run through the Siemens_DirStructure class methods
        scannerDirs.print_currentSeries()
        assert scannerDirs.getUniqueSeries() == set(['000013'])

        ## Test waitForNewSeries function by simulating new series data
        # threading.timer object to copy in new data after a few sec
        newSeriesNum = 999
        t = threading.Timer(1.0, fakeNewSiemensSeries, [newSeriesNum])
        t.start()

        scannerDirs.waitForNewSeries()

        # assuming that didn't crash, stop the timer object and remove new file
        t.cancel()
        removeFakeSiemensSeries(newSeriesNum)

        # remove local paths from the config file
        helper_tools.cleanConfigFile(configFile)
Esempio n. 3
0
    def test_initializeSession(self):
        """ test general_utils.initializeSession() """
        # loop over the different scan environments
        for scanEnv in ['GE', 'Philips', 'Siemens']:
            print('testing environment: ' + scanEnv)

            # set paths based on current test environment
            if scanEnv == 'GE':
                envDir = paths['GE_dir']
                funcDir = paths['GE_funcDir']
            elif scanEnv == 'Philips':
                envDir = paths['Philips_dir']
                funcDir = paths['Philips_funcDir']
            elif scanEnv == 'Siemens':
                envDir = paths['Siemens_dir']
                funcDir = paths['Siemens_funcDir']

            # update config file to match local paths
            configFile = join(envDir, 'scannerConfig.yaml')
            helper_tools.replace_scannerConfig_sessionDir(configFile, funcDir)

            general_utils.initializeSession(pynealScannerDir=envDir)

            # remove local paths from config file
            helper_tools.cleanConfigFile(configFile)

            print('Passed!')
Esempio n. 4
0
    def test_Philips_DirStructure(self):
        """ test Philips_utils.Philips_DirStucture """
        # update config file to match local paths
        configFile = join(paths['Philips_dir'], 'scannerConfig.yaml')
        helper_tools.replace_scannerConfig_baseDir(configFile, paths['Philips_funcDir'])

        # create instance of ScannerSettings class from general_utils
        scannerSettings = general_utils.ScannerSettings(paths['Philips_dir'])

        # create instance of Philips_DirStructure for testing
        scannerDirs = Philips_utils.Philips_DirStructure(scannerSettings)

        ### Run through Philips_DirStructure class methods
        scannerDirs.print_currentSeries()
        assert scannerDirs.get_seriesDirs() == ['0001']

        ### Test the waitForSeriesDir function by creating a fake dir
        # threading.timer object to create a new dir after a few sec
        fakeNewSeries = join(paths['Philips_funcDir'], '0TEST')
        t = threading.Timer(1.0, helper_tools.createFakeSeriesDir, [fakeNewSeries])
        t.start()

        scannerDirs.waitForSeriesDir()

        # assuming it didn't crash, cancel the timer function and delete new dir
        t.cancel()
        shutil.rmtree(fakeNewSeries)

        # remove local paths from the config file
        helper_tools.cleanConfigFile(configFile)
Esempio n. 5
0
    def test_Siemens_DirStructure(self):
        # update config file to match local paths
        configFile = join(paths['Siemens_dir'], 'scannerConfig.yaml')
        helper_tools.replace_scannerConfig_baseDir(configFile, paths['Siemens_funcDir'])

        # create instace of ScannerSettings class from general_utils
        scannerSettings = general_utils.ScannerSettings(paths['Siemens_dir'])

        # create instance of Philips_DirStructure for testing
        scannerDirs = Siemens_utils.Siemens_DirStructure(scannerSettings)

        ## Run through the Siemens_DirStructure class methods
        scannerDirs.print_currentSeries()
        assert scannerDirs.getUniqueSeries() == set(['000013'])

        ## Test waitForNewSeries function by simulating new series data
        # threading.timer object to copy in new data after a few sec
        newSeriesNum = 999
        t = threading.Timer(1.0, fakeNewSiemensSeries, [newSeriesNum])
        t.start()

        scannerDirs.waitForNewSeries()

        # assuming that didn't crash, stop the timer object and remove new file
        t.cancel()
        removeFakeSiemensSeries(newSeriesNum)

        # remove local paths from the config file
        helper_tools.cleanConfigFile(configFile)
Esempio n. 6
0
    def test_initializeSession(self):
        """ test general_utils.initializeSession() """
        # loop over the different scan environments
        for scanEnv in ['GE', 'Philips', 'Siemens']:
            print('testing environment: ' + scanEnv)

            # set paths based on current test environment
            if scanEnv == 'GE':
                envDir = paths['GE_dir']
                funcDir = paths['GE_funcDir']
            elif scanEnv == 'Philips':
                envDir = paths['Philips_dir']
                funcDir = paths['Philips_funcDir']
            elif scanEnv == 'Siemens':
                envDir = paths['Siemens_dir']
                funcDir = paths['Siemens_funcDir']

            # update config file to match local paths
            configFile = join(envDir, 'scannerConfig.yaml')
            helper_tools.replace_scannerConfig_baseDir(configFile, funcDir)

            general_utils.initializeSession(pynealScannerDir=envDir)

            # remove local paths from config file
            helper_tools.cleanConfigFile(configFile)

            print('Passed!')
Esempio n. 7
0
    def test_ScannerSettings(self):
        """ test general_utils.ScannerSettings class

        Test methods in ScannerSettings class against sample data from each
        scanner make
        """
        # loop over the different scan environments
        for scanEnv in ['GE', 'Philips', 'Siemens']:
            print('testing environment: ' + scanEnv)

            # set paths based on current test environment
            if scanEnv == 'GE':
                envDir = paths['GE_dir']
                funcDir = paths['GE_funcDir']
            elif scanEnv == 'Philips':
                envDir = paths['Philips_dir']
                funcDir = paths['Philips_funcDir']
            elif scanEnv == 'Siemens':
                envDir = paths['Siemens_dir']
                funcDir = paths['Siemens_funcDir']

            # update config file to match local paths
            configFile = join(envDir, 'scannerConfig.yaml')
            helper_tools.replace_scannerConfig_sessionDir(configFile, funcDir)

            # run through all functions in ScannerSettings class
            scanSettings = general_utils.ScannerSettings(envDir)
            scanSettings.print_allSettings()
            scanSettings.get_scannerMake()
            scanSettings.get_scannerSessionDir()
            scanSettings.get_pynealSocketHost()
            scanSettings.get_pynealSocketPort()
            scanSettings.get_allSettings()

            # remove local paths from config file
            helper_tools.cleanConfigFile(configFile)

            print('Passed!')
Esempio n. 8
0
    def test_getSeries_Siemens(self):
        """ test getSeries.getSeries_Siemens """

        envDir = paths['Siemens_dir']
        funcDir = paths['Siemens_funcDir']

        # update config file to match local paths
        configFile = join(envDir, 'scannerConfig.yaml')
        helper_tools.replace_scannerConfig_baseDir(configFile, funcDir)

        # run initializeSettings to get the scannerDirs object
        scannerSettings, scannerDirs = general_utils.initializeSession(
            pynealScannerDir=envDir)

        ### run getSeries_Siemens
        import pyneal_scanner.getSeries as getSeries

        # module expects user to input 2 things: desired series, and output prefix.
        # We have to mock the input for automatic testing, but can only mock one
        # input (at least as far as I can figure out). So, by hardcoding the input
        # to '000013', we will get series 000013 and build a nifti named
        # '000013_000013.nii.gz' saved in pyneal/pyneal_scanner/data. Delete this file
        # at end of test
        seriesNum = '000013'
        getSeries.input = lambda x: seriesNum
        getSeries.getSeries_Siemens(scannerDirs)

        # return the module input to the normal __builtin__ input function
        getSeries.input = input

        # ensure output file created, then delete
        outputFile = join(paths['pynealScannerDir'], 'data',
                          '{}_{}.nii.gz'.format(seriesNum, seriesNum))
        assert os.path.exists(outputFile)
        os.remove(outputFile)

        # remove local paths from the config file
        helper_tools.cleanConfigFile(configFile)
Esempio n. 9
0
    def test_GE_DirStructure(self):
        """ test GE_utils.GE_DirStructure """

        # update config file to match local paths
        configFile = join(paths['GE_dir'], 'scannerConfig.yaml')
        helper_tools.replace_scannerConfig_baseDir(configFile,
                                                   paths['GE_funcDir'])

        # create instance of ScannerSettings class from general_utils
        scannerSettings = general_utils.ScannerSettings(paths['GE_dir'])

        # create instance of GE_DirStructure for testing
        scannerDirs = GE_utils.GE_DirStructure(scannerSettings)

        ### Run through the GE_DirStructure class methods
        scannerDirs.print_currentSeries()

        # confirm paths match test directories
        assert scannerDirs.get_seriesDirs() == ['s1925']
        assert scannerDirs.get_pDir() == 'p1'
        assert scannerDirs.get_eDir() == 'e123'
        assert scannerDirs.get_sessionDir() == join(paths['GE_dir'], 'p1/e123')

        ### Test the waitForSeriesDir function by creating a fake dir
        # threading.timer object to create a new directory after a few sec
        fakeNewSeries = join(paths['GE_funcDir'], 'p1/e123/sTEST')
        t = threading.Timer(1.0, helper_tools.createFakeSeriesDir,
                            [fakeNewSeries])
        t.start()

        scannerDirs.waitForSeriesDir()

        # assuming it didn't crash, cancel the timer function and delete new dir
        t.cancel()
        shutil.rmtree(fakeNewSeries)

        # remove local paths from config file
        helper_tools.cleanConfigFile(configFile)
Esempio n. 10
0
    def test_ScannerSettings(self):
        """ test general_utils.ScannerSettings class

        Test methods in ScannerSettings class against sample data from each
        scanner make
        """
        # loop over the different scan environments
        for scanEnv in ['GE', 'Philips', 'Siemens']:
            print('testing environment: ' + scanEnv)

            # set paths based on current test environment
            if scanEnv == 'GE':
                envDir = paths['GE_dir']
                funcDir = paths['GE_funcDir']
            elif scanEnv == 'Philips':
                envDir = paths['Philips_dir']
                funcDir = paths['Philips_funcDir']
            elif scanEnv == 'Siemens':
                envDir = paths['Siemens_dir']
                funcDir = paths['Siemens_funcDir']

            # update config file to match local paths
            configFile = join(envDir, 'scannerConfig.yaml')
            helper_tools.replace_scannerConfig_baseDir(configFile, funcDir)

            # run through all functions in ScannerSettings class
            scanSettings = general_utils.ScannerSettings(envDir)
            scanSettings.print_allSettings()
            scanSettings.get_scannerMake()
            scanSettings.get_scannerBaseDir()
            scanSettings.get_pynealSocketHost()
            scanSettings.get_pynealSocketPort()
            scanSettings.get_allSettings()

            # remove local paths from config file
            helper_tools.cleanConfigFile(configFile)

            print('Passed!')