far.read_log() # read grainspotter.log file far.read_rej( ) # 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: from FitAllB import near_field near_field.find_refl(far) near_field.match(far) 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
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_multidet.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 far.read_res() # read paramters file to resume refinement # mandatory farfield info far.read_par(far.files['par_file']) # read detector.par file far.read_flt(far.files['flt_file']) # read peaks_t##.flt file keys = ['dety_size', 'detz_size'] for key in keys: far.fit[key + '0'] = far.fit[key] keys = ['o11', 'o12', 'o21', 'o22'] for key in keys: far.param[key + '0'] = far.param[key] # second detector if far.fit['no_det'] > 1: far1 = deepcopy(far) del (far1.labels) del (far1.tth) del (far1.eta) del (far1.nrefl) del (far1.id) del (far1.h) del (far1.k) del (far1.l) keys = ['dety_size', 'detz_size'] for key in keys: far1.fit[key] = far.fit[key + '1'] far1.read_par(far.files['par_file_1']) # read detector.par file far1.read_flt(far.files['flt_file_1']) # read peaks_t##.flt file #put info from far1 in far 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', 'wedge' ] for key in keys: assert far1.param[key] == far.param[ key], '%s is different for par_file and and par_file_1' % key keys = [ 'distance', 'o11', 'o12', 'o21', 'o22', 'tilt_x', 'tilt_y', 'tilt_z', 'y_center', 'z_center', 'y_size', 'z_size' ] for key in keys: far.param[key + '1'] = far1.param[key] print('parameters of second detector read successfully') # third detector, NB more can be added in this way!! if far.fit['no_det'] > 2: far2 = deepcopy(far) del (far2.labels) del (far2.tth) del (far2.eta) del (far2.nrefl) del (far2.id) del (far2.h) del (far2.k) del (far2.l) keys = ['dety_size', 'detz_size'] for key in keys: far2.fit[key] = far.fit[key + '2'] far2.read_par(far.files['par_file_2']) # read detector.par file far2.read_flt(far.files['flt_file_2']) # read peaks_t##.flt file #put info from far1 in far 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', 'wedge' ] for key in keys: assert far2.param[key] == far.param[ key], '%s is different for par_file and and par_file_1' % key keys = [ 'distance', 'o11', 'o12', 'o21', 'o22', 'tilt_x', 'tilt_y', 'tilt_z', 'y_center', 'z_center', 'y_size', 'z_size' ] for key in keys: far.param[key + '2'] = far2.param[key] print('parameters of third detector read successfully') # set values and errors for refinement start far.set_start() check_input_multidet.set_globals(far) if far.fit['no_det'] > 1: far1.set_start() check_input_multidet.set_globals(far1) if far.fit['no_det'] > 2: far2.set_start() check_input_multidet.set_globals(far2) # for key in far.param.keys(): # print key,far.param[key] # forward projection to assign reflections if far.files['res_file'] != None and far.labels == None: from FitAllB import near_field near_field.find_refl(far) print('\nFirst detector') near_field.match(far) from FitAllB import error error.vars(far) from FitAllB import build_fcn build_fcn.FCN(far) far.reject() far.nrefl = [far.nrefl] far.id = [far.id] far.h = [far.h] far.k = [far.k] far.l = [far.l] far.w = [far.w] far.dety = [far.dety] far.detz = [far.detz] # far.vars = [far.vars] far.param['total_refl'] = [far.param['total_refl']] if far.fit['no_det'] > 1: if far1.files['res_file'] != None and far1.labels == None: from FitAllB import near_field near_field.find_refl(far1) print('\nSecond detector') near_field.match(far1) error.vars(far1) from FitAllB import build_fcn build_fcn.FCN(far1) far1.reject() far.nrefl.append(far1.nrefl) far.id.append(far1.id) far.h.append(far1.h) far.k.append(far1.k) far.l.append(far1.l) far.w.append(far1.w) far.dety.append(far1.dety) far.detz.append(far1.detz) # far.vars.append(far1.vars) far.param['total_refl'].append(far1.param['total_refl']) if far.fit['no_det'] > 2: if far2.files['res_file'] != None and far2.labels == None: from FitAllB import near_field near_field.find_refl(far2) print('\nThird detector') near_field.match(far2) error.vars(far2) from FitAllB import build_fcn build_fcn.FCN(far2) far2.reject() far.nrefl.append(far2.nrefl) far.id.append(far2.id) far.h.append(far2.h) far.k.append(far2.k) far.l.append(far2.l) far.w.append(far2.w) far.dety.append(far2.dety) far.detz.append(far2.detz) # far.vars.append(far2.vars) far.param['total_refl'].append(far2.param['total_refl']) # print far.nrefl from . import error_multidet error_multidet.vars(far) # print far.vars # 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'] # if k==0: # far.fit['reforder'] = ['start%s' %k,'end'] far.fit['goon'] = far.fit['reforder'][0] far.fit['newreject_grain'] = list(range(far.no_grains + 1)) # refine grains from FitAllB import fit_multidet 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 m in range(far.fit['no_det']): for j in range(far.nrefl[m][i]): far.residual[i].append(1) far.volume[i].append(1) far.mean_ia[i].append(1) from FitAllB import build_fcn_multidet build_fcn_multidet.FCN(far) import fcn importlib.reload(fcn) fit_multidet.refine(far) # refine globals far.fit['reforder'] = ['globals%s' % k, 'end'] far.fit['goon'] = far.fit['reforder'][0] from FitAllB import fitga_multidet 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 m in range(far.fit['no_det']): for j in range(far.nrefl[m][i]): far.residual[i].append(1) far.volume[i].append(1) far.mean_ia[i].append(1) # ---- OK until here fitga_multidet.refine(far) from FitAllB import reject_multidet reject_multidet.residual(far, far.fit['rej_resmedian']) reject_multidet.mean_ia( far, far.fit['rej_ia'] * float(k + 2) / float(k + 1)) # reject.intensity(far) from FitAllB import write_output_multidet write_output_multidet.write_rej(far, message='globals%i' % k) no_ref = [] for i in range(far.no_grains): no_ref.append(0) for k in range(far.fit['no_det']): no_ref[i] = no_ref[i] + far.nrefl[k][i] for i in range(far.no_grains): if no_ref[i] < far.fit['min_refl'] and i + 1 not in far.fit['skip']: far.fit['skip'].append(i + 1) far.fit['skip'].sort() # --- OK after this point # program ends here after deleting fcn.py and fcn.pyc print('\nNormal termination of FitGlobAll_MultiDet') 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)
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)
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'])