pyexodus¶
Pure Python (still requires h5py and numpy) package to write exodus files. It emulates the Python API of the official Python exodus wrapper but is much much easier to get going. Additionally it manages to avoid the installation of two very large C/C++ libraries (netCDF and exodus) that are potentially tricky to install, and is also easy to install on Windows.
Additionally it is quite a bit faster (I guess due to more direct memory to file paths), uses less memory, and supports Python 2.7, 3.4, 3.5, and 3.6.
Don’t expect this to be complete anytime soon - we will add stuff as soon as we need it.
Installation¶
$ conda install -c conda-forge numpy h5netcdf pip pytest
$ git clone https://github.com/SalvusHub/pyexodus.git
$ cd pyexodus
$ pip install -v -e .
# Run the tests to make sure everything works.
$ py.test
API¶
Deviations from the official API¶
By and large pyexodus
aims to be fully compatible with the official Python exodus API.
Deviations are listed here.
- It supports optional compression. This is quite a bit slower to write but can have a very
big impact on file size. See the
compression
argument ofpyexodus.exodus
. pyexodus.exodus.put_elem_connectivity()
has two additional optional arguments:shift_indices
andchunk_size_in_mb
.pyexodus.exodus.get_elem_connectivity()
has an additional optional argument:indices
.pyexodus.exodus.get_coord()
can also take a list of indices.- New methods:
-
pyexodus.exodus.get_elem_type_for_block()
- Convenient properites on the
pyexodus.exodus
object: -pyexodus.exodus.num_dims
-
class
pyexodus.
exodus
(file, mode='r', array_type='numpy', title=None, numDims=None, numNodes=None, numElems=None, numBlocks=None, numNodeSets=None, numSideSets=None, io_size=0, compression=None)[source]¶ Create a new Exodus file. Can also be used as a context manager.
Parameters: - file (str) – Filename
- mode (str) – File mode. Must currently be
"r"
,"a"
, or"w"
. - array_type (str) – Must be
"numpy"
. - title (str) – The title of the mesh.
- numDims (int) – The number of dimensions.
- numNodes (int) – The number of nodes.
- numElems (int) – The number of elements.
- numBlocks (int) – The number of element blocks.
- numNodeSets (int) – The number of node side sets.
- numSideSets (int) – The number of element side sets.
- io_size (int) –
Determines how floating point variables are stored in the file. Inputs will be converted if required.
0
: machine precision4
: single precision8
: double precision
- compression (tuple) – Turn on compression. Pass a tuple of
(method, option)
, e.g.("gzip", 2)
. Slows down writing a lot but the resulting files are potentially much smaller.
-
get_coord
(i)[source]¶ Get x, y, z of i-th node in the exodus file.
Parameters: i (int or array/list of ints) – Node index or indices. 1-based. The official exodus API can only take single indices - pyexodus can take a list of indices. In that case it will still return a three-tuple, but each now contains multiple variables.
-
get_elem_connectivity
(id, indices=None)[source]¶ Get the connectivity for a certain element block.
Returns a tuple with three things: The actual connectivity as an array of node indices, the number of elements in this block, and the number of nodes per elements in this block.
Parameters: - id (int) – Id of the element block.
- indices (
numpy.ndarray
) – If given, only get the connectivity of the specified element indices relative to the element block. These are 1-based indices in accordance with the exodus convention! Note that the second and third returned item are always stats for the whole connectivity array regardless of this argument. This parameter is not part of the official exodus Python API.
-
get_elem_type_for_block
(id)[source]¶ Return the element type for an element block as a string.
Note
This method does not have a counter part in the official exodus Python API.
Parameters: id (int) – The element block id.
-
get_element_variable_values
(blockId, name, step)[source]¶ Get values from element block id and variable name at step.
Parameters: Return values: The actual values.
-
get_node_variable_values
(name, step)[source]¶ Get the node variable values for a a certain step.
Parameters:
-
get_side_set
(id)[source]¶ Get element and side ids for a certain side set.
Returns a tuple of two arrays. The first are the element indices, the second the side ids in these elements.
Parameters: id (int) – The id of the side set.
-
get_side_set_node_list
(id)[source]¶ Get the nodes for a certain side set.
Returns a tuple of two arrays. The first contains the number of nodes on each face the the seconds are the local node ids for the side set in the exodus file.
Parameters: id (int) – The id of the side set.
-
num_dims
¶ Number of dimensions in the exodus file.
-
put_coords
(xCoords, yCoords, zCoords)[source]¶ Put coordinates in the exodus file.
Parameters: - xCoords (
numpy.ndarray
) – The X coordiantes. - yCoords (
numpy.ndarray
) – The Y coordinates. - zCoords (
numpy.ndarray
) – The Z coordinates.
- xCoords (
-
put_elem_blk_info
(id, elemType, numElems, numNodesPerElem, numAttrsPerElem)[source]¶ Set the details of an element block.
Parameters:
-
put_elem_connectivity
(id, connectivity, shift_indices=0, chunk_size_in_mb=128)[source]¶ Set the element connectivity array for all elements in a block.
The information for this block must have already been set by calling e.put_elem_blk_info() on this block.
Parameters: - id (int) – The id of the element block.
- connectivity (
numpy.ndarray
) – The connectivity. Must be equal to the number of of elements times the number of nodes per element for any given block. - shift_indices (int) – Not available in the official exodus Python API! This value will be added to all indices before they are written to the file. This is useful if you for example internally work with a 0-based indexing scheme but exodus requires a 1-based indexing scheme.
- chunk_size_in_mb (int) – If
shift_indices
!= 0 values will be written in chunks of this size. This is also the maximum memory usage of this method. Ifshift_indices
== 0, all indices will be written directly from memory and no additional memory is required.
-
put_element_variable_name
(name, index)[source]¶ Element variable with name at index into exodus file.
Parameters:
-
put_element_variable_values
(blockId, name, step, values)[source]¶ Put values into element block id and variable name at step.
Parameters:
-
put_global_variable_name
(name, index)[source]¶ Put global variable with name at index into exodus file.
Parameters:
-
put_global_variable_value
(name, step, value)[source]¶ Put global variable value and variable name at time step into exodus file.
Parameters:
-
put_info_records
(info)[source]¶ Puts the info records into the exodus file.
Does currently not do anything.
Parameters: info (list of str) – The strings to save.
-
put_node_variable_name
(name, index)[source]¶ Node variable with name at index into exodus file.
Parameters:
-
put_node_variable_values
(name, step, values)[source]¶ Put node values into variable name at step into exodus file
Parameters:
-
put_side_set
(id, sideSetElements, sideSetSides)[source]¶ Set the id, element ids, and side ids for a side set (creates the side set).
Parameters: - id (int) – The id of the side set.
- sideSetElements (
numpy.ndarray
) – The side set elements. - sideSetSides (
numpy.ndarray
) – The side set sides.
-
put_side_set_name
(id, name)[source]¶ Write side set name for side set “id” in exodus file
Parameters:
-
put_side_set_params
(id, numSetSides, numSetDistFacts)[source]¶ Set ID, num elements, and num nodes of a sideset
Parameters:
-
set_element_variable_number
(number)[source]¶ Set number of element variables in exodus file.
Parameters: number (int) – The number of variables per element.
Note
Acknowledgements
- The offical Python API can be here: https://github.com/gsjaardema/seacas
- Logo made by Roundicons from http://www.flaticon.com (Creative Commons BY 3.0 License)