moreniius 0.6.0__py3-none-any.whl → 0.6.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
moreniius/mccode/comp.py CHANGED
@@ -95,27 +95,41 @@ def diskchopper_translator(nxinstance):
95
95
  return nxinstance.make_nx(NXdisk_chopper, slit_edges=NXfield(nx_slit_edges, units='degrees'), **resolve_parameter_links(pars))
96
96
 
97
97
 
98
- def elliptic_guide_gravity_translator(nxinstance):
99
- from nexusformat.nexus import NXguide
98
+ def _ellipse_vertices_faces(major_x, minor_x, offset_x, major_y, minor_y, offset_y, l, n=10):
99
+ """
100
+ Create vertices and faces for an elliptical guide with given parameters.
101
+
102
+ Parameters
103
+ ----------
104
+ major_x : float
105
+ Major axis half-length in the x-direction.
106
+ minor_x : float
107
+ Minor axis half-length in the x-direction.
108
+ offset_x : float
109
+ Offset from the end of the ellipse to the guide entrance in the x-direction.
110
+ major_y : float
111
+ Major axis half-length in the y-direction.
112
+ minor_y : float
113
+ Minor axis half-length in the y-direction.
114
+ offset_y : float
115
+ Offset from the end of the ellipse to the guide entrance in the y-direction.
116
+ l : float
117
+ Length of the guide. l <= 2*major_x - offset_x and l <= 2*major_y - offset_y
118
+ n : int, optional
119
+ Number of segments along the length of the guide. Default is 10.
120
+ """
100
121
  from numpy import arange, sqrt
101
- from moreniius.nxoff import NXoff
102
- if not '"mid"' == nxinstance.obj.get_parameter('dimensionsAt'):
103
- log.warn('Only midpoint geometry supported by Elliptic_guide_gravity translator')
104
- log.info(f'The current guide has {nxinstance.obj.get_parameter("dimensionsAt")} specified')
105
122
 
106
- def ellipse_width(minor, distance, at):
107
- major = sqrt((distance / 2) ** 2 + minor ** 2)
123
+ def ellipse_width(minor, major, at):
108
124
  return 0 if abs(at) > major else minor * sqrt(1 - (at / major) ** 2)
109
125
 
110
- pars = dict(xw='xwidth', xi='linxw', xo='loutxw', yw='yheight', yi='linyh', yo='loutyh', l='l')
111
- p = {k: nxinstance.parameter(v) for k, v in pars.items()}
112
- n = 10
113
126
  rings = arange(n + 1) / n
114
127
  faces, vertices = [], []
115
128
  for x in rings:
116
- w = ellipse_width(p['xw'] / 2, p['xi'] + p['l'] + p['xo'], p['xi'] / 2 + (x - 0.5) * p['l'] - p['xo'] / 2)
117
- h = ellipse_width(p['yw'] / 2, p['yi'] + p['l'] + p['yo'], p['yi'] / 2 + (x - 0.5) * p['l'] - p['yo'] / 2)
118
- z = x * p['l']
129
+ z = x * l
130
+ w = ellipse_width(minor_x, major_x, offset_x - minor_x + z)
131
+ h = ellipse_width(minor_y, major_y, offset_y - minor_y + x)
132
+
119
133
  vertices.extend([[-w, -h, z], [-w, h, z], [w, h, z], [w, -h, z]])
120
134
 
121
135
  # These are only the guide faces (that is, the inner faces of the sides of the guide housing)
@@ -124,6 +138,55 @@ def elliptic_guide_gravity_translator(nxinstance):
124
138
  j0, j1, j2, j3, j4, j5, j6, j7 = [4 * i + k for k in range(8)]
125
139
  faces.extend([[j0, j1, j5, j4], [j1, j2, j6, j5], [j2, j3, j7, j6], [j3, j0, j4, j7]])
126
140
 
141
+ return vertices, faces
142
+
143
+ def _ellipse_parameters_from_widths(nxinstance):
144
+ from numpy import sqrt
145
+
146
+ def parameters(which, w, i, o, l):
147
+ foci = i + l + o
148
+ offset = foci / 2 - i
149
+ if 'mid' in which:
150
+ minor = w / 2
151
+ major = sqrt(foci ** 2 + minor ** 2) / 2
152
+ else:
153
+ t, b = (o, i) if 'entrance' in which else (i, o)
154
+ t += l
155
+ w /= 2
156
+ b = sqrt(b * b + w * w / 4) + sqrt(t * t + w * w / 4)
157
+ major = b / 2
158
+ minor = sqrt(b * b - foci * foci) / 2
159
+ return major, minor, offset
160
+
161
+ pars = dict(xw='xwidth', xi='linxw', xo='loutxw', yw='yheight', yi='linyh', yo='loutyh', l='l')
162
+ p = {k: nxinstance.parameter(v) for k, v in pars.items()}
163
+
164
+ dim_at = str(nxinstance.obj.get_parameter('dimensionsAt').value)
165
+ major_x, minor_x, offset_x = parameters(dim_at, p['xw'], p['xi'], p['xo'], p['l'])
166
+ major_y, minor_y, offset_y = parameters(dim_at, p['yw'], p['yi'], p['yo'], p['l'])
167
+
168
+ return major_x, minor_x, offset_x, major_y, minor_y, offset_y, p['l']
169
+
170
+
171
+ def elliptic_guide_gravity_translator(nxinstance):
172
+ from nexusformat.nexus import NXguide
173
+ from moreniius.nxoff import NXoff
174
+
175
+ ellipse_pars = [f'{f}{s}' for f in ('majorAxis', 'minorAxis', 'majorAxisOffset') for s in ('xw', 'yh')]
176
+ if all(nxinstance.obj.defines_parameter(p) for p in ellipse_pars):
177
+ # we can use the specified ellipse parameters directly
178
+ major_x = nxinstance.parameter('majorAxisxw')
179
+ minor_x = nxinstance.parameter('minorAxisxw')
180
+ offset_x = nxinstance.parameter('majorAxisOffsetxw')
181
+ major_y = nxinstance.parameter('majorAxisyh')
182
+ minor_y = nxinstance.parameter('minorAxisyh')
183
+ offset_y = nxinstance.parameter('majorAxisOffsetyh')
184
+ l = nxinstance.parameter('l')
185
+ else:
186
+ major_x, minor_x, offset_x, major_y, minor_y, offset_y, l = _ellipse_parameters_from_widths(nxinstance)
187
+
188
+ vertices, faces = _ellipse_vertices_faces(major_x, minor_x, offset_x, major_y, minor_y, offset_y, l, n=10)
189
+
127
190
  nx_vertices = [[nxinstance.expr2nx(expr) for expr in vector] for vector in vertices]
