Example #1
0
        Spectr Measuring(int sp_num, float common)
        {
            Common.Dev.CheckConnection();

            SpectrCondition cond = new SpectrCondition(Common.Dev.Tick,
                                                       SpectrCondition.GetDefaultCondition(false, false, (float)nmExpFrom.Value, (float)nmExpTo.Value, (float)(nmExpFrom.Value + nmExpTo.Value) * 9, 10));

            Common.Dev.Measuring(cond, null);

            Dispers disp = new Dispers();
            OpticFk fk   = new OpticFk();
            Spectr  sp   = new Spectr(cond, disp, fk, "SensTest");

            for (int i = 0; i < Common.Dev.LetestResult.Count; i++)
            {
                sp.Add(Common.Dev.LetestResult[i]);
            }

            Sp[sp_num] = sp;

            string file_name = GetSpectrName(sp_num);

            Sp[sp_num].SaveAs(file_name);

            Common.Log(Common.MLS.Get(MLSConst, "Done..."));
            return(sp);
        }
Example #2
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();
            }
        }
Example #3
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];
                    }
                }
            }
        }
        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);
        }
Example #5
0
 static double[] AddSpectr(int sn, float[] bas, float[] sig,
                           float[] nul, OpticFk ofk, float max_level_in, double[] k)
 {
     return(AddSpectr(sn, bas, sig, nul, ofk, max_level_in, k, 0));
 }
Example #6
0
        static public SpectrDataView Mix(SpectrDataView[] sigi,
                                         SpectrDataView[] nuli,
                                         OpticFk ofk)
        {
            int sn = sigi[0].GetSensorCount();

            float[][] ret;
            ret = new float[sn][];

            if (sigi.Length == 1)
            {
                return(ofk.GetCorrectedData(sigi[0], nuli[0]));

                /*for (int s = 0; s < sn; s++)
                 * {
                 *  int size = sigi[0].GetSensorSize(s);
                 *  ret[s] = new float[size];
                 *  float[] si = sigi[0].GetSensorData(s);
                 *  float[] nu = nuli[0].GetSensorData(s);
                 *  for (int i = 0; i < size; i++)
                 *      ret[s][i] = (si[i] - nu[i]) * ofk.SensK[s][i];
                 * }*/
            }
            else
            {
                for (int s = 0; s < sn; s++)
                {
                    float[][] sig = new float[sigi.Length][];
                    float[][] nul = new float[sigi.Length][];

                    int      ss                = sigi[0].GetSensorData(s).Length;
                    int[]    calc_order        = new int[sigi.Length];
                    double[] calc_order_levels = new double[sigi.Length];

                    for (int si = 0; si < sigi.Length; si++)
                    {
                        sig[si]        = sigi[si].GetSensorData(s);
                        nul[si]        = nuli[si].GetSensorData(s);
                        calc_order[si] = si;
                        for (int i = 0; i < nul[si].Length; i++)
                        {
                            sig[si][i]             = (float)(sig[si][i]);
                            nul[si][i]             = (float)(nul[si][i]);
                            calc_order_levels[si] += nul[si][i];
                        }
                    }

                    for (int t = 0; t < sigi.Length; t++)
                    {
                        for (int i = 0; i < sigi.Length - 1; i++)
                        {
                            if (calc_order_levels[i] > calc_order_levels[i + 1])
                            {
                                double tmpd = calc_order_levels[i];
                                int    tmpi = calc_order[i];

                                calc_order[i]        = calc_order[i + 1];
                                calc_order_levels[i] = calc_order_levels[i + 1];

                                calc_order[i + 1]        = tmpi;
                                calc_order_levels[i + 1] = tmpd;
                            }
                        }
                    }

                    ret[s] = new float[ss];
                    int order = calc_order[0];
                    for (int i = 0; i < ss; i++)
                    {
                        ret[s][i] = (short)(sig[order][i] - nul[order][i]);
                    }

                    double[] k = null;
                    for (int i = 1; i < calc_order.Length; i++)
                    {
                        k = AddSpectr(s, ret[s], sig[calc_order[i]],
                                      nul[calc_order[i]], ofk,
                                      sigi[0].MaxLinarLevel, k);
                    }
                }
            }
            return(new SpectrDataView(sigi[0].GetCondition(), ret, null, null, 0, 0));
        }
Example #7
0
        static double[] AddSpectr(int sn, float[] bas, float[] sig,
                                  float[] nul, OpticFk ofk, float max_level_in, double[] k,
                                  int call_level)
        {
            bool[]  trusted    = new bool[bas.Length];
            float[] new_sp     = new float[bas.Length];
            int     good_count = 0;
            float   max_level  = max_level_in * 2 / 3;

            for (int i = 0; i < bas.Length; i++)
            {
                if (sig[i] < max_level)
                {
                    good_count++;
                    trusted[i] = true;
                }
                else
                {
                    trusted[i] = false;
                }
                new_sp[i] = ofk.GetCorrectedValue(sn, i, sig, nul, max_level_in);//(sig[i] - nul[i]) * ok[i];
            }

            if (good_count > 20)//sig.Length / 200)
            {
                double[] x  = new double[good_count];
                double[] y  = new double[good_count];
                int      gv = 0;
                for (int i = 0; i < bas.Length; i++)
                {
                    if (sig[i] < max_level)
                    {
                        x[gv] = bas[i];
                        y[gv] = new_sp[i];
                        gv++;
                    }
                }

                k = fk.Interpolation.mInterpol1(x, y);
            }
            else
            {
                if (call_level == 0)
                {
                    return(AddSpectr(sn, bas, sig, nul, ofk, Common.Dev.Reg.GetMaxValue(), k, 1));
                }
                else
                {
                    double[] ret = new double[bas.Length];
                    for (int i = 0; i < ret.Length; i++)
                    {
                        ret[i] = bas[i];
                    }
                    return(ret);
                }
            }

            for (int i = 0; i < bas.Length; i++)
            {
                bool trust = trusted[i];
                if (i > 0)
                {
                    trust &= trusted[i - 1];
                }
                if (i < bas.Length - 1)
                {
                    trust &= trusted[i + 1];
                }
                if (i > 1)
                {
                    trust &= trusted[i - 2];
                }
                if (i < bas.Length - 2)
                {
                    trust &= trusted[i + 2];
                }
                if (trust == false || good_count < sig.Length / 100)
                {
                    //bas[i] = (float)(k[0] + k[1] * bas[i]);
                    bas[i] = (float)(k[1] + k[0] * bas[i]);
                }
                else
                {
                    bas[i] = new_sp[i];
                }
            }

            return(k);
        }