Esempio n. 1
0
def testInteg():
    from peakBBA import peakFitBBA
    from monDimReduce import SAXSDimReduce
    from input_file_parsing import parse_config
    calibList = getAllCalibPath()

    dataPath = expUsr('~/allSampleTest/')
    configPath = expUsr('~/monHiTp/config')
    fileList = glob.glob(os.path.join(dataPath, '*.tif'))

    fileGen = (x for x in fileList)
    config = parse_config(configPath)
    if config:
        QRange = (config['Qmin'], config['Qmax'])
        ChiRange = (config['ChiMin'], config['ChiMax'])
        # require all bounds to exist, currently can't check default limits
        if (any(isinstance(n, str) for n in QRange)
                or any(isinstance(m, str) for m in ChiRange)):
            print('Pass found, ignoring Q,Chi limits')
            QRange, ChiRange = None, None
        peakShape = config['peakShape']
        peakNo = config['peakNo']
        fit_order = config['fit_order']
        hiLimit = config['highlightLimit']

        config['bkgdPath'] = expUsr('~/monHiTp/')
    else:
        #Qrange, peakShape, peakNo, fit_order, hiLimit = None, None, None, None, None
        print('no config file')

    start = time.time()
    for f in fileGen:
        if any(x in f for x in ['k1', 'k2', 'k3', 'a1', 'k5']):
            c = calibList[0]
        elif any(x in f for x in ['k6', 'k7']):
            c = calibList[5]
        elif any(x in f for x in ['k8a']):
            c = calibList[1]
        elif any(x in f for x in ['k9a']):
            c = calibList[2]
        elif any(x in f for x in ['r5', 'r15']):
            c = calibList[4]
        else:
            c = calibList[3]

        print(f + '\n<===>\n' + c)

        SAXSDimReduce(c, f, config)
        peakFitBBA(f, config)

    end = time.time()

    print(end - start)
    print(len(fileList))
def mainWrapper():
    # grab monitor folder
    root = Tkinter.Tk()
    root.withdraw()

    calibPath = tkFileDialog.askopenfilename(title='Select Calibration File')
    #calibPath = os.path.expanduser('~/monHiTp/testHold/8Nov17_calib_1.calib')
    if calibPath is '':
        print('No calibration path selected, aborting...')
        return

    #configPath = tkFileDialog.askopenfilename(title='Select Config File')
    configPath = os.path.expanduser('~/monHiTp/config')
    if configPath is '':
        print('No config file supplied, aborting...')
        return
    config = parse_config(configPath)

    monFoldPath = tkFileDialog.askdirectory(title='Select folder to watch')
    #monFoldPath = os.path.expanduser('~/monHiTp/testMon')
    if monFoldPath is '':
        print('No monitor folder selected, aborting...')
        return

    print('monitoring: ' + monFoldPath + '===================================')
    print('==================================================================')

    # Initialize monitor
    watchManager = pyinotify.WatchManager()
    #eventNotifier = pyinotify.Notifier(watchManager) # Enable to monitor all
    eventNotifier = pyinotify.Notifier(
        watchManager, EventProcessor(calibPath=calibPath, config=config))
    # Enable to use custom event processor

    watchManager.add_watch(monFoldPath, pyinotify.ALL_EVENTS)
    # Begin loop and handle events
    eventNotifier.loop()
    print('No bkgd file supplied, aborting...')
    sys.exit()

print('Calibration File: ' + calibPath)
print('Config File: ' + configPath)
print('BkgdImg File: ' + configPath)
print('Folder to process: ' + dataPath)
print('')

##########################################Extension chooser?...
fileList = glob.glob(os.path.join(dataPath, '*.tif'))
if len(fileList) == 0:
    sys.exit('No files found')

# Sort out config file
config = parse_config(configPath)
if config:
    QRange = (config['Qmin'], config['Qmax'])
    ChiRange = (config['ChiMin'], config['ChiMax'])
    # require all bounds to exist, currently can't check default limits
    if (any(isinstance(n, str) for n in QRange)
            or any(isinstance(m, str) for m in ChiRange)):
        print('Pass found, ignoring Q,Chi limits')
        QRange, ChiRange = None, None
    peakShape = config['peakShape']
    peakNo = config['peakNo']
    fit_order = config['fit_order']
    hiLimit = config['highlightLimit']
    skipExisting = config['skipExisting']
else:
    #Qrange, peakShape, peakNo, fit_order, hiLimit = None, None, None, None, None