py-pluto 1.1.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyPLUTO/__init__.py +22 -0
- pyPLUTO/amr.py +745 -0
- pyPLUTO/baseloadmixin.py +258 -0
- pyPLUTO/baseloadstate.py +45 -0
- pyPLUTO/codes/echo_load.py +161 -0
- pyPLUTO/configure.py +261 -0
- pyPLUTO/gui/config.py +174 -0
- pyPLUTO/gui/custom_var.py +435 -0
- pyPLUTO/gui/globals.py +108 -0
- pyPLUTO/gui/main.py +17 -0
- pyPLUTO/gui/main_window.py +177 -0
- pyPLUTO/gui/panels.py +66 -0
- pyPLUTO/gui/utils.py +273 -0
- pyPLUTO/h_pypluto.py +84 -0
- pyPLUTO/image.py +302 -0
- pyPLUTO/imagefuncs/colorbar.py +240 -0
- pyPLUTO/imagefuncs/contour.py +254 -0
- pyPLUTO/imagefuncs/create_axes.py +464 -0
- pyPLUTO/imagefuncs/display.py +306 -0
- pyPLUTO/imagefuncs/figure.py +395 -0
- pyPLUTO/imagefuncs/imagetools.py +487 -0
- pyPLUTO/imagefuncs/interactive.py +403 -0
- pyPLUTO/imagefuncs/legend.py +250 -0
- pyPLUTO/imagefuncs/plot.py +311 -0
- pyPLUTO/imagefuncs/range.py +242 -0
- pyPLUTO/imagefuncs/scatter.py +270 -0
- pyPLUTO/imagefuncs/set_axis.py +497 -0
- pyPLUTO/imagefuncs/streamplot.py +297 -0
- pyPLUTO/imagefuncs/zoom.py +428 -0
- pyPLUTO/imagemixin.py +259 -0
- pyPLUTO/imagestate.py +45 -0
- pyPLUTO/load.py +447 -0
- pyPLUTO/loadfuncs/baseloadtools.py +71 -0
- pyPLUTO/loadfuncs/codeselection.py +48 -0
- pyPLUTO/loadfuncs/defpluto.py +123 -0
- pyPLUTO/loadfuncs/descriptor.py +102 -0
- pyPLUTO/loadfuncs/findfiles.py +182 -0
- pyPLUTO/loadfuncs/findformat.py +245 -0
- pyPLUTO/loadfuncs/initload.py +203 -0
- pyPLUTO/loadfuncs/loadvars.py +227 -0
- pyPLUTO/loadfuncs/offsetdata.py +87 -0
- pyPLUTO/loadfuncs/offsetfluid.py +408 -0
- pyPLUTO/loadfuncs/read_files.py +213 -0
- pyPLUTO/loadfuncs/readdata.py +619 -0
- pyPLUTO/loadfuncs/readdata_old.py +567 -0
- pyPLUTO/loadfuncs/readdefplini.py +101 -0
- pyPLUTO/loadfuncs/readfluid.py +479 -0
- pyPLUTO/loadfuncs/readformat.py +277 -0
- pyPLUTO/loadfuncs/readgridalone.py +224 -0
- pyPLUTO/loadfuncs/readgridfile.py +255 -0
- pyPLUTO/loadfuncs/readgridout.py +451 -0
- pyPLUTO/loadfuncs/readpart.py +419 -0
- pyPLUTO/loadfuncs/readtab.py +105 -0
- pyPLUTO/loadfuncs/write_files.py +283 -0
- pyPLUTO/loadmixin.py +419 -0
- pyPLUTO/loadpart.py +233 -0
- pyPLUTO/loadstate.py +68 -0
- pyPLUTO/newload.py +81 -0
- pyPLUTO/pytools.py +145 -0
- pyPLUTO/toolfuncs/findlines.py +551 -0
- pyPLUTO/toolfuncs/fourier.py +149 -0
- pyPLUTO/toolfuncs/nabla.py +676 -0
- pyPLUTO/toolfuncs/parttools.py +152 -0
- pyPLUTO/toolfuncs/transform.py +638 -0
- pyPLUTO/utils/annotator.py +27 -0
- pyPLUTO/utils/inspector.py +145 -0
- pyPLUTO/utils/make_docstrings.py +3 -0
- py_pluto-1.1.4.dist-info/METADATA +218 -0
- py_pluto-1.1.4.dist-info/RECORD +73 -0
- py_pluto-1.1.4.dist-info/WHEEL +5 -0
- py_pluto-1.1.4.dist-info/entry_points.txt +2 -0
- py_pluto-1.1.4.dist-info/licenses/LICENSE +27 -0
- py_pluto-1.1.4.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
"""Module to manage the streamplot function from matplotlib.pyplot."""
|
|
2
|
+
|
|
3
|
+
import warnings
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
import numpy as np
|
|
7
|
+
from matplotlib.collections import LineCollection
|
|
8
|
+
from numpy.typing import NDArray
|
|
9
|
+
|
|
10
|
+
from pyPLUTO.imagefuncs.colorbar import ColorbarManager
|
|
11
|
+
from pyPLUTO.imagefuncs.imagetools import ImageToolsManager
|
|
12
|
+
from pyPLUTO.imagefuncs.range import RangeManager
|
|
13
|
+
from pyPLUTO.imagefuncs.set_axis import AxisManager
|
|
14
|
+
from pyPLUTO.imagemixin import ImageMixin
|
|
15
|
+
from pyPLUTO.imagestate import ImageState
|
|
16
|
+
from pyPLUTO.utils.inspector import track_kwargs
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class StreamplotManager(ImageMixin):
|
|
20
|
+
"""Manages the streamplot function from matplotlib.pyplot."""
|
|
21
|
+
|
|
22
|
+
exposed_methods = ("streamplot",)
|
|
23
|
+
|
|
24
|
+
def __init__(self, state: ImageState) -> None:
|
|
25
|
+
"""Initialize the StreamplotManager with the given state."""
|
|
26
|
+
self.state = state
|
|
27
|
+
|
|
28
|
+
self.AxisManager = AxisManager(state)
|
|
29
|
+
self.ColorbarManager = ColorbarManager(state)
|
|
30
|
+
self.ImageToolsManager = ImageToolsManager(state)
|
|
31
|
+
self.RangeManager = RangeManager(state)
|
|
32
|
+
|
|
33
|
+
@track_kwargs
|
|
34
|
+
def streamplot(
|
|
35
|
+
self,
|
|
36
|
+
var1: NDArray[np.generic],
|
|
37
|
+
var2: NDArray[np.generic],
|
|
38
|
+
check: bool = True,
|
|
39
|
+
**kwargs: Any,
|
|
40
|
+
) -> LineCollection:
|
|
41
|
+
"""Plot a streamplot of a vector field.
|
|
42
|
+
|
|
43
|
+
The function uses the streamplot function from matplotlib.pyplot.
|
|
44
|
+
|
|
45
|
+
Returns
|
|
46
|
+
-------
|
|
47
|
+
- strm: LineCollection
|
|
48
|
+
The streamplot of the given vector field.
|
|
49
|
+
|
|
50
|
+
Parameters
|
|
51
|
+
----------
|
|
52
|
+
- alpha: float, default 1.0
|
|
53
|
+
Sets the opacity of the plot, where 1.0 means total opaque and 0.0
|
|
54
|
+
means total transparent.
|
|
55
|
+
- arrowsize: float, default 1.0
|
|
56
|
+
Sets the size of the arrows of the streamline.
|
|
57
|
+
- arrowstyle: str, default '-|>'
|
|
58
|
+
Sets the style of the arrows of the streamline.
|
|
59
|
+
- aspect: {'auto', 'equal', float}, default 'auto'
|
|
60
|
+
Sets the aspect ratio of the plot. The 'auto' keyword is the default
|
|
61
|
+
option (most likely the plot will be squared). The 'equal' keyword
|
|
62
|
+
will set the same scaling for x and y. A float will fix the ratio
|
|
63
|
+
between the y-scale and the x-scale (1.0 is the same as 'equal').
|
|
64
|
+
- ax: axis object
|
|
65
|
+
The axis where to plot the streamlines. If not given, the last
|
|
66
|
+
considered axis will be used.
|
|
67
|
+
- brokenlines: bool, default True
|
|
68
|
+
Splits the streamlines in shorter segments.
|
|
69
|
+
- c: str, default self.color
|
|
70
|
+
Determines the streamplot color. If not defined, the program will
|
|
71
|
+
loop over an array of 6 color which are different for the most
|
|
72
|
+
common vision deficiencies.
|
|
73
|
+
- cmap: str, default 'hot'
|
|
74
|
+
Selects the colormap. If not defined, the colormap 'hot' will be
|
|
75
|
+
adopted. Some useful colormaps are: plasma, magma, seismic. Please
|
|
76
|
+
avoid using colorbars like jjet or rainbow, which are not
|
|
77
|
+
perceptively uniform and not suited for people with vision
|
|
78
|
+
deficiencies.
|
|
79
|
+
All the colormap available are listed in the following link:
|
|
80
|
+
https://matplotlib.org/stable/tutorials/colors/colormaps.html
|
|
81
|
+
- cpos: {'top','bottom','left','right'}, default None
|
|
82
|
+
Enables the colorbar (if defined), default position on the right.
|
|
83
|
+
- cscale: {'linear','log','symlog','twoslope'}, default 'linear'
|
|
84
|
+
Sets the colorbar scale. Default is the linear ('norm') scale.
|
|
85
|
+
- density: float, default 1.0
|
|
86
|
+
Sets the density and closeness of the streamlines. The domain is
|
|
87
|
+
divided in a 30x30 grid. When set as default, each cell contains at
|
|
88
|
+
most a number of crossing streamplot line equal to this keyword.
|
|
89
|
+
- extend: {'neither','both','min','max'}, default 'neither'
|
|
90
|
+
Sets the extension of the triangular colorbar extension.
|
|
91
|
+
- extendrect: bool, default False
|
|
92
|
+
If True, the colorbar extension will be rectangular.
|
|
93
|
+
- fontsize: float, default 17.0
|
|
94
|
+
Sets the fontsize for all the axis components (only for the current
|
|
95
|
+
axis).
|
|
96
|
+
- grid: bool, default False
|
|
97
|
+
Enables/disables the grid on the plot.
|
|
98
|
+
- integration_direction: {'forward', 'backward', 'both'}, default:'both'
|
|
99
|
+
Sets the streamlines integration in the forward direction, backward
|
|
100
|
+
direction, or both.
|
|
101
|
+
- labelsize: float, default fontsize
|
|
102
|
+
Sets the labels fontsize (which is the same for both labels).
|
|
103
|
+
The default value corresponds to the value of the keyword
|
|
104
|
+
'fontsize'.
|
|
105
|
+
- lw: float, default 1.0
|
|
106
|
+
Sets the width of the streamlines.
|
|
107
|
+
- maxlength: float, default 5.0
|
|
108
|
+
Sets the maximum length of a streamline in coordinates units.
|
|
109
|
+
- minlength: float, default 0.1
|
|
110
|
+
Sets the minimum length of a streamline in coordinates units.
|
|
111
|
+
- minorticks: str, default None
|
|
112
|
+
If not None enables the minor ticks on the plot (for both grid
|
|
113
|
+
axes).
|
|
114
|
+
- start_points: np.ndarray, default None
|
|
115
|
+
Sets the starting points of the streamlines, if a more controlled
|
|
116
|
+
plot is wanted.
|
|
117
|
+
- ticksdir: {'in', 'out'}, default 'in'
|
|
118
|
+
Sets the ticks direction. The default option is 'in'.
|
|
119
|
+
- tickssize: float | bool, default True
|
|
120
|
+
Sets the ticks fontsize (which is the same for both grid axes).
|
|
121
|
+
The default value corresponds to the value of the keyword
|
|
122
|
+
'fontsize'.
|
|
123
|
+
- title: str, default None
|
|
124
|
+
Places the title of the plot on top of it.
|
|
125
|
+
- titlepad: float, default 8.0
|
|
126
|
+
Sets the distance between the title and the top of the plot
|
|
127
|
+
- titlesize: float, default fontsize
|
|
128
|
+
Sets the title fontsize. The default value corresponds to the value
|
|
129
|
+
of the keyword 'fontsize'.
|
|
130
|
+
- transpose: True/False, default False
|
|
131
|
+
Transposes the variable matrix. Use is not recommended if not really
|
|
132
|
+
necessary (e.g. in case of highly customized variables and plots)
|
|
133
|
+
- tresh: float, default max(abs(vmin),vmax)*0.01
|
|
134
|
+
Sets the threshold for the colormap. If not defined, the threshold
|
|
135
|
+
will be set to 1% of the maximum absolute value of the variable.
|
|
136
|
+
The default cases are the following:
|
|
137
|
+
- twoslope colorscale: sets the limit between the two linear
|
|
138
|
+
regimes.
|
|
139
|
+
- symlog: sets the limit between the logaitrhmic and the linear
|
|
140
|
+
regime.
|
|
141
|
+
- var1 (not optional): np.ndarray
|
|
142
|
+
The x1-component of the vector field.
|
|
143
|
+
- var2 (not optional): np.ndarray
|
|
144
|
+
The x2-component of the vector field.
|
|
145
|
+
- vmax: float
|
|
146
|
+
The maximum value of the vector field norm.
|
|
147
|
+
- vmin: float
|
|
148
|
+
The minimum value of the vector field norm.
|
|
149
|
+
- x1: np.ndarray
|
|
150
|
+
The x-axis variable.
|
|
151
|
+
- x2: np.ndarray
|
|
152
|
+
The y-axis variable.
|
|
153
|
+
- xrange: [float, float], default [0,1]
|
|
154
|
+
Sets the range in the x-direction. If not defined the code will
|
|
155
|
+
compute the range while plotting the data.
|
|
156
|
+
- xscale: {'linear','log'}, default 'linear'
|
|
157
|
+
If enabled (and different from True), sets automatically the scale
|
|
158
|
+
on the x-axis. Data in log scale should be used with the keyword
|
|
159
|
+
'log', while data in linear scale should be used with the keyword
|
|
160
|
+
'linear'.
|
|
161
|
+
- xticks: {[float], None, True}, default True
|
|
162
|
+
If enabled (and different from True), sets manually ticks on
|
|
163
|
+
x-axis. In order to completely remove the ticks the keyword should
|
|
164
|
+
be used with None.
|
|
165
|
+
- xtickslabels: {[str], None, True}, default True
|
|
166
|
+
If enabled (and different from True), sets manually the ticks
|
|
167
|
+
labels on the x-axis. In order to completely remove the ticks the
|
|
168
|
+
keyword should be used with None. Note that fixed tickslabels should
|
|
169
|
+
always correspond to fixed ticks.
|
|
170
|
+
- xtitle: str, default None
|
|
171
|
+
Sets and places the label of the x-axis.
|
|
172
|
+
- yrange: [float, float], default [0,1]
|
|
173
|
+
Sets the range in the y-direction. If not defined the code will
|
|
174
|
+
compute the range while plotting the data.
|
|
175
|
+
- yscale: {'linear','log'}, default 'linear'
|
|
176
|
+
If enabled (and different from True), sets automatically the scale
|
|
177
|
+
on the y-axis. Data in log scale should be used with the keyword
|
|
178
|
+
'log', while data in linear scale should be used with the keyword
|
|
179
|
+
'linear'.
|
|
180
|
+
- yticks: {[float], None, True}, default True
|
|
181
|
+
If enabled (and different from True), sets manually ticks on
|
|
182
|
+
y-axis. In order to completely remove the ticks the keyword should
|
|
183
|
+
be used with None.
|
|
184
|
+
- ytickslabels: {[str], None, True}, default True
|
|
185
|
+
If enabled (and different from True), sets manually the ticks
|
|
186
|
+
labels on the y-axis. In order to completely remove the ticks the
|
|
187
|
+
keyword should be used with None. Note that fixed tickslabels should
|
|
188
|
+
always correspond to fixed ticks.
|
|
189
|
+
- ytitle: str, default None
|
|
190
|
+
Sets and places the label of the y-axis.
|
|
191
|
+
|
|
192
|
+
----
|
|
193
|
+
|
|
194
|
+
Examples
|
|
195
|
+
--------
|
|
196
|
+
- Example #1: Plot a streamplot of a vector field
|
|
197
|
+
|
|
198
|
+
>>> I.streamplot(D.Bx1, D.Bx2)
|
|
199
|
+
|
|
200
|
+
"""
|
|
201
|
+
kwargs.pop("check", check)
|
|
202
|
+
|
|
203
|
+
if np.shape(var1) != np.shape(var2):
|
|
204
|
+
raise ValueError("The shapes of the variables are different.")
|
|
205
|
+
|
|
206
|
+
# Set or create figure and axes
|
|
207
|
+
ax, nax = self.ImageToolsManager.assign_ax(
|
|
208
|
+
kwargs.pop("ax", None), **kwargs
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
if self.fig is None:
|
|
212
|
+
raise ValueError(
|
|
213
|
+
"No figure is present. Please create a figure first."
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
x = np.asarray(kwargs.get("x1", np.arange(len(var1[:, 0]))))
|
|
217
|
+
y = np.asarray(kwargs.get("x2", np.arange(len(var1[0, :]))))
|
|
218
|
+
|
|
219
|
+
# Keyword x1 and x2
|
|
220
|
+
varx, vary = (
|
|
221
|
+
np.array(var2.T, dtype=float, copy=True),
|
|
222
|
+
np.array(var1.T, dtype=float, copy=True),
|
|
223
|
+
)
|
|
224
|
+
if kwargs.get("transpose", False) is True:
|
|
225
|
+
varx, vary = varx.T, vary.T
|
|
226
|
+
|
|
227
|
+
fieldmod = np.sqrt(varx**2 + vary**2)
|
|
228
|
+
vmax = kwargs.get("vmax", np.nanmax(fieldmod))
|
|
229
|
+
vmin = kwargs.get("vmin", np.nanmin(fieldmod))
|
|
230
|
+
|
|
231
|
+
# Apply the masks to set the corresponding elements
|
|
232
|
+
# in varx and vary to NaN
|
|
233
|
+
mask = np.logical_or(fieldmod > vmax, fieldmod < vmin)
|
|
234
|
+
varx[mask] = vary[mask] = np.nan
|
|
235
|
+
|
|
236
|
+
# Set ax parameters
|
|
237
|
+
self.AxisManager.set_axis(ax=ax, check=False, **kwargs)
|
|
238
|
+
self.ImageToolsManager.hide_text(nax, ax.texts)
|
|
239
|
+
|
|
240
|
+
# Keyword for colorbar and colorscale
|
|
241
|
+
color = kwargs.get("c")
|
|
242
|
+
cmap = self.ImageToolsManager.find_cmap(kwargs.get("cmap"))
|
|
243
|
+
cpos = kwargs.get("cpos")
|
|
244
|
+
cscale = kwargs.get("cscale", "norm")
|
|
245
|
+
tresh = kwargs.get("tresh", max(np.abs(vmin), vmax) * 0.01)
|
|
246
|
+
lint = kwargs.get("lint")
|
|
247
|
+
|
|
248
|
+
if "colors" in kwargs and "cmap" in kwargs:
|
|
249
|
+
warn = "Both colors and cmap are defined. Using c."
|
|
250
|
+
warnings.warn(warn, UserWarning, stacklevel=2)
|
|
251
|
+
|
|
252
|
+
# Set the lines properties
|
|
253
|
+
linewidth = kwargs.get("lw", 1)
|
|
254
|
+
density = kwargs.get("density", 1)
|
|
255
|
+
arrowstyle = kwargs.get("arrowstyle", "-|>")
|
|
256
|
+
arrowsize = kwargs.get("arrowsize", 1)
|
|
257
|
+
minlength = kwargs.get("minlength", 0.1)
|
|
258
|
+
integration_direction = kwargs.get("integration_direction", "both")
|
|
259
|
+
start_points = kwargs.get("start_points")
|
|
260
|
+
maxlength = kwargs.get("maxlength", 5)
|
|
261
|
+
broken_streamlines = kwargs.get("brokenlines", True)
|
|
262
|
+
|
|
263
|
+
# Set the colorbar scale (put in function)
|
|
264
|
+
norm = self.ImageToolsManager.set_cscale(
|
|
265
|
+
cscale, vmin, vmax, tresh, lint
|
|
266
|
+
)
|
|
267
|
+
|
|
268
|
+
# Plot the streamplot
|
|
269
|
+
strm = ax.streamplot(
|
|
270
|
+
x,
|
|
271
|
+
y,
|
|
272
|
+
vary,
|
|
273
|
+
varx,
|
|
274
|
+
norm=norm,
|
|
275
|
+
cmap=cmap,
|
|
276
|
+
color=color,
|
|
277
|
+
linewidth=linewidth,
|
|
278
|
+
density=density,
|
|
279
|
+
arrowsize=arrowsize,
|
|
280
|
+
minlength=minlength,
|
|
281
|
+
maxlength=maxlength,
|
|
282
|
+
start_points=start_points,
|
|
283
|
+
arrowstyle=arrowstyle,
|
|
284
|
+
integration_direction=integration_direction,
|
|
285
|
+
broken_streamlines=broken_streamlines,
|
|
286
|
+
)
|
|
287
|
+
|
|
288
|
+
if cpos is not None:
|
|
289
|
+
self.ColorbarManager.colorbar(strm.lines, check=False, **kwargs)
|
|
290
|
+
|
|
291
|
+
# If tight_layout is enabled, is re-inforced
|
|
292
|
+
if self.tight:
|
|
293
|
+
self.fig.tight_layout()
|
|
294
|
+
|
|
295
|
+
del varx, vary
|
|
296
|
+
|
|
297
|
+
return strm.lines
|