<commit_before>#!/usr/bin/env python
# XDSIntegrateHelpers.py
#   Copyright (C) 2006 CCLRC, <NAME>
#
#   This code is distributed under the BSD license, a copy of which is
#   included in the root directory of this package.
#
# Routines which help with working with XDS INTEGRATE - e.g. parsing the
# output INTEGRATE.LP.
#

import math
import os
import sys

if not os.environ.has_key('XIA2_ROOT'):
    raise RuntimeError, 'XIA2_ROOT not defined'

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

from Handlers.Streams import Chatter

def _parse_integrate_lp_updates(filename):
    '''Parse the integrate.lp file to get the values for any updated
    parameters.'''

    if not os.path.split(filename)[-1] == 'INTEGRATE.LP':
        raise RuntimeError, 'input filename not INTEGRATE.LP'

    file_contents = open(filename, 'r').readlines()

    updates = { }

    for i in range(len(file_contents)):
        if ' ***** SUGGESTED VALUES FOR INPUT PARAMETERS *****' in \
           file_contents[i]:
            beam_parms = file_contents[i + 1].replace('=', '').split()
            reflecting_parms = file_contents[i + 2].replace('=', '').split()
            updates[beam_parms[0]] = float(beam_parms[1])
            updates[beam_parms[2]] = float(beam_parms[3])
            updates[reflecting_parms[0]] = float(reflecting_parms[1])
            updates[reflecting_parms[2]] = float(reflecting_parms[3])

    return updates

def _parse_integrate_lp(filename):
    '''Parse the contents of the INTEGRATE.LP file pointed to by filename.'''

    if not os.path.split(filename)[-1] == 'INTEGRATE.LP':
        raise RuntimeError, 'input filename not INTEGRATE.LP'

    file_contents = open(filename, 'r').readlines()

    per_image_stats = { }

    block_start_finish = (0, 0)

    oscillation_range = 0.0

    block_images = []

    for i in range(len(file_contents)):

        # check for the header contents - this is basically a duplicate
        # of the input data....

        if 'OSCILLATION_RANGE=' in file_contents[i]:
            oscillation_range = float(file_contents[i].split()[1])

        if 'PROCESSING OF IMAGES' in file_contents[i]:
            lst = file_contents[i].split()
            block_start_finish = (int(lst[3]), int(lst[5]))

            block_images = [j for j in range(int(lst[3]), int(lst[5]) + 1)]

        # look for explicitly per-image information
        if 'IMAGE IER  SCALE' in file_contents[i]:
            j = i + 1
            while len(file_contents[j].strip()):
                lst = file_contents[j].split()
                image = int(lst[0])
                status = int(lst[1])
                scale = float(lst[2])
                overloads = int(lst[4])
                all = int(lst[5])
                strong = int(lst[6])
                rejected = int(lst[7])

                if status == 0:

                    # trap e.g. missing images - need to be able to
                    # record this somewhere...

                    fraction_weak = 1.0 - (float(strong) / float(all))

                    per_image_stats[image] = {'scale':scale,
                                              'overloads':overloads,
                                              'strong':strong,
                                              'all':all,<commit_msg>Cope with no reflections on an image<commit_after>#!/usr/bin/env python
# XDSIntegrateHelpers.py
#   Copyright (C) 2006 CCLRC, <NAME>
#
#   This code is distributed under the BSD license, a copy of which is
#   included in the root directory of this package.
#
# Routines which help with working with XDS INTEGRATE - e.g. parsing the
# output INTEGRATE.LP.
#

import math
import os
import sys

if not os.environ.has_key('XIA2_ROOT'):
    raise RuntimeError, 'XIA2_ROOT not defined'

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

from Handlers.Streams import Chatter

def _parse_integrate_lp_updates(filename):
    '''Parse the integrate.lp file to get the values for any updated
    parameters.'''

    if not os.path.split(filename)[-1] == 'INTEGRATE.LP':
        raise RuntimeError, 'input filename not INTEGRATE.LP'

    file_contents = open(filename, 'r').readlines()

    updates = { }

    for i in range(len(file_contents)):
        if ' ***** SUGGESTED VALUES FOR INPUT PARAMETERS *****' in \
           file_contents[i]:
            beam_parms = file_contents[i + 1].replace('=', '').split()
            reflecting_parms = file_contents[i + 2].replace('=', '').split()
            updates[beam_parms[0]] = float(beam_parms[1])
            updates[beam_parms[2]] = float(beam_parms[3])
            updates[reflecting_parms[0]] = float(reflecting_parms[1])
            updates[reflecting_parms[2]] = float(reflecting_parms[3])

    return updates

def _parse_integrate_lp(filename):
    '''Parse the contents of the INTEGRATE.LP file pointed to by filename.'''

    if not os.path.split(filename)[-1] == 'INTEGRATE.LP':
        raise RuntimeError, 'input filename not INTEGRATE.LP'

    file_contents = open(filename, 'r').readlines()

    per_image_stats = { }

    block_start_finish = (0, 0)

    oscillation_range = 0.0

    block_images = []

    for i in range(len(file_contents)):

        # check for the header contents - this is basically a duplicate
        # of the input data....

        if 'OSCILLATION_RANGE=' in file_contents[i]:
            oscillation_range = float(file_contents[i].split()[1])

        if 'PROCESSING OF IMAGES' in file_contents[i]:
            lst = file_contents[i].split()
            block_start_finish = (int(lst[3]), int(lst[5]))

            block_images = [j for j in range(int(lst[3]), int(lst[5]) + 1)]

        # look for explicitly per-image information
        if 'IMAGE IER  SCALE' in file_contents[i]:
            j = i + 1
            while len(file_contents[j].strip()):
                lst = file_contents[j].split()
                image = int(lst[0])
                status = int(lst[1])
                scale = float(lst[2])
                overloads = int(lst[4])
                all = int(lst[5])
                strong = int(lst[6])
                rejected = int(lst[7])

                if status == 0:

                    # trap e.g. missing images - need to be able to
                    # record this somewhere...

                    if all:
                        fraction_weak = 1.0 - (float(strong) / float(all))
                    else:
                        fraction_weak = 1.0

                    per_image_stats[image] = {'scale':scale,
                                              'overloads':overloads,
                                              'strong':strong,
                                              'all':all,
{'fraction_non_alphanumeric': 0.11842686699072029, 'fraction_numerical': 0.012372956252761821, 'mean_word_length': 2.06131650135257, 'pattern_counts': {'":': 0, '<': 5, '<?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': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4022288', 'n_tokens_mistral': 2105, 'n_tokens_neox': 2013, 'n_words': 522}