128
191
  nx_faces = [[nxinstance.expr2nx(expr) for expr in face] for face in faces]
129
192
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: moreniius
3
- Version: 0.6.0
3
+ Version: 0.6.2
4
4
  Author-email: Gregory Tucker <gregory.tucker@ess.eu>
5
5
  Classifier: License :: OSI Approved :: BSD License
6
6
  Classifier: Development Status :: 2 - Pre-Alpha
@@ -10,10 +10,11 @@ Classifier: Programming Language :: Python :: 3.10
10
10
  Classifier: Programming Language :: Python :: 3.11
11
11
  Classifier: Programming Language :: Python :: 3.12
12
12
  Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Programming Language :: Python :: 3.14
13
14
  Description-Content-Type: text/markdown
14
15
  Requires-Dist: zenlog>=1.1
15
16
  Requires-Dist: platformdirs>=3.11
16
- Requires-Dist: mccode-antlr[hdf5]>=0.16.1
17
+ Requires-Dist: mccode-antlr[hdf5]>=0.16.2
17
18
  Requires-Dist: nexusformat>=1.0.6
18
19
  Requires-Dist: networkx
19
20
 
@@ -6,13 +6,13 @@ moreniius/nxoff.py,sha256=WHp9wYNn_4Hcx8Nzi9rpX1p8_iwI-AdgTQouSAEG8N4,3288
6
6
  moreniius/utils.py,sha256=R81eHjc0EWjMsP-Z8WI9sZkc_QY357z_aYziflQAUEU,9238
7
7
  moreniius/writer.py,sha256=zgrbo7RfAriAGrOpPhFHSwwn3yWG4_ZJndIi6HhTzss,6815
8
8
  moreniius/mccode/__init__.py,sha256=1QiZdh90G3gp_WlVpdJB_ZGauoW0GJEQ13Nelaqa5JE,151
9
- moreniius/mccode/comp.py,sha256=uR1L5nLfYPHhMKd3XnDbqf5xhkfwfPLRnttREc3jqBg,7382
9
+ moreniius/mccode/comp.py,sha256=iaOooI2nIevA0Vhz5jZQJCqXYgmZ3jMm0s3gUtR8Unc,9637
10
10
  moreniius/mccode/instance.py,sha256=yydYeMGITlZrVWBVYregBWQ0Sd_2A71hgoyCrLLW-Jk,8058
11
11
  moreniius/mccode/instr.py,sha256=D4B3ylD4BMfkiP5t2hx5xop9c7yk7QVSleT1wvpK17E,6161
12
12
  moreniius/mccode/mccode.py,sha256=0Ck9xFUHU3EkBGTNIXelMgtLA1JXOs976Sj2wXfMQng,4237
13
13
  moreniius/mccode/orientation.py,sha256=khT0jTMXyXkPCoEpDg-eLKulF-J2wIqNhUi1NzFWvto,3907
14
- moreniius-0.6.0.dist-info/METADATA,sha256=aN4VsNhha0nvgcvb7sJI_7GdvPCFG747YUfrNFxOctg,895
15
- moreniius-0.6.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
16
- moreniius-0.6.0.dist-info/entry_points.txt,sha256=Ga3k4P4fyBt5_dJ03Oapic2Qlgqv9jufQGdxWiz_j2A,63
17
- moreniius-0.6.0.dist-info/top_level.txt,sha256=RzMo23UfVhgQeuOYeS5P9I0qVbxx4Gbe6Roc29Mr02c,10
18
- moreniius-0.6.0.dist-info/RECORD,,
14
+ moreniius-0.6.2.dist-info/METADATA,sha256=PXdfy0oL-NxMtfRpyaP9O2t2uo5aZubQDl7XnkB0kAE,946
15
+ moreniius-0.6.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
16
+ moreniius-0.6.2.dist-info/entry_points.txt,sha256=Ga3k4P4fyBt5_dJ03Oapic2Qlgqv9jufQGdxWiz_j2A,63
17
+ moreniius-0.6.2.dist-info/top_level.txt,sha256=RzMo23UfVhgQeuOYeS5P9I0qVbxx4Gbe6Roc29Mr02c,10
18
+ moreniius-0.6.2.dist-info/RECORD,,