<commit_before>#!/usr/bin/env python
from __future__ import print_function, division

import argparse

parser = argparse.ArgumentParser()
parser.add_argument('file', type=str, help='H5MD datafile')
parser.add_argument('--obs', type=str,
                    help='Observables to plot, e.g. \'temperature\'',
                    nargs='+')
parser.add_argument('--traj', type=str)
parser.add_argument('--field', type=str)
parser.add_argument('--com', action='store_true')
parser.add_argument('--hist', action='store_true')
parser.add_argument('--mean', action='store_true')
parser.add_argument('--index', type=int)
args = parser.parse_args()

import numpy as np
import h5py
import matplotlib.pyplot as plt

with h5py.File(args.file, 'r') as f:
    if args.obs:
        for obs in args.obs:
            g = f['observables'][obs]
            if 'time' in g:
                time = g['time']
            else:
                time = g['step']
            if len(time.shape) == 1:
                plt.plot(time, g['value'])
            else:
                plt.plot(np.arange(g['value'].shape[0])*time, g['value'])
    elif args.traj:
        group, traj = args.traj.split('/')
        edges = f['particles'][group]['box/edges'][:]
        if args.com:
            if traj == 'position':
                pos = f['particles'][group][traj]['value']
                im = f['particles'][group]['image']['value']
                data = pos[:,:,:] + im[:,:,:]*edges.reshape((1, 1, 3))
            else:
                data = f['particles'][group][traj]['value'][:,:,:]
            data = data.mean(axis=1)
        else:
            data = f['particles'][group][traj]['value'][:,0,:]
        for i in range(3):
            plt.subplot(3, 1, i+1)
            if args.hist:
                plt.hist(data[:,i], bins=32)
                print('xyz'[i], 'mean', data[:,i].mean(),
                      'std', data[:,i].std())
            else:
                plt.plot(data[:,i])
                plt.ylabel('xyz'[i])

    elif args.field:
        g = f['fields'][args.field]
        value = g['value']
        if len(value.shape)==3:
            value = value[:,:,args.index]
        if args.mean:
            plt.plot(value.mean(axis=0))
        else:
            N = value.shape[0]
            plt.plot(value[::N//4].T)<commit_msg>fix: transform dataset into array<commit_after>#!/usr/bin/env python
from __future__ import print_function, division

import argparse

parser = argparse.ArgumentParser()
parser.add_argument('file', type=str, help='H5MD datafile')
parser.add_argument('--obs', type=str,
                    help='Observables to plot, e.g. \'temperature\'',
                    nargs='+')
parser.add_argument('--traj', type=str)
parser.add_argument('--field', type=str)
parser.add_argument('--com', action='store_true')
parser.add_argument('--hist', action='store_true')
parser.add_argument('--mean', action='store_true')
parser.add_argument('--index', type=int)
args = parser.parse_args()

import numpy as np
import h5py
import matplotlib.pyplot as plt

with h5py.File(args.file, 'r') as f:
    if args.obs:
        for obs in args.obs:
            g = f['observables'][obs]
            if 'time' in g:
                time = g['time']
            else:
                time = g['step']
            if len(time.shape) == 1:
                plt.plot(time, g['value'])
            else:
                plt.plot(np.arange(g['value'].shape[0])*time, g['value'])
    elif args.traj:
        group, traj = args.traj.split('/')
        edges = f['particles'][group]['box/edges'][:]
        if args.com:
            if traj == 'position':
                pos = f['particles'][group][traj]['value']
                im = f['particles'][group]['image']['value']
                data = pos[:,:,:] + im[:,:,:]*edges.reshape((1, 1, 3))
            else:
                data = f['particles'][group][traj]['value'][:,:,:]
            data = data.mean(axis=1)
        else:
            data = f['particles'][group][traj]['value'][:,0,:]
        for i in range(3):
            plt.subplot(3, 1, i+1)
            if args.hist:
                plt.hist(data[:,i], bins=32)
                print('xyz'[i], 'mean', data[:,i].mean(),
                      'std', data[:,i].std())
            else:
                plt.plot(data[:,i])
                plt.ylabel('xyz'[i])

    elif args.field:
        g = f['fields'][args.field]
        value = g['value']
        if len(value.shape)==3:
            value = value[:,:,args.index]
        else:
            value = value[:]
        if args.mean:
            plt.plot(value.mean(axis=0))
        else:
            N = value.shape[0]
            plt.plot(value[::N//4].T)
{'fraction_non_alphanumeric': 0.18359957401490948, 'fraction_numerical': 0.008519701810436636, 'mean_word_length': 1.9553178099433606, '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': '3669350', 'n_tokens_mistral': 1529, 'n_tokens_neox': 1501, 'n_words': 290}