<commit_before>#!/usr/bin/env python

import h5py
from lxml import etree
import numpy as np
from scipy.optimize import curve_fit
import matplotlib.pyplot as plt
from matplotlib.ticker import FormatStrFormatter

# helper functions
# ====================

def grab_density_parameters(qmc_input_xml):
    root = etree.parse(qmc_input_xml)
    dens_est = root.find("qmcsystem/hamiltonian/estimator")
    nx,ny,nz = [int(1./float(x)) for x in dens_est.attrib["delta"].split()]

    x = np.linspace( float(dens_est.attrib["x_min"]),
                    float(dens_est.attrib["x_max"]),nx)
    y = np.linspace( float(dens_est.attrib["y_min"]),
                    float(dens_est.attrib["y_max"]),ny)
    z = np.linspace( float(dens_est.attrib["z_min"]),
                    float(dens_est.attrib["z_max"]),nz)
    
    return x,y,z
# end def grab_density_parameters

def grab_density(h5file):
    # get density
    f = h5py.File(h5file)
    for name,quantity in f.items():<commit_msg>more robust density estimator entry<commit_after>#!/usr/bin/env python

import h5py
from lxml import etree
import numpy as np
from scipy.optimize import curve_fit
import matplotlib.pyplot as plt
from matplotlib.ticker import FormatStrFormatter

# helper functions
# ====================

def grab_density_parameters(qmc_input_xml):
    root = etree.parse(qmc_input_xml)
    dens_est_list = root.xpath('//estimator[@type="density"]')
    if len(dens_est_list) != 1:
        print "expected 1 density estimator, found: ", len(dens_est_list)
        raise InputError()
    # end if
    dens_est = dens_est_list[0]
    nx,ny,nz = [int(1./float(x)) for x in dens_est.attrib["delta"].split()]

    x = np.linspace( float(dens_est.attrib["x_min"]),
                    float(dens_est.attrib["x_max"]),nx)
    y = np.linspace( float(dens_est.attrib["y_min"]),
                    float(dens_est.attrib["y_max"]),ny)
    z = np.linspace( float(dens_est.attrib["z_min"]),
                    float(dens_est.attrib["z_max"]),nz)
    
    return x,y,z
# end def grab_density_parameters

def grab_density(h5file):
    # get density
    f = h5py.File(h5file)
    for name,quantity in f.items():
{'fraction_non_alphanumeric': 0.14371812702828002, 'fraction_numerical': 0.00602688919796013, 'mean_word_length': 3.5431578947368423, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '1596469', 'n_tokens_mistral': 794, 'n_tokens_neox': 765, 'n_words': 149}