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,428 @@
|
|
|
1
|
+
"""Module to manage the zoom functionality in pyPLUTO."""
|
|
2
|
+
|
|
3
|
+
import warnings
|
|
4
|
+
from typing import Any, cast
|
|
5
|
+
|
|
6
|
+
import numpy as np
|
|
7
|
+
from matplotlib.axes import Axes
|
|
8
|
+
from matplotlib.collections import QuadMesh
|
|
9
|
+
|
|
10
|
+
from pyPLUTO.imagefuncs.create_axes import CreateAxesManager
|
|
11
|
+
from pyPLUTO.imagefuncs.display import DisplayManager
|
|
12
|
+
from pyPLUTO.imagefuncs.imagetools import ImageToolsManager
|
|
13
|
+
from pyPLUTO.imagefuncs.plot import PlotManager
|
|
14
|
+
from pyPLUTO.imagefuncs.set_axis import AxisManager
|
|
15
|
+
from pyPLUTO.imagemixin import ImageMixin
|
|
16
|
+
from pyPLUTO.imagestate import ImageState
|
|
17
|
+
from pyPLUTO.utils.inspector import track_kwargs
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class ZoomManager(ImageMixin):
|
|
21
|
+
"""Manager for the zoom functionality in pyPLUTO.
|
|
22
|
+
|
|
23
|
+
This class provides methods to create inset zooms of existing plots or
|
|
24
|
+
displays. It allows customization of the zoom axes, including position,
|
|
25
|
+
size, and various display options.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
exposed_methods = ("zoom",)
|
|
29
|
+
|
|
30
|
+
def __init__(self, state: ImageState) -> None:
|
|
31
|
+
"""Initialize the ZoomManager with the given state."""
|
|
32
|
+
self.state = state
|
|
33
|
+
self.ImageToolsManager = ImageToolsManager(state)
|
|
34
|
+
self.CreateAxesManager = CreateAxesManager(state)
|
|
35
|
+
self.PlotManager = PlotManager(state)
|
|
36
|
+
self.DisplayManager = DisplayManager(state)
|
|
37
|
+
self.AxisManager = AxisManager(state)
|
|
38
|
+
|
|
39
|
+
@track_kwargs
|
|
40
|
+
def zoom(
|
|
41
|
+
self, ax: Axes | int | None = None, check: bool = True, **kwargs: Any
|
|
42
|
+
) -> Axes:
|
|
43
|
+
"""Creation of an inset zoom of an already existent plot or display.
|
|
44
|
+
|
|
45
|
+
It creates a set of axes within the same figure as the original plot or
|
|
46
|
+
display, and can be placed anywhere in the figure.
|
|
47
|
+
The zoom thus created is to all intents and purposes a self-sufficient
|
|
48
|
+
plot or display, with all the necessary customization options.
|
|
49
|
+
|
|
50
|
+
Returns
|
|
51
|
+
-------
|
|
52
|
+
- Axis object where the zoom plot is set
|
|
53
|
+
|
|
54
|
+
Parameters
|
|
55
|
+
----------
|
|
56
|
+
- alpha: float, default 1.0
|
|
57
|
+
Sets the opacity of the plot, where 1.0 means total opaque and 0.0
|
|
58
|
+
means total transparent.
|
|
59
|
+
- aspect: {'auto', 'equal', float}, default 'auto'
|
|
60
|
+
Sets the aspect ratio of the plot.
|
|
61
|
+
The 'auto' keyword is the default option (most likely the plot will
|
|
62
|
+
be squared). The 'equal' keyword will set the same scaling for
|
|
63
|
+
x and y. A float will fix the ratio between the y-scale and the
|
|
64
|
+
x-scale (1.0 is the same as 'equal').
|
|
65
|
+
- ax: ax object, default None
|
|
66
|
+
The axis to customize. If None the current axis will be selected.
|
|
67
|
+
- bottom: float, default 0.6 + height
|
|
68
|
+
Bottom position of the inset plot. If not defined the program will
|
|
69
|
+
give a standard value.
|
|
70
|
+
- clabel: str, default None
|
|
71
|
+
Sets the label of the colorbar.
|
|
72
|
+
- cmap: str, default 'hot'
|
|
73
|
+
Selects the colormap. If not defined, the colormap 'hot' will be
|
|
74
|
+
adopted.
|
|
75
|
+
Some useful colormaps are: plasma, magma, seismic. Please avoid
|
|
76
|
+
using colorbars like jet or rainbow, which are not perceptively
|
|
77
|
+
uniform and not suited for people with vision deficiencies.
|
|
78
|
+
All the colormap available are listed in the following link:
|
|
79
|
+
https://matplotlib.org/stable/tutorials/colors/colormaps.html
|
|
80
|
+
- cpad: float, default 0.07
|
|
81
|
+
Fraction of original axes between colorbar and the axes (in case cax
|
|
82
|
+
is not defined).
|
|
83
|
+
- cpos: {'top','bottom','left','right'}, default None
|
|
84
|
+
Enables the colorbar (if defined), default position on the right.
|
|
85
|
+
- cscale: {'linear','log','symlog','twoslope'}, default 'linear'
|
|
86
|
+
Sets the colorbar scale. Default is the linear ('norm') scale.
|
|
87
|
+
- cticks: {[float], None}, default None
|
|
88
|
+
If enabled (and different from None), sets manually ticks on the
|
|
89
|
+
colorbar.
|
|
90
|
+
- ctickslabels: str, default None
|
|
91
|
+
If enabled, sets manually ticks labels on the colorbar.
|
|
92
|
+
- extend: {'neither','both','min','max'}, default 'neither'
|
|
93
|
+
Sets the extension of the triangular colorbar extension.
|
|
94
|
+
- extendrect: bool, default False
|
|
95
|
+
If True, the colorbar extension will be rectangular.
|
|
96
|
+
- fontsize: float, default 17.0
|
|
97
|
+
Sets the fontsize for all the axis components (only for the current
|
|
98
|
+
axis).
|
|
99
|
+
- grid: bool, default False
|
|
100
|
+
Enables the grid.
|
|
101
|
+
- height: float, default 0.15
|
|
102
|
+
Height of the inset zoom. It is used to defind the top (if not
|
|
103
|
+
previously defined).
|
|
104
|
+
- label: str, default None
|
|
105
|
+
Associates a label to each line. Such labels will be used for the
|
|
106
|
+
creation of the legend.
|
|
107
|
+
- labelsize: float, default fontsize
|
|
108
|
+
Sets the labels fontsize (which is the same for both labels).
|
|
109
|
+
The default value corresponds to the value of the keyword
|
|
110
|
+
'fontsize'.
|
|
111
|
+
- left: float, default 0.6
|
|
112
|
+
Left position of the inset plot.
|
|
113
|
+
- minorticks: str, default None
|
|
114
|
+
If not None enables the minor ticks on the plot (for both grid
|
|
115
|
+
axes).
|
|
116
|
+
- pos: [float,float,float,float], default None
|
|
117
|
+
Position of the inset plot (left, right, bottom, top).
|
|
118
|
+
If missing the code will look for the single keywords
|
|
119
|
+
(top/bottom, left, width, height).
|
|
120
|
+
- shading: {'flat,'nearest','auto','gouraud'}, default 'auto'
|
|
121
|
+
The shading between the grid points. If not defined, the shading
|
|
122
|
+
will be one between 'flat' and 'nearest' depending on the size of
|
|
123
|
+
the x,y and z arrays. The 'flat' shading works only if, given a NxM
|
|
124
|
+
z-array, the x- and y-arrays have sizes of, respectively, N+1 and
|
|
125
|
+
M+1. All the other shadings require a N x-array and a M y-array.
|
|
126
|
+
- ticksdir: {'in', 'out'}, default 'in'
|
|
127
|
+
Sets the ticks direction. The default option is 'in'.
|
|
128
|
+
- tickssize: float, default fontsize
|
|
129
|
+
Sets the ticks fontsize (which is the same for both grid axes).
|
|
130
|
+
The default value corresponds to the value of the keyword
|
|
131
|
+
'fontsize'.
|
|
132
|
+
- title: str, default None
|
|
133
|
+
Places the title of the plot on top of it.
|
|
134
|
+
- titlesize: float, default fontsize
|
|
135
|
+
Sets the title fontsize. The default value corresponds to the value
|
|
136
|
+
of the keyword 'fontsize'.
|
|
137
|
+
- top: float, default bottom + height
|
|
138
|
+
Top position of the inset plot. If both top and bottom keywords are
|
|
139
|
+
present the priority will go to the top keyword.
|
|
140
|
+
- transpose: True/False, default False
|
|
141
|
+
Transposes the variable matrix. Use is not recommended if not really
|
|
142
|
+
necessary (e.g. in case of highly customized variables and plots)
|
|
143
|
+
- tresh: float, default max(abs(vmin),vmax)*0.01
|
|
144
|
+
Additional parameter in presence of a composite colormap. The
|
|
145
|
+
specific cases are the following:
|
|
146
|
+
- twoslope colorscale: sets the limit between the two linear
|
|
147
|
+
regimes.
|
|
148
|
+
- symlog: sets the limit between the logarithmic and the linear
|
|
149
|
+
regime.
|
|
150
|
+
- var: 2D array
|
|
151
|
+
The array to be plotted.
|
|
152
|
+
- vmax: float, default max(z)
|
|
153
|
+
The maximum value of the colormap. If not defined, the maximum value
|
|
154
|
+
of z will be taken.
|
|
155
|
+
- vmin: float, default min(z)
|
|
156
|
+
The minimum value of the colormap. If not defined, the minimum value
|
|
157
|
+
of z will be taken.
|
|
158
|
+
- width: float, default 0.15
|
|
159
|
+
Width of the inset zoom. It is used to define the right border.
|
|
160
|
+
- x1: 1D/2D array, default 'Default'
|
|
161
|
+
the 'x' array. If not defined, a default array will be generated
|
|
162
|
+
depending on the size of z.
|
|
163
|
+
- x2: 1D/2D array, default 'Default'
|
|
164
|
+
the 'y' array. If not defined, a default array will be generated
|
|
165
|
+
depending on the size of z.
|
|
166
|
+
- xrange: [float, float], default [0,1]
|
|
167
|
+
Sets the range in the x-direction. If not defined the code will
|
|
168
|
+
compute the range while plotting the data.
|
|
169
|
+
- xscale: {'linear','log'}, default 'linear'
|
|
170
|
+
If enabled (and different from 'Default'), sets automatically the
|
|
171
|
+
scale on the x-axis. Data in log scale should be used with the
|
|
172
|
+
keyword 'log', while data in linear scale should be used with the
|
|
173
|
+
keyword 'linear'.
|
|
174
|
+
- xticks: {[float], None, 'Default'}, default 'Default'
|
|
175
|
+
If enabled (and different from 'Default'), sets manually ticks on
|
|
176
|
+
x-axis. In order to completely remove the ticks the keyword should
|
|
177
|
+
be used with None.
|
|
178
|
+
- xtickslabels: {[str], None, 'Default'}, default 'Default'
|
|
179
|
+
If enabled (and different from 'Default'), sets manually the ticks
|
|
180
|
+
labels on the x-axis. In order to completely remove the ticks the
|
|
181
|
+
keyword should be used with None. Note that fixed tickslabels should
|
|
182
|
+
always correspond to fixed ticks.
|
|
183
|
+
- xtitle: str, default None
|
|
184
|
+
Sets and places the label of the x-axis.
|
|
185
|
+
- yrange: [float, float], default [0,1]
|
|
186
|
+
Sets the range in the y-direction. If not defined the code will
|
|
187
|
+
compute the range while plotting the data.
|
|
188
|
+
- yscale: {'linear','log'}, default 'linear'
|
|
189
|
+
If enabled (and different from 'Default'), sets automatically the
|
|
190
|
+
scale on the y-axis. Data in log scale should be used with the
|
|
191
|
+
keyword 'log', while data in linear scale should be used with the
|
|
192
|
+
keyword 'linear'.
|
|
193
|
+
- yticks: {[float], None, 'Default'}, default 'Default'
|
|
194
|
+
If enabled (and different from 'Default'), sets manually ticks on
|
|
195
|
+
y-axis. In order to completely remove the ticks the keyword should
|
|
196
|
+
be used with None.
|
|
197
|
+
- ytickslabels: {[str], None, 'Default'}, default 'Default'
|
|
198
|
+
If enabled (and different from 'Default'), sets manually the ticks
|
|
199
|
+
labels on the y-axis. In order to completely remove the ticks the
|
|
200
|
+
keyword should be used with None. Note that fixed tickslabels should
|
|
201
|
+
always correspond to fixed ticks.
|
|
202
|
+
- ytitle: str, default None
|
|
203
|
+
Sets and places the label of the y-axis.
|
|
204
|
+
- zoomcolor: str, default 'k'
|
|
205
|
+
Sets the color of the inset zoom lines
|
|
206
|
+
- zoomlines: bool, default True
|
|
207
|
+
Keyword in order to add/remove the inset zoom lines. The default
|
|
208
|
+
option is True.
|
|
209
|
+
|
|
210
|
+
----
|
|
211
|
+
|
|
212
|
+
Examples
|
|
213
|
+
--------
|
|
214
|
+
- Example #1: create a simple zoom of a 1d plot
|
|
215
|
+
|
|
216
|
+
>>> import pyPLUTO as pp
|
|
217
|
+
>>> I = pp.Image()
|
|
218
|
+
>>> I.plot(x1, var)
|
|
219
|
+
>>> I.zoom(pos = [0.1,0.2,0.1,0.3], xrange = [1,10], y
|
|
220
|
+
... range = [10,20])
|
|
221
|
+
|
|
222
|
+
- Example #2: create a simple zoom of a 2d plot
|
|
223
|
+
|
|
224
|
+
>>> import pyPLUTO as pp
|
|
225
|
+
>>> I = pp.Image()
|
|
226
|
+
>>> I.display(var, x1=x1, x2=x2)
|
|
227
|
+
>>> I.zoom(
|
|
228
|
+
... left=0.8,
|
|
229
|
+
... bottom=0.9,
|
|
230
|
+
... height=0.2,
|
|
231
|
+
... width=0.2,
|
|
232
|
+
... xrange=[1, 10],
|
|
233
|
+
... yrange=[10, 20],
|
|
234
|
+
... )
|
|
235
|
+
|
|
236
|
+
- Example #3: create a zoom of a different quantity over a 2d plot
|
|
237
|
+
|
|
238
|
+
>>> import pyPLUTO as pp
|
|
239
|
+
>>> I = pp.Image()
|
|
240
|
+
>>> I.display(var, x1=x1, x2=x2)
|
|
241
|
+
>>> I.zoom(var=var2, xrange=[1, 10], yrange=[10, 20])
|
|
242
|
+
|
|
243
|
+
"""
|
|
244
|
+
kwargs.pop("check", check)
|
|
245
|
+
|
|
246
|
+
self.tight = False
|
|
247
|
+
|
|
248
|
+
# Set or create figure and axes
|
|
249
|
+
ax, nax = self.ImageToolsManager.assign_ax(ax, **kwargs)
|
|
250
|
+
|
|
251
|
+
if self.fig is None:
|
|
252
|
+
raise ValueError(
|
|
253
|
+
"No figure is present. Please create a figure first."
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
# Sets position of the zoom
|
|
257
|
+
if kwargs.get("pos"):
|
|
258
|
+
axins = self.place_inset_pos(ax, kwargs["pos"])
|
|
259
|
+
else:
|
|
260
|
+
axins = self.place_inset_loc(ax, **kwargs)
|
|
261
|
+
kwargs["fontsize"] = kwargs.get("fontsize", self.fontsize)
|
|
262
|
+
kwargs["titlesize"] = kwargs.get("titlesize", self.fontsize)
|
|
263
|
+
|
|
264
|
+
self.ax.append(axins)
|
|
265
|
+
self.CreateAxesManager.add_ax(axins, len(self.ax))
|
|
266
|
+
|
|
267
|
+
# Set ticks (None is the default value)
|
|
268
|
+
if "xticks" not in kwargs:
|
|
269
|
+
kwargs["xticks"] = None
|
|
270
|
+
if "yticks" not in kwargs:
|
|
271
|
+
kwargs["yticks"] = None
|
|
272
|
+
|
|
273
|
+
self.AxisManager.set_axis(ax=axins, check=False, **kwargs)
|
|
274
|
+
|
|
275
|
+
pcm = ax.collections
|
|
276
|
+
|
|
277
|
+
# Plots the lines
|
|
278
|
+
pcm = ax.collections
|
|
279
|
+
if len(pcm) > 0:
|
|
280
|
+
self.zoomdisplay(ax, nax, axins, **kwargs)
|
|
281
|
+
else:
|
|
282
|
+
self.zoomplot(ax, axins)
|
|
283
|
+
|
|
284
|
+
# Indicates the inset zoom
|
|
285
|
+
zoomc = kwargs.get("zoomcolor", "k")
|
|
286
|
+
if kwargs.get("zoomlines", True) is True:
|
|
287
|
+
ax.indicate_inset_zoom(axins, edgecolor=zoomc)
|
|
288
|
+
|
|
289
|
+
axins.spines["left"].set_color(zoomc)
|
|
290
|
+
axins.spines["bottom"].set_color(zoomc)
|
|
291
|
+
axins.spines["right"].set_color(zoomc)
|
|
292
|
+
axins.spines["top"].set_color(zoomc)
|
|
293
|
+
|
|
294
|
+
return axins
|
|
295
|
+
|
|
296
|
+
def zoomplot(self, ax: Axes, axins: Axes) -> None:
|
|
297
|
+
"""Plot the lines on the inset zoom."""
|
|
298
|
+
lines = ax.get_lines()
|
|
299
|
+
for i in lines:
|
|
300
|
+
self.PlotManager.plot(
|
|
301
|
+
i.get_xdata(),
|
|
302
|
+
i.get_ydata(),
|
|
303
|
+
c=i.get_color(),
|
|
304
|
+
ls=i.get_linestyle(),
|
|
305
|
+
lw=i.get_linewidth(),
|
|
306
|
+
marker=i.get_marker(),
|
|
307
|
+
ms=i.get_markersize(),
|
|
308
|
+
ax=axins,
|
|
309
|
+
)
|
|
310
|
+
|
|
311
|
+
@track_kwargs
|
|
312
|
+
def zoomdisplay(
|
|
313
|
+
self, ax: Axes, nax: int, axins: Axes, **kwargs: Any
|
|
314
|
+
) -> None:
|
|
315
|
+
"""Plot the zoom on the inset zoom, for a display plot."""
|
|
316
|
+
pcm = ax.collections[0]
|
|
317
|
+
pnr = str(pcm.norm).split()[0].split(".")[2]
|
|
318
|
+
dict_norm = {
|
|
319
|
+
"Normalize": "norm",
|
|
320
|
+
"LogNorm": "log",
|
|
321
|
+
"SymLogNorm": "symlog",
|
|
322
|
+
"TwoSlopeNorm": "twoslope",
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
kwargs["cmap"] = kwargs.pop("cmap", pcm.cmap)
|
|
326
|
+
kwargs["cscale"] = kwargs.pop("cscale", dict_norm[pnr])
|
|
327
|
+
|
|
328
|
+
if not isinstance(pcm, QuadMesh):
|
|
329
|
+
raise TypeError(
|
|
330
|
+
"The zoom can be applied only to a QuadMesh object."
|
|
331
|
+
)
|
|
332
|
+
|
|
333
|
+
ccd = cast(np.ndarray[Any, Any], pcm.get_coordinates())
|
|
334
|
+
xc = kwargs.pop("x1", ccd[:, :, 0])
|
|
335
|
+
yc = kwargs.pop("x2", ccd[:, :, 1])
|
|
336
|
+
|
|
337
|
+
psh = kwargs.pop("shading", getattr(pcm, "_shading", "flat"))
|
|
338
|
+
leny = len(xc[0]) if np.ndim(yc) > 1 else len(yc)
|
|
339
|
+
lxc = len(xc) - 1 if psh == "flat" else len(xc)
|
|
340
|
+
lyc = leny - 1 if psh == "flat" else leny
|
|
341
|
+
# if psh == 'flat':
|
|
342
|
+
# lxc = len(xc) - 1
|
|
343
|
+
# lyc = len(xc[0]) - 1
|
|
344
|
+
# else:
|
|
345
|
+
# lxc = len(xc)
|
|
346
|
+
# lyc = len(xc[0])
|
|
347
|
+
arr = pcm.get_array()
|
|
348
|
+
if "var" in kwargs and arr is not None:
|
|
349
|
+
pcm0 = kwargs.pop("var", None)
|
|
350
|
+
elif arr is not None:
|
|
351
|
+
pcm0 = arr.reshape((lxc, lyc)).T
|
|
352
|
+
else:
|
|
353
|
+
raise ValueError(
|
|
354
|
+
"No variable is present in the zoom display. "
|
|
355
|
+
"Please provide a variable to plot."
|
|
356
|
+
)
|
|
357
|
+
# pcm0 = kwargs.pop('var', pcm.reshape((lxc, lyc)).T)
|
|
358
|
+
kwargs["vmin"] = kwargs.pop("vmin", self.vlims[nax][0])
|
|
359
|
+
kwargs["vmax"] = kwargs.pop("vmax", self.vlims[nax][1])
|
|
360
|
+
kwargs["tresh"] = kwargs.pop("tresh", self.vlims[nax][2])
|
|
361
|
+
|
|
362
|
+
self.DisplayManager.display(
|
|
363
|
+
pcm0, x1=xc, x2=yc, ax=axins, check=False, shading=psh, **kwargs
|
|
364
|
+
)
|
|
365
|
+
|
|
366
|
+
def place_inset_pos(self, ax: Axes, pos: list[float]) -> Axes:
|
|
367
|
+
"""Place an inset axes given the position (left, top, bottom, right).
|
|
368
|
+
|
|
369
|
+
Returns
|
|
370
|
+
-------
|
|
371
|
+
- The inset axes
|
|
372
|
+
|
|
373
|
+
Parameters
|
|
374
|
+
----------
|
|
375
|
+
- ax: ax object
|
|
376
|
+
The axis where the inset axes is placed.
|
|
377
|
+
- pos: list[float]
|
|
378
|
+
The position of the inset axes.
|
|
379
|
+
|
|
380
|
+
"""
|
|
381
|
+
# Compute the position of the inset axis and return it
|
|
382
|
+
left = pos[0]
|
|
383
|
+
bottom = pos[2]
|
|
384
|
+
width = pos[1] - pos[0]
|
|
385
|
+
height = pos[3] - pos[2]
|
|
386
|
+
return ax.inset_axes((left, bottom, width, height))
|
|
387
|
+
|
|
388
|
+
def place_inset_loc(self, ax: Axes, **kwargs: Any) -> Axes:
|
|
389
|
+
"""Place an inset axes given different keywords.
|
|
390
|
+
|
|
391
|
+
In case both top and bottom are given, the top is given priority and a
|
|
392
|
+
warning is raised.
|
|
393
|
+
|
|
394
|
+
Returns
|
|
395
|
+
-------
|
|
396
|
+
- The inset axes
|
|
397
|
+
|
|
398
|
+
Parameters
|
|
399
|
+
----------
|
|
400
|
+
- ax: ax object
|
|
401
|
+
The axis where the inset axes is placed.
|
|
402
|
+
- left: float
|
|
403
|
+
The left boundary of the axes.
|
|
404
|
+
- top: float
|
|
405
|
+
The top boundary of the axes.
|
|
406
|
+
- bottom: float
|
|
407
|
+
The bottom boundary of the axes.
|
|
408
|
+
- width: float
|
|
409
|
+
The width of the inset axis.
|
|
410
|
+
- height: float
|
|
411
|
+
The height of the inset axis.
|
|
412
|
+
|
|
413
|
+
"""
|
|
414
|
+
# Check if both "top" and "bottom" keywords are given
|
|
415
|
+
if kwargs.get("top") and kwargs.get("bottom"):
|
|
416
|
+
warn = (
|
|
417
|
+
"Both top and bottom keys are given, priority goes to the top"
|
|
418
|
+
)
|
|
419
|
+
warnings.warn(warn, UserWarning, stacklevel=2)
|
|
420
|
+
|
|
421
|
+
# Compute the position of the inset axis and return it
|
|
422
|
+
left = kwargs.get("left", 0.6)
|
|
423
|
+
width = kwargs.get("width", 0.2)
|
|
424
|
+
height = kwargs.get("height", 0.15)
|
|
425
|
+
bottom = kwargs.get("top", 0.75) - height
|
|
426
|
+
bottom = kwargs.get("bottom", 0.6)
|
|
427
|
+
|
|
428
|
+
return ax.inset_axes((left, bottom, width, height))
|
pyPLUTO/imagemixin.py
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
"""Mixin class for image handling."""
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from matplotlib.axes import Axes
|
|
6
|
+
from matplotlib.figure import Figure
|
|
7
|
+
|
|
8
|
+
from pyPLUTO.imagestate import ImageState
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class ImageMixin:
|
|
12
|
+
"""Mixin class for image handling.
|
|
13
|
+
|
|
14
|
+
It provides properties and methods related to the image state and axes.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
# pylint: disable=too-many-public-methods
|
|
18
|
+
|
|
19
|
+
state: ImageState
|
|
20
|
+
|
|
21
|
+
@property
|
|
22
|
+
def ax(self) -> list[Axes]:
|
|
23
|
+
"""Get the ax attribute of the image."""
|
|
24
|
+
return self.state.ax
|
|
25
|
+
|
|
26
|
+
@ax.setter
|
|
27
|
+
def ax(self, value: list[Axes]) -> None:
|
|
28
|
+
"""Set the ax attribute of the image."""
|
|
29
|
+
self.state.ax = value
|
|
30
|
+
|
|
31
|
+
@property
|
|
32
|
+
def color(self) -> list[str]:
|
|
33
|
+
"""Get the color attribute of the image."""
|
|
34
|
+
return self.state.color
|
|
35
|
+
|
|
36
|
+
@color.setter
|
|
37
|
+
def color(self, value: list[str]) -> None:
|
|
38
|
+
"""Set the color attribute of the image."""
|
|
39
|
+
self.state.color = value
|
|
40
|
+
|
|
41
|
+
@property
|
|
42
|
+
def dictcol(self) -> dict[int, str]:
|
|
43
|
+
"""Get the dictcol attribute of the image."""
|
|
44
|
+
return self.state.dictcol
|
|
45
|
+
|
|
46
|
+
@dictcol.setter
|
|
47
|
+
def dictcol(self, value: dict[int, str]) -> None:
|
|
48
|
+
"""Set the dictcol attribute of the image."""
|
|
49
|
+
self.state.dictcol = value
|
|
50
|
+
|
|
51
|
+
@property
|
|
52
|
+
def fig(self) -> Figure | None:
|
|
53
|
+
"""Get the fig attribute of the image."""
|
|
54
|
+
return self.state.fig
|
|
55
|
+
|
|
56
|
+
@fig.setter
|
|
57
|
+
def fig(self, value: Figure | None) -> None:
|
|
58
|
+
"""Set the fig attribute of the image."""
|
|
59
|
+
self.state.fig = value
|
|
60
|
+
|
|
61
|
+
@property
|
|
62
|
+
def figsize(self) -> list[float]:
|
|
63
|
+
"""Get the figsize attribute of the image."""
|
|
64
|
+
return self.state.figsize
|
|
65
|
+
|
|
66
|
+
@figsize.setter
|
|
67
|
+
def figsize(self, value: list[float]) -> None:
|
|
68
|
+
"""Set the figsize attribute of the image."""
|
|
69
|
+
self.state.figsize = value
|
|
70
|
+
|
|
71
|
+
@property
|
|
72
|
+
def fontsize(self) -> int:
|
|
73
|
+
"""Get the fontsize attribute of the image."""
|
|
74
|
+
return self.state.fontsize
|
|
75
|
+
|
|
76
|
+
@fontsize.setter
|
|
77
|
+
def fontsize(self, value: int) -> None:
|
|
78
|
+
"""Set the fontsize attribute of the image."""
|
|
79
|
+
self.state.fontsize = value
|
|
80
|
+
|
|
81
|
+
@property
|
|
82
|
+
def LaTeX(self) -> bool | str:
|
|
83
|
+
"""Get the LaTeX attribute of the image."""
|
|
84
|
+
return self.state.LaTeX
|
|
85
|
+
|
|
86
|
+
@LaTeX.setter
|
|
87
|
+
def LaTeX(self, value: bool | str) -> None:
|
|
88
|
+
"""Set the LaTeX attribute of the image."""
|
|
89
|
+
self.state.LaTeX = value
|
|
90
|
+
|
|
91
|
+
@property
|
|
92
|
+
def legpar(self) -> list[list[float]]:
|
|
93
|
+
"""Get the legpar attribute of the image."""
|
|
94
|
+
return self.state.legpar
|
|
95
|
+
|
|
96
|
+
@legpar.setter
|
|
97
|
+
def legpar(self, value: list[list[float]]) -> None:
|
|
98
|
+
"""Set the legpar attribute of the image."""
|
|
99
|
+
self.state.legpar = value
|
|
100
|
+
|
|
101
|
+
@property
|
|
102
|
+
def legpos(self) -> list[int | str | None]:
|
|
103
|
+
"""Get the legpos attribute of the image."""
|
|
104
|
+
return self.state.legpos
|
|
105
|
+
|
|
106
|
+
@legpos.setter
|
|
107
|
+
def legpos(self, value: list[int | str | None]) -> None:
|
|
108
|
+
"""Set the legpos attribute of the image."""
|
|
109
|
+
self.state.legpos = value
|
|
110
|
+
|
|
111
|
+
@property
|
|
112
|
+
def ncol0(self) -> int:
|
|
113
|
+
"""Get the ncol0 attribute of the image."""
|
|
114
|
+
return self.state.ncol0
|
|
115
|
+
|
|
116
|
+
@ncol0.setter
|
|
117
|
+
def ncol0(self, value: int) -> None:
|
|
118
|
+
"""Set the ncol0 attribute of the image."""
|
|
119
|
+
self.state.ncol0 = value
|
|
120
|
+
|
|
121
|
+
@property
|
|
122
|
+
def nline(self) -> list[int]:
|
|
123
|
+
"""Get the nline attribute of the image."""
|
|
124
|
+
return self.state.nline
|
|
125
|
+
|
|
126
|
+
@nline.setter
|
|
127
|
+
def nline(self, value: list[int]) -> None:
|
|
128
|
+
"""Set the nline attribute of the image."""
|
|
129
|
+
self.state.nline = value
|
|
130
|
+
|
|
131
|
+
@property
|
|
132
|
+
def nrow0(self) -> int:
|
|
133
|
+
"""Get the nrow0 attribute of the image."""
|
|
134
|
+
return self.state.nrow0
|
|
135
|
+
|
|
136
|
+
@nrow0.setter
|
|
137
|
+
def nrow0(self, value: int) -> None:
|
|
138
|
+
"""Set the nrow0 attribute of the image."""
|
|
139
|
+
self.state.nrow0 = value
|
|
140
|
+
|
|
141
|
+
@property
|
|
142
|
+
def ntext(self) -> list[Any | None]:
|
|
143
|
+
"""Get the ntext attribute of the image."""
|
|
144
|
+
return self.state.ntext
|
|
145
|
+
|
|
146
|
+
@ntext.setter
|
|
147
|
+
def ntext(self, value: list[Any | None]) -> None:
|
|
148
|
+
"""Set the ntext attribute of the image."""
|
|
149
|
+
self.state.ntext = value
|
|
150
|
+
|
|
151
|
+
@property
|
|
152
|
+
def nwin(self) -> int:
|
|
153
|
+
"""Get the nwin attribute of the image."""
|
|
154
|
+
return self.state.nwin
|
|
155
|
+
|
|
156
|
+
@nwin.setter
|
|
157
|
+
def nwin(self, value: int) -> None:
|
|
158
|
+
"""Set the nwin attribute of the image."""
|
|
159
|
+
self.state.nwin = value
|
|
160
|
+
|
|
161
|
+
@property
|
|
162
|
+
def setax(self) -> list[Any | int]:
|
|
163
|
+
"""Get the setax attribute of the image."""
|
|
164
|
+
return self.state.setax
|
|
165
|
+
|
|
166
|
+
@setax.setter
|
|
167
|
+
def setax(self, value: list[Any | int]) -> None:
|
|
168
|
+
"""Set the setax attribute of the image."""
|
|
169
|
+
self.state.setax = value
|
|
170
|
+
|
|
171
|
+
@property
|
|
172
|
+
def setay(self) -> list[Any | int]:
|
|
173
|
+
"""Get the setay attribute of the image."""
|
|
174
|
+
return self.state.setay
|
|
175
|
+
|
|
176
|
+
@setay.setter
|
|
177
|
+
def setay(self, value: list[Any | int]) -> None:
|
|
178
|
+
"""Set the setay attribute of the image."""
|
|
179
|
+
self.state.setay = value
|
|
180
|
+
|
|
181
|
+
@property
|
|
182
|
+
def set_size(self) -> bool:
|
|
183
|
+
"""Get the set_size attribute of the image."""
|
|
184
|
+
return self.state.set_size
|
|
185
|
+
|
|
186
|
+
@set_size.setter
|
|
187
|
+
def set_size(self, value: bool) -> None:
|
|
188
|
+
"""Set the set_size attribute of the image."""
|
|
189
|
+
self.state.set_size = value
|
|
190
|
+
|
|
191
|
+
@property
|
|
192
|
+
def shade(self) -> list[str]:
|
|
193
|
+
"""Get the shade attribute of the image."""
|
|
194
|
+
return self.state.shade
|
|
195
|
+
|
|
196
|
+
@shade.setter
|
|
197
|
+
def shade(self, value: list[str]) -> None:
|
|
198
|
+
"""Set the shade attribute of the image."""
|
|
199
|
+
self.state.shade = value
|
|
200
|
+
|
|
201
|
+
@property
|
|
202
|
+
def style(self) -> str:
|
|
203
|
+
"""Get the style attribute of the image."""
|
|
204
|
+
return self.state.style
|
|
205
|
+
|
|
206
|
+
@style.setter
|
|
207
|
+
def style(self, value: str) -> None:
|
|
208
|
+
"""Set the style attribute of the image."""
|
|
209
|
+
self.state.style = value
|
|
210
|
+
|
|
211
|
+
@property
|
|
212
|
+
def tickspar(self) -> list[Any | int]:
|
|
213
|
+
"""Get the tickspar attribute of the image."""
|
|
214
|
+
return self.state.tickspar
|
|
215
|
+
|
|
216
|
+
@tickspar.setter
|
|
217
|
+
def tickspar(self, value: list[Any | int]) -> None:
|
|
218
|
+
"""Set the tickspar attribute of the image."""
|
|
219
|
+
self.state.tickspar = value
|
|
220
|
+
|
|
221
|
+
@property
|
|
222
|
+
def tight(self) -> bool:
|
|
223
|
+
"""Get the tight attribute of the image."""
|
|
224
|
+
return self.state.tight
|
|
225
|
+
|
|
226
|
+
@tight.setter
|
|
227
|
+
def tight(self, value: bool) -> None:
|
|
228
|
+
"""Set the tight attribute of the image."""
|
|
229
|
+
self.state.tight = value
|
|
230
|
+
|
|
231
|
+
@property
|
|
232
|
+
def vlims(self) -> list[list[float]]:
|
|
233
|
+
"""Get the vlims attribute of the image."""
|
|
234
|
+
return self.state.vlims
|
|
235
|
+
|
|
236
|
+
@vlims.setter
|
|
237
|
+
def vlims(self, value: list[list[float]]) -> None:
|
|
238
|
+
"""Set the vlims attribute of the image."""
|
|
239
|
+
self.state.vlims = value
|
|
240
|
+
|
|
241
|
+
@property
|
|
242
|
+
def xscale(self) -> list[str]:
|
|
243
|
+
"""Get the xscale attribute of the image."""
|
|
244
|
+
return self.state.xscale
|
|
245
|
+
|
|
246
|
+
@xscale.setter
|
|
247
|
+
def xscale(self, value: list[str]) -> None:
|
|
248
|
+
"""Set the xscale attribute of the image."""
|
|
249
|
+
self.state.xscale = value
|
|
250
|
+
|
|
251
|
+
@property
|
|
252
|
+
def yscale(self) -> list[str]:
|
|
253
|
+
"""Get the yscale attribute of the image."""
|
|
254
|
+
return self.state.yscale
|
|
255
|
+
|
|
256
|
+
@yscale.setter
|
|
257
|
+
def yscale(self, value: list[str]) -> None:
|
|
258
|
+
"""Set the yscale attribute of the image."""
|
|
259
|
+
self.state.yscale = value
|