public double RateSpectrDataView(Spectr sp, SpectrDataView sig, SpectrDataView nul)
        {
            if (chbEnabled.Checked == false)
            {
                return(-1);
            }
            List <double> rate = new List <double>();

            for (int i = 0; i < Data.Count; i++)
            {
                double r = Data[i].RateSpectrDataView(sp, sig, nul);
                if (serv.IsValid(r) == false)
                {
                    continue;
                }
                rate.Add(r);
            }
            if (rate.Count == 0)
            {
                return(-1);
            }
            double ever = analit.Stat.GetEver(rate);

            return(ever);
        }
Esempio n. 2
0
        public SpectrDataView GetCorrectedData(SpectrDataView signal_minus_nul)
        {
            int sn = signal_minus_nul.GetSensorCount();

            float[][] rez = new float[sn][];
            for (int s = 0; s < sn; s++)
            {
                float[] data = signal_minus_nul.GetSensorData(s);
                rez[s] = new float[data.Length];
                for (int i = 0; i < data.Length; i++)
                {
                    if (rez[s][i] != float.MaxValue)
                    {
                        rez[s][i] = GetCorrectedValue(s, i, data, signal_minus_nul.MaxLinarLevel);//data[i] * SensK[s][i];
                    }
                }
                //if(use_gaus)
                //    rez[s] = SpectrFunctions.FoldingGaus(0, rez[s].Length, rez[s],
                //            WFk[s], AFk[s], 1);
            }

            return(new SpectrDataView(signal_minus_nul.GetCondition(), rez,
                                      (short)signal_minus_nul.OverloadLevel,
                                      (short)signal_minus_nul.MaxLinarLevel));
        }
Esempio n. 3
0
        private void btSaveAll_Click(object sender, EventArgs e)
        {
            try
            {
                string[] list = Directory.GetFiles(DirToSave, tbFilePrefix.Text + "*.*");
                if (list != null && list.Length != 0)
                {
                    DialogResult dr = MessageBox.Show(MainForm.MForm, "Существуют файлы с такой маской. Продолжать?", "Возможный конфликт",
                                                      MessageBoxButtons.YesNo, MessageBoxIcon.Hand);
                    if (dr != DialogResult.Yes)
                    {
                        return;
                    }
                }
                //for (int i = 0; i < ToSave.Count; i++)
                //    ToSave[i].SaveToFile(DirToSave + "\\" + tbFilePrefix.Text, (ViewElementTypes)cbType.SelectedIndex);
                Dispers disp = Sp.GetCommonDispers();
                SaveFile(DirToSave + "\\" + tbFilePrefix.Text + " спектр для отображения.csv", disp, Sp.OFk, Sp.GetDefultView(), null);
                //SaveFile(DirToSave + "\\" + tbFilePrefix.Text + " спектр для отображения.csv", disp, Sp.GetDefultView(), null);

                int[] indexes            = Sp.GetShotIndexes();
                List <SpectrDataView> vs = Sp.GetViewsSet();
                for (int i = 0; i < indexes.Length; i++)
                {
                    SpectrDataView nul = Sp.GetNullFor(indexes[i]);
                    SpectrDataView sig = vs[indexes[i]];
                    SaveFile(DirToSave + "\\" + tbFilePrefix.Text + " экспозиция " + (i + 1) + ".csv", disp, Sp.OFk, sig, nul);
                }
            }
            catch (Exception ex)
            {
                Common.Log(ex);
            }
        }
Esempio n. 4
0
        static public SpectrDataView Ever(List <SpectrDataView> datas)
        {
            float[][] data_ret = datas[0].GetFullData();
            for (int di = 1; di < datas.Count; di++)
            {
                float[][] data1 = datas[di].GetFullDataNoClone();
                for (int sn = 0; sn < data1.Length; sn++)
                {
                    for (int i = 0; i < data1[sn].Length; i++)
                    {
                        data_ret[sn][i] += data1[sn][i];
                    }
                }
            }
            int n = datas.Count;

            for (int sn = 0; sn < data_ret.Length; sn++)
            {
                for (int i = 0; i < data_ret[sn].Length; i++)
                {
                    data_ret[sn][i] /= n;
                }
            }
            SpectrDataView ret = new SpectrDataView(datas[0].GetCondition(),
                                                    data_ret, null, null,
                                                    (short)datas[0].OverloadLevel,
                                                    (short)datas[0].MaxLinarLevel);

            return(ret);
        }
Esempio n. 5
0
 public MethodData(double con, bool en, int prob_index, int sub_prob_index, int frame_index,
                   SpectrDataView data_view_sig, SpectrDataView data_view_nul,
                   Dispers disp)
 {
     Con          = con;
     Disp         = disp;
     En           = en;
     ProbIndex    = prob_index;
     SubProbIndex = sub_prob_index;
     FrameIndex   = frame_index;
     DataViewSig  = data_view_sig;
     DataViewNull = data_view_nul;
     float[][] nul = DataViewNull.GetFullDataNoClone();
     float[][] sig = DataViewSig.GetFullDataNoClone();
     DataMinusNull = new float[nul.Length][];
     for (int s = 0; s < nul.Length; s++)
     {
         int len = nul[s].Length;
         DataMinusNull[s] = new float[len];
         for (int i = 0; i < len; i++)
         {
             DataMinusNull[s][i] = sig[s][i] - nul[s][i];
         }
     }
 }
Esempio n. 6
0
        public Spectr GetCorrectedSpectr(Spectr nul, Spectr sig)
        {
            Spectr sp = new Spectr(sig.GetMeasuringCondition(), new Dispers(), new OpticFk(), "SensTest");

            short[][] data;
            int[]     ss = sig.GetCommonDispers().GetSensorSizes();
            data = new short[ss.Length][];

            List <SpectrDataView> vnul = nul.GetViewsSet();
            List <SpectrDataView> vsig = sig.GetViewsSet();

            for (int s = 0; s < ss.Length; s++)
            {
                data[s] = new short[ss[s]];
                for (int i = 0; i < ss[s]; i++)
                {
                    data[s][i] = (short)(GetK(vnul, vsig, s, i) * K[s][i]);
                }
            }

            SpectrDataView view = new SpectrDataView(sig.GetMeasuringCondition(), data, short.MaxValue, short.MaxValue);

            sp.Add(view);

            return(sp);
        }
Esempio n. 7
0
        private void btnTest_Click(object sender, EventArgs e)
        {
            try
            {
                String   base_path   = "Тестовые измерения спектров\\Ire 30-20-10-0\\";
                String[] t_names     = { "m20_", "m10_", "0_", "10_", "20_", "30_" };
                String[] exp_names   = { " 0,5c", " 1c", " 2c", " 4c" };
                int[]    exp_index_f = { 2, 3, 4, 5 };
                int[]    exp_index_s = { 10, 11, 12, 13 };
                for (int exp_index = 0; exp_index < exp_index_f.Length; exp_index++)
                {
                    for (int temp = 0; temp < t_names.Length; temp++)
                    {
                        for (int sp_index = 1; sp_index <= 8; sp_index++)
                        {
                            try
                            {
                                String path = base_path + t_names[temp] + sp_index;
                                Spectr sp   = new Spectr(path);
                                List <SpectrDataView> dv    = sp.GetViewsSet();
                                SpectrDataView        view1 = dv[exp_index_f[exp_index]];
                                SpectrDataView        view2 = dv[exp_index_s[exp_index]];
                                float[] data1 = getData(view1);
                                float[] data2 = getData(view2);

                                float sko1, sko2;
                                LevelTestResult[exp_index, temp, (sp_index - 1) * 2]              = testCalcLevel(data1, out sko1, out sko2);
                                LevelTestResultSKOAnalog[exp_index, temp, (sp_index - 1) * 2]     = sko1;
                                LevelTestResultSKOSignal[exp_index, temp, (sp_index - 1) * 2]     = sko2;
                                LevelTestResult[exp_index, temp, (sp_index - 1) * 2 + 1]          = testCalcLevel(data2, out sko1, out sko2);
                                LevelTestResultSKOAnalog[exp_index, temp, (sp_index - 1) * 2 + 1] = sko1;
                                LevelTestResultSKOSignal[exp_index, temp, (sp_index - 1) * 2 + 1] = sko2;

                                NoiseTestResult[exp_index, temp, (sp_index - 1)] = testCalcNoise(data1, data2);

                                StepsTestResult[exp_index, temp, (sp_index - 1) * 2]     = testCalcSteps(data1);
                                StepsTestResult[exp_index, temp, (sp_index - 1) * 2 + 1] = testCalcSteps(data2);
                            }
                            catch (Exception ex)
                            {
                                Common.Log(ex);
                                return;
                            }
                        }
                    }
                }
                saveAsCSV("подставка", exp_names, LevelTestResult, 4, 6, 16);
                saveAsCSV("подставка СКО ацп", exp_names, LevelTestResultSKOAnalog, 4, 6, 16);
                saveAsCSV("подставка СКО шума", exp_names, LevelTestResultSKOSignal, 4, 6, 16);
                saveAsCSV("шум", exp_names, NoiseTestResult, 4, 6, 8);
                saveAsCSV("ступеньки", exp_names, StepsTestResult, 4, 6, 16);
            }
            catch (Exception ex)
            {
                Common.Log(ex);
            }
        }
        public double[] RateSpectr(Spectr sp)
        {
            int[]    shot_index       = sp.GetShotIndexes();
            double[] ret              = new double[shot_index.Length];
            List <SpectrDataView> spv = sp.GetViewsSet();

            for (int i = 0; i < ret.Length; i++)
            {
                SpectrDataView sig = spv[shot_index[i]];
                SpectrDataView nul = sp.GetNullFor(shot_index[i]);
                ret[i] = RateSpectrDataView(sp, sig, nul);
            }
            return(ret);
        }
