<commit_before>from __future__ import absolute_import

import six
import numpy as np
from collections import OrderedDict
# from scipy.interpolate import interp1d, interp2d
import copy
import re

import math
import matplotlib
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
import matplotlib.ticker as mticker
from mpl_toolkits.axes_grid1 import ImageGrid
from atom.api import Atom, Str, observe, Typed, Int, List, Dict, Bool, Float

from ..core.utils import normalize_data_by_scaler, grid_interpolate

from ..core.quant_analysis import ParamQuantitativeAnalysis

import logging
logger = logging.getLogger()


class DrawImageAdvanced(Atom):
    """
    This class performs 2D image rendering, such as showing multiple
    2D fitting or roi images based on user's selection.

    Attributes
    ----------
    img_data : dict
        dict of 2D array
    fig : object
        matplotlib Figure
    file_name : str
    stat_dict : dict
        determine which image to show
    data_dict : dict
        multiple data sets to plot, such as fit data, or roi data
    data_dict_keys : list
    data_opt : int
        index to show which data is chosen to plot
    dict_to_plot : dict
        selected data dict to plot, i.e., fitting data or roi is selected
    items_in_selected_group : list
        keys of dict_to_plot
    scale_opt : str
        linear or log plot
    color_opt : str
        orange or gray plot
    scaler_norm_dict : dict
        scaler normalization data, from data_dict
    scaler_items : list
        keys of scaler_norm_dict
    scaler_name_index : int
        index to select on GUI level
    scaler_data : None or numpy
        selected scaler data
    x_pos : list
        define data range in horizontal direction
    y_pos : list
        define data range in vertical direction
    pixel_or_pos : int
        index to choose plot with pixel (== 0) or with positions (== 1)
    grid_interpolate: bool
        choose to interpolate 2D image in terms of x,y or not
    limit_dict : Dict
        save low and high limit for image scaling
    """

    fig = Typed(Figure)
    stat_dict = Dict()
    data_dict = Dict()
    data_dict_keys = List()
    data_opt = Int(0)
    dict_to_plot = Dict()
    items_in_selected_group = List()
    items_previous_selected = List()

    scale_opt = Str('Linear')
    color_opt = Str('viridis')
    img_title = Str()

    scaler_norm_dict = Dict()
    scaler_items = List()
    scaler_name_index = Int()
    scaler_data = Typed(object)

    x_pos = List()
    y_pos = List()

    pixel_or_pos = Int(0)
    grid_interpolate = Bool(False)
    data_dict_default = Dict()
    limit_dict = Dict()
    range_dict = Dict()
    scatter_show = Bool(False)
    name_not_scalable = List()

    # The value is synchronized with currently selected value of incident energy
    #   Should not be changed directly
    incident_energy = Float(12.0)

    # Variable that indicates whether quanitative normalization should be applied to data
    #   Associated with 'Quantitative' checkbox
    quantitative_normalization = Bool(False)

    # The following fields are used for storing parameters used for quantitative analysis
    param_quant_analysis = Typed(object)
    # Distance to sample for the scan that is currently processed, synchronized with the contents
    #   of the field in 'Quantitative Analysis' tab, may be used for computations
    #   Enaml 'FloatField' requires this variable to be a string, but the string will always
    #   represent valid 'float' number
    quant_distance_to_sample = Float(0.0)
    # The following fields are used to facilitate GUI operation, not for long-term data storage
    #   Don't use those fields for any computations outside the GUI controls
    quant_calibration_data = List()
    quant_calibration_settings = List()
    quant_active_emission_lines = List()
    quant_calibration_data_preview = Str()

    def __init__(self):
        self.fig = plt.figure(figsize=(3, 2))
        matplotlib.rcParams['axes.formatter.useoffset'] = True

        # Do not apply scaler norm on following data
        self.name_not_scalable = ['r2_adjust', 'alive', 'dead', 'elapsed_time', 'scaler_alive',
                                  'i0_time', 'time', 'time_diff', 'dwell_time']

        self.param_quant_analysis = ParamQuantitativeAnalysis()
        self.param_quant_analysis.set_experiment_distance_to_sample(distance_to_sample=0.0)
        self.param_quant_analysis.set_experiment_incident_energy(incident_energy=self.incident_energy)

    def data_dict_update(self, change):
        """
        Observer function to be connected to the fileio model<commit_msg>ENH: integration of processing of 'lazy' arrays<commit_after>from __future__ import absolute_import

import six
import numpy as np
from collections import OrderedDict
# from scipy.interpolate import interp1d, interp2d
import copy
import re

import math
import matplotlib
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
import matplotlib.ticker as mticker
from mpl_toolkits.axes_grid1 import ImageGrid
from atom.api import Atom, Str, observe, Typed, Int, List, Dict, Bool, Float

from ..core.utils import normalize_data_by_scaler, grid_interpolate

from ..core.quant_analysis import ParamQuantitativeAnalysis

import logging
logger = logging.getLogger()


class DrawImageAdvanced(Atom):
    """
    This class performs 2D image rendering, such as showing multiple
    2D fitting or roi images based on user's selection.

    Attributes
    ----------
    img_data : dict
        dict of 2D array
    fig : object
        matplotlib Figure
    file_name : str
    stat_dict : dict
        determine which image to show
    data_dict : dict
        multiple data sets to plot, such as fit data, or roi data
    data_dict_keys : list
    data_opt : int
        index to show which data is chosen to plot
    dict_to_plot : dict
        selected data dict to plot, i.e., fitting data or roi is selected
    items_in_selected_group : list
        keys of dict_to_plot
    scale_opt : str
        linear or log plot
    color_opt : str
        orange or gray plot
    scaler_norm_dict : dict
        scaler normalization data, from data_dict
    scaler_items : list
        keys of scaler_norm_dict
    scaler_name_index : int
        index to select on GUI level
    scaler_data : None or numpy
        selected scaler data
    x_pos : list
        define data range in horizontal direction
    y_pos : list
        define data range in vertical direction
    pixel_or_pos : int
        index to choose plot with pixel (== 0) or with positions (== 1)
    grid_interpolate: bool
        choose to interpolate 2D image in terms of x,y or not
    limit_dict : Dict
        save low and high limit for image scaling
    """

    fig = Typed(Figure)
    stat_dict = Dict()
    data_dict = Dict()
    data_dict_keys = List()
    data_opt = Int(0)
    dict_to_plot = Dict()
    items_in_selected_group = List()
    items_previous_selected = List()

    scale_opt = Str('Linear')
    color_opt = Str('viridis')
    img_title = Str()

    scaler_norm_dict = Dict()
    scaler_items = List()
    scaler_name_index = Int()
    scaler_data = Typed(object)

    x_pos = List()
    y_pos = List()

    pixel_or_pos = Int(0)
    grid_interpolate = Bool(False)
    data_dict_default = Dict()
    limit_dict = Dict()
    range_dict = Dict()
    scatter_show = Bool(False)
    name_not_scalable = List()

    # The value is synchronized with currently selected value of incident energy
    #   Should not be changed directly
    incident_energy = Float(12.0)

    # Variable that indicates whether quanitative normalization should be applied to data
    #   Associated with 'Quantitative' checkbox
    quantitative_normalization = Bool(False)

    # The following fields are used for storing parameters used for quantitative analysis
    param_quant_analysis = Typed(object)
    # Distance to sample for the scan that is currently processed, synchronized with the contents
    #   of the field in 'Quantitative Analysis' tab, may be used for computations
    #   Enaml 'FloatField' requires this variable to be a string, but the string will always
    #   represent valid 'float' number
    quant_distance_to_sample = Float(0.0)
    # The following fields are used to facilitate GUI operation, not for long-term data storage
    #   Don't use those fields for any computations outside the GUI controls
    quant_calibration_data = List()
    quant_calibration_settings = List()
    quant_active_emission_lines = List()
    quant_calibration_data_preview = Str()

    def __init__(self):
        self.fig = plt.figure(figsize=(3, 2))
        matplotlib.rcParams['axes.formatter.useoffset'] = True

        # Do not apply scaler norm on following data
        self.name_not_scalable = ['r2_adjust', 'r_factor', 'alive', 'dead', 'elapsed_time',
                                  'scaler_alive', 'i0_time', 'time', 'time_diff', 'dwell_time']

        self.param_quant_analysis = ParamQuantitativeAnalysis()
        self.param_quant_analysis.set_experiment_distance_to_sample(distance_to_sample=0.0)
        self.param_quant_analysis.set_experiment_incident_energy(incident_energy=self.incident_energy)

    def data_dict_update(self, change):
        """
        Observer function to be connected to the fileio model
{'fraction_non_alphanumeric': 0.06202370872142252, 'fraction_numerical': 0.0046570702794242165, 'mean_word_length': 3.0940207972270364, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3918019', 'n_tokens_mistral': 2773, 'n_tokens_neox': 2690, 'n_words': 940}