Beispiel #1
0
def _intial_gui_setup(sys_argv):

    global inifname  # name of .ini file
    inifname = os.curdir + '/.' + os.path.basename(__file__).replace(
        '.py', '.ini')

    for i, argv in enumerate(sys_argv):
        print('arg {}: '.format(i) + argv)

    if len(sys_argv) == 1:

        default_ini = wpu.load_ini_file(inifname)
        foldername = default_ini['Files']['Folder Name']

        if easyqt.get_yes_or_no('Select new folder?\n' +
                                '[ESC load folder of previous run]'):

            foldername = easyqt.get_directory_name(title='Select Folder that' +
                                                   '\ncontains *csv files')

    elif len(sys_argv) == 2:

        foldername = sys_argv[1]

    else:

        print('ERROR: wrong number of inputs: {} \n'.format(len(argv) - 1) +
              'Usage: \n'
              '\n' + os.path.basename(__file__) +
              ' : (no inputs) load dialogs \n'
              '\n' + os.path.basename(__file__) + ' [args] \n'
              '\n'
              'arg1: folder that contains the *csv files\n'
              '\n')

        exit(-1)

    wpu.set_at_ini_file(inifname, 'Files', 'Folder Name', foldername)

    list_of_files = sorted(glob.glob(foldername + '/*csv'))

    nfiles = len(list_of_files)

    data, header_list = wpu.load_csv_file(list_of_files[0])

    wpu.print_blue('MESSAGE: Header of data files:')
    wpu.print_blue(header_list)

    ncurves = data.shape[1] - 1

    label_list = [
        fname.rsplit('_', 1)[1].split('.')[0] for fname in list_of_files
    ]

    #[fname.rsplit('/', 1)[1].split('_Y_integrated')[0]
    #                  for fname in list_of_files]

    return list_of_files, nfiles, ncurves, label_list, header_list
phenergy = 1e20
wavelength = wpu.hc / phenergy

# here is to choose which collum in the csv fitting data is used for the response function calculation
profilenumber = 1

# %%

if len(sys.argv) == 1:
    dirName = easyqt.get_directory_name('Directory to the data:')
else:
    dirName = sys.argv[1]

# here the response function initialization file
inifname = '.Revise_response_func.ini'
defaults = wpu.load_ini_file(inifname)

if dirName == '':
    dirName = defaults['Files'].get('Folder with csv files')

else:
    wpu.set_at_ini_file(inifname, 'Files', 'Folder with csv files', dirName)

print(dirName)
'''
Here use the cap to wavesensor data transfer function to generate the same structure
data file with the wavefront measurement curve. The file is generated in the dir_name path
'''