Esempio n. 9
0
        static public SpectrDataView Add(SpectrDataView sdv1, SpectrDataView sdv2)
        {
            float[][] data1 = sdv1.GetFullData();
            float[][] data2 = sdv2.GetFullDataNoClone();
            for (int sn = 0; sn < data1.Length; sn++)
            {
                for (int i = 0; i < data1[sn].Length; i++)
                {
                    data1[sn][i] = (data1[sn][i] + data2[sn][i]) / 2;
                }
            }
            SpectrDataView ret = new SpectrDataView(sdv1.GetCondition(), data1,
                                                    (short)sdv1.OverloadLevel, (short)sdv1.MaxLinarLevel);

            return(ret);
        }
Esempio n. 10
0
        List <double> HasLine(int sn, double ly, Dispers disp, int plus_minus, out double ly_real, out List <float[]> data)
        {
            int prob_count = Method.GetProbCount();
            //double ret = 0;
            int n_ret = 0;

            ly_real = 0;
            List <double> ret = new List <double>();

            data = new List <float[]>();
            for (int pr = 0; pr < prob_count; pr++)
            {
                MethodSimpleProb msp = Method.GetProbHeader(pr);
                for (int spr = 0; spr < msp.MeasuredSpectrs.Count; spr++)
                {
                    MethodSimpleProbMeasuring pm = msp.MeasuredSpectrs[spr];
                    if (pm.Sp == null)
                    {
                        continue;
                    }
                    SpectrDataView sdv      = pm.Sp.GetDefultView();
                    double         tmp      = 0;
                    double         ly_cur   = 0;
                    float[]        data_cur = null;
                    try
                    {
                        tmp = CheckLine(sn, ly, sdv.GetFullDataNoClone(), disp, plus_minus, out ly_cur, out data_cur);
                    }
                    catch
                    {
                    }
                    if (tmp == 0)
                    {
                        ly_real = -1;
                        data    = null;
                        return(null);
                    }
                    ly_real += ly_cur;
                    ret.Add(tmp);
                    data.Add(data_cur);
                    n_ret++;
                }
            }
            ly_real /= n_ret;
            return(ret);// / n_ret;
        }
        public double RateSpectrDataView(Spectr sp, SpectrDataView sig, SpectrDataView nul)
        {
            if (Enabled == false)
            {
                return(-1);
            }
            List <GLogRecord>     log   = new List <GLogRecord>();
            List <SpectrDataView> sig_l = new List <SpectrDataView>();

            sig_l.Add(sig);
            List <SpectrDataView> nul_l = new List <SpectrDataView>();

            nul_l.Add(nul);
            List <double> analit = new List <double>();
            List <double> aq     = new List <double>();
            //bool is_too_low = false;
            CalcLineAtrib attr = new CalcLineAtrib();
            bool          rez  = Params.Calc(log, LogSectionName, "",
                                             //null,
                                             sig_l, nul_l, sp,
                                             analit, aq, ref attr, false);

            if (rez == false)
            {
                return(-1);
            }
            if (analit[0] == 0 ||
                serv.IsValid(analit[0]) == false)
            {
                return(-1);
            }
            double lim;

            if (analit[0] > AnalitEver)
            {
                lim = AnalitTo;
            }
            else
            {
                lim = AnalitFrom;
            }
            return(Math.Abs(analit[0] - AnalitEver) /
                   Math.Abs(AnalitEver - lim));
        }
Esempio n. 12
0
        public SpectrDataView GetCorrectedData(SpectrDataView signal,
                                               SpectrDataView nul)
        {
            float[][] data      = new float[signal.GetSensorCount()][];
            float     max_level = signal.MaxLinarLevel;

            for (int s = 0; s < data.Length; s++)
            {
                float[] tsig = signal.GetSensorData(s);
                float[] tnul = nul.GetSensorData(s);
                data[s] = new float[signal.GetSensorSize(s)];
                for (int i = 0; i < data[s].Length; i++)
                {
                    data[s][i] = GetCorrectedValue(s, i, tsig, tnul, max_level);
                }
            }
            SpectrDataView s_minus_nul = new SpectrDataView(signal.GetCondition(),
                                                            data, (short)signal.OverloadLevel, (short)signal.MaxLinarLevel);

            return(s_minus_nul);// GetCorrectedData(s_minus_nul, use_gaus);
        }
Esempio n. 13
0
        //0-empty-14 15-blank-28 29-signal-3676 3677-blank-3690
        float[] getData(SpectrDataView view)
        {
            short[] start = view.BlankStart[0];
            short[] end   = view.BlankEnd[0];
            float[] data  = view.GetFullDataNoClone()[0];
            float[] res   = new float[4096];
            int     ind   = 0;

            for (int i = 0; i < start.Length; i++, ind++)
            {
                res[ind] = start[i];
            }
            for (int i = 0; i < data.Length; i++, ind++)
            {
                res[ind] = data[i];
            }
            for (int i = 0; i < end.Length; i++, ind++)
            {
                res[ind] = end[i];
            }
            return(res);
        }
Esempio n. 14
0
 public ViewElementData(SpectrDataView spv, string description, string fsufix, Dispers disp, int sn)
 {
     if (spv.BlankStart != null)
     {
         BlankStart = new float[spv.BlankStart[sn].Length];
         for (int i = 0; i < BlankStart.Length; i++)
         {
             BlankStart[i] = spv.BlankStart[sn][i];
         }
         //BlankStartFFT = GetFFT(BlankStart);
     }
     if (spv.BlankEnd != null)
     {
         BlankEnd = new float[spv.BlankEnd[sn].Length];
         for (int i = 0; i < BlankEnd.Length; i++)
         {
             BlankEnd[i] = spv.BlankEnd[sn][i];
         }
         //BlankEndFFT = GetFFT(BlankEnd);
     }
     Init(spv.GetSensorData(sn), description, fsufix, disp, sn);
     //DtFFT = GetFFT(Dt);
 }
Esempio n. 15
0
        double CheckSensK(SpectrDataView etalon_sig, SpectrDataView etalon_nul,
                          SpectrDataView cur_sig, SpectrDataView cur_nul,
                          int sn, double shifts)
        {
            float[] esig_data = etalon_sig.GetSensorData(sn);
            float[] enul_data = etalon_nul.GetSensorData(sn);

            float[] csig_data = cur_sig.GetSensorData(sn);
            float[] cnul_data = cur_nul.GetSensorData(sn);

            float[] etalon = new float[esig_data.Length];
            float[] cur    = new float[esig_data.Length];

            for (int i = 0; i < etalon.Length; i++)
            {
                etalon[i] = esig_data[i] - enul_data[i];
                cur[i]    = csig_data[i] - cnul_data[i];
            }

            float[] etalon_hi = SpectrFunctions.FoldingGaus(etalon, 1F, 10);
            float[] cur_hi    = SpectrFunctions.FoldingGaus(cur, 1F, 10);
            return(CheckSensK(etalon_hi, cur_hi, sn, shifts * 10));//*/
            //return CheckSensK(etalon, cur, sn, shifts);
        }
Esempio n. 16
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); }
        }
