Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge: fileBased -> groupBased #4

Open
ax3l opened this issue Jan 9, 2017 · 0 comments
Open

Merge: fileBased -> groupBased #4

ax3l opened this issue Jan 9, 2017 · 0 comments

Comments

@ax3l
Copy link
Member

ax3l commented Jan 9, 2017

I recently needed a small script that converted our usual "fileBased" iterationEncoding to a single "groupBased" file (in HDF5).

Next time I need it I will rewrite it in pure python so it's more portable. (Actually, I tried pure bash but needed a small in-file manipulation which I found no CLI tool for).

Nevertheless, here it is already:

#!/usr/bin/env bash
#
# Copyright 2017 Axel Huebl
#
# Use under the ISC software license.
#

# needs input argument parsing & help

dumps=($(ls h5/*_*.h5))
first=0

for d in ${dumps[@]};
do
    if [ $first -eq 0 ]
    then
        # includes copy of / attributes from first file
        cp $d simData.h5
        first=1
    else
        step=$(echo $d | sed 's/.\+_\([0-9]\+\)\.h5/\1/')
        h5copy -i $d -s "/data/$step" \
               -o simData.h5 -d "/data/$step"
    fi
done

# that might not be necessary if your files already had compression enabled
h5repack -i simData.h5 -o simData.h5.gz -f GZIP=1 && \
    mv simData.h5.gz simData.h5

# change attributes:
#   "/iterationEncoding" -> "groupBased"
#   "/iterationFormat" -> "/data/%T/"
python -c 'import h5py; import numpy as np; f=h5py.File("simData.h5", "a"); f.attrs["iterationEncoding"] = np.string_("groupBased"); f.attrs["iterationFormat"] = np.string_("/data/%T/"); f.close()'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant