public SpectrCalc(MethodSimple ms, int el_index, int formula_index) { MethodSimpleElement mse = ms.GetElHeader(el_index); Formula = mse.Formula[formula_index]; double ly = (double)Formula.Formula.analitParamCalc.methodLineCalc1.nmLy.Value; bool next = Formula.Formula.analitParamCalc.methodLineCalc1.cbFromSnNum.SelectedIndex == 1; int pr_count = ms.GetProbCount(); for (int pr = 0; pr < pr_count; pr++) { List <Data> prob_data = new List <SpectrCalc.Data>(); MethodSimpleProb msp = ms.GetProbHeader(pr); int sp_count = msp.MeasuredSpectrs.Count; for (int sp = 0; sp < sp_count; sp++) { MethodSimpleCell msc = ms.GetCell(el_index, pr); MethodSimpleCellFormulaResult mscfr = msc.GetData(sp, formula_index); MethodSimpleProbMeasuring mspm = msp.MeasuredSpectrs[sp]; if (mscfr.Enabled) { prob_data.Add(new Data(mspm.Sp, (float)msc.Con, ly, next)); } } DataSet.Add(prob_data); } }
public static List <MethodData> getData(MethodSimple method, int element, int formula, bool use_all, out int used) { MethodSimpleElementFormula msef = method.GetElHeader(element).Formula[formula]; bool[] used_frames = msef.Formula.GetUsedFrames(); List <MethodData> ret = new List <MethodData>(); int prob_count = method.GetProbCount(); used = 0; for (int pr = 0; pr < prob_count; pr++) { MethodSimpleProb m_prob = method.GetProbHeader(pr); MethodSimpleCell m_cell = method.GetCell(element, pr); double con = m_cell.Con; if (con < 0) { continue; } int sub_prob_count = method.GetSubProbCount(pr); for (int sub_pr = 0; sub_pr < sub_prob_count; sub_pr++) { MethodSimpleProbMeasuring m_prob_measuring = m_prob.MeasuredSpectrs[sub_pr]; Spectr sp = m_prob_measuring.Sp; if (sp == null) { continue; } bool en = m_cell.GetData(sub_pr, formula).Enabled; if (use_all == true) { en = true; } int short_count = sp.GetShotCount(); int[] shorts = sp.GetShotIndexes(); for (int short_index = 0; short_index < shorts.Length; short_index++) { bool fl = en & used_frames[short_index]; if (fl) { used++; } MethodData md = new MethodData(con, fl, pr, sub_pr, short_index, sp.GetViewsSet()[shorts[short_index]], sp.GetNullFor(shorts[short_index]), sp.GetCommonDispers()); ret.Add(md); } } } if (ret.Count == 0) { return(null); } return(ret); }
public void Add(MethodSimple method, int prob, int sub_prob) { DateTime now = DateTime.Now; Element[] elem = method.GetElementList(); MethodSimpleProb msp = method.GetProbHeader(prob); for (int el = 0; el < elem.Length; el++) { MethodSimpleCell cell = method.GetCell(el, prob); MethodSimpleElement mse = method.GetElHeader(el); for (int f = 0; f < mse.Formula.Count; f++) { MethodSimpleElementFormula formula = mse.Formula[f]; MethodSimpleCellFormulaResult mscfr = cell.GetData(sub_prob, f); Records.Add(new StandartHistryRecord(mse, f, formula, mscfr, now)); } } Save(); }
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); }
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); } }
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; }
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); } }