Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,14 +395,18 @@ def get_version_tofu(path=_HERE):
# installing-additional-files # noqa
# In this case, 'data_file' will be installed into '<sys.prefix>/my_data'
# data_files=[('my_data', ['data/data_file'])],

# To provide executable scripts, use entry points in preference to the
# "scripts" keyword. Entry points provide cross-platform support and allow
# pip to create the appropriate form of executable for the target platform.
# entry_points={
# 'console_scripts': [
# 'sample=sample:main',
# ],
# },
entry_points={
'console_scripts': [
'tofuplot=tofu.scripts.tofuplot:main',
'tofucalc=tofu.scripts.tofucalc:main',
],
},

# Extensions and commands
ext_modules=extensions,
cmdclass={"build_ext": build_ext,
"clean": CleanCommand},
Expand Down
67 changes: 40 additions & 27 deletions tofu/geom/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3594,7 +3594,7 @@ def __init__(self, dgeom=None, lOptics=None, Etendues=None, Surfaces=None,
config=None, dchans=None, dX12='geom',
Id=None, Name=None, Exp=None, shot=None, Diag=None,
sino_RefPt=None, fromdict=None, sep=None, method='optimized',
SavePath=os.path.abspath('./'), color=None, plotdebug=True):
SavePath=os.path.abspath('./'), color=None):

# Create a dplot at instance level
self._dplot = copy.deepcopy(self.__class__._dplot)
Expand Down Expand Up @@ -4436,10 +4436,20 @@ def _compute_kInOut(self, largs=None, dkwd=None, indStruct=None):
indout[0, :] = indStruct[indout[0, :]]
return kIn, kOut, vperp, indout, indStruct

def compute_dgeom(self, extra=True, plotdebug=True):
def compute_dgeom(self, extra=True, show_debug_plot=True):
""" Compute dictionnary of geometrical attributes (dgeom)

Parameters
----------
show_debug_plot: bool
In case some lines of sight have no visibility inside the tokamak,
they will be considered invalid. tofu will issue a warning with
their indices and if show_debug_plot is True, try to plot a 3d
figure to help understand why these los have no visibility
"""
# Can only be computed if config if provided
if self._dconfig["Config"] is None:
msg = "Attribute dgeom cannot be computed without a config !"
msg = "Attribute dgeom cannot be computed without a config!"
warnings.warn(msg)
return

Expand All @@ -4450,36 +4460,39 @@ def compute_dgeom(self, extra=True, plotdebug=True):
# Perform computation of kIn and kOut
kIn, kOut, vperp, indout, indStruct = self._compute_kInOut()

# Clean up (in case of nans)
# Check for LOS that have no visibility inside the plasma domain (nan)
ind = np.isnan(kIn)
kIn[ind] = 0.0
ind = np.isnan(kOut) | np.isinf(kOut)
if np.any(ind):
kOut[ind] = np.nan
msg = "Some LOS have no visibility inside the plasma domain !\n"
msg += "Nb. of LOS concerned: %s out of %s\n" % (
str(ind.sum()),
str(kOut.size),
)
msg += "Indices of LOS ok:\n"
msg += repr((~ind).nonzero()[0])
msg += "\nIndices of LOS with no visibility:\n"
msg += repr(ind.nonzero()[0])
warnings.warn(msg)
if plotdebug:
msg = ("Some LOS have no visibility inside the plasma domain!\n"
+ "Nb. of LOS concerned: {} / {}\n".format(ind.sum(),
kOut.size)
+ "Indices of LOS ok:\n"
+ repr((~ind).nonzero()[0])
+ "\nIndices of LOS with no visibility:\n"
+ repr(ind.nonzero()[0]))
if show_debug_plot is True:
PIn = self.D[:, ind] + kIn[None, ind] * self.u[:, ind]
POut = self.D[:, ind] + kOut[None, ind] * self.u[:, ind]
# To be updated
_plot._LOS_calc_InOutPolProj_Debug(
self.config,
self.D[:, ind],
self.u[:, ind],
PIn,
POut,
nptstot=kOut.size,
Lim=[np.pi / 4.0, 2.0 * np.pi / 4],
Nstep=50,
)
msg2 = ("\n\tD = {}\n".format(self.D[:, ind])
+ "\tu = {}\n".format(self.u[:, ind])
+ "\tPIn = {}\n".format(PIn)
+ "\tPOut = {}".format(POut))
warnings.warn(msg2)
# plot 3d debug figure
# _plot._LOS_calc_InOutPolProj_Debug(
# self.config,
# self.D[:, ind],
# self.u[:, ind],
# PIn,
# POut,
# nptstot=kOut.size,
# Lim=[np.pi / 4.0, 2.0 * np.pi / 4],
# Nstep=50,
# )
kOut[ind] = np.nan
raise Exception(msg)

# Handle particular cases with kIn > kOut
ind = np.zeros(kIn.shape, dtype=bool)
Expand Down
2 changes: 1 addition & 1 deletion tofu/geom/_def.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def Plot_3D_plt_Tor_DefAxes(fs=None, wintit='tofu'):
ax.set_xlabel(r"X (m)")
ax.set_ylabel(r"Y (m)")
ax.set_zlabel(r"Z (m)")
ax.set_aspect(aspect="equal", adjustable='datalim')
# ax.set_aspect(aspect="equal", adjustable='datalim')
return ax


Expand Down
15 changes: 5 additions & 10 deletions tofu/geom/_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,19 +788,14 @@ def _LOS_calc_InOutPolProj_Debug(config, Ds, us ,PIns, POuts,
msg = '_LOS_calc_InOutPolProj - Debugging %s / %s pts'%(str(nP),str(nptstot))
ax.set_title(msg)
ax.plot(pts[0,:], pts[1,:], pts[2,:], c='k', lw=1, ls='-')
ax.plot(PIns[0,:],PIns[1,:],PIns[2,:], c='b', ls='None', marker='o', label=r"PIn")
ax.plot(POuts[0,:],POuts[1,:],POuts[2,:], c='r', ls='None', marker='x', label=r"POut")
#ax.legend(**_def.TorLegd)
# ax.plot(PIns[0,:],PIns[1,:],PIns[2,:],
# c='b', ls='None', marker='o', label=r"PIn")
# ax.plot(POuts[0,:],POuts[1,:],POuts[2,:],
# c='r', ls='None', marker='x', label=r"POut")
# ax.legend(**_def.TorLegd)
if draw:
ax.figure.canvas.draw()

msg = "\nDebugging %s / %s pts with no visibility:\n"%(str(nP),str(nptstot))
msg += " D = %s\n"%str(Ds)
msg += " u = %s\n"%str(us)
msg += " PIn = %s\n"%str(PIns)
msg += " POut = %s\n"%str(POuts)
print(msg)


def _get_LLOS_Leg(GLLOS, Leg=None, ind=None, Val=None, Crit='Name', PreExp=None,
PostExp=None, Log='any', InOut='In'):
Expand Down
Loading