diff --git a/nafuma/xrd/refinement.py b/nafuma/xrd/refinement.py index 84a76f2..921c1cf 100644 --- a/nafuma/xrd/refinement.py +++ b/nafuma/xrd/refinement.py @@ -104,8 +104,53 @@ def make_initial_inp(data: dict, options={}): fout.write(line) +def make_manual_background(data, options): + #FIXME generalize this so it works properly + #FIXME fix so that plotting is optional + import numpy as np + import nafuma.xrd as xrd + import matplotlib.pyplot as plt - + default_options = { + 'plot_background': True, + 'interval_length': 0.05, + 'save_dir': 'background' + } + if "noheaders" in data['path'][0]: + filename = os.path.basename(data['path'][0]).split('_noheaders.')[0] + else: + filename = os.path.basename(data['path'][0]).split('.')[0] + + + options = aux.update_options(options=options, default_options=default_options) + + #data['background_in_q'] is a .txt-file with one column of x-values that are good starting points for background determination, as they should not include any peaks for that specific material + + #importing the pre-made background points in Q into a dataframe + df_backgroundpoints_q=pd.read_csv(data['background_in_q'],names=["background_q"]) + + diffractogram, wavelength = xrd.io.read_xy(data=data) + + #transferring q-range background to the respective wavelength + x_background_points=[] + for q in df_backgroundpoints_q["background_q"]: + twotheta=2*180/np.pi*np.arcsin(q*wavelength/(4*np.pi)) + x_background_points.append(twotheta) + + fig,ax=plt.subplots(figsize=(20,20)) + diffractogram.plot(x="2th",y="I", kind="scatter",ax=ax) + intervallength=options['interval_length'] + background=pd.DataFrame() + + for i, x in enumerate(x_background_points): + test=diffractogram.loc[(diffractogram["2th"]>x-intervallength) & (diffractogram["2th"]