Esempio n. 17
0
        public void CollectDataMiner(List <SpectrDataView> data, SpectrCondition cond)
        {
            float max_level = Common.Conf.MaxLevel;

            int[] line_sizes   = Reg.GetSensorSizes();
            int[] orientations = Common.Conf.USBOrientationVals;
            int   line_size;

            if (line_sizes[0] > 3048)
            {
                line_size = 4096;
            }
            else
            {
                line_size = 2048;
            }
            for (int step = 0; step < cond.Lines.Count; step++)
            {
                if (cond.Lines[step].Type == SpectrCondition.CondTypes.Exposition)
                {
                    /*byte[] bbuffer = new byte[4096 * 2 * 15];
                     * short[] bbuffer_sub_count = new short[4096 * 2 * 15];
                     * FileStream fs = new FileStream("data" + cond.Lines[step].TmpInteger, FileMode.Open, FileAccess.Read);
                     * int size = fs.Read(bbuffer, 0, bbuffer.Length);
                     * fs.Close();
                     *
                     * short[] sbuffer = new short[size / 2];
                     * for (int i = 0; i < size; i += 2)
                     * {
                     *  short val = (short)(bbuffer[i + 1] & 0xFF);
                     *  if (val > 0xF)
                     *      throw new Exception("Val is too big");
                     *  val <<= 8;
                     *  val |= (short)(bbuffer[i] & 0xFF);
                     *  sbuffer[i / 2] = val;
                     * }*/

                    FileStream fs                   = new FileStream("data" + cond.Lines[step].TmpInteger, FileMode.Open, FileAccess.Read);
                    long[]     sbuffer              = new long[15 * line_size];
                    short[]    sbuffer_counter      = new short[sbuffer.Length];
                    short[]    sbuffer_fill_counter = new short[15];
                    bool[]     sbuffer_fill_flag    = new bool[15];
                    byte[]     bbuffer              = new byte[line_size * 2];
                    do
                    {
                        int size = fs.Read(bbuffer, 0, bbuffer.Length);
                        if (size == 0)
                        {
                            break;
                        }
                        if (size != bbuffer.Length)
                        {
                            throw new Exception("Can't load full data...");
                        }
                        for (int i = 0; i < bbuffer.Length; i += 2)
                        {
                            short val = (short)(bbuffer[i + 1] & 0xF);
                            val <<= 8;
                            val  |= (short)(bbuffer[i] & 0xFF);
                            if (val < 0)
                            {
                                throw new Exception("Negative value");
                            }
                            int sn = (bbuffer[i + 1] >> 4);
                            sbuffer_fill_flag[sn] = true;
                            int index = line_size * sn + sbuffer_fill_counter[sn];
                            sbuffer[index] += val;
                            if (sbuffer[index] < 0)
                            {
                                throw new Exception("Negative value");
                            }
                            sbuffer_counter[index]++;
                            sbuffer_fill_counter[sn]++;
                            if (sbuffer_fill_counter[sn] >= line_size)
                            {
                                sbuffer_fill_counter[sn] = 0;
                            }
                        }
                    } while (true);
                    fs.Close();
                    for (int i = 0; i < sbuffer.Length; i++)
                    {
                        if (sbuffer_counter[i] > 0)
                        {
                            sbuffer[i] /= sbuffer_counter[i];
                        }
                        else
                        {
                            sbuffer[i] = -1;
                        }
                    }
                    int sbuffer_shift = 0;
                    for (int s = 0; s < 15; s++)
                    {
                        if (sbuffer_fill_flag[s] == false)
                        {
                            sbuffer_shift += line_size;
                        }
                        else
                        {
                            if (sbuffer_shift == 0)
                            {
                                continue;
                            }
                            int from = s * line_size;
                            int to   = from - sbuffer_shift;
                            for (int i = 0; i < line_size; i++)
                            {
                                sbuffer[to + i] = sbuffer[from + i];
                            }
                        }
                    }

                    //if (size < 4096 * line_sizes.Length)
                    //    throw new Exception("No data for expoistion " + step + "-" + cond.Lines[step].TmpInteger);

                    float[][] line_data     = new float[line_sizes.Length][];
                    short[][] bb            = new short[line_sizes.Length][];
                    short[][] be            = new short[line_sizes.Length][];
                    int[]     index_in_data = new int[line_sizes.Length];
                    for (int i = 0; i < orientations.Length; i++)
                    {
                        index_in_data[i] = (int)Math.Abs(orientations[i]) - 1;
                    }
                    for (int i = 0; i < index_in_data.Length; i++)
                    {
                        bool found = false;
                        for (int j = 1; j < index_in_data.Length; j++)
                        {
                            if (index_in_data[j - 1] > index_in_data[j])
                            {
                                int tmp = index_in_data[j - 1];
                                index_in_data[j - 1] = index_in_data[j];
                                index_in_data[j]     = tmp;
                                found = true;
                            }
                        }
                        if (found == false)
                        {
                            break;
                        }
                    }
                    for (int li = 0; li < line_sizes.Length; li++)
                    {
                        int l  = 0;
                        int or = (int)Math.Abs(orientations[li]) - 1;
                        for (int i = 0; i < orientations.Length; i++)
                        {
                            if (or == index_in_data[i])
                            {
                                l = i;
                                break;
                            }
                        }
                        int orient = orientations[li];
                        int index;
                        int beg_blank_size, end_blank_size;
                        if (orient < 0)
                        {
                            beg_blank_size = Common.Conf.BlakPixelEnd;
                            end_blank_size = Common.Conf.BlakPixelStart;
                        }
                        else
                        {
                            end_blank_size = Common.Conf.BlakPixelEnd;
                            beg_blank_size = Common.Conf.BlakPixelStart;
                        }
                        index = l;
                        int     pos = index * 4096;
                        short[] rez = new short[4096];
                        for (int i = 0; i < 4096; i++)
                        {
                            short val = (short)sbuffer[pos + i];
                            if (orient > 0)
                            {
                                rez[i] = val;//(short)sbuffer[pos + i];
                            }
                            else
                            {
                                rez[4095 - i] = val;//(short)sbuffer[pos + i];
                            }
                        }
                        int base_level = 0, bl = 0;
                        for (int i = 0; i < 15; i++, bl++)
                        {
                            base_level += (short)sbuffer[pos + i];
                        }
                        base_level /= bl;
                        int blank_level = 0;
                        bl = 0;
                        for (int i = 17; i < 28; i++, bl++)
                        {
                            blank_level += (short)sbuffer[pos + i];
                        }
                        blank_level /= bl;
                        int ever = blank_level - base_level + 10;
                        line_data[li] = new float[4096 - end_blank_size - beg_blank_size];
                        bb[li]        = new short[beg_blank_size];
                        be[li]        = new short[end_blank_size];
                        int ind;
                        //int collect_to;
                        //if(beg_blank_size
                        for (ind = 0; ind < beg_blank_size; ind++)
                        {
                            bb[li][ind] = rez[ind];
                        }
                        int index_from = ind;
                        for (; ind < 4096 - end_blank_size; ind++)
                        {
                            line_data[li][ind - index_from] = rez[ind];
                        }
                        index_from = ind;
                        for (; ind < 4096; ind++)
                        {
                            be[li][ind - index_from] = rez[ind];
                        }
                        if (Common.Conf.BlankSub == false)
                        {
                            ever = 0;
                        }
                        for (int i = 0; i < line_data[li].Length; i++)
                        {
                            if (line_data[li][i] > max_level)
                            {
                                line_data[li][i] = max_level + 1;
                            }
                            else
                            {
                                line_data[li][i] = line_data[li][i] - ever;//*/
                            }
                            if (line_data[li][i] < 0)
                            {
                                throw new Exception("Negative value...");
                            }
                        }
                    }
                    SpectrDataView cur_spview = new SpectrDataView(new SpectrCondition(Tick, cond.Lines[step]), line_data, bb, be,
                                                                   Common.Dev.Reg.GetMaxValue(),
                                                                   Common.Dev.Reg.GetMaxLinarValue());
                    data.Add(cur_spview);
                }
            }
        }