listOfFiles = glob.glob(dirName + '/*.csv')
listOfFiles.sort()
Beispiel #3
0
def _intial_gui_setup():

    #    global inifname  # name of .ini file
    #    pwd, inifname = argvzero.rsplit('/', 1)
    #    inifname = pwd + '/.' + inifname.replace('.py', '.ini')

    defaults = wpu.load_ini_file(inifname)

    fname = easyqt.get_file_names("File to Plot (Pickle or sdf)")

    if fname == []:
        fname = defaults['Files'].get('file with thickness')

    else:
        fname = fname[0]
        defaults['Files']['file with thickness'] = fname

    wpu.print_blue('MESSAGE: Loading File: ' + fname)

    with open(inifname, 'w') as configfile:
        defaults.write(configfile)

    if defaults is None:
        p1 = ''
        p2 = 100e-6

    else:
        p1 = defaults['Parameters'].get('String for Titles')
        p2 = float(defaults['Parameters'].get('Nominal Radius For Fitting'))
        p3 = defaults['Parameters']['Diameter of active area for fitting']
        p4 = defaults['Parameters']['Lens Geometry']

    str4title = easyqt.get_string('String for Titles', 'Enter String', p1)

    if str4title != '':
        defaults['Parameters']['String for Titles'] = str4title

    wpu.print_blue('MESSAGE: Loading Pickle: ' + fname)

    if p4 == '2D Lens Stigmatic Lens':
        menu_choices4lensmode = [
            '2D Lens Stigmatic Lens', '1Dx Horizontal focusing',
            '1Dy Vertical focusing'
        ]
    elif p4 == '1Dx Horizontal focusing':
        menu_choices4lensmode = [
            '1Dx Horizontal focusing', '1Dy Vertical focusing',
            '2D Lens Stigmatic Lens'
        ]
    elif p4 == '1Dy Vertical focusing':
        menu_choices4lensmode = [
            '1Dy Vertical focusing', '1Dx Horizontal focusing',
            '2D Lens Stigmatic Lens'
        ]

    lensGeometry = easyqt.get_choice(message='Lens Geometry',
                                     title='Input Parameter',
                                     choices=menu_choices4lensmode)

    nominalRadius = easyqt.get_float(
        'Nominal Curvature Radius' + ' for Fitting [um]',
        title='Input Parameter',
        default_value=p2 * 1e6) * 1e-6

    diameter4fit_str = easyqt.get_string(
        'Diameter of active area for fitting [um]',
        title='Input Parameter',
        default_response=p3)

    diameter4fit_list = [float(a) * 1e-6 for a in diameter4fit_str.split(',')]

    defaults['Parameters']['Nominal Radius For Fitting'] = str(nominalRadius)
    defaults['Parameters'][
        'Diameter of active area for fitting'] = diameter4fit_str
    defaults['Parameters']['Lens Geometry'] = lensGeometry

    with open(inifname, 'w') as configfile:
        defaults.write(configfile)

    return fname, str4title, nominalRadius, diameter4fit_list, lensGeometry
