예제 #1
0
def test_regenerate_powder_map_data(_):
    # Read from existing file first to allow option of only replacing for
    # certain test cases or keys
    try:
        with open(powder_map_output_file, 'r') as json_file:
            json_data = json.load(json_file)
    except FileNotFoundError:
        json_data = {}

    for powder_map_param in powder_map_params:
        # Generate current figure for us to retrieve with gcf
        euphonic.cli.powder_map.main(powder_map_param)

        # Retrieve with gcf and write to file
        image_data = get_current_plot_image_data()
        # Optionally only write certain keys
        keys_to_replace = []
        if len(keys_to_replace) > 0:
            for key in keys_to_replace:
                json_data[args_to_key(powder_map_param)][key] = image_data[key]
        else:
            json_data[args_to_key(powder_map_param)] = image_data

    with open(powder_map_output_file, 'w+') as json_file:
        json.dump(json_data, json_file, indent=4)
예제 #2
0
def test_regenerate_disp_data(_):
    json_data = {}
    for disp_param in disp_params:
        # Generate current figure for us to retrieve with gcf
        euphonic.cli.dispersion.main(disp_param)
        # Retrieve with gcf and write to file
        json_data[args_to_key(disp_param)] = get_current_plot_line_data()
    with open(disp_output_file, 'w+') as json_file:
        json.dump(json_data, json_file, indent=4)
예제 #3
0
def test_regenerate_intensity_map_data(_):

    json_data = {}

    for intensity_map_param in intensity_map_params:
        # Generate current figure for us to retrieve with gcf
        euphonic.cli.intensity_map.main(intensity_map_param)

        # Retrieve with gcf and write to file
        json_data[args_to_key(
            intensity_map_param)] = get_current_plot_image_data()

    with open(intensity_map_output_file, 'w+') as json_file:
        json.dump(json_data, json_file, indent=4)
예제 #4
0
    def test_plots_produce_expected_image(self, inject_mocks, powder_map_args):
        euphonic.cli.powder_map.main(powder_map_args)

        image_data = get_current_plot_image_data()

        with open(powder_map_output_file, 'r') as expected_data_file:
            expected_image_data = json.load(expected_data_file)[args_to_key(
                powder_map_args)]
        for key, value in image_data.items():
            if key == 'extent':
                # Lower bound of y-data (energy) varies by up to ~2e-6 on
                # different systems when --asr is used, compared to
                # the upper bound of 100s of meV this is effectively zero,
                # so increase tolerance to allow for this
                npt.assert_allclose(value, expected_image_data[key], atol=2e-6)
            elif isinstance(value, list) and isinstance(value[0], float):
                # Errors of 2-4 epsilon seem to be common when using
                # broadening, so slightly increase tolerance
                npt.assert_allclose(value,
                                    expected_image_data[key],
                                    atol=1e-14)
            else:
                assert value == expected_image_data[key]
예제 #5
0
    def test_plots_contain_expected_data(self, inject_mocks, dispersion_args):
        euphonic.cli.dispersion.main(dispersion_args)

        line_data = get_current_plot_line_data()

        with open(disp_output_file, 'r') as f:
            expected_line_data = json.load(f)[args_to_key(dispersion_args)]
        # Increase tolerance if asr present - can give slightly
        # different results with different libs
        if any(['--asr' in arg for arg in dispersion_args]):
            atol = 1.5e-6
        else:
            atol = sys.float_info.epsilon
        for key, value in line_data.items():
            if key == 'xy_data':
                # numpy can only auto convert 2D lists - xy_data has
                # dimensions (n_lines, 2, n_points) so check in a loop
                for idx, line in enumerate(value):
                    npt.assert_allclose(line,
                                        expected_line_data[key][idx],
                                        atol=atol)
            else:
                assert value == expected_line_data[key]