Esempio n. 18
0
        private void btCallectSpaces_Click(object sender, EventArgs e)
        {
            try
            {
                EmptySpaces.Clear();
                //ExceptionLy.Clear();
                Dispers d        = null;
                int     pr_count = Method.GetProbCount();
                int[]   ss       = Common.Dev.Reg.GetSensorSizes();
                int[][] founds   = new int[ss.Length][];
                for (int i = 0; i < ss.Length; i++)
                {
                    founds[i] = new int[ss[i]];
                }
                int side = (int)nmMinLineWidth.Value / 2;
                for (int pr = 0; pr < pr_count; pr++)
                {
                    MethodSimpleProb msp = Method.GetProbHeader(pr);
                    int sp_count         = msp.MeasuredSpectrs.Count;
                    for (int sp = 0; sp < sp_count; sp++)
                    {
                        MethodSimpleProbMeasuring mspm = msp.MeasuredSpectrs[sp];
                        Spectr spectr = mspm.Sp;
                        if (spectr.IsEmpty())
                        {
                            continue;
                        }
                        int[] view = mspm.Sp.GetShotIndexes();
                        List <SpectrDataView> views = mspm.Sp.GetViewsSet();
                        int sum = side * 2 + 2;
                        for (int vi = 0; vi < view.Length; vi++)
                        {
                            SpectrDataView cur_view  = views[view[vi]];
                            float          max_level = cur_view.MaxLinarLevel;
                            SpectrDataView nul_view  = mspm.Sp.GetNullFor(view[vi]);
                            d = spectr.GetCommonDispers();//cur_view.GetDispersRO();
                            for (int sn = 0; sn < ss.Length; sn++)
                            {
                                float[] sig  = cur_view.GetSensorData(sn);
                                float[] nul  = nul_view.GetSensorData(sn);
                                float[] data = new float[sig.Length];
                                for (int pix = 0; pix < data.Length; pix++)
                                {
                                    data[pix] = sig[pix] - nul[pix];
                                }
                                int   len = ss[sn] - 10;
                                float min = 0;
                                for (int pix = 0; pix < 10; pix++)
                                {
                                    min += data[pix];
                                }
                                for (int pix = 0; pix < len; pix++)
                                {
                                    float tmp = 0;
                                    for (int j = pix; j < pix + 10; j++)
                                    {
                                        tmp += data[j];
                                    }
                                    if (tmp < min)
                                    {
                                        min = tmp;
                                    }
                                }
                                len  = ss[sn] - side - 3;
                                min /= 10;
                                min *= 3;
                                int left  = 0;
                                int right = 0;
                                for (int pix = side + 3; pix < len; pix++)
                                {
                                    if (isLine(data, len + side + 1, pix, max_level, side, sum, ref left, ref right))
                                    {
                                        for (int i = pix - left; i <= pix + right; i++)
                                        {
                                            founds[sn][i]++;
                                        }
                                        pix += right;
                                    }
                                }
                            }
                        }
                    }
                }

                for (int sn = 0; sn < ss.Length; sn++)
                {
                    int margin_before = (int)nmMargine.Value;
                    int len           = 0;
                    int pix_from      = 0;
                    for (int pix = 0; pix < ss[sn]; pix++)
                    {
                        if (founds[sn][pix] <= 1 && pix < ss[sn] - 1)
                        {
                            if (margin_before > 0)
                            {
                                margin_before--;
                                pix_from = pix;
                            }
                            else
                            {
                                len++;
                            }
                        }
                        else
                        {
                            len -= (int)nmMargine.Value;
                            if (len >= nmMinFreeSpaceSize.Value)
                            {
                                float[] es = { 1,                             (float)d.GetLyByLocalPixel(sn, pix_from),
                                               (float)d.GetLyByLocalPixel(sn, pix - (int)nmMargine.Value),   len };
                                EmptySpaces.Add(es);
                            }
                            margin_before = (int)nmMargine.Value;
                            len           = 0;
                        }
                    }
                }

                ReInitList();
            }
            catch (Exception ex)
            {
                Common.Log(ex);
            }
        }
Esempio n. 19
0
        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);
        }
Esempio n. 20
0
        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);
        }
Esempio n. 21
0
        public bool CalcBackGround(List <GLogRecord> log,
                                   string log_section,
                                   string log_prefix,
                                   //Spectr ly_spectr,
                                   SpectrDataView sig,
                                   SpectrDataView nul,
                                   Spectr spectr,
                                   out double analit,
                                   out double err)
        {
            analit = 0;
            err    = 0;

            int sn;

            if (GetSnNum(log, log_section, spectr.GetCommonDispers(),
                         sig.MaxLinarLevel, out sn) == false)
            {
                log.Add(new GLogMsg(log_section,
                                    Common.MLS.Get(MLSConst, "Не корректная длина волны."),
                                    Color.Black));
                return(false);
            }

            Function fk;

            bool[] mask;
            sig.GetBackGroundFunction(sn, out fk, out mask);
            float[] sg = sig.GetSensorData(sn);
            if (fk == null)
            {
                #region calc backgound region level
                double  max_level = sig.MaxLinarLevel * 0.5;
                float[] sg_plav   = sig.GetSensorData(sn);
                float[] nl        = nul.GetSensorData(sn);

                for (int i = 0; i < sg.Length; i++)
                {
                    if (sg[i] < max_level)
                    {
                        sg[i] -= nl[i];
                    }
                    else
                    {
                        sg[i] = float.MaxValue;
                    }
                }

                for (int i = 3; i < sg.Length - 3; i++)
                {
                    if (sg[i] < float.MaxValue &&
                        sg[i + 1] < float.MaxValue &&
                        sg[i - 1] < float.MaxValue)
                    {
                        sg_plav[i] = (sg[i] + sg[i - 1] + sg[i + 1] + sg[i - 2] + sg[i + 2]) / 5;
                    }
                }

                bool[] flags = new bool[sg_plav.Length];
                for (int i = 1; i < sg.Length - 1; i++)
                {
                    flags[i] = true;
                }
                for (int i = 2; i < sg.Length - 2; i++)
                {
                    if (sg[i] == float.MaxValue ||
                        sg[i - 1] == float.MaxValue ||
                        sg[i + 1] == float.MaxValue ||
                        sg[i - 2] == float.MaxValue ||
                        sg[i + 2] == float.MaxValue)
                    {
                        flags[i - 2] = false;
                        flags[i - 1] = false;
                        flags[i]     = false;
                        flags[i + 1] = false;
                        flags[i + 2] = false;
                        continue;
                    }
                    if (sg_plav[i] > sg_plav[i + 1] &&
                        sg_plav[i] > sg_plav[i - 1] &&
                        sg_plav[i + 1] > sg_plav[i + 2] &&
                        sg_plav[i - 1] > sg_plav[i - 2])
                    {
                        for (int j = i; j < sg.Length - 1 && sg_plav[j] > sg_plav[j + 1]; j++)
                        {
                            flags[j] = false;
                        }
                        for (int j = i; j > 1 && sg_plav[j] > sg_plav[j - 1]; j--)
                        {
                            flags[j] = false;
                        }
                    }
                }
                for (int i = 1; i < sg.Length; i++)
                {
                    if (flags[i - 1] == false && flags[i] == true)
                    {
                        flags[i] = false;
                        i++;
                    }
                }
                for (int i = 1; i < sg.Length; i++)
                {
                    if (flags[i - 1] == true && flags[i] == false)
                    {
                        flags[i - 1] = true;
                        i++;
                    }
                }
                int count = 0;
                for (int i = 3; i < sg.Length - 3; i++)
                {
                    if (flags[i])
                    {
                        int from = i;
                        for (int j = 0; i < sg.Length && flags[i] && j < 4; i++, j++)
                        {
                            ;
                        }
                        int to  = i - 1;
                        int len = to - from;
                        if (len <= 2)
                        {
                            for (int j = from; j <= to; j++)
                            {
                                flags[j] = false;
                            }
                        }
                        i--;
                    }
                }

                for (int i = 3; i < sg.Length - 3; i++)
                {
                    if (flags[i])
                    {
                        count++;
                    }
                }

                double[] pixel = new double[count];
                double[] val   = new double[count];
                count = 0;
                for (int i = 3; i < sg.Length - 3; i++)
                {
                    if (flags[i])
                    {
                        pixel[count] = i;
                        val[count]   = sg[i];
                        count++;
                    }
                }
                fk   = new Function(Function.Types.Polinom3, pixel, val, false, false, 1);
                mask = flags;
                sig.SetBackGroundFunction(sn, fk, mask);
                #endregion
            }

            //Dispers disp = ly_spectr.GetCommonDispers();
            Dispers disp = spectr.GetCommonDispers();
            int[]   ss   = disp.GetSensorSizes();

            /*double ly_from = disp.GetLyByLocalPixel(sn,40);
             * double ly_to = disp.GetLyByLocalPixel(sn,ss[sn]-40);
             * disp = spectr.GetCommonDispers();// sig.GetDispersRO();
             * int pixel_from = (int)disp.GetLocalPixelByLy(sn,ly_from);
             * int pixel_to = (int)disp.GetLocalPixelByLy(sn,ly_to);*/
            int    pixel_from = 5;
            int    pixel_to   = ss[sn] - 5;
            double ever       = 0;
            double sko        = 0;
            int    sko_num    = 0;
            for (int i = pixel_from; i <= pixel_to; i++)
            {
                double val = fk.CalcY(i);
                ever += val;
                if (mask[i])
                {
                    double tmp = sg[i] - val;
                    sko += tmp * tmp;
                    sko_num++;
                }
            }

            ever  /= (pixel_to - pixel_from + 1);
            sko   /= sko_num;
            sko    = Math.Sqrt(sko) * 100 / ever;
            analit = ever;
            err    = sko;

            log.Add(new GLogMsg(log_section,
                                Common.MLS.Get(MLSConst, "Уровень фона=") + ever +
                                Common.MLS.Get(MLSConst, " с СКО=") + sko,
                                Color.Black));

            return(true);
        }
