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,254 @@
|
|
|
1
|
+
"""Module for managing contour plots in image displays."""
|
|
2
|
+
|
|
3
|
+
import warnings
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
import numpy as np
|
|
7
|
+
from matplotlib.contour import QuadContourSet
|
|
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 ContourManager(ImageMixin):
|
|
20
|
+
"""Class to manage contour plots in the image.
|
|
21
|
+
|
|
22
|
+
This class provides methods to create contour plots of variables in the
|
|
23
|
+
image class. It allows for customization of the contour lines, colorbars,
|
|
24
|
+
and other properties.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
exposed_methods = ("contour",)
|
|
28
|
+
|
|
29
|
+
def __init__(self, state: ImageState) -> None:
|
|
30
|
+
"""Initialize the ContourManager with the given state."""
|
|
31
|
+
self.state = state
|
|
32
|
+
self.AxisManager = AxisManager(state)
|
|
33
|
+
self.ColorbarManager = ColorbarManager(state)
|
|
34
|
+
self.ImageToolsManager = ImageToolsManager(state)
|
|
35
|
+
self.RangeManager = RangeManager(state)
|
|
36
|
+
|
|
37
|
+
@track_kwargs
|
|
38
|
+
def contour(
|
|
39
|
+
self, var: NDArray[np.generic], check: bool = True, **kwargs: Any
|
|
40
|
+
) -> QuadContourSet:
|
|
41
|
+
"""Plot a contour plot of a given variable.
|
|
42
|
+
|
|
43
|
+
The function uses the matplotlib.pyplot.contour function. The function
|
|
44
|
+
returns None.
|
|
45
|
+
|
|
46
|
+
Returns
|
|
47
|
+
-------
|
|
48
|
+
- cnt: LineCollection
|
|
49
|
+
The set of contour lines of the given variable.
|
|
50
|
+
|
|
51
|
+
Parameters
|
|
52
|
+
----------
|
|
53
|
+
- alpha: float, default 1.0
|
|
54
|
+
Sets the transparency of the contour lines.
|
|
55
|
+
- aspect: {'auto', 'equal', float}, default 'auto'
|
|
56
|
+
Sets the aspect ratio of the plot. The 'auto' keyword is the default
|
|
57
|
+
option (most likely the plot will be squared). The 'equal' keyword
|
|
58
|
+
will set the same scaling for x and y. A float will fix the ratio
|
|
59
|
+
between the y-scale and the x-scale (1.0 is the same as 'equal').
|
|
60
|
+
- ax: {ax object, 'old', None}, default None
|
|
61
|
+
The axis where to plot the lines. If None, a new axis is created.
|
|
62
|
+
If 'old', the last considered axis will be used.
|
|
63
|
+
- c: str, default self.color
|
|
64
|
+
Determines the contour lines plot. If not defined, the program will
|
|
65
|
+
loop over an array of 6 color which are different for the most
|
|
66
|
+
common vision deficiencies.
|
|
67
|
+
- cmap: str, default 'hot'
|
|
68
|
+
Selects the colormap. If not defined, the colormap 'hot' will be
|
|
69
|
+
adopted. Some useful colormaps are: plasma, magma, seismic. Please
|
|
70
|
+
avoid using colorbars like jjet or rainbow, which are not
|
|
71
|
+
perceptively uniform and not suited for people with vision
|
|
72
|
+
deficiencies.
|
|
73
|
+
- cpos: {'top','bottom','left','right'}, default None
|
|
74
|
+
Enables the colorbar (if defined), default position on the right.
|
|
75
|
+
- cscale: {'linear','log','symlog','twoslope'}, default 'linear'
|
|
76
|
+
Sets the colorbar scale. Default is the linear ('norm') scale.
|
|
77
|
+
- extend: {'neither','both','min','max'}, default 'neither'
|
|
78
|
+
Sets the extension of the triangular colorbar extension.
|
|
79
|
+
- extendrect: bool, default False
|
|
80
|
+
If True, the colorbar extension will be rectangular.
|
|
81
|
+
- fontsize: float, default 17.0
|
|
82
|
+
Sets the fontsize for all the axis components (only for the current
|
|
83
|
+
axis).
|
|
84
|
+
- grid: bool, default False
|
|
85
|
+
Enables/disables the grid on the plot.
|
|
86
|
+
- labelsize: float, default fontsize
|
|
87
|
+
Sets the labels fontsize (which is the same for both labels).
|
|
88
|
+
The default value corresponds to the value of the keyword
|
|
89
|
+
'fontsize'.
|
|
90
|
+
- levels: np.ndarray
|
|
91
|
+
The levels of the contour lines.
|
|
92
|
+
- minorticks: str, default None
|
|
93
|
+
If not None enables the minor ticks on the plot (for both grid
|
|
94
|
+
axes).
|
|
95
|
+
- sharex: Matplotlib axis | False, default False
|
|
96
|
+
Shares the x-axis with another axis.
|
|
97
|
+
- sharey: Matplotlib axis | False, default False
|
|
98
|
+
Shares the y-axis with another axis.
|
|
99
|
+
- ticksdir: {'in', 'out'}, default 'in'
|
|
100
|
+
Sets the ticks direction. The default option is 'in'.
|
|
101
|
+
- tickssize: float | bool, default True
|
|
102
|
+
Sets the ticks fontsize (which is the same for both grid axes).
|
|
103
|
+
The default value corresponds to the value of the keyword
|
|
104
|
+
'fontsize'.
|
|
105
|
+
- title: str, default None
|
|
106
|
+
Places the title of the plot on top of it.
|
|
107
|
+
- titlepad: float, default 8.0
|
|
108
|
+
Sets the distance between the title and the top of the plot
|
|
109
|
+
- titlesize: float, default fontsize
|
|
110
|
+
Sets the title fontsize. The default value corresponds to the value
|
|
111
|
+
of the keyword 'fontsize'.
|
|
112
|
+
- transpose: True/False, default False
|
|
113
|
+
Transposes the variable matrix. Use is not recommended if not really
|
|
114
|
+
necessary (e.g. in case of highly customized variables and plots).
|
|
115
|
+
- tresh: float, default max(abs(vmin),vmax)*0.01
|
|
116
|
+
Sets the threshold for the colormap. If not defined, the threshold
|
|
117
|
+
will be set to 1% of the maximum absolute value of the variable.
|
|
118
|
+
The default cases are the following:
|
|
119
|
+
- twoslope colorscale: sets the limit between the two linear
|
|
120
|
+
regimes.
|
|
121
|
+
- symlog: sets the limit between the logaitrhmic and the linear
|
|
122
|
+
regime.
|
|
123
|
+
- var (not optional): np.ndarray
|
|
124
|
+
The variable to be plotted.
|
|
125
|
+
- vmax: float
|
|
126
|
+
The maximum value of the colormap.
|
|
127
|
+
- vmin: float
|
|
128
|
+
The minimum value of the colormap.
|
|
129
|
+
- x1: 1D array, default 'Default'
|
|
130
|
+
The 'x' array.
|
|
131
|
+
- x2: 1D array, default 'Default'
|
|
132
|
+
The 'y' array.
|
|
133
|
+
- xrange: [float, float], default [0,1]
|
|
134
|
+
Sets the range in the x-direction. If not defined the code will
|
|
135
|
+
compute the range while plotting the data.
|
|
136
|
+
- xscale: {'linear','log'}, default 'linear'
|
|
137
|
+
If enabled (and different from True), sets automatically the scale
|
|
138
|
+
on the x-axis. Data in log scale should be used with the keyword
|
|
139
|
+
'log', while data in linear scale should be used with the keyword
|
|
140
|
+
'linear'.
|
|
141
|
+
- xticks: {[float], None, True}, default True
|
|
142
|
+
If enabled (and different from True), sets manually ticks on
|
|
143
|
+
x-axis. In order to completely remove the ticks the keyword should
|
|
144
|
+
be used with None.
|
|
145
|
+
- xtickslabels: {[str], None, True}, default True
|
|
146
|
+
If enabled (and different from True), sets manually the ticks
|
|
147
|
+
labels on the x-axis. In order to completely remove the ticks the
|
|
148
|
+
keyword should be used with None. Note that fixed tickslabels should
|
|
149
|
+
always correspond to fixed ticks.
|
|
150
|
+
- xtitle: str, default None
|
|
151
|
+
Sets and places the label of the x-axis.
|
|
152
|
+
- yrange: [float, float], default [0,1]
|
|
153
|
+
Sets the range in the y-direction. If not defined the code will
|
|
154
|
+
compute the range while plotting the data.
|
|
155
|
+
- yscale: {'linear','log'}, default 'linear'
|
|
156
|
+
If enabled (and different from True), sets automatically the scale
|
|
157
|
+
on the y-axis. Data in log scale should be used with the keyword
|
|
158
|
+
'log', while data in linear scale should be used with the keyword
|
|
159
|
+
'linear'.
|
|
160
|
+
- yticks: {[float], None, True}, default True
|
|
161
|
+
If enabled (and different from True), sets manually ticks on
|
|
162
|
+
y-axis. In order to completely remove the ticks the keyword should
|
|
163
|
+
be used with None.
|
|
164
|
+
- ytickslabels: {[str], None, True}, default True
|
|
165
|
+
If enabled (and different from True), sets manually the ticks
|
|
166
|
+
labels on the y-axis. In order to completely remove the ticks the
|
|
167
|
+
keyword should be used with None. Note that fixed tickslabels should
|
|
168
|
+
always correspond to fixed ticks.
|
|
169
|
+
- ytitle: str, default None
|
|
170
|
+
Sets and places the label of the y-axis.
|
|
171
|
+
|
|
172
|
+
----
|
|
173
|
+
|
|
174
|
+
Examples
|
|
175
|
+
--------
|
|
176
|
+
- Example #1: Plot a contour plot of a variable
|
|
177
|
+
|
|
178
|
+
>>> I.contour(D.rho, levels=10)
|
|
179
|
+
|
|
180
|
+
"""
|
|
181
|
+
kwargs.pop("check", check)
|
|
182
|
+
|
|
183
|
+
# Set or create figure and axes
|
|
184
|
+
ax, nax = self.ImageToolsManager.assign_ax(
|
|
185
|
+
kwargs.pop("ax", None), **kwargs
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
if self.fig is None:
|
|
189
|
+
raise ValueError(
|
|
190
|
+
"No figure is present. Please create a figure first."
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
# Keyword x1 and x2
|
|
194
|
+
x = np.asarray(kwargs.get("x1", np.arange(len(var[:, 0]))))
|
|
195
|
+
y = np.asarray(kwargs.get("x2", np.arange(len(var[0, :]))))
|
|
196
|
+
|
|
197
|
+
# Transpose if needed
|
|
198
|
+
var = np.asarray(var.T)
|
|
199
|
+
if kwargs.get("transpose", False) is True:
|
|
200
|
+
var = var.T
|
|
201
|
+
|
|
202
|
+
# Set ax parameters
|
|
203
|
+
self.AxisManager.set_axis(ax=ax, check=False, **kwargs)
|
|
204
|
+
self.ImageToolsManager.hide_text(nax, ax.texts)
|
|
205
|
+
|
|
206
|
+
# Keywords vmin and vmax
|
|
207
|
+
vmin = kwargs.get("vmin", np.nanmin(var))
|
|
208
|
+
vmax = kwargs.get("vmax", np.nanmax(var))
|
|
209
|
+
|
|
210
|
+
# Sets levels for the contour plot
|
|
211
|
+
levels = kwargs.get("levels", np.linspace(vmin, vmax, 10))
|
|
212
|
+
|
|
213
|
+
# Keyword for colorbar and colorscale
|
|
214
|
+
colors = kwargs.get("c")
|
|
215
|
+
cmap = self.ImageToolsManager.find_cmap(kwargs.get("cmap"))
|
|
216
|
+
cpos = kwargs.get("cpos")
|
|
217
|
+
cscale = kwargs.get("cscale", "norm")
|
|
218
|
+
tresh = kwargs.get("tresh", max(np.abs(vmin), vmax) * 0.01)
|
|
219
|
+
lint = kwargs.get("lint")
|
|
220
|
+
lw = kwargs.get("lw", 1.0)
|
|
221
|
+
|
|
222
|
+
if "colors" in kwargs and "cmap" in kwargs:
|
|
223
|
+
warn = "Both colors and cmap are defined. Using c."
|
|
224
|
+
warnings.warn(warn, UserWarning, stacklevel=2)
|
|
225
|
+
|
|
226
|
+
# Set the colorbar scale (put in function)
|
|
227
|
+
norm = self.ImageToolsManager.set_cscale(
|
|
228
|
+
cscale, vmin, vmax, tresh, lint
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
# Select shading
|
|
232
|
+
alpha = kwargs.get("alpha", 1.0)
|
|
233
|
+
|
|
234
|
+
# Plot the contour plot
|
|
235
|
+
cnt = ax.contour(
|
|
236
|
+
x,
|
|
237
|
+
y,
|
|
238
|
+
var,
|
|
239
|
+
levels=levels,
|
|
240
|
+
norm=norm,
|
|
241
|
+
cmap=cmap,
|
|
242
|
+
colors=colors,
|
|
243
|
+
alpha=alpha,
|
|
244
|
+
linewidths=lw,
|
|
245
|
+
)
|
|
246
|
+
|
|
247
|
+
if cpos is not None:
|
|
248
|
+
self.ColorbarManager.colorbar(cnt, check=False, **kwargs)
|
|
249
|
+
|
|
250
|
+
# If tight_layout is enabled, is re-inforced
|
|
251
|
+
if self.tight:
|
|
252
|
+
self.fig.tight_layout()
|
|
253
|
+
|
|
254
|
+
return cnt
|