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

import csv
from itertools import chain
import os
import sys

import click
import numpy as np

from htsohm import load_config_file, db
from htsohm.db import Material
from htsohm.htsohm_serial import calc_bins

def dof_analysis(config_path, output_directory, run_id=None):
    config = load_config_file(config_path)
    db.init_database(config["database_connection_string"])
    session = db.get_session()

    children_per_generation = config['children_per_generation']
    prop1range = config['prop1range']
    prop2range = config['prop2range']

    num_bins = config['number_of_convergence_bins']
    bin_counts = np.zeros((num_bins, num_bins))

    vf_binunits = (prop1range[1] - prop1range[0]) / num_bins
    ml_binunits = (prop2range[1] - prop2range[0]) / num_bins

    materials = session.query(Material)
    if run_id:
        materials = materials.filter(Material.run_id==run_id)

    perturbation_types = ["lattice", "lattice_nodens", "atom_types", "atom_sites", "density", "all"]

    tsv_output_path = os.path.join(output_directory, "data.tsv")
    tsvfile = open(tsv_output_path, 'w')
    tsv = csv.writer(tsvfile, delimiter="\t", lineterminator="\n")
    tsv.writerow([""] + list(chain.from_iterable([[t] * 5 for t in perturbation_types])))
    tsv.writerow(["gen"] + list(chain.from_iterable([["#", "∆vf", "∆ml", "dist", "new_bins"] for t in perturbation_types])))

    mats_d = materials.all()
    mats_r = [(m.void_fraction[0].void_fraction, m.gas_loading[0].absolute_volumetric_loading) for m in mats_d]

    new_mats_d = mats_d[0:children_per_generation]
    new_mats_r = mats_r[0:children_per_generation]
    new_bins = calc_bins(new_mats_r, num_bins, prop1range=prop1range, prop2range=prop2range)
    for i, (bx, by) in enumerate(new_bins):
        bin_counts[bx,by] += 1

    pts = {t:[] for t in perturbation_types}
    gen = 1
    new_mats_d = mats_d[gen*children_per_generation:(gen + 1)*children_per_generation]
    new_mats_r = mats_r[gen*children_per_generation:(gen + 1)*children_per_generation]
    animation = []
    while len(new_mats_d) > 0:
        new_bins = calc_bins(new_mats_r, num_bins, prop1range=prop1range, prop2range=prop2range)

        gen_animation = []<commit_msg>initial random generation should show in animation<commit_after>#!/usr/bin/env python3

import csv
from itertools import chain
import os
import sys

import click
import numpy as np

from htsohm import load_config_file, db
from htsohm.db import Material
from htsohm.htsohm_serial import calc_bins

def dof_analysis(config_path, output_directory, run_id=None):
    config = load_config_file(config_path)
    db.init_database(config["database_connection_string"])
    session = db.get_session()

    children_per_generation = config['children_per_generation']
    prop1range = config['prop1range']
    prop2range = config['prop2range']

    num_bins = config['number_of_convergence_bins']
    bin_counts = np.zeros((num_bins, num_bins))

    vf_binunits = (prop1range[1] - prop1range[0]) / num_bins
    ml_binunits = (prop2range[1] - prop2range[0]) / num_bins

    materials = session.query(Material)
    if run_id:
        materials = materials.filter(Material.run_id==run_id)

    perturbation_types = ["lattice", "lattice_nodens", "atom_types", "atom_sites", "density", "all"]

    tsv_output_path = os.path.join(output_directory, "data.tsv")
    tsvfile = open(tsv_output_path, 'w')
    tsv = csv.writer(tsvfile, delimiter="\t", lineterminator="\n")
    tsv.writerow([""] + list(chain.from_iterable([[t] * 5 for t in perturbation_types])))
    tsv.writerow(["gen"] + list(chain.from_iterable([["#", "∆vf", "∆ml", "dist", "new_bins"] for t in perturbation_types])))

    mats_d = materials.all()
    mats_r = [(m.void_fraction[0].void_fraction, m.gas_loading[0].absolute_volumetric_loading) for m in mats_d]

    new_mats_d = mats_d[0:children_per_generation]
    new_mats_r = mats_r[0:children_per_generation]
    new_bins = calc_bins(new_mats_r, num_bins, prop1range=prop1range, prop2range=prop2range)
    for i, (bx, by) in enumerate(new_bins):
        bin_counts[bx,by] += 1

    pts = {t:[] for t in perturbation_types}
    gen = 1
    new_mats_d = mats_d[gen*children_per_generation:(gen + 1)*children_per_generation]
    new_mats_r = mats_r[gen*children_per_generation:(gen + 1)*children_per_generation]
    animation = [[[b[0], b[1], -1, -1] for b in new_bins]]

    while len(new_mats_d) > 0:
        new_bins = calc_bins(new_mats_r, num_bins, prop1range=prop1range, prop2range=prop2range)

        gen_animation = []
{'fraction_non_alphanumeric': 0.12439877568867512, 'fraction_numerical': 0.014429383471797114, 'mean_word_length': 4.828025477707007, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '178737', 'n_tokens_mistral': 1757, 'n_tokens_neox': 1640, 'n_words': 312}