Subtracting data sets¶
It can be very useful to subtract two data sets from each other, e.g. to look for diffuse magnetic scattering. In DMCpy, two data sets with the same A3 can be subtracted from each other. An example of a code is below. The subtraction is perfomed on the DataSet and 3DViewer, plotQPlane, and plotCut1D can be used on the subtracted data.
1from DMCpy import DataSet,DataFile,_tools
2
3# Give file number and folder the file is stored in.
4scanNumbers = '8540'
5folder = 'data/SC'
6year = 2022
7
8filePath = _tools.fileListGenerator(scanNumbers,folder,year=year)
9
10# # # load dataFiles
11dataFiles = [DataFile.loadDataFile(dFP) for dFP in filePath]
12
13# load data files and make data set
14ds = DataSet.DataSet(dataFiles)
15
16# run the Interactive Viewer
17df = ds[0]
18IA1 = df.InteractiveViewer()
19IA1.set_clim(0,20)
20IA1.set_clim_zIntegrated(0,1000)
21
22IA1.fig.savefig('figure0.png',format='png')
23
24# # # subtract dataSets. Needs to be loaded same way as the first DataSet
25if True:
26 scanNumbers_sub = '8553'
27 filePath_sub = _tools.fileListGenerator(scanNumbers_sub,folder,year=year)
28
29 dataFiles_sub = [DataFile.loadDataFile(dFP_sub) for dFP_sub in filePath_sub]
30
31 ds_sub = DataSet.DataSet(dataFiles_sub)
32
33 # we can choose if we write the subtracted data into the original data file or if we make a new file.
34 ds.directSubtractDS(ds_sub,saveToFile=True,saveToNewFile='subtracted_data.hdf')
35
36 #saveToFile (bool): If True, save background to data file, else save in RAM (default False)
37 #saveToNewFile (string) If provided, and saveToFile is True, save a new file with the background subtraction (default False)
38
39# run the Interactive Viewer
40IA2 = df.InteractiveViewer()
41IA2.set_clim(0,20)
42IA2.set_clim_zIntegrated(0,1000)
43
44IA2.fig.savefig('figure1.png',format='png')
45
46Viewer = ds.Viewer3D(0.03,0.03,0.03,rlu=False)
47Viewer.set_clim(0,0.001)
48zSteps = Viewer.Z.shape[-1]
49Viewer.setPlane(int(zSteps/2)-1)
50Viewer.ax.axis('equal')
51
52fig = Viewer.ax.get_figure()
53fig.savefig('figure2.png',format='png')
54
55# # # mask data
56if True:
57 for df in ds:
58 df.mask[:,:,300:400] = True
59
60Viewer2 = ds.Viewer3D(0.03,0.03,0.03,rlu=False)
61Viewer2.set_clim(0,0.001)
62Viewer2.setPlane(int(zSteps/2)-1)
63Viewer2.ax.axis('equal')
64
65fig2 = Viewer2.ax.get_figure()
66fig2.savefig('figure3.png',format='png')
The above code takes the data from the A3 scan file dmc2022n008540 and subtracts dmc2022n008553. The files are meaured under identical conditions and we expect a good subtraction. We see in both interactive Viewer and 3DViewer that we have good subtractoin, but the Cu rings from the sample can is still visible together with some intensity on the 111-reflection.
First data overview
Second data overview with background subtraction and A3 step 114
Third data overview with background subtraction and A3 step 114
Fourth data overview with a mask between detector pixcel 300 and 400