-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExample_Script.py
82 lines (65 loc) · 2.69 KB
/
Example_Script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# Diamond I16 Analysis Script
# [Experiment Name]
# [Script Description]
#
# By [User]
# 23/10/2017
"--------------Import Stuff-------------"
import sys,os
import numpy as np
import matplotlib.pyplot as plt # Plotting
from mpl_toolkits.mplot3d import Axes3D # 3D plotting
# Load Py16progs
sys.path.insert(0,'/dls_sw/i16/software/python/Py16/Py16progs.py') # location of Py16progs
import Py16progs as dp
"-----Set Directories and parameters----"
# Current Directory of this file - if you need it
cf=os.path.dirname(__file__)
# Directory to load data from ***CHANGE THIS***
dp.filedir = '/dls/i16/data/2015/cm12169-2'
# Directory to save files to ***CHANGE THIS***
dp.savedir='/home/i16user/Desktop'
# Update default save location for exported plots
plt.rcParams["savefig.directory"] = dp.savedir
# Experiment Parameters (feel free to ignore or remove unless you want to change them)
dp.exp_ring_current = 300.0 # Average ring current for normalisation
dp.exp_monitor = 800.0 # Average monitor current for normalisation
dp.normby = 'rc' # ring current ('rc'), monitor ('ic1') or none ('none')
dp.pil_centre = [110, 242] # Find the current value in /dls_sw/i16/software/gda/config/scripts/localStation.py (search for "ci=")
dp.peakregion=[7,153,186,332] # 'nroi_peak' will search for peaks within this area of the detector [min_y,min_x,max_y,max_x]
dp.exp_title = '' # exp_title will appear in plot titles
"---------------------------------------"
"------------Analysis Stuff-------------"
"---------------------------------------"
### Single Scan ###
d = dp.readscan(123456)
eta_array = d.eta
initial_eta_value = d.metadata.eta
x,y,dy,varx,vary,ttl,d = dp.getdata(scn,vary='roi1_sum')
### Multiple Scans ###
scans = range(512404,512664,5) + [512665,512666]
# Multi-scan plots
help(dp.plotscan) # See the function documentation!
dp.plotscan(scans)
dp.plotscans3D(scans)
dp.plotscansSURF(scans)
# Automatic Peak Fitting & Integration
fit,err = dp.fit_scans(scans,vary='roi1_sum',depvar='Ta',peaktest=1,fit_type='pVoight',plot=['all','int'],saveFIT=None,savePLOT=None)
# Load fitted data:
#fit,err = dp.load_fits(scans,depvar='Ta',fit_type='pVoight')
### Manual analysis of data ###
temp,value = [],[]
for scn in scans:
x,y,dy,varx,vary,ttl,d = dp.getdata(scn,vary='roi1_sum') # read normalised data
# x = array of scanned values (e.g. eta)
# y = array of recoreded values, normalised by time, attenuation + ring current (e.g. 'roi1_sum')
# dy = errors on y
# varx/y = string label for x/y
# ttl = automatically generated scan title
# d = dataholder as from d = dp.readscan(scn)
temp += [d.metadata.Ta]
value += [sum(y)]
# Basic plotting with Matplotlib
plt.figure()
plt.plot(temp,value,'r-o')
dp.labels('Title','temp','value')