athenakit.io
I/O utilities for reading and writing AthenaK data formats.
Binary reader
- Functions to:
convert bin –> Python dictionary
convert Python dictionary –> athdf(xdmf) files
This module contains a collection of helper functions for reading and writing athena file data formats. More information is provided in the function docstrings.
In order to translate a binary file into athdf and corresponding xdmf files, you could do the following:
import bin_convert import os
binary_fname = “path/to/file.bin” athdf_fname = binary_fname.replace(“.bin”, “.athdf”) xdmf_fname = athdf_fname + “.xdmf” filedata = bin_convert.read_binary(binary_fname) bin_convert.write_athdf(athdf_fname, filedata) bin_convert.write_xdmf_for(xdmf_fname, os.path.basename(athdf_fname), filedata)
Notice that write_xdmf_for(…) function expects the relative path to the athdf file from the xdmf, so please be aware of this requirement.
The read_*(…) functions return a filedata dictionary-like object with
- filedata[‘header’] = array of strings
ordered array of header, including all the header information
- filedata[‘time’] = float
time from input file
- filedata[‘cycle’] = int
cycle from input file
- filedata[‘var_names’] = array of strings
ordered array of variable names, like [‘dens’, ‘eint’, …]
- filedata[‘n_mbs’] = int
total number of meshblocks in the file
- filedata[‘nx1_mb’] = int
number of cells in x1 direction in MeshBlock
- filedata[‘nx2_mb’] = int
number of cells in x2 direction in MeshBlock
- filedata[‘nx3_mb’] = int
number of cells in x3 direction in MeshBlock
- filedata[‘nx1_out_mb’] = int
number of output cells in x1 direction in MeshBlock (useful for slicing)
- filedata[‘nx2_out_mb’] = int
number of output cells in x2 direction in MeshBlock (useful for slicing)
- filedata[‘nx3_out_mb’] = int
number of output cells in x3 direction in MeshBlock (useful for slicing)
- filedata[‘Nx1’] = int
total number of cell in x1 direction in root grid
- filedata[‘Nx2’] = int
total number of cell in x2 direction in root grid
- filedata[‘Nx3’] = int
total number of cell in x3 direction in root grid
- filedata[‘x1min’] = float
coordinate minimum of root grid in x1 direction
- filedata[‘x1max’] = float
coordinate maximum of root grid in x1 direction
- filedata[‘x2min’] = float
coordinate minimum of root grid in x2 direction
- filedata[‘x2max’] = float
coordinate maximum of root grid in x2 direction
- filedata[‘x3min’] = float
coordinate minimum of root grid in x3 direction
- filedata[‘x3max’] = float
coordinate maximum of root grid in x3 direction
- filedata[‘nvars’] = int
number of output variables (including magnetic field if it exists)
- filedata[‘mb_index’] = array with shape [n_mbs, 6]
is,ie,js,je,ks,ke range for output MeshBlock indexing (useful for slicing)
- filedata[‘mb_logical’] = array with shape [n_mbs, 4]
i,j,k,level coordinates for each MeshBlock
- filedata[‘mb_geometry’] = array with shape [n_mbs, 6]
x1i,x2i,x3i,dx1,dx2,dx3 including cell-centered location of left-most cell and offsets between cells
- filedata[‘mb_data’] = dict of arrays with shape [n_mbs, nx3, nx2, nx1]
{‘var1’:var1_array, ‘var2’:var2_array, …} dictionary of fluid data arrays for each variable in var_names
- athenakit.io.bin_convert.read_binary(filename)[source]
Reads a bin file from filename to dictionary.
Originally written by Lev Arzamasskiy (leva@ias.edu) on 11/15/2021 Updated to support mesh refinement by George Wong (gnwong@ias.edu) on 01/27/2022
- Parameters:
string (filename -) – filename of bin file to read
- Returns:
- filedata - dict
dictionary of fluid file data
- athenakit.io.bin_convert.write_athdf(filename, fdata, varsize_bytes=4, locsize_bytes=8)[source]
Writes an athdf (hdf5) file from a loaded python filedata object.
- Parameters:
string (filename -) – filename for output athdf (hdf5) file
dict (fdata -) – dictionary of fluid file data, e.g., as loaded from read_binary(…)
int (locsize_bytes -) – number of bytes to use for output variable data
int – number of bytes to use for output location data
- athenakit.io.bin_convert.write_xdmf_for(xdmfname, dumpname, fdata, mode='auto')[source]
Writes an xdmf file for a fluid snapshot file.
- Parameters:
string (mode -) – name of xdmf file
string – location of fluid data file relative to xdmfname directory
dict (fdata -) – dictionary of fluid file data, e.g., as loaded from read_binary(…)
string – force xdmf for format (auto sets by extension)