<commit_before>
from rssynergia.base_diagnostics import lfplot

def row_has_data(row):
    for k in row:
        if k != 'name' and row[k] != 0:
            return True
    return False

lattice = synergia.lattice.MadX_reader().get_lattice('{{ use_beamline }}', LATTICE_FILE)
stepper = synergia.simulation.Independent_stepper_elements(
    lattice,
    {{ simulationSettings_map_order }}, # map_order
    5 # num_steps_per_element
)
twiss = lfplot.get_sliced_lf_fns(lattice, stepper.get_lattice_simulator())

import h5py
import numpy as np
h5file = h5py.File('{{ twissFileName }}', 'w')
for k in twiss[0]:
    d = h5py.string_dtype(encoding='utf-8') if k == 'name' else np.dtype(float)
    rows = []
    for row in twiss:
        if row_has_data(row):
            rows.append(row[k])
    data = h5file.create_dataset(k, (len(rows),), dtype=d)
    data[:] = rows
h5file.close()<commit_msg>Revert "fix #2406 use proper string type for h5py"<commit_after>
from rssynergia.base_diagnostics import lfplot

def row_has_data(row):
    for k in row:
        if k != 'name' and row[k] != 0:
            return True
    return False

lattice = synergia.lattice.MadX_reader().get_lattice('{{ use_beamline }}', LATTICE_FILE)
stepper = synergia.simulation.Independent_stepper_elements(
    lattice,
    {{ simulationSettings_map_order }}, # map_order
    5 # num_steps_per_element
)
twiss = lfplot.get_sliced_lf_fns(lattice, stepper.get_lattice_simulator())

import h5py
import numpy as np
h5file = h5py.File('{{ twissFileName }}', 'w')
for k in twiss[0]:
    dtype = np.dtype('a30') if k == 'name' else np.dtype(float)
    rows = []
    for row in twiss:
        if row_has_data(row):
            rows.append(row[k])
    data = h5file.create_dataset(k, (len(rows),), dtype=dtype)
    data[:] = rows
h5file.close()
{'fraction_non_alphanumeric': 0.12826207662409772, 'fraction_numerical': 0.0138811771238201, 'mean_word_length': 3.717277486910995, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3013744', 'n_tokens_mistral': 677, 'n_tokens_neox': 669, 'n_words': 149}