public Data(Spectr sp, float con, double ly, bool from_next) { Sp = sp; Con = con; Dispers disp = sp.GetCommonDispers(); List <int> snl = disp.FindSensors(ly); int sn; if (from_next) { sn = snl[1]; } else { sn = snl[0]; } int pixel = (int)disp.GetLocalPixelByLy(sn, ly); int[] sh_indexes = sp.GetShotIndexes(); Analit = new double[sh_indexes.Length]; Comp = new double[sh_indexes.Length]; List <SpectrDataView> views = sp.GetViewsSet(); for (int i = 0; i < Analit.Length; i++) { float[] sig = views[sh_indexes[i]].GetSensorData(sn); float[] nul = sp.GetNullFor(sh_indexes[i]).GetSensorData(sn); float[] sig_nul = new float[sig.Length]; for (int j = 0; j < sig.Length; j++) { sig_nul[j] = sig[j] - nul[j]; } Analit[i] = CalcAnalit(sig_nul, pixel); } }
bool GetSnNum(List <GLogRecord> log, string log_section, Dispers disp, float max_val, out int sn) { //Dispers disp = sp.GetDispersRO(); List <int> snr = disp.FindSensors((double)nmLy.Value); if (cbFromSnNum.SelectedIndex != 0) { if (snr.Count < 2) { log.Add(new GLogMsg(log_section, Common.MLS.Get(MLSConst, "Предупреждение: Длина волны не на пересечении сенсоров. Ly:") + nmLy.Value, Color.Red)); sn = snr[0]; return(true); } sn = snr[1]; } else { if (snr != null && snr.Count > 0) { sn = snr[0]; } else { sn = -1; return(false); } } return(true); }
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); }
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 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); }
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); }