2d slice python script not working properly

11 views
Skip to first unread message

Mateusz Pater

unread,
Jun 18, 2019, 5:20:16 AM6/18/19
to moltres-users
Hello again,

While browsing through Moltres repositories I came across some python scripts that seem to be very useful in visualizing data, like this one, which plots slices of the reactor and chosen variables:

import yt
from moltres_functions import actual_center_and_widths

home_root = '/home/peppe/'

field_label = {
  'group1': r'$\phi_1\cdot$10$^{13}$ cm$^{-2}$ s$^{-1}$',
  'group2': r'$\phi_2\cdot$10$^{13}$ cm$^{-2}$ s$^{-1}$',
  'temp': 'T (K)',
  'pre1': r'C$_1$ cm$^{-3}$',
  'pre2': r'C$_2$ cm$^{-3}$',
  'pre3': r'C$_3$ cm$^{-3}$',
  'pre4': r'C$_4$ cm$^{-3}$',
  'pre5': r'C$_5$ cm$^{-3}$',
  'pre6': r'C$_6$ cm$^{-3}$'}
names = [name for name in field_label.keys() if 'pre' in name]
for name in names:
  field_label[name + '_scaled'] = field_label[name]


def _scale(field, data):
  new_field = field.name
  ftype, fname = new_field
  original_fname = fname.split('_')[0]
  return 1e13 * data[('all', original_fname)]


ds = yt.load(
  home_root +
  'projects/2group_out.e', step=-1)
for i in range(1, 7):
  fname = 'pre%d_scaled' % i
  ds.add_field(('all', fname), function=_scale, take_log=False)
actual_domain_widths, actual_center = actual_center_and_widths(ds)

for field in ds.field_info.keys():
  field_type, field_name = field
  if field_type != 'all':
      continue
  if 'scaled' not in field_name and 'temp' not in field_name and 'group' not in field_name:
      continue
  slc = yt.SlicePlot(ds, 'z', field, origin='native', center=actual_center)
  slc.set_log(field, False)
  slc.set_width((actual_domain_widths[0], actual_domain_widths[1]))
  slc.set_xlabel("r (cm)")
  slc.set_ylabel("z (cm)")
  if field_name == 'temp':
      slc.set_zlim(field, 922, ds.all_data()[('all', 'temp')].max())
  slc.set_colorbar_label(field, field_label[field_name])
  slc.set_figure_size(3)
  slc.save(home_root + 'projects/' +
           field_name)


After running it, only the 'group2' slice appeared and I don't know how to fix it so that all images are created. The error shown in the terminal goes as follows:

Traceback (most recent call last):
  File "slice.py", line 43, in <module>
    slc = yt.SlicePlot(ds, 'z', field, center=actual_center)
  File "/home/peppe/yt/yt-conda/lib/python2.7/site-packages/yt/visualization/plot_window.py", line 1977, in SlicePlot
    return AxisAlignedSlicePlot(ds, normal, fields, *args, **kwargs)
  File "/home/peppe/yt/yt-conda/lib/python2.7/site-packages/yt/visualization/plot_window.py", line 1289, in __init__
    slc.get_data(fields)
  File "/home/peppe/yt/yt-conda/lib/python2.7/site-packages/yt/data_objects/data_containers.py", line 1370, in get_data
    fluids, self, self._current_chunk)
  File "/home/peppe/yt/yt-conda/lib/python2.7/site-packages/yt/geometry/geometry_handler.py", line 245, in _read_fluid_fields
    chunk_size)
  File "/home/peppe/yt/yt-conda/lib/python2.7/site-packages/yt/frontends/exodus_ii/io.py", line 86, in _read_fluid_selection
    (field_ind + 1, mesh_id)][:]
KeyError: 'vals_elem_var4eb2'

I also tried plotting precursor concentrations only, using LinePlot.from_lines but there was a similar error. Is it happening because of my YT, because the Exodus format has changed, or is it the python script itself?
I would be grateful if someone had a look at this issue.
Thank you,
Matt

Huff, Kathryn D

unread,
Jun 24, 2019, 9:52:33 PM6/24/19
to moltres-users
Looks like maybe a yt version issue? 


--
You received this message because you are subscribed to the Google Groups "moltres-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to moltres-user...@googlegroups.com.
To post to this group, send email to moltre...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/moltres-users/73ff56cf-da8a-4504-b7f1-52c5a079b5a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Kathryn Huff
Assistant Professor
Nuclear, Plasma, and Radiological Engineering
The University of Illinois at Urbana-Champaign
Preferred Pronoun: she/her
Research group site: http://arfc.npre.illinois.edu/ 
Office: 118 Talbot Laboratory, 104 S. Wright St. 
Book a meeting with me: https://katyhuff.youcanbook.me/

Mateusz Pater

unread,
Jun 25, 2019, 7:29:02 AM6/25/19
to moltres-users
I downgraded yt to 3.4.0 but the error seems to remain the same
Reply all
Reply to author
Forward
0 new messages