Beispiel #1
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));
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }
Beispiel #4
0
        public override bool RunProc()
        {
            try
            {
                Shifts = null;
                SensK  = null;

                DbFolder folder  = Common.Db.GetFolder(Common.DbNameSystemFolder);
                Spectr   sp_base = new Spectr(folder, Common.DbObjectNamesLinkMatrixFile);

                folder = Common.Db.GetFolder(Common.DbNameTestingFolder);

                Spectr sp_cur;
                if (DevTest.DoNotStart == false)
                {
                    Common.Dev.Measuring(sp_base.GetMeasuringCondition(), null);
                    sp_cur = Common.Dev.GetLetestDataAsSpectr();
                    string path = folder.GetRecordPath(Common.DbObjectNamesLinkMatrixFile + "_last");
                    sp_cur.SaveAs(path);
                }
                else
                {
                    //string path = folder.GetRecordPath(Common.DbObjectNamesLinkMatrixFile + "_last");
                    sp_cur = new Spectr(folder, Common.DbObjectNamesLinkMatrixFile + "_last");
                }

                Res = GetReportPrefix();
                //Res += Common.MLS.Get(MLSConst, "Спектр промерен и сохранён... ")+serv.Endl;

                int[] ss = Common.Dev.Reg.GetSensorSizes();

                sp_cur.OFk.ResetSens();
                sp_cur.ResetDefaultView();

                SpectrDataView base_view = sp_base.GetDefultView();
                SpectrDataView cur_view  = sp_cur.GetDefultView();
                double[]       shifts    = new double[ss.Length];
                int            max_shift = 800;
                Res += Common.MLS.Get(MLSConst, "Проверка сдвижек на сенсоре:") + serv.Endl + "   ";
                for (int s = Common.Conf.ValidSensorFrom - 1;
                     s < ss.Length && s < Common.Conf.ValidSensorTo;
                     s++)
                {
                    //Res += Common.MLS.Get(MLSConst, "Проверка сдвижек на сенсоре #") + (s + 1);

                    float[] input_data = base_view.GetSensorData(s);
                    float[] hi_base    = SpectrFunctions.FoldingGaus(input_data, 1F, 10);
                    float[] rez_data   = cur_view.GetSensorData(s);
                    float[] hi_rez     = SpectrFunctions.FoldingGaus(rez_data, 1F, 10);

                    double crit  = 0;
                    int    shift = 0;
                    for (int sh = -max_shift; sh <= max_shift; sh++)
                    {
                        double cand = SpectrFunctions.CalcCorel(hi_base, hi_rez, sh, max_shift + 10);
                        if (serv.IsValid(cand) == false || cand < 0 || cand > 32000.0 * 32000.0 * hi_rez.Length)
                        {
                            cand = SpectrFunctions.CalcCorel(hi_base, hi_rez, sh, max_shift + 10);
                            continue;
                        }
                        if (cand > crit)
                        {
                            crit  = cand;
                            shift = sh;
                            SpectroWizard.gui.MainForm.MForm.SetupPersents(100.0 * (s * 1001 + sh) / (ss.Length * 1001));
                        }
                    }
                    shifts[s] = -(shift / 10.0);
                    //Res += Common.MLS.Get(MLSConst, " Значение сдвижки:") + shifts[s];
                    Res += "   " + Math.Round(shifts[s], 1) + "   ";
                    if (Math.Abs(shifts[s]) > max_shift / 20)
                    {
                        Res += Common.MLS.Get(MLSConst, " Слишком много!") + serv.Endl;
                        Res += serv.Endl;
                    }
                }

                Res += serv.Endl;

                for (int i = 0; i < Common.Conf.ValidSensorFrom - 1; i++)
                {
                    shifts[i] = shifts[Common.Conf.ValidSensorFrom - 1];
                }

                for (int i = Common.Conf.ValidSensorTo; i < shifts.Length; i++)
                {
                    shifts[i] = shifts[Common.Conf.ValidSensorTo - 1];
                }

                for (int i = 0; i < shifts.Length; i++)
                {
                    if (Math.Abs(shifts[i]) > max_shift / 20)
                    {
                        Res += Common.MLS.Get(MLSConst, "Слишком большие сдвижки.") + serv.Endl;
                        return(false);
                    }
                }

                for (int i = 2; i < shifts.Length; i += 2)
                {
                    if (Math.Abs(shifts[i] - shifts[i - 2]) > Common.Conf.ValidSensorDiff)
                    {
                        Res += Common.MLS.Get(MLSConst, "Слишком большая разница между сдвижками.") + shifts[i] + " " + shifts[i - 2] +
                               Common.MLS.Get(MLSConst, " Допустимый максимум: ") + Common.Conf.ValidSensorDiff + serv.Endl;
                        return(false);
                    }
                }

                for (int i = 3; i < shifts.Length; i += 2)
                {
                    if (Math.Abs(shifts[i] - shifts[i - 2]) > Common.Conf.ValidSensorDiff)
                    {
                        Res += Common.MLS.Get(MLSConst, "Слишком большая разница между сдвижками.") + shifts[i] + " " + shifts[i - 2] +
                               Common.MLS.Get(MLSConst, " Допустимый максимум: ") + Common.Conf.ValidSensorDiff + serv.Endl;
                        return(false);
                    }
                }

                double[] sensk = new double[ss.Length];
                bool     is_ok = true;
                if (Common.Conf.UseLineAmpl)
                {
                    Res += Common.MLS.Get(MLSConst, "Проверка уровня освещённости сенсоров:") + serv.Endl + "   ";

                    List <SpectrDataView> views = sp_base.GetViewsSet();
                    int[] active_indexes        = sp_base.GetShotIndexes();
                    int   use_view = -1;
                    float use_max  = -1;
                    for (int i = 0; i < active_indexes.Length; i++)
                    {
                        SpectrDataView data = views[active_indexes[i]];
                        if (data.GetCondition().Lines[0].CommonTime > use_max)
                        {
                            use_view = active_indexes[i];
                            use_max  = data.GetCondition().Lines[0].CommonTime;
                        }
                    }

                    SpectrDataView base_sig = views[use_view];
                    SpectrDataView base_nul = sp_base.GetNullFor(use_view);

                    views = sp_cur.GetViewsSet();
                    SpectrDataView cur_sig = views[use_view];
                    SpectrDataView cur_nul = sp_cur.GetNullFor(use_view);

                    for (int s = 0; s < ss.Length; s++)
                    {
                        float[] input_data = base_view.GetSensorData(s);
                        float[] rez_data   = cur_view.GetSensorData(s);

                        //double sens = CheckSensK(input_data, rez_data, s, shifts[s]);
                        double sens = CheckSensK(base_sig, base_nul, cur_sig, cur_nul, s, shifts[s]);
                        if (double.IsNaN(sens))
                        {
                            sens = 1;
                            Res += Common.MLS.Get(MLSConst, "Неполучилось сбалансировать линейку №") + (s + 1) + " " +
                                   Common.MLS.Get(MLSConst, "Причина :") + CheckSensKErrors;
                            Res  += serv.Endl;
                            is_ok = false;
                        }
                        else
                        {
                            //Res += " ";
                            Res += "   " + Math.Round(sens, 3) + "   ";
                        }

                        sensk[s] = sens;
                    }

                    if (is_ok == true)
                    {
                        Res += serv.Endl;
                        StatLineBalansCompiler(ref sensk);
                        //sp_cur.ApplyLineLevelK(sensk);
                        //sp_cur.ResetDefaultView();
                    }//*/
                }
                else
                {
                    //Res += Common.MLS.Get(MLSConst, "Проверка уровней засветок не проводилась т.к. данная опция на включена в конфигурации...") + serv.Endl;
                    for (int s = 0; s < ss.Length; s++)
                    {
                        sensk[s] = 1;
                    }
                }

                Res += serv.Endl;
                //for (int s = 0; s < ss.Length; s++)
                //    sp_cur.GetCommonDispers().ApplyShifts(shifts[s], s);
                sp_cur.ApplySifts(shifts);
                sp_cur.Save();

                if (is_ok == true)
                {
                    Shifts = shifts;
                    SensK  = sensk;
                    Common.Env.Store();
                }
                else
                {
                    return(false);
                }


                return(true);
            }
            catch (Exception ex)
            {
                Common.Log(ex);
                Res += Common.MLS.Get(MLSConst, "Критическая ошибка! ") + ex;
                return(false);
            }
            //return true;
        }