<commit_before>#!/usr/bin/env python

#=========================================================================
# LOG HEADER:
#
# Dialogs boxes for thellier_gui.py
#
#=========================================================================
#
#  11/16/2014 add some units to criteria dialogs
#
# 11/08/2014 Version add k_prime description
#
# 08/08/2014 Version add k_prime description
#
# 3/22/2014 Version 1.0 by <NAME>
#
#
#=========================================================================

#--------------------------------------------------------------
# Thellier GUI dialog
#--------------------------------------------------------------

import matplotlib
# matplotlib.use('WXAgg')
import wx
import wx.lib.scrolledpanel
import copy
import os
import scipy
from scipy import arange
# only this one is nessesary.
import wx
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigCanvas
import pmagpy.pmag as pmag
from dialogs import pmag_widgets as pw
#--------------------------------------------------------------
# paleointensity statistics list (SPD.v.1.0)
#--------------------------------------------------------------


class PI_Statistics_Dialog(wx.Dialog):

    def __init__(self, parent, show_statistics_on_gui, title):
        style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER
        super(PI_Statistics_Dialog, self).__init__(
            parent, title=title, style=style)
        self.show_statistics_on_gui = copy.copy(show_statistics_on_gui)

        # dicts to contain small window elements
        self.bSizers = {}
        self.hboxes = {}
        self.set_specimen_windows = {}
        self.specimen_btns = {}

        self.stat_by_category = {}

        self.stat_by_category['Arai plot'] = ['specimen_int_n',
                                              'specimen_frac', 'specimen_f', 'specimen_fvds',
                                              'specimen_b_sigma', 'specimen_b_beta', 'specimen_scat',
                                              'specimen_g', 'specimen_gmax',
                                              'specimen_k', 'specimen_k_sse',
                                              'specimen_k_prime', 'specimen_k_prime_sse',
                                              'specimen_z', 'specimen_z_md',
                                              'specimen_q',
                                              'specimen_r_sq', 'specimen_coeff_det_sq',
                                              ]
        self.stat_by_category['Direction'] = ['specimen_int_mad', 'specimen_int_mad_anc', 'specimen_int_dang',
                                              'specimen_int_alpha', 'specimen_alpha_prime', 'specimen_theta', 'specimen_int_crm', 'specimen_gamma']
        self.stat_by_category['pTRM Checks'] = ['specimen_int_ptrm_n', 'specimen_ptrm', 'specimen_drat', 'specimen_drats', 'specimen_cdrat', 'specimen_mdrat',
                                                'specimen_dck', 'specimen_maxdev', 'specimen_mdev', 'specimen_dpal']
        self.stat_by_category['Tail Checks'] = ['specimen_int_ptrm_tail_n',
                                                'specimen_md', 'specimen_tail_drat', 'specimen_dtr', 'specimen_dt']
        self.stat_by_category['Additivity Checks'] = [
            'specimen_ac_n', 'specimen_dac']
        self.DESC = {}
        self.DESC['specimen_frac'] = 'The angle between the applied field direction and the ChRM direction of the NRM as determined from the free-floating PCA fit to the selected demagnetization steps of the paleointensity experiment'
        self.DESC['specimen_int_n'] = 'Number of measurements included in field strength calculations'
        self.DESC['specimen_alpha_prime'] = 'Angular difference between the anchored best-fit direction from the paleointensity experiment and an independent measure of the paleomagnetic direction'
        self.DESC['specimen_alpha'] = 'Angular difference between the anchored and free-floating best-fit directions on a vector component diagram'
        self.DESC['specimen_int_alpha'] = 'Angular difference between the anchored and free-floating best-fit directions on a vector component diagram from a paleointensity experiment'
        self.DESC['specimen_mad'] = 'Maximum Angular Deviation (MAD) of the free-floating directional PCA fits to the paleomagnetic vector'
        self.DESC['specimen_mad_anc'] = 'Maximum Angular Deviation (MAD) of the anchored directional PCA fits to the paleomagnetic vector'
        self.DESC['specimen_int_mad'] = 'Maximum Angular Deviation (MAD) of the free-floating directional PCA fits to the paleomagnetic vector from a paleointensity experiment'
        self.DESC['specimen_int_mad_anc'] = 'Maximum Angular Deviation (MAD) of the anchored directional PCA fits to the paleomagnetic vector from a paleointensity experiment'
        self.DESC['specimen_w'] = 'Weighting factor'
        self.DESC['specimen_q'] = 'A measure of the overall quality of the paleointensity estimate and combines the relative scatter of the best-fit line, the NRM fraction and the gap factor'
        self.DESC['specimen_f'] = 'NRM fraction used for the best-fit on an Arai plot '
        self.DESC['specimen_fvds'] = 'NRM fraction used for the best-fit on an Arai plot calculated as a vector difference sum'
        self.DESC['specimen_b'] = 'The slope of the best-fit line of the selected TRM and NRM points on an Arai plot'
        self.DESC['specimen_b_sigma'] = 'The standard error on the slope on an Arai plot'
        self.DESC['specimen_b_beta'] = 'The ratio of the standard error of the slope to the absolute value of the slope on an Arai plot'
        self.DESC['specimen_g'] = 'The gap reflects the average spacing of the selected Arai plot points along the best-fit line'
        self.DESC['specimen_gmax'] = 'The maximum gap between two points in Arai plot determined by vector arithmetic'
        self.DESC['specimen_r_sq'] = 'The squared correlation coefficient to estimate the strength of the linear relationship between the NRM and TRM over the best-fit Arai plot segment'
        self.DESC['specimen_coeff_det_sq'] = 'The squared coefficient of determination to estimate variance accounted for by the linear model fit on an Arai plot'
        self.DESC['specimen_dang'] = 'Deviation angle of direction of component with respect to origin'
        self.DESC['specimen_int_dang'] = 'The angle between the free-floating best-fit direction and the vector connecting the center of mass and the origin of the vector component diagram'
        self.DESC['specimen_int_crm'] = 'The cumulative deflection between the NRM vectors and the ChRM direction'
        self.DESC['specimen_int_ptrm_tail_n'] = 'Number of pTRM tail checks used in paleointensity experiment'
        self.DESC['specimen_md'] = 'Maximum absolute difference produced by a pTRM tail check, normalized by the vector difference sum of the NRM'
        self.DESC['specimen_tail_drat'] = 'Maximum absolute difference produced by a pTRM tail check, normalized by the length of the best-fit line'
        self.DESC[
            'specimen_dtr'] = 'Maximum absolute difference produced by a pTRM tail check, normalized by the NRM (obtained from the intersection of the best-fit line and the y-axis on an Arai plot)'
        self.DESC['specimen_int_ptrm_n'] = 'Number of pTRM checks used in paleointensity experiment'
        self.DESC['specimen_ptrm'] = 'Maximum absolute difference produced by a pTRM check, normalized by the TRM acquired at that heating step'
        self.DESC[
            'specimen_dck'] = 'Maximum absolute difference produced by a pTRM check, normalized by the total TRM (obtained from the intersection of the best-fit line and the x-axis on an Arai plot)'
        self.DESC['specimen_maxdev'] = 'Maximum absolute difference produced by a pTRM check, normalized by the length of the TRM segment of the best-fit line on an Arai plot'
        self.DESC['specimen_drat'] = 'Maximum absolute difference produced by a pTRM check, normalized by the length of the best-fit line'
        self.DESC['specimen_mdrat'] = 'The average difference produced by a pTRM check, normalized by the length of the best-fit line'
        self.DESC['specimen_cdrat'] = 'Cumulative difference ratio difference produced by a pTRM check'
        self.DESC['specimen_drats'] = 'Cumulative pTRM check difference normalized by the pTRM gained at the maximum temperature used for the best-fit on the Arai plot'
        self.DESC['specimen_mdev'] = 'Mean deviation of a pTRM check'
        self.DESC[
            'specimen_dpal'] = 'A measure of cumulative alteration determined by the difference of the alteration corrected intensity estimate (Valet et al., 1996) and the uncorrected estimate, normalized by the uncorrected estimate (Leonhardt et al., 2004a)'
        self.DESC['specimen_dt'] = 'The extent of a pTRM tail after correction for angular dependence'
        self.DESC[
            'specimen_dac'] = 'The maximum absolute additivity check difference normalized by the total TRM (obtained from the intersection of the best-fit line and the x-axis on an Arai plot'
        self.DESC['specimen_ac_n'] = 'The number of additivity checks used to analyze the best-fit segment on an Arai plot'
        self.DESC['specimen_k'] = 'The curvature of the Arai plot as determined by the best-fit circle to all of the data '
        self.DESC['specimen_k_sse'] = 'The quality of the best-fit circle used to determine k'
        self.DESC['specimen_k_prime'] = 'The curvature of the Arai plot as determined by the best-fit circle to the selected data points'
        self.DESC['specimen_k_prime_sse'] = 'The quality of the best-fit circle used to determine k_prime'
        self.DESC['specimen_z'] = 'Arai plot zigzag parameter calculated using the scatter around the best-fit slope on an Arai plot'
        self.DESC['specimen_z_md'] = 'Arai plot zigzag parameter calculated by the area bounded by the curve that the ZI points make and the curve that the IZ points make'
        self.DESC[
            'specimen_scat'] = 'All pTRM checks, MD checks, IZ ZI data, etc. are in the box (g = good or b=bad)'
        self.DESC['specimen_viscosity_index'] = 'Viscosity index'
        self.DESC['specimen_lab_field_dc'] = 'Applied DC field in laboratory'
        self.DESC['specimen_lab_field_ac'] = 'Applied maximum or peak AC field in laboratory'
        self.DESC['specimen_magn_moment'] = 'Measured magnetic moment'
        self.DESC['specimen_magn_volume'] = 'Measured intensity of magnetization, Volume normalized'
        self.DESC['specimen_magn_mass'] = 'Measured intensity of magnetization, Mass normalized'
        self.DESC['specimen_int_corr_cooling_rate'] = 'Cooling rate correction factor for intensity'
        self.DESC['specimen_int_corr_anisotropy'] = 'Anisotropy correction factor for intensity'
        self.DESC['specimen_int_corr_nlt'] = 'Non-linear TRM correction factor for intensity'
        self.DESC['specimen_delta'] = 'Maximum angle of deviation between assumed NRM and measured NRM in perpendicular paleointensity method'
        self.DESC['specimen_theta'] = 'The angle between the applied field direction and the ChRM direction of the NRM as determined from the free-floating PCA fit to the selected demagnetization steps of the paleointensity experiment'
        self.DESC['specimen_gamma'] = 'Maximum angle of deviation between acquired pTRM direction and assumed applied field direction'
        self.InitUI()
        self.initialize_stat()

    def InitUI(self):

        pnl1 = wx.Panel(self)
        vbox = wx.BoxSizer(wx.VERTICAL)

        #============================
        # design the panel
        #============================

        #---------------------------
        # sizer 1
        # Specimen criteria
        #---------------------------

        categories = ['Arai plot', 'Direction',
                      'pTRM Checks', 'Tail Checks', 'Additivity Checks']
        for k, cat in enumerate(categories):
            self.bSizers[k] = wx.StaticBoxSizer(wx.StaticBox(pnl1, wx.ID_ANY, cat), wx.VERTICAL)

            for stat in self.stat_by_category[cat]:
                short_name = stat.replace("specimen_", "")
                self.set_specimen_windows[short_name] = wx.CheckBox(pnl1, -1, label=short_name, name=short_name)
                self.Bind(wx.EVT_CHECKBOX, self.OnCheckBox, self.set_specimen_windows[short_name])
                self.specimen_btns[short_name] = wx.Button(pnl1, -1, label='description',name=stat)
                self.Bind(wx.EVT_BUTTON, self.PI_stat_description, self.specimen_btns[short_name])

            self.hboxes[k] = {}<commit_msg>in Thellier GUI prevent users from accessing specimen_dt (since we don’t currently calculate that in SPD)<commit_after>#!/usr/bin/env python

