Example #1
0
            public Data(Spectr sp, float con, double ly, bool from_next)
            {
                Sp  = sp;
                Con = con;
                Dispers    disp = sp.GetCommonDispers();
                List <int> snl  = disp.FindSensors(ly);
                int        sn;

                if (from_next)
                {
                    sn = snl[1];
                }
                else
                {
                    sn = snl[0];
                }
                int pixel = (int)disp.GetLocalPixelByLy(sn, ly);

                int[] sh_indexes = sp.GetShotIndexes();
                Analit = new double[sh_indexes.Length];
                Comp   = new double[sh_indexes.Length];
                List <SpectrDataView> views = sp.GetViewsSet();

                for (int i = 0; i < Analit.Length; i++)
                {
                    float[] sig     = views[sh_indexes[i]].GetSensorData(sn);
                    float[] nul     = sp.GetNullFor(sh_indexes[i]).GetSensorData(sn);
                    float[] sig_nul = new float[sig.Length];
                    for (int j = 0; j < sig.Length; j++)
                    {
                        sig_nul[j] = sig[j] - nul[j];
                    }
                    Analit[i] = CalcAnalit(sig_nul, pixel);
                }
            }
Example #2
0
        double CheckLine(int sn, double ly, float[][] data, Dispers disp, int plus_minus, out double ly_real, out float[] data_cur)
        {
            int pixel = (int)disp.GetLocalPixelByLy(sn, ly);

            for (int i = 0; i < plus_minus && i < data[sn].Length - 2 &&
                 (data[sn][pixel] + data[sn][pixel + 1] + data[sn][pixel - 1]) <
                 (data[sn][pixel] + data[sn][pixel + 1] + data[sn][pixel + 2]);
                 i++, pixel++)
            {
                ;
            }
            for (int i = 0; i < plus_minus && i > 2 &&
                 (data[sn][pixel] + data[sn][pixel + 1] + data[sn][pixel - 1]) <
                 (data[sn][pixel - 2] + data[sn][pixel - 1] + data[sn][pixel]);
                 i++, pixel--)
            {
                ;
            }
            double left_v  = data[sn][pixel - 3] + data[sn][pixel - 2] + data[sn][pixel - 1],
                   midl_v  = data[sn][pixel - 1] + data[sn][pixel] + data[sn][pixel + 1],
                   right_v = data[sn][pixel + 1] + data[sn][pixel + 2] + data[sn][pixel + 3];

            if (left_v < midl_v && midl_v > right_v)
            {
                int left = 1;
                for (; left < plus_minus && (pixel - 2 - left) > 0 &&
                     (data[sn][pixel - left] + data[sn][pixel + 1 - left] + data[sn][pixel - 1 - left]) >
                     (data[sn][pixel - left] + data[sn][pixel - 1 - left] + data[sn][pixel - 2 - left]); left++)
                {
                    ;
                }
                int right = 1;
                for (; right < plus_minus && (pixel + 2 + right) < data[sn].Length &&
                     (data[sn][pixel + right] + data[sn][pixel + 1 + right] + data[sn][pixel - 1 + right]) >
                     (data[sn][pixel + right] + data[sn][pixel + 1 + right] + data[sn][pixel + 2 + right]); right++)
                {
                    ;
                }
                if (left > 2 && right > 2 && left + right >= numMinWidth.Value)
                {
                    ly_real  = disp.GetLyByLocalPixel(sn, pixel);
                    data_cur = new float[5];
                    for (int i = 0; i < 5; i++)
                    {
                        data_cur[i] = data[sn][pixel - 2 + i];
                    }
                    return(midl_v);//return disp.GetLyByLocalPixel(sn,pixel);
                }
            }
            ly_real  = -1;
            data_cur = null;
            return(0);
        }
