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,152 @@
|
|
|
1
|
+
import warnings
|
|
2
|
+
from collections.abc import Callable
|
|
3
|
+
|
|
4
|
+
import numpy as np
|
|
5
|
+
|
|
6
|
+
from ..h_pypluto import check_par
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def spectrum(
|
|
10
|
+
self, var=None, scale="lin", check: bool = True, **kwargs
|
|
11
|
+
) -> list[np.ndarray]:
|
|
12
|
+
"""Compute the spectrum of a given particle variable.
|
|
13
|
+
|
|
14
|
+
Returns
|
|
15
|
+
-------
|
|
16
|
+
- bins: np.ndarray
|
|
17
|
+
The x1 array of the histogram.
|
|
18
|
+
- hist: np.ndarray
|
|
19
|
+
The x2 array of the histogram.
|
|
20
|
+
|
|
21
|
+
Parameters
|
|
22
|
+
----------
|
|
23
|
+
- density: bool, default False
|
|
24
|
+
If True, the histogram is normalized.
|
|
25
|
+
- nbins: int
|
|
26
|
+
The number of bins wanted for the histogram.
|
|
27
|
+
- scale: {'lin','log'}, default 'lin'
|
|
28
|
+
The scale of the histogram, linear or logarithmic.
|
|
29
|
+
- var: np.ndarray
|
|
30
|
+
The chosen variable for the histogram.
|
|
31
|
+
- vmin: float
|
|
32
|
+
The minimum value of the chosen variable.
|
|
33
|
+
- vmax: float
|
|
34
|
+
The maximum value of the chosen variable.
|
|
35
|
+
|
|
36
|
+
----
|
|
37
|
+
|
|
38
|
+
Examples
|
|
39
|
+
--------
|
|
40
|
+
- Example #1: Compute the spectrum of the particles velocity
|
|
41
|
+
|
|
42
|
+
>>> import pyPLUTO as pp
|
|
43
|
+
>>> D = pp.LoadPart(0)
|
|
44
|
+
>>> v2 = D.vx1**2 + D.vx2**2 + D.vx3**2
|
|
45
|
+
>>> pp.spectrum(v2, scale="log")
|
|
46
|
+
|
|
47
|
+
"""
|
|
48
|
+
# Check parameters
|
|
49
|
+
param = {"density", "nbins", "vmin", "vmax"}
|
|
50
|
+
if check is True:
|
|
51
|
+
check_par(param, "spectrum", **kwargs)
|
|
52
|
+
|
|
53
|
+
# Set limits
|
|
54
|
+
vmin = kwargs.get("vmin", np.nanmin(var))
|
|
55
|
+
vmax = kwargs.get("vmax", np.nanmax(var))
|
|
56
|
+
|
|
57
|
+
# Set the number of bins
|
|
58
|
+
nbins = kwargs.get("nbins", 100)
|
|
59
|
+
|
|
60
|
+
# Set the bins
|
|
61
|
+
bins = (
|
|
62
|
+
np.linspace(vmin, vmax, nbins)
|
|
63
|
+
if scale == "lin"
|
|
64
|
+
else np.logspace(np.log10(vmin), np.log10(vmax), nbins)
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
bins = kwargs.get("bins") if bin in kwargs else bins
|
|
68
|
+
|
|
69
|
+
# Compute the histogram
|
|
70
|
+
hist, bins = np.histogram(
|
|
71
|
+
var, bins=bins, range=(vmin, vmax), density=kwargs.get("density", True)
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
# Compute the bin centers
|
|
75
|
+
bins = 0.5 * (bins[1:] + bins[:-1])
|
|
76
|
+
|
|
77
|
+
# Return the histogram
|
|
78
|
+
return hist, bins
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def select(
|
|
82
|
+
self,
|
|
83
|
+
var: np.ndarray,
|
|
84
|
+
cond: str | Callable,
|
|
85
|
+
sort: bool = False,
|
|
86
|
+
ascending: bool = True,
|
|
87
|
+
) -> np.ndarray:
|
|
88
|
+
"""Selects or sorts the indices that satisfy a given condition for
|
|
89
|
+
the particles. The condition is given by a string or a callable
|
|
90
|
+
function.
|
|
91
|
+
|
|
92
|
+
Returns
|
|
93
|
+
-------
|
|
94
|
+
- indx: np.ndarray
|
|
95
|
+
|
|
96
|
+
Parameters
|
|
97
|
+
----------
|
|
98
|
+
- ascending: bool, default True
|
|
99
|
+
If True, the indices are sorted in ascending order.
|
|
100
|
+
- cond (not optional): str | Callable
|
|
101
|
+
The condition to be satisfied.
|
|
102
|
+
- sort: bool, default False
|
|
103
|
+
If True, the indices are sorted in descending (or ascending) order.
|
|
104
|
+
- var (not optional): np.ndarray
|
|
105
|
+
The chosen variable for the selection.
|
|
106
|
+
|
|
107
|
+
----
|
|
108
|
+
|
|
109
|
+
Examples
|
|
110
|
+
--------
|
|
111
|
+
- Example #1: Select the indices that satisfy a condition
|
|
112
|
+
|
|
113
|
+
>>> import pyPLUTO as pp
|
|
114
|
+
>>> D = pp.LoadPart(0)
|
|
115
|
+
>>> indx = pp.select(D.vx1, "vx1 > 0.0")
|
|
116
|
+
>>> print(indx)
|
|
117
|
+
|
|
118
|
+
- Example #2: Sort the indices that satisfy a condition through a callable
|
|
119
|
+
|
|
120
|
+
>>> import pyPLUTO as pp
|
|
121
|
+
>>> D = pp.LoadPart(0)
|
|
122
|
+
>>> indx = pp.select(D.vx1, lambda v: v > 0 sort = True)
|
|
123
|
+
>>> print(indx)
|
|
124
|
+
|
|
125
|
+
"""
|
|
126
|
+
# Determine the indices that satisfy the condition
|
|
127
|
+
if isinstance(cond, str):
|
|
128
|
+
warn = (
|
|
129
|
+
"The condition should be a callable function to "
|
|
130
|
+
"avoid security issues."
|
|
131
|
+
)
|
|
132
|
+
warnings.warn(warn)
|
|
133
|
+
|
|
134
|
+
condition = f"var {cond}"
|
|
135
|
+
indx = np.where(eval(condition))[0]
|
|
136
|
+
|
|
137
|
+
elif callable(cond):
|
|
138
|
+
indx = np.where(cond(var))[0]
|
|
139
|
+
else:
|
|
140
|
+
err = (
|
|
141
|
+
"Condition must be either a string or a callable "
|
|
142
|
+
"(e.g., a lambda function)"
|
|
143
|
+
)
|
|
144
|
+
raise ValueError(err)
|
|
145
|
+
|
|
146
|
+
# Sort the indices if requested
|
|
147
|
+
if sort:
|
|
148
|
+
sort_order = np.argsort(var[indx])
|
|
149
|
+
sort_order = sort_order[::-1] if not ascending else sort_order
|
|
150
|
+
indx = indx[sort_order]
|
|
151
|
+
|
|
152
|
+
return indx
|