Ejemplo n.º 1
0
def main(args=None):

    # Setup the object.
    analyzer = DiffractionAnalysis(
        input_path=args.input_path,
        pattern_indices=eval(args.pattern_indices),
        poissonize=eval(args.poissonize),
    )

    # Plot if requested.
    if args.plot:
        analyzer.plotPattern(
            logscale=args.logscale,
            operation=eval(args.operation),
        )
    # Plot if requested.
    if args.radial:
        analyzer.plotRadialProjection(
            logscale=args.logscale,
            operation=eval(args.operation),
        )

    if args.statistics:
        analyzer.statistics()

    plt.show()

    # Animate if requested.
    if args.animation_filename:
        analyzer.animatePatterns(output_path=args.animation_filename)

        print "Animated gif saved to %s." % (
            analyzer._DiffractionAnalysis__animation_output_path)
Ejemplo n.º 2
0
    def testAnimatePatterns(self):
        """ Test the animation feature. """

        # Setup the analyser with a sequence of patterns.
        analyzer = DiffractionAnalysis(
            input_path=self.__test_data,
            pattern_indices=list(range(1, 11)),
        )

        # Check exceptions on faulty path.
        self.assertRaises(TypeError,
                          analyzer.animatePatterns,
                          output_path=["not", "a", "path"])
        self.assertRaises(IOError,
                          analyzer.animatePatterns,
                          output_path="/users/home/myself/animation.gif")

        # Check default behaviour.
        analyzer.animatePatterns(output_path=None)

        # Check output is present.
        animation_out_path = 'animated_patterns.gif'
        self.__files_to_remove.append(animation_out_path)
        self.assertIn(animation_out_path, os.listdir(os.getcwd()))

        # Check path is stored on object.
        self.assertEqual(analyzer._DiffractionAnalysis__animation_output_path,
                         os.path.join(os.getcwd(), animation_out_path))

        # Check exception on overwrite.
        self.assertRaises(IOError,
                          analyzer.animatePatterns,
                          output_path=animation_out_path)

        # Execute with parameter.
        animation_out_path = 'animation2.gif'
        self.__files_to_remove.append(animation_out_path)

        analyzer.animatePatterns(output_path=animation_out_path)

        # Check path is stored on object.
        self.assertEqual(analyzer._DiffractionAnalysis__animation_output_path,
                         os.path.join(os.getcwd(), animation_out_path))

        # Check file is present.
        self.assertIn(animation_out_path, os.listdir(os.getcwd()))