Esempio n. 22
0
        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);
        }
Esempio n. 23
0
        void SaveFile(string file_name, Dispers disp, OpticFk ofk, SpectrDataView sig, SpectrDataView nul)
        {
            string separator = "; ", endl = serv.Endl;

            if (cbType.SelectedIndex == 0)
            {
                separator = "; ";
            }
            else
            {
                separator = ", ";
            }
            string tmp = "id" + separator +
                         " ccd" + separator +
                         " pixel" + separator +
                         " vpixel" + separator +
                         " signal" + separator +
                         " null" + separator +
                         " ly" + separator +
                         " sens_k" + separator + endl;

            int[]   sn, vpix, pix;
            float[] sigd, nuld, sens;

            GetData(sig, disp, ofk, out sn, out pix, out vpix, out sigd, out sens);
            if (nul != null)
            {
                GetData(nul, disp, ofk, out sn, out pix, out vpix, out nuld, out sens);
            }
            else
            {
                nuld = null;
            }

            FileStream fs = new FileStream(file_name, FileMode.OpenOrCreate, FileAccess.Write);

            try
            {
                fs.SetLength(0);

                byte[] buf = Encoding.ASCII.GetBytes(tmp);
                fs.Write(buf, 0, buf.Length);

                for (int i = 0; i < sn.Length; i++)
                {
                    tmp  = "" + (i + 1) + separator;
                    tmp += (sn[i] + 1) + separator;
                    tmp += pix[i] + separator;
                    tmp += vpix[i] + separator;
                    tmp += sigd[i] + separator;
                    if (nuld != null)
                    {
                        tmp += nuld[i] + separator;
                    }
                    else
                    {
                        tmp += "0" + separator;
                    }
                    tmp += disp.GetLyByLocalPixel(sn[i], vpix[i]) + separator;
                    tmp += sens[i] + separator;
                    tmp += endl;

                    buf = Encoding.ASCII.GetBytes(tmp);
                    fs.Write(buf, 0, buf.Length);
                }
                fs.Flush();
            }
            finally
            {
                fs.Close();
            }
        }
Esempio n. 24
0
        public void CollectData(List <SpectrDataView> data, SpectrCondition cond)
        {
            float max_level = Common.Conf.MaxLevel;

            byte[] bbuffer      = new byte[4096 * 2 * 15];
            int[]  line_sizes   = Reg.GetSensorSizes();
            int[]  orientations = Common.Conf.USBOrientationVals;
            for (int step = 0; step < cond.Lines.Count; step++)
            {
                if (cond.Lines[step].Type == SpectrCondition.CondTypes.Exposition)
                {
                    FileStream fs   = new FileStream("data" + cond.Lines[step].TmpInteger, FileMode.Open, FileAccess.Read);
                    int        size = fs.Read(bbuffer, 0, bbuffer.Length);
                    fs.Close();

                    short[] sbuffer = new short[size / 2];
                    for (int i = 0; i < size; i += 2)
                    {
                        short val = (short)(bbuffer[i + 1] & 0xFF);
                        if (val > 0xF)
                        {
                            throw new Exception("Val is too big");
                        }
                        val          <<= 8;
                        val           |= (short)(bbuffer[i] & 0xFF);
                        sbuffer[i / 2] = val;
                    }

                    /*int ever = 0;
                     * for(int i = 0;i<4096;i++)
                     *  ever += sbuffer[i];
                     * ever /= 4096;//*/

                    if (size < 4096 * line_sizes.Length)
                    {
                        throw new Exception("No data for expoistion " + step + "-" + cond.Lines[step].TmpInteger);
                    }

                    float[][] line_data     = new float[line_sizes.Length][];
                    short[][] bb            = new short[line_sizes.Length][];
                    short[][] be            = new short[line_sizes.Length][];
                    int[]     index_in_data = new int[line_sizes.Length];
                    for (int i = 0; i < orientations.Length; i++)
                    {
                        index_in_data[i] = (int)Math.Abs(orientations[i]) - 1;
                    }
                    for (int i = 0; i < index_in_data.Length; i++)
                    {
                        bool found = false;
                        for (int j = 1; j < index_in_data.Length; j++)
                        {
                            if (index_in_data[j - 1] > index_in_data[j])
                            {
                                int tmp = index_in_data[j - 1];
                                index_in_data[j - 1] = index_in_data[j];
                                index_in_data[j]     = tmp;
                                found = true;
                            }
                        }
                        if (found == false)
                        {
                            break;
                        }
                    }
                    for (int li = 0; li < line_sizes.Length; li++)
                    {
                        int l  = 0;
                        int or = (int)Math.Abs(orientations[li]) - 1;
                        for (int i = 0; i < orientations.Length; i++)
                        {
                            if (or == index_in_data[i])
                            {
                                l = i;
                                break;
                            }
                        }
                        int orient = orientations[li];
                        int index;
                        int beg_blank_size, end_blank_size;
                        if (orient < 0)
                        {
                            //index = -orient;
                            beg_blank_size = Common.Conf.BlakPixelEnd;
                            end_blank_size = Common.Conf.BlakPixelStart;
                        }
                        else
                        {
                            //index = orient;
                            end_blank_size = Common.Conf.BlakPixelEnd;
                            beg_blank_size = Common.Conf.BlakPixelStart;
                        }
                        index = l;
                        //index--;
                        int     pos = index * 4096;
                        short[] rez = new short[4096];
                        for (int i = 0; i < 4096; i++)
                        {
                            //short val = (short)(buffer[pos+i+1]&0xFF);
                            //val <<= 8;
                            //val |= (short)((buffer[pos+i])&0xFF);
                            if (orient > 0)
                            {
                                rez[i] = sbuffer[pos + i];
                            }
                            else
                            {
                                rez[4095 - i] = sbuffer[pos + i];
                            }
                        }
                        int base_level = 0, bl = 0;
                        for (int i = 0; i < 15; i++, bl++)
                        {
                            base_level += sbuffer[pos + i];
                        }
                        base_level /= bl;
                        int blank_level = 0;
                        bl = 0;
                        for (int i = 17; i < 28; i++, bl++)
                        {
                            blank_level += sbuffer[pos + i];
                        }
                        blank_level /= bl;
                        int ever = blank_level - base_level + 10;
                        line_data[li] = new float[4096 - end_blank_size - beg_blank_size];
                        bb[li]        = new short[beg_blank_size];
                        be[li]        = new short[end_blank_size];
                        int ind;
                        //int collect_to;
                        //if(beg_blank_size
                        for (ind = 0; ind < beg_blank_size; ind++)
                        {
                            bb[li][ind] = rez[ind];
                        }
                        int index_from = ind;
                        for (; ind < 4096 - end_blank_size; ind++)
                        {
                            line_data[li][ind - index_from] = rez[ind];
                        }
                        index_from = ind;
                        for (; ind < 4096; ind++)
                        {
                            be[li][ind - index_from] = rez[ind];
                        }

                        /*short[] to_sum;
                         * int to_sum_from = 0;
                         * if (be[li].Length < 100)//> 400)
                         * {
                         *  to_sum = be[li];
                         *  to_sum_from = to_sum.Length - 18;//50;
                         * }
                         * else
                         * {
                         *  to_sum = bb[li];
                         *  to_sum_from = 0;
                         * }
                         * int ever = 0;
                         * /*for (int i = 0; i < 18; i++)
                         *  ever += to_sum[i + to_sum_from];
                         * ever /= 18;*/
                        if (Common.Conf.BlankSub == false)
                        {
                            ever = 0;
                        }
                        for (int i = 0; i < line_data[li].Length; i++)
                        {
                            if (line_data[li][i] > max_level)
                            {
                                line_data[li][i] = max_level + 1;
                            }
                            else
                            {
                                line_data[li][i] = line_data[li][i] - ever;//*/
                            }
                        }
                    }
                    SpectrDataView cur_spview = new SpectrDataView(new SpectrCondition(Tick, cond.Lines[step]), line_data, bb, be,
                                                                   Common.Dev.Reg.GetMaxValue(),
                                                                   Common.Dev.Reg.GetMaxLinarValue());
                    data.Add(cur_spview);
                }
            }
        }