def _intial_gui_setup(sys_argv):

    global inifname  # name of .ini file
    inifname = os.curdir + '/.' + os.path.basename(__file__).replace(
        '.py', '.ini')

    for i, argv in enumerate(sys_argv):
        print('arg {}: '.format(i) + argv)

    if len(sys_argv) == 1:

        default_ini = wpu.load_ini_file(inifname)
        p0 = float(default_ini['Parameters']['Photon Energy [eV]'])
        p1 = float(default_ini['Parameters']['grazing angle [mrad]'])
        p2 = int(default_ini['Parameters']['n profiles'])
        p3 = int(default_ini['Parameters']['filter width'])
        p4 = float(default_ini['Parameters']['projection From Divergence'])

        if easyqt.get_yes_or_no('Load new files?\n' +
                                '[ESC load file(s) of previous run]'):

            fnameH = easyqt.get_file_names(title='Select DPC Horizontal\n' +
                                           '(and Vertical if you want)')
            fnameV = None

            if len(fnameH) == 1:
                fnameH = fnameH[0]
                wpu.print_blue('MESSAGE: Horiz DPC: Loading ' + fnameH)
            elif len(fnameH) == 0:
                fnameH = None
            elif len(fnameH) == 2:
                [fnameH, fnameV] = fnameH
                wpu.print_blue('MESSAGE: Horiz DPC: Loading ' + fnameH)
                wpu.print_blue('MESSAGE: Vert DPC: Loading ' + fnameV)

            if fnameV is None:
                fnameV = easyqt.get_file_names(title='Select DPC Vertical')

                if len(fnameV) == 1:
                    fnameV = fnameV[0]
                    wpu.print_blue('MESSAGE: Vert DPC: Loading ' + fnameV)

                elif len(fnameV) == 0:
                    fnameV = None

        else:
            fnameH = default_ini['Files']['dpc H']
            fnameV = default_ini['Files']['dpc V']

            wpu.print_blue('MESSAGE: Horiz DPC: Loading ' + fnameH)
            wpu.print_blue('MESSAGE: Vert DPC: Loading ' + fnameV)

            if fnameH == 'None':
                fnameH = None
            if fnameV == 'None':
                fnameV = None

        phenergy = easyqt.get_float("Enter Photon Energy [KeV]",
                                    title='Experimental Values',
                                    default_value=p0 * 1e-3) * 1e3

        grazing_angle = easyqt.get_float(
            'Grazing angle [mrad]\n' + '[0.0 to ignore projection]',
            title='Experimental Values',
            default_value=p1) * 1e-3

        projectionFromDiv = easyqt.get_float('projection From Divergence\n' +
                                             '[Multiplication factor]',
                                             title='Experimental Values',
                                             default_value=p4)

        nprofiles = easyqt.get_int("Number of profiles to plot",
                                   title='Experimental Values',
                                   default_value=p2)

        filter_width = easyqt.get_int("Width fo uniform filter [pixels]",
                                      title='Experimental Values',
                                      default_value=p3)

        remove2ndOrder = easyqt.get_yes_or_no("Remove 2nd Order?",
                                              title='Experimental Values')

    elif len(sys_argv) == 8:

        if 'none' in sys_argv[1].lower():
            fnameH = None
        else:
            fnameH = sys_argv[1]

        if 'none' in sys_argv[2].lower():
            fnameV = None
        else:
            fnameV = sys_argv[2]

        phenergy = float(sys_argv[3]) * 1e3
        nprofiles = int(sys_argv[4])
        filter_width = int(sys_argv[5])
        grazing_angle = float(sys_argv[6]) * 1e-3
        projectionFromDiv = float(sys_argv[7])

    else:

        print(
            'ERROR: wrong number of inputs: {} \n'.format(len(argv) - 1) +
            'Usage: \n'
            '\n' + os.path.basename(__file__) +
            ' : (no inputs) load dialogs \n'
            '\n' + os.path.basename(__file__) + ' [args] \n'
            '\n'
            'arg1: file name DPC Horiz (type "None" '
            '      to ignore it)\n'
            'arg2: file name DPC Vert (type "None" '
            '      to ignore it)\n'
            'arg3: Photon Energy [KeV]\n'
            'arg4: Number of profiles to plot\n'
            'arg5: Width  of uniform filter [pixels]\n'
            'arg6: Grazing angle to project coordinates to mirror [mrad], use zero to ignore\n'
            'arg7: Projection From Divergence, use 1 to ignore'
            '\n')

        exit(-1)

    wpu.set_at_ini_file(inifname, 'Files', 'DPC H', fnameH)
    wpu.set_at_ini_file(inifname, 'Files', 'DPC V', fnameV)
    wpu.set_at_ini_file(inifname, 'Parameters', 'Photon Energy [eV]', phenergy)
    wpu.set_at_ini_file(inifname, 'Parameters', 'grazing angle [mrad]',
                        grazing_angle * 1e3)
    wpu.set_at_ini_file(inifname, 'Parameters', 'projection From Divergence',
                        projectionFromDiv)
    wpu.set_at_ini_file(inifname, 'Parameters', 'n profiles', nprofiles)
    wpu.set_at_ini_file(inifname, 'Parameters', 'filter width', filter_width)

    wpu.set_at_ini_file(inifname, 'Parameters', 'Remove 2nd Order',
                        remove2ndOrder)

    return (fnameH, fnameV, phenergy, grazing_angle, projectionFromDiv,
            nprofiles, remove2ndOrder, filter_width)
