<commit_before>#!/usr/bin/env python
#
# dials.integrate.py
#
#  Copyright (C) 2013 Diamond Light Source
#
#  Author: <NAME>
#
#  This code is distributed under the BSD license, a copy of which is
#  included in the root directory of this package.
from __future__ import division
from dials.util.script import ScriptRunner


class Script(ScriptRunner):
    '''A class for running the script.'''

    def __init__(self):
        '''Initialise the script.'''

        # The script usage
        usage = "usage: %prog [options] [param.phil] sweep.json crystal.json"

        # Initialise the base class
        ScriptRunner.__init__(self, usage=usage)

        # Output filename option
        self.config().add_option(
            '-o', '--output-filename',
            dest = 'output_filename',
            type = 'string', default = 'integrated.pickle',
            help = 'Set the filename for integrated reflections.')

        # Option to save profiles with reflection data
        self.config().add_option(
            '-p', '--save-profiles',
            dest = 'save_profiles',
            action = 'store_true', default = False,
            help = 'Output profiles with reflection data.')

    def main(self, params, options, args):
        '''Execute the script.'''
        from dials.algorithms.integration import IntegratorFactory
        from dials.model.serialize import load
        import cPickle as pickle

        # Check the number of arguments is correct
        if len(args) != 2:
            self.config().print_help()
            return

        # Get the integrator from the input parameters
        print 'Configurating integrator from input parameters'
        integrate = IntegratorFactory.from_parameters(params)

        # Try to load the models
        print 'Loading models from {0} and {1}'.format(args[0], args[1])
        sweep = load.sweep(args[0])
        crystal = load.crystal(args[1])

        # Intregate the sweep's reflections
        print 'Integrating reflections'
        reflections = integrate(sweep, crystal)

        # Save the reflections to file
        print 'Saving reflections to {0}'.format(options.output_filename)
        if options.save_profiles == False:
            from scitbx.array_family import flex
            for r in reflections:
                r.shoebox = flex.double()
                r.shoebox_mask = flex.int()
                r.shoebox_background = flex.double()
                r.transformed_shoebox = flex.double()
        pickle.dump(reflections, open(options.output_filename, 'wb'),
            pickle.HIGHEST_PROTOCOL)


if __name__ == '__main__':
    script = Script()
    script.run()<commit_msg>Using shoebox.deallocate to optionally get rid of profiles before saving to file.<commit_after>#!/usr/bin/env python
#
# dials.integrate.py
#
#  Copyright (C) 2013 Diamond Light Source
#
#  Author: <NAME>
#
#  This code is distributed under the BSD license, a copy of which is
#  included in the root directory of this package.
from __future__ import division
from dials.util.script import ScriptRunner


class Script(ScriptRunner):
    '''A class for running the script.'''

    def __init__(self):
        '''Initialise the script.'''

        # The script usage
        usage = "usage: %prog [options] [param.phil] sweep.json crystal.json"

        # Initialise the base class
        ScriptRunner.__init__(self, usage=usage)

        # Output filename option
        self.config().add_option(
            '-o', '--output-filename',
            dest = 'output_filename',
            type = 'string', default = 'integrated.pickle',
            help = 'Set the filename for integrated reflections.')

        # Option to save profiles with reflection data
        self.config().add_option(
            '-p', '--save-profiles',
            dest = 'save_profiles',
            action = 'store_true', default = False,
            help = 'Output profiles with reflection data.')

    def main(self, params, options, args):
        '''Execute the script.'''
        from dials.algorithms.integration import IntegratorFactory
        from dials.algorithms import shoebox
        from dials.model.serialize import load
        import cPickle as pickle

        # Check the number of arguments is correct
        if len(args) != 2:
            self.config().print_help()
            return

        # Get the integrator from the input parameters
        print 'Configurating integrator from input parameters'
        integrate = IntegratorFactory.from_parameters(params)

        # Try to load the models
        print 'Loading models from {0} and {1}'.format(args[0], args[1])
        sweep = load.sweep(args[0])
        crystal = load.crystal(args[1])

        # Intregate the sweep's reflections
        print 'Integrating reflections'
        reflections = integrate(sweep, crystal)

        # Save the reflections to file
        print 'Saving reflections to {0}'.format(options.output_filename)
        if options.save_profiles == False:
            shoebox.deallocate(reflections)
        pickle.dump(reflections, open(options.output_filename, 'wb'),
            pickle.HIGHEST_PROTOCOL)


if __name__ == '__main__':
    script = Script()
    script.run()
{'fraction_non_alphanumeric': 0.09676802447886786, 'fraction_numerical': 0.004589787722317842, 'mean_word_length': 2.396103896103896, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1747953', 'n_tokens_mistral': 1457, 'n_tokens_neox': 1388, 'n_words': 445}