Exemple #1
0
def get_spectrum_experiment(material: con.Material,
                            temperatures: tuple,
                            data: tuple,
                            parameters: dict,
                            scale=None):
    """Returns inelastic neutron scattering spectrum from experiment"""
    data_kwargs = {
        'x': data[0]['x'],
        'y_set': OrderedDict(),
        'errors': OrderedDict(),
        'legend': OrderedDict(),
    }
    for i, temperature in enumerate(temperatures):
        data_kwargs['y_set'][temperature] = data[i]['y']
        data_kwargs['errors'][temperature] = data[i]['errors']
        data_kwargs['legend'][temperature] = f'{temperature} K'
    with CubicPlot(data=con.Data(**data_kwargs), material=material) as plot:
        plot.set_labels(**con.SPECTRUM_LABELS)
        plot.set_limits(**scale.limits)
        plot.set_locators(**scale.locators)
        plot.make_plot(mode='errorbar')
        plot.save_in_two_forms(filename=plot.get_graph_file_name(
            data_name='spectra',
            parameters=parameters,
        ))
Exemple #2
0
def get_llw_ratios_plot(material: con.Material,
                        experimental_value,
                        limits: dict,
                        ticks: dict,
                        choice=0):
    """Returns graphs for dependence of transition energies or intensities
     ratios on CEF parameters"""
    data_name = 'ratios_energies' if choice == 0 else 'ratios_intensities'
    for w_parameter in (1, -1):
        data = {
            'x': [],
            'y_set': OrderedDict({'Experiment': []}),
            'legend': OrderedDict({'Experiment': 'Experiment'})
        }
        for name in ut.get_ratios_names(choice):
            data['y_set'][name] = []
            data['legend'][name] = name
        parameters = {'w': w_parameter}
        ratio_file_name = get_paths(
            data_name=data_name,
            material=material,
            parameters=parameters,
        )
        with ut.OpenedFile(ratio_file_name) as file:
            for line in file:
                array = line.rstrip('\n').split('\t')
                array = [float(value.strip()) for value in array]
                data['x'].append(array[0])
                data['y_set']['Experiment'].append(experimental_value)
                for level, name in enumerate(ut.get_ratios_names(choice)):
                    if array[level + 1] == 0:
                        data['y_set'][name].append(con.INFINITY)
                    else:
                        data['y_set'][name].append(array[level + 1])
        ut.data_popping(
            data, lambda arg: (len(arg) == 0 or min(arg) > experimental_value
                               or max(arg) < experimental_value))
        parameters['exp'] = experimental_value
        data = con.Data(
            x=data['x'],
            y_set=data['y_set'],
            legend=data['legend'],
            errors=None,
        )
        with CubicPlot(data=data, material=material) as plot:
            plot.set_labels(
                xlabel=r'$x$',
                ylabel=(con.ENERGY_TRANSFER_RATIO
                        if choice == 0 else con.TRANSITION_INTENSITY_RATIO),
                title=fr'{material.rare_earth}, $W={parameters["w"]}$ мэВ',
            )
            plot.set_limits(**limits)
            plot.set_locators(**ticks)
            plot.make_plot(mode='scatter')
            plot.save_in_two_forms(filename=plot.get_graph_file_name(
                data_name=data_name,
                parameters=parameters,
            ))
