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,258 @@
1
+ """Mixin class for base load functionality."""
2
+
3
+ from pathlib import Path
4
+ from typing import Any, TypeVar
5
+
6
+ from numpy.typing import NDArray
7
+
8
+ from pyPLUTO.baseloadstate import BaseLoadState
9
+
10
+ S = TypeVar("S", bound=BaseLoadState)
11
+
12
+
13
+ class BaseLoadMixin[S: BaseLoadState]:
14
+ """Mixin class that provides base functionality for load state."""
15
+
16
+ # pylint: disable=too-many-public-methods
17
+
18
+ state: S
19
+
20
+ @property
21
+ def alone(self) -> bool:
22
+ """Get the alone attribute of the load state."""
23
+ return self.state.alone
24
+
25
+ @alone.setter
26
+ def alone(self, value: bool) -> None:
27
+ """Set the alone attribute of the load state."""
28
+ self.state.alone = value
29
+
30
+ @property
31
+ def charsize(self) -> int:
32
+ """Get the charsize attribute of the load state."""
33
+ return self.state.charsize
34
+
35
+ @charsize.setter
36
+ def charsize(self, value: int) -> None:
37
+ """Set the charsize attribute of the load state."""
38
+ self.state.charsize = value
39
+
40
+ @property
41
+ def class_name(self) -> str:
42
+ """Get the class_name attribute of the load state."""
43
+ return self.state.class_name
44
+
45
+ @class_name.setter
46
+ def class_name(self, value: str) -> None:
47
+ """Set the class_name attribute of the load state."""
48
+ self.state.class_name = value
49
+
50
+ @property
51
+ def code(self) -> str:
52
+ """Get the code attribute of the load state."""
53
+ return self.state.code
54
+
55
+ @code.setter
56
+ def code(self, value: str) -> None:
57
+ """Set the code attribute of the load state."""
58
+ self.state.code = value
59
+
60
+ @property
61
+ def d_info(self) -> dict[str, Any]:
62
+ """Get the d_info attribute of the load state."""
63
+ return self.state.d_info
64
+
65
+ @d_info.setter
66
+ def d_info(self, value: dict[str, Any]) -> None:
67
+ """Set the d_info attribute of the load state."""
68
+ self.state.d_info = value
69
+
70
+ @property
71
+ def d_vars(self) -> dict[str, Any]:
72
+ """Get the d_vars attribute of the load state."""
73
+ return self.state.d_vars
74
+
75
+ @d_vars.setter
76
+ def d_vars(self, value: dict[str, Any]) -> None:
77
+ """Set the d_vars attribute of the load state."""
78
+ self.state.d_vars = value
79
+
80
+ @property
81
+ def endian(self) -> str | None:
82
+ """Get the endian attribute of the load state."""
83
+ return self.state.endian
84
+
85
+ @endian.setter
86
+ def endian(self, value: str | None) -> None:
87
+ """Set the endian attribute of the load state."""
88
+ self.state.endian = value
89
+
90
+ @property
91
+ def filepath(self) -> Path:
92
+ """Get the filepath attribute of the load state."""
93
+ return self.state.filepath
94
+
95
+ @filepath.setter
96
+ def filepath(self, value: Path) -> None:
97
+ """Set the filepath attribute of the load state."""
98
+ self.state.filepath = value
99
+
100
+ @property
101
+ def format(self) -> str:
102
+ """Get the format attribute of the load state."""
103
+ return self.state.format
104
+
105
+ @format.setter
106
+ def format(self, value: str) -> None:
107
+ """Set the format attribute of the load state."""
108
+ self.state.format = value
109
+
110
+ @property
111
+ def infogrid(self) -> bool:
112
+ """Get the infogrid attribute of the load state."""
113
+ return self.state.infogrid
114
+
115
+ @infogrid.setter
116
+ def infogrid(self, value: bool) -> None:
117
+ """Set the infogrid attribute of the load state."""
118
+ self.state.infogrid = value
119
+
120
+ @property
121
+ def lennout(self) -> int:
122
+ """Get the lennout attribute of the load state."""
123
+ return self.state.lennout
124
+
125
+ @lennout.setter
126
+ def lennout(self, value: int) -> None:
127
+ """Set the lennout attribute of the load state."""
128
+ self.state.lennout = value
129
+
130
+ @property
131
+ def lennoutlist(self) -> int:
132
+ """Get the lenoutlist attribute of the load state."""
133
+ return self.state.lennoutlist
134
+
135
+ @lennoutlist.setter
136
+ def lennoutlist(self, value: int) -> None:
137
+ """Set the lennoutlist attribute of the load state."""
138
+ self.state.lennoutlist = value
139
+
140
+ @property
141
+ def matching_files(self) -> list[str] | None:
142
+ """Get the matching_files attribute of the load state."""
143
+ return self.state.matching_files
144
+
145
+ @matching_files.setter
146
+ def matching_files(self, value: list[str] | None) -> None:
147
+ """Set the matching_files attribute of the load state."""
148
+ self.state.matching_files = value
149
+
150
+ @property
151
+ def multiple(self) -> bool:
152
+ """Get the multiple attribute of the load state."""
153
+ return self.state.multiple
154
+
155
+ @multiple.setter
156
+ def multiple(self, value: bool) -> None:
157
+ """Set the multiple attribute of the load state."""
158
+ self.state.multiple = value
159
+
160
+ @property
161
+ def nout(self) -> int | NDArray[Any]:
162
+ """Get the nout attribute of the load state."""
163
+ return self.state.nout
164
+
165
+ @nout.setter
166
+ def nout(self, value: int | NDArray[Any]) -> None:
167
+ """Set the nout attribute of the load state."""
168
+ self.state.nout = value
169
+
170
+ @property
171
+ def noutlist(self) -> NDArray[Any]:
172
+ """Get the nout attribute of the load state."""
173
+ return self.state.noutlist
174
+
175
+ @noutlist.setter
176
+ def noutlist(self, value: NDArray[Any]) -> None:
177
+ """Set the nout attribute of the load state."""
178
+ self.state.noutlist = value
179
+
180
+ @property
181
+ def ntime(self) -> int | NDArray[Any]:
182
+ """Get the ntime attribute of the load state."""
183
+ return self.state.ntime
184
+
185
+ @ntime.setter
186
+ def ntime(self, value: int | NDArray[Any]) -> None:
187
+ """Set the ntime attribute of the load state."""
188
+ self.state.ntime = value
189
+
190
+ @property
191
+ def ntimelist(self) -> NDArray[Any]:
192
+ """Get the ntime attribute of the load state."""
193
+ return self.state.ntimelist
194
+
195
+ @ntimelist.setter
196
+ def ntimelist(self, value: NDArray[Any]) -> None:
197
+ """Set the ntime attribute of the load state."""
198
+ self.state.ntimelist = value
199
+
200
+ @property
201
+ def outlist(self) -> NDArray[Any]:
202
+ """Get the outlist attribute of the load state."""
203
+ return self.state.outlist
204
+
205
+ @outlist.setter
206
+ def outlist(self, value: NDArray[Any]) -> None:
207
+ """Set the outlist attribute of the load state."""
208
+ self.state.outlist = value
209
+
210
+ @property
211
+ def pathdir(self) -> str | Path:
212
+ """Get the pathdir attribute of the load state."""
213
+ return self.state.pathdir
214
+
215
+ @pathdir.setter
216
+ def pathdir(self, value: str | Path) -> None:
217
+ """Set the pathdir attribute of the load state."""
218
+ self.state.pathdir = value
219
+
220
+ @property
221
+ def text(self) -> bool | None:
222
+ """Get the text attribute of the load state."""
223
+ return self.state.text
224
+
225
+ @text.setter
226
+ def text(self, value: bool | None) -> None:
227
+ """Set the text attribute of the load state."""
228
+ self.state.text = value
229
+
230
+ @property
231
+ def timelist(self) -> NDArray[Any]:
232
+ """Get the timelist attribute of the load state."""
233
+ return self.state.timelist
234
+
235
+ @timelist.setter
236
+ def timelist(self, value: NDArray[Any]) -> None:
237
+ """Set the timelist attribute of the load state."""
238
+ self.state.timelist = value
239
+
240
+ @property
241
+ def varoffset(self) -> dict[str, Any]:
242
+ """Get the varoffset attribute of the load state."""
243
+ return self.state.varoffset
244
+
245
+ @varoffset.setter
246
+ def varoffset(self, value: dict[str, Any]) -> None:
247
+ """Set the varoffset attribute of the load state."""
248
+ self.state.varoffset = value
249
+
250
+ @property
251
+ def varshape(self) -> dict[str, Any]:
252
+ """Get the varshape attribute of the load state."""
253
+ return self.state.varshape
254
+
255
+ @varshape.setter
256
+ def varshape(self, value: dict[str, Any]) -> None:
257
+ """Set the varshape attribute of the load state."""
258
+ self.state.varshape = value
@@ -0,0 +1,45 @@
1
+ """Module that contains the LoadState class."""
2
+
3
+ from dataclasses import dataclass, field
4
+ from pathlib import Path
5
+ from typing import Any
6
+
7
+ from numpy.typing import NDArray
8
+
9
+
10
+ @dataclass(slots=True)
11
+ class BaseLoadState:
12
+ """Class that stores the state of the Load class.
13
+
14
+ Its purpose is to keep track of the current state of the data loading,
15
+ such as the file paths, data arrays, and other properties and update the
16
+ key attributes through all the different classes that handle the data
17
+ loading at runtime.
18
+ """
19
+
20
+ # pylint: disable=too-many-instance-attributes
21
+
22
+ alone: bool = field(init=False)
23
+ charsize: int = field(init=False)
24
+ class_name: str = field(init=False)
25
+ code: str = "gPLUTO"
26
+ d_info: dict[str, Any] = field(init=False)
27
+ d_vars: dict[str, Any] = field(default_factory=dict)
28
+ endian: str | None = None
29
+ filepath: Path = field(init=False)
30
+ format: str = "Unknown"
31
+ infogrid: bool = True
32
+ lennout: int = field(init=False)
33
+ lennoutlist: int = field(init=False)
34
+ matching_files: list[str] | None = None
35
+ multiple: bool = False
36
+ nout: int | NDArray[Any] = field(init=False)
37
+ noutlist: NDArray[Any] = field(init=False)
38
+ ntime: int | NDArray[Any] = field(init=False)
39
+ ntimelist: NDArray[Any] = field(init=False)
40
+ outlist: NDArray[Any] = field(init=False)
41
+ pathdir: str | Path = "./"
42
+ text: bool | None = None
43
+ timelist: NDArray[Any] = field(init=False)
44
+ varoffset: dict[str, Any] = field(init=False)
45
+ varshape: dict[str, Any] = field(init=False)
@@ -0,0 +1,161 @@
1
+ """Module to load the data from the output files of the ECHO code."""
2
+
3
+ import warnings
4
+ from pathlib import Path
5
+ from typing import Any, cast
6
+
7
+ import h5py
8
+
9
+ from pyPLUTO.loadmixin import LoadMixin
10
+ from pyPLUTO.loadstate import LoadState
11
+ from pyPLUTO.utils.inspector import track_kwargs
12
+
13
+
14
+ @track_kwargs
15
+ class EchoLoadManager(LoadMixin):
16
+ """Manager for the loading of the ECHO code data."""
17
+
18
+ @track_kwargs
19
+ def __init__(self, state: LoadState) -> None:
20
+ """Initialize the EchoLoadManager."""
21
+ self.state = state
22
+
23
+ def load_echo(
24
+ self, nout: int | str | list[int | str] | None, **kwargs: Any
25
+ ) -> None:
26
+ """Load the data from the output files of the ECHO code.
27
+
28
+ The data are loaded only from h5 files and only a single output is
29
+ possible. Note that binary files produced by ECHO are not supported
30
+ by this method. The data are loaded in the PLUTO format, so the
31
+ variables are renamed to match the PLUTO naming convention.
32
+
33
+ Parameters
34
+ ----------
35
+ - nout: int | str | list | None, default 0
36
+ The output number to be loaded.
37
+ - path: str, default './'
38
+ The path to the folder containing the data files.
39
+ - vars: str | list[str] | bool | None, default True
40
+ The variables to be loaded. If 'True', all the variables are loaded.
41
+
42
+ Returns
43
+ -------
44
+ - None
45
+
46
+ Examples
47
+ --------
48
+ Example 1: Load all the variables from the last output in the current
49
+ folder.
50
+
51
+ >>> NOT IMPLEMENTED YET
52
+
53
+ """
54
+ print("load, echo")
55
+
56
+ # Geometry is set to CARTESIAN by default
57
+ self.geom = "CARTESIAN"
58
+
59
+ # Dictionary to convert the keys from ECHO to PLUTO
60
+ conv_dict = {
61
+ "x": "x1",
62
+ "y": "x2",
63
+ "z": "x3",
64
+ "rh": "rho",
65
+ "pg": "prs",
66
+ "se": "ent",
67
+ "vx": "vx1",
68
+ "vy": "vx2",
69
+ "vz": "vx3",
70
+ "bx": "Bx1",
71
+ "by": "Bx2",
72
+ "bz": "Bx3",
73
+ "ex": "Ex1",
74
+ "ey": "Ex2",
75
+ "ez": "Ex3",
76
+ }
77
+
78
+ self.echo_load_grid(conv_dict)
79
+ self.echo_set_grid_dims()
80
+
81
+ if isinstance(nout, str) or nout is None:
82
+ warnings.warn(
83
+ "Please specify the output or it will be set to 0.",
84
+ stacklevel=2,
85
+ )
86
+ self.nout = 0
87
+ elif isinstance(nout, list):
88
+ if isinstance(nout[0], int):
89
+ self.nout = nout[0]
90
+ else:
91
+ warnings.warn(
92
+ "Please specify the output or it will be set to 0.",
93
+ stacklevel=2,
94
+ )
95
+ self.nout = 0
96
+ else:
97
+ self.nout = nout
98
+
99
+ file = self.pathdir / Path(f"out{self.nout:03d}.h5")
100
+
101
+ loadvars = True
102
+ if kwargs.get("vars") is not None:
103
+ warnings.warn(
104
+ "'vars' argument is deprecated. Use 'var' instead.",
105
+ DeprecationWarning,
106
+ stacklevel=2,
107
+ )
108
+ loadvars = kwargs.get("vars", loadvars)
109
+ loadvars = kwargs.get("var", loadvars)
110
+
111
+ with h5py.File(str(file), "r") as tmp:
112
+ self.ntime = cast(h5py.Dataset, tmp["time"])[()][0]
113
+ var = list(tmp.keys()) if loadvars is True else loadvars or []
114
+ self.echo_load_vars(tmp, conv_dict, var)
115
+
116
+ def echo_load_grid(self, conv_dict: dict[str, str]) -> None:
117
+ """Load grid.h5 and set attributes."""
118
+ with h5py.File(str(self.pathdir / Path("grid.h5")), "r") as grid:
119
+ for key, obj in grid.items():
120
+ if not isinstance(obj, h5py.Dataset):
121
+ continue
122
+ data = obj[()]
123
+ name = conv_dict.get(key, key)
124
+ if name is not None:
125
+ setattr(self, name, data)
126
+
127
+ def echo_set_grid_dims(self) -> None:
128
+ """Compute nx1, nx2, nx3, dim, gridsize, nshp."""
129
+ for dim in ["x1", "x2", "x3"]:
130
+ n = len(getattr(self, dim)) if hasattr(self, dim) else 1
131
+ setattr(self, f"n{dim}", n)
132
+
133
+ self.dim = (self.nx1 > 1) + (self.nx2 > 1) + (self.nx3 > 1)
134
+ self.gridsize = self.nx1 * self.nx2 * self.nx3
135
+ dim_dict = {
136
+ 1: self.nx1,
137
+ 2: (self.nx1, self.nx2),
138
+ 3: (self.nx1, self.nx2, self.nx3),
139
+ }
140
+ self.nshp = dim_dict[self.dim]
141
+
142
+ def echo_load_vars(
143
+ self, tmp: h5py.File, conv_dict: dict[str, str], var: list[str]
144
+ ) -> None:
145
+ """Load variables from output file."""
146
+ for key in var:
147
+ if key == "time":
148
+ continue
149
+ valkey = next((k for k, v in conv_dict.items() if v == key), key)
150
+ obj = tmp.get(valkey)
151
+ if not isinstance(obj, h5py.Dataset):
152
+ warnings.warn(
153
+ f"'{valkey}' not a dataset (found {type(obj)})",
154
+ stacklevel=2,
155
+ )
156
+ continue
157
+ loadvar = obj[()]
158
+ for dim in [self.nx3, self.nx2, self.nx1]:
159
+ if dim == 1:
160
+ loadvar = loadvar[0]
161
+ setattr(self.state, conv_dict.get(valkey, valkey), loadvar.T)