syned 1.0.47__py3-none-any.whl → 1.0.49__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.
Files changed (52) hide show
  1. syned/beamline/__init__.py +1 -1
  2. syned/beamline/beamline.py +155 -155
  3. syned/beamline/beamline_element.py +76 -76
  4. syned/beamline/element_coordinates.py +199 -199
  5. syned/beamline/optical_element.py +47 -47
  6. syned/beamline/optical_element_with_surface_shape.py +126 -126
  7. syned/beamline/optical_elements/__init__.py +1 -1
  8. syned/beamline/optical_elements/absorbers/absorber.py +21 -21
  9. syned/beamline/optical_elements/absorbers/beam_stopper.py +63 -63
  10. syned/beamline/optical_elements/absorbers/filter.py +61 -61
  11. syned/beamline/optical_elements/absorbers/holed_filter.py +67 -67
  12. syned/beamline/optical_elements/absorbers/slit.py +80 -80
  13. syned/beamline/optical_elements/crystals/__init__.py +1 -1
  14. syned/beamline/optical_elements/crystals/crystal.py +70 -70
  15. syned/beamline/optical_elements/gratings/__init__.py +1 -1
  16. syned/beamline/optical_elements/gratings/grating.py +279 -279
  17. syned/beamline/optical_elements/ideal_elements/__init__.py +1 -1
  18. syned/beamline/optical_elements/ideal_elements/ideal_element.py +15 -15
  19. syned/beamline/optical_elements/ideal_elements/ideal_fzp.py +183 -183
  20. syned/beamline/optical_elements/ideal_elements/ideal_lens.py +54 -54
  21. syned/beamline/optical_elements/ideal_elements/screen.py +15 -15
  22. syned/beamline/optical_elements/mirrors/__init__.py +1 -1
  23. syned/beamline/optical_elements/mirrors/mirror.py +39 -39
  24. syned/beamline/optical_elements/multilayers/__init__.py +46 -46
  25. syned/beamline/optical_elements/multilayers/multilayer.py +45 -45
  26. syned/beamline/optical_elements/refractors/__init__.py +1 -1
  27. syned/beamline/optical_elements/refractors/crl.py +79 -79
  28. syned/beamline/optical_elements/refractors/interface.py +60 -60
  29. syned/beamline/optical_elements/refractors/lens.py +105 -105
  30. syned/beamline/shape.py +2884 -2803
  31. syned/storage_ring/__init__.py +1 -1
  32. syned/storage_ring/electron_beam.py +804 -804
  33. syned/storage_ring/empty_light_source.py +40 -40
  34. syned/storage_ring/light_source.py +90 -90
  35. syned/storage_ring/magnetic_structure.py +8 -8
  36. syned/storage_ring/magnetic_structures/__init__.py +1 -1
  37. syned/storage_ring/magnetic_structures/bending_magnet.py +329 -329
  38. syned/storage_ring/magnetic_structures/insertion_device.py +169 -169
  39. syned/storage_ring/magnetic_structures/undulator.py +413 -413
  40. syned/storage_ring/magnetic_structures/wiggler.py +27 -27
  41. syned/syned_object.py +273 -264
  42. syned/util/__init__.py +21 -21
  43. syned/util/json_tools.py +196 -198
  44. syned/widget/widget_decorator.py +66 -66
  45. {syned-1.0.47.dist-info → syned-1.0.49.dist-info}/METADATA +88 -88
  46. syned-1.0.49.dist-info/RECORD +52 -0
  47. {syned-1.0.47.dist-info → syned-1.0.49.dist-info}/WHEEL +1 -1
  48. {syned-1.0.47.dist-info → syned-1.0.49.dist-info}/licenses/LICENSE +20 -20
  49. syned/__test/__init__.py +0 -46
  50. syned/__test/test.py +0 -28
  51. syned-1.0.47.dist-info/RECORD +0 -54
  52. {syned-1.0.47.dist-info → syned-1.0.49.dist-info}/top_level.txt +0 -0