Exemple #3
0
def get_intensity_on_temperature(
    material: con.Material,
    crosses: con.CrossPoint,
    y_max: float,
):
    """
    Returns graphs for dependence of transition intensities on temperature.

    """
    data_kwargs = {
        'x': [],
        'y_set': OrderedDict(),
        'errors': OrderedDict(),
        'legend': OrderedDict(),
    }
    data_name = 'intensities_on_temperature'
    for cross_number, cross in enumerate(crosses):
        llw = {'w': cross.w, 'x': cross.x}
        label = f'$W = {cross.w:.3f}, x = {cross.x:.3f}$'
        data_kwargs['y_set'][label] = []
        data_kwargs['errors'][label] = None
        data_kwargs['legend'][label] = label
        cubic_object = Cubic(
            material=material,
            llw_parameters=llw,
        )
        cubic_object.save_intensities()
        file_name = get_paths(
            data_name=data_name,
            material=material,
            parameters=llw,
        )
        with ut.OpenedFile(file_name) as file:
            for line in file:
                row = line.rstrip('\n').split('\t')
                row = [float(value) for value in row]
                if cross_number == 0:
                    data_kwargs['x'].append(row[0])
                data_kwargs['y_set'][label].append(row[1] / row[2])
    with CubicPlot(data=con.Data(**data_kwargs), material=material) as plot:
        plot.set_labels(
            xlabel='Temperature, K',
            ylabel=con.TRANSITION_INTENSITY_RATIO,
        )
        plot.set_limits(
            y_min=0,
            y_max=y_max,
        )
        plot.set_locators()
        plot.make_plot(mode='scatter')
        plot.save_in_two_forms(
            filename=plot.get_graph_file_name(data_name=data_name, ))
Exemple #4
0
def get_llw_plot(material: con.Material, y_max, y_major, y_minor, choice=0):
    """Returns graphs for dependence of transition energies
    or intensities on CEF parameters"""
    data_name = 'energies' if choice == 0 else 'intensities'
    for w_parameter in (1, -1):
        data = {'x': [], 'y_set': OrderedDict(), 'legend': OrderedDict()}
        for level in range(1, 7):
            data['y_set'][ut.get_label(level, choice)] = []
            data['legend'][ut.get_label(level,
                                        choice)] = ut.get_label(level, choice)

        parameters = {'w': w_parameter}
        peak_file_name = get_paths(
            data_name=data_name,
            material=material,
            parameters=parameters,
        )
        with ut.OpenedFile(peak_file_name) as file:
            for line in file:
                array = line.rstrip('\n').split('\t')
                array = [float(value.strip()) for value in array]
                data['x'].append(array[0])
                for level in range(1, 7):
                    try:
                        data['y_set'][ut.get_label(
                            level, choice)].append(con.INFINITY if (
                                (choice != 0) and (level == 1)
                            ) else array[level])
                    except IndexError:
                        data['y_set'][ut.get_label(level, choice)].append(
                            con.INFINITY)
        ut.data_popping(data, lambda arg: len(arg) == 0)
        data = con.Data(
            x=data['x'],
            y_set=data['y_set'],
            legend=data['legend'],
            errors=None,
        )
        with CubicPlot(data=data, material=material) as plot:
            plot.set_labels(
                xlabel=r'$x$',
                ylabel=(con.ENERGY_TRANSFER
                        if choice == 0 else con.TRANSITION_INTENSITY),
                title=fr'{material.rare_earth}, $W={parameters["w"]}$ мэВ',
            )
            if y_max:
                plot.set_limits(
                    x_min=-1,
                    x_max=1,
                    y_min=-10 if choice == 0 else 0,
                    y_max=y_max,
                )
            if y_major and y_minor:
                plot.set_locators(
                    x_major=0.5,
                    x_minor=0.1,
                    y_major=y_major,
                    y_minor=y_minor,
                )
            plot.make_plot(mode='scatter')
            plot.save_in_two_forms(filename=plot.get_graph_file_name(
                data_name=data_name,
                parameters=parameters,
            ))
Exemple #5
0
 X_ARRAY = list(range(11))
 Y_ARRAY = {
     '4': [x**4 for x in X_ARRAY],
     '3': [x**3 for x in X_ARRAY],
     '2': [x**2 for x in X_ARRAY],
     '1': [x**1 for x in X_ARRAY],
 }
 LEGEND = {
     '4': '$x^4$',
     '3': '$x^3$',
     '2': '$x^2$',
     '1': '$x^1$',
 }
 DATA = con.Data(
     x=X_ARRAY,
     y_set=Y_ARRAY,
     legend=LEGEND,
     errors=None,
 )
 with CustomPlot(data=DATA, dpi=100) as custom_plot:
     custom_plot.set_limits(
         x_min=2,
         x_max=8,
         y_min=0,
         y_max=5000,
     )
     custom_plot.set_labels(
         xlabel='x_test',
         ylabel='y_test',
         title='test',
     )
     custom_plot.set_locators()