Ticket #7776: create_rings.py

File create_rings.py, 1.5 KB (added by Gesner Passos, 7 years ago)
Line 
1
2import numpy
3import math
4# get an instrument
5ws = Load('LOQ48098', SpectrumMin=2, SpectrumMax=16000)
6
7# process the workspace in order to get an image with circles around the
8# defined origin (look at the resulting workspace at instrument view)
9origin = V3D(0.006,0,15.15)
10n = ws.blocksize()
11x_pos = numpy.zeros(ws.getNumberHistograms())
12y_pos = numpy.zeros(ws.getNumberHistograms())
13for i in range(ws.getNumberHistograms()):       
14        try:
15          if ws.getDetector(i).isMonitor() : 
16                ws.setY(i,numpy.zeros(n))
17                continue
18          x_pos[i] = ws.getDetector(i).getPos().getX()
19          y_pos[i] = ws.getDetector(i).getPos().getY()
20          dist = ws.getDetector(i).getPos().distance(origin)
21          if (math.sin(dist*30)<0):
22            ws.setY(i,numpy.zeros(n))
23          else:
24            ws.setY(i, numpy.zeros(n) + math.sin(dist*30))
25        except : 
26                print 'ex'
27                pass
28
29
30# execute the ring profile for all the image in different rings.
31min_r = 0.001
32max_r = 0.33
33num_steps = 20
34num_bins = 36
35startangle = -1
36y_values = list()
37delta = (max_r-min_r)/num_steps
38centre = [0.006,0,15.15]
39
40for i in range(num_steps):
41  aux = RingProfile(ws, centre, min_r, min_r+delta, num_bins, startangle) 
42  min_r += delta
43  y_values.append(numpy.copy(aux.readY(0)))
44  #if you want to compensate the fact that for small rings, the numbers of
45  # detectors are smaller, uncoment this line
46  #y_values.append(aux.readY(0)/((min_r+delta/2)**2))
47       
48# create the result output
49all_rings = CreateWorkspace(aux.readX(0),numpy.concatenate(y_values),NSpec=num_steps)
50