pion-reader 2.0.0__tar.gz

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.
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2020, Samuel Green
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,67 @@
1
+ Metadata-Version: 2.4
2
+ Name: pion-reader
3
+ Version: 2.0.0
4
+ Summary: Read and plot the Silo snapshot files of the PION (radiation-)MHD code
5
+ Author: Sam Green, Jonathan Mackey, Arun Mathew
6
+ License-Expression: BSD-3-Clause
7
+ Project-URL: Homepage, https://github.com/jmackey-astro/PyPion-dev
8
+ Project-URL: Documentation, https://pion-docs-dev.readthedocs.io/en/latest/python.html
9
+ Project-URL: Issues, https://github.com/jmackey-astro/PyPion-dev/issues
10
+ Keywords: pion,pypion,silo,visualisation,computational fluid dynamics
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Topic :: Scientific/Engineering :: Astronomy
14
+ Requires-Python: >=3.9
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE.md
17
+ Requires-Dist: numpy
18
+ Requires-Dist: astropy
19
+ Requires-Dist: matplotlib
20
+ Provides-Extra: yt
21
+ Requires-Dist: yt>=4.4.0; extra == "yt"
22
+ Dynamic: license-file
23
+
24
+ # pion-reader: Python library for PION
25
+
26
+ Reads and plots the Silo snapshot files written by
27
+ [PION](https://gitlab.git.nrw/jmackey1/pion-dev), on uniform and nested
28
+ grids in 1D, 2D and 3D: both the current layout (all levels of a snapshot
29
+ in one set of files, PION 3.0.0-dev.2 and later) and the older one (one file
30
+ per level). It continues PyPion (Sam Green et al.; the `pypion` package on
31
+ PyPI), with the module renamed from `pypion` to `pion_reader`.
32
+
33
+ The source is in `src/pion_reader`, example plotting scripts are in
34
+ `examples/`, and `tests/` reads PION snapshots of both layouts
35
+ (`pytest tests`).
36
+
37
+ # Installation
38
+
39
+ ```
40
+ python3 -m pip install pion-reader # or "pion-reader[yt]" with yt
41
+ ```
42
+
43
+ ```python
44
+ from pion_reader.ReadData import ReadData
45
+ data = ReadData("MyRun_0000.00000100.silo") # all levels of a snapshot
46
+ rho = data.get_2Darray("Density") # one array per level
47
+ ```
48
+
49
+ Scripts written for PyPion only need `pypion` replaced by `pion_reader` in
50
+ their imports.
51
+
52
+ The Silo Python module is installed separately: see the
53
+ [PION documentation](https://pion-docs-dev.readthedocs.io/en/latest/python.html)
54
+ (or the script in `src/silo/` of this repository).
55
+
56
+ # Documentation
57
+
58
+ Usage: https://pion-docs-dev.readthedocs.io/en/latest/python.html
59
+
60
+ Developers: see `doc/dev.md`; format the code with `tools/format.sh`
61
+ (yapf) before committing.
62
+
63
+ # Developers/Maintainers
64
+
65
+ * Samuel Green
66
+ * Jonathan Mackey
67
+ * Arun Mathew
@@ -0,0 +1,44 @@
1
+ # pion-reader: Python library for PION
2
+
3
+ Reads and plots the Silo snapshot files written by
4
+ [PION](https://gitlab.git.nrw/jmackey1/pion-dev), on uniform and nested
5
+ grids in 1D, 2D and 3D: both the current layout (all levels of a snapshot
6
+ in one set of files, PION 3.0.0-dev.2 and later) and the older one (one file
7
+ per level). It continues PyPion (Sam Green et al.; the `pypion` package on
8
+ PyPI), with the module renamed from `pypion` to `pion_reader`.
9
+
10
+ The source is in `src/pion_reader`, example plotting scripts are in
11
+ `examples/`, and `tests/` reads PION snapshots of both layouts
12
+ (`pytest tests`).
13
+
14
+ # Installation
15
+
16
+ ```
17
+ python3 -m pip install pion-reader # or "pion-reader[yt]" with yt
18
+ ```
19
+
20
+ ```python
21
+ from pion_reader.ReadData import ReadData
22
+ data = ReadData("MyRun_0000.00000100.silo") # all levels of a snapshot
23
+ rho = data.get_2Darray("Density") # one array per level
24
+ ```
25
+
26
+ Scripts written for PyPion only need `pypion` replaced by `pion_reader` in
27
+ their imports.
28
+
29
+ The Silo Python module is installed separately: see the
30
+ [PION documentation](https://pion-docs-dev.readthedocs.io/en/latest/python.html)
31
+ (or the script in `src/silo/` of this repository).
32
+
33
+ # Documentation
34
+
35
+ Usage: https://pion-docs-dev.readthedocs.io/en/latest/python.html
36
+
37
+ Developers: see `doc/dev.md`; format the code with `tools/format.sh`
38
+ (yapf) before committing.
39
+
40
+ # Developers/Maintainers
41
+
42
+ * Samuel Green
43
+ * Jonathan Mackey
44
+ * Arun Mathew
@@ -0,0 +1,41 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "pion-reader"
7
+ version = "2.0.0"
8
+ description = "Read and plot the Silo snapshot files of the PION (radiation-)MHD code"
9
+ readme = "README.md"
10
+ license = "BSD-3-Clause"
11
+ license-files = ["LICENSE.md"]
12
+ authors = [
13
+ { name = "Sam Green" },
14
+ { name = "Jonathan Mackey" },
15
+ { name = "Arun Mathew" },
16
+ ]
17
+ classifiers = [
18
+ "Programming Language :: Python :: 3",
19
+ "Operating System :: OS Independent",
20
+ "Topic :: Scientific/Engineering :: Astronomy",
21
+ ]
22
+ keywords = ["pion", "pypion", "silo", "visualisation", "computational fluid dynamics"]
23
+ requires-python = ">=3.9"
24
+ dependencies = [
25
+ "numpy",
26
+ "astropy",
27
+ "matplotlib",
28
+ ]
29
+
30
+ [project.optional-dependencies]
31
+ # needed only for pion2yt.py, derived_fields_yt.py and example_plots_yt.py
32
+ yt = ["yt >= 4.4.0"]
33
+
34
+ [project.urls]
35
+ Homepage = "https://github.com/jmackey-astro/PyPion-dev"
36
+ Documentation = "https://pion-docs-dev.readthedocs.io/en/latest/python.html"
37
+ Issues = "https://github.com/jmackey-astro/PyPion-dev/issues"
38
+
39
+ [tool.setuptools.packages.find]
40
+ where = ["src"]
41
+ include = ["pion_reader*"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,263 @@
1
+ # Author: Sam Green, Created: 20-10-17
2
+ # Script that defines functions to use the data created from core2D_Silo.py to plot the silo file's data.
3
+
4
+ # Comments from previous script version (Silo_Plot.py):
5
+ # -2016-09-22 SG: Created to work with the Bubble Nebula simulations, adapted from MultiMesh_Silo_plot.py.
6
+ # -2016-09-23 JM/SG: Correction to fix the "too many files open" bug; edited to accommodate new InputValues class.
7
+ # -2016-12-14 JM: Set up instance of class "ThisFile" to try to fix
8
+ # memory leak problems. Also only setup InputValues() once.
9
+ # -2017-01-17 SG: Set density and temperature to a constant max and min.
10
+ # -2017-5-22 SG: Few small changes made to fix some bugs.
11
+
12
+ # New comments:
13
+ # -2017-10-28 SG: Set up plotting code as a function
14
+ # -2017-11-6 SG: New class to plot velocity data as vector/streamline
15
+ # -2017-12-05 SG: Few changes made to temp plotting function.
16
+ # -2019-07-22 SG: Added class to plot slices of the 3D data.
17
+ # -2019-08-12 SG: Tidied up a few things.
18
+
19
+ #############################################################
20
+ # Here's what each function does at a glance:
21
+
22
+ # 3D stuff:
23
+ # XZslice - plots a slice in the XZ-direction.
24
+ # XYslice - plots a slice in the XY-direction.
25
+ # XZXYslice - plots a slice in the XZ and XY -direction onto the same figure.
26
+
27
+ # magplot - plots the magnitude of the magnetic field.
28
+ #----------------------------------------------------------
29
+ # 2D stuff:
30
+ # plot_single - plots a single parameter in the top-half of the sim.
31
+ # plot_double - plots 1 parameter above the x-axis and another below it.
32
+ # Used when you've anly simulated half on the 2D object.
33
+
34
+ #############################################################
35
+ # -------------- Set of libraries needed:
36
+ from .ReadData import ReadData
37
+
38
+ import matplotlib
39
+ # Using this to stop matplotlib from using a $DISPLAY environment variable.
40
+ # i.e. This now works over ssh.
41
+ #matplotlib.use('Agg')
42
+ from matplotlib.colorbar import Colorbar
43
+ import matplotlib.pyplot as plt
44
+ import matplotlib as mpl
45
+ from mpl_toolkits.axes_grid1 import make_axes_locatable
46
+ from matplotlib.ticker import MultipleLocator
47
+ import matplotlib.gridspec as gridspec
48
+
49
+ import numpy as np
50
+ from astropy import units as u
51
+
52
+ plt.rc('font', **{'size': 12})
53
+ # plt.rc('lines', linewidth=2)
54
+ plt.rc('font', weight='bold') # <-------------
55
+
56
+ # -------------- Class to plot the data from 2d Silo files.
57
+
58
+
59
+ class Plotting2d(ReadData):
60
+
61
+ def plotsilo_2d(self, lim_min, lim_max, fig, var1, var2):
62
+ xmin = (self.xmin() * u.cm).to(u.pc) # Set data to units of parsecs.
63
+ xmax = (self.xmax() * u.cm).to(u.pc)
64
+
65
+ var1 = var1
66
+ var2 = var2
67
+
68
+ level_min = (self.level_min() * u.cm).to(
69
+ u.pc) # Set data to units of parsecs.
70
+ level_max = (self.level_max() * u.cm).to(u.pc)
71
+
72
+ ax1 = fig.add_subplot(2, 1, 1)
73
+ ax1.set_title(' Time = %5.5f Myr' % self.sim_time().value)
74
+
75
+ if var1[4] == 'log':
76
+ log_d = np.log10(self.get_2Darray(var1[0])['data'])
77
+ else:
78
+ log_d = self.get_2Darray(var1[0])['data']
79
+
80
+ ax1.set_xlim(lim_min[0].value, lim_max[0].value)
81
+ ax1.set_ylim(lim_min[1].value, lim_max[1].value)
82
+
83
+ im1 = ax1.imshow(log_d,
84
+ interpolation='nearest',
85
+ cmap=var1[3],
86
+ extent=[
87
+ level_min[0].value, level_max[0].value,
88
+ level_min[1].value, level_max[1].value
89
+ ],
90
+ origin='lower',
91
+ vmax=var1[1],
92
+ vmin=var1[2])
93
+ divider1 = make_axes_locatable(
94
+ ax1) # Create divider for existing axes instance.
95
+ cax1 = divider1.append_axes(
96
+ "right", size="5%", pad=0.05) # Append axes to the right of ax1.
97
+ cbar1 = plt.colorbar(
98
+ im1, cax=cax1, ticks=MultipleLocator(1),
99
+ format="%.2f") # Create colorbar in the appended axes.
100
+ txt1 = ax1.text(0.8, 0.92, r'$log(\rho)$', transform=ax1.transAxes)
101
+ ax1.axes.get_xaxis().set_visible(False) # Remove the x-axis.
102
+
103
+ # Temperature plot:
104
+ ax2 = fig.add_subplot(2, 1, 2)
105
+
106
+ if var1[4] == 'log':
107
+ log_t = np.log10(self.get_2Darray(var2[0])['data'])
108
+ else:
109
+ log_t = self.get_2Darray(var2[0])['data']
110
+
111
+ ax2.set_xlim(lim_min[0].value, lim_max[0].value)
112
+ ax2.set_ylim(-lim_max[1].value, lim_min[1].value)
113
+
114
+ im2 = ax2.imshow(log_t,
115
+ interpolation='nearest',
116
+ cmap=var2[3],
117
+ extent=[
118
+ level_min[0].value, level_max[0].value,
119
+ -level_max[1].value, -level_min[1].value
120
+ ],
121
+ vmax=var2[1],
122
+ vmin=var2[2])
123
+ divider2 = make_axes_locatable(ax2)
124
+ cax2 = divider2.append_axes("right", size="5%", pad=0.05)
125
+ cbar2 = plt.colorbar(im2,
126
+ cax=cax2,
127
+ ticks=MultipleLocator(1),
128
+ format="%.2f")
129
+ txt2 = ax2.text(0.8,
130
+ 0.05,
131
+ r'$log(T)$',
132
+ transform=ax2.transAxes,
133
+ color='white')
134
+ ax2.set_xlabel(' x-axis (pc)')
135
+ ax2.set_ylabel(
136
+ ' z-axis (pc)')
137
+
138
+ fig.subplots_adjust(
139
+ wspace=0, hspace=0) # Remove the whitespace between the images
140
+
141
+ del xmin
142
+ del xmax
143
+ return fig
144
+
145
+ def plot2d_1(self, param, Fig, var1):
146
+
147
+ # assign necessary data to arrays.
148
+ data = self.get_2Darray(param)['data']
149
+
150
+ lim_max = (self.get_2Darray(param)['max_extents'] * u.cm).to(u.pc)
151
+ lim_min = (self.get_2Darray(param)['min_extents'] * u.cm).to(u.pc)
152
+ # sim_time = self.get_2Darray(param)['sim_time'].to(u.Myr)
153
+
154
+ fig = Fig
155
+ ax1 = fig.add_subplot(1, 1, 1)
156
+ ax1.set_xlim(lim_min[0][0].value, lim_max[0][0].value)
157
+ ax1.set_ylim(lim_min[0][1].value, lim_max[0][1].value)
158
+ ax1.set_xlabel('x-axis (pc)')
159
+ ax1.set_ylabel('y-axis (pc)')
160
+
161
+ for i in range(len(data)):
162
+ x = data[i]
163
+ log_data = np.log10(x)
164
+
165
+ # --------------Left Plot----------------------------
166
+ # ax1.set_title(' Time = %5.5f Myr' % sim_time.value)
167
+ im1 = ax1.imshow(log_data,
168
+ interpolation='nearest',
169
+ cmap="viridis",
170
+ extent=[
171
+ lim_min[i][0].value, lim_max[i][0].value,
172
+ lim_min[i][1].value, lim_max[i][1].value
173
+ ],
174
+ origin='lower',
175
+ vmax=-22,
176
+ vmin=-27)
177
+
178
+ #cbax = plt.subplot(gs[-1, 0:])
179
+ #cb = Colorbar(ax=cbax, mappable=im1, orientation='horizontal', ticklocation='bottom')
180
+ return fig
181
+
182
+
183
+ class Plotting3d(ReadData):
184
+
185
+ def XZXYslice(self, param, Fig, var1):
186
+
187
+ # assign necessary data to arrays.
188
+ data = self.get_3Darray(param)['data']
189
+ lim_max = (self.get_3Darray(param)['max_extents'] * u.cm).to(u.pc)
190
+ lim_min = (self.get_3Darray(param)['min_extents'] * u.cm).to(u.pc)
191
+ sim_time = self.get_3Darray(param)['sim_time'].to(u.Myr)
192
+
193
+ fig = Fig
194
+ gs = gridspec.GridSpec(2,
195
+ 2,
196
+ height_ratios=[1, 0.05],
197
+ width_ratios=[1, 1])
198
+ gs.update(left=0.05,
199
+ right=0.95,
200
+ bottom=0.08,
201
+ top=0.93,
202
+ wspace=0.02,
203
+ hspace=0.03)
204
+
205
+ var = var1
206
+
207
+ ax1 = fig.add_subplot(gs[0, 0])
208
+ ax1.set_title(
209
+ ' Time = %5.5f Myr'
210
+ % sim_time.value)
211
+ ax1.set_xlim(lim_min[0][0].value, lim_max[0][0].value)
212
+ ax1.set_ylim(lim_min[0][1].value, lim_max[0][1].value)
213
+ ax1.set_xlabel('x-axis (pc)')
214
+ ax1.set_ylabel('z-axis (pc)')
215
+ ax2 = fig.add_subplot(gs[0, 1])
216
+ # ax2.set_title('Time = %5.5f Myr' % self.sim_time().value)
217
+ ax2.set_xlim(lim_min[0][0].value, lim_max[0][0].value)
218
+ ax2.set_ylim(lim_min[0][2].value, lim_max[0][2].value)
219
+ ax2.set_xlabel('x-axis (pc)')
220
+ ax2.yaxis.set_label_position("right")
221
+ ax2.yaxis.tick_right()
222
+ ax2.set_ylabel('y-axis (pc)')
223
+
224
+ for i in range(len(data)):
225
+ x_slice = data[i][var[5], :, :]
226
+ y_slice = data[i][:, var[5], :]
227
+
228
+ log_dx = np.log10(x_slice)
229
+ log_dy = np.log10(y_slice)
230
+
231
+ # --------------Left Plot----------------------------
232
+ im1 = ax1.imshow(log_dy,
233
+ interpolation='nearest',
234
+ cmap="viridis",
235
+ extent=[
236
+ lim_min[i][0].value, lim_max[i][0].value,
237
+ lim_min[i][1].value, lim_max[i][1].value
238
+ ],
239
+ origin='lower',
240
+ vmax=-22,
241
+ vmin=-27)
242
+ # txt1 = ax1.text(0.8, 0.92, r'$log(\rho)$', transform=ax1.transAxes)
243
+ # --------------Right Plot----------------------------
244
+ im2 = ax2.imshow(log_dx,
245
+ interpolation='nearest',
246
+ cmap=var[3],
247
+ extent=[
248
+ lim_min[i][0].value, lim_max[i][0].value,
249
+ lim_min[i][2].value, lim_max[i][2].value
250
+ ],
251
+ origin='lower',
252
+ vmax=var[1],
253
+ vmin=var[2])
254
+ # txt2 = ax2.text(0.8, 0.92, r'$log(\rho)$', transform=ax1.transAxes)
255
+
256
+ cbax = plt.subplot(gs[-1, 0:])
257
+ cb = Colorbar(ax=cbax,
258
+ mappable=im1,
259
+ orientation='horizontal',
260
+ ticklocation='bottom')
261
+ # cb.set_label(r'Colorbar !', labelpad=10)
262
+ #plt.savefig("test.png", bbox_inches='tight', dpi=300)
263
+ return fig
@@ -0,0 +1,204 @@
1
+ # Author: Sam Green, Created: 18-10-2017
2
+ # Script sets up a set of core classes/functions to read data from silo data files.
3
+
4
+ # Comments from previous script version (Silo_Modules.py):
5
+ # -2016-06-10 SG: Opens MultiMesh silo files and can plot 2D structures.
6
+ # -2016-09-29 SG: PARAMETER and PARAMETER_MAIN Function added to save density and temperature data depending on
7
+ # what variable name is called,
8
+ # no longer separate functions to calculate density and temperature data.
9
+ # -2016-10-07 SG: PARAMETER Function modified to allow velocity to be chosen as the variable name.
10
+ # -2016-12.14 JM: self.Param and self.BigArray_Param no longer class
11
+ # member data.
12
+ # -2017-02-23 SG: Added comments.
13
+ # -2017-03-10 SG: Added Class to read in VTK data produced by PION 2D projection code and calculate data to
14
+ # plot the column density and nebular line emission.
15
+
16
+ # New comments:
17
+ # - 2017-10-28 SG: Rewritten some functions to remove errors, increase efficiency.
18
+ # - 2017-10-29 SG: Bugs in reshaped_parameter2d function fixed.
19
+ # - 2018-03-26 SG: Added class to plot slices of the 3D data.
20
+ # - 22-04-2020 SG: Moved the parameter and variable function to SiloHeader_data.py
21
+ # - 22-04-2020 SG: Both functions now open all the files associated with each timestep and saves the data arrays for each of them.
22
+
23
+ # This is to make the scripts work with nested-grids.
24
+ # Works in 1D, 2D, and 3D. Should also work with non-nestedgrid too (i.e. 1 level of data).
25
+
26
+ # -------------- Set of libraries needed:
27
+ import numpy as np
28
+ from .SiloHeader_data import OpenData
29
+
30
+ # --------------Class to access each 2D sub-domain and save density, temperature, etc. data:
31
+
32
+
33
+ class ReadData(OpenData):
34
+
35
+ # Function to read 1D data from multiple nested grid levels from
36
+ # a Silo file, and return the data as numpy arrays with extents.
37
+ def get_1Darray(self, param):
38
+
39
+ level = self.nlevels()
40
+ arr = [[None]] * level
41
+ level_max = [[None]] * level
42
+ level_min = [[None]] * level
43
+ sim_time = self.sim_time().value
44
+
45
+ # one level at a time (the levels' directories of one file, or the
46
+ # files of an old snapshot)
47
+ i = 0
48
+ for ilev in range(self.nlevels_to_read()):
49
+ self.open(ilev)
50
+
51
+ variable_array = np.zeros((self.ngrid()[0]))
52
+
53
+ domain = self.dom_size()
54
+ a = domain['DomSize'][0]
55
+ c = domain['Ndom'][0]
56
+ e, min_ext = self.parameter(param)
57
+ level_max[i] = self.level_max()
58
+ level_min[i] = self.level_min()
59
+ dx = (level_max[i][0] - level_min[i][0]) / c
60
+
61
+ for idom in range(c):
62
+ # Sets the positions of each process array.
63
+ ix = int((min_ext[idom][0] - level_min[i][0]) * 1.01 / dx)
64
+ x0 = ix * a
65
+ x1 = x0 + a
66
+ # Saves all the values into the 1D image array
67
+ variable_array[x0:x1] = e[idom]
68
+
69
+ arr[i] = variable_array
70
+ i += 1
71
+
72
+ del a
73
+ del c
74
+ del e
75
+ del variable_array
76
+
77
+ return {
78
+ 'data': arr,
79
+ 'max_extents': level_max,
80
+ 'min_extents': level_min,
81
+ 'sim_time': sim_time
82
+ }
83
+
84
+ # Function to read 2D data from multiple nested grid levels from
85
+ # a Silo file, and return the data as numpy arrays with extents.
86
+ def get_2Darray(self, param):
87
+
88
+ level = self.nlevels()
89
+ arr = [[None]] * level
90
+ level_max = [[None]] * level
91
+ level_min = [[None]] * level
92
+ sim_time = self.sim_time().value
93
+
94
+ # one level at a time (the levels' directories of one file, or the
95
+ # files of an old snapshot)
96
+ i = 0
97
+ for ilev in range(self.nlevels_to_read()):
98
+ self.open(ilev)
99
+
100
+ variable_array = np.zeros((self.ngrid()[1], self.ngrid()[0]))
101
+
102
+ domain = self.dom_size()
103
+ a = domain['DomSize'][0]
104
+ b = domain['DomSize'][1]
105
+ c = domain['Ndom'][0]
106
+ d = domain['Ndom'][1]
107
+ e, min_ext = self.parameter(param)
108
+ level_max[i] = self.level_max()
109
+ level_min[i] = self.level_min()
110
+ dx = (level_max[i][0] - level_min[i][0]) / c
111
+ dy = (level_max[i][1] - level_min[i][1]) / d
112
+ ndom = c * d
113
+
114
+ for idom in range(ndom):
115
+ # get the (ix,iy,iz) location of sub-domain from its extents
116
+ ix = int((min_ext[idom][0] - level_min[i][0]) * 1.01 / dx)
117
+ iy = int((min_ext[idom][1] - level_min[i][1]) * 1.01 / dy)
118
+ x0 = ix * a
119
+ y0 = iy * b
120
+ x1 = x0 + a
121
+ y1 = y0 + b
122
+ variable_array[y0:y1, x0:x1] = e[idom]
123
+
124
+ arr[i] = variable_array
125
+ i += 1
126
+
127
+ del a
128
+ del b
129
+ del c
130
+ del d
131
+ del e
132
+ del variable_array
133
+
134
+ return {
135
+ 'data': arr,
136
+ 'max_extents': level_max,
137
+ 'min_extents': level_min,
138
+ 'sim_time': sim_time
139
+ }
140
+
141
+ # Function to read 3D data from multiple nested grid levels from
142
+ # a Silo file, and return the data as numpy arrays with extents.
143
+ def get_3Darray(self, param):
144
+
145
+ level = self.nlevels()
146
+ arr = [[None]] * level
147
+ level_max = [[None]] * level
148
+ level_min = [[None]] * level
149
+ sim_time = self.sim_time()
150
+
151
+ # one level at a time (the levels' directories of one file, or the
152
+ # files of an old snapshot)
153
+ i = 0
154
+ for ilev in range(self.nlevels_to_read()):
155
+ self.open(ilev)
156
+
157
+ variable_array = np.zeros(
158
+ (self.ngrid()[2], self.ngrid()[1], self.ngrid()[0]))
159
+ domain = self.dom_size()
160
+ a = domain['DomSize'][0]
161
+ b = domain['DomSize'][1]
162
+ f = domain['DomSize'][2]
163
+ c = domain['Ndom'][0]
164
+ d = domain['Ndom'][1]
165
+ g = domain['Ndom'][2]
166
+ e, min_ext = self.parameter(param)
167
+ level_max[i] = self.level_max()
168
+ level_min[i] = self.level_min()
169
+ dx = (level_max[i][0] - level_min[i][0]) / c
170
+ dy = (level_max[i][1] - level_min[i][1]) / d
171
+ dz = (level_max[i][2] - level_min[i][2]) / g
172
+ ndom = c * d * g
173
+
174
+ for idom in range(ndom):
175
+ # get the (ix,iy,iz) location of sub-domain from its extents
176
+ ix = int((min_ext[idom][0] - level_min[i][0]) * 1.01 / dx)
177
+ iy = int((min_ext[idom][1] - level_min[i][1]) * 1.01 / dy)
178
+ iz = int((min_ext[idom][2] - level_min[i][2]) * 1.01 / dz)
179
+ x0 = ix * a
180
+ y0 = iy * b
181
+ z0 = iz * f
182
+ x1 = x0 + a
183
+ y1 = y0 + b
184
+ z1 = z0 + f
185
+ variable_array[z0:z1, y0:y1, x0:x1] = e[idom]
186
+
187
+ arr[i] = variable_array
188
+ i += 1
189
+
190
+ del a
191
+ del b
192
+ del c
193
+ del d
194
+ del e
195
+ del g
196
+ del f
197
+ del variable_array
198
+
199
+ return {
200
+ 'data': arr,
201
+ 'max_extents': level_max,
202
+ 'min_extents': level_min,
203
+ 'sim_time': sim_time
204
+ }