Beispiel #1
0
def run(options):
    if options.filename == None:
        raise ValueError("\nNo input file supplied [-i filename]\n")

    try:
        if options.killfile is not None and os.path.exists(options.killfile):
            print("The purpose of the killfile option is to create that file")
            print("only when you want fitallb to stop")
            print("If the file already exists when you run fitallb it is")
            print("never going to get started")
            raise ValueError("Your killfile " + options.killfile +
                             " already exists")
    except:
        pass

    #Read and check input
    far = check_input.parse_input(
        input_file=options.filename)  # Make instance of parse_input class
    far.read()  # read input file
    far.check()  # check validity of input
    if far.missing == True:  # if problem exit
        logging.info('MISSING ITEMS')
        sys.exit()
    far.initialize()  # if ok initialize
    # mandatory farfield info
    far.read_par(far.files['par_file'])  # read detector.par file
    far.read_res(
    )  # read paramters file to resume refinement                              NB! optional
    far.read_flt(far.files['flt_file'])  # read peaks_t##.flt file
    if far.files['res_file'] == None:
        far.read_log()  # read grainspotter.log file
        far.read_rej(
            far.files['rej_file']
        )  # read file containing rejected peaks to resume refinement   NB! optional
    far.set_start()  # set values and errors for refinement start
    check_input.set_globals(far)

    # optional nearfield info
    if far.files['near_flt_file'] != None:
        check_input.interrupt(options.killfile)
        assert far.files[
            'near_par_file'] != None, 'near_par_file parameter file for near-field detector is missing'
        near = deepcopy(far)
        # take special care of near-field keywords (eg copy near_dety_size to dety_size)
        for key in list(near.fit.keys()):
            if key[0:5] == 'near_':
                near.fit[key[5:len(key)]] = near.fit[key]
        near.fit['stem'] = far.fit['stem'] + '_near'
        #        print 'far.files', far.files
        #        print 'near.files', near.files
        near.read_par(near.files['near_par_file'])
        near.read_flt(near.files['near_flt_file'])
        keys = [
            'cell__a', 'cell__b', 'cell__c', 'cell_alpha', 'cell_beta',
            'cell_gamma', 'cell_lattice_[P,A,B,C,I,F,R]', 'chi', 'omegasign',
            'wavelength'
        ]
        for key in keys:
            assert near.param[key] == far.param[
                key], '%s is different for near- and far-field detectors' % key
        # in case of different wedge use farfield value and refine
        if near.param['wedge'] != far.param['wedge']:
            near.param['wedge'] = far.param['wedge']
        near.values = far.values
        near.errors = far.errors
        near.fit['skip'] = far.fit['skip']
        check_input.set_globals(near)
        # match peaks on nearfield detector and reject outliers
        from FitAllB import near_field
        check_input.interrupt(options.killfile)
        near_field.find_refl(near)
        check_input.interrupt(options.killfile)
        near_field.match(near)
        near.read_rej(
            near.files['near_rej_file']
        )  # read file containing rejected peaks to resume refinement   NB! optional
        from FitAllB import error
        error.vars(near)
        from FitAllB import build_fcn
        build_fcn.FCN(near)
        check_input.interrupt(options.killfile)
        near.reject()
        near.write_rej()
        near.fit['reforder'] = ['start', 'rotpos', 'end']
        near.fit['goon'] = near.fit['reforder'][0]
        # nearfield refinement
        from FitAllB import fit
        fit.refine(near, options.killfile)
        try:
            far.fitarg = near.fitarg  # needed to carry on parameters for iminuit
        except:
            pass

    #  Farfield outlier rejection
    #check_input.set_globals(far)
    if far.files['res_file'] != None and far.labels == None:
        check_input.interrupt(options.killfile)
        from FitAllB import near_field
        near_field.find_refl(far)
        check_input.interrupt(options.killfile)
        near_field.match(far)
        far.read_rej(
            far.files['rej_file']
        )  # read file containing rejected peaks to resume refinement   NB! optional
    from FitAllB import error
    error.vars(far)
    from FitAllB import build_fcn
    build_fcn.FCN(far)
    check_input.interrupt(options.killfile)
    far.reject()
    far.write_rej()

    # farfield refinement
    far.fit['reforder'] = ['grain', 'final', 'end']
    far.fit['goon'] = far.fit['reforder'][0]
    from FitAllB import fit
    fit.refine(far, options.killfile)

    # program ends here after deleting fcn.py and fcn.pyc
    print('\nNormal termination of FitAllB')
    os.remove('%s/fcn.py' % far.fit['direc'])
    # os.remove('%s/fcn.pyc' % far.fit['direc'])
    # pyc file now goes inside a __pycache__ directory
    import shutil
    pycache_dir = os.path.join(far.fit['direc'], "__pycache__")
    shutil.rmtree(pycache_dir)