def _intial_gui_setup(sys_argv):

    global inifname  # name of .ini file
    pwd, inifname = sys_argv[0].rsplit('/', 1)
    inifname = pwd + '/.' + inifname.replace('.py', '.ini')

    for i, argv in enumerate(sys_argv):
        print('arg {}: '.format(i) + argv)

    if len(sys_argv) == 1:

        default_ini = wpu.load_ini_file(inifname)
        p0 = float(default_ini['Parameters']['Photon Energy [eV]'])
        p1 = float(default_ini['Parameters']['grazing angle [mrad]'])
        p2 = int(default_ini['Parameters']['n profiles'])
        p3 = int(default_ini['Parameters']['filter width'])
        p4 = float(default_ini['Parameters']['projection From Divergence'])

        if easyqt.get_yes_or_no('Load new files?\n' +
                                '[ESC load file(s) of previous run]'):

            fnameH = easyqt.get_file_names(title='Select DPC Horizontal\n' +
                                           '(and Vertical if you want)')
            fnameV = None

            if len(fnameH) == 1:
                fnameH = fnameH[0]
                wpu.print_blue('MESSAGE: Horiz DPC: Loading ' + fnameH)
            elif len(fnameH) == 0:
                fnameH = None
            elif len(fnameH) == 2:
                [fnameH, fnameV] = fnameH
                wpu.print_blue('MESSAGE: Horiz DPC: Loading ' + fnameH)
                wpu.print_blue('MESSAGE: Vert DPC: Loading ' + fnameV)

            if fnameV is None:
                fnameV = easyqt.get_file_names(title='Select DPC Vertical')

                if len(fnameV) == 1:
                    fnameV = fnameV[0]
                    wpu.print_blue('MESSAGE: Vert DPC: Loading ' + fnameV)

                elif len(fnameV) == 0:
                    fnameV = None

        else:
            fnameH = default_ini['Files']['dpc H']
            fnameV = default_ini['Files']['dpc V']

            wpu.print_blue('MESSAGE: Horiz DPC: Loading ' + fnameH)
            wpu.print_blue('MESSAGE: Vert DPC: Loading ' + fnameV)

            if fnameH == 'None':
                fnameH = None
            if fnameV == 'None':
                fnameV = None

        phenergy = easyqt.get_float("Enter Photon Energy [KeV]",
                                    title='Experimental Values',
                                    default_value=p0*1e-3)*1e3

        grazing_angle = easyqt.get_float('Grazing angle [mrad]\n' +
                                         '[0.0 to ignore projection]',
                                         title='Experimental Values',
                                         default_value=p1)*1e-3

        projectionFromDiv = easyqt.get_float('projection From Divergence\n' +
                                             '[Multiplication factor]',
                                             title='Experimental Values',
                                             default_value=p4)

        nprofiles = easyqt.get_int("Number of profiles to plot",
                                   title='Experimental Values',
                                   default_value=p2)

        filter_width = easyqt.get_int("Width fo uniform filter [pixels]",
                                      title='Experimental Values',
                                      default_value=p3, max_=1e6)


        remove1stOrderDPC = easyqt.get_yes_or_no("Remove 1st Order DPC?",
                                                 title='Experimental Values')

        remove2ndOrder = easyqt.get_yes_or_no("Remove 2nd Order?",
                                              title='Experimental Values')

    elif len(sys_argv) == 10:

        if 'none' in sys_argv[1].lower():
            fnameH = None
        else:
            fnameH = sys_argv[1]

        if 'none' in sys_argv[2].lower():
            fnameV = None
        else:
            fnameV = sys_argv[2]

        phenergy = float(sys_argv[3])*1e3
        nprofiles = int(sys_argv[4])
        filter_width = int(sys_argv[5])
        grazing_angle = float(sys_argv[6])*1e-3
        projectionFromDiv = float(sys_argv[7])
        remove1stOrderDPC = bool(int(argv[8]))
        remove2ndOrder = bool(int(argv[9]))

    else:

        print('ERROR: wrong number of inputs: {} \n'.format(len(argv)-1) +
              'Usage: \n'
              '\n' +
              sys_argv[0].rsplit('/')[-1] + ' : (no inputs) load dialogs \n'
              '\n' +
              sys_argv[0].rsplit('/')[-1] + ' [args] \n'
              '\n'
              'arg1: file name DPC Horiz (type "None" '
              '      to ignore it)\n'
              'arg2: file name DPC Vert (type "None" '
              '      to ignore it)\n'
              'arg3: Photon Energy [KeV]\n'
              'arg4: Number of profiles to plot\n'
              'arg5: Width  of uniform filter [pixels]\n'
              'arg6: Grazing angle to project coordinates to mirror [mrad], use zero to ignore\n'
              'arg7: Projection From Divergence, use 1 to ignore'
              '\n')

        exit(-1)

    wpu.set_at_ini_file(inifname, 'Files', 'DPC H', fnameH)
    wpu.set_at_ini_file(inifname, 'Files', 'DPC V', fnameV)
    wpu.set_at_ini_file(inifname, 'Parameters', 'Photon Energy [eV]', phenergy)
    wpu.set_at_ini_file(inifname, 'Parameters',
                        'grazing angle [mrad]', grazing_angle*1e3)
    wpu.set_at_ini_file(inifname, 'Parameters',
                        'projection From Divergence', projectionFromDiv)
    wpu.set_at_ini_file(inifname, 'Parameters', 'n profiles', nprofiles)
    wpu.set_at_ini_file(inifname, 'Parameters', 'filter width', filter_width)

    wpu.set_at_ini_file(inifname, 'Parameters', 'Remove 1st Order DPC', remove1stOrderDPC)
    wpu.set_at_ini_file(inifname, 'Parameters', 'Remove 2nd Order', remove2ndOrder)

    return (fnameH, fnameV,
            phenergy, grazing_angle, projectionFromDiv,
            nprofiles, remove1stOrderDPC, remove2ndOrder, filter_width)