#=========================================================================
# LOG HEADER:
#
# Dialogs boxes for thellier_gui.py
#
#=========================================================================
#
#  11/16/2014 add some units to criteria dialogs
#
# 11/08/2014 Version add k_prime description
#
# 08/08/2014 Version add k_prime description
#
# 3/22/2014 Version 1.0 by <NAME>
#
#
#=========================================================================

#--------------------------------------------------------------
# Thellier GUI dialog
#--------------------------------------------------------------

import matplotlib
# matplotlib.use('WXAgg')
import wx
import wx.lib.scrolledpanel
import copy
import os
import scipy
from scipy import arange
# only this one is nessesary.
import wx
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigCanvas
import pmagpy.pmag as pmag
from dialogs import pmag_widgets as pw
#--------------------------------------------------------------
# paleointensity statistics list (SPD.v.1.0)
#--------------------------------------------------------------


class PI_Statistics_Dialog(wx.Dialog):

    def __init__(self, parent, show_statistics_on_gui, title):
        style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER
        super(PI_Statistics_Dialog, self).__init__(
            parent, title=title, style=style)
        self.show_statistics_on_gui = copy.copy(show_statistics_on_gui)

        # dicts to contain small window elements
        self.bSizers = {}
        self.hboxes = {}
        self.set_specimen_windows = {}
        self.specimen_btns = {}

        self.stat_by_category = {}

        self.stat_by_category['Arai plot'] = ['specimen_int_n',
                                              'specimen_frac', 'specimen_f', 'specimen_fvds',
                                              'specimen_b_sigma', 'specimen_b_beta', 'specimen_scat',
                                              'specimen_g', 'specimen_gmax',
                                              'specimen_k', 'specimen_k_sse',
                                              'specimen_k_prime', 'specimen_k_prime_sse',
                                              'specimen_z', 'specimen_z_md',
                                              'specimen_q',
                                              'specimen_r_sq', 'specimen_coeff_det_sq',
                                              ]
        self.stat_by_category['Direction'] = ['specimen_int_mad', 'specimen_int_mad_anc', 'specimen_int_dang',
                                              'specimen_int_alpha', 'specimen_alpha_prime', 'specimen_theta', 'specimen_int_crm', 'specimen_gamma']
        self.stat_by_category['pTRM Checks'] = ['specimen_int_ptrm_n', 'specimen_ptrm', 'specimen_drat', 'specimen_drats', 'specimen_cdrat', 'specimen_mdrat',
                                                'specimen_dck', 'specimen_maxdev', 'specimen_mdev', 'specimen_dpal']
        self.stat_by_category['Tail Checks'] = ['specimen_int_ptrm_tail_n',
                                                'specimen_md', 'specimen_tail_drat', 'specimen_dtr', 'specimen_dt']
        self.stat_by_category['Additivity Checks'] = [
            'specimen_ac_n', 'specimen_dac']
        self.DESC = {}
        self.DESC['specimen_frac'] = 'The angle between the applied field direction and the ChRM direction of the NRM as determined from the free-floating PCA fit to the selected demagnetization steps of the paleointensity experiment'
        self.DESC['specimen_int_n'] = 'Number of measurements included in field strength calculations'
        self.DESC['specimen_alpha_prime'] = 'Angular difference between the anchored best-fit direction from the paleointensity experiment and an independent measure of the paleomagnetic direction'
        self.DESC['specimen_alpha'] = 'Angular difference between the anchored and free-floating best-fit directions on a vector component diagram'
        self.DESC['specimen_int_alpha'] = 'Angular difference between the anchored and free-floating best-fit directions on a vector component diagram from a paleointensity experiment'
        self.DESC['specimen_mad'] = 'Maximum Angular Deviation (MAD) of the free-floating directional PCA fits to the paleomagnetic vector'
        self.DESC['specimen_mad_anc'] = 'Maximum Angular Deviation (MAD) of the anchored directional PCA fits to the paleomagnetic vector'
        self.DESC['specimen_int_mad'] = 'Maximum Angular Deviation (MAD) of the free-floating directional PCA fits to the paleomagnetic vector from a paleointensity experiment'
        self.DESC['specimen_int_mad_anc'] = 'Maximum Angular Deviation (MAD) of the anchored directional PCA fits to the paleomagnetic vector from a paleointensity experiment'
        self.DESC['specimen_w'] = 'Weighting factor'
        self.DESC['specimen_q'] = 'A measure of the overall quality of the paleointensity estimate and combines the relative scatter of the best-fit line, the NRM fraction and the gap factor'
        self.DESC['specimen_f'] = 'NRM fraction used for the best-fit on an Arai plot '
        self.DESC['specimen_fvds'] = 'NRM fraction used for the best-fit on an Arai plot calculated as a vector difference sum'
        self.DESC['specimen_b'] = 'The slope of the best-fit line of the selected TRM and NRM points on an Arai plot'
        self.DESC['specimen_b_sigma'] = 'The standard error on the slope on an Arai plot'
        self.DESC['specimen_b_beta'] = 'The ratio of the standard error of the slope to the absolute value of the slope on an Arai plot'
        self.DESC['specimen_g'] = 'The gap reflects the average spacing of the selected Arai plot points along the best-fit line'
        self.DESC['specimen_gmax'] = 'The maximum gap between two points in Arai plot determined by vector arithmetic'
        self.DESC['specimen_r_sq'] = 'The squared correlation coefficient to estimate the strength of the linear relationship between the NRM and TRM over the best-fit Arai plot segment'
        self.DESC['specimen_coeff_det_sq'] = 'The squared coefficient of determination to estimate variance accounted for by the linear model fit on an Arai plot'
        self.DESC['specimen_dang'] = 'Deviation angle of direction of component with respect to origin'
        self.DESC['specimen_int_dang'] = 'The angle between the free-floating best-fit direction and the vector connecting the center of mass and the origin of the vector component diagram'
        self.DESC['specimen_int_crm'] = 'The cumulative deflection between the NRM vectors and the ChRM direction'
        self.DESC['specimen_int_ptrm_tail_n'] = 'Number of pTRM tail checks used in paleointensity experiment'
        self.DESC['specimen_md'] = 'Maximum absolute difference produced by a pTRM tail check, normalized by the vector difference sum of the NRM'
        self.DESC['specimen_tail_drat'] = 'Maximum absolute difference produced by a pTRM tail check, normalized by the length of the best-fit line'
        self.DESC[
            'specimen_dtr'] = 'Maximum absolute difference produced by a pTRM tail check, normalized by the NRM (obtained from the intersection of the best-fit line and the y-axis on an Arai plot)'
        self.DESC['specimen_int_ptrm_n'] = 'Number of pTRM checks used in paleointensity experiment'
        self.DESC['specimen_ptrm'] = 'Maximum absolute difference produced by a pTRM check, normalized by the TRM acquired at that heating step'
        self.DESC[
            'specimen_dck'] = 'Maximum absolute difference produced by a pTRM check, normalized by the total TRM (obtained from the intersection of the best-fit line and the x-axis on an Arai plot)'
        self.DESC['specimen_maxdev'] = 'Maximum absolute difference produced by a pTRM check, normalized by the length of the TRM segment of the best-fit line on an Arai plot'
        self.DESC['specimen_drat'] = 'Maximum absolute difference produced by a pTRM check, normalized by the length of the best-fit line'
        self.DESC['specimen_mdrat'] = 'The average difference produced by a pTRM check, normalized by the length of the best-fit line'
        self.DESC['specimen_cdrat'] = 'Cumulative difference ratio difference produced by a pTRM check'
        self.DESC['specimen_drats'] = 'Cumulative pTRM check difference normalized by the pTRM gained at the maximum temperature used for the best-fit on the Arai plot'
        self.DESC['specimen_mdev'] = 'Mean deviation of a pTRM check'
        self.DESC[
            'specimen_dpal'] = 'A measure of cumulative alteration determined by the difference of the alteration corrected intensity estimate (Valet et al., 1996) and the uncorrected estimate, normalized by the uncorrected estimate (Leonhardt et al., 2004a)'
        self.DESC['specimen_dt'] = 'The extent of a pTRM tail after correction for angular dependence.  NOT CURRENTLY AVAILABLE'
        self.DESC[
            'specimen_dac'] = 'The maximum absolute additivity check difference normalized by the total TRM (obtained from the intersection of the best-fit line and the x-axis on an Arai plot'
        self.DESC['specimen_ac_n'] = 'The number of additivity checks used to analyze the best-fit segment on an Arai plot'
        self.DESC['specimen_k'] = 'The curvature of the Arai plot as determined by the best-fit circle to all of the data '
        self.DESC['specimen_k_sse'] = 'The quality of the best-fit circle used to determine k'
        self.DESC['specimen_k_prime'] = 'The curvature of the Arai plot as determined by the best-fit circle to the selected data points'
        self.DESC['specimen_k_prime_sse'] = 'The quality of the best-fit circle used to determine k_prime'
        self.DESC['specimen_z'] = 'Arai plot zigzag parameter calculated using the scatter around the best-fit slope on an Arai plot'
        self.DESC['specimen_z_md'] = 'Arai plot zigzag parameter calculated by the area bounded by the curve that the ZI points make and the curve that the IZ points make'
        self.DESC[
            'specimen_scat'] = 'All pTRM checks, MD checks, IZ ZI data, etc. are in the box (g = good or b=bad)'
        self.DESC['specimen_viscosity_index'] = 'Viscosity index'
        self.DESC['specimen_lab_field_dc'] = 'Applied DC field in laboratory'
        self.DESC['specimen_lab_field_ac'] = 'Applied maximum or peak AC field in laboratory'
        self.DESC['specimen_magn_moment'] = 'Measured magnetic moment'
        self.DESC['specimen_magn_volume'] = 'Measured intensity of magnetization, Volume normalized'
        self.DESC['specimen_magn_mass'] = 'Measured intensity of magnetization, Mass normalized'
        self.DESC['specimen_int_corr_cooling_rate'] = 'Cooling rate correction factor for intensity'
        self.DESC['specimen_int_corr_anisotropy'] = 'Anisotropy correction factor for intensity'
        self.DESC['specimen_int_corr_nlt'] = 'Non-linear TRM correction factor for intensity'
        self.DESC['specimen_delta'] = 'Maximum angle of deviation between assumed NRM and measured NRM in perpendicular paleointensity method'
        self.DESC['specimen_theta'] = 'The angle between the applied field direction and the ChRM direction of the NRM as determined from the free-floating PCA fit to the selected demagnetization steps of the paleointensity experiment'
        self.DESC['specimen_gamma'] = 'Maximum angle of deviation between acquired pTRM direction and assumed applied field direction'
        self.InitUI()
        self.initialize_stat()

    def InitUI(self):

        pnl1 = wx.Panel(self)
        vbox = wx.BoxSizer(wx.VERTICAL)

        #============================
        # design the panel
        #============================

        #---------------------------
        # sizer 1
        # Specimen criteria
        #---------------------------

        categories = ['Arai plot', 'Direction',
                      'pTRM Checks', 'Tail Checks', 'Additivity Checks']
        for k, cat in enumerate(categories):
            self.bSizers[k] = wx.StaticBoxSizer(wx.StaticBox(pnl1, wx.ID_ANY, cat), wx.VERTICAL)

            for stat in self.stat_by_category[cat]:
                short_name = stat.replace("specimen_", "")
                disp_name = short_name
                if short_name == 'dt':
                    disp_name = 'dt (NOT AVAILABLE)'
                self.set_specimen_windows[short_name] = wx.CheckBox(pnl1, -1, label=disp_name, name=short_name)
                if short_name == 'dt':
                    self.set_specimen_windows[short_name].Disable()
                self.Bind(wx.EVT_CHECKBOX, self.OnCheckBox, self.set_specimen_windows[short_name])
                self.specimen_btns[short_name] = wx.Button(pnl1, -1, label='description',name=stat)
                self.Bind(wx.EVT_BUTTON, self.PI_stat_description, self.specimen_btns[short_name])

            self.hboxes[k] = {}
{'fraction_non_alphanumeric': 0.12055328268069355, 'fraction_numerical': 0.0038963569062926166, 'mean_word_length': 2.8653614457831327, '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': 48, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '644299', 'n_tokens_mistral': 7076, 'n_tokens_neox': 6745, 'n_words': 2361}