Example #3
0
        private void mmLineToPik_Click(object sender, EventArgs e)
        {
            try
            {
                bool result;

                LastLinks = Disp.Compile(tbLinks.Text, true, out result);
                //result = ApplyDispers();
                //ApplyDispersDelProc();
                //if (ApplyDispResult != 1)//
                if (result == false)
                {
                    MessageBox.Show(MainForm.MForm,
                                    Common.MLS.Get(MLSConst, "Обнаружены ошибки. Их необходимо исправить."), //"Compilation error. Correct problem first."),
                                    Common.MLS.Get(MLSConst, "Проблема"),                                    //"Problem"),
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Hand);
                    return;
                }
                Dispers disp = Disp;
                Control.SelectSpectr();
                if (SelectedMarker < 0)
                {
                    return;
                }
                int s = 0;
                if (sender == mmLineToPik1)
                {
                    s = 0;
                }
                else
                {
                    if (sender == mmLineToPik2)
                    {
                        s = 1;
                    }
                    else
                    {
                        if (sender == mmLineToPik3)
                        {
                            s = 2;
                        }
                    }
                }

                Spectr sp = GetSpectr(s);
                if (sp == null)
                {
                    return;
                }

                SpectrDataView view = sp.GetDefultView();
                //Dispers disp = sp.GetCommonDispers();

                int     sn    = LastLinks[SelectedMarker].Sn;
                float[] data  = view.GetSensorData(sn);
                int     pixel = (int)disp.GetLocalPixelByLy(sn, LastLinks[SelectedMarker].Ly);

                try
                {
                    if (data[pixel] < data[pixel + 1])
                    {
                        while (data[pixel] < data[pixel + 1])
                        {
                            pixel++;
                        }
                    }
                    else
                    {
                        if (data[pixel] < data[pixel - 1])
                        {
                            while (data[pixel] < data[pixel - 1])
                            {
                                pixel--;
                            }
                        }
                    }
                }
                catch { }

                float  nly    = (float)disp.GetLyByLocalPixel(sn, pixel);
                float  gpixel = (float)disp.GetGlobalPixelByLy(sn, nly);
                string text   = (string)tbLinks.Text.Clone();
                int    from   = tbLinks.SelectionStart;
                int    len    = tbLinks.SelectionLength;
                string txt1   = text.Substring(0, from);
                string txt2   = text.Substring(from + len + 1);
                text = txt1 + Math.Round(gpixel, 1) + "-" + Math.Round(gpixel, 2) + txt2;
                //tbLinks.Text = text;
                //SetupMarkers(false);
                ApplyDispers();
            }
            catch (Exception ex) { Common.Log(ex); }
        }
        static public List <DataShot> extract(MethodSimple method, string element, int formula,
                                              double ly, int widthPlusMinus, bool useConDlt,
                                              double min, double max, bool relative)
        {
            int             mul_k   = (int)Common.Conf.MultFactor;
            int             is_ok   = 0;
            int             is_over = 0;
            List <DataShot> ret     = new List <DataShot>();

            Element[] list = method.GetElementList();
            for (int el = 0; el < list.Length; el++)
            {
                if (list[el].Name.Equals(element) || element == null)
                {
                    MethodSimpleElementFormula calcFormula = method.GetElHeader(el).Formula[formula];
                    bool[] frames = calcFormula.Formula.GetUsedFrames();
                    for (int prob_index = 0; prob_index < method.GetProbCount(); prob_index++)
                    {
                        MethodSimpleProb prob = method.GetProbHeader(prob_index);
                        MethodSimpleCell msc  = method.GetCell(el, prob_index);
                        if (useConDlt == false)
                        {
                            double fkVal = msc.Con;
                            double con   = fkVal;

                            /*if (useConDlt)
                             * {
                             *  double sko, sko1;
                             *  double rcon = //msc.CalcRealCon(out sko, out sko1);
                             *  fkVal -= rcon;
                             * }//*/
                            for (int measuring_index = 0; measuring_index < prob.MeasuredSpectrs.Count; measuring_index++)
                            {
                                MethodSimpleCellFormulaResult mscfr = msc.GetData(measuring_index, formula);
                                if (mscfr.Enabled == false)
                                {
                                    continue;
                                }
                                MethodSimpleProbMeasuring mspm = prob.MeasuredSpectrs[measuring_index];
                                Spectr sp = mspm.Sp;
                                if (sp == null)
                                {
                                    continue;
                                }
                                List <SpectrDataView> viewSet = sp.GetViewsSet();
                                int[]      shotIndexes        = sp.GetShotIndexes();
                                Dispers    disp    = sp.GetCommonDispers();
                                List <int> sensors = disp.FindSensors(ly);
                                bool       isEnabled;
                                if (con >= 0)
                                {
                                    isEnabled = msc.Enabled;
                                }
                                else
                                {
                                    isEnabled = false;
                                }
                                for (int shot_index = 0; shot_index < shotIndexes.Length; shot_index++)
                                {
                                    if (frames[shot_index] == false)
                                    {
                                        continue;
                                    }
                                    SpectrDataView sig = viewSet[shotIndexes[shot_index]];
                                    SpectrDataView nul = sp.GetNullFor(shotIndexes[shot_index]);
                                    for (int sn = 0; sn < 1 && sn < sensors.Count; sn++)
                                    {
                                        int     sensorIndex = sensors[sn];
                                        int     n           = (int)disp.GetLocalPixelByLy(sensorIndex, ly);
                                        float[] sigData     = sig.GetSensorData(sensorIndex);
                                        float[] nulData     = nul.GetSensorData(sensorIndex);
                                        float   minSignal   = float.MaxValue;
                                        float[] signal      = new float[sigData.Length];
                                        for (int i = 0; i < signal.Length; i++)
                                        {
                                            signal[i] = sigData[i] - nulData[i];
                                        }
                                        for (int i = 500; i < sigData.Length - 500; i++)
                                        {
                                            float val = (signal[i - 1] + signal[i] + signal[i + 1]) / 3;
                                            if (val < minSignal)
                                            {
                                                minSignal = val;
                                            }
                                        }

                                        float[] data      = new float[widthPlusMinus * 2 + 1];
                                        double  maxSignal = -double.MaxValue;
                                        for (int i = 0; i < data.Length; i++)
                                        {
                                            int index = n - widthPlusMinus + i;
                                            if (index < 0 || index >= sigData.Length)
                                            {
                                                data[i]   = -float.MaxValue;
                                                isEnabled = false;
                                                continue;
                                            }
                                            data[i] = signal[index];//sigData[index] - nulData[index];
                                            if (data[i] > max)
                                            {
                                                isEnabled = false;
                                            }
                                            if (data[i] > maxSignal && i > widthPlusMinus - 4 && i < widthPlusMinus + 4)
                                            {
                                                maxSignal = data[i];
                                            }
                                        }
                                        if (maxSignal < min)
                                        {
                                            isEnabled = false;
                                        }
                                        if (isEnabled)
                                        {
                                            is_ok++;
                                        }
                                        else
                                        {
                                            is_over++;
                                        }
                                        DataShot dsh = new DataShot(ly, fkVal, data, isEnabled);
                                        ret.Add(dsh);
                                    }
                                }
                            }
                        }
                        else
                        {
                            for (int measuring_index = 0; measuring_index < prob.MeasuredSpectrs.Count; measuring_index++)
                            {
                                MethodSimpleProbMeasuring mspm = prob.MeasuredSpectrs[measuring_index];
                                Spectr sp = mspm.Sp;
                                if (sp == null)
                                {
                                    continue;
                                }
                                List <SpectrDataView> viewSet = sp.GetViewsSet();
                                int[]      shotIndexes        = sp.GetShotIndexes();
                                Dispers    disp    = sp.GetCommonDispers();
                                List <int> sensors = disp.FindSensors(ly);
                                bool       isEnabled;
                                if (msc.Con >= 0)
                                {
                                    isEnabled = msc.Enabled;
                                }
                                else
                                {
                                    isEnabled = false;
                                }
                                MethodSimpleCellFormulaResult result = msc.GetData(measuring_index, formula);
                                int data_index = 0;
                                for (int shot_index = 0; shot_index < shotIndexes.Length; shot_index++)
                                {
                                    if (frames[shot_index] == false)
                                    {
                                        continue;
                                    }
                                    double tmpAnalit = result.AnalitValue[data_index];
                                    double fkVal;
                                    if (relative == false)
                                    {
                                        fkVal = calcFormula.Formula.CalcCon(0, tmpAnalit, 0) - msc.Con;
                                    }
                                    else
                                    {
                                        if (msc.Con > 0.01)
                                        {
                                            fkVal = (calcFormula.Formula.CalcCon(0, tmpAnalit, 0) - msc.Con) / msc.Con;
                                        }
                                        else
                                        {
                                            fkVal = Double.NaN;
                                        }
                                    }
                                    SpectrDataView sig = viewSet[shotIndexes[shot_index]];
                                    SpectrDataView nul = sp.GetNullFor(shotIndexes[shot_index]);
                                    for (int sn = 0; sn < sensors.Count; sn++)
                                    {
                                        int     sensorIndex = sensors[sn];
                                        int     n           = (int)disp.GetLocalPixelByLy(sensorIndex, ly);
                                        float[] sigData     = sig.GetSensorData(sensorIndex);
                                        float[] nulData     = nul.GetSensorData(sensorIndex);

                                        float[] data = new float[widthPlusMinus * 2 + 1];
                                        for (int i = 0; i < data.Length; i++)
                                        {
                                            int index = n - widthPlusMinus + i;
                                            if (index < 0 || index >= sigData.Length)
                                            {
                                                data[i]   = -float.MaxValue;
                                                isEnabled = false;
                                                continue;
                                            }
                                            data[i] = sigData[index] - nulData[index];
                                            if (data[i] > max)
                                            {
                                                isEnabled = false;
                                            }
                                        }
                                        if (isEnabled)
                                        {
                                            is_ok++;
                                        }
                                        else
                                        {
                                            is_over++;
                                        }
                                        DataShot dsh = new DataShot(ly, fkVal, data, isEnabled);
                                        ret.Add(dsh);
                                    }
                                    data_index++;
                                }
                            }
                        }
                    }
                    break;
                }
            }
            if (is_ok == 0 || is_over / is_ok > 0.1)
            {
                return(null);
            }
            return(ret);
        }
        public bool Calc(List <GLogRecord> log,
                         string log_section, string log_prefix,
                         SpectrDataView sig,
                         SpectrDataView nul,
                         Spectr spectr,
                         out double analit,
                         out double aq,
                         ref CalcLineAtrib attrib,
                         bool is_calibr)
        {
            if (nmLy.Value < 10)
            {
                nmLy.Value = 0;
                analit     = 1;
                aq         = 0;
                return(true);
            }
            analit = 0;
            aq     = 0;

            int sn;

            if (GetSnNum(log, log_section, spectr.GetCommonDispers(),
                         sig.MaxLinarLevel, out sn) == false)
            {
                return(false);
            }

            Dispers disp         = spectr.GetCommonDispers();//sig.GetDispersRO();
            int     ss           = disp.GetSensorSizes()[sn];
            float   base_pixel_f = (float)disp.GetLocalPixelByLy(sn, (double)nmLy.Value);
            int     base_pixel   = (int)base_pixel_f;

            int pixel_from = base_pixel - PixelDlt;

            if (pixel_from < 0)
            {
                pixel_from = 0;
            }
            int pixel_to = base_pixel + PixelDlt;

            if (pixel_to > ss - 1)
            {
                pixel_to = ss - 1;
            }
            float[] sig_data         = sig.GetSensorDataWithCorrection(sn);
            float[] nul_data         = nul.GetSensorDataWithCorrection(sn);
            int     start_pixel      = (int)((base_pixel_f - pixel_from) * Common.Conf.MultFactor);
            int     start_pixel_orig = start_pixel;

            //float max_val = sig.MaxLinarLevel;
            float max_val = Common.Conf.MaxLevel;

            float[] sig_nul = new float[pixel_to - pixel_from + 1];
            OpticFk ofk     = spectr.OFk;

            //float[][] sensK = ofk.GetSensK();
            for (int i = 0; i < sig_nul.Length; i++)
            {
                sig_nul[i] = ofk.GetCorrectedValue(sn, i + pixel_from, sig_data, nul_data, max_val);// sig_data[i + pixel_from] - nul_data[i + pixel_from];
                //sig_nul[i] *= sensK[sn][i+pixel_from];
            }

            int max_pix = base_pixel;

            for (; max_pix < sig_data.Length - 1 &&
                 sig_data[max_pix] - nul_data[max_pix] < sig_data[max_pix + 1] - nul_data[max_pix + 1];
                 max_pix++)
            {
                ;
            }
            for (; max_pix > 1 &&
                 sig_data[max_pix] - nul_data[max_pix] < sig_data[max_pix - 1] - nul_data[max_pix - 1];
                 max_pix--)
            {
                ;
            }

            int sig_val = (int)(sig_data[max_pix] - nul_data[max_pix]);

            if (sig_val < MinSignalAmpl)
            {
                MinSignalAmpl = sig_val;
            }
            if (sig_val > MaxSignalAmpl)
            {
                MaxSignalAmpl = sig_val;
            }

            double[] working_data = PrepareData(sig_data, sig_nul, sn, pixel_from, spectr, max_val, Common.Conf.MultFactor);

            if (LySpectrEtalon != null)
            {
                if (LySpectrEtalonCalc == null)
                {
                    LySpectrEtalonCalc = PrepareData(sig_data, LySpectrEtalon, sn, 0, spectr, max_val, Common.Conf.MultFactor);
                }

                double min_etalon = double.MaxValue;
                double min_sig    = double.MaxValue;
                int    shift      = (int)(LySpectrLocalPixel - LySpectrEtalonPixelFrom) * Common.Conf.MultFactor - start_pixel;

                double crit = Corel(LySpectrEtalonCalc, working_data,
                                    shift, start_pixel, spectr.OverloadLevel,
                                    ref min_etalon, ref min_sig);
                for (int i = 0; i < 4 * Common.Conf.MultFactor; i++)
                {
                    double cand_crit = Corel(LySpectrEtalonCalc, working_data,
                                             shift + 1, start_pixel, spectr.OverloadLevel,
                                             ref min_etalon, ref min_sig);
                    if (cand_crit > crit)
                    {
                        shift++;
                        start_pixel--;
                        crit = cand_crit;
                    }
                    else
                    {
                        break;
                    }
                }
                for (int i = 0; i < 4 * Common.Conf.MultFactor; i++)
                {
                    double cand_crit = Corel(LySpectrEtalonCalc, working_data,
                                             shift - 1, start_pixel, spectr.OverloadLevel,
                                             ref min_etalon, ref min_sig);
                    if (cand_crit > crit)
                    {
                        shift--;
                        start_pixel++;
                        crit = cand_crit;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            else
            {
                log.Add(new GLogMsg(log_section,
                                    log_prefix + Common.MLS.Get(MLSConst, "Нет профиля линии. Для устаноки Ly используйте 'Устан.'") + nmLy.Value,
                                    Color.Orange));
            }


            if (cbMaximumType.SelectedIndex == 0 || cbMaximumType.SelectedIndex == 1)
            {
                int steps;
                if (cbMaximumType.SelectedIndex == 0)
                {
                    steps = 5;
                }
                else
                {
                    steps = 30;
                }
                if (working_data[start_pixel] < working_data[start_pixel + 1])
                {
                    for (int i = 0; i < steps &&
                         working_data[start_pixel] < working_data[start_pixel + 1];
                         i++, start_pixel++)
                    {
                        start_pixel++;
                    }
                    start_pixel--;
                }
                if (working_data[start_pixel] < working_data[start_pixel - 1])
                {
                    for (int i = 0; i < steps &&
                         working_data[start_pixel] < working_data[start_pixel - 1];
                         i++, start_pixel--)
                    {
                        start_pixel--;
                    }
                    start_pixel++;
                }
            }

            analit = working_data[start_pixel];
            if (cbExtraCalcType.SelectedIndex == 1)
            {
                double bkg_analit, bkg_aq;
                CalcBackGround(log, log_section, log_prefix + "bkg", sig, nul, spectr, out bkg_analit, out bkg_aq);
                analit /= bkg_analit;
            }
            //double min = working_data[0];//1 = working_data[start_pixel - 10];
            //double min2 = working_data[start_pixel + 10];
            //for (int i = start_pixel - 10; i > 0 && working_data[i] < working_data[i + 1]; i--)
            //if (working_data[i] < min1)
            //min1 = working_data[i];
            //for (int i = start_pixel + 10; i < working_data.Length-1 && working_data[i] < working_data[i - 1]; i++)
            //if (working_data[i] < min2)
            //min2 = working_data[i];
            double ampl = analit;// - (min1+min2)/2;

            if (is_calibr)
            {
                if (ampl < MinAnalitValue)
                {
                    MinAnalitValue = (float)ampl;
                }
                if (ampl > MaxAnalitValue)
                {
                    MaxAnalitValue = (float)ampl;
                }
            }
            else
            {
                //double dlt = (MinAnalitValue-MinAnalitValue)
                float extr_val = MinAnalitValue * (1 - Common.Env.MaxAmplDlt);
                if (ampl < extr_val)
                {
                    attrib.IsTooLow = true;
                    log.Add(new GLogMsg(log_section,
                                        log_prefix + Common.MLS.Get(MLSConst, "Линия слишком слабая: ") + nmLy.Value + "   " + (int)ampl + "<" + (int)extr_val,
                                        Color.Red));
                }
                extr_val = MaxAnalitValue * (1 + Common.Env.MaxAmplDlt);
                if (ampl > extr_val)
                {
                    attrib.IsTooHi = true;
                    log.Add(new GLogMsg(log_section,
                                        log_prefix + Common.MLS.Get(MLSConst, "Линия слишком сильная: ") + nmLy.Value + "   " + (int)ampl + ">" + (int)extr_val,
                                        Color.Red));
                }
                int pix = (int)(pixel_from + start_pixel / Common.Conf.MultFactor);
                if (sig_data[pix] > max_val ||
                    sig_data[pix + 1] > max_val ||
                    sig_data[pix + 2] > max_val ||
                    sig_data[pix + 3] > max_val ||
                    sig_data[pix - 1] > max_val ||
                    sig_data[pix - 2] > max_val ||
                    sig_data[pix - 3] > max_val)
                {
                    attrib.IsNonLinar = true;
                    log.Add(new GLogMsg(log_section,
                                        log_prefix + Common.MLS.Get(MLSConst, "Линия превысила допустимое значение: ") + nmLy.Value,
                                        Color.Red));
                }
            }
            log.Add(new GLogMsg(log_section,
                                log_prefix + "A(" + nmLy.Value + ")=" + serv.GetGoodValue(analit, 3) + " [" + serv.GetGoodValue(ampl, 2) + "]",// + " min_analit_val=" + MinAnalitValue,
                                Color.Black));
            log.Add(new GLogSpData(log_section,
                                   log_prefix + "Ly(" + nmLy.Value + ")",
                                   working_data, start_pixel, start_pixel,
                                   start_pixel_orig, (double)nmLy.Value, Color.Blue, Color.Red));

            if (LySpectrEtalonCalc != null)
            {
                int center = LySpectrEtalonCalc.Length / 2;
                log.Add(new GLogSpData(log_section,
                                       log_prefix + "Ly(" + nmLy.Value + ")",
                                       formatEtalon(working_data, LySpectrEtalonCalc), center, center,
                                       center - 10, (double)nmLy.Value, Color.LightGray, Color.Black));
            }

            return(true);
        }
        public bool SetupLy(float ly, bool force)//,int PixelDlt)
        {
            Spectr sp = Sp;

            if (sp == null)
            {
                return(false);
            }

            float      _ForLy = ly;//(float)nmLy.Value;
            Dispers    disp   = sp.GetCommonDispers();
            List <int> fsn    = disp.FindSensors(_ForLy);

            if (fsn.Count == 0)
            {
                return(false);
            }
            int sn = 0;

            if (cbFromSnNum.SelectedIndex == 0 || fsn.Count == 1)
            {
                sn = fsn[0];
            }
            else
            {
                sn = fsn[1];
            }
            float _LySpectrLocalPixel = (float)disp.GetLocalPixelByLy(sn, _ForLy);
            int   ss = disp.GetSensorSizes()[sn];

            int pixel_from = (int)(_LySpectrLocalPixel - PixelDlt * 4);
            int pixel_to   = (int)(_LySpectrLocalPixel + PixelDlt * 4);
            int _LySpectrEtalonPixelFrom = pixel_from;

            int[]          short_indexes = sp.GetShotIndexes();
            int            sh_ind        = short_indexes[short_indexes.Length / 2];
            SpectrDataView nul           = sp.GetNullFor(sh_ind);
            SpectrDataView sig           = sp[sh_ind];

            float[] nul_data = nul.GetSensorData(sn);
            float[] sig_data = sig.GetSensorData(sn);
            float[] ly_cand  = new float[pixel_to - pixel_from + 1];
            for (int i = 0; i < ly_cand.Length; i++)
            {
                if (i + pixel_from >= 0 && i + pixel_from < sig_data.Length)
                {
                    ly_cand[i] = (sig_data[i + pixel_from] - nul_data[i + pixel_from]) + 10;
                }
                else
                {
                    ly_cand[i] = 0;
                }
            }
            GraphPreview gp = new GraphPreview();

            if (force || gp.check(ParentForm, ly_cand))
            {
                double min = double.MaxValue, max = -double.MaxValue;
                for (int i = 0; i < ly_cand.Length; i++)
                {
                    if (ly_cand[i] == 0)
                    {
                        continue;
                    }
                    if (min > ly_cand[i])
                    {
                        min = ly_cand[i];
                    }
                    if (max < ly_cand[i])
                    {
                        max = ly_cand[i];
                    }
                }

                double weight = 0;
                double noise  = 0;
                for (int i = Common.Conf.MultFactor; i < ly_cand.Length - Common.Conf.MultFactor; i += Common.Conf.MultFactor)
                {
                    if (ly_cand[i] == 0 || ly_cand[i - Common.Conf.MultFactor] == 0)
                    {
                        continue;
                    }
                    double dlt  = Math.Abs(ly_cand[i - Common.Conf.MultFactor] - ly_cand[i]);
                    double ever = (ly_cand[i - Common.Conf.MultFactor] + ly_cand[i]) / 2;
                    noise  += dlt / ever;
                    weight += 1 / ever;
                }
                noise /= weight;
                noise *= gp.NoiseCenselationLevel;
                float   level    = (float)(min + noise);
                float[] fly_cand = new float[ly_cand.Length];
                for (int i = 0; i < ly_cand.Length; i++)
                {
                    if (ly_cand[i] < level)
                    {
                        fly_cand[i] = 0;
                    }
                    else
                    {
                        fly_cand[i] = ly_cand[i] - level;
                    }
                }

                if (force || gp.check(ParentForm, fly_cand))
                {
                    ly_cand = fly_cand;
                }

                ForLy = _ForLy;
                LySpectrLocalPixel      = _LySpectrLocalPixel;
                LySpectrEtalon          = ly_cand;
                LySpectrEtalonPixelFrom = _LySpectrEtalonPixelFrom;

                return(true);
            }
            return(false);
        }
        public List <ExtraLineInfo> CheckSpectr(Spectr sp)
        {
            List <ExtraLineInfo> ret = new List <ExtraLineInfo>();

            if (EmptySpaces.Count == 0)
            {
                return(ret);
            }

            List <SpectrDataView> views = sp.GetViewsSet();

            int[] active_view_indexes = sp.GetShotIndexes();
            int[] ss = sp.GetCommonDispers().GetSensorSizes();

            for (int esi = 0; esi < EmptySpaces.Count; esi++)
            {
                for (int vi = 0; vi < active_view_indexes.Length; vi++)
                {
                    SpectrDataView view = views[active_view_indexes[vi]];
                    SpectrDataView nul  = sp.GetNullFor(active_view_indexes[vi]);
                    Dispers        d    = sp.GetCommonDispers();

                    List <int> sns = d.FindSensors(EmptySpaces[esi][1]);
                    if (sns.Count == 0)
                    {
                        continue;
                    }

                    int sn         = sns[0];
                    int pixel_from = (int)d.GetLocalPixelByLy(sn, EmptySpaces[esi][1]) - (int)nmMargine.Value;
                    if (pixel_from < 0)
                    {
                        pixel_from = 0;
                    }
                    int pixel_to = (int)d.GetLocalPixelByLy(sn, EmptySpaces[esi][2]) + (int)nmMargine.Value;
                    if (pixel_to >= ss[sn])
                    {
                        pixel_to = ss[sn] - 1;
                    }

                    float[] data_s = view.GetSensorData(sn); //.GetFullData()[sn];
                    float[] data_n = nul.GetSensorData(sn);  //.GetFullData()[sn];
                    float[] data   = new float[pixel_to - pixel_from];
                    for (int i = 0; i < data.Length; i++)
                    {
                        data[i] = data_s[pixel_from + i] - data_n[pixel_from + i];
                    }
                    int side = (int)nmMinLineWidth.Value / 2;
                    for (int i = (int)nmMinLineWidth.Value; i < data.Length - (int)nmMinLineWidth.Value; i++)
                    {
                        while (i < data.Length - 5 && data[i] < data[i + 1])
                        {
                            i++;
                        }
                        int left  = 0;
                        int right = 0;
                        if (isLine(data, data.Length - 2, i, view.MaxLinarLevel, side, side * 2 + 2, ref left, ref right))
                        {
                            int start_pixel = i - 2;
                            int final_pixel = i + 2;
                            for (; start_pixel > 0 && data[start_pixel] < data[start_pixel + 1]; start_pixel--)
                            {
                                ;
                            }
                            for (; final_pixel < data.Length - 1 && data[final_pixel] < data[final_pixel - 1]; final_pixel++)
                            {
                                ;
                            }
                            if (data[i] - (data[start_pixel] + data[final_pixel]) / 2 > (int)nmMinAmpl.Value)
                            {
                                ret.Add(new ExtraLineInfo(sn, i + pixel_from, d, (data[i] + data[i + 1] + data[i - 1]) / 3));
                            }
                            i += right;
                        }
                    }
                }
            }
            return(ret);
        }