forked from npshub/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sns_instrument.py
85 lines (67 loc) · 3.33 KB
/
sns_instrument.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
83
84
85
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
# NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
#pylint: disable=invalid-name
"""
Instrument-specific utility functions for EQSANS
"""
from .hfir_instrument import _get_pixel_info
def get_pixel_from_coordinate(x, y, workspace):
"""
Returns the pixel coordinates corresponding to the
given real-space position.
This assumes that the center of the detector is aligned
with the beam. An additional offset may need to be applied
@param x: real-space x coordinate [m]
@param y: real-space y coordinate [m]
@param workspace: the pixel number and size info will be taken from the workspace
"""
nx_pixels, ny_pixels, pixel_size_x, pixel_size_y = _get_pixel_info(workspace)
return [-x/pixel_size_x*1000.0 + nx_pixels/2.0-0.5,
y/pixel_size_y*1000.0 + ny_pixels/2.0-0.5]
def get_coordinate_from_pixel(x, y, workspace):
"""
Returns the real-space coordinates corresponding to the
given pixel coordinates [m].
This assumes that the center of the detector is aligned
with the beam. An additional offset may need to be applied
@param x: pixel x coordinate
@param y: pixel y coordinate
@param workspace: the pixel number and size info will be taken from the workspace
"""
nx_pixels, ny_pixels, pixel_size_x, pixel_size_y = _get_pixel_info(workspace)
return [(nx_pixels/2.0-0.5-x) * pixel_size_x/1000.0,
(y-ny_pixels/2.0+0.5) * pixel_size_y/1000.0]
def get_masked_pixels(nx_low, nx_high, ny_low, ny_high, workspace):
"""
Generate a list of masked pixels.
@param nx_low: number of pixels to mask on the lower-x side of the detector
@param nx_high: number of pixels to mask on the higher-x side of the detector
@param ny_low: number of pixels to mask on the lower-y side of the detector
@param ny_high: number of pixels to mask on the higher-y side of the detector
@param workspace: the pixel number and size info will be taken from the workspace
"""
nx_pixels, ny_pixels, pixel_size_x, pixel_size_y = _get_pixel_info(workspace)
if nx_low<0 or nx_high<0 or ny_low<0 or ny_high<0:
raise RuntimeError("Pixel edges should be greater than zero")
masked_x = list(range(0, nx_low))
masked_x.extend(list(range(nx_pixels-nx_high, nx_pixels)))
masked_y = list(range(0, ny_low))
masked_y.extend(list(range(ny_pixels-ny_high, ny_pixels)))
masked_pts = []
for y in masked_y:
masked_pts.extend([ [x,y] for x in range(nx_pixels) ])
for x in masked_x:
masked_pts.extend([ [x,y] for y in range(ny_low, ny_pixels-ny_high) ])
return masked_pts
def get_detector_from_pixel(pixel_list, workspace):
"""
Returns a list of detector IDs from a list of [x,y] pixels,
where the pixel coordinates are in pixel units.
@param workspace: the pixel number and size info will be taken from the workspace
"""
nx_pixels, ny_pixels, pixel_size_x, pixel_size_y = _get_pixel_info(workspace)
return [ ny_pixels*p[0] + p[1] for p in pixel_list ]