From cb2267c79a9266d2fe88448207256451905621a0 Mon Sep 17 00:00:00 2001 From: otto Date: Mon, 27 Oct 2025 09:05:27 +0200 Subject: [PATCH] converting .h5 files --- scaling_converter.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 scaling_converter.py diff --git a/scaling_converter.py b/scaling_converter.py new file mode 100644 index 0000000..33dffa6 --- /dev/null +++ b/scaling_converter.py @@ -0,0 +1,26 @@ +"scaling the images, so that the maximums would be the same" + +import numpy as np +import h5py +import argparse + +parser = argparse.ArgumentParser() +parser.add_argument("--infile", type = str, help = "input file with all the calculated images") +parser.add_argument('--converted', type = str, help = 'name of the converted data file') + +args = parser.parse_args() + + +with h5py.File(args.infile, 'r') as input_images, h5py.File(args.converted, 'w') as converter: + for name in input_images: + if isinstance(input_images[name], h5py.Group): + input_images.copy(name, converter) + + def conv(name, obj): + if isinstance(obj, h5py.Dataset): + data = obj[:] + mod = data / np.max(data) * 100 + obj[...] = mod + + converter.visititems(conv) +