Beispiel #2
0
from FitAllB import error
error.vars(far)
from FitAllB import build_fcn
build_fcn.FCN(far)
far.reject()
far.write_rej()

# farfield refinement
for k in range(far.fit['cycle']):
    #while len(far.fit['newreject_grain']) > 0:
    # refine grain paramters
    far.fit['reforder'] = ['start%s' % k, 'rotpos%s' % k, 'end']
    far.fit['goon'] = far.fit['reforder'][0]
    far.fit['newreject_grain'] = list(range(far.no_grains + 1))
    from FitAllB import fit
    fit.refine(far)
    # refine globals
    far.fit['reforder'] = ['globals%s' % k, 'end']
    far.fit['goon'] = far.fit['reforder'][0]
    from FitAllB import fitga
    fitga.refine(far)
    far.residual = []
    far.volume = []
    far.mean_ia = []
    for i in range(far.no_grains):
        far.residual.append([])
        far.volume.append([])
        far.mean_ia.append([])
        for j in range(far.nrefl[i]):
            far.residual[i].append(1)
            far.volume[i].append(1)
Beispiel #3
0
def run(options):
    if options.filename == None:
        #parser.print_help()
        print "\nNo input file supplied [-i filename]\n"
        sys.exit()

    #Read and check input
    far = check_input.parse_input(
        input_file=options.filename)  # Make instance of parse_input class
    far.read()  # read input file
    far.check()  # check validity of input
    if far.missing == True:  # if problem exit
        logging.info('MISSING ITEMS')
        sys.exit()
    far.initialize()  # if ok initialize
    # mandatory farfield info
    far.read_par(far.files['par_file'])  # read detector.par file
    far.read_res(
    )  # read paramters file to resume refinement                              NB! optional
    far.read_flt(far.files['flt_file'])  # read peaks_t##.flt file
    if far.files['res_file'] == None:
        far.read_log()  # read grainspotter.log file
        far.read_rej(
            far.files['rej_file']
        )  # read file containing rejected peaks to resume refinement   NB! optional
    far.set_start()  # set values and errors for refinement start
    check_input.set_globals(far)

    #for key in far.param.keys():
    #    print key,far.param[key]

    #  Farfield outlier rejection
    if far.files['res_file'] != None and far.labels == None:
        from FitAllB import near_field
        near_field.find_refl(far)
        near_field.match(far)
        far.read_rej(
            far.files['rej_file']
        )  # read file containing rejected peaks to resume refinement   NB! optional
    from FitAllB import error
    error.vars(far)
    from FitAllB import build_fcn
    build_fcn.FCN(far)
    far.reject()
    far.write_rej()

    # farfield refinement
    for k in range(far.fit['cycle']):
        #while len(far.fit['newreject_grain']) > 0:
        # refine grain paramters
        far.fit['reforder'] = ['start%s' % k, 'rotpos%s' % k, 'end']
        far.fit['goon'] = far.fit['reforder'][0]
        if k == 0:  #start with globals in stead of grain refinement
            far.fit['reforder'] = ['start%s' % k, 'end']
        far.fit['newreject_grain'] = range(far.no_grains + 1)
        from FitAllB import fit
        fit.refine(far)
        # refine globals
        far.fit['reforder'] = ['globals%s' % k, 'end']
        far.fit['goon'] = far.fit['reforder'][0]
        from FitAllB import fitga
        fitga.refine(far)
        far.residual = []
        far.volume = []
        far.mean_ia = []
        for i in range(far.no_grains):
            far.residual.append([])
            far.volume.append([])
            far.mean_ia.append([])
            for j in range(far.nrefl[i]):
                far.residual[i].append(1)
                far.volume[i].append(1)
                far.mean_ia[i].append(1)
        from FitAllB import reject
        reject.residual(far, far.fit['rej_resmedian'])
        reject.mean_ia(far, far.fit['rej_ia'] * float(k + 2) / float(k + 1))
        reject.intensity(far)
        from FitAllB import write_output
        write_output.write_rej(far, message='globals%i' % k)

        for i in range(far.no_grains):
            if far.nrefl[i] < far.fit['min_refl'] and i + 1 not in far.fit[
                    'skip']:
                far.fit['skip'].append(i + 1)
        far.fit['skip'].sort()

    # optional nearfield info
    if far.files['near_flt_file'] != None:
        assert far.files[
            'near_par_file'] != None, 'near_par_file parameter file for near-field detector is missing'
        near = deepcopy(far)
        # take special care of near-field keywords (eg copy near_dety_size to dety_size)
        for key in near.fit.keys():
            if key[0:5] == 'near_':
                near.fit[key[5:len(key)]] = near.fit[key]
        near.fit['stem'] = far.fit['stem'] + '_near'
        near.read_par(near.files['near_par_file'])
        near.read_flt(near.files['near_flt_file'])
        keys = [
            'cell__a', 'cell__b', 'cell__c', 'cell_alpha', 'cell_beta',
            'cell_gamma', 'cell_lattice_[P,A,B,C,I,F,R]', 'chi', 'omegasign',
            'wavelength'
        ]
        for key in keys:
            assert near.param[key] == far.param[
                key], '%s is different for near- and far-field detectors' % key
        # in case of different wedge use farfield value and refine
        if near.param['wedge'] != far.param['wedge']:
            near.param['wedge'] = far.param['wedge']
        near.values = far.values
        near.errors = far.errors
        near.fit['skip'] = far.fit['skip']
        check_input.set_globals(near)
        # match peaks on nearfield detector and reject outliers
        from FitAllB import near_field
        near_field.find_refl(near)
        near_field.match(near)
        from FitAllB import error
        error.vars(near)
        from FitAllB import build_fcn
        build_fcn.FCN(near)
        near.reject()
        near.write_rej()

        # nearfield refinement
        for k in range(near.fit['cycle']):
            # refine grain paramters
            near.fit['reforder'] = ['start%s' % k, 'rotpos%s' % k, 'end']
            near.fit['goon'] = near.fit['reforder'][0]
            near.fit['newreject_grain'] = range(near.no_grains + 1)
            from FitAllB import fit
            fit.refine(near)
            # refine globals
            near.fit['reforder'] = ['globals%s' % k, 'end']
            near.fit['goon'] = near.fit['reforder'][0]
            from FitAllB import fitga
            fitga.refine(near)
            near.residual = []
            near.volume = []
            near.mean_ia = []
            for i in range(near.no_grains):
                near.residual.append([])
                near.volume.append([])
                near.mean_ia.append([])
                for j in range(near.nrefl[i]):
                    near.residual[i].append(1)
                    near.volume[i].append(1)
                    near.mean_ia[i].append(1)
            from FitAllB import reject
            reject.residual(near, near.fit['rej_resmedian'])
            reject.mean_ia(near,
                           near.fit['rej_ia'] * float(k + 2) / float(k + 1))
            reject.intensity(near)
            from FitAllB import write_output
            write_output.write_rej(near, message='globals%i' % k)

            for i in range(near.no_grains):
                if near.nrefl[i] < near.fit[
                        'min_refl'] and i + 1 not in near.fit['skip']:
                    near.fit['skip'].append(i + 1)
            near.fit['skip'].sort()

    # program ends here after deleting fcn.py and fcn.pyc
    print '\nNormal termination of FitGlobAll'
    os.remove('%s/fcn.py' % far.fit['direc'])
    os.remove('%s/fcn.pyc' % far.fit['direc'])