tofu.geom¶
Load all core packages and modules which are all machine-independent, diagnostic-independent and code-independent
Created on Wed May 18 2016
@version: 0.9 @author: didiervezinet @author_email: didier.vezinet@gmail.com
-
class
tofu.geom.
Ves
(Id, Poly, Type='Tor', DLong=None, Sino_RefPt=None, Sino_NP=50, Clock=False, arrayorder='C', Exp=None, shot=None, dtime=None, dtimeIn=False, SavePath=None)[source]¶ A class defining a Linear or Toroidal vaccum vessel (i.e. a 2D polygon representing a cross-section and assumed to be linearly or toroidally invariant)
A Ves object is mostly defined by a close 2D polygon, which can be understood as a poloidal cross-section in (R,Z) cylindrical coordinates if Type=’Tor’ (toroidal shape) or as a straight cross-section through a cylinder in (Y,Z) cartesian coordinates if Type=’Lin’ (linear shape). Attributes such as the surface, the angular volume (if Type=’Tor’) or the center of mass are automatically computed. The instance is identified thanks to an attribute Id (which is itself a tofu.ID class object) which contains informations on the specific instance (name, Type...).
Parameters: - Id (str / tfpf.ID) – A name string or a pre-built tfpf.ID class to be used to identify this particular instance, if a string is provided, it is fed to tfpf.ID()
- Poly (np.ndarray) – An array (2,N) or (N,2) defining the contour of the vacuum vessel in a cross-section, if not closed, will be closed automatically
- Type (str) – Flag indicating whether the vessel will be a torus (‘Tor’) or a linear device (‘Lin’)
- DLong (list / np.ndarray) – Array or list of len=2 indicating the limits of the linear device volume on the x axis
- Sino_RefPt (None / np.ndarray) – Array specifying a reference point for computing the sinogram (i.e. impact parameter), if None automatically set to the (surfacic) center of mass of the cross-section
- Sino_NP (int) – Number of points in [0,2*pi] to be used to plot the vessel sinogram envelop
- Clock (bool) – Flag indicating whether the input polygon should be made clockwise (True) or counter-clockwise (False)
- arrayorder (str) – Flag indicating whether the attributes of type=np.ndarray (e.g.: Poly) should be made C-contiguous (‘C’) or Fortran-contiguous (‘F’)
- Exp (None / str) – Flag indicating which experiment the object corresponds to, allowed values are in [None,’AUG’,’MISTRAL’,’JET’,’ITER’,’TCV’,’TS’,’Misc’]
- shot (None / int) – Shot number from which this Ves is usable (in case of change of geometry)
- SavePath (None / str) – If provided, forces the default saving path of the object to the provided value
- dtime (None / dtm.datetime) – A time reference to be used to identify this particular instance (used for debugging mostly)
- dtimeIn (bool) – Flag indicating whether dtime should be included in the SaveName (used for debugging mostly)
Returns: Ves (Ves object) – The created Ves object, with all necessary computed attributes and methods
-
BaryS
¶ Return the (surfacic) center of mass of the polygon defining the vessel cross-section
-
BaryV
¶ Return the (volumic) center of mass of the polygon defining the vessel cross-section
-
Id
¶ Return the tfpf.ID object of the vessel
-
Poly
¶ Return the polygon defining the vessel cross-section
-
Sino_NP
¶ Return the number of points used used for plotting the Ves polygon in projection space
-
Sino_RefPt
¶ Return the 2D coordinates of the points used as a reference for computing the Ves polygon in projection space (where sinograms are plotted)
-
Surf
¶ Return the area of the polygon defining the vessel cross-section
-
Type
¶ Return the type of vessel
-
Vect
¶ Return the polygon elementary vectors
-
Vin
¶ Return the normalized vectors pointing inwards for each segment of the polygon
-
VolLin
¶ Return the angular volume of the polygon defining the vessel cross-section of Tor type
-
arrayorder
¶ Return the flag indicating which order is used for multi-dimensional array attributes
-
get_InsideConvexPoly
(RelOff=0.05, ZLim='Def', Spline=True, Splprms=[100.0, 2.0, 3], NP=100, Plot=False, Test=True)[source]¶ Return a polygon that is a smaller and smoothed approximation of Ves.Poly, useful for excluding the divertor region in a Tokamak
For some uses, it can be practical to approximate the polygon defining the Ves object (which can be non-convex, like with a divertor), by a simpler, sligthly smaller and convex polygon. This method provides a fast solution for computing such a proxy.
Parameters: - RelOff (float) – Fraction by which an homothetic polygon should be reduced (1.-RelOff)*(Poly-BaryS)
- ZLim (None / str / tuple) – Flag indicating what limits shall be put to the height of the polygon (used for excluding divertor)
- Spline (bool) – Flag indiating whether the reduced and truncated polygon shall be smoothed by 2D b-spline curves
- Splprms (list) – List of 3 parameters to be used for the smoothing [weights,smoothness,b-spline order], fed to scipy.interpolate.splprep()
- NP (int) – Number of points to be used to define the smoothed polygon
- Plot (bool) – Flag indicating whether the result shall be plotted for visual inspection
- Test (bool) – Flag indicating whether the inputs should be tested for conformity
Returns: Poly (np.ndarray) – (2,N) polygon resulting from homothetic transform, truncating and optional smoothing
-
get_MeshCrossSection
(CrossMesh=[0.01, 0.01], CrossMeshMode='abs', Test=True)[source]¶ Return a (2,N) array of 2D points coordinates meshing the Ves cross-section using the spacing specified by CrossMesh for each direction (taken as absolute distance or relative to the total size)
Method used for fast automatic meshing of the cross-section using a rectangular mesh uniform in each direction. Returns the flattened points coordinates array, as well as the two increasing vectors and number of points.
Parameters: - CrossMesh (iterable) – Iterable of len()==2 specifying the distance to be used between points in each direction (R or Y and Z), in absolute value or relative to the total size of the Ves in each direction
- CrossMeshMode (str) – Flag specifying whether the distances provided in CrossMesh are absolute (‘abs’) or relative (‘rel’)
- Test (bool) – Flag indicating whether the inputs should be tested for conformity
Returns: - Pts (np.ndarray) – Array of shape (2,N), comtaining the 2D coordinates of the N points consituting the mesh, only points lying inside the cross-section are returned
- X1 (np.ndarray) – Flat array of the unique first coordinates of the mesh points (R or Y)
- X2 (np.ndarray) – Flat array of the unique second coordinates of the mesh points (Z)
- NumX1 (int) – Number of unique values in X1 (=X1.size)
- NumX2 (int) – Number of unique values in X2 (=X2.size)
-
isInside
(Pts, In='(X, Y, Z)')[source]¶ Return an array of booleans indicating whether each point lies inside the Ves volume
Tests for each point whether it lies inside the Ves object. The points coordinates can be provided in 2D or 3D, just specify which coordinate system is provided using the ‘In’ parameter. An array of boolean flags is returned.
Parameters: - Pts (np.ndarray) – (2,N) or (3,N) array with the coordinates of the points to be tested
- In (str) – Flag indicating the coordinate system in which the points are provided, in [‘(X,Y,Z)’,’(R,Z)’,’‘]
Returns: ind (np.ndarray) – Array of booleans of shape (N,), True if a point is inside the Ves volume
-
plot
(Lax=None, Proj='All', Elt='PIBsBvV', Pdict=None, Idict={'marker': 'x', 'mew': 2, 'c': 'k', 'markersize': 8, 'ls': 'dashed'}, Bsdict={'marker': 'x', 'mew': 2, 'c': 'b', 'markersize': 8, 'ls': 'dashed'}, Bvdict={'marker': 'x', 'mew': 2, 'c': 'g', 'markersize': 8, 'ls': 'dashed'}, Vdict={'color': 'r', 'scale': 10}, IdictHor={'c': 'k', 'ls': 'dashed'}, BsdictHor={'c': 'b', 'ls': 'dashed'}, BvdictHor={'c': 'g', 'ls': 'dashed'}, Lim=[1.5707963267948966, 6.283185307179586], Nstep=50, LegDict={'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, draw=True, a4=False, Test=True)[source]¶ Plot the polygon defining the vessel, with a cross-section view, a longitudinal view or both, and optionally its reference point for plotting it in projection space
Generic method for plotting the Ves object, the projections to be plotted, the elements to plot, and the dictionaries or properties to be used for plotting each elements can all be specified using keyword arguments. If an ax is not provided a default one is created.
Parameters: - Lax (list or plt.Axes) – The axes to be used for plotting (provide a list of 2 axes if Proj=’All’), if None a new figure with axes is created
- Proj (str) – Flag specifying the kind of projection used for the plot (‘Cross’ for a cross-section, ‘Hor’ for a horizontal plane, or ‘All’ for the two plots)
- Elt (str) –
- Flag specifying which elements to plot, each capital letter corresponds to an element
- ‘P’: polygon
- ‘I’: point used as a reference for computing impact parameters
- ‘Bs’: (surfacic) center of mass
- ‘Bv’: (volumic) center of mass for Tor type
- ‘V’: vector pointing inward perpendicular to each segment defining the polygon
- Pdict (dict or None) – Dictionary of properties used for plotting the polygon, fed to plt.Axes.plot() or plt.plot_surface() if Proj=‘3d’, set to ToFu_Defauts.py if None
- Idict (dict) – Dictionary of properties used for plotting point ‘I’ in Cross-section projection, fed to plt.Axes.plot()
- IdictHor (dict) – Dictionary of properties used for plotting point ‘I’ in horizontal projection, fed to plt.Axes.plot()
- Bsdict (dict) – Dictionary of properties used for plotting point ‘Bs’ in Cross-section projection, fed to plt.Axes.plot()
- BsdictHor (dict) – Dictionry of properties used for plotting point ‘Bs’ in horizontal projection, fed to plt.Axes.plot()
- Bvdict (dict) – Dictionary of properties used for plotting point ‘Bv’ in Cross-section projection, fed to plt.Axes.plot()
- BvdictHor (dict) – Dictionary of properties used for plotting point ‘Bv’ in horizontal projection, fed to plt.Axes.plot()
- Vdict (dict) – Dictionary of properties used for plotting point ‘V’ in cross-section projection, fed to plt.Axes.quiver()
- LegDict (dict or None) – Dictionary of properties used for plotting the legend, fed to plt.legend(), the legend is not plotted if None
- Lim (list or tuple) – Array of a lower and upper limit of angle (rad.) or length for plotting the ‘3d’ Proj
- Nstep (int) – Number of points for sampling in ignorable coordinate (toroidal angle or length)
- draw (bool) – Flag indicating whether the fig.canvas.draw() shall be called automatically
- a4 (bool) – Flag indicating whether the figure should be plotted in a4 dimensions for printing
- Test (bool) – Flag indicating whether the inputs should be tested for conformity
Returns: La list or plt.Axes Handles of the axes used for plotting (list if several axes where used)
-
plot_Sinogram
(Proj='Cross', ax=None, Ang='theta', AngUnit='rad', Sketch=True, Pdict=None, LegDict={'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, draw=True, a4=False, Test=True)[source]¶ Plot the sinogram of the vessel polygon, by computing its envelopp in a cross-section, can also plot a 3D version of it
The envelop of the polygon is computed using self.Sino_RefPt as a reference point in projection space, and plotted using the provided dictionary of properties. Optionaly a smal sketch can be included illustrating how the angle and the impact parameters are defined (if the axes is not provided).
Parameters: - Proj (str) – Flag indicating whether to plot a classic sinogram (‘Cross’) from the vessel cross-section (assuming 2D), or an extended 3D version ‘3d’ of it with additional angle
- ax (None or plt.Axes) – The axes on which the plot should be done, if None a new figure and axes is created
- Ang (str) – Flag indicating which angle to use for the impact parameter, the angle of the line itself (xi) or of its impact parameter (theta)
- AngUnit (str) – Flag for the angle units to be displayed, ‘rad’ for radians or ‘deg’ for degrees
- Sketch (bool) – Flag indicating whether a small skecth showing the definitions of angles ‘theta’ and ‘xi’ should be included or not
- Pdict (dict) – Dictionary of properties used for plotting the polygon envelopp, fed to plt.plot() if Proj=’Cross’ and to plt.plot_surface() if Proj=‘3d’
- LegDict (None or dict) – Dictionary of properties used for plotting the legend, fed to plt.legend(), the legend is not plotted if None
- draw (bool) – Flag indicating whether the fig.canvas.draw() shall be called automatically
- a4 (bool) – Flag indicating whether the figure should be plotted in a4 dimensions for printing
- Test (bool) – Flag indicating whether the inputs shall be tested for conformity
Returns: ax (plt.Axes) – The axes used to plot
-
save
(SaveName=None, Path=None, Mode='npz')[source]¶ Save the object in folder Name, under file name SaveName, using specified mode
Most tofu objects can be saved automatically as numpy arrays (.npz, recommended) at the default location (recommended) by simply calling self.save()
Parameters: - SaveName (None / str) – The name to be used for the saved file, if None (recommended) uses self.Id.SaveName
- Path (None / str) – Path specifying where to save the file, if None (recommended) uses self.Id.SavePath
- Mode (str) – Flag specifying whether to save the object as a numpy array file (‘.npz’, recommended) or an object using cPickle (not recommended, heavier and may cause retro-compatibility issues)
-
class
tofu.geom.
Struct
(Id, Poly, Type='Tor', DLong=None, Ves=None, Clock=False, arrayorder='C', Exp=None, shot=None, dtime=None, dtimeIn=False, SavePath=None)[source]¶ A class defining a Linear or Toroidal structural element (i.e. a 2D polygon representing a cross-section and assumed to be linearly or toroidally invariant), like a
Ves
but with less properties.A Struct object is mostly defined by a close 2D polygon, which can be understood as a poloidal cross-section in (R,Z) cylindrical coordinates if Type=’Tor’ (toroidal shape) or as a straight cross-section through a cylinder in (Y,Z) cartesian coordinates if Type=’Lin’ (linear shape). Attributes such as the surface, the angular volume (if Type=’Tor’) or the center of mass are automatically computed. The instance is identified thanks to an attribute Id (which is itself a tofu.ID class object) which contains informations on the specific instance (name, Type...).
Parameters: - Id (str / tfpf.ID) – A name string or a pre-built tfpf.ID class to be used to identify this particular instance, if a string is provided, it is fed to tfpf.ID()
- Poly (np.ndarray) – An array (2,N) or (N,2) defining the contour of the vacuum vessel in a cross-section, if not closed, will be closed automatically
- Type (str) – Flag indicating whether the vessel will be a torus (‘Tor’) or a linear device (‘Lin’)
- DLong (list / np.ndarray) – Array or list of len=2 indicating the limits of the linear device volume on the x axis
- Ves (None or
Ves
) – An optional associated vessel - Clock (bool) – Flag indicating whether the input polygon should be made clockwise (True) or counter-clockwise (False)
- arrayorder (str) – Flag indicating whether the attributes of type=np.ndarray (e.g.: Poly) should be made C-contiguous (‘C’) or Fortran-contiguous (‘F’)
- Exp (None / str) – Flag indicating which experiment the object corresponds to, allowed values are in [None,’AUG’,’MISTRAL’,’JET’,’ITER’,’TCV’,’TS’,’Misc’]
- shot (None / int) – Shot number from which this Ves is usable (in case of change of geometry)
- SavePath (None / str) – If provided, forces the default saving path of the object to the provided value
- dtime (None / dtm.datetime) – A time reference to be used to identify this particular instance (used for debugging mostly)
- dtimeIn (bool) – Flag indicating whether dtime should be included in the SaveName (used for debugging mostly)
Returns: struct (Struct object) – The created Struct object, with all necessary computed attributes and methods
-
BaryS
¶ Return the (surfacic) center of mass of the polygon defining the vessel cross-section
-
BaryV
¶ Return the (volumic) center of mass of the polygon defining the vessel cross-section
-
DLong
¶ Return the length spanned by the object in the ignorable coordinate
-
Id
¶ Return the tfpf.ID object of the structure
-
Poly
¶ Return the polygon defining the vessel cross-section
-
Surf
¶ Return the area of the polygon defining the vessel cross-section
-
Type
¶ Return the type of structure
-
Vect
¶ Return the polygon elementary vectors
-
Ves
¶ Return the associated
Ves
object, if any
-
Vin
¶ Return the normalized vectors pointing inwards for each segment of the polygon
-
VolLin
¶ Return the angular volume of the polygon defining the vessel cross-section of Tor type
-
arrayorder
¶ Return the flag indicating which order is used for multi-dimensional array attributes
-
isInside
(Pts, In='(X, Y, Z)')[source]¶ Return an array of booleans indicating whether each point lies inside the Ves volume
Tests for each point whether it lies inside the Ves object. The points coordinates can be provided in 2D or 3D, just specify which coordinate system is provided using the ‘In’ parameter. An array of boolean flags is returned.
Parameters: - Pts (np.ndarray) – (2,N) or (3,N) array with the coordinates of the points to be tested
- In (str) – Flag indicating the coordinate system in which the points are provided, in [‘(X,Y,Z)’,’(R,Z)’,’‘]
Returns: ind (np.ndarray) – Array of booleans of shape (N,), True if a point is inside the Ves volume
-
plot
(Lax=None, Proj='All', Elt='PBsBvV', Pdict=None, Bsdict={'marker': 'x', 'mew': 2, 'c': 'b', 'markersize': 8, 'ls': 'dashed'}, Bvdict={'marker': 'x', 'mew': 2, 'c': 'g', 'markersize': 8, 'ls': 'dashed'}, Vdict={'color': 'r', 'scale': 10}, BsdictHor={'c': 'b', 'ls': 'dashed'}, BvdictHor={'c': 'g', 'ls': 'dashed'}, Lim=[1.5707963267948966, 6.283185307179586], Nstep=50, LegDict={'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, draw=True, a4=False, Test=True)[source]¶ Plot the polygon defining the vessel, with a cross-section view, a longitudinal view or both, and optionally its reference point for plotting it in projection space
Generic method for plotting the Ves object, the projections to be plotted, the elements to plot, and the dictionaries or properties to be used for plotting each elements can all be specified using keyword arguments. If an ax is not provided a default one is created.
Parameters: - Lax (list or plt.Axes) – The axes to be used for plotting (provide a list of 2 axes if Proj=’All’), if None a new figure with axes is created
- Proj (str) – Flag specifying the kind of projection used for the plot (‘Cross’ for a cross-section, ‘Hor’ for a horizontal plane, or ‘All’ for the two plots)
- Elt (str) –
- Flag specifying which elements to plot, each capital letter corresponds to an element
- ‘P’: polygon
- ‘Bs’: (surfacic) center of mass
- ‘Bv’: (volumic) center of mass for Tor type
- ‘V’: vector pointing inward perpendicular to each segment defining the polygon
- Pdict (dict or None) – Dictionary of properties used for plotting the polygon, fed to plt.Axes.plot() or plt.plot_surface() if Proj=‘3d’, set to ToFu_Defauts.py if None
- Bsdict (dict) – Dictionary of properties used for plotting point ‘Bs’ in Cross-section projection, fed to plt.Axes.plot()
- BsdictHor (dict) – Dictionry of properties used for plotting point ‘Bs’ in horizontal projection, fed to plt.Axes.plot()
- Bvdict (dict) – Dictionary of properties used for plotting point ‘Bv’ in Cross-section projection, fed to plt.Axes.plot()
- BvdictHor (dict) – Dictionary of properties used for plotting point ‘Bv’ in horizontal projection, fed to plt.Axes.plot()
- Vdict (dict) – Dictionary of properties used for plotting point ‘V’ in cross-section projection, fed to plt.Axes.quiver()
- LegDict (dict or None) – Dictionary of properties used for plotting the legend, fed to plt.legend(), the legend is not plotted if None
- Lim (list or tuple) – Array of a lower and upper limit of angle (rad.) or length for plotting the ‘3d’ Proj
- Nstep (int) – Number of points for sampling in ignorable coordinate (toroidal angle or length)
- draw (bool) – Flag indicating whether the fig.canvas.draw() shall be called automatically
- a4 (bool) – Flag indicating whether the figure should be plotted in a4 dimensions for printing
- Test (bool) – Flag indicating whether the inputs should be tested for conformity
Returns: La list or plt.Axes Handles of the axes used for plotting (list if several axes where used)
-
save
(SaveName=None, Path=None, Mode='npz')[source]¶ Save the object in folder Name, under file name SaveName, using specified mode
Most tofu objects can be saved automatically as numpy arrays (.npz, recommended) at the default location (recommended) by simply calling self.save()
Parameters: - SaveName (None / str) – The name to be used for the saved file, if None (recommended) uses self.Id.SaveName
- Path (None / str) – Path specifying where to save the file, if None (recommended) uses self.Id.SavePath
- Mode (str) – Flag specifying whether to save the object as a numpy array file (‘.npz’, recommended) or an object using cPickle (not recommended, heavier and may cause retro-compatibility issues)
-
class
tofu.geom.
LOS
(Id, Du, Ves=None, Sino_RefPt=None, arrayorder='C', Clock=False, Type=None, Exp=None, Diag=None, shot=None, dtime=None, dtimeIn=False, SavePath=None)[source]¶ A Line-Of-Sight object (semi-line with signed direction) with all useful geometrical parameters, associated
Ves
object and built-in methods for plotting, defined in (X,Y,Z) cartesian coordinatesA Line of Sight (LOS) is a semi-line. It is a useful approximate representation of a (more accurate) Volume of Sight (VOS) when the latter is narrow and elongated. It is usually associated to a detector placed behind apertures. When associated to a
Ves
object, special points are automatically computed (entry point, exit point, closest point to the center of theVes
object...) as well as a projection in a cross-section. While tofu provides the possibility of creating LOS objects for academic and simplification pueposes, it is generally not recommended to use them for doing physics, consider using a Detect object instead (which will provide you with a proper and automatically-computed VOS as well as with a LOS if you want).Parameters: - Id (str / tfpf.ID) – A name string or a pre-built tfpf.ID class to be used to identify this particular instance, if a string is provided, it is fed to tfpf.ID()
- Du (list / tuple) – List of 2 arrays of len=3, the (X,Y,Z) coordinates of respectively the starting point D of the LOS and its directing vector u (will be automatically normalized)
- Ves (
Ves
) – AVes
instance to be associated to the created LOS - Sino_RefPt (None or np.ndarray) – If provided, array of size=2 containing the (R,Z) (for ‘Tor’ Type) or (Y,Z) (for ‘Lin’ Type) coordinates of the reference point for the sinogram
- arrayorder (str) – Flag indicating whether the attributes of type=np.ndarray (e.g.: Poly) should be made C-contiguous (‘C’) or Fortran-contiguous (‘F’)
- Type (None) – (not used in the current version)
- Exp (None / str) – Experiment to which the Lens belongs, should be identical to Ves.Id.Exp if Ves is provided, if None and Ves is provided, Ves.Id.Exp is used
- Diag (None / str) – Diagnostic to which the Lens belongs
- shot (None / int) – Shot number from which this Lens is usable (in case its position was changed from a previous configuration)
- SavePath (None / str) – If provided, forces the default saving path of the object to the provided value
- dtime (None / dtm.datetime) – A time reference to be used to identify this particular instance (used for debugging mostly)
- dtimeIn (bool) – Flag indicating whether dtime should be included in the SaveName (used for debugging mostly)
-
plot
(Lax=None, Proj='All', Lplot='Tot', Elt='LDIORP', EltVes='', Leg='', Ldict={'lw': 2, 'c': 'k'}, MdictD={'c': 'k', 'markersize': 8, 'lw': 2, 'mew': 2, 'ls': 'None', 'marker': 'x'}, MdictI={'c': 'k', 'markersize': 8, 'lw': 2, 'mew': 2, 'ls': 'None', 'marker': 'x'}, MdictO={'c': 'k', 'markersize': 8, 'lw': 2, 'mew': 2, 'ls': 'None', 'marker': 'x'}, MdictR={'c': 'k', 'markersize': 8, 'lw': 2, 'mew': 2, 'ls': 'None', 'marker': 'x'}, MdictP={'c': 'k', 'markersize': 8, 'lw': 2, 'mew': 2, 'ls': 'None', 'marker': 'x'}, LegDict={'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, Vesdict={'draw': True, 'LegDict': {'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, 'BsdictHor': {'c': 'b', 'ls': 'dashed'}, 'Bvdict': {'marker': 'x', 'mew': 2, 'c': 'g', 'markersize': 8, 'ls': 'dashed'}, 'Lim': [1.5707963267948966, 6.283185307179586], 'Test': True, 'Proj': 'All', 'IdictHor': {'c': 'k', 'ls': 'dashed'}, 'Elt': 'PIBsBvV', 'Pdict': None, 'Vdict': {'color': 'r', 'scale': 10}, 'Idict': {'marker': 'x', 'mew': 2, 'c': 'k', 'markersize': 8, 'ls': 'dashed'}, 'Bsdict': {'marker': 'x', 'mew': 2, 'c': 'b', 'markersize': 8, 'ls': 'dashed'}, 'Lax': None, 'BvdictHor': {'c': 'g', 'ls': 'dashed'}, 'Nstep': 50}, draw=True, a4=False, Test=True)[source]¶ Plot the LOS, in a cross-section projection, a horizontal projection or both, and optionally the
Ves
object associated to it.Plot the desired projections of the LOS object. The plot can include the special points, the directing vector, and the properties of the plotted objects are specified by dictionaries.
Parameters: - Lax (list / plt.Axes) – The axes to be used for plotting (provide a list of 2 axes if Proj=’All’), if None a new figure with axes is created
- Proj (str) – Flag specifying the kind of projection used for the plot (‘Cross’ for a cross-section, ‘Hor’ for a horizontal plane, ‘All’ both and ‘3d’ for 3d)
- Elt (str) –
- Flag specifying which elements to plot, each capital letter corresponds to an element
- ‘L’: LOS
- ‘D’: Starting point of the LOS
- ‘I’: Input point (i.e.: where the LOS enters the Vessel)
- ‘O’: Output point (i.e.: where the LOS exits the Vessel)
- ‘R’: Point of minimal major radius R (only for Vessel of Type=’Tor’)
- ‘P’: Point of used for impact parameter (i.e.: minimal distance to reference point Sino_RefPt)
- Lplot (str) – Flag specifying whether to plot the full LOS (‘Tot’: from starting point output point) or only the fraction inside the vessel (‘In’: from input to output point)
- EltVes (str) – Flag specifying the elements of the Vessel to be plotted, fed to
plot()
- Leg (str) – Legend to be used to identify this LOS, if Leg=’’ the LOS name is used
- Ldict (dict / None) – Dictionary of properties used for plotting the polygon, fed to plt.Axes.plot() or plt.plot_surface() if Proj=‘3d’, set to ToFu_Defauts.py if None
- MdictD (dict) – Dictionary of properties used for plotting point ‘D’, fed to plt.Axes.plot()
- MdictI (dict) – Dictionary of properties used for plotting point ‘I’, fed to plt.Axes.plot()
- MdictO (dict) – Dictionary of properties used for plotting point ‘O’, fed to plt.Axes.plot()
- MdictR (dict) – Dictionary of properties used for plotting point ‘R’, fed to plt.Axes.plot()
- MdictP (dict) – Dictionary of properties used for plotting point ‘P’, fed to plt.Axes.plot()
- LegDict (dict or None) – Dictionary of properties used for plotting the legend, fed to plt.legend(), the legend is not plotted if None
- Vesdict (dict) – Dictionary of kwdargs to fed to
plot()
, and ‘EltVes’ is used instead of ‘Elt’ - draw (bool) – Flag indicating whether the fig.canvas.draw() shall be called automatically
- a4 (bool) – Flag indicating whether the figure should be plotted in a4 dimensions for printing
- Test (bool) – Flag indicating whether the inputs should be tested for conformity
Returns: La (list / plt.Axes) – Handles of the axes used for plotting (list if several axes where used)
-
plot_Sinogram
(Proj='Cross', ax=None, Elt='LV', Sketch=True, Ang='theta', AngUnit='rad', Ldict={'c': 'k', 'markersize': 8, 'lw': 2, 'mew': 2, 'ls': 'None', 'marker': 'x'}, Vdict={'edgecolor': (0.8, 0.8, 0.8, 1.0), 'linewidth': 1, 'linestyle': 'solid', 'facecolor': (0.8, 0.8, 0.8, 1.0)}, LegDict={'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, draw=True, a4=False, Test=True)[source]¶ Plot the sinogram of the vessel polygon, by computing its envelopp in a cross-section, can also plot a 3D version of it
Plot the LOS in projection space (where sinograms are plotted) as a point. You can plot the conventional projection-space (in 2D in a cross-section), or a 3D extrapolation of it, where the third coordinate is provided by the angle that the LOS makes with the cross-section plane (useful in case of multiple LOS with a partially tangential view).
Parameters: - Proj (str) – Flag indicating whether to plot a classic sinogram (‘Cross’) from the vessel cross-section (assuming 2D), or an extended 3D version (‘3d’) of it with additional angle
- ax (None or plt.Axes) – The axes on which the plot should be done, if None a new figure and axes is created
- Elt (str) –
- Flag indicating which elements to plot, each capital letter stands for one element
- ‘L’: LOS
- ‘V’: Vessel
- Ang (str) – Flag indicating which angle to use for the impact parameter, the angle of the line itself (xi) or of its impact parameter (theta)
- AngUnit (str) – Flag for the angle units to be displayed, ‘rad’ for radians or ‘deg’ for degrees
- Sketch (bool) – Flag indicating whether a small skecth showing the definitions of angles ‘theta’ and ‘xi’ should be included or not
- Ldict (dict) – Dictionary of properties used for plotting the LOS point, fed to plt.plot() if Proj=’Cross’ and to plt.plot_surface() if Proj=‘3d’
- Vdict (dict) – Dictionary of properties used for plotting the polygon envelopp, fed to plt.plot() if Proj=’Cross’ and to plt.plot_surface() if Proj=‘3d’
- LegDict (None or dict) – Dictionary of properties used for plotting the legend, fed to plt.legend(), the legend is not plotted if None
- draw (bool) – Flag indicating whether to draw the figure
- a4 (bool) – Flag indicating whether the figure should be plotted in a4 dimensions for printing
- Test (bool) – Flag indicating whether the inputs shall be tested for conformity
Returns: ax (plt.Axes) – The axes used to plot
-
save
(SaveName=None, Path=None, Mode='npz')[source]¶ Save the object in folder Name, under file name SaveName, using specified mode
Most tofu objects can be saved automatically as numpy arrays (.npz, recommended) at the default location (recommended) by simply calling self.save()
Parameters: - SaveName (None / str) – The name to be used for the saved file, if None (recommended) uses self.Id.SaveName
- Path (None / str) – Path specifying where to save the file, if None (recommended) uses self.Id.SavePath
- Mode (str) – Flag specifying whether to save the object as a numpy array file (‘.npz’, recommended) or an object using cPickle (not recommended, heavier and may cause retro-compatibility issues)
-
class
tofu.geom.
GLOS
(Id, LLOS, Ves=None, Sino_RefPt=None, Type=None, Exp=None, Diag=None, shot=None, arrayorder='C', Clock=False, dtime=None, dtimeIn=False, SavePath=None)[source]¶ An object regrouping a group of LOS objects with some common features (e.g.: all belong to the same camera) and the same
Ves
object, provides methods for common computing and plottingUsually
LOS
correspond to detectors which are naturally grouped in ‘cameras’ (sets of detectors located in the same place or sharing an aperture or a data acquisition system). The GLOS object provided by tofu provides the object-oriented equivalent. The GLOS objects provides the same methods as theLOS
objects, plus extra methods for fast handling or selecting of the whole set. Note that you must first create eachLOS
independently and then provide them as a list argument to a GLOS object.Parameters: - Id (str / tfpf.ID) – A name string or a pre-built tfpf.ID class to be used to identify this particular instance, if a string is provided, it is fed to tfpf.ID()
- LLOS (list / :class:'LOS') – List of LOS instances with the same
Ves
instance - Type (None) – (not used in the current version)
- Exp (None / str) – Experiment to which the Lens belongs, should be identical to Ves.Id.Exp if Ves is provided, if None and Ves is provided, Ves.Id.Exp is used
- Diag (None / str) – Diagnostic to which the Lens belongs
- shot (None / int) – Shot number from which this Lens is usable (in case its position was changed from a previous configuration)
- Sino_RefPt (None / iterable) – If provided, array of size=2 containing the (R,Z) (for ‘Tor’ Type) or (Y,Z) (for ‘Lin’ Type) coordinates of the reference point for the sinogram
- arrayorder (str) – Flag indicating whether the attributes of type=np.ndarray (e.g.: Poly) should be made C-contiguous (‘C’) or Fortran-contiguous (‘F’)
- SavePath (None / str) – If provided, forces the default saving path of the object to the provided value
- None / dtm.datetime (dtime) – A time reference to be used to identify this particular instance (used for debugging mostly)
- bool (dtimeIn) – Flag indicating whether dtime should be included in the SaveName (used for debugging mostly)
-
plot
(Lax=None, Proj='All', Lplot='Tot', Elt='LDIORP', EltVes='', Leg='', Ldict={'lw': 2, 'c': 'k'}, MdictD={'c': 'k', 'markersize': 8, 'lw': 2, 'mew': 2, 'ls': 'None', 'marker': 'x'}, MdictI={'c': 'k', 'markersize': 8, 'lw': 2, 'mew': 2, 'ls': 'None', 'marker': 'x'}, MdictO={'c': 'k', 'markersize': 8, 'lw': 2, 'mew': 2, 'ls': 'None', 'marker': 'x'}, MdictR={'c': 'k', 'markersize': 8, 'lw': 2, 'mew': 2, 'ls': 'None', 'marker': 'x'}, MdictP={'c': 'k', 'markersize': 8, 'lw': 2, 'mew': 2, 'ls': 'None', 'marker': 'x'}, LegDict={'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, ind=None, Val=None, Crit='Name', PreExp=None, PostExp=None, Log='any', InOut='In', Vesdict={'draw': True, 'LegDict': {'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, 'BsdictHor': {'c': 'b', 'ls': 'dashed'}, 'Bvdict': {'marker': 'x', 'mew': 2, 'c': 'g', 'markersize': 8, 'ls': 'dashed'}, 'Lim': [1.5707963267948966, 6.283185307179586], 'Test': True, 'Proj': 'All', 'IdictHor': {'c': 'k', 'ls': 'dashed'}, 'Elt': 'PIBsBvV', 'Pdict': None, 'Vdict': {'color': 'r', 'scale': 10}, 'Idict': {'marker': 'x', 'mew': 2, 'c': 'k', 'markersize': 8, 'ls': 'dashed'}, 'Bsdict': {'marker': 'x', 'mew': 2, 'c': 'b', 'markersize': 8, 'ls': 'dashed'}, 'Lax': None, 'BvdictHor': {'c': 'g', 'ls': 'dashed'}, 'Nstep': 50}, draw=True, a4=False, Test=True)[source]¶ Plot the GLOS, with a cross-section view, a horizontal view or both, and optionally the
Ves
object associated to it.Plot all the
LOS
of the GLOS, or only a selection of them (using the same parameters as self.select()).Parameters: - Lax (list or plt.Axes) – The axes to be used for plotting (provide a list of 2 axes if Proj=’All’), if None a new figure with axes is created
- Proj (str) – Flag specifying the kind of projection used for the plot (‘Cross’ for a cross-section, ‘Hor’ for a horizontal plane, ‘All’ both and ‘3d’ for 3d)
- Elt (str) –
- Flag specifying which elements to plot, each capital letter corresponds to an element
- ‘L’: LOS
- ‘D’: Starting point of the LOS
- ‘I’: Input point (i.e.: where the LOS enters the Vessel)
- ‘O’: Output point (i.e.: where the LOS exits the Vessel)
- ‘R’: Point of minimal major radius R (only for Vessel of Type=’Tor’)
- ‘P’: Point of used for impact parameter (i.e.: minimal distance to reference point ImpRZ)
- Lplot (str) – Flag specifying whether to plot the full LOS (‘Tot’: from starting point output point) or only the fraction inside the vessel (‘In’: from input to output point)
- EltVes (str) – Flag specifying the elements of the Vessel to be plotted, fed to
plot()
- Leg (str) – Legend to be used to identify this LOS, if Leg=’’ the LOS name is used
- Ldict (dict or None) – Dictionary of properties used for plotting the polygon, fed to plt.Axes.plot() or plt.plot_surface() if Proj=‘3d’, set to ToFu_Defauts.py if None
- MdictD (dict) – Dictionary of properties used for plotting point ‘D’, fed to plt.Axes.plot()
- MdictI (dict) – Dictionary of properties used for plotting point ‘I’, fed to plt.Axes.plot()
- MdictO (dict) – Dictionary of properties used for plotting point ‘O’, fed to plt.Axes.plot()
- MdictR (dict) – Dictionary of properties used for plotting point ‘R’, fed to plt.Axes.plot()
- MdictP (dict) – Dictionary of properties used for plotting point ‘P’, fed to plt.Axes.plot()
- LegDict (dict or None) – Dictionary of properties used for plotting the legend, fed to plt.legend(), the legend is not plotted if None
- Vesdict (dict) – Dictionary of kwdargs to fed to
plot()
, and ‘EltVes’ is used instead of ‘Elt’ - Lim (list or tuple) – Array of a lower and upper limit of angle (rad.) or length for plotting the ‘3d’ Proj
- draw (bool) – Flag indicating whether the fig.canvas.draw() shall be called automatically
- Test (bool) – Flag indicating whether the inputs should be tested for conformity
- None or np.ndarray (ind) – Array of indices (int or bool) of the LOS to be plotted if only some of them are to be plotted
- kwdargs – kwdargs to be fed to GLOS.select() if ind=None and only a fraction of the LOS are to be plotted
Returns: La (list or plt.Axes) – Handles of the axes used for plotting (list if several axes where used)
-
plot_Sinogram
(Proj='Cross', ax=None, Elt='LV', Sketch=True, Ang='theta', AngUnit='rad', Ldict={'c': 'k', 'markersize': 8, 'lw': 2, 'mew': 2, 'ls': 'None', 'marker': 'x'}, Vdict={'edgecolor': (0.8, 0.8, 0.8, 1.0), 'linewidth': 1, 'linestyle': 'solid', 'facecolor': (0.8, 0.8, 0.8, 1.0)}, LegDict={'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, draw=True, a4=False, Test=True, ind=None, Val=None, Crit='Name', PreExp=None, PostExp=None, Log='any', InOut='In')[source]¶ Plot the sinogram of the vessel polygon, by computing its envelopp in a cross-section, can also plot a 3D version of it
Plot all the
LOS
of the GLOS, or only a selection of them in projection spaceParameters: - Proj (str) – Flag indicating whether to plot a classic sinogram (‘Cross’) from the vessel cross-section (assuming 2D), or an extended 3D version ‘3d’ of it with additional angle, default: ‘Cross’
- ax (None or plt.Axes) – The axes on which the plot should be done, if None a new figure and axes is created, default: None
- Elt (str) –
- Flag indicating which elements to plot, each capital letter stands for one element, default: ‘LV’
- ‘L’: LOS
- ‘V’: Vessel
- Ang (str) – Flag indicating which angle to use for the impact parameter, the angle of the line itself (xi) or of its impact parameter (theta), default: ‘theta’
- AngUnit (str) – Flag for the angle units to be displayed, ‘rad’ for radians or ‘deg’ for degrees, default: ‘rad’
- Sketch (bool) – Flag indicating whether a small skecth showing the definitions of angles ‘theta’ and ‘xi’ should be included or not
- Ldict (dict) – Dictionary of properties used for plotting the LOS point, fed to plt.plot() if Proj=’Cross’ and to plt.plot_surface() if Proj=‘3d’, default: see ToFu_Defaults.py
- Vdict (dict) – Dictionary of properties used for plotting the polygon envelopp, fed to plt.plot() if Proj=’Cross’ and to plt.plot_surface() if Proj=‘3d’, default: see ToFu_Defaults.py
- LegDict (None or dict) – Dictionary of properties used for plotting the legend, fed to plt.legend(), the legend is not plotted if None, default: see ToFu_Defaults.py
- draw (bool) – Flag indicating whether to draw the figure, default: True
- Test (bool) – Flag indicating whether the inputs shall be tested for conformity, default: True
Returns: ax (plt.Axes) – The axes used to plot
-
save
(SaveName=None, Path=None, Mode='npz')[source]¶ Save the object in folder Name, under file name SaveName, using specified mode
Most tofu objects can be saved automatically as numpy arrays (.npz, recommended) at the default location (recommended) by simply calling self.save()
Parameters: - SaveName (None / str) – The name to be used for the saved file, if None (recommended) uses self.Id.SaveName
- Path (None / str) – Path specifying where to save the file, if None (recommended) uses self.Id.SavePath
- Mode (str) – Flag specifying whether to save the object as a numpy array file (‘.npz’, recommended) or an object using cPickle (not recommended, heavier and may cause retro-compatibility issues)
-
select
(Val=None, Crit='Name', PreExp=None, PostExp=None, Log='any', InOut='In', Out=<type 'bool'>)[source]¶ Return the indices or instances of all instances matching the specified criterion.
The selection can be done according to 2 different mechanism (1) and (2).
For mechanism (1): the user provides the value (Val) that the specified criterion (Crit) should take for a
LOS
to be selected. The criteria are typically attributes of the self.Id attribute (i.e.: name of the instance, or user-defined attributes like the camera head...)For mechanism (2), used if Val=None: the user provides a str expression (or a list of such) to be fed to eval(), used to check on quantitative criteria, placed before the criterion value (e.g.: ‘not ‘ or ‘<=’). Another str or list of str expressions can be provided that will be placed after the criterion value.
Other parameters are used to specify logical operators for the selection (match any or all the criterion...) and the type of output.
Parameters: - Crit (str) – Flag indicating which criterion to use for discrimination Can be set to any attribute of the tofu.pathfile.ID class (e.g.: ‘Name’,’SaveName’,’SavePath’...) or any key of ID.USRdict (e.g.: ‘Exp’...)
- Val (list, str or None) – The value to match for the chosen criterion, can be a list of different values Used for selection mechanism (1)
- PreExp (list, str or None) – A str of list of str expressions to be fed to eval(), used to check on quantitative criteria, placed before the criterion value (e.g.: ‘not ‘) Used for selection mechanism (2)
- PostExp (list, str or None) – A str of list of str expressions to be fed to eval(), used to check on quantitative criteria, placed after the criterion value (e.g.: ‘>=5.’) Used for selection mechanism (2)
- Log (str) – Flag indicating whether the criterion shall match all provided values or one of them (‘any’ or ‘all’)
- InOut (str) – Flag indicating whether the returned indices are the ones matching the criterion (‘In’) or the ones not matching it (‘Out’)
- Out (type / str) – Flag indicating in which form shall the result be returned, as an array of integer indices (int), an array of booleans (bool), a list of names (‘Names’) or a list of instances (‘LOS’)
Returns: ind (list / np.ndarray) – The computed output (array of index, list of names or instances depending on parameter ‘Out’)
Examples
>>> import tofu.geom as tfg >>> ves = tfg.Ves('ves', [[0.,1.,1.,0.],[0.,0.,1.,1.]], DLong=[-1.,1.], Type='Lin', Exp='Misc', shot=0) >>> los1 = tfg.LOS('los1', ([0.,-0.1,-0.1],[0.,1.,1.]), Ves=ves, Exp='Misc', Diag='D', shot=0) >>> los2 = tfg.LOS('los2', ([0.,-0.1,-0.1],[0.,0.5,1.]), Ves=ves, Exp='Misc', Diag='D', shot=1) >>> los3 = tfg.LOS('los3', ([0.,-0.1,-0.1],[0.,1.,0.5]), Ves=ves, Exp='Misc', Diag='D', shot=1) >>> glos = tfg.GLOS('glos', [los1,los2,los3]) >>> ind = glos.select(Val=['los1','los3'], Log='any', Out='LOS') >>> print [ii.Id.Name for ii in ind] ['los1', 'los3'] >>> ind = glos.select(Val=['los1','los3'], Log='any', InOut='Out', Out=int) array([1])
-
class
tofu.geom.
Lens
(Id, O, nIn, Rad, F1, F2=inf, R1=None, R2=None, dd=None, Ves=None, Type='Sph', Exp=None, Diag=None, shot=None, arrayorder='C', Clock=False, SavePath=None, dtime=None, dtimeIn=False)[source]¶ A Lens class with all geometrical data and built-in methods, defined as a planar polygon in 3D cartesian coordinates, with optional
Ves
objectA Lens object is useful for implementing one of the two possible optical arrangements available in tofu. A Lens (implicitly convergent) is used for focusing incoming light on a detector of reduced size (i.e.g: like the end of an optic fiber cable). In this case, anmd in its current version, tofu only handles spherical lenses and assumes that the detector has a circular active surface, centered on the same axis as the lens and located in its focal plane.
Parameters: - Id (str or tfpf.ID) – A name string or a pre-built tfpf.ID class to be used to identify this particular instance, if a string is provided, it is fed to tfpf.ID()
- O (iterable) – Array of 3D cartesian coordinates of the center of the Lens
- nIn (iterable) – Array of 3D cartesian coordiantes of the vector defining the axis of the Lens
- Rad (float) – Radius of the Lens
- F1 (float) – Focal length of the Lens, on the detector side
- F2 (float) – Focal length of the Lens, on the plasma side (only np.inf supported so far)
- Type (str) – Flag indicating the type of Lens (only ‘Sph’ - for spherical lens - supported so far)
- R1 (None or float) – Radius of the first face of the Lens, for full description only
- R2 (None or float) – Radius of the second face of the Lens, for full description only
- dd (None or float) – Width of the Lens along its axis, for full description only
- Ves (
Ves
) –Ves
object to which the aperture is assigned - Exp (None or str) – Experiment to which the Lens belongs, should be identical to Ves.Id.Exp if Ves is provided, if None and Ves is provided, Ves.Id.Exp is used
- Diag (None or str) – Diagnostic to which the Lens belongs
- shot (None or int) – Shot number from which this Lens is usable (in case its position was changed from a previous configuration)
- SavePath (None / str) – If provided, forces the default saving path of the object to the provided value
- Clock (bool) – Flag indicating whether the input polygon should be made clockwise (True) or counter-clockwise (False), default: False
- arrayorder (str) – Flag indicating whether the attributes of type=np.ndarray (e.g.: Poly) should be made C-contiguous (‘C’) or Fortran-contiguous (‘F’), default: ‘C’
- dtime (None or dtm.datetime) – A time reference to be used to identify this particular instance (used for debugging mostly), default: None
- dtimeIn (bool) – Flag indicating whether dtime should be included in the SaveName (used for debugging mostly), default: False
-
Poly
¶ Return a simple representation of the Lens as a 3D circle (if Lens.Type=’Sph’)
-
plot
(Lax=None, Proj='All', Elt='PV', EltVes='', Leg=None, LVIn=0.1, Pdict={'lw': 2, 'c': 'k', 'ls': 'solid'}, Vdict={'color': 'r', 'lw': 2, 'ls': 'solid'}, Vesdict={'draw': True, 'LegDict': {'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, 'BsdictHor': {'c': 'b', 'ls': 'dashed'}, 'Bvdict': {'marker': 'x', 'mew': 2, 'c': 'g', 'markersize': 8, 'ls': 'dashed'}, 'Lim': [1.5707963267948966, 6.283185307179586], 'Test': True, 'Proj': 'All', 'IdictHor': {'c': 'k', 'ls': 'dashed'}, 'Elt': 'PIBsBvV', 'Pdict': None, 'Vdict': {'color': 'r', 'scale': 10}, 'Idict': {'marker': 'x', 'mew': 2, 'c': 'k', 'markersize': 8, 'ls': 'dashed'}, 'Bsdict': {'marker': 'x', 'mew': 2, 'c': 'b', 'markersize': 8, 'ls': 'dashed'}, 'Lax': None, 'BvdictHor': {'c': 'g', 'ls': 'dashed'}, 'Nstep': 50}, LegDict={'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, draw=True, a4=False, Test=True)[source]¶ Plot the Lens object, optionally with the associated
Ves
objectPlot the chosen projections of the Lens polygon.
Parameters: - Lax (list or plt.Axes) – The axes to be used for plotting (provide a list of 2 axes if Proj=’All’), if None a new figure with axes is created
- Proj (str) – Flag specifying the kind of projection used for the plot (‘Cross’ for a cross-section, ‘Hor’ for a horizontal plane, ‘All’ both and ‘3d’ for 3d)
- Elt (str) –
- Flag specifying which elements to plot, each capital letter corresponds to an element
- ‘P’: polygon
- ‘V’: vector perpendicular to the polygon, oriented towards the interior of the Vessel
- EltVes (str) – Flag specifying the elements of the Vessel to be plotted, fed to
plot()
- Leg (str) – Legend to be used to identify this LOS, if Leg=’’ the LOS name is used
- LVIn (float) – Length (in data coordinates, meters) of the vector ‘V’
- Pdict (dict) – Dictionary of properties used for plotting the polygon, fed to plt.Axes.plot() or plt.plot_surface() if Proj=‘3d’, set to ToFu_Defauts.py if None (default: None)
- Vdict (dict) – Dictionary of properties used for plotting vector ‘V’, fed to plt.Axes.plot()
- Vesdict (dict) – Dictionary of kwdargs to fed to
plot()
, and ‘EltVes’ is used instead of ‘Elt’ - LegDict (dict or None) – Dictionary of properties used for plotting the legend, fed to plt.legend(), the legend is not plotted if None
- draw (bool) – Flag indicating whether the fig.canvas.draw() shall be called automatically
- a4 (bool) – Flag indicating whether the figure should be a4 size (for printing or saving as pdf for example)
- Test (bool) – Flag indicating whether the inputs should be tested for conformity
Returns: Lax (list or plt.Axes) – Handles of the axes used for plotting (list if several axes where used)
-
plot_alone
(ax=None, V='red', nin=1.5, nout=1.0, Lmax='F', V_NP=50, src=None, draw=True, a4=False, Test=True)[source]¶ Plot a 2D representation of the Lens object, optionally with 2D viewing cone and rays of several sources in the plane, either with reduced of full representation
Plot a sketch of the Lens, optionally with ray-traced incoming light beams. This plotting routine does not consider any syurrounding and plots everything assuming the origine of the coordinate system is on the Lens
Parameters: - ax (None or plt.Axes) – Axes to be used for plotting, if None a new figure with axes is created (default: None)
- V (str) – Flag indicating whether the Lens should be considered in its reduced geometry model (‘red’) or its full version (‘full’), default: ‘red’
- nin (float) – Value of the optical index to be used inside the Lens (useful when V=’full’ only)
- nout (float) – Value of the optical index to be used outside the Lens (useful when V=’full’ only)
- Lmax (float) – Maximum length on which the source beams should be plotted after going through the Lens, if ‘F’ all beams are plotted up to the focal plane
- V_NP (int) – Number of points to be used to plot each circle fraction of the full version of the Lens geometry (useful when V=’full’ only)
- src (None or dict) –
- Dictionary of parameters for the source of ray beams:
- ‘Pt’: iterable of len()=2 with the 2D cartesian coordinates of the point where the source should be located with reference to the Lens center (0,0) and axis (1,0)
- ‘Type’: Flag indicating whether the source should a point (‘Pt’) or an array of parallel beams perpendicular to a plane passing through Pt
- ‘nn’: iterable of len()=2 with the 2D cartesian coordinates of a vector directing the array of parallel beams
- ‘NP’: int, number of beams to be plotted from the source
- draw (bool) – Flag indicating whether the fig.canvas.draw() shall be called automatically, default: True
- a4 (bool) – Flag indicating whether the figure should be a4 size (for printing or saving as pdf for example)
- Test (bool) – Flag indicating whether the inputs should be tested for conformity, default: True
Returns: ax (plt.Axes) – Handle of the axes used for plotting
-
save
(SaveName=None, Path=None, Mode='npz')[source]¶ Save the object in folder Name, under file name SaveName, using specified mode
Most tofu objects can be saved automatically as numpy arrays (.npz, recommended) at the default location (recommended) by simply calling self.save()
Parameters: - SaveName (None / str) – The name to be used for the saved file, if None (recommended) uses self.Id.SaveName
- Path (None / str) – Path specifying where to save the file, if None (recommended) uses self.Id.SavePath
- Mode (str) – Flag specifying whether to save the object as a numpy array file (‘.npz’, recommended) or an object using cPickle (not recommended, heavier and may cause retro-compatibility issues)
-
class
tofu.geom.
Apert
(Id, Poly, Type=None, Ves=None, Exp=None, Diag=None, shot=None, arrayorder='C', Clock=False, SavePath=None, dtime=None, dtimeIn=False)[source]¶ An Aperture class with all geometrical data and built-in methods, defined as a planar polygon in 3D cartesian coordinates, with optional
Ves
objectAn Apert object is useful for implementing one of the two possible optical arrangements available in tofu. An aperture is modelled as a planar polygon (of any non self-intersecting shape) through which light can pass (fully transparent) and around which light cannot pass (fully non-transparent). One of the added-values of tofu is that it allows to create several non-coplanar aperture and assign them to a single detector. It then computes automatically the volume of sight by assuming that a detectable photon should go through all apertures.
Parameters: - Id (str or tfpf.ID) – A name string or a pre-built tfpf.ID class to be used to identify this particular instance, if a string is provided, it is fed to tfpf.ID()
- Poly (np.ndarray) – An array (2,N) or (N,2) defining the contour of the aperture in 3D (X,Y,Z) cartesian coordinates, if not closed, will be closed automatically
- Ves (
Ves
) –Ves
object to which the aperture is assigned - Type (None or str) – Flag specifying the type of Apert
- Exp (None or str) – Experiment to which the Lens belongs, should be identical to Ves.Id.Exp if Ves is provided, if None and Ves is provided, Ves.Id.Exp is used
- Diag (None or str) – Diagnostic to which the Lens belongs
- shot (None or int) – Shot number from which this Lens is usable (in case its position was changed from a previous configuration)
- SavePath (None / str) – If provided, forces the default saving path of the object to the provided value
- Clock (bool) – Flag indicating whether the input polygon should be made clockwise (True) or counter-clockwise (False)
- dtime (None or dtm.datetime) – A time reference to be used to identify this particular instance (mostly used for debugging)
- dtimeIn (bool) – Flag indicating whether dtime should be included in the SaveName (mostly used for debugging)
-
BaryS
¶ Return the (surfacic) center of mass of the polygon (in 3D cartesian coordinates)
-
Id
¶ Return the associated tfpf.ID object
-
NP
¶ Return the number of points defining the polygon
-
Poly
¶ Return the planar polygon defining the aperture (in 3D cartesian coordinates)
-
Surf
¶ Return the area of the polygon
-
nIn
¶ Return the normalized vector perpendicular to the polygon surface and oriented towards the interior of the associated vessel (in 3D cartesian coordinates)
-
plot
(Lax=None, Proj='All', Elt='PV', EltVes='', Leg=None, LVIn=0.1, Pdict={'lw': 2, 'c': 'k', 'ls': 'solid'}, Vdict={'color': 'r', 'lw': 2, 'ls': 'solid'}, Vesdict={'draw': True, 'LegDict': {'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, 'BsdictHor': {'c': 'b', 'ls': 'dashed'}, 'Bvdict': {'marker': 'x', 'mew': 2, 'c': 'g', 'markersize': 8, 'ls': 'dashed'}, 'Lim': [1.5707963267948966, 6.283185307179586], 'Test': True, 'Proj': 'All', 'IdictHor': {'c': 'k', 'ls': 'dashed'}, 'Elt': 'PIBsBvV', 'Pdict': None, 'Vdict': {'color': 'r', 'scale': 10}, 'Idict': {'marker': 'x', 'mew': 2, 'c': 'k', 'markersize': 8, 'ls': 'dashed'}, 'Bsdict': {'marker': 'x', 'mew': 2, 'c': 'b', 'markersize': 8, 'ls': 'dashed'}, 'Lax': None, 'BvdictHor': {'c': 'g', 'ls': 'dashed'}, 'Nstep': 50}, LegDict={'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, draw=True, a4=False, Test=True)[source]¶ Plot the Apert, with a cross-section view, a horizontal view or both, or a 3d view, and optionally the
Ves
object associated to it.Plot the desired projections of the polygon defining the aperture.
Parameters: - list or plt.Axes (Lax) – The axes to be used for plotting (provide a list of 2 axes if Proj=’All’), if None a new figure with axes is created
- str (Leg) – Flag specifying the kind of projection used for the plot (‘Cross’ for a cross-section, ‘Hor’ for a horizontal plane, ‘All’ both and ‘3d’ for 3d)
- str –
- Flag specifying which elements to plot, each capital letter corresponds to an element
- ‘P’: polygon
- ‘V’: vector perpendicular to the polygon, oriented towards the interior of the Vessel
- str – Flag specifying the elements of the Vessel to be plotted, fed to
plot()
- str – Legend to be used to identify this LOS, if Leg=’’ the LOS name is used
- float (LVIn) – Length (in data coordinates, meters) of the vector ‘V’
- dict (Vesdict) – Dictionary of properties used for plotting the polygon, fed to plt.Axes.plot() or plt.plot_surface() if Proj=‘3d’, set to ToFu_Defauts.py if None
- dict – Dictionary of properties used for plotting vector ‘V’, fed to plt.Axes.plot()
- dict – Dictionary of kwdargs to fed to
plot()
, and ‘EltVes’ is used instead of ‘Elt’ - dict or None (LegDict) – Dictionary of properties used for plotting the legend, fed to plt.legend(), the legend is not plotted if None
- bool (Test) – Flag indicating whether the fig.canvas.draw() shall be called automatically
- bool – Flag indicating whether the figure should be a4 size (for printing or saving as pdf for example)
- bool – Flag indicating whether the inputs should be tested for conformity
Returns: La list or plt.Axes – Handles of the axes used for plotting (list if several axes where used)
-
save
(SaveName=None, Path=None, Mode='npz')[source]¶ Save the object in folder Name, under file name SaveName, using specified mode
Most tofu objects can be saved automatically as numpy arrays (.npz, recommended) at the default location (recommended) by simply calling self.save()
Parameters: - SaveName (None / str) – The name to be used for the saved file, if None (recommended) uses self.Id.SaveName
- Path (None / str) – Path specifying where to save the file, if None (recommended) uses self.Id.SavePath
- Mode (str) – Flag specifying whether to save the object as a numpy array file (‘.npz’, recommended) or an object using cPickle (not recommended, heavier and may cause retro-compatibility issues)
-
class
tofu.geom.
Detect
(Id, Poly, Optics=None, Ves=None, Sino_RefPt=None, CalcEtend=True, CalcSpanImp=True, CalcCone=True, CalcPreComp=True, Calc=True, Verb=True, Etend_Method='quad', Etend_RelErr=0.001, Etend_dX12=[0.01, 0.01], Etend_dX12Mode='rel', Etend_Ratio=0.02, Colis=True, LOSRef='Cart', Cone_DRY=0.0025, Cone_DXTheta=None, Cone_DZ=0.0025, Cone_NPsi=20, Cone_Nk=60, arrayorder='C', Clock=False, Type=None, Exp=None, Diag=None, shot=None, dtime=None, dtimeIn=False, SavePath=None)[source]¶ A Detector class with all geometrical data and built-in methods, defined as a planar polygon in 3D cartesian coordinates, with optional aperture objects
A Detect object is at the core of tofu’s added value and is mostly defined by a 3D planar polygon of any non self-intersecting shape representing the active surface of a detector. It can then be associated to optics (a
Lens
or a list ofApert
objects) and to aVes
to automatically compute a natural :class:’LOS’ (with its etendue) and, most importantly, a proper VOS (that can be discretized for 3D numerical integration). It can be 2 different types: either ‘Circ’ if it is associated to aLens
(in which case it is simply defined by radius and is assumed to be circular and placed at the focal plane of theLens
object), or None in the more general case in which it is associated to a set of apertures. Most of the commonly used quantities are automatically calculated (etendue of the LOS, VOS...) and it comes with built-in methods for plotting and computing synthetic data.To compute the VOS, tofu tests all points inside a 3D grid to see if each point is visible from the detector through the apertures or not. The meshed space is determined by the volume spanned by a LOS sampling of the VOS. Then, a contour function is used to find the polygons limiting the cross-section and horizontal projections of the VOS. Once computed, the viewing cones are assigned to attributes of the Detect instance.
In the particular case (1) when the LOS of the detector lies entirely inside one cross-section (e.g.: tomography diagnostics), tofu also computes the integral in the direction of the ignorable coordinate of the solid angle on a regular mesh (for faster computation of the geometry assuming toroidaly invariant basis functions). This regular mesh is defined in 2D, by the distance between a mesh point and the detector (k) and by the poloidal angle between the LOS and the line going from the detector to the mesh point (psi)
Parameters: - Id (str or tfpf.ID) – A name string or a pre-built tfpf.ID class to be used to identify this particular instance, if a string is provided, it is fed to tfpf.ID()
- Poly (dict or np.ndarray) –
- Contains the information regarding the geometry of the Detect object
- np.ndarray: (2,N) or (N,2) defining the contour of the detector active surface in 3D (X,Y,Z) cartesian coordinates, if not closed, will be closed automatically, if Type=None
- dict: dictionary of properties for a circular detector placed in the focal plane of a Lens on its axis, contains field ‘Rad’=float (radius), if Optics is Lens and Type=’Circ’
- Optics (list or Lens) – The optics to be associated to the detector, either a spherical
Lens
or a list of aperturesApert
- Ves (
Ves
or None) –Ves
object to which the detector is assigned - Sino_RefPt (np.ndarray or None) – Array of size=2 containing the (R,Z) (for ‘Tor’ Type) or (Y,Z) (for ‘Lin’ Type) coordinates of the reference point for the sinogram
- CalcEtend (bool) – Flag indicating whether to compute the etendue
- CalcSpanImp (bool) – Flag indicating whether to compute the maximal span of the viewing volume
- CalcCone (bool) – Flag indicating whether to compute the viewing volume or viewing cone and its two projections
- CalcPreComp (bool) – Flag indicating whether to pre-compute a set of pre-defined points inside the viewing volume for faster computation of signal from 3D emissivity
- Calc (bool) – Flag indicating whether to compute all the above
- Verb (bool) – Flag indicating whether the creation of the object should be verbose (comments for each step)
- Etend_Method (str) – Flag indicating which numerical integration to use for the computation of the etendue (picked from scipy.integrate : ‘quad’, ‘simps’, ‘trapz’)
- Etend_RelErr (float) – If Etend_Method=’quad’, specifies the maximum relative error to be tolerated on the value of the integral (i.e.: etendue)
- Etend_dX12 (list) – If Etend_Method in [‘simps’,’trapz’], which implies a discretization of the plane perpendicular to the LOS, specifies the resolution of the discretization
- Etend_dX12Mode (str) – If Etend_Method in [‘simps’,’trapz’], specifies whether Etend_dX12 should be iunderstood as an absolute distance (‘abs’) or a fraction of the maximum width (‘rel’)
- Etend_Ratio (float) – The numerical integration is performed on an automatically-deterimned interval, this ratio (fraction of unity) is a safety margin to increase a bit the interval and make sure all non-zero values are included
- Colis (bool) – Flag indicating whether the collision detection mechanism should be considered when computing the VOS
- LOSRef (str) – Key indicating which of the
LOS
in the LOS dictionary should be considered as the reference LOS - Cone_DRY (float) – Resolution of the grid in the R (for ‘Tor’ vessel types) or Y (for ‘Lin’ vessel types) direction, in meters
- Cone_DXTheta (float) – Resolution of the grid in the toroidal (for ‘Tor’ vessel types, in radians) or X (for ‘Lin’ vessel types, in meters) direction
- Cone_DZ (float) – Resolution of the grid in the Z direction, in meters
- Cone_NPsi (int) – Number of points of the regular mesh in psi direction (angle), in case (1)
- Cone_Nk (bool) – Flag indicating whether the inputs should be tested for conformity
- Type (None / str) – If the detector is associated to a
Lens
, it should be of type ‘Circ’ (only circular shaped detectors are handled by tofu behind spherical lenses) - Exp (None or str) – Experiment to which the Lens belongs, should be identical to Ves.Id.Exp if Ves is provided, if None and Ves is provided, Ves.Id.Exp is used
- Diag (None or str) – Diagnostic to which the Lens belongs
- shot (None or int) – Shot number from which this Lens is usable (in case its position was changed from a previous configuration)
- SavePath (None / str) – If provided, forces the default saving path of the object to the provided value
- Clock (bool) – Flag indicating whether the input polygon should be made clockwise (True) or counter-clockwise (False), default: False
- arrayorder (str) – Flag indicating whether the attributes of type=np.ndarray (e.g.: Poly) should be made C-contiguous (‘C’) or Fortran-contiguous (‘F’), default: ‘C’
- dtime (None or dtm.datetime) – A time reference to be used to identify this particular instance (used for debugging mostly)
- dtimeIn (bool) – Flag indicating whether dtime should be included in the SaveName (used for debugging mostly)
-
BaryS
¶ Return the (surfacic) center of mass of the polygon (in 3D cartesian coordinates)
-
Cone_PolyCross
¶ Return the polygon that is the projection in a cross-section of the viewing cone
-
Cone_PolyHor
¶ Return the polygon that is the projection in a horizontal plane of the viewing cone
-
Id
¶ Return the associated tfpf.ID object
-
NP
¶ Return the number of points defining the polygon
-
OpticsNb
¶ Return the number of associated Optics
-
OpticsType
¶ Return the type of associated Optics objects
-
Poly
¶ Return the planar polygon defining the aperture (in 3D cartesian coordinates)
-
Rad
¶ Return the radius of the polygon (if Type=’Circ’, else None)
-
SAngCross_Int
¶ Return the integral of the solid angle at pre-computed points of the VOS in a cross-section projection
-
SAngCross_Points
¶ Return the pre-computed points of the VOS in a cross-section projection
-
SAngHor_Int
¶ Return the integral of the solid angle at pre-computed points of the VOS in a horizontal projection
-
SAngHor_Points
¶ Return the pre-computed points of the VOS in a horizontal projection
-
Sino_RefPt
¶ Return the coordinates (R,Z) or (Y,Z) for Ves of Type ‘Tor’ or (Y,Z) for Ves of Type ‘Lin’ of the reference point used to compute the sinogram
-
Surf
¶ Return the area of the polygon
-
calc_Etendue_AlongLOS
(Length='', NP=20, Modes=['trapz', 'quad'], RelErr=0.001, dX12=[0.005, 0.005], dX12Mode='abs', Ratio=0.02, Colis=True, LOSRef=None, Test=True)[source]¶ Return the etendue computed at different points along the LOS, with various numerical methods, with or without collision detection
Computing the etendue along the LOS of a Detect object can be useful for checking whether the etendue is constant (as it should be if the LOS approximation is to be used). Cases with non-constant etendue include in particular partially obstructed VOS in the divertor region of Tokamaks. Also useful for debugging: if the etendue is not constant but the VOS is not obstructed, something might be wrong with the computation of the etendue or with the model (e.g.: for Lens optics). Indeed, the model implemented for a Lens is ideal, but a close look at the etendue shows that the model is not perfect (but sufficiently accurate for most uses though).
Parameters: - Length (str) – Flag indicating whether to use the full length of the VOS (including partially obstructed parts: ‘’), or just the length of the LOS unil its exit point (‘LOS’).
- NP (int) – Number of points (uniformly distributed along the LOS) where the etendue should be computed
- Modes (list or str) – Flag or list of flags indicating which numerical integration methods shoud be used in [‘quad’,’simps’,’trapz’]
- RelErr (float) – For ‘quad’, a positive float defining the relative tolerance allowed
- dX12 (list) – For ‘simps’ or ‘trapz’, a list of 2 floats defining the resolution of the sampling in X1 and X2
- dX12Mode (str) – For ‘simps’ or’trapz’, ‘rel’ or ‘abs’, if ‘rel’ the resolution dX12 is in dimensionless units in [0;1] (hence a value of 0.1 means 10 discretisation points between the extremes), if ‘abs’ dX12 is in meters
- Ratio (float) – A float specifying the relative margin to be taken for integration boundaries
- Colis (bool) – Flag indicating whether collision detection should be used
- LOSRef (None or str) – Flag indicating which LOS should be used
- Test (bool) – Flag indicating whether the inputs should be tested for conformity
Returns: - Etend (np.ndarray) – Computed etendues
- Pts (np.ndarray) – (3,NP) array specifying the 3D (X,Y,Z) coordinates of the points along the LOS where the etendue was computed
- kPts (np.ndarray) – (NP,) array of the distance-coordinate k along the LOS
- LOSRef (str) – The LOS that was used
-
calc_SAngNb
(Pts=None, Proj='Cross', Slice='Int', DRY=None, DXTheta=None, DZ=None, Colis=True)[source]¶ Compute the solid angle subtended by the Detect+Optics system as seen for desired points, in a slice or integrated manner
Mostly useful in the
GDetect
object when there are several detectors. Computes, for each point in the desired projection, the total solid angle subtended by all the detectors (or its integral) and the number of detectors that ‘see’ each point.Parameters: - Pts (None / np.ndarray) – (3,N) array of cartesian (X,Y,Z) coordinates of the provided N points, if None a default set of points is computed according to DRY, DXTheta and DZ
- Proj (str) – Flag indicating to which projection of the VOS the method should be applied
- Slice (str) – Flag indicating whether to compute the solid angle (‘Slice’), the maximum solid angle along the ignorable coordinate (‘Max’), or the integral over the ignorable coordinate (‘Int’)
- DRY (None / float) – Resolution (in horizontal direction of the cross-section) of the mesh to be constructed if the points are not provided
- DXTheta (None / float) – Resolution (in ignorable coordinate direction) of the mesh to be constructed if the points are not provided
- DZ (None / float) – Resolution (in vertical direction) of the mesh to be constructed if the points are not provided
- Colis (bool) – Flag indicating whether collision detection should be used
Returns: - SA (np.ndarray) – Array of (ND,NP) solid angle values, where ND is the number of detectors and NP the number of points
- Nb (np.ndarray) – Array of (ND,NP) booleans, True if a point is seen by a detector
- Pts (np.ndarray) – The computed points (in case they were not provided)
-
calc_SAngVect
(Pts, In='(X, Y, Z)', Colis=True, Test=True)[source]¶ Return the Solid Angle of the Detect-Apert system as seen from the specified points, including collisions detection or not
Compute the solid angle and the directing vector subtended by the Detect-Optics system as seen from the desired points (provided in the specified coordinates). This can be useful for visualizing the solid angle distribution or for computing synthetic signal from simulated emissivity in a 3D numerical integration manner. The automtic detection of collisions with the edges of the
Ves
object can be switched off (not recommended).Parameters: - Pts (np.ndarray) – (2,N) or (3,N) array of coordinates of the provided N points
- In (str) – Flag indicating in which coordinate system the Pts are provided, must be in [‘(R,Z)’,’(X,Y,Z)’,’(R,phi,Z)’]
- Colis (bool) – Flag indicating whether collision detection should be activated
- Test (bool) – Flag indicating whether the inputs should be tested for conformity
Returns: SAng (np.ndarray) – (N,) array of floats, the computed solid angles
-
calc_Sig
(ff, extargs={}, Method='Vol', Mode='simps', PreComp=True, epsrel=0.0001, dX12=[0.005, 0.005], dX12Mode='abs', ds=0.005, dsMode='abs', MarginS=0.001, Colis=True, Test=True)[source]¶ Return the signal computed from an input emissivity function, using a 3D or LOS method
The synthetic signal resulting from a simulated emissivity can be computed automatically in several ways. The user can choose between a VOS and a LOS approach (volume integration or line integration with etendue). In each case the user can choose between the numerical integration method (from scipy.integrate + np.sum()). It is possible to specify that, for a VOS approach, you want to use the pre-conputed mesh for faster computation (see
set_SigPrecomp()
). For a VOS approach, the user can specify how fine the discretization should be. The collision detection with the edges of theVes
object can be switched off (not recommended).Parameters: - ff (function) –
- Input emissiviy function, should take one input as follows:
- ff(Pts), where Points is a np.ndarray of shape=(3,N), with the (X,Y,Z) coordinates of any N number of points
- Method (str) – Flag indicating whether the spatial integration should be done with a volume (‘Vol’) or a LOS (‘LOS’) approach
- Mode (str) – Flag indicating the numerical integration method in [‘quad’,’simps’,’trapz’,’nptrapz’,’sum’]
- PreComp (bool) – Flag indicating whether the pre-computed grid should be used
- epsrel (float) – Float specifying the tolerated relative error on the numerical integration, used for ‘quad’
- dX12 (list) – Array of the 2 resolutions to be used to define the grid in a plane perpendicular to the LOS
- dX12Mode (str) – Flag specifying whether the values in dX12 are absolute distances or relative values (i.e. fraction of the total width [0;1])
- ds (float) – Float indicating the resolution in the longitudinal direction
- dsMode (str) – Flag specifying whether ds is an absolute distance or relative (i.e. fraction of the total length [0;1])
- Colis (bool) – Flag indicating whether collision detection should be used
- Test (bool) – Flag indicating whether the inputs should be tested for conformity
Returns: Sig (float) – The computed signal
- ff (function) –
-
isInside
(Points, In='(X, Y, Z)', Test=True)[source]¶ Return an array of indices indicating whether each point lies both in the cross-section and horizontal porojections of the viewing cone
Like for the
Ves
object, points can be provided in 2D or 3D coordinates (specified by ‘In’), and an array of booleans is returned.Parameters: - Points (np.ndarray) – (2,N) or (3,N) array of coordinates of the N points to be tested
- In (str) –
- Flag indicating in which coordinate system the Points are provided, must be in [‘(R,Z)’,’(Y,Z)’,’(X,Y)’,’(X,Y,Z)’,’(R,phi,Z)’]
- ‘(R,Z)’: All points are assumed to lie in the horizontal projection, for ‘Tor’ vessel type only
- ‘(Y,Z)’: All points are assumed to lie in the horizontal projection, for ‘Lin’ vessel type only
- ‘(X,Y)’: All points are assumed to lie in the cross-section projection
- Test (bool) – Flag indicating whether the inputs should be tested for conformity
Returns: ind (np.ndarray) – (N,) array of booleans with True if a point lies inside both projections of the viewing cone
-
nIn
¶ Return the normalized vector perpendicular to the polygon surface and oriented towards the interior of the associated vessel (in 3D cartesian coordinates)
-
plot
(Lax=None, Proj='All', Elt='PVC', EltLOS='LDIORP', EltOptics='P', EltVes='', Leg=None, LOSRef=None, Pdict={'lw': 2, 'c': 'k', 'ls': 'solid'}, Vdict={'color': 'r', 'lw': 2, 'ls': 'solid'}, Cdict={'edgecolors': 'k', 'antialiaseds': False, 'linestyles': '-', 'linewidths': 0.0, 'alpha': 0.2, 'facecolors': (0.8, 0.8, 0.8, 0.2)}, LVIn=0.1, LOSdict={'draw': True, 'LegDict': {'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, 'EltVes': '', 'Proj': 'All', 'Test': True, 'Elt': 'LDIORP', 'MdictP': {'c': 'k', 'markersize': 8, 'lw': 2, 'mew': 2, 'ls': 'None', 'marker': 'x'}, 'MdictR': {'c': 'k', 'markersize': 8, 'lw': 2, 'mew': 2, 'ls': 'None', 'marker': 'x'}, 'Leg': '', 'Lplot': 'Tot', 'Lax': None, 'Vesdict': {'draw': True, 'LegDict': {'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, 'BsdictHor': {'c': 'b', 'ls': 'dashed'}, 'Bvdict': {'marker': 'x', 'mew': 2, 'c': 'g', 'markersize': 8, 'ls': 'dashed'}, 'Lim': [1.5707963267948966, 6.283185307179586], 'Test': True, 'Proj': 'All', 'IdictHor': {'c': 'k', 'ls': 'dashed'}, 'Elt': 'PIBsBvV', 'Pdict': None, 'Vdict': {'color': 'r', 'scale': 10}, 'Idict': {'marker': 'x', 'mew': 2, 'c': 'k', 'markersize': 8, 'ls': 'dashed'}, 'Bsdict': {'marker': 'x', 'mew': 2, 'c': 'b', 'markersize': 8, 'ls': 'dashed'}, 'Lax': None, 'BvdictHor': {'c': 'g', 'ls': 'dashed'}, 'Nstep': 50}, 'MdictI': {'c': 'k', 'markersize': 8, 'lw': 2, 'mew': 2, 'ls': 'None', 'marker': 'x'}, 'Ldict': {'lw': 2, 'c': 'k'}, 'MdictO': {'c': 'k', 'markersize': 8, 'lw': 2, 'mew': 2, 'ls': 'None', 'marker': 'x'}, 'MdictD': {'c': 'k', 'markersize': 8, 'lw': 2, 'mew': 2, 'ls': 'None', 'marker': 'x'}}, Opticsdict={'draw': True, 'LegDict': {'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, 'Pdict': {'lw': 2, 'c': 'k', 'ls': 'solid'}, 'Vdict': {'color': 'r', 'lw': 2, 'ls': 'solid'}, 'EltVes': '', 'Leg': '', 'Lax': None, 'Vesdict': {'draw': True, 'LegDict': {'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, 'BsdictHor': {'c': 'b', 'ls': 'dashed'}, 'Bvdict': {'marker': 'x', 'mew': 2, 'c': 'g', 'markersize': 8, 'ls': 'dashed'}, 'Lim': [1.5707963267948966, 6.283185307179586], 'Test': True, 'Proj': 'All', 'IdictHor': {'c': 'k', 'ls': 'dashed'}, 'Elt': 'PIBsBvV', 'Pdict': None, 'Vdict': {'color': 'r', 'scale': 10}, 'Idict': {'marker': 'x', 'mew': 2, 'c': 'k', 'markersize': 8, 'ls': 'dashed'}, 'Bsdict': {'marker': 'x', 'mew': 2, 'c': 'b', 'markersize': 8, 'ls': 'dashed'}, 'Lax': None, 'BvdictHor': {'c': 'g', 'ls': 'dashed'}, 'Nstep': 50}, 'LVIn': 0.1, 'Test': True, 'Elt': 'PV', 'Proj': 'All'}, Vesdict={'draw': True, 'LegDict': {'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, 'BsdictHor': {'c': 'b', 'ls': 'dashed'}, 'Bvdict': {'marker': 'x', 'mew': 2, 'c': 'g', 'markersize': 8, 'ls': 'dashed'}, 'Lim': [1.5707963267948966, 6.283185307179586], 'Test': True, 'Proj': 'All', 'IdictHor': {'c': 'k', 'ls': 'dashed'}, 'Elt': 'PIBsBvV', 'Pdict': None, 'Vdict': {'color': 'r', 'scale': 10}, 'Idict': {'marker': 'x', 'mew': 2, 'c': 'k', 'markersize': 8, 'ls': 'dashed'}, 'Bsdict': {'marker': 'x', 'mew': 2, 'c': 'b', 'markersize': 8, 'ls': 'dashed'}, 'Lax': None, 'BvdictHor': {'c': 'g', 'ls': 'dashed'}, 'Nstep': 50}, LegDict={'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, draw=True, a4=False, Test=True)[source]¶ Plot the Detect instance in a projection or in 3D, its polygon, perpendicular vector, projected viewing cones and optionally its
LOS
,Apert
, andVes
objectsThe Detect instance can be plotted in a cross-section or horizontal projection, or in 3D. Several of its attributes can be plotted too using the usual ‘Elt’ keyword argument. Dedicated ‘Elt’ keyword arguments are also usable to specify the elements to be plotted for sub-classes like
LOS
,Apert
, andVes
. Dedicated dictionary help specify how each element sshould be plotted.Parameters: - Lax (None, plt.Axes or list) – Axes or list of axes to be used for plotting, if None a new figure and appropriate axes are created
- Proj (str) – Flag indicating whether to plot the cross-section (‘Cross’), the horizontal projection (‘Hor’), both (‘All’) or a 3D representation (‘3D’)
- Elt (str) –
- Flag indicating which elements of the Detect instance to plot, each capital letter stands for an element
- ‘P’: polygon
- ‘V’: perpendicular vector
- ‘C’: viewing cone
- EltLOS (None or str) – Flag indicating which elements of the LOS to plot, will be fed to LOS.plot(), if None uses the ‘Elt’ arg of LOSdict instead
- EltOptics (None or str) – Flag indicating which elements of the Aperts to plot, will be fed to Apert.plot(), if None uses the ‘Elt’ arg of Apertdict instead
- EltVes (None or str) – Flag indicating which elements of the Ves to plot, will be fed to
plot()
, if None uses the ‘Elt’ arg of Vesdict instead - Leg (str) – Legend to be used for the detector, if ‘’ the Detect.iD.Name is used
- LOSRef (None or str) – Flag indicating which LOS should be represented, if None Detect._LOSRef is used
- Pdict (dict) – Dictionary of properties for the Polygon
- Vdict (dict) – Dictionary of properties for the Vector
- Cdict (dict) – Dictionary of properties for the Cone
- LVIn (float) – Length of the Vector
- LOSdict (dict) – Dictionary of properties for the LOS if EltLOS is not ‘’, fed to LOS.plot()
- Apertdict (dict) – Dictionary of properties for the Apert if EltOptics is not ‘’, fed to Apert.plot()
- Vesdict (dict) – Dictionary of properties for the Ves if EltVes is not ‘’, fed to
plot()
- LegDict (dict) – Dictionary of properties for the legend, fed to plt.legend()
- draw (bool) – Flag indicating whether to draw the figure
- a4 (bool) – Flag indicating whether the default figure should be of size a4 paper
- Test (bool) – Flag indicating whether the inputs should be tested for conformity
Returns: Lax plt.Axes or list – Axes or list of axes used for plotting
-
plot_Etend_AlongLOS
(ax=None, NP=20, kMode='rel', Modes=['trapz'], Length='', RelErr=0.001, dX12=[0.005, 0.005], dX12Mode='abs', Ratio=0.02, LOSRef=None, LOSPts=True, Ldict={'lw': 2, 'c': 'k', 'ls': 'solid'}, LegDict={'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, Colis=True, draw=True, a4=True, Test=True)[source]¶ Plot the etendue of the selected LOS along it, with or without collision detection
The number of points along the LOS where the etendue is computed can be specified via arguments, as well as the numerical integration method. Arguments Length, NP, Modes, RelErr, dX12, dX12Mode, Ratio, Colis, LOSRef are fed to
calc_Etendue_AlongLOS()
Parameters: - ax (None or plt.Axes) – Axes to be used for plotting, if None a new figure and appropriate axes are created
- kMode (str) – Flag indicating whether the distance on the line should be plotted as abolute distance (‘abs’) or relative to the total length (‘rel’)
- Ldict (dict) – Dictionary of properties for plotting the result
- LegDict (None / dict) – If None, no legend is plotted, else LegDict is fed to :meth:’~matplotlib.pyplot.Axes.legend’
- draw (bool) – Flag indicating whether to draw the figure
- a4 (bool) – Flag indicating whether the created figure should have a4 dimensions (useful for printing)
- Test (bool) – Flag indicating whether the inputs should be tested for conformity
Returns: ax (plt.Axes) – The axes used for plotting
-
plot_SAngNb
(Lax=None, Proj='Cross', Slice='Int', Pts=None, plotfunc='scatter', DRY=None, DXTheta=None, DZ=None, Elt='P', EltVes='P', EltLOS='', EltOptics='P', Pdict={'lw': 2, 'c': 'k', 'ls': 'solid'}, Vdict={'color': 'r', 'lw': 2, 'ls': 'solid'}, Cdict={'edgecolors': 'k', 'antialiaseds': False, 'linestyles': '-', 'linewidths': 0.0, 'alpha': 0.2, 'facecolors': (0.8, 0.8, 0.8, 0.2)}, LVIn=0.1, LOSdict={'draw': True, 'LegDict': {'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, 'EltVes': '', 'Proj': 'All', 'Test': True, 'Elt': 'LDIORP', 'MdictP': {'c': 'k', 'markersize': 8, 'lw': 2, 'mew': 2, 'ls': 'None', 'marker': 'x'}, 'MdictR': {'c': 'k', 'markersize': 8, 'lw': 2, 'mew': 2, 'ls': 'None', 'marker': 'x'}, 'Leg': '', 'Lplot': 'Tot', 'Lax': None, 'Vesdict': {'draw': True, 'LegDict': {'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, 'BsdictHor': {'c': 'b', 'ls': 'dashed'}, 'Bvdict': {'marker': 'x', 'mew': 2, 'c': 'g', 'markersize': 8, 'ls': 'dashed'}, 'Lim': [1.5707963267948966, 6.283185307179586], 'Test': True, 'Proj': 'All', 'IdictHor': {'c': 'k', 'ls': 'dashed'}, 'Elt': 'PIBsBvV', 'Pdict': None, 'Vdict': {'color': 'r', 'scale': 10}, 'Idict': {'marker': 'x', 'mew': 2, 'c': 'k', 'markersize': 8, 'ls': 'dashed'}, 'Bsdict': {'marker': 'x', 'mew': 2, 'c': 'b', 'markersize': 8, 'ls': 'dashed'}, 'Lax': None, 'BvdictHor': {'c': 'g', 'ls': 'dashed'}, 'Nstep': 50}, 'MdictI': {'c': 'k', 'markersize': 8, 'lw': 2, 'mew': 2, 'ls': 'None', 'marker': 'x'}, 'Ldict': {'lw': 2, 'c': 'k'}, 'MdictO': {'c': 'k', 'markersize': 8, 'lw': 2, 'mew': 2, 'ls': 'None', 'marker': 'x'}, 'MdictD': {'c': 'k', 'markersize': 8, 'lw': 2, 'mew': 2, 'ls': 'None', 'marker': 'x'}}, Opticsdict={'draw': True, 'LegDict': {'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, 'Pdict': {'lw': 2, 'c': 'k', 'ls': 'solid'}, 'Vdict': {'color': 'r', 'lw': 2, 'ls': 'solid'}, 'EltVes': '', 'Leg': '', 'Lax': None, 'Vesdict': {'draw': True, 'LegDict': {'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, 'BsdictHor': {'c': 'b', 'ls': 'dashed'}, 'Bvdict': {'marker': 'x', 'mew': 2, 'c': 'g', 'markersize': 8, 'ls': 'dashed'}, 'Lim': [1.5707963267948966, 6.283185307179586], 'Test': True, 'Proj': 'All', 'IdictHor': {'c': 'k', 'ls': 'dashed'}, 'Elt': 'PIBsBvV', 'Pdict': None, 'Vdict': {'color': 'r', 'scale': 10}, 'Idict': {'marker': 'x', 'mew': 2, 'c': 'k', 'markersize': 8, 'ls': 'dashed'}, 'Bsdict': {'marker': 'x', 'mew': 2, 'c': 'b', 'markersize': 8, 'ls': 'dashed'}, 'Lax': None, 'BvdictHor': {'c': 'g', 'ls': 'dashed'}, 'Nstep': 50}, 'LVIn': 0.1, 'Test': True, 'Elt': 'PV', 'Proj': 'All'}, Vesdict={'draw': True, 'LegDict': {'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, 'BsdictHor': {'c': 'b', 'ls': 'dashed'}, 'Bvdict': {'marker': 'x', 'mew': 2, 'c': 'g', 'markersize': 8, 'ls': 'dashed'}, 'Lim': [1.5707963267948966, 6.283185307179586], 'Test': True, 'Proj': 'All', 'IdictHor': {'c': 'k', 'ls': 'dashed'}, 'Elt': 'PIBsBvV', 'Pdict': None, 'Vdict': {'color': 'r', 'scale': 10}, 'Idict': {'marker': 'x', 'mew': 2, 'c': 'k', 'markersize': 8, 'ls': 'dashed'}, 'Bsdict': {'marker': 'x', 'mew': 2, 'c': 'b', 'markersize': 8, 'ls': 'dashed'}, 'Lax': None, 'BvdictHor': {'c': 'g', 'ls': 'dashed'}, 'Nstep': 50}, CDictSA=None, CDictNb=None, Colis=True, a4=False, draw=True, Test=True)[source]¶ Plot the solid angle projections (integrated ‘Int’ or maximum ‘Max’) as well as the number of detectors visible from each point in the plasma
Mostly useful with the
GDetect
object, used to visualize the goemetrical coverage in terms of total solid angle and number of detectors ‘seeing’ each point for a set of detectors (seecalc_SAngNb()
method for details).Parameters: - Lax (None or list or plt.Axes) – Axes or list of Axes to be used for plotting, if None a new figure and appropriate axes are created
- Proj (str) – Flag indicating whether to plot the cross-section (‘Cross’) or the horizontal projection (‘Hor’)
- Mode (str, None or float) –
- Flag indicating whether to plot:
- ‘Int’: the integrated value along the projected coordinates
- ‘Max’: the maximum value along the projected coordinates
- float: the projected coordinate at which to plot the slice (Theta or X if Proj=’Cross’, Z if Proj=’Hor’)
- None: the slice is done in the middle of the viewing volume
- plotfunc (str) – Flag indicating which plotting method to use (‘scatter’, ‘contour’, ‘contourf’ or ‘imshow’)
- DCross (float) – Resolution along the 1st cross-section coordinate (R for Type=’Tor’, Y for Type=’Lin’)
- DXTheta (float) – Resolution along the ignorable coordinate (Theta for Type=’Tor’, X for Type=’Lin’)
- DZ (float) – Vertical resolution (for both Types)
- CDictSA (dict) – Properties of the solid angle plot, to be fed to the function chosen by plotfunc
- CDictNb (dict) – Properties of the Nb plot, to be fed to the chsoen plotting routine
- Colis (bool) – Flag indicating whether collision detection should be used
- a4 (bool) – Flag indicating whether to use a4 dimensions to create a new figure if Lax=None
- draw (bool) – Flag indicating whether to draw the figure
- Test (bool) – Flag indicating whether the inputs should be tested for conformity
Returns: Lax (plt.Axes or list) – List of the axes used for plotting
-
plot_Sinogram
(ax=None, Proj='Cross', Elt='DLV', Ang='theta', AngUnit='rad', Sketch=True, Ddict={'lw': 1, 'c': 'k', 'ls': 'solid'}, Ldict={'c': 'k', 'markersize': 8, 'lw': 2, 'mew': 2, 'ls': 'None', 'marker': 'x'}, Vdict={'edgecolor': (0.8, 0.8, 0.8, 1.0), 'linewidth': 1, 'linestyle': 'solid', 'facecolor': (0.8, 0.8, 0.8, 1.0)}, LegDict={'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, LOSRef=None, draw=True, a4=False, Test=True)[source]¶ Plot the the Detect VOS in projection space, optionally also the associated
Ves
object and reference LOSIn projection space, a VOS is a patch (as opposed to a LOS which is a point). The patch is estimated by plotting a large number of LOS sampling the VOS and taking the convex hull of the resulting points on projection space. Notice that this method results in irrelevant patches for VOS lying at the edges of the projection space. See
plot_Sinogram()
for details.Parameters: - ax (None / plt.Axes) – Axes on which to plot the Etendue, if None a default axes is created
- Proj (str) – Flag indicating whether to plot the traditional sinogram in a cross-section (‘Cross’) or a 3D sinogram (‘3d’), cannot be ‘3d’ if ‘D’ in Elt.
- Elt (str) – Flags indicating whether to plot the VOS of the Detect (‘D’ in Elt => only Proj=’Cross’), the LOS (‘L’ in Elt) and the
Ves
(‘V’ in Elt) - Ang (str) – Flag indicating which angle to use for the plot, with respect to the considered line () or to the impact parameter line ()
- AngUnit (str) – Flag indicating whether the angle should be measured in ‘rad’ or ‘deg’
- Sketch (bool) – Flag indicating whether a small sketch illustrating the definitions of angles and impact parameter should be included
- Ddict (dict) – Plotting properties of the VOS of the Detect, fed to plt.plot()
- Ldict (dict) – Plotting properties of the LOS, fed to plt.plot()
- Vdict (dict) – Plotting properties of the Ves, fed to plt.plot()
- LegDict (None / dict) – Plotting properties of the legend, if None no legend is plotted
- LOSRef (None / str) – Flag indicating which LOS to plot, if None self._LOSRef is used
- draw (bool) – Flag indicating whether to draw the figure
- a4 (bool) – Flag indicating whether the created figure should have a4 dimensions (useful for printing)
- Test (bool) – Flag indicating whether the inputs should be tested for conformity
Returns: ax (plt.Axes) – The axes used for plotting
-
refine_ConePoly
(dMax=0.02, Proj='Cross', indPoly=0, Verb=True, Test=True)[source]¶ Reduce the number of points of the selected Cone_Poly projection using the provided maximum distance and checking for convexity
Provide a built-in method to simplify the 2 projections of the viewing cone (VOS). In its raw form, the projection of the VOS is a polygon with potentially a high number of points (computed using matplotlib._cntr() function). A re-sampled version of this polygon is computed by taking its convex hull and checking, for each edge, how far it is from the original edge. Each edge (2 points) of the convex hull is then compared to the set of original edges it encloses. If the maximum distance between this convex hull-derived edge and the original set of edges is smaller than dMax, then the convex hull-derived egde is used, otherwise the original edges are preserved. The method does not return a value, instead it assigns the new polygon to a dedicated attribute of the object, thus ensuring that both the original and the re-sampled projections of the VOS are available.
Parameters: - dMax (float) – Threshold absolute distance that limits the acceptable discrepancy between the original polygon and its convex hull (checked for each edge of the convex hull)
- Proj (str) – Flag indicating to which projection of the VOS the method should be applied
- indPoly (int) – Index of the polygon to be treated (i.e.: in case one projection of the VOS results in a list of several polygons instead of just one polygon as is usually the case)
- Verb (bool) – Flag indicating whether a one-line comment should be printed at the end of the calculation giving the number of points of the new polygon vs the number of points of the original polygon
- Test (bool) – Flag indicating whether the inputs should be tested for conformity
-
save
(SaveName=None, Path=None, Mode='npz', SynthDiag=False)[source]¶ Save the object in folder Name, under file name SaveName, using specified mode
Most tofu objects can be saved automatically as numpy arrays (.npz, recommended) at the default location (recommended) by simply calling self.save() In the case of Detect and GDetect instances, there is an additional keyword argument ‘SynthDiag’ which allows to not save the pre-computed 3D mesh of the VOS for synthetic diagnostic. Indeed, this pre-computed data is often large and results in big files. Not saving it results in significantly smaller files, and it can be re-computed when loading the instance.
Parameters: - SaveName (None / str) – The name to be used for the saved file, if None (recommended) uses self.Id.SaveName
- Path (None / str) – Path specifying where to save the file, if None (recommended) uses self.Id.SavePath
- Mode (str) – Flag specifying whether to save the object as a numpy array file (‘.npz’, recommended) or an object using cPickle (not recommended, heavier and may cause retro-compatibility issues)
- SynthDiag (bool) – Flag indicating whether the pre-computed mesh for synthetic diagnostics calculations shall be saved too (can be heavy, if False, it will be re-computed when opening the saved object)
-
set_SigPrecomp
(CalcPreComp=True, dX12=None, dX12Mode=None, ds=None, dsMode=None, MarginS=None, Colis=None)[source]¶ Precompute a 3D grid for fast integration of a 3D emissivity for a synthetic diagnostic approach
In order to accelerate the computation of synthetic signal from simulated emissivity, it is possible to pre-compute a discretisation of the VOS (mesh points + solid angle) and store it as an attribute of the Detect object. While such pre-computation does speed-up significantly the numerical integration, it also burdens the object with heavy attributes that can make it too big to save. Hence, the saving method has a special argument that allows to specify that these pre-computed attributes should not be saved but should instead be re-computed automatically when loading the file. The parameters dX12, dX12Mode, ds and dsMode give the user control over how fine the discretization of the VOS should be, which affects both the accuracy of the numerical integration and the size of the resulting mesh.
Parameters: - CalcPreComp (bool) – Flag indicating whether the pre-computation should be run
- dX12 (list) – Array of the 2 resolutions to be used to define the grid in a plane perpendicular to the LOS
- dX12Mode (str) – Flag specifying whether the values in dX12 are absolute distances or relative values (i.e. fraction of the total width [0;1])
- ds (float) – Float indicating the resolution in the longitudinal direction
- dsMode (str) – Flag specifying whether ds is an absolute distance or relative (i.e. fraction of the total length [0;1])
- MarginS (float) – Float specifying
- Colis (bool) – Flag indicating whether collision detection should be used
-
class
tofu.geom.
GDetect
(Id, LDetect, Type=None, Exp=None, Diag=None, shot=None, Sino_RefPt=None, LOSRef=None, arrayorder='C', Clock=False, dtime=None, dtimeIn=False, SavePath=None)[source]¶ An object grouping a list of
Detect
objects with some common features (e.g.: all belong to the same camera) and the sameVes
object, provides methods for common computing and plottingA GDetect object is a convenient tool for managing groups of detectors, applying common treatment, plotting... It is typically suited for a camera (e.g.: a group of detectors sharing a common aperture)
Parameters: - Id (str or tfpf.ID) – A name string or a pre-built tfpf.ID class to be used to identify this particular instance, if a string is provided, it is fed to
ID
- LDetect (list or Detect) – List of Detect instances with the same
Ves
instance - Type (None) – Not used in the current verion of tofu
- Exp (None or str) – Experiment to which the Lens belongs, should be identical to Ves.Id.Exp if Ves is provided, if None and Ves is provided, Ves.Id.Exp is used
- Diag (None or str) – Diagnostic to which the Lens belongs
- shot (None or int) – Shot number from which this Lens is usable (in case its position was changed from a previous configuration)
- SavePath (None / str) – If provided, forces the default saving path of the object to the provided value
- Sino_RefPt (None or iterable) – If provided, forces the common
Sino_RefPt
to the provided value for allDetect
instances - arrayorder (str) – Flag indicating whether the attributes of type=np.ndarray (e.g.: Poly) should be made C-contiguous (‘C’) or Fortran-contiguous (‘F’)
- dtime (None or dtm.datetime) – A time reference to be used to identify this particular instance (used for debugging mostly)
- dtimeIn (bool) – Flag indicating whether dtime should be included in the SaveName (used for debugging mostly)
-
Id
¶ the associated tfpf.ID object
-
Sino_RefPt
¶ Return the coordinates (R,Z) or (Y,Z) for Ves of Type ‘Tor’ or (Y,Z) for Ves of Type ‘Lin’ of the reference point used to compute the sinogram
-
calc_SAngVect
(Pts, In='(X, Y, Z)', Colis=True, Test=True)[source]¶ Applies
calc_SAngVect()
to allDetect
instancesReturn the result as two 2D arrays where the first dimension is the number of
Detect
instances seecalc_SAngVect()
for details
-
calc_Sig
(ff, extargs={}, Method='Vol', Mode='simps', PreComp=True, epsrel=0.0001, dX12=[0.005, 0.005], dX12Mode='abs', ds=0.005, dsMode='abs', MarginS=0.001, Colis=True, Test=True, ind=None, Val=None, Crit='Name', PreExp=None, PostExp=None, Log='any', InOut='In')[source]¶ Applies
calc_Sig()
to allDetect
instancesSee
calc_Sig()
for details Arguments ind, Val, Crit, PreExp, PostExp, Log and InOut are fed toselect()
-
get_GLOS
(Name=None, LOSRef=None)[source]¶ Return the
GLOS
instance that can be built by grouping theLOS
of eachDetect
instanceCan be useful for handling a GLOS instead of a GDetect (heavier) instance
Parameters: - Name (None / str) – Name to be given to the GLOS instance, if None a name is built from the name of the GDetect object by appending ‘_GLOS’
- LOSRef (None / str) – Key indicating which LOS to be used, if None the default LOSRef is used
Returns:
-
isInside
(Points, In='(X, Y, Z)', Test=True)[source]¶ Return an array of indices indicating whether each point lies both in the cross-section and horizontal porojections of the viewing cone of each
Detect
see
isInside()
for detailsParameters: - Points (np.ndarray) – (2,N) or (3,N) array of coordinates of the N points to be tested
- In (str) –
- Flag indicating in which coordinate system the Points are provided, must be in [‘(R,Z)’,’(Y,Z)’,’(X,Y)’,’(X,Y,Z)’,’(R,phi,Z)’]
- ‘(R,Z)’: All points are assumed to lie in the horizontal projection, for ‘Tor’ vessel type only
- ‘(Y,Z)’: All points are assumed to lie in the horizontal projection, for ‘Lin’ vessel type only
- ‘(X,Y)’: All points are assumed to lie in the cross-section projection
- Test (bool) – Flag indicating whether the inputs should be tested for conformity
Returns: ind (np.ndarray) – (ND,N) array of booleans with True if a point lies inside both projections of the viewing cone, where ND is the number of Detect instances
-
plot
(Lax=None, Proj='All', Elt='PVC', EltLOS='LDIORP', EltOptics='P', EltVes='', Leg=None, LOSRef=None, Pdict={'lw': 2, 'c': 'k', 'ls': 'solid'}, Vdict={'color': 'r', 'lw': 2, 'ls': 'solid'}, Cdict={'edgecolors': 'k', 'antialiaseds': False, 'linestyles': '-', 'linewidths': 0.0, 'alpha': 0.2, 'facecolors': (0.8, 0.8, 0.8, 0.2)}, LVIn=0.1, LOSdict={'draw': True, 'LegDict': {'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, 'EltVes': '', 'Proj': 'All', 'Test': True, 'Elt': 'LDIORP', 'MdictP': {'c': 'k', 'markersize': 8, 'lw': 2, 'mew': 2, 'ls': 'None', 'marker': 'x'}, 'MdictR': {'c': 'k', 'markersize': 8, 'lw': 2, 'mew': 2, 'ls': 'None', 'marker': 'x'}, 'Leg': '', 'Lplot': 'Tot', 'Lax': None, 'Vesdict': {'draw': True, 'LegDict': {'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, 'BsdictHor': {'c': 'b', 'ls': 'dashed'}, 'Bvdict': {'marker': 'x', 'mew': 2, 'c': 'g', 'markersize': 8, 'ls': 'dashed'}, 'Lim': [1.5707963267948966, 6.283185307179586], 'Test': True, 'Proj': 'All', 'IdictHor': {'c': 'k', 'ls': 'dashed'}, 'Elt': 'PIBsBvV', 'Pdict': None, 'Vdict': {'color': 'r', 'scale': 10}, 'Idict': {'marker': 'x', 'mew': 2, 'c': 'k', 'markersize': 8, 'ls': 'dashed'}, 'Bsdict': {'marker': 'x', 'mew': 2, 'c': 'b', 'markersize': 8, 'ls': 'dashed'}, 'Lax': None, 'BvdictHor': {'c': 'g', 'ls': 'dashed'}, 'Nstep': 50}, 'MdictI': {'c': 'k', 'markersize': 8, 'lw': 2, 'mew': 2, 'ls': 'None', 'marker': 'x'}, 'Ldict': {'lw': 2, 'c': 'k'}, 'MdictO': {'c': 'k', 'markersize': 8, 'lw': 2, 'mew': 2, 'ls': 'None', 'marker': 'x'}, 'MdictD': {'c': 'k', 'markersize': 8, 'lw': 2, 'mew': 2, 'ls': 'None', 'marker': 'x'}}, Opticsdict={'draw': True, 'LegDict': {'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, 'Pdict': {'lw': 2, 'c': 'k', 'ls': 'solid'}, 'Vdict': {'color': 'r', 'lw': 2, 'ls': 'solid'}, 'EltVes': '', 'Leg': '', 'Lax': None, 'Vesdict': {'draw': True, 'LegDict': {'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, 'BsdictHor': {'c': 'b', 'ls': 'dashed'}, 'Bvdict': {'marker': 'x', 'mew': 2, 'c': 'g', 'markersize': 8, 'ls': 'dashed'}, 'Lim': [1.5707963267948966, 6.283185307179586], 'Test': True, 'Proj': 'All', 'IdictHor': {'c': 'k', 'ls': 'dashed'}, 'Elt': 'PIBsBvV', 'Pdict': None, 'Vdict': {'color': 'r', 'scale': 10}, 'Idict': {'marker': 'x', 'mew': 2, 'c': 'k', 'markersize': 8, 'ls': 'dashed'}, 'Bsdict': {'marker': 'x', 'mew': 2, 'c': 'b', 'markersize': 8, 'ls': 'dashed'}, 'Lax': None, 'BvdictHor': {'c': 'g', 'ls': 'dashed'}, 'Nstep': 50}, 'LVIn': 0.1, 'Test': True, 'Elt': 'PV', 'Proj': 'All'}, Vesdict={'draw': True, 'LegDict': {'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, 'BsdictHor': {'c': 'b', 'ls': 'dashed'}, 'Bvdict': {'marker': 'x', 'mew': 2, 'c': 'g', 'markersize': 8, 'ls': 'dashed'}, 'Lim': [1.5707963267948966, 6.283185307179586], 'Test': True, 'Proj': 'All', 'IdictHor': {'c': 'k', 'ls': 'dashed'}, 'Elt': 'PIBsBvV', 'Pdict': None, 'Vdict': {'color': 'r', 'scale': 10}, 'Idict': {'marker': 'x', 'mew': 2, 'c': 'k', 'markersize': 8, 'ls': 'dashed'}, 'Bsdict': {'marker': 'x', 'mew': 2, 'c': 'b', 'markersize': 8, 'ls': 'dashed'}, 'Lax': None, 'BvdictHor': {'c': 'g', 'ls': 'dashed'}, 'Nstep': 50}, LegDict={'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, draw=True, a4=False, Test=True, ind=None, Val=None, Crit='Name', PreExp=None, PostExp=None, Log='any', InOut='In')[source]¶ Plot all or a subset of the Detect instances in a projection or in 3D
See
plot()
for details Arguments ind, Val, Crit, PreExp, PostExp, Log and InOut are fed toselect()
Parameters: - Lax (None, plt.Axes or list) – Axes or list of axes to be used for plotting, if None a new figure and appropriate axes are created
- Proj (str) – Flag indicating whether to plot the cross-section (‘Cross’), the horizontal projection (‘Hor’), both (‘All’) or a 3D representation (‘3D’)
- Elt (str) –
- Flag indicating which elements of the Detect instance to plot, each capital letter stands for an element
- ‘P’: polygon
- ‘V’: perpendicular vector
- ‘C’: viewing cone
- EltLOS (None or str) – Flag indicating which elements of the LOS to plot, will be fed to LOS.plot(), if None uses the ‘Elt’ arg of LOSdict instead
- EltOptics (None or str) – Flag indicating which elements of the Aperts to plot, will be fed to Apert.plot(), if None uses the ‘Elt’ arg of Apertdict instead
- EltVes (None or str) – Flag indicating which elements of the
Ves
to plot, will be fed toplot()
, if None uses the ‘Elt’ arg of Vesdict instead - Leg (str) – Legend to be used for the detector, if ‘’ the Detect.iD.Name is used
- LOSRef (None or str) – Flag indicating which LOS should be represented, if None Detect._LOSRef is used
- Pdict (dict) – Dictionary of properties for the Polygon
- Vdict (dict) – Dictionary of properties for the Vector
- Cdict (dict) – Dictionary of properties for the Cone
- LVIn (float) – Length of the Vector
- LOSdict (dict) – Dictionary of properties for the LOS if EltLOS is not ‘’, fed to LOS.plot()
- Apertdict (dict) – Dictionary of properties for the Apert if EltOptics is not ‘’, fed to Apert.plot()
- Vesdict (dict) – Dictionary of properties for the
Ves
if EltVes is not ‘’, fed toplot()
- LegDict (dict) – Dictionary of properties for the legend, fed to plt.legend()
- draw (bool) – Flag indicating whether to draw the figure
- a4 (bool) – Flag indicating whether the default figure should be of size a4 paper
- Test (bool) – Flag indicating whether the inputs should be tested for conformity
Returns: Lax plt.Axes or list – Axes or list of axes used for plotting
-
plot_Etend_AlongLOS
(ax=None, NP=20, kMode='rel', Modes=['trapz'], RelErr=None, dX12=None, dX12Mode=None, Ratio=None, LOSRef=None, LOSPts=True, Ldict={'lw': 2, 'c': 'k', 'ls': 'solid'}, LegDict={'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, Colis=True, draw=True, a4=True, Test=True, ind=None, Val=None, Crit='Name', PreExp=None, PostExp=None, Log='any', InOut='In')[source]¶ Plot the etendue of the selected LOS along it, with or without collision detection
The number of points along the LOS where the etendue is computed can be specified via arguments, as well as the numerical integration method. See
plot_Etendue_AlongLOS()
for details Arguments Length, NP, Modes, RelErr, dX12, dX12Mode, Ratio, Colis, LOSRef are fed tocalc_Etendue_AlongLOS()
Arguments ind, Val, Crit, PreExp, PostExp, Log and InOut are fed toselect()
Parameters: - ax (None or plt.Axes) – Axes to be used for plotting, if None a new figure and appropriate axes are created
- NP (int) – Number of points along the LOS at which the Etendue should be computed
- kMode (str) – Flag indicating whether the distance on the line should be plotted as abolute distance (‘abs’) or relative to the total length (‘rel’)
- Modes (str or list) – Flag or list of flags indicating which integration method should be used
- Colis (bool) – Flag indicating whether collision detection should be used
- LOSRef (None or str) – Flag indicating which LOS should be used
- Ldict (dict) – Dictionary of properties for plotting the result
- LegDict (None / dict) – If None, no legend is plotted, else LegDict is fed to :meth:’~matplotlib.pyplot.Axes.legend’
- draw (bool) – Flag indicating whether to draw the figure
- a4 (bool) – Flag indicating whether the created figure should have a4 dimensions (useful for printing)
- Test (bool) – Flag indicating whether the inputs should be tested for conformity
Returns: ax (plt.Axes) – The axes used for plotting
-
plot_Etendues
(Mode='Etend', Elt='', ax=None, Adict={'marker': '+', 'lw': 2, 'c': 'k', 'ls': 'None'}, Rdict={'marker': 'x', 'lw': 2, 'c': 'b', 'ls': 'None'}, Edict={'marker': 'o', 'lw': 2, 'c': 'g', 'ls': 'None'}, LegDict={'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, draw=True, a4=False, Test=True, ind=None, Val=None, Crit='Name', PreExp=None, PostExp=None, Log='any', InOut='In')[source]¶ Plot the etendues of all or a subset of the
Detect
instances for the chosenLOS
A given Detect+Optics system has a VOS, under proper conditions, this VOS can be approximated by a LOS, but the choice of the LOS is not unique, there is an infinite number of possible LOS in a single VOS. The LOS automatically computed by tofu os the ‘natural’ option : goes from the midlle of the Detect area throught the middle of the optics. Then tofu automatically computes the associated etendue. This methods plots all the etendues of all the chosen
Detect
instances for the chosenLOS
, which is by default the ‘natural’ LOS computed by tofuParameters: - Mode (str) – Flasg indicating whether to plot the etendue (‘Etend’) or a geometrical calibration factor (‘Calib’) computed as the 4pi/etendue
- Elt (str) – Flag indicating whether to plot, in addition to the etendue, also the direct (‘A’) and reverse (‘R’) 0-order approximation of the etendue
- ax (None or plt.Axes) – Axes to be used for plotting, if None a new figure and appropriate axes are created
- Adict (dict) – Dictionary of properties for plotting the direct 0-order approximation of the etendue (if ‘A’ in Elt), fed to
plot()
- Rdict (dict) – Dictionary of properties for plotting the reverse 0-order approximation of the etendue (if ‘R’ in Elt), fed to
plot()
- Edict (dict) – Dictionary of properties for plotting the etendue, fed to
plot()
- LegDict (dict) – If None, no legend is plotted, else LegDict is fed to :meth:’~matplotlib.pyplot.Axes.legend’
- draw (bool) – Flag indicating whether to draw the figure
- a4 (bool) – Flag indicating whether the created figure should have a4 dimensions (useful for printing)
- Test (bool) – Flag indicating whether the inputs should be tested for conformity
Returns: ax (plt.Axes) – The axes used for plotting
-
plot_SAngNb
(Lax=None, Proj='Cross', Slice='Int', Pts=None, plotfunc='scatter', DRY=None, DXTheta=None, DZ=None, Elt='P', EltVes='P', EltLOS='', EltOptics='P', Pdict={'lw': 2, 'c': 'k', 'ls': 'solid'}, Vdict={'color': 'r', 'lw': 2, 'ls': 'solid'}, Cdict={'edgecolors': 'k', 'antialiaseds': False, 'linestyles': '-', 'linewidths': 0.0, 'alpha': 0.2, 'facecolors': (0.8, 0.8, 0.8, 0.2)}, LVIn=0.1, LOSdict={'draw': True, 'LegDict': {'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, 'EltVes': '', 'Proj': 'All', 'Test': True, 'Elt': 'LDIORP', 'MdictP': {'c': 'k', 'markersize': 8, 'lw': 2, 'mew': 2, 'ls': 'None', 'marker': 'x'}, 'MdictR': {'c': 'k', 'markersize': 8, 'lw': 2, 'mew': 2, 'ls': 'None', 'marker': 'x'}, 'Leg': '', 'Lplot': 'Tot', 'Lax': None, 'Vesdict': {'draw': True, 'LegDict': {'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, 'BsdictHor': {'c': 'b', 'ls': 'dashed'}, 'Bvdict': {'marker': 'x', 'mew': 2, 'c': 'g', 'markersize': 8, 'ls': 'dashed'}, 'Lim': [1.5707963267948966, 6.283185307179586], 'Test': True, 'Proj': 'All', 'IdictHor': {'c': 'k', 'ls': 'dashed'}, 'Elt': 'PIBsBvV', 'Pdict': None, 'Vdict': {'color': 'r', 'scale': 10}, 'Idict': {'marker': 'x', 'mew': 2, 'c': 'k', 'markersize': 8, 'ls': 'dashed'}, 'Bsdict': {'marker': 'x', 'mew': 2, 'c': 'b', 'markersize': 8, 'ls': 'dashed'}, 'Lax': None, 'BvdictHor': {'c': 'g', 'ls': 'dashed'}, 'Nstep': 50}, 'MdictI': {'c': 'k', 'markersize': 8, 'lw': 2, 'mew': 2, 'ls': 'None', 'marker': 'x'}, 'Ldict': {'lw': 2, 'c': 'k'}, 'MdictO': {'c': 'k', 'markersize': 8, 'lw': 2, 'mew': 2, 'ls': 'None', 'marker': 'x'}, 'MdictD': {'c': 'k', 'markersize': 8, 'lw': 2, 'mew': 2, 'ls': 'None', 'marker': 'x'}}, Opticsdict={'draw': True, 'LegDict': {'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, 'Pdict': {'lw': 2, 'c': 'k', 'ls': 'solid'}, 'Vdict': {'color': 'r', 'lw': 2, 'ls': 'solid'}, 'EltVes': '', 'Leg': '', 'Lax': None, 'Vesdict': {'draw': True, 'LegDict': {'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, 'BsdictHor': {'c': 'b', 'ls': 'dashed'}, 'Bvdict': {'marker': 'x', 'mew': 2, 'c': 'g', 'markersize': 8, 'ls': 'dashed'}, 'Lim': [1.5707963267948966, 6.283185307179586], 'Test': True, 'Proj': 'All', 'IdictHor': {'c': 'k', 'ls': 'dashed'}, 'Elt': 'PIBsBvV', 'Pdict': None, 'Vdict': {'color': 'r', 'scale': 10}, 'Idict': {'marker': 'x', 'mew': 2, 'c': 'k', 'markersize': 8, 'ls': 'dashed'}, 'Bsdict': {'marker': 'x', 'mew': 2, 'c': 'b', 'markersize': 8, 'ls': 'dashed'}, 'Lax': None, 'BvdictHor': {'c': 'g', 'ls': 'dashed'}, 'Nstep': 50}, 'LVIn': 0.1, 'Test': True, 'Elt': 'PV', 'Proj': 'All'}, Vesdict={'draw': True, 'LegDict': {'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, 'BsdictHor': {'c': 'b', 'ls': 'dashed'}, 'Bvdict': {'marker': 'x', 'mew': 2, 'c': 'g', 'markersize': 8, 'ls': 'dashed'}, 'Lim': [1.5707963267948966, 6.283185307179586], 'Test': True, 'Proj': 'All', 'IdictHor': {'c': 'k', 'ls': 'dashed'}, 'Elt': 'PIBsBvV', 'Pdict': None, 'Vdict': {'color': 'r', 'scale': 10}, 'Idict': {'marker': 'x', 'mew': 2, 'c': 'k', 'markersize': 8, 'ls': 'dashed'}, 'Bsdict': {'marker': 'x', 'mew': 2, 'c': 'b', 'markersize': 8, 'ls': 'dashed'}, 'Lax': None, 'BvdictHor': {'c': 'g', 'ls': 'dashed'}, 'Nstep': 50}, CDictSA=None, CDictNb=None, Colis=True, a4=False, draw=True, Test=True, ind=None, Val=None, Crit='Name', PreExp=None, PostExp=None, Log='any', InOut='In')[source]¶ Plot the solid angle projections (integrated ‘Int’ or maximum ‘Max’) as well as the number of detectors visible from each point in the plasma
See
plot_SAngNb()
for details Arguments ind, Val, Crit, PreExp, PostExp, Log and InOut are fed toselect()
Parameters: - Lax (None or list or plt.Axes) – Axes or list of Axes to be used for plotting, if None a new figure and appropriate axes are created
- Proj (str) – Flag indicating whether to plot the cross-section (‘Cross’) or the horizontal projection (‘Hor’)
- Mode (str, None or float) –
- Flag indicating whether to plot:
- ‘Int’: the integrated value along the projected coordinates
- ‘Max’: the maximum value along the projected coordinates
- float: the projected coordinate at which to plot the slice (Theta or X if Proj=’Cross’, Z if Proj=’Hor’)
- None: the slice is done in the middle of the viewing volume
- plotfunc (str) – Flag indicating which plotting method to use (‘scatter’, ‘contour’, ‘contourf’ or ‘imshow’)
- DCross (float) – Resolution along the 1st cross-section coordinate (R for Type=’Tor’, Y for Type=’Lin’)
- DXTheta (float) – Resolution along the ignorable coordinate (Theta for Type=’Tor’, X for Type=’Lin’)
- DZ (float) – Vertical resolution (for both Types)
- CDictSA (dict) – Properties of the solid angle plot, to be fed to the function chosen by plotfunc
- CDictNb (dict) – Properties of the Nb plot, to be fed to ...
- Colis (bool) – Flag indicating whether collision detection should be used
- a4 (bool) – Flag indicating whether to use a4 dimensions to create a new figure if Lax=None
- draw (bool) – Flag indicating whether to draw the figure
- Test (bool) – Flag indicating whether the inputs should be tested for conformity
Returns: Lax plt.Axes or list List of the axes used for plotting
-
plot_Sig
(ffSig, extargs={}, Method='Vol', Mode='simps', ax=None, Leg='', Sdict={'marker': '+', 'lw': 2, 'c': 'k', 'ls': 'solid'}, LegDict={'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, draw=True, a4=False, Test=True, PreComp=True, epsrel=0.0001, dX12=[0.005, 0.005], dX12Mode='abs', ds=0.005, dsMode='abs', MarginS=0.001, Colis=True, ind=None, Val=None, Crit='Name', PreExp=None, PostExp=None, Log='any', InOut='In')[source]¶ Plot the ignal computed for each or a subset of the
Detect
instancesIf the signal is not directly provided as an array, it is computed from a function. If ffSig is a callable function, arguments ffSig, extargs, Method, Mode, PreComp, epsrel, dX12, dX12Mode, ds, dsMode, MarginS, Colis and Test are fed to
calc_Sig()
Arguments ind, Val, Crit, PreExp, PostExp, Log and InOut are fed toselect()
Parameters: - np.ndarray or callable (ffSig) – Either a np.ndarray containing the signal to be plotted (of shape (ND,) or (N,ND) where ND is the number of detectors to be plotted) or a callable to be fed to for computing the signal
- ax (None or plt.Axes) – Axes to be used for plotting, if None a new figure and appropriate axes are created
- Sdict (dict) – Dictionary of properties for plotting the signal, fed to
plot()
- Leg (str) – Label to be used for the plot
- LegDict (dict) – If None, no legend is plotted, else LegDict is fed to :meth:’~matplotlib.pyplot.Axes.legend’
- draw (bool) – Flag indicating whether to draw the figure
- a4 (bool) – Flag indicating whether the created figure should have a4 dimensions (useful for printing)
- Test (bool) – Flag indicating whether the inputs should be tested for conformity
Returns: ax (plt.Axes) – The axes used for plotting
-
plot_Sinogram
(ax=None, Proj='Cross', Elt='DLV', Ang='theta', AngUnit='rad', Sketch=True, Ddict={'lw': 1, 'c': 'k', 'ls': 'solid'}, Ldict={'c': 'k', 'markersize': 8, 'lw': 2, 'mew': 2, 'ls': 'None', 'marker': 'x'}, Vdict={'edgecolor': (0.8, 0.8, 0.8, 1.0), 'linewidth': 1, 'linestyle': 'solid', 'facecolor': (0.8, 0.8, 0.8, 1.0)}, LegDict={'loc': 2, 'bbox_to_anchor': (1.01, 1), 'prop': {'size': 10}, 'ncol': 1, 'borderaxespad': 0.0, 'frameon': False}, LOSRef=None, draw=True, a4=False, Test=True, ind=None, Val=None, Crit='Name', PreExp=None, PostExp=None, Log='any', InOut='In')[source]¶ Plot the VOS of all or of a subset of the
Detect
instances in projection space, optionally also the associatedVes
object and referenceLOS
See
plot_Sinogram()
for details Arguments ind, Val, Crit, PreExp, PostExp, Log and InOut are fed toselect()
-
save
(SaveName=None, Path=None, Mode='npz', SynthDiag=False)[source]¶ Save the object in folder Name, under file name SaveName, using specified mode
Most tofu objects can be saved automatically as numpy arrays (.npz, recommended) at the default location (recommended) by simply calling self.save() In the case of Detect and GDetect instances, there is an additional keyword argument ‘SynthDiag’ which allows to not save the pre-computed 3D mesh of the VOS for synthetic diagnostic. Indeed, this pre-computed data is often large and results in big files. Not saving it results in significantly smaller files, and it can be re-computed when loading the instance.
Parameters: - SaveName (None / str) – The name to be used for the saved file, if None (recommended) uses self.Id.SaveName
- Path (None / str) – Path specifying where to save the file, if None (recommended) uses self.Id.SavePath
- Mode (str) – Flag specifying whether to save the object as a numpy array file (‘.npz’, recommended) or an object using cPickle (not recommended, heavier and may cause retro-compatibility issues)
- SynthDiag (bool) – Flag indicating whether the pre-computed mesh for synthetic diagnostics calculations shall be saved too (can be heavy, if False, it will be re-computed when opening the saved object)
-
select
(Val=None, Crit='Name', PreExp=None, PostExp=None, Log='any', InOut='In', Out=<type 'bool'>)[source]¶ Return the indices or instances of all instances matching the specified criterion.
The selection can be done according to 2 different mechanism (1) and (2).
For mechanism (1): the user provides the value (Val) that the specified criterion (Crit) should take for a
tofu.geom.Detect
to be selected. The criteria are typically attributes of the self.Id attribute (i.e.: name of the instance, or user-defined attributes like the camera head...)For mechanism (2), used if Val=None: the user provides a str expression (or a list of such) to be fed to eval(), used to check on quantitative criteria, placed before the criterion value (e.g.: ‘not ‘ or ‘<=’). Another str or list of str expressions can be provided that will be placed after the criterion value.
Other parameters are used to specify logical operators for the selection (match any or all the criterion...) and the type of output. See
select()
for examplesParameters: - Crit (str) – Flag indicating which criterion to use for discrimination Can be set to any attribute of the tofu.pathfile.ID class (e.g.: ‘Name’,’SaveName’,’SavePath’...) or any key of ID.USRdict (e.g.: ‘Exp’...)
- Val (list, str or None) – The value to match for the chosen criterion, can be a list of different values Used for selection mechanism (1)
- PreExp (list, str or None) – A str of list of str expressions to be fed to eval(), used to check on quantitative criteria, placed before the criterion value (e.g.: ‘not ‘) Used for selection mechanism (2)
- PostExp (list, str or None) – A str of list of str expressions to be fed to eval(), used to check on quantitative criteria, placed after the criterion value (e.g.: ‘>=5.’) Used for selection mechanism (2)
- Log (str) – Flag indicating whether the criterion shall match all provided values or one of them (‘any’ or ‘all’)
- InOut (str) – Flag indicating whether the returned indices are the ones matching the criterion (‘In’) or the ones not matching it (‘Out’)
- Out (type / str) – Flag indicating in which form shall the result be returned, as an array of integer indices (int), an array of booleans (bool), a list of names (‘Names’) or a list of instances (‘Detect’)
Returns: ind (list / np.ndarray) – The computed output (array of index, list of names or instances depending on parameter ‘Out’)
-
set_SigPrecomp
(CalcPreComp=True, dX12=[0.005, 0.005], dX12Mode='abs', ds=0.005, dsMode='abs', MarginS=0.001, Colis=True)[source]¶ Applies
set_SigPrecomp()
to allDetect
instances
- Id (str or tfpf.ID) – A name string or a pre-built tfpf.ID class to be used to identify this particular instance, if a string is provided, it is fed to
-
tofu.plugins.AUG.SXR.geom.
create
(shot=0, VesName='V1', SavePathObj=None, RootpluginElt='/afs/ipp-garching.mpg.de/home/d/didiv/Python/tofu/tofu/plugins/AUG/SXR/geom', forceshot=False, overwrite=False, save=True, CamHeads=['F', 'G', 'H1', 'H2', 'H3', 'I1', 'I2', 'I3', 'J1', 'J2', 'J3', 'K1', 'K2', 'L', 'M'], dtime=None, dtFormat='D%Y%m%d_T%H%M%S', CalcEtend=True, CalcSpanImp=True, CalcCone=True, CalcPreComp=True, Calc=True, Verb=True, Etend_Method='quad', Etend_RelErr=0.001, Etend_dX12=[0.01, 0.01], Etend_dX12Mode='rel', Etend_Ratio=0.02, Colis=True, LOSRef='Cart', Cone_DRY=0.0025, Cone_DXTheta=0.0030679615757712823, Cone_DZ=0.0025, Cone_NPsi=20, Cone_Nk=60)[source]¶ Create the tfg.GDetect objects (i.e.: the cameras, which are groups of detectors) from geometry taken from CSX disgnostic for the proposed shot or earlier (looks for the oldest version of the matching geometry) and stores them in the SavePathObj
Parameters: - shot (int) – Shot number for which to build the geometry
- VesName (str) – Name of the tfg.Ves object to be fed as an input to the tfg.GDetect objects
- SavePathObj (None / str) – Absolute path where the created tfg.GDetect objects should be saved (if save=True), if None the default is used
- RootpluginElt (str) – If SavePathObj=None, a default value is created by appending ‘/Objects/’ to RootpluginElt
- forceshot (bool) – Flag indicating whether the shot number shall be downgraded to the oldest shot with the same geometry (False) or whether the provided shot number shall be enforced (True, for all camera heads)
- overwrite (bool) – Flag indicating whether new tfg.GDetect objects shall be computed (and possibly saved) when similar ones already exist (True)
- save (bool) – Flag indicating whether to save the created tfg.GDetect objects (in SavePathObj)
- dtime (None / dtm.datetime) – If provided (i.e.: not None), used as a label of the created tfg.GDetect objects (mostly used for debugging)
- dtFormat (str) – The time format to be used for labelling the created tfg.GDetect objects (mostly used for debugging)
:param All other arguments are fed to
Detect
:Returns: LGD (list) – A list of all the created tfg.GDetect objects
-
tofu.plugins.AUG.SXR.geom.
load
(Cams=[], shot=inf, SavePathObj=None, RootpluginElt='/afs/ipp-garching.mpg.de/home/d/didiv/Python/tofu/tofu/plugins/AUG/SXR/geom', sort=False)[source]¶ Load and return the desired tfg.GDetect objects (i.e.: camera heads)
Parameters: - Cams (list / tfg.GDetect) – A name or a list of names of the camera heads to be loaded (available are [‘F’,’G’,’H1’,’H2’,’H3’,’I1’,’I2’,’I3’,’J1’,’J2’,’J3’,’K1’,’K2’,’L’,’M’])
- shot (int / float / np.float) – A shot number indicating which version of the geometry should be loaded (the )
- SavePathObj (None / str) – Absolute path where the created tfg.GDetect objects should be saved (if save=True), if None the default is used
- RootpluginElt (str) – If SavePathObj=None, a default value is created by appending ‘/Objects/’ to RootpluginElt
- sort (bool) – Flag indicating whether the loaded GDetect objects shall be returned sorted by alphabetical order of the names (True) or in the same order as asked in Cams (False)
- Returns –
- -------- –
- Cams – The loaded tfg.GDetect objects, returned as a single object if Cams was provided as a single name, as a list otherwise