Esempio n. 25
0
        private void btSeachStart_Click(object sender, EventArgs e)
        {
            try
            {
                tbLog.Text = "";
                Log("Поиск линий...");
                int prc = Method.GetProbCount();
                //List<int> found_sn = new List<int>();
                //List<double> found_ly = new List<double>();
                List <SpectrData> found_lines = new List <SpectrData>();
                Dispers           disp        = null;
                for (int pr = 0; pr < prc; pr++)
                {
                    MethodSimpleProb msp = Method.GetProbHeader(pr);
                    int sprc             = msp.MeasuredSpectrs.Count;
                    for (int spr = 0; spr < sprc; spr++)
                    {
                        if (msp.MeasuredSpectrs[spr].Sp != null)
                        {
                            disp = msp.MeasuredSpectrs[spr].Sp.GetCommonDispers();
                            break;
                        }
                    }
                }
                int[] ss   = disp.GetSensorSizes();
                int   step = (int)(numMinWidth.Value / 2);
                for (int sn = 0; sn < ss.Length; sn++)
                {
                    double prev_found_ly = 0;
                    for (int p = 15; p < ss[sn] - 15; p += step)
                    {
                        double         ly;
                        List <float[]> spectr_data = null;
                        List <double>  vals        = HasLine(sn, disp.GetLyByLocalPixel(sn, p), disp, step, out ly, out spectr_data);
                        if (vals == null)
                        {
                            continue;
                        }
                        if (Math.Abs(prev_found_ly - ly) < 0.1)
                        {
                            continue;
                        }
                        found_lines.Add(new SpectrData(sn, ly, vals, spectr_data));
                        prev_found_ly = ly;
                    }
                }
                Log("Найдено " + found_lines.Count + " линий.");
                for (int i = 0; i < found_lines.Count - 1; i++)
                {
                    if (found_lines[i].Value.Count != found_lines[i + 1].Value.Count)
                    {
                        for (i = 0; i < found_lines.Count - 3; i++)
                        {
                            if (found_lines[i].Value.Count == found_lines[i + 1].Value.Count &&
                                found_lines[i + 1].Value.Count == found_lines[i + 2].Value.Count &&
                                found_lines[i + 2].Value.Count == found_lines[i + 3].Value.Count)
                            {
                                int real_num = found_lines[i].Value.Count;
                                int skipped  = 0;
                                for (i = 0; i < found_lines.Count - 3; i++)
                                {
                                    if (found_lines[i].Value.Count == real_num)
                                    {
                                        found_lines.RemoveAt(i);
                                        i--;
                                        skipped++;
                                    }
                                }
                                Log("Отбраковано по количеству " + skipped + " линий.");
                                break;
                            }
                        }
                        break;
                    }
                }

                //List<ProbInfo> pairs = new List<ProbInfo>();
                MethodSimpleElementFormula msef = Method.GetElHeader(Element).Formula[Formula];
                msef.Formula.Founds.Clear();
                msef.Formula.Pairs.Clear();
                bool[] used          = msef.Formula.GetUsedFrames();
                int[]  used_to_index = new int[used.Length];
                int    to_index      = 0;
                // формируем массив пересчёта индекса в массиве отношений в номер кадра
                for (int i = 0; i < used_to_index.Length; i++)
                {
                    if (used[i] == false)
                    {
                        continue;
                    }
                    used_to_index[to_index] = i;
                    to_index++;
                }
                for (int pr = 0; pr < prc; pr++)
                {
                    MethodSimpleCell msc = Method.GetCell(Element, pr);
                    MethodSimpleProb msp = Method.GetProbHeader(pr);
                    int sub_prob_count   = msp.MeasuredSpectrs.Count;
                    for (int sub_prob_i = 0; sub_prob_i < sub_prob_count; sub_prob_i++)
                    {
                        if (msp.MeasuredSpectrs[sub_prob_i].Sp != null)
                        {
                            MethodSimpleProbMeasuring     mspm  = msp.MeasuredSpectrs[sub_prob_i];
                            MethodSimpleCellFormulaResult mscfr = msc.GetData(sub_prob_i, Formula);
                            if (mscfr.Enabled == false)
                            {
                                continue;
                            }
                            double ever_analit = 0;
                            for (int i = 0; i < mscfr.ReCalcCon.Length; i++)
                            {
                                ever_analit += mscfr.AnalitValue[i];
                            }
                            ever_analit /= mscfr.AnalitValue.Length;
                            List <SpectrDataView> data = msp.MeasuredSpectrs[sub_prob_i].Sp.GetViewsSet();
                            int[] active_sp            = msp.MeasuredSpectrs[sub_prob_i].Sp.GetShotIndexes();
                            for (int i = 0; i < mscfr.AnalitValue.Length; i++)
                            {
                                //pr, spr, used_to_index[i],
                                SpectrDataView sig = data[active_sp[used_to_index[i]]];
                                SpectrDataView nul = msp.MeasuredSpectrs[sub_prob_i].Sp.GetNullFor(active_sp[used_to_index[i]]);
                                float[][]      d   = msp.MeasuredSpectrs[sub_prob_i].Sp.OFk.GetCorrectedData(sig, nul).GetFullDataNoClone();
                                msef.Formula.Pairs.Add(new ProbInfo(pr, sub_prob_i, used_to_index[i], ever_analit, mscfr.AnalitValue[i],
                                                                    d, msp.MeasuredSpectrs[sub_prob_i].Sp.GetCommonDispers()));
                            }
                        }
                    }
                }
                Log("Сформирован список из " + msef.Formula.Pairs.Count + " отклонений от среднего.");
                string tmp      = (string)tbLog.Text.Clone();
                int    ps_max   = found_lines.Count * (found_lines.Count / 2 - 1);
                int    ps_count = 0;
                for (int i = 0; i < found_lines.Count; i++)
                {
                    for (int j = i + 1; j < found_lines.Count; j++)
                    {
                        if (chTheSameLine.Checked && found_lines[i].Sn != found_lines[j].Sn)
                        {
                            continue;
                        }
                        CorellFounds rez;
                        try
                        {
                            rez = Corel(msef.Formula.Pairs, found_lines[i].Ly, found_lines[i].Sn, found_lines[j].Ly, found_lines[j].Sn);
                            if (rez.CorellAbs > 0.1)
                            {
                                bool inserted = false;
                                for (int k = 0; k < msef.Formula.Founds.Count; k++)
                                {
                                    if (rez.CorellAbs > msef.Formula.Founds[k].CorellAbs)
                                    {
                                        msef.Formula.Founds.Insert(k, rez);
                                        inserted = true;
                                        break;
                                    }
                                }
                                if (inserted == false)
                                {
                                    msef.Formula.Founds.Add(rez);
                                }
                                while (msef.Formula.Founds.Count > 80)
                                {
                                    msef.Formula.Founds.RemoveAt(msef.Formula.Founds.Count - 1);
                                }
                            }
                            if (msef.Formula.Founds.Count > 0)
                            {
                                tbLog.Text = "Проверено " + Math.Round(ps_count * 100.0 / ps_max, 1) + "% пар... K=" +
                                             msef.Formula.Founds[0].Corell + serv.Endl + tmp;
                            }
                            else
                            {
                                tbLog.Text = "Проверено " + Math.Round(ps_count * 100.0 / ps_max, 1) + "% пар..." +
                                             serv.Endl + tmp;
                            }
                            tbLog.Refresh();
                        }
                        catch (Exception ex)
                        {
                        }
                        ps_count++;
                    }
                }
                tbLog.Text = tmp;
                if (msef.Formula.Founds.Count == 0)
                {
                    Log("Поиск зависимостей завершён.Зависимостей нет.");
                }
                else
                {
                    Log("Поиск зависимостей завершён.Максимальный коэффициент корелляции = " +
                        msef.Formula.Founds[0].Corell);
                }
                InitList();//*/
            }
            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);
        }