syned/util/json_tools.py CHANGED
@@ -1,198 +1,196 @@
1
- """
2
- Functions to read/write syned objects in json files.
3
-
4
- Notes
5
- -----
6
- The elements that are not explicitely imported in the code that follows, but they MUST be imported
7
- to define the objects at run time.
8
- To import more elements, yoy can use the exec_command keyword.
9
-
10
- """
11
- from syned.storage_ring.electron_beam import ElectronBeam
12
- from syned.storage_ring.magnetic_structures.undulator import Undulator
13
- from syned.storage_ring.magnetic_structures.wiggler import Wiggler
14
- from syned.storage_ring.magnetic_structures.bending_magnet import BendingMagnet
15
- from syned.storage_ring.magnetic_structure import MagneticStructure
16
- from syned.beamline.optical_elements.ideal_elements.screen import Screen
17
- from syned.beamline.optical_elements.ideal_elements.ideal_lens import IdealLens
18
- from syned.beamline.optical_elements.absorbers.filter import Filter
19
- from syned.beamline.optical_elements.absorbers.slit import Slit
20
- from syned.beamline.optical_elements.absorbers.beam_stopper import BeamStopper
21
- from syned.beamline.optical_elements.absorbers.holed_filter import HoledFilter
22
- from syned.beamline.optical_elements.mirrors.mirror import Mirror
23
- from syned.beamline.optical_elements.crystals.crystal import Crystal
24
- from syned.beamline.optical_elements.gratings.grating import Grating
25
- from syned.beamline.optical_elements.gratings.grating import GratingVLS
26
- from syned.beamline.optical_elements.gratings.grating import GratingBlaze
27
- from syned.beamline.optical_elements.gratings.grating import GratingLamellar
28
-
29
- from syned.beamline.shape import BoundaryShape
30
- from syned.beamline.shape import Rectangle, Ellipse, Circle
31
- from syned.beamline.shape import MultiplePatch
32
- from syned.beamline.shape import DoubleRectangle, DoubleEllipse, DoubleCircle
33
-
34
- from syned.beamline.shape import SurfaceShape
35
- from syned.beamline.shape import Conic, Plane, Sphere, SphericalCylinder
36
- from syned.beamline.shape import Ellipsoid, EllipticalCylinder
37
- from syned.beamline.shape import Paraboloid, ParabolicCylinder
38
- from syned.beamline.shape import Hyperboloid, HyperbolicCylinder
39
- from syned.beamline.shape import Toroid
40
-
41
- from syned.storage_ring.light_source import LightSource
42
- from syned.storage_ring.empty_light_source import EmptyLightSource
43
-
44
- from syned.beamline.beamline import Beamline
45
- from syned.beamline.beamline_element import BeamlineElement
46
- from syned.beamline.element_coordinates import ElementCoordinates
47
-
48
- from collections import OrderedDict
49
-
50
- try:
51
- import json_tricks as json # to save numpy arrays
52
- except:
53
- import json
54
- from urllib.request import urlopen
55
-
56
- def load_from_json_file(file_name, exec_commands=None):
57
- """
58
- Function to load a syned object from a json file.
59
-
60
- Parameters
61
- ----------
62
- file_name : str
63
- The file name.
64
- exec_commands : str
65
- The commands (typically import...) to be executed before accesing the file.
66
-
67
- Returns
68
- -------
69
- instance of SynedObject
70
-
71
- """
72
- f = open(file_name)
73
- text = f.read()
74
- f.close()
75
- return load_from_json_text(text, exec_commands=exec_commands)
76
-
77
- def load_from_json_url(file_url, exec_commands=None):
78
- """
79
- Function to load a syned object from a remote json file.
80
-
81
- Parameters
82
- ----------
83
- file_url : str
84
- The URL with the file name.
85
- exec_commands : str
86
- The commands (typically import...) to be executed before accesing the file.
87
-
88
- Returns
89
- -------
90
- instance of SynedObject
91
-
92
- """
93
- u = urlopen(file_url)
94
- ur = u.read()
95
- url = ur.decode(encoding='UTF-8')
96
- return load_from_json_text(url, exec_commands=exec_commands)
97
-
98
- def load_from_json_text(text, exec_commands=None):
99
- """
100
- Function to load a syned object from a json txt.
101
-
102
- Parameters
103
- ----------
104
- text : str
105
- The text with the corresponding info.
106
- exec_commands : str
107
- The commands (typically import...) to be executed before accesing the file.
108
-
109
- Returns
110
- -------
111
- instance of SynedObject
112
-
113
- """
114
- return load_from_json_dictionary_recurrent(json.loads(text), exec_commands=exec_commands)
115
-
116
- def load_from_json_dictionary_recurrent(jsn, verbose=False, exec_commands=None):
117
- """
118
- Function to convert a dictionary (got from json file) into a syned object.
119
-
120
- Parameters
121
- ----------
122
- jsn : dict
123
- The dictionary with json file information.
124
- verbose : boolean, optional
125
- Define or not verbose output.
126
- exec_commands : str
127
- The commands (typically import...) to be executed before accesing the file.
128
-
129
- Returns
130
- -------
131
- instance of SynedObject
132
-
133
- """
134
- if isinstance(exec_commands, list):
135
- for command in exec_commands:
136
- if verbose: print(">>>>",command)
137
- exec(command)
138
- elif isinstance(exec_commands, str):
139
- if verbose: print(">>>>", exec_commands)
140
- exec(exec_commands)
141
-
142
- if verbose: print(jsn.keys())
143
- if "CLASS_NAME" in jsn.keys():
144
- if verbose: print("FOUND CLASS NAME: ",jsn["CLASS_NAME"])
145
- if verbose: print(">>>>eval: ", jsn["CLASS_NAME"])
146
- try:
147
- tmp1 = eval(jsn["CLASS_NAME"]+"()")
148
- except:
149
- raise RuntimeError("Error evaluating: "+jsn["CLASS_NAME"]+"() ** you could use the exec_command keyword to import it at run time **")
150
-
151
-
152
- if tmp1.keys() is not None:
153
- NOT_FOUND = "--------NOT-FOUND--------"
154
- for key in tmp1.keys():
155
- stored_value = jsn.get(key, NOT_FOUND)
156
- if str(stored_value) != NOT_FOUND:
157
- if verbose: print(">>>>processing",key ,type(jsn[key]))
158
- if isinstance(jsn[key],dict):
159
- if verbose: print(">>>>>>>>dictionary found, starting recurrency",key ,type(jsn[key]))
160
- tmp2 = load_from_json_dictionary_recurrent(jsn[key],exec_commands=exec_commands)
161
- if verbose: print(">>>>2",key,type(tmp2))
162
- tmp1.set_value_from_key_name(key,tmp2)
163
- elif isinstance(jsn[key], list):
164
- if verbose: print(">>>>>>>>LIST found, starting recurrency",key ,type(jsn[key]))
165
- out_list_of_objects = []
166
- for element in jsn[key]:
167
- if isinstance(element, dict):
168
- if verbose: print(">>>>>>>>LIST found, starting recurrency",key ,type(element))
169
- tmp3 = load_from_json_dictionary_recurrent(element, exec_commands=exec_commands)
170
- if verbose: print(">>>>3",type(tmp3))
171
- out_list_of_objects.append(tmp3)
172
- else:
173
- print("***** Failed to load", element)
174
- if verbose: print("kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk",out_list_of_objects)
175
- tmp1.set_value_from_key_name(key,out_list_of_objects)
176
- # tmp1.set_value_from_key_name(key,tmp2)
177
- else:
178
- if verbose: print(">>>>>>> setting value for key: ",key," to: ",repr(jsn[key]))
179
- tmp1.set_value_from_key_name(key,jsn[key])
180
-
181
- return tmp1
182
-
183
-
184
- if __name__ == "__main__":
185
-
186
- file_url = "http://ftp.esrf.fr/pub/scisoft/syned/lightsources/ESRF_ID01_EBS_PPU35_22.json"
187
- syned_obj = load_from_json_url(file_url)
188
- print(syned_obj.info())
189
-
190
-
191
- #
192
- # file_url = "/home/manuel/Oasys/ALSU-IR-BM.json"
193
- # syned_obj = load_from_json_file(file_url)
194
- # print(syned_obj.info())
195
-
196
- # file_url = "/home/manuel/Oasys/bl.json"
197
- # syned_obj = load_from_json_file(file_url)
198
- # print(syned_obj.info())
1
+ """
2
+ Functions to read/write syned objects in json files.
3
+
4
+ Notes
5
+ -----
6
+ The elements that are not explicitely imported in the code that follows, but they MUST be imported
7
+ to define the objects at run time.
8
+ To import more elements, yoy can use the exec_command keyword.
9
+
10
+ """
11
+ from syned.storage_ring.electron_beam import ElectronBeam
12
+ from syned.storage_ring.magnetic_structures.undulator import Undulator
13
+ from syned.storage_ring.magnetic_structures.wiggler import Wiggler
14
+ from syned.storage_ring.magnetic_structures.bending_magnet import BendingMagnet
15
+ from syned.storage_ring.magnetic_structure import MagneticStructure
16
+ from syned.beamline.optical_elements.ideal_elements.screen import Screen
17
+ from syned.beamline.optical_elements.ideal_elements.ideal_lens import IdealLens
18
+ from syned.beamline.optical_elements.absorbers.filter import Filter
19
+ from syned.beamline.optical_elements.absorbers.slit import Slit
20
+ from syned.beamline.optical_elements.absorbers.beam_stopper import BeamStopper
21
+ from syned.beamline.optical_elements.absorbers.holed_filter import HoledFilter
22
+ from syned.beamline.optical_elements.mirrors.mirror import Mirror
23
+ from syned.beamline.optical_elements.crystals.crystal import Crystal
24
+ from syned.beamline.optical_elements.gratings.grating import Grating
25
+ from syned.beamline.optical_elements.gratings.grating import GratingVLS
26
+ from syned.beamline.optical_elements.gratings.grating import GratingBlaze
27
+ from syned.beamline.optical_elements.gratings.grating import GratingLamellar
28
+
29
+ from syned.beamline.shape import BoundaryShape
30
+ from syned.beamline.shape import Rectangle, Ellipse, Circle
31
+ from syned.beamline.shape import MultiplePatch
32
+ from syned.beamline.shape import DoubleRectangle, DoubleEllipse, DoubleCircle
33
+
34
+ from syned.beamline.shape import SurfaceShape
35
+ from syned.beamline.shape import Conic, Plane, Sphere, SphericalCylinder
36
+ from syned.beamline.shape import Ellipsoid, EllipticalCylinder
37
+ from syned.beamline.shape import Paraboloid, ParabolicCylinder
38
+ from syned.beamline.shape import Hyperboloid, HyperbolicCylinder
39
+ from syned.beamline.shape import Toroid
40
+
41
+ from syned.storage_ring.light_source import LightSource
42
+ from syned.storage_ring.empty_light_source import EmptyLightSource
43
+
44
+ from syned.beamline.beamline import Beamline
45
+ from syned.beamline.beamline_element import BeamlineElement
46
+ from syned.beamline.element_coordinates import ElementCoordinates
47
+
48
+ from collections import OrderedDict
49
+
50
+ import json_tricks # to save numpy arrays
51
+
52
+ from urllib.request import urlopen
53
+
54
+ def load_from_json_file(file_name, exec_commands=None):
55
+ """
56
+ Function to load a syned object from a json file.
57
+
58
+ Parameters
59
+ ----------
60
+ file_name : str
61
+ The file name.
62
+ exec_commands : str
63
+ The commands (typically import...) to be executed before accesing the file.
64
+
65
+ Returns
66
+ -------
67
+ instance of SynedObject
68
+
69
+ """
70
+ f = open(file_name)
71
+ text = f.read()
72
+ f.close()
73
+ return load_from_json_text(text, exec_commands=exec_commands)
74
+
75
+ def load_from_json_url(file_url, exec_commands=None):
76
+ """
77
+ Function to load a syned object from a remote json file.
78
+
79
+ Parameters
80
+ ----------
81
+ file_url : str
82
+ The URL with the file name.
83
+ exec_commands : str
84
+ The commands (typically import...) to be executed before accesing the file.
85
+
86
+ Returns
87
+ -------
88
+ instance of SynedObject
89
+
90
+ """
91
+ u = urlopen(file_url)
92
+ ur = u.read()
93
+ url = ur.decode(encoding='UTF-8')
94
+ return load_from_json_text(url, exec_commands=exec_commands)
95
+
96
+ def load_from_json_text(text, exec_commands=None):
97
+ """
98
+ Function to load a syned object from a json txt.
99
+
100
+ Parameters
101
+ ----------
102
+ text : str
103
+ The text with the corresponding info.
104
+ exec_commands : str
105
+ The commands (typically import...) to be executed before accesing the file.
106
+
107
+ Returns
108
+ -------
109
+ instance of SynedObject
110
+
111
+ """
112
+ return load_from_json_dictionary_recurrent(json_tricks.loads(text), exec_commands=exec_commands)
113
+
114
+ def load_from_json_dictionary_recurrent(jsn, verbose=False, exec_commands=None):
115
+ """
116
+ Function to convert a dictionary (got from json file) into a syned object.
117
+
118
+ Parameters
119
+ ----------
120
+ jsn : dict
121
+ The dictionary with json file information.
122
+ verbose : boolean, optional
123
+ Define or not verbose output.
124
+ exec_commands : str
125
+ The commands (typically import...) to be executed before accesing the file.
126
+
127
+ Returns
128
+ -------
129
+ instance of SynedObject
130
+
131
+ """
132
+ if isinstance(exec_commands, list):
133
+ for command in exec_commands:
134
+ if verbose: print(">>>>",command)
135
+ exec(command)
136
+ elif isinstance(exec_commands, str):
137
+ if verbose: print(">>>>", exec_commands)
138
+ exec(exec_commands)
139
+
140
+ if verbose: print(jsn.keys())
141
+ if "CLASS_NAME" in jsn.keys():
142
+ if verbose: print("FOUND CLASS NAME: ",jsn["CLASS_NAME"])
143
+ if verbose: print(">>>>eval: ", jsn["CLASS_NAME"])
144
+ try:
145
+ tmp1 = eval(jsn["CLASS_NAME"]+"()")
146
+ except:
147
+ raise RuntimeError("Error evaluating: "+jsn["CLASS_NAME"]+"() ** you could use the exec_command keyword to import it at run time **")
148
+
149
+
150
+ if tmp1.keys() is not None:
151
+ NOT_FOUND = "--------NOT-FOUND--------"
152
+ for key in tmp1.keys():
153
+ stored_value = jsn.get(key, NOT_FOUND)
154
+ if str(stored_value) != NOT_FOUND:
155
+ if verbose: print(">>>>processing",key ,type(jsn[key]))
156
+ if isinstance(jsn[key],dict):
157
+ if verbose: print(">>>>>>>>dictionary found, starting recurrency",key ,type(jsn[key]))
158
+ tmp2 = load_from_json_dictionary_recurrent(jsn[key],exec_commands=exec_commands)
159
+ if verbose: print(">>>>2",key,type(tmp2))
160
+ tmp1.set_value_from_key_name(key,tmp2)
161
+ elif isinstance(jsn[key], list):
162
+ if verbose: print(">>>>>>>>LIST found, starting recurrency",key ,type(jsn[key]))
163
+ out_list_of_objects = []
164
+ for element in jsn[key]:
165
+ if isinstance(element, dict):
166
+ if verbose: print(">>>>>>>>LIST found, starting recurrency",key ,type(element))
167
+ tmp3 = load_from_json_dictionary_recurrent(element, exec_commands=exec_commands)
168
+ if verbose: print(">>>>3",type(tmp3))
169
+ out_list_of_objects.append(tmp3)
170
+ else:
171
+ print("***** Failed to load", element)
172
+ if verbose: print("kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk",out_list_of_objects)
173
+ tmp1.set_value_from_key_name(key,out_list_of_objects)
174
+ # tmp1.set_value_from_key_name(key,tmp2)
175
+ else:
176
+ if verbose: print(">>>>>>> setting value for key: ",key," to: ",repr(jsn[key]))
177
+ tmp1.set_value_from_key_name(key,jsn[key])
178
+
179
+ return tmp1
180
+
181
+
182
+ if __name__ == "__main__":
183
+
184
+ file_url = "http://ftp.esrf.fr/pub/scisoft/syned/lightsources/ESRF_ID01_EBS_PPU35_22.json"
185
+ syned_obj = load_from_json_url(file_url)
186
+ print(syned_obj.info())
187
+
188
+
189
+ #
190
+ # file_url = "/home/manuel/Oasys/ALSU-IR-BM.json"
191
+ # syned_obj = load_from_json_file(file_url)
192
+ # print(syned_obj.info())
193
+
194
+ # file_url = "/home/manuel/Oasys/bl.json"
195
+ # syned_obj = load_from_json_file(file_url)
196
+ # print(syned_obj.info())
@@ -1,67 +1,67 @@
1
-
2
- from syned.beamline.beamline import Beamline
3
-
4
- class WidgetDecorator(object):
5
- """
6
- Definition of a widget decorator (to be used by widget implementations).
7
-
8
- """
9
-
10
- @classmethod
11
- def syned_input_data(cls, multi_input=False):
12
- """
13
- A string to help defining SYNED data in OASYS.
14
-
15
- Returns
16
- -------
17
- list
18
- [("SynedData", Beamline, "receive_syned_data")]
19
-
20
- """
21
- try: # OASYS2
22
- import oasys2
23
-
24
- if not multi_input:
25
- from orangewidget.widget import Input
26
-
27
- return Input(name="Syned Data",
28
- type=Beamline,
29
- id="SynedData",
30
- default=True, auto_summary=False)
31
- else:
32
- from orangewidget.widget import MultiInput
33
-
34
- return MultiInput(name="Syned Data",
35
- type=Beamline,
36
- id="SynedData",
37
- default=True, auto_summary=False)
38
- except:
39
- return [("SynedData", Beamline, "receive_syned_data")]
40
-
41
- @classmethod
42
- def append_syned_input_data(cls, inputs):
43
- """
44
-
45
- Parameters
46
- ----------
47
- inputs
48
-
49
-
50
- """
51
- for input in WidgetDecorator.syned_input_data():
52
- inputs.append(input)
53
-
54
- def receive_syned_data(self, data):
55
- """
56
- To be implemented in the main object.
57
-
58
- Parameters
59
- ----------
60
- data
61
-
62
- Raises
63
- ------
64
- NotImplementedError
65
-
66
- """
1
+
2
+ from syned.beamline.beamline import Beamline
3
+
4
+ class WidgetDecorator(object):
5
+ """
6
+ Definition of a widget decorator (to be used by widget implementations).
7
+
8
+ """
9
+
10
+ @classmethod
11
+ def syned_input_data(cls, multi_input=False):
12
+ """
13
+ A string to help defining SYNED data in OASYS.
14
+
15
+ Returns
16
+ -------
17
+ list
18
+ [("SynedData", Beamline, "receive_syned_data")]
19
+
20
+ """
21
+ try: # OASYS2
22
+ import oasys2
23
+
24
+ if not multi_input:
25
+ from orangewidget.widget import Input
26
+
27
+ return Input(name="Syned Data",
28
+ type=Beamline,
29
+ id="SynedData",
30
+ default=True, auto_summary=False)
31
+ else:
32
+ from orangewidget.widget import MultiInput
33
+
34
+ return MultiInput(name="Syned Data",
35
+ type=Beamline,
36
+ id="SynedData",
37
+ default=True, auto_summary=False)
38
+ except:
39
+ return [("SynedData", Beamline, "receive_syned_data")]
40
+
41
+ @classmethod
42
+ def append_syned_input_data(cls, inputs):
43
+ """
44
+
45
+ Parameters
46
+ ----------
47
+ inputs
48
+
49
+
50
+ """
51
+ for input in WidgetDecorator.syned_input_data():
52
+ inputs.append(input)
53
+
54
+ def receive_syned_data(self, data):
55
+ """
56
+ To be implemented in the main object.
57
+
58
+ Parameters
59
+ ----------
60
+ data
61
+
62
+ Raises
63
+ ------
64
+ NotImplementedError
65
+
66
+ """
67
67
  raise NotImplementedError("Should be implemented")