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.
Files changed (73) hide show
  1. pyPLUTO/__init__.py +22 -0
  2. pyPLUTO/amr.py +745 -0
  3. pyPLUTO/baseloadmixin.py +258 -0
  4. pyPLUTO/baseloadstate.py +45 -0
  5. pyPLUTO/codes/echo_load.py +161 -0
  6. pyPLUTO/configure.py +261 -0
  7. pyPLUTO/gui/config.py +174 -0
  8. pyPLUTO/gui/custom_var.py +435 -0
  9. pyPLUTO/gui/globals.py +108 -0
  10. pyPLUTO/gui/main.py +17 -0
  11. pyPLUTO/gui/main_window.py +177 -0
  12. pyPLUTO/gui/panels.py +66 -0
  13. pyPLUTO/gui/utils.py +273 -0
  14. pyPLUTO/h_pypluto.py +84 -0
  15. pyPLUTO/image.py +302 -0
  16. pyPLUTO/imagefuncs/colorbar.py +240 -0
  17. pyPLUTO/imagefuncs/contour.py +254 -0
  18. pyPLUTO/imagefuncs/create_axes.py +464 -0
  19. pyPLUTO/imagefuncs/display.py +306 -0
  20. pyPLUTO/imagefuncs/figure.py +395 -0
  21. pyPLUTO/imagefuncs/imagetools.py +487 -0
  22. pyPLUTO/imagefuncs/interactive.py +403 -0
  23. pyPLUTO/imagefuncs/legend.py +250 -0
  24. pyPLUTO/imagefuncs/plot.py +311 -0
  25. pyPLUTO/imagefuncs/range.py +242 -0
  26. pyPLUTO/imagefuncs/scatter.py +270 -0
  27. pyPLUTO/imagefuncs/set_axis.py +497 -0
  28. pyPLUTO/imagefuncs/streamplot.py +297 -0
  29. pyPLUTO/imagefuncs/zoom.py +428 -0
  30. pyPLUTO/imagemixin.py +259 -0
  31. pyPLUTO/imagestate.py +45 -0
  32. pyPLUTO/load.py +447 -0
  33. pyPLUTO/loadfuncs/baseloadtools.py +71 -0
  34. pyPLUTO/loadfuncs/codeselection.py +48 -0
  35. pyPLUTO/loadfuncs/defpluto.py +123 -0
  36. pyPLUTO/loadfuncs/descriptor.py +102 -0
  37. pyPLUTO/loadfuncs/findfiles.py +182 -0
  38. pyPLUTO/loadfuncs/findformat.py +245 -0
  39. pyPLUTO/loadfuncs/initload.py +203 -0
  40. pyPLUTO/loadfuncs/loadvars.py +227 -0
  41. pyPLUTO/loadfuncs/offsetdata.py +87 -0
  42. pyPLUTO/loadfuncs/offsetfluid.py +408 -0
  43. pyPLUTO/loadfuncs/read_files.py +213 -0
  44. pyPLUTO/loadfuncs/readdata.py +619 -0
  45. pyPLUTO/loadfuncs/readdata_old.py +567 -0
  46. pyPLUTO/loadfuncs/readdefplini.py +101 -0
  47. pyPLUTO/loadfuncs/readfluid.py +479 -0
  48. pyPLUTO/loadfuncs/readformat.py +277 -0
  49. pyPLUTO/loadfuncs/readgridalone.py +224 -0
  50. pyPLUTO/loadfuncs/readgridfile.py +255 -0
  51. pyPLUTO/loadfuncs/readgridout.py +451 -0
  52. pyPLUTO/loadfuncs/readpart.py +419 -0
  53. pyPLUTO/loadfuncs/readtab.py +105 -0
  54. pyPLUTO/loadfuncs/write_files.py +283 -0
  55. pyPLUTO/loadmixin.py +419 -0
  56. pyPLUTO/loadpart.py +233 -0
  57. pyPLUTO/loadstate.py +68 -0
  58. pyPLUTO/newload.py +81 -0
  59. pyPLUTO/pytools.py +145 -0
  60. pyPLUTO/toolfuncs/findlines.py +551 -0
  61. pyPLUTO/toolfuncs/fourier.py +149 -0
  62. pyPLUTO/toolfuncs/nabla.py +676 -0
  63. pyPLUTO/toolfuncs/parttools.py +152 -0
  64. pyPLUTO/toolfuncs/transform.py +638 -0
  65. pyPLUTO/utils/annotator.py +27 -0
  66. pyPLUTO/utils/inspector.py +145 -0
  67. pyPLUTO/utils/make_docstrings.py +3 -0
  68. py_pluto-1.1.4.dist-info/METADATA +218 -0
  69. py_pluto-1.1.4.dist-info/RECORD +73 -0
  70. py_pluto-1.1.4.dist-info/WHEEL +5 -0
  71. py_pluto-1.1.4.dist-info/entry_points.txt +2 -0
  72. py_pluto-1.1.4.dist-info/licenses/LICENSE +27 -0
  73. 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