def _intial_gui_setup(argvzero):

    global inifname  # name of .ini file
    pwd, inifname = argvzero.rsplit('/', 1)
    inifname = pwd + '/.' + inifname.replace('.py', '.ini')

    defaults = wpu.load_ini_file(inifname)

    if defaults is None:
        p1, p2, p3, p4, p5, p6 = [0, 0, 0, 0, 0, 0]

    else:

        p1 = float(defaults['Parameters'].get('Pixel Size'))
        p2 = float(defaults['Parameters'].get('Chekerboard Grating Period'))
        p3 = defaults['Parameters'].get('Pattern')
        p4 = float(defaults['Parameters'].get('Distance Detector to Gr'))
        p5 = float(defaults['Parameters'].get('Photon Energy'))
        p6 = float(defaults['Parameters'].get('Source Distance'))

    title = 'Select Sample, Reference and Dark Images. '
    title += 'Press ESC to repeat last run.'
    fname1, fname2, fname3 = wpu.gui_load_data_ref_dark_filenames(title=title)

    if fname1 is None:
        fname1 = defaults['Files'].get('Sample')
        fname2 = defaults['Files'].get('Reference')
        fname3 = defaults['Files'].get('Blank')

    else:
        defaults['Files']['Sample'] = fname1
        defaults['Files']['Reference'] = fname2
        defaults['Files']['Blank'] = fname3

    wpu.print_blue('MESSAGE: loading dark: ' + fname3)
    wpu.print_blue('MESSAGE: loading Reference: ' + fname2)
    wpu.print_blue('MESSAGE: loading Image: ' + fname1)

    pixelsize = easyqt.get_float("Enter Pixel Size [um]",
                                 title='Experimental Values',
                                 default_value=p1*1e6)*1e-6

    gratingPeriod = easyqt.get_float("Enter CB Grating Period [um]",
                                     title='Experimental Values',
                                     default_value=p2*1e6)*1e-6

    if p3 == 'Diagonal half pi':
        choices = ['Diagonal half pi', 'Edge pi']
    else:
        choices = ['Edge pi', 'Diagonal half pi']

    pattern = easyqt.get_choice(message='Select CB Grating Pattern',
                                title='Title',
                                choices=choices)

    distDet2sample = easyqt.get_float("Enter Distance Sample - Detector [mm]",
                                      title='Experimental Values',
                                      default_value=p4*1e3)*1e-3

    phenergy = easyqt.get_float("Enter Photon Energy [KeV]",
                                title='Experimental Values',
                                default_value=p5*1e-3)*1e3

    sourceDistance = easyqt.get_float("Enter Distance to Source [m]",
                                      title='Experimental Values',
                                      default_value=p6)

    defaults['Parameters']['Pixel Size'] = str(pixelsize)
    defaults['Parameters']['Chekerboard Grating Period'] = str(gratingPeriod)
    defaults['Parameters']['Pattern'] = pattern
    defaults['Parameters']['Distance Detector to Gr'] = str(distDet2sample)
    defaults['Parameters']['Photon Energy'] = str(phenergy)
    defaults['Parameters']['Source Distance'] = str(sourceDistance)

    with open(inifname, 'w') as configfile:
            defaults.write(configfile)

    return (fname1, fname2, fname3,
            pixelsize, gratingPeriod, pattern, distDet2sample,
            phenergy, sourceDistance)