public NulDatas(SpectrConditionCompiledLine line) { Line = line; DevReg.SimpleTimeCorrection(Common.Dev, line.CommonTime, line.Expositions, out CommonTime, out Exps); int common_time = 0; int n = 8; int max_exp = Exps[0]; for (int i = 1; i < Exps.Length; i++) { if (max_exp < Exps[i]) { max_exp = Exps[i]; } } common_time = max_exp * n; while (common_time < CommonTime) { bool is_good = true; for (int i = 0; i < Exps.Length; i++) { if ((common_time % (Exps[i])) != 0) { is_good = false; break; } } if (is_good) { CommonTime = common_time; break; } n++; common_time = max_exp * n; } DbFolder folder = Common.Db.GetFolder(Common.DbNameNulFolder); string record_name = line.CommonTime + "["; for (int i = 0; i < line.Expositions.Length; i++) { if (i != 0) { record_name += " "; } record_name += line.Expositions[i]; } record_name += "]"; Path = folder.GetRecordPath(record_name); Load(); }
private void btUseLinks_Click(object sender, EventArgs e) { try { DialogResult dr = MessageBox.Show(MainForm.MForm, Common.MLS.Get(MLSConst, "Применить матрицу привязок?"),//"Apply new linking matrix?"), Common.MLS.Get(MLSConst, "Новая матрица привязок."), MessageBoxButtons.OKCancel, MessageBoxIcon.Stop); if (dr != DialogResult.OK) { return; } //bool result; ApplyDispersDelProc(); if (ApplyDispResult != 1)//Disp.Compile(tbLinks.Text, true, out result); { MessageBox.Show(MainForm.MForm, Common.MLS.Get(MLSConst, "Ошибка применения матрицы привязок"),//"Apply linking matrix error."), Common.MLS.Get(MLSConst, "Ошибка"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Common.Env.DefaultDisp = Disp; Common.Env.DefaultDispText = (string)tbLinks.Text.Clone(); //string name = (string)clSpList.Items[0]; string name = BaseMatrixName; Spectr sp = new Spectr(Folder, name); DbFolder fl = Common.Db.GetFolder(Common.DbNameSystemFolder); sp.SaveAs(fl.GetRecordPath(Common.DbObjectNamesLinkMatrixFile)); } catch (Exception ex) { Common.Log(ex); } }
protected short[][] MeasuringMonoExp(double common_time, double exp_time, string file_name, Spectr add_to, bool is_on, out string cond, int split_k) { float tick = Common.Dev.Tick; int exp = (int)(exp_time / tick); if (exp < 1) { exp = 1; } int common = (int)(common_time / exp_time) * exp; if (common < exp) { common = exp; } cond = "e:" + (common * tick) + "( "; int[] exps = Common.Dev.Reg.GetSensorSizes(); for (int i = 0; i < exps.Length; i++) { if (i != 0) { cond += ';'; } exps[i] = exp; cond += (exps[i] * tick); } if (is_on) { cond += ")On()"; } else { cond += ")Off()"; } int com_i = common / exp; if (com_i < 1) { com_i = 1; } common = com_i * exp; int tmp = common / split_k; tmp /= exp; if (tmp * exp * split_k != common) { throw new Exception("Системные проблемы. Экспозиция не кратна общему времени..."); } common /= split_k; short[][][] data = new short[split_k][][]; short[][] bs, be; SpectrCondition sp_cond = new SpectrCondition(tick, cond); for (int att = 0; att < split_k; att++) { Common.Dev.Gen.SetStatus(false); //gui.MainForm.MForm.SetupTimeOut(common * tick); Common.Log("Mono exp measuring: " + common + " [" + exp + "]"); //short[][] data[att] = Common.Dev.Reg.RegFrame(common, exps, out bs, out be); //gui.MainForm.MForm.SetupTimeOut(0); } if (split_k > 1) { double[] buf = new double[split_k]; for (int sn = 0; sn < data[0].Length; sn++) { for (int pix = 0; pix < data[0][sn].Length; pix++) { for (int i = 0; i < split_k; i++) { buf[i] = data[i][sn][pix]; } data[0][sn][pix] = (short)SpectroWizard.analit.Stat.GetEver(buf); } } } Spectr sp; DbFolder folder = Common.Db.GetFolder(Common.DbNameTestingFolder); if (add_to == null) { sp = new Spectr(sp_cond, new Dispers(), new OpticFk(), "DevTest"); } else { sp = add_to; } sp.Add(new SpectrDataView(sp_cond, data[0], null, null, Common.Dev.Reg.GetMaxValue(), Common.Dev.Reg.GetMaxLinarValue())); sp.SaveAs(folder.GetRecordPath(file_name)); return(data[0]); }
public override bool RunProc() { try { if (DevTest.DoNotStart == true) { Result = TestState.NoRun; return(true); } Res = GetReportPrefix(); short[][] sig_data = null; //short[][] sig_data1 = null; //short[][] sig_data2 = null; //float common = 1; float test_tick_from = 1; float test_tick = test_tick_from; //Common.Dev.Reg.SetFillLightStatus(true); if (Common.Dev.Fill.Has() == false) { Res += Common.MLS.Get(MLSConst, "В оборудовании нет управляемого источника заливающего света!") + serv.Endl; return(true); } Common.Dev.Fill.SetFillLight(true); System.Threading.Thread.Sleep(1000); float min = float.MaxValue, max = -float.MaxValue, ever = 0; bool found = false; string tmp_cond; while (test_tick >= Common.Dev.Tick * 5) { min = float.MaxValue; max = -float.MaxValue; ever = 0; Common.Log(Common.MLS.Get(MLSConst, "Тестовое измерение ." + test_tick + ":" + test_tick)); sig_data = MeasuringMonoExp(test_tick, test_tick, FileName, null, true, out tmp_cond); for (int s = 0; s < sig_data.Length; s++) { CheckStat(sig_data[s], ref min, ref max, ref ever); } if (max < Common.Dev.Reg.GetMaxLinarValue())// * 0.6) { found = true; break; } else { test_tick = test_tick * 0.9F; } } if (found == false) { Common.Dev.Fill.SetFillLight(false); Res += Common.MLS.Get(MLSConst, "Освититель слишком интенсивный... Тест невозможен...") + serv.Endl; Common.Log(Common.MLS.Get(MLSConst, "Тест не прошёл.")); return(false); } if (test_tick_from == test_tick) { Res += Common.MLS.Get(MLSConst, "Освититель слабоват...") + serv.Endl; Common.Log(Common.MLS.Get(MLSConst, "Освититель слабоват...")); } Res += Common.MLS.Get(MLSConst, "Выбор рабочей экспозиции...") + test_tick + serv.Endl; float test_common = test_tick; while (test_common < 20) /// test_common < 40 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! { test_common = test_common * 2; } float comm_l = test_tick * 16; while (comm_l < 5) { comm_l *= 2; } /*float comm_lh = common * 2; * while (comm_lh < 5) * comm_lh *= 2; * float comm_mh = common * 3; * while (comm_mh < 5) * comm_mh *= 2;*/ float k1 = 10; float k2 = 0.7F; float k3 = 3; Common.Log(Common.MLS.Get(MLSConst, "Измерение заливающего света." + test_common + ":" + test_tick)); sig_data = MeasuringMonoExp(test_common, test_tick, FileName, null, true, out tmp_cond, 8); Common.Log(Common.MLS.Get(MLSConst, "Измерение пониженного заливающего света.")); MeasuringMonoExp(comm_l, test_tick / k1, FileNameCompLow, null, true, out tmp_cond); Common.Log(Common.MLS.Get(MLSConst, "Измерение повышенного заливающего света.")); MeasuringMonoExp(comm_l, test_tick / k2, FileNameCompHi, null, true, out tmp_cond); Res += Common.MLS.Get(MLSConst, "Измерение промежуточного уровня...") + serv.Endl; MeasuringMonoExp(comm_l, test_tick / k3, FileNameCompM, null, true, out tmp_cond); //Common.Dev.Reg.SetFillLightStatus(false); Common.Dev.Fill.SetFillLight(false); System.Threading.Thread.Sleep(1000); DbFolder folder = Common.Db.GetFolder(Common.DbNameTestingFolder); Spectr sp_base = new Spectr(folder, FileName); Spectr sp_l = new Spectr(folder, FileNameCompLow); Spectr sp_h = new Spectr(folder, FileNameCompHi); Spectr sp_m = new Spectr(folder, FileNameCompM); Common.Log(Common.MLS.Get(MLSConst, "Калибровка нуля." + test_common + ":" + test_tick)); MeasuringMonoExp(test_common, test_tick, FileName, sp_base, false, out tmp_cond, 8); Common.Log(Common.MLS.Get(MLSConst, "Калибровка пониженного нуля.")); MeasuringMonoExp(comm_l, test_tick / k1, FileNameCompLow, sp_l, false, out tmp_cond); Common.Log(Common.MLS.Get(MLSConst, "Калибровка повышенного нуля.")); MeasuringMonoExp(comm_l, test_tick / k2, FileNameCompHi, sp_h, false, out tmp_cond); Common.Log(Common.MLS.Get(MLSConst, "Калибровка среднего нуля.")); MeasuringMonoExp(comm_l, test_tick / k3, FileNameCompM, sp_m, false, out tmp_cond); sp_base.OFk.ResetSens(); int[] ss = sp_base.GetCommonDispers().GetSensorSizes(); //float[][] sensK = sp_base.OFk.GetSensKForTesting();// new float[sig_data.Length][]; //sp_base.OFk.SetSensK(sensK); float[][] sensK = new float[ss.Length][]; for (int s = 0; s < sensK.Length; s++) { sensK[s] = new float[ss[s]]; //for(int i = 0;i<sensK[s];i++) float[] y = sp_base.GetDefultView().GetSensorData(s); float[] x = new float[y.Length]; for (int i = 0; i < x.Length; i++) { x[i] = i; } //k[s] = new float[x.Length]; Function fk = new Function(Function.Types.Polinom2, x, y, false, false, 0); double mink = double.MaxValue; double maxk = -double.MaxValue; for (int i = 0; i < x.Length; i++) { sensK[s][i] = (float)(fk.CalcY(i) / y[i]); if (sensK[s][i] < mink) { mink = sensK[s][i]; } if (maxk < sensK[s][i]) { maxk = sensK[s][i]; } } Res += " MinK = " + mink + ", MaxK = " + maxk + serv.Endl; } Common.Env.DefaultOpticFk = new OpticFk();// sp_base.OFk; Common.Env.DefaultOpticFk.SetupK(sensK); Common.Env.Store(); sp_base.OFk.ResetSens(); sp_base.Save(); //SpectrDataView corrected_data = sp_base.OFk.GetCorrectedData(sp_base.GetDefultView()); Spectr rez_sp = new Spectr(sp_base.GetDefultView().GetCondition(), sp_base.GetCommonDispers(), sp_base.OFk, "DevTestSensCalibr"); rez_sp.Add(sp_base.GetViewsSet()[0]);// corrected_data); rez_sp.Add(sp_base.GetViewsSet()[1]); //rez_sp.OFk.ResetSens(); rez_sp.OFk.SetupK(sensK); rez_sp.GetDefultView(); rez_sp.SaveAs(folder.GetRecordPath(FileNameComp)); for (int i = 0; i < 3; i++) { Spectr sp; string file_name; switch (i)//if (i == 0) { case 0: Res += Common.MLS.Get(MLSConst, "Коррекция заниженного спектра...") + serv.Endl; file_name = FileNameCompLow; sp = sp_l; break; case 1: Res += Common.MLS.Get(MLSConst, "Коррекция завышенного спектра...") + serv.Endl; file_name = FileNameCompHi; sp = sp_h; break; case 2: Res += Common.MLS.Get(MLSConst, "Коррекция среднего спектра...") + serv.Endl; file_name = FileNameCompM; sp = sp_m; break; /*case 3: * Res += Common.MLS.Get(MLSConst, "Коррекция исходного спектра...") + serv.Endl; * file_name = FileNameComp; * sp = sp_base; * break;*/ default: throw new Exception("Unexpected spectr index into test"); } //corrected_data = Common.Env.DefaultOpticFk.GetCorrectedData(sp.GetDefultView()); rez_sp = new Spectr(sp_base.GetDefultView().GetCondition(), sp_base.GetCommonDispers(), sp_base.OFk, "DevTestSensCalibr"); rez_sp.Add(sp.GetViewsSet()[0]);// corrected_data); rez_sp.Add(sp.GetViewsSet()[1]); rez_sp.OFk.SetupK(sensK); rez_sp.GetDefultView(); //rez_sp.Add(sp.GetDefultView()); //rez_sp.OFk.SetupK(sensK); rez_sp.SaveAs(folder.GetRecordPath(file_name)); } Common.Log(Common.MLS.Get(MLSConst, "Завершено.")); //sp_base.OFk.ResetSens(); //sp_base.Save(); } catch (Exception ex) { Common.Log(ex); } try { //Common.Dev.Reg.SetFillLightStatus(false); Common.Dev.Fill.SetFillLight(false); } catch (Exception ex) { Common.Log(ex); } return(true); }
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; }