<commit_before>#!/usr/bin/env python
# TestRegistry.py
#   Copyright (C) 2011 <NAME>, <NAME>
#
#   This code is distributed under the BSD license, a copy of which is
#   included in the root directory of this package.
#
# Code to give the registry a bit of a workout.

import os
import sys

assert('XIA2_ROOT' in os.environ)

if not os.environ['XIA2_ROOT'] in sys.path:
    sys.path.append(os.environ['XIA2_ROOT'])

from dxtbx.format.Registry import Registry

import time

def TestRegistry(files):
    '''Print the class which claims to work with each file.'''

    s = time.time()

    for f in files:

        print f

        format = Registry.find(f)

        print format.__name__

        if format.understand(f) >= 2:
            i = format(f)
            print i.get_beam()
            print i.get_goniometer()
            print i.get_detector()

    return time.time() - s

def TestRegistry2(files):
    '''First find the class, then read every frame with it.'''

    s = time.time()

    format = Registry.find(files[0])

    b0 = format(files[0]).get_beam()
    g0 = format(files[0]).get_goniometer()
    d0 = format(files[0]).get_detector()

    for f in files:

        print f

        i = format(f)
        print i.get_beam()
        print i.get_goniometer()
        print i.get_detector()
        print i.get_scan()

        print i.get_beam() == b0, i.get_goniometer() == g0, \
              i.get_detector() == d0

    return time.time() - s

def TestRegistry3(files):
    '''First find the class, then read every frame with it, then add the scans
    together to make sure that they all make sense.'''

    s = time.time()

    format = Registry.find(files[0])

    scan = format(files[0]).get_scan()

    for f in files[1:]:

        i = format(f)

        scan += i.get_scan()

    print scan
    print scan[:len(scan) // 2]
    print scan[:]
    print scan[:len(scan)]
    print scan[1 + len(scan) // 2:]

    return time.time() - s

if __name__ == '__main__':

    # t = TestRegistry(sys.argv[1:])
    t = TestRegistry2(sys.argv[1:])
    # t = TestRegistry3(sys.argv[1:])

    print t
<commit_msg>In discussion with NKS, reducinhg dependencies on XIA2_ROOT<commit_after>#!/usr/bin/env python
# TestRegistry.py
#   Copyright (C) 2011 <NAME>, <NAME>
#
#   This code is distributed under the BSD license, a copy of which is
#   included in the root directory of this package.
#
# Code to give the registry a bit of a workout.

import os
import sys

if 'XIA2_ROOT' in os.environ and not os.environ['XIA2_ROOT'] in sys.path:
    sys.path.append(os.environ['XIA2_ROOT'])

from dxtbx.format.Registry import Registry

import time

def TestRegistry(files):
    '''Print the class which claims to work with each file.'''

    s = time.time()

    for f in files:

        print f

        format = Registry.find(f)

        print format.__name__

        if format.understand(f) >= 2:
            i = format(f)
            print i.get_beam()
            print i.get_goniometer()
            print i.get_detector()

    return time.time() - s

def TestRegistry2(files):
    '''First find the class, then read every frame with it.'''

    s = time.time()

    format = Registry.find(files[0])

    b0 = format(files[0]).get_beam()
    g0 = format(files[0]).get_goniometer()
    d0 = format(files[0]).get_detector()

    for f in files:

        print f

        i = format(f)
        print i.get_beam()
        print i.get_goniometer()
        print i.get_detector()
        print i.get_scan()

        print i.get_beam() == b0, i.get_goniometer() == g0, \
              i.get_detector() == d0

    return time.time() - s

def TestRegistry3(files):
    '''First find the class, then read every frame with it, then add the scans
    together to make sure that they all make sense.'''

    s = time.time()

    format = Registry.find(files[0])

    scan = format(files[0]).get_scan()

    for f in files[1:]:

        i = format(f)

        scan += i.get_scan()

    print scan
    print scan[:len(scan) // 2]
    print scan[:]
    print scan[:len(scan)]
    print scan[1 + len(scan) // 2:]

    return time.time() - s

if __name__ == '__main__':

    # t = TestRegistry(sys.argv[1:])
    t = TestRegistry2(sys.argv[1:])
    # t = TestRegistry3(sys.argv[1:])

    print t

{'fraction_non_alphanumeric': 0.12637234291053492, 'fraction_numerical': 0.014716187806587245, 'mean_word_length': 2.409235668789809, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '2744315', 'n_tokens_mistral': 1490, 'n_tokens_neox': 1404, 'n_words': 428}