Esempio n. 27
0
        void ShearchThread()
        {
            try
            {
                lbSearchResult.Enabled = false;
                List <int> sn_list = new List <int>();
                //float x, y;
                //List<float> pixt;
                List <int> snt;

                Dispers disp = Sp.GetCommonDispers();
                int[]   ss   = disp.GetSensorSizes();

                Results.Clear();
                bool is_line = cbGraphType.SelectedIndex == 0;
                switch (cbSearchType.SelectedIndex)
                {
                case 0:
                    snt = disp.FindSensors((float)Formula.Formula.analitParamCalc.methodLineCalc1.nmLy.Value);
                    if (Formula.Formula.analitParamCalc.methodLineCalc1.cbFromSnNum.SelectedIndex == 0)
                    {
                        sn_list.Add(snt[0]);
                    }
                    else
                    {
                        sn_list.Add(snt[1]);
                    }
                    break;

                case 1:
                    for (int i = 0; i < ss.Length; i++)
                    {
                        if ((i % 2) != 0)
                        {
                            sn_list.Add(i);
                        }
                    }
                    break;

                case 2:
                    for (int i = 0; i < ss.Length; i++)
                    {
                        if ((i % 2) == 0)
                        {
                            sn_list.Add(i);
                        }
                    }
                    break;

                case 3:
                    for (int i = 0; i < ss.Length; i++)
                    {
                        sn_list.Add(i);
                    }
                    break;
                }


                SimpleFormulaEditor.Setup(ElementName, Formula.Formula,
                                          Method, Spv, ElementIndex, SelectedCol);

                int redraw_count = 0;
                //DelRecalcFormula frd = new DelRecalcFormula(DelRecalcFormulaProc);

                MaxSize = 0;
                for (int s_index = 0; s_index < sn_list.Count; s_index++)
                {
                    MaxSize += ss[sn_list[s_index]] - 60;
                }
                Passed = 0;
                SpectrDataView def_viwe = Sp.GetDefultView();
                for (int s_index = 0; s_index < sn_list.Count && Visible && Th != null && Common.IsRunning; s_index++)
                {
                    SpectrCalc calc = new SpectrCalc(Method, ElementIndex, SelectedCol);
                    calc.InitData(sn_list[s_index]);
                    //Thread.Sleep(10);
                    int sn = sn_list[s_index];
                    CurrentSN = sn;

                    float[] data = def_viwe.GetSensorData(sn);
                    for (int pix = 30; pix < ss[sn] - 30; pix++)
                    {
                        if (analit.SpectrFunctions.IsPick(data, pix, Common.Conf.MaxLevel) == false)
                        {
                            continue;
                        }
                        CurrentPix = pix;
                        float ly = (float)disp.GetLyByLocalPixel(sn, pix);

                        double     sko = calc.CalcSKO(pix, is_line);
                        CalcResult cr  = new CalcResult(ly, sn, sko, pix);
                        if (Results.Count == 0)
                        {
                            Results.Add(cr);
                        }
                        else
                        {
                            bool added = false;
                            for (int i = 0; i < Results.Count; i += 100)
                            {
                                if (Results[i].SKO > sko || i + 100 >= Results.Count)
                                {
                                    int ifrom = i - 100;
                                    if (ifrom < 0)
                                    {
                                        ifrom = 0;
                                    }
                                    int ito = i + 10;
                                    if (ito >= Results.Count)
                                    {
                                        ito = Results.Count;
                                    }
                                    for (i = ifrom; i < ito; i++)
                                    {
                                        if (Results[i].SKO > sko)
                                        {
                                            Results.Insert(i, cr);
                                            added = true;
                                            break;
                                        }
                                    }
                                    //Results.Insert(i, cr);
                                    //added = true;
                                    break;
                                }
                            }

                            if (added == false && Results.Count < 2000)
                            {
                                Results.Add(cr);
                            }
                            while (Results.Count > 2000)
                            {
                                Results.RemoveAt(Results.Count - 1);
                            }
                        }
                        if ((redraw_count % 100) == 0)
                        {
                            This.Invoke(new MethodInvoker(UpdateLb));
                        }
                        redraw_count++;
                        Passed++;
                        pix += 3;
                    }
                    for (int i = 0; i < Results.Count; i++)
                    {
                        int pixel = Results[i].Pixel;
                        int s     = Results[i].Sn;
                        for (int j = i + 1; j < Results.Count; j++)
                        {
                            if (s == Results[j].Sn && Math.Abs(pixel - Results[j].Pixel) < 10)
                            {
                                Results.RemoveAt(j);
                                j--;
                            }
                        }
                    }
                }

                This.Invoke(new MethodInvoker(UpdateLb));

                MemoryStream ms = new MemoryStream();
                BinaryWriter bw = new BinaryWriter(ms);
                bw.Write(1);
                bw.Write(Results.Count);
                for (int i = 0; i < Results.Count; i++)
                {
                    Results[i].Save(bw);
                }
                bw.Flush();
                Formula.Formula.SeachBuffer = ms.GetBuffer();
            }
            catch (Exception ex)
            {
                Common.Log(ex);
            }
            finally
            {
                This.Invoke(new MethodInvoker(AfterThread));
            }
        }
        public void Calc(MethodSimple method)
        {
            int pr_count = method.GetProbCount();

            Params.ResetMinLineValues();
            List <double> div = new List <double>();

            for (int pri = 0; pri < pr_count; pri++)
            {
                MethodSimpleProb pr = method.GetProbHeader(pri);
                int sp_count        = pr.MeasuredSpectrs.Count;
                for (int spri = 0; spri < sp_count; spri++)
                {
                    MethodSimpleProbMeasuring prm = pr.MeasuredSpectrs[spri];
                    int[] shot_index          = prm.Sp.GetShotIndexes();
                    List <SpectrDataView> spv = prm.Sp.GetViewsSet();
                    for (int spi = 0; spi < shot_index.Length; spi++)
                    {
                        SpectrDataView sig = spv[shot_index[spi]];
                        SpectrDataView nul = prm.Sp.GetNullFor(shot_index[spi]);

                        List <SpectrDataView> sig_l = new List <SpectrDataView>();
                        sig_l.Add(sig);
                        List <SpectrDataView> nul_l = new List <SpectrDataView>();
                        nul_l.Add(nul);

                        List <double> analit1 = new List <double>();
                        List <double> aq1     = new List <double>();
                        //bool is_too_low = false;
                        CalcLineAtrib attr = new CalcLineAtrib();
                        bool          rez  = Params.Calc(Log, LogSectionName, "",
                                                         //null,
                                                         sig_l, nul_l, prm.Sp,
                                                         analit1, aq1, ref attr, true);
                        if (rez == false)
                        {
                            continue;
                        }
                        if (analit1[0] == 0 ||
                            serv.IsValid(analit1[0]) == false)
                        {
                            continue;
                        }

                        div.Add(analit1[0]);
                    }
                }
            }
            AnalitEver = (float)analit.Stat.GetEver(div);
            if (analit.Stat.LastGoodSKO == 0)
            {
                Sko = (float)analit.Stat.LastSKO;
            }
            else
            {
                Sko = (float)analit.Stat.LastGoodSKO;
            }
            float k = (float)Math.Sqrt(2);

            AnalitFrom = AnalitEver - Sko * k;
            AnalitTo   = AnalitEver + Sko * k;
        }
Esempio n. 29
0
        void GetData(SpectrDataView data, Dispers disp, OpticFk fk,
                     out int[] sn, out int[] pixel, out int[] vpixel, out float[] signal, out float[] sens)
        {
            int[]     ss   = disp.GetSensorSizes();
            float[][] vals = data.GetFullDataNoClone();
            int       len  = 0;

            for (int s = 0; s < ss.Length; s++)
            {
                if (data.BlankStart != null)
                {
                    len += data.BlankStart[s].Length;
                }
                if (data.BlankEnd != null)
                {
                    len += data.BlankEnd[s].Length;
                }
                len += vals[s].Length;
            }

            sn     = new int[len];
            pixel  = new int[len];
            vpixel = new int[len];
            signal = new float[len];
            sens   = new float[len];

            int ind = 0;

            for (int s = 0; s < ss.Length; s++)
            {
                int pix  = 0;
                int vpix = 0;
                int l;
                if (data.BlankStart != null)
                {
                    l = data.BlankStart[s].Length;
                    for (int i = 0; i < l; i++, ind++, pix++)
                    {
                        sn[ind]     = s;
                        pixel[ind]  = pix;
                        vpixel[ind] = -1;
                        sens[ind]   = 1;
                        signal[ind] = data.BlankStart[s][i];
                    }
                }
                l = vals[s].Length;
                for (int i = 0; i < l; i++, ind++, pix++, vpix++)
                {
                    sn[ind]     = s;
                    pixel[ind]  = pix;
                    vpixel[ind] = vpix;
                    signal[ind] = vals[s][i];
                    sens[ind]   = 1;//fk.SensK[s][i];
                }
                if (data.BlankEnd != null)
                {
                    l = data.BlankEnd[s].Length;
                    for (int i = 0; i < l; i++, ind++, pix++)
                    {
                        sn[ind]     = s;
                        pixel[ind]  = pix;
                        vpixel[ind] = -1;
                        sens[ind]   = 1;
                        signal[ind] = data.BlankEnd[s][i];
                    }
                }
            }
        }
