pion-reader 2.0.0__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.
@@ -0,0 +1,233 @@
1
+ from . import util
2
+ from .SiloHeader_data import OpenData
3
+ import re
4
+ import numpy as np
5
+
6
+ # PION constants
7
+ pion_elements = {
8
+ 'H': "Hydrogen",
9
+ 'He': "Helium",
10
+ 'C': "Carbon",
11
+ 'N': "Nitrogen",
12
+ 'O': "Oxygen",
13
+ 'Ne': "Neon",
14
+ 'Si': "Silicon",
15
+ 'S': "Sulfur",
16
+ 'Fe': "Iron"
17
+ }
18
+
19
+ mass = {
20
+ 'H': 1.6738e-24,
21
+ 'He': 6.6464768e-24,
22
+ 'C': 1.994374e-23,
23
+ 'N': 2.325892e-23,
24
+ 'O': 2.6567628e-23,
25
+ 'Ne': 3.3509177e-23,
26
+ 'Si': 4.6637066e-23,
27
+ 'S': 5.3245181e-23,
28
+ 'Fe': 9.2732796e-23
29
+ }
30
+
31
+ atomic_number = {
32
+ 'H': 1,
33
+ 'He': 2,
34
+ 'C': 6,
35
+ 'N': 7,
36
+ 'O': 8,
37
+ 'Ne': 10,
38
+ 'Si': 14,
39
+ 'S': 16,
40
+ 'Fe': 26
41
+ }
42
+
43
+ top_level_ions = {
44
+ 'H1+', 'He2+', 'C6+', 'N7+', 'O8+', 'Ne10+', 'Si14+', 'S16+', 'Fe26+'
45
+ }
46
+
47
+
48
+ class microphysics():
49
+
50
+ ######################################################################################
51
+ # initialize microphysics
52
+ ######################################################################################
53
+ def __init__(self, silo_set):
54
+ self.silo_set = silo_set
55
+ self.chemistry_container = {}
56
+
57
+ ######################################################################################
58
+ # load chemistry
59
+ ######################################################################################
60
+ def load_chemistry(self):
61
+ '''
62
+ This method extracts information related to the chemistry and chemical tracers,
63
+ transforming the chemical tracer names to a format that PyPion can directly
64
+ read from the Silo file. This method can be included in the next version of
65
+ PyPion.
66
+
67
+ Parameters
68
+ ----------
69
+ instant_silo_set : The instance for which chemical data is to be extracted
70
+
71
+ Returns
72
+ -------
73
+ Generates and stores the following in self.chemistry_container:
74
+ - 'dynamics': Dynamics data retrieved from the Silo file
75
+ - 'chemistry': Chemistry flag indicating if chemistry data is available
76
+ - 'E_update': Energy update information (if chemistry flag is true)
77
+ - 'chemistry_code': The code indicating the type of chemistry (if chemistry flag is true)
78
+ - 'microphysics': List of microphysics processes (if chemistry flag is true)
79
+ - 'Ntracers': Number of chemical tracers
80
+ - 'mpv10_elements': List of elements identified for MPv10 chemistry code
81
+ - 'mpv10_tracers': List of tracers corresponding to each element for MPv10 chemistry code
82
+ '''
83
+
84
+ # Open the data for the first silo instant silo
85
+ header_data = OpenData(self.silo_set[0])
86
+ # Set the directory to '/header'
87
+ header_data.db.SetDir('/header')
88
+ # print(header_data.header_info())
89
+ # Retrieve the value of "EP_chemistry" from the header data
90
+ chemistry_flag = header_data.db.GetVar("EP_chemistry")
91
+ self.chemistry_container['chemistry'] = chemistry_flag
92
+
93
+ # Define the list of process variable names
94
+ processes = [
95
+ 'EP_coll_ionisation', 'EP_rad_recombination', 'EP_cooling',
96
+ 'EP_raytracing', 'EP_phot_ionisation', 'EP_charge_exchange'
97
+ ]
98
+
99
+ # Define the list of process names corresponding to the process variable names
100
+ processes_name = [
101
+ 'coll_ionisation', 'rad_recombination', 'cooling', 'raytracing',
102
+ 'phot_ionisation', 'charge_exchange'
103
+ ]
104
+
105
+ # Check if chemistry_flag is true
106
+ if chemistry_flag:
107
+ # Retrieve the value of "EP_update_erg"
108
+ energy_update = header_data.db.GetVar("EP_update_erg")
109
+ # save the energy_update value in the chemistry_container dictionary
110
+ self.chemistry_container['E_update'] = energy_update
111
+ # Retrieve the value of "chem_code"
112
+ chemistry_code = header_data.db.GetVar("chem_code")[0]
113
+ # save the chemistry_code value in the chemistry_container dictionary
114
+ self.chemistry_container['chemistry_code'] = chemistry_code
115
+
116
+ # Initialize an empty list to store microphysics processes
117
+ microphysics = []
118
+ # Check if the chemistry_code is not 'MPv10'
119
+ if not chemistry_code == 'MPv10':
120
+ # Exit with an error if the chemistry_code is not 'MPv10'
121
+ util.exit_with_error(
122
+ " PION is not running NEMO v1.0; NelubaPy functionality is limited."
123
+ )
124
+ else:
125
+ # print the chemistry code
126
+ print(f" Microphysics module loaded")
127
+ print(" Module : NEMO")
128
+
129
+ # Loop through each process
130
+ for index, process in enumerate(processes):
131
+ # Check if the process variable exists in the header data
132
+ if header_data.db.GetVar(process):
133
+ # Append the corresponding process name to the microphysics list
134
+ microphysics.append(processes_name[index])
135
+
136
+ # save the microphysics list in the chemistry_container dictionary
137
+ self.chemistry_container['microphysics'] = microphysics
138
+ # Retrieve the number of tracers
139
+ Ntracers = header_data.db.GetVar('num_tracer')
140
+ # elements in the tracer list
141
+ tracer_elements = []
142
+ # mass_fraction
143
+ mass_fractions = {}
144
+ # list of element wise tracer list
145
+ elementWiseTracers = [[] for _ in range(len(pion_elements))]
146
+ # list of element names from the nebula_elements dictionary keys
147
+ element_list = list(pion_elements.keys())
148
+ # save the number of tracers in the chemistry_container dictionary
149
+ self.chemistry_container['Ntracers'] = Ntracers
150
+ # If verbose is enabled, print the number of chemical tracers
151
+
152
+ # Loop through each tracer index
153
+ for i in range(Ntracers):
154
+ # create a tracer index string with leading zeros
155
+ tracer_index = f'Tracer{i:03}'
156
+ # retrieve the tracer value
157
+ chem_tracer = header_data.db.GetVar(tracer_index)[0]
158
+
159
+ # check if the tracer is an element ('X' denoting elemental mass fraction)
160
+ if 'X' in chem_tracer and chem_tracer.replace(
161
+ "_", "").replace("X", "") in pion_elements:
162
+ # extract the element name
163
+ element = chem_tracer.replace("_", "").replace("X", "")
164
+ tracer_elements.append(element)
165
+ # get the full element name from the nebula_elements dictionary
166
+ mass_fractions[element] = f'Tr{i:03}_' + chem_tracer
167
+ # get the index of the element in the element_list
168
+ element_index = element_list.index(element)
169
+ # append the tracer with the corresponding element to the mpv10tracers list
170
+ if 0 <= element_index < len(elementWiseTracers):
171
+ elementWiseTracers[element_index].append(
172
+ f'Tr{i:03}_' + chem_tracer)
173
+
174
+ # check if the tracer is a corresponding ion
175
+ if re.sub(r'\d{1,2}\+', '', chem_tracer) in pion_elements:
176
+ self.chemistry_container[
177
+ chem_tracer] = f'Tr{i:03}_' + chem_tracer.replace(
178
+ '+', 'p')
179
+ # extract the element name
180
+ element = re.sub(r'\d{1,2}\+', '', chem_tracer)
181
+ # get the index of the element in the element_list
182
+ element_index = element_list.index(element)
183
+ # gppend the tracer with the corresponding ion to the mpv10tracers list
184
+ elementWiseTracers[element_index].append(
185
+ f'Tr{i:03}_' + chem_tracer.replace('+', 'p'))
186
+
187
+ print(f" Tracers ({Ntracers}): {', '.join(tracer_elements)}")
188
+ # save mass fraction to chemistry_container dictionary
189
+ # self.chemistry_container['mass_fractions'] = mass_fractions
190
+ self.element_list = tracer_elements
191
+ self.chemistry_container[
192
+ 'elemental_mass_fraction'] = mass_fractions
193
+ self.chemistry_container['tracer_elements'] = tracer_elements
194
+ self.chemistry_container[
195
+ 'element_wise_tracer_list'] = elementWiseTracers
196
+ else:
197
+ util.exit_with_error(
198
+ 'Chemistry flag is inactive in the loaded simulation file.')
199
+ header_data.close()
200
+
201
+ ######################################################################################
202
+ # get elements
203
+ ######################################################################################
204
+ def get_elements(self):
205
+ return np.array(self.chemistry_container['tracer_elements'])
206
+
207
+ ######################################################################################
208
+ # get chemical tracers
209
+ ######################################################################################
210
+ def get_chemical_tracers(self):
211
+ """
212
+ Retrieve the list of chemical tracer strings for each tracer in the chemistry
213
+ container dictionary, processed element by element. Each sublist starts with the
214
+ mass fraction of the element followed by the tracers.
215
+
216
+ Returns:
217
+ list of lists: Each sublist contains the mass fraction followed by the values of
218
+ the tracers for a specific element.
219
+ """
220
+ elements = self.get_elements()
221
+ tracers = []
222
+
223
+ for element in elements:
224
+ # Retrieve tracers for the element
225
+ element_tracers = [
226
+ self.chemistry_container[f"{element}{q}+" if q >
227
+ 0 else element]
228
+ for q in range(atomic_number[element])
229
+ ]
230
+
231
+ tracers.append(element_tracers)
232
+
233
+ return tracers
pion_reader/pion2yt.py ADDED
@@ -0,0 +1,445 @@
1
+ __author__ = "Thomas Jones, Jonathan Mackey"
2
+
3
+ import yt
4
+ import os
5
+ import glob
6
+ import numpy as np
7
+ import re
8
+ from .derived_fields_yt import derived_fields
9
+ from .ReadData import ReadData
10
+
11
+
12
+ class pion2yt:
13
+
14
+ ##########################################################################
15
+ def __init__(self):
16
+ print("init pion2yt")
17
+
18
+ # return make_snapshots(data_path, file_base):
19
+
20
+ ##########################################################################
21
+
22
+ def make_snapshots(self, data_path, file_base):
23
+ """
24
+ Function to make snapshots of silo files.
25
+
26
+ Input: path to silo files, base of filename
27
+ Output: list of snapshots - each snapshot is a list of silo files of different levels at the same time instant.
28
+
29
+ Example:
30
+ evolution = make_snapshots(data_path, file_base)
31
+
32
+ """
33
+ ########## Cataloging silo files ###############################
34
+ # Get the list of silo files
35
+ silo_files = os.listdir(data_path)
36
+ #silo_files = sorted([f for f in silo_files if f.contains(file_base)]
37
+ silo_files = sorted([f for f in silo_files if f.endswith('.silo')])
38
+ filename = (silo_files[0]).replace('_level00_0000.00000000.silo', '')
39
+ filename = file_base
40
+
41
+ print("Info from silo files:")
42
+ print(f"Basename of silo files: {filename}")
43
+
44
+ file_list = glob.glob(os.path.join(data_path, '*.silo'),
45
+ recursive=False)
46
+
47
+ level_list = []
48
+ files = []
49
+
50
+ for f in file_list:
51
+ level = re.search('_level(.*)_', f)
52
+ if level == None:
53
+ pass
54
+ else:
55
+ level = level.group(1)
56
+ if not level in level_list:
57
+ level_list.append(level)
58
+ level_list.sort()
59
+
60
+ ########## Categorizing data files into levels #################
61
+ if len(level_list) <= 1:
62
+ # one level, or all levels in one set of files (PION since
63
+ # 3.0.0-dev.2): one file (_0000) per snapshot
64
+ print('Simulation Info: one file per snapshot')
65
+ catalog = []
66
+ files = sorted(f for f in glob.glob(
67
+ os.path.join(data_path, filename + '_0000.*.silo'))
68
+ if '_level' not in os.path.basename(f))
69
+ catalog.append(files)
70
+ else:
71
+ print(f'Simulation Info: {len(level_list)} levels')
72
+ catalog = []
73
+ for i in range(len(level_list)):
74
+ files = sorted(
75
+ glob.glob(
76
+ os.path.join(
77
+ data_path,
78
+ f"{filename}_level{level_list[i]}_0000.*.silo")))
79
+ catalog.append(files)
80
+
81
+ # Bundle silo files of different levels of same time instant into a snapshot.
82
+ evolution = np.array(catalog).T
83
+ print(f"Number of snapshots: {evolution.shape[0]}")
84
+
85
+ return evolution
86
+ ##########################################################################
87
+
88
+ ##########################################################################
89
+
90
+ def get_ds(self,
91
+ filename,
92
+ quantities=["density"],
93
+ **kwargs) -> yt.data_objects.static_output.Dataset:
94
+ """
95
+ Function to create a yt dataset from a silo file.
96
+ Input: snapshot of silo file (list of filepaths for a single snapshot), list of quantities to be loaded
97
+ Output: yt dataset
98
+
99
+ Example:
100
+ evolution = make_snapshots(data_path)
101
+ file = evolution[0]
102
+ ds = get_ds(file, quantities=["density", "temperature", "velocity", "magnetic_field"])
103
+
104
+ """
105
+ data = ReadData(filename)
106
+ ndim = data.ndim()
107
+
108
+ if (ndim == 3):
109
+ ds = self.get_ds3D(data, quantities, **kwargs)
110
+ elif (ndim == 2):
111
+ ds = self.get_ds2D(data, quantities, **kwargs)
112
+ elif (ndim == 1):
113
+ print("IMPLEMENT A 1D READER PLEASE! AND WHY DO YOU NEED YT?")
114
+ ds = self.get_ds2D(data, quantities, **kwargs)
115
+ else:
116
+ print("Bad ndim in silo file:", ndim)
117
+ quit()
118
+
119
+ return ds
120
+ ##########################################################################
121
+
122
+ ##########################################################################
123
+
124
+ def get_ds3D(self,
125
+ data,
126
+ quantities=["density"],
127
+ **kwargs) -> yt.data_objects.static_output.Dataset:
128
+ sim_time = data.sim_time()
129
+ N_levels = data.nlevels()
130
+ Dom_size = max(np.array(data.level_max()) - np.array(data.level_min()))
131
+ rdata = data.get_3Darray("Density")
132
+ data_den = rdata['data']
133
+ # get extents normalised to length 1, and with negative corner at the origin:
134
+ lmin = np.array(rdata['min_extents']) #/Dom_size
135
+ lmax = np.array(rdata['max_extents']) #/Dom_size
136
+ # switch ordering or array because pion_reader returns ordering (z,y,x)
137
+ N_grids = data.ngrid()[::-1]
138
+ lmin = np.fliplr(lmin)
139
+ lmax = np.fliplr(lmax)
140
+ print(
141
+ f"Simulation Info: {N_levels} levels, {N_grids} grids, {Dom_size} cm"
142
+ )
143
+
144
+ # Arrays for quantities
145
+ if quantities.__contains__("density"):
146
+ data_den = rdata['data']
147
+ if quantities.__contains__("logdensity"):
148
+ data_lden = np.log10(rdata['data'])
149
+ if quantities.__contains__("temperature"):
150
+ data_temp = data.get_3Darray("Temperature")['data']
151
+ if quantities.__contains__("pressure"):
152
+ data_pressure = data.get_3Darray("Pressure")['data']
153
+ if quantities.__contains__("NG_Mask"):
154
+ data_ngmask = data.get_3Darray("NG_Mask")['data']
155
+ if quantities.__contains__("windtracer"):
156
+ data_windtr = data.get_3Darray("Tr000_WIND")['data']
157
+ if quantities.__contains__("windtracer0"):
158
+ data_windtr0 = data.get_3Darray("Tr000_WIND0")['data']
159
+ if quantities.__contains__("windtracer1"):
160
+ data_windtr1 = data.get_3Darray("Tr000_WIND1")['data']
161
+ if quantities.__contains__("velocity"):
162
+ data_velx = data.get_3Darray("VelocityX")['data']
163
+ data_vely = data.get_3Darray("VelocityY")['data']
164
+ data_velz = data.get_3Darray("VelocityZ")['data']
165
+ if quantities.__contains__("magnetic_field"):
166
+ data_Bx = data.get_3Darray("MagneticFieldX")['data']
167
+ data_By = data.get_3Darray("MagneticFieldY")['data']
168
+ data_Bz = data.get_3Darray("MagneticFieldZ")['data']
169
+ if quantities.__contains__("xray_emission"):
170
+ df = derived_fields()
171
+ out = df.xray_em_interp3D(data)
172
+ data_emx001 = out['emx_001']
173
+ data_emx002 = out['emx_002']
174
+ data_emx003 = out['emx_003']
175
+ data_emx005 = out['emx_005']
176
+ data_emx010 = out['emx_010']
177
+ data_emx020 = out['emx_020']
178
+ data_emx025 = out['emx_025']
179
+ data_emx030 = out['emx_030']
180
+ data_emx050 = out['emx_050']
181
+ data_emx100 = out['emx_100']
182
+
183
+ grid_data = np.array([
184
+ dict(left_edge=lmin[n],
185
+ right_edge=lmax[n],
186
+ level=n,
187
+ dimensions=N_grids) for n in range(N_levels)
188
+ ])
189
+
190
+ bbox = np.array([lmin[0], lmax[0]]).T
191
+
192
+ i = 0
193
+ for g in grid_data:
194
+ if quantities.__contains__("density"):
195
+ g[("gas", "density")] = (data_den[i], "g/cm**3")
196
+ if quantities.__contains__("logdensity"):
197
+ g[("gas", "logdensity")] = (data_lden[i], "")
198
+ if quantities.__contains__("temperature"):
199
+ g[("gas", "temperature")] = (data_temp[i], "K")
200
+ if quantities.__contains__("pressure"):
201
+ g[("gas", "pressure")] = (data_pressure[i], "dyne/cm**2")
202
+ if quantities.__contains__("NG_Mask"):
203
+ g[("gas", "NG_Mask")] = (data_ngmask[i], "K")
204
+ if quantities.__contains__("windtracer"):
205
+ g[("gas", "windtracer")] = (data_windtr[i], "")
206
+ if quantities.__contains__("windtracer0"):
207
+ g[("gas", "windtracer0")] = (data_windtr0[i], "")
208
+ if quantities.__contains__("windtracer1"):
209
+ g[("gas", "windtracer1")] = (data_windtr1[i], "")
210
+ if quantities.__contains__("velocity"):
211
+ g[("gas", "velocity_x")] = (data_velx[i], "cm/s")
212
+ g[("gas", "velocity_y")] = (data_vely[i], "cm/s")
213
+ g[("gas", "velocity_z")] = (data_velz[i], "cm/s")
214
+ if quantities.__contains__("magnetic_field"):
215
+ g[("gas", "magnetic_field_x")] = (data_Bx[i], "G")
216
+ g[("gas", "magnetic_field_y")] = (data_By[i], "G")
217
+ g[("gas", "magnetic_field_z")] = (data_Bz[i], "G")
218
+ if quantities.__contains__("xray_emission"):
219
+ g[("gas", "xray_0.1")] = (data_emx001[i],
220
+ "erg/cm**3/s/arcmin**2")
221
+ g[("gas", "xray_0.2")] = (data_emx002[i],
222
+ "erg/cm**3/s/arcmin**2")
223
+ g[("gas", "xray_0.3")] = (data_emx003[i],
224
+ "erg/cm**3/s/arcmin**2")
225
+ g[("gas", "xray_0.5")] = (data_emx005[i],
226
+ "erg/cm**3/s/arcmin**2")
227
+ g[("gas", "xray_1.0")] = (data_emx010[i],
228
+ "erg/cm**3/s/arcmin**2")
229
+ g[("gas", "xray_2.0")] = (data_emx020[i],
230
+ "erg/cm**3/s/arcmin**2")
231
+ g[("gas", "xray_2.5")] = (data_emx025[i],
232
+ "erg/cm**3/s/arcmin**2")
233
+ g[("gas", "xray_3.0")] = (data_emx030[i],
234
+ "erg/cm**3/s/arcmin**2")
235
+ g[("gas", "xray_5.0")] = (data_emx050[i],
236
+ "erg/cm**3/s/arcmin**2")
237
+ g[("gas", "xray_10.0")] = (data_emx100[i],
238
+ "erg/cm**3/s/arcmin**2")
239
+ print("adding emissivity to g,", i)
240
+
241
+ i += 1
242
+
243
+ data.close()
244
+
245
+ ds = yt.load_amr_grids(grid_data,
246
+ N_grids,
247
+ length_unit=f"cm",
248
+ geometry=("cartesian"),
249
+ axis_order=("z", "y", "x"),
250
+ sim_time=sim_time.value,
251
+ bbox=bbox,
252
+ time_unit="s",
253
+ unit_system="cgs",
254
+ periodicity=(False, False, False))
255
+ return ds
256
+ ##########################################################################
257
+
258
+ ##########################################################################
259
+
260
+ def get_ds2D(self,
261
+ data,
262
+ quantities=["density"],
263
+ **kwargs) -> yt.data_objects.static_output.Dataset:
264
+ sim_time = data.sim_time()
265
+ N_levels = data.nlevels()
266
+ Dom_size = max(np.array(data.level_max()) - np.array(data.level_min()))
267
+ rdata = data.get_2Darray("Density")
268
+ data_den = rdata['data']
269
+ # get extents in cgs units
270
+ lmin = np.array(rdata['min_extents'])
271
+ lmax = np.array(rdata['max_extents'])
272
+ # switch ordering or array because pion_reader returns ordering (z,y,x)
273
+ lmin[:, [0, 1]] = lmin[:, [1, 0]] # swap z,r
274
+ lmax[:, [0, 1]] = lmax[:, [1, 0]] # swap z,r
275
+ N_grids = np.array(data.ngrid())
276
+ N_grids[[0, 1]] = N_grids[[1, 0]] # swap z,r
277
+ lmin[:, 2] = 0 # theta dir should have finite extent
278
+ lmax[:, 2] = 2.0 * np.pi # theta dir should have finite extent
279
+ #print("lmin",lmin)
280
+ #print("lmax",lmax)
281
+ print(
282
+ f"Simulation Info: {N_levels} levels, {N_grids} grids, {Dom_size} cm"
283
+ )
284
+
285
+ # Arrays for quantities
286
+ if quantities.__contains__("density"):
287
+ data_den = rdata['data']
288
+ if quantities.__contains__("logdensity"):
289
+ data_lden = np.log10(rdata['data'])
290
+ if quantities.__contains__("temperature"):
291
+ data_temp = data.get_2Darray("Temperature")['data']
292
+ if quantities.__contains__("pressure"):
293
+ data_pressure = data.get_2Darray("Pressure")['data']
294
+ if quantities.__contains__("NG_Mask"):
295
+ data_ngmask = data.get_2Darray("NG_Mask")['data']
296
+ if quantities.__contains__("windtracer"):
297
+ data_windtr = data.get_2Darray("Tr000_WIND")['data']
298
+ if quantities.__contains__("windtracer0"):
299
+ data_windtr0 = data.get_2Darray("Tr000_WIND0")['data']
300
+ if quantities.__contains__("windtracer1"):
301
+ data_windtr1 = data.get_2Darray("Tr000_WIND1")['data']
302
+ if quantities.__contains__("velocity"):
303
+ data_velx = data.get_2Darray("VelocityX")['data']
304
+ data_vely = data.get_2Darray("VelocityY")['data']
305
+ data_velz = data.get_2Darray("VelocityZ")['data']
306
+ if quantities.__contains__("magnetic_field"):
307
+ data_Bx = data.get_2Darray("MagneticFieldX")['data']
308
+ data_By = data.get_2Darray("MagneticFieldY")['data']
309
+ data_Bz = data.get_2Darray("MagneticFieldZ")['data']
310
+ if quantities.__contains__("xray_emission"):
311
+ df = derived_fields()
312
+ out = df.xray_em_interp2D(data)
313
+ data_emx001 = out['emx_001']
314
+ data_emx002 = out['emx_002']
315
+ data_emx003 = out['emx_003']
316
+ data_emx005 = out['emx_005']
317
+ data_emx010 = out['emx_010']
318
+ data_emx020 = out['emx_020']
319
+ data_emx025 = out['emx_025']
320
+ data_emx030 = out['emx_030']
321
+ data_emx050 = out['emx_050']
322
+ data_emx100 = out['emx_100']
323
+
324
+ grid_data = np.array([
325
+ dict(left_edge=lmin[n],
326
+ right_edge=lmax[n],
327
+ level=n,
328
+ dimensions=N_grids) for n in range(N_levels)
329
+ ])
330
+ bbox = np.array([lmin[0], lmax[0]]).T
331
+
332
+ i = 0
333
+ for g in grid_data:
334
+ if quantities.__contains__("density"):
335
+ g[("gas", "density")] = (data_den[i].reshape(
336
+ (data_den[i].shape[0], data_den[i].shape[1], 1)),
337
+ "g/cm**3")
338
+ # g[("gas", "density")] = (data_den[i], "g/cm**3")
339
+ if quantities.__contains__("logdensity"):
340
+ g[("gas", "logdensity")] = (data_lden[i].reshape(
341
+ (data_lden[i].shape[0], data_lden[i].shape[1], 1)), "")
342
+ if quantities.__contains__("temperature"):
343
+ g[("gas", "temperature")] = (data_temp[i].reshape(
344
+ (data_temp[i].shape[0], data_temp[i].shape[1], 1)), "K")
345
+ if quantities.__contains__("pressure"):
346
+ g[("gas", "pressure")] = (data_pressure[i].reshape(
347
+ (data_pressure[i].shape[0], data_pressure[i].shape[1], 1)),
348
+ "dyne/cm**2")
349
+ if quantities.__contains__("NG_Mask"):
350
+ g[("gas", "NG_Mask")] = (data_ngmask[i].reshape(
351
+ (data_ngmask[i].shape[0], data_ngmask[i].shape[1], 1)),
352
+ "K")
353
+ if quantities.__contains__("windtracer"):
354
+ g[("gas", "windtracer")] = (data_windtr[i].reshape(
355
+ (data_windtr[i].shape[0], data_windtr[i].shape[1], 1)), "")
356
+ if quantities.__contains__("velocity"):
357
+ g[("gas", "velocity_x")] = (data_velx[i].reshape(
358
+ (data_velx[i].shape[0], data_velx[i].shape[1], 1)), "cm/s")
359
+ g[("gas", "velocity_y")] = (data_vely[i].reshape(
360
+ (data_vely[i].shape[0], data_vely[i].shape[1], 1)), "cm/s")
361
+ g[("gas", "velocity_z")] = (data_velz[i].reshape(
362
+ (data_velz[i].shape[0], data_velz[i].shape[1], 1)), "cm/s")
363
+ if quantities.__contains__("magnetic_field"):
364
+ g[("gas", "magnetic_field_x")] = (data_Bx[i].reshape(
365
+ (data_Bx[i].shape[0], data_Bx[i].shape[1], 1)), "G")
366
+ g[("gas", "magnetic_field_y")] = (data_By[i].reshape(
367
+ (data_By[i].shape[0], data_By[i].shape[1], 1)), "G")
368
+ g[("gas", "magnetic_field_z")] = (data_Bz[i].reshape(
369
+ (data_Bz[i].shape[0], data_Bz[i].shape[1], 1)), "G")
370
+ if quantities.__contains__("xray_emission"):
371
+ g[("gas", "xray_0.1")] = (data_emx001[i].reshape(
372
+ (data_emx001[i].shape[0], data_emx001[i].shape[1], 1)),
373
+ "erg/cm**3/s/arcmin**2")
374
+ g[("gas", "xray_0.2")] = (data_emx002[i].reshape(
375
+ (data_emx002[i].shape[0], data_emx002[i].shape[1], 1)),
376
+ "erg/cm**3/s/arcmin**2")
377
+ g[("gas", "xray_0.3")] = (data_emx003[i].reshape(
378
+ (data_emx003[i].shape[0], data_emx003[i].shape[1], 1)),
379
+ "erg/cm**3/s/arcmin**2")
380
+ g[("gas", "xray_0.5")] = (data_emx005[i].reshape(
381
+ (data_emx005[i].shape[0], data_emx005[i].shape[1], 1)),
382
+ "erg/cm**3/s/arcmin**2")
383
+ g[("gas", "xray_1.0")] = (data_emx010[i].reshape(
384
+ (data_emx010[i].shape[0], data_emx010[i].shape[1], 1)),
385
+ "erg/cm**3/s/arcmin**2")
386
+ g[("gas", "xray_2.0")] = (data_emx020[i].reshape(
387
+ (data_emx020[i].shape[0], data_emx020[i].shape[1], 1)),
388
+ "erg/cm**3/s/arcmin**2")
389
+ g[("gas", "xray_2.5")] = (data_emx025[i].reshape(
390
+ (data_emx025[i].shape[0], data_emx025[i].shape[1], 1)),
391
+ "erg/cm**3/s/arcmin**2")
392
+ g[("gas", "xray_3.0")] = (data_emx030[i].reshape(
393
+ (data_emx030[i].shape[0], data_emx030[i].shape[1], 1)),
394
+ "erg/cm**3/s/arcmin**2")
395
+ g[("gas", "xray_5.0")] = (data_emx050[i].reshape(
396
+ (data_emx050[i].shape[0], data_emx050[i].shape[1], 1)),
397
+ "erg/cm**3/s/arcmin**2")
398
+ g[("gas", "xray_10.0")] = (data_emx100[i].reshape(
399
+ (data_emx100[i].shape[0], data_emx100[i].shape[1], 1)),
400
+ "erg/cm**3/s/arcmin**2")
401
+ print("adding emissivity to g,", i)
402
+
403
+ i += 1
404
+
405
+ data.close()
406
+
407
+ ds = yt.load_amr_grids(grid_data,
408
+ N_grids,
409
+ length_unit=f"cm",
410
+ geometry=("cylindrical"),
411
+ axis_order=("r", "z", "theta"),
412
+ sim_time=sim_time.value,
413
+ bbox=bbox,
414
+ time_unit="s",
415
+ unit_system="cgs",
416
+ periodicity=(False, False, True))
417
+ return ds
418
+ ##########################################################################
419
+
420
+ ##########################################################################
421
+ # Create list of yt datasets representing a time series of simulation
422
+ # snapshots.
423
+
424
+ def get_ts(self, selfevolution, **kwargs):
425
+
426
+ ds_list = []
427
+
428
+ start = kwargs.get('start', 1)
429
+ end = kwargs.get('end', 10)
430
+ step = kwargs.get('step', 1)
431
+
432
+ # Load the desired snapshots
433
+ for i in range(start, end, step):
434
+ ds_list.append(
435
+ get_ds(evolution[i],
436
+ quantities=kwargs.get("quantities", ["density"]),
437
+ start_time=kwargs.get("start_time", 0)))
438
+
439
+ print("Number of datasets: ", len(ds_list))
440
+ # Create time series object
441
+ return yt.DatasetSeries(ds_list)
442
+ del ds_list
443
+
444
+
445
+ ##########################################################################