コード例 #1
0
ファイル: analysis_proc.cs プロジェクト: kissingleman/LIBS
        //获取某元素波长的方程,前置约束为调用者已经完成所有所有标样的读取
        //函数返回方程的同时,将返回方程进行计算时用到的标样点
        public static LinearFit.LfReValue get_equation(spec_metadata spec_obj, int element_index, ref double[] concentration, ref double[] standards_integration_average_strenth, int bs)
        {
            double[]       wave_all     = spec_obj.read_wave_all;
            double[]       env          = spec_obj.env_spec;
            standard[]     standards    = spec_obj.standards;
            int            standard_cnt = spec_obj.standard_cnt;
            select_element element      = spec_obj.elements[element_index];

            double[,,] spec_standard = spec_obj.read_standard_spec;

            //提取该元素列标样数据,得到方程
            standards_integration_average_strenth = new double[standard_cnt];
            //标样平均的积分平均强度
            for (int i = 0; i < standard_cnt; i++)              //每个标样
            {
                double standard_element_interval_average = 0.0; //平均的平均
                //如果点击的为标样,在计算方程的循环中直接获取多次积分平均值
                double[] strenght_oneshot = get_oneshot_all_strength(spec_obj, i, element_index);
                for (int t = 0; t < standards[i].average_times; t++)
                {
                    standard_element_interval_average += strenght_oneshot[t];
                }
                standards_integration_average_strenth[i] = standard_element_interval_average / standards[i].average_times;
            }
            concentration = new double[standard_cnt]; //浓度
            for (int j = 0; j < standard_cnt; j++)
            {
                concentration[j] = standards[j].standard_ppm[element.sequece_index - 1];
            }
            LinearFit.LfReValue equation;
            //过空白或不过空白读取
            if (bs == 0)
            {
                equation = LinearFit.linearFitFunc(concentration, standards_integration_average_strenth, standard_cnt);
            }
            else
            {
                equation = LinearFit.linearFitFunc_blank(concentration, standards_integration_average_strenth, standard_cnt);
            }

            return(equation);
        }
コード例 #2
0
ファイル: analysis_proc.cs プロジェクト: kissingleman/LIBS
        //准备分析窗体峰视图显示的x_minimal,x_maximal,x_unit,y_minimal,y_maiximal,y_unit以及数据spec_selected
        private static void prepare_peak_chart_data(spec_metadata spec_obj, int click_row, int click_column, ref double[] spec_selected, ref double x_minimal, ref double x_maximal, ref double x_show_unit, ref double y_minimal, ref double y_maximal, ref int y_show_unit)
        {
            standard[] standards    = spec_obj.standards;
            int        standard_cnt = spec_obj.standard_cnt;

            double[,,] spec_standard = spec_obj.read_standard_spec;
            double[,,] spec_sample   = spec_obj.read_sample_spec;
            double[]       wave_all  = spec_obj.read_wave_all;
            double[]       env       = spec_obj.env_spec;
            select_element element   = spec_obj.elements[click_column - 3];
            int            pixel_cnt = spec_obj.read_wave_all.Length;

            spec_selected = new double[pixel_cnt];
            if (click_row < standard_cnt)
            {
                for (int i = 0; i < pixel_cnt; i++)
                {
                    spec_selected[i] = spec_standard[click_row, 0, i]; //展示波峰图时,简单的展示第0次平均的值
                }
            }
            else
            {
                for (int i = 0; i < pixel_cnt; i++)
                {
                    spec_selected[i] = spec_sample[click_row - standard_cnt, 0, i]; //展示波峰图时,简单的展示第0次平均的值
                }
            }
            //设置显示配置
            double peak_wave = element.peak_wave;

            x_minimal = peak_wave - 0.25;
            x_maximal = peak_wave + 0.25;

            int show_x_start = data_util.get_index_by_wave(wave_all, x_minimal);
            int show_x_end   = data_util.get_index_by_wave(wave_all, x_maximal);

            y_minimal = spec_selected[show_x_start];
            y_maximal = spec_selected[show_x_start];
            for (int i = show_x_start; i < show_x_end; i++)
            {
                if (spec_selected[i] < y_minimal)
                {
                    y_minimal = spec_selected[i];
                }
                if (spec_selected[i] > y_maximal)
                {
                    y_maximal = spec_selected[i];
                }
                if (env[i] < y_minimal)
                {
                    y_minimal = env[i];
                }
                if (env[i] > y_maximal)
                {
                    y_maximal = env[i];
                }
            }
            y_maximal += (y_maximal - y_minimal) * 0.1; // maximal + 10% * range

            x_show_unit = 0.05;
            y_show_unit = data_util.normalize_y(y_minimal, y_maximal);
            //y的显示不随放大缩小改变, x将利用 data_util 来规范显示数据,初始时,x_show_unit固定为0.05
            y_minimal = (int)((y_minimal - 0.001) / y_show_unit - 1) * y_show_unit;
            y_maximal = (int)((y_maximal - 0.001) / y_show_unit + 1) * y_show_unit;
            data_util.normalize_data_for_show(x_show_unit, 10, ref x_show_unit, ref x_minimal, ref x_maximal); //
        }