Esempio n. 30
0
        void MeasuringTech()
        {
            try
            {
                Reg.NullMeasuringEnabled = false;
                while (Reg.NullMeasuring == true && Common.IsRunning)
                {
                    Thread.Sleep(10);
                }
                if (Common.IsRunning == false)
                {
                    return;
                }
                SpectrCondition       cond = Cond;
                List <SpectrDataView> ret  = new List <SpectrDataView>();
                CheckConnection();
                BeforeMeasuring();

                int   common_time_i = 1;
                int[] exps_i;

                if (IsUSBConsole())
                {
                    int[]  line_sizes      = Reg.GetSensorSizes();
                    float  time_step       = Common.Conf.MinTick * (Common.Conf.Divider2 + 1);
                    string program         = "n" + line_sizes.Length + ";s4096;d" + Common.Conf.Divider2 + ";";
                    int    measuring_index = 0;
                    cond.saveExtra(Common.Env.DefaultDisp);
                    int[] orientations = Common.Conf.USBOrientationVals;
                    for (int i = 0; i < cond.Lines.Count; i++)
                    {
                        switch (cond.Lines[i].Type)//SpectrCondition.ParseStringType(line))
                        {
                        case SpectrCondition.CondTypes.FillLight:
                            Fill.SetFillLight(cond.Lines[i].IsFillLight);
                            break;

                        case SpectrCondition.CondTypes.Comment: break;

                        case SpectrCondition.CondTypes.Empty: break;

                        case SpectrCondition.CondTypes.Unexpected: break;

                        case SpectrCondition.CondTypes.Prespark:
                            program += "p" + cond.Lines[i].CommonTime + ";";
                            break;

                        case SpectrCondition.CondTypes.Exposition:
                            CorrectExposition(cond.Lines[i], out common_time_i, out exps_i);
                            cond.Lines[i].TmpInteger = measuring_index;
                            if (cond.Lines[i].IsGenOn)
                            {
                                program += "E";
                            }
                            else
                            {
                                program += "e";
                            }
                            program += cond.Lines[i].TmpInteger + "_" + common_time_i + "_";
                            int[] exps = new int[16];
                            for (int ei = 0; ei < exps.Length && ei < orientations.Length; ei++)
                            {
                                if (exps_i[ei] > 255)
                                {
                                    throw new Exception("Exposition is too bit!");
                                }
                                exps[(int)Math.Abs(orientations[ei]) - 1] = exps_i[ei];
                            }
                            for (int l = 0; l < 16; l++)
                            {
                                program += exps[l] + " ";
                                //if (l < exps_i.Length)
                                //    program += exps_i[l] + " ";
                                //else
                                //    program += "0 ";
                            }
                            program += ";";
                            measuring_index++;
                            break;
                        }
                    }
                    FileStream fs    = new FileStream("cur_prog.txt", FileMode.Create);
                    byte[]     array = Encoding.ASCII.GetBytes(program);
                    fs.Write(array, 0, array.Length);
                    fs.Flush();
                    fs.Close();

                    //Process proc = Process.Start("USBDataCollector.exe", "cur_prog.txt");
                    //Process proc = Process.Start("USBMiner.exe", "cur_prog.txt");
                    //Process proc = Process.Start("measuring.bat");
                    System.Diagnostics.ProcessStartInfo proc = new System.Diagnostics.ProcessStartInfo("measuring.bat");

                    proc.RedirectStandardOutput = false;
                    proc.UseShellExecute        = false;

                    // Do not create the black window.
                    proc.CreateNoWindow = true;
                    proc.WindowStyle    = ProcessWindowStyle.Hidden;

                    System.Diagnostics.Process process = new System.Diagnostics.Process();
                    process.StartInfo = proc;
                    process.Start();

                    process.WaitForExit();
                    int exit_code = process.ExitCode;

                    if (exit_code != 0)
                    {
                        throw new Exception("Measuring error: " + exit_code);
                    }

                    //((USBConDev)this).CollectDataMiner(ret, cond); //uncomment if use USBDataCollector.exe
                    ((USBConDev)this).CollectDataMiner(ret, cond);
                }
                else
                {
                    string source = cond.SourceCode;
                    int    i      = 0;
                    //string line = SpectrCondition.GetLine(source, ref i);
                    int[]          ssize = Reg.GetSensorSizes();
                    double[]       exps  = new double[ssize.Length];
                    float[][]      data;
                    short[][]      datas;
                    SpectrDataView cur_spview;
                    for (i = 0; i < cond.Lines.Count; i++)//(line != null)
                    {
                        if (Aborted || Common.CancelFlag == true)
                        {
                            try { Common.Dev.Gen.SetStatus(false); }
                            catch { }
                            return;
                        }
                        try
                        {
                            gui.MainForm.MForm.SetupPersents(i * 100 / cond.Lines.Count);
                            switch (cond.Lines[i].Type)//SpectrCondition.ParseStringType(line))
                            {
                            case SpectrCondition.CondTypes.FillLight:
                                Fill.SetFillLight(cond.Lines[i].IsFillLight);
                                break;

                            case SpectrCondition.CondTypes.Comment: break;

                            case SpectrCondition.CondTypes.Empty: break;

                            case SpectrCondition.CondTypes.Unexpected: break;

                            case SpectrCondition.CondTypes.Prespark:
                                Common.Log(Common.MLS.Get("Dev", "Start prespark. ") + cond.Lines[i].CommonTime);
                                //gui.MainForm.MForm.SetupTimeOut(cond.Lines[i].CommonTime);

                                /*common_time_i = (int)(cond.Lines[i].CommonTime / Tick);
                                 * exps_i = new int[exps.Length];
                                 * for (int j = 0; j < exps.Length; j++)
                                 *  exps_i[j] = 1;*/
                                exps_i = null;
                                for (int t = 0; t < cond.Lines.Count; t++)
                                {
                                    if (cond.Lines[t].IsActive && cond.Lines[t].Expositions != null)
                                    {
                                        CorrectExposition(cond.Lines[i].CommonTime, cond.Lines[t].Expositions,
                                                          out common_time_i, out exps_i);
                                        break;
                                    }
                                }
                                Gen.SetStatus(true);
                                Reg.RegFrame(common_time_i, exps_i);
                                break;

                            case SpectrCondition.CondTypes.Exposition:
                                bool nul;
                                CorrectExposition(cond.Lines[i], out common_time_i, out exps_i);
                                string msg;
                                if (cond.Lines[i].IsActive)
                                {
                                    msg = Common.MLS.Get("Dev", "Spark. ");
                                    nul = false;
                                }
                                else
                                {
                                    msg = Common.MLS.Get("Dev", "Null. ");
                                    nul = true;
                                }
                                msg += +common_time_i + " [ ";
                                for (int j = 0; j < exps_i.Length; j++)
                                {
                                    msg += exps_i[j] + " ";
                                }
                                msg += "] " + Math.Round(cond.Lines[i].CommonTime, 2);
                                Common.Log(msg);

                                //gui.MainForm.MForm.SetupTimeOut(cond.Lines[i].CommonTime);
                                Gen.SetStatus(cond.Lines[i].IsGenOn);
                                short[][] bb, ba;
                                if (nul == false)
                                {
                                    datas = Reg.RegFrame(common_time_i, exps_i, out bb, out ba);
                                }
                                else
                                {
                                    datas = Reg.GetNull(cond.Lines[i], out bb, out ba);
                                }

                                data = new float[datas.Length][];
                                for (int s = 0; s < datas.Length; s++)
                                {
                                    int size = datas[s].Length;
                                    data[s] = new float[size];
                                    for (int j = 0; j < size; j++)
                                    {
                                        data[s][j] = datas[s][j];
                                    }
                                }
                                cur_spview = new SpectrDataView(new SpectrCondition(Tick, cond.Lines[i]), data, bb, ba,
                                                                Common.Dev.Reg.GetMaxValue(),
                                                                Common.Dev.Reg.GetMaxLinarValue());
                                ret.Add(cur_spview);
                                break;
                            }
                        }
                        catch (Exception ex)
                        {
                            Common.Log(ex);
                            break;
                        }
                    }
                    Gen.SetStatus(false);
                }
                AfterMeasuring();
                LetestResult = ret;
                if (FinalCall != null)
                {
                    FinalCall(ret, Cond);
                }
                //gui.MainForm.MForm.SetupTimeOut(0);
                gui.MainForm.MForm.SetupPersents(-1);
            }
            catch (Exception ex)
            {
                Common.Log(ex);
            }
            finally
            {
                try
                {
                    Reg.NullMeasuringEnabled = true;
                    gui.MainForm.MForm.SetupTimeOut(0);
                }
                catch
                {
                }
                try
                {
                    FinalCall = null;
                    //gui.MainForm.MForm.Enabled = true;
                    gui.MainForm.MForm.EnableToolExit();
                }
                catch
                {
                }
                try
                {
                    Reg.Reset();
                }
                catch (Exception ex)
                {
                    Common.LogNoMsg(ex);
                }
            }
        }