From eca70ba3df84335c777c1f97a2f669fd6058ef04 Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Thu, 3 Nov 2016 16:49:10 -0400 Subject: [PATCH 1/4] Fix PyAPI plot pixels bug; add aspect ratio --- openmc/universe.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/openmc/universe.py b/openmc/universe.py index 545b05d5a1..fc71d9a2ec 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -153,7 +153,8 @@ class Universe(object): return [] def plot(self, center=(0., 0., 0.), width=(1., 1.), pixels=(200, 200), - basis='xy', color_by='cell', colors=None, filename=None, seed=None): + basis='xy', color_by='cell', colors=None, filename=None, seed=None, + aspect='auto'): """Display a slice plot of the universe. Parameters @@ -171,9 +172,9 @@ class Universe(object): colors : dict Assigns colors to specific materials or cells. Keys are instances of - :class:`Cell` or :class:`Material` and values are RGB 3-tuples or RGBA - 4-tuples. Red, green, blue, and alpha should all be floats in the - range [0.0, 1.0], for example: + :class:`Cell` or :class:`Material` and values are RGB 3-tuples or + RGBA 4-tuples. Red, green, blue, and alpha should all be floats in + the range [0.0, 1.0], for example: .. code-block:: python @@ -188,6 +189,9 @@ class Universe(object): Hashable object which is used to seed the random number generator used to select colors. If None, the generator is seeded from the current time. + aspect : 'auto' or Real or None + This argument is passed directly to matplotlib.pyplot.imshow. + 'auto' makes the image aspect ratio match the physical units. """ import matplotlib.pyplot as plt @@ -211,7 +215,8 @@ class Universe(object): y_min = center[1] - 0.5*width[1] y_max = center[1] + 0.5*width[1] elif basis == 'yz': - # The x-axis will correspond to physical y and the y-axis will correspond to physical z + # The x-axis will correspond to physical y and the y-axis will + # correspond to physical z x_min = center[1] - 0.5*width[0] x_max = center[1] + 0.5*width[0] y_min = center[2] - 0.5*width[1] @@ -229,8 +234,9 @@ class Universe(object): y_coords = np.linspace(y_max, y_min, pixels[1], endpoint=False) - \ 0.5*(y_max - y_min)/pixels[1] - # Search for locations and assign colors - img = np.zeros(pixels + (4,)) # Use RGBA form + # Initialize output image in RGBA format. Flip the pixels from + # traditional (x, y) to (y, x) used in graphics. + img = np.zeros((pixels[1], pixels[0], 4)) for i, x in enumerate(x_coords): for j, y in enumerate(y_coords): if basis == 'xy': @@ -257,7 +263,7 @@ class Universe(object): img[j, i, :] = colors[obj] # Display image - plt.imshow(img, extent=(x_min, x_max, y_min, y_max)) + plt.imshow(img, extent=(x_min, x_max, y_min, y_max), aspect=aspect) # Show or save the plot if filename is None: From df1d82708ed41134d57c3dc13828e76a5e45ea4b Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Tue, 8 Nov 2016 13:16:20 -0500 Subject: [PATCH 2/4] Make Universe.plot pass kwargs to matplotlib --- openmc/universe.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/openmc/universe.py b/openmc/universe.py index fc71d9a2ec..260b9faf4c 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -154,7 +154,7 @@ class Universe(object): def plot(self, center=(0., 0., 0.), width=(1., 1.), pixels=(200, 200), basis='xy', color_by='cell', colors=None, filename=None, seed=None, - aspect='auto'): + **kwargs): """Display a slice plot of the universe. Parameters @@ -189,9 +189,11 @@ class Universe(object): Hashable object which is used to seed the random number generator used to select colors. If None, the generator is seeded from the current time. - aspect : 'auto' or Real or None - This argument is passed directly to matplotlib.pyplot.imshow. - 'auto' makes the image aspect ratio match the physical units. + + Keyword arguments + ----------------- + All keyword arguments are passed to matplotlib.pyplot.imshow. See the + matplotlib documentation for available kwargs. """ import matplotlib.pyplot as plt @@ -263,7 +265,7 @@ class Universe(object): img[j, i, :] = colors[obj] # Display image - plt.imshow(img, extent=(x_min, x_max, y_min, y_max), aspect=aspect) + plt.imshow(img, extent=(x_min, x_max, y_min, y_max), **kwargs) # Show or save the plot if filename is None: From daa6b9a10b9bbb523d93995d3e0bb9fd28810589 Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Tue, 8 Nov 2016 18:20:08 -0500 Subject: [PATCH 3/4] Link Universe.plot docstring to matplotlib docs --- docs/source/conf.py | 3 ++- openmc/universe.py | 8 +++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 75e621bc17..672217c84f 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -249,5 +249,6 @@ napoleon_use_ivar = True intersphinx_mapping = { 'python': ('https://docs.python.org/3', None), 'numpy': ('http://docs.scipy.org/doc/numpy/', None), - 'pandas': ('http://pandas.pydata.org/pandas-docs/stable/', None) + 'pandas': ('http://pandas.pydata.org/pandas-docs/stable/', None), + 'matplotlib': ('http://matplotlib.org/', None) } diff --git a/openmc/universe.py b/openmc/universe.py index 260b9faf4c..b2e7dbb920 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -189,11 +189,9 @@ class Universe(object): Hashable object which is used to seed the random number generator used to select colors. If None, the generator is seeded from the current time. - - Keyword arguments - ----------------- - All keyword arguments are passed to matplotlib.pyplot.imshow. See the - matplotlib documentation for available kwargs. + **kwargs + All keyword arguments are passed to + :func:`matplotlib.pyplot.imshow`. """ import matplotlib.pyplot as plt From db1cf06a4d96e8bd13ae734c35103145002382aa Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Wed, 9 Nov 2016 12:56:03 -0600 Subject: [PATCH 4/4] Fix argument in h5sget_simple_extend_ndims_f --- src/hdf5_interface.F90 | 2 +- src/mgxs_header.F90 | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/hdf5_interface.F90 b/src/hdf5_interface.F90 index c8892c53c4..2a0711954f 100644 --- a/src/hdf5_interface.F90 +++ b/src/hdf5_interface.F90 @@ -2589,7 +2589,7 @@ contains subroutine get_ndims(obj_id, ndims) integer(HID_T), intent(in) :: obj_id - integer(HID_T), intent(out) :: ndims + integer, intent(out) :: ndims integer :: hdf5_err integer :: type diff --git a/src/mgxs_header.F90 b/src/mgxs_header.F90 index fc5e8cb3e1..17104d5088 100644 --- a/src/mgxs_header.F90 +++ b/src/mgxs_header.F90 @@ -430,7 +430,8 @@ module mgxs_header ! in that conversion character(MAX_LINE_LEN) :: temp_str - integer(HID_T) :: xsdata, xsdata_grp, scatt_grp, ndims + integer(HID_T) :: xsdata, xsdata_grp, scatt_grp + integer :: ndims integer(HSIZE_T) :: dims(2) real(8), allocatable :: temp_arr(:), temp_2d(:, :) real(8), allocatable :: temp_beta(:, :) @@ -1113,7 +1114,8 @@ module mgxs_header ! in that conversion character(MAX_LINE_LEN) :: temp_str - integer(HID_T) :: xsdata, xsdata_grp, scatt_grp, ndims + integer(HID_T) :: xsdata, xsdata_grp, scatt_grp + integer :: ndims integer(HSIZE_T) :: dims(4) integer, allocatable :: int_arr(:) real(8), allocatable :: temp_1d(:), temp_3d(:, :, :)