public static TempSpec Sum(TempSpec spec1, TempSpec spec2, double rv1, double rv2) { if (spec1.Length != spec2.Length) { return(null); } TempSpec specSum = new TempSpec(spec1.Length); LinInterpolator li1 = new LinInterpolator(spec1.lambs, spec1.norm_intes); LinInterpolator li2 = new LinInterpolator(spec2.lambs, spec2.norm_intes); LinInterpolator liCont1 = new LinInterpolator(spec1.lambs, spec1.cont); LinInterpolator liCont2 = new LinInterpolator(spec2.lambs, spec2.cont); double lambda1 = spec1.Lambdas[0]; double lambda2 = spec1.Lambdas[spec1.Length - 1]; double dlambda = (lambda2 - lambda1) / spec1.Length; double c = 299792.458; double lambda, cont1, cont2; for (int i = 0; i < specSum.Length; i++) { lambda = lambda1 + i * dlambda; specSum.lambs[i] = lambda; cont1 = liCont1.InterpUni(lambda - lambda * rv1 / c); cont2 = liCont2.InterpUni(lambda - lambda * rv2 / c); specSum.cont[i] = cont1 + cont2; specSum.norm_intes[i] = (li1.InterpUni(lambda - lambda * rv1 / c) * cont1 + li2.InterpUni(lambda - lambda * rv2 / c) * cont2) / specSum.cont[i]; } return(specSum); }
public TempSpec RVShift(double rv) { TempSpec specRes = new TempSpec(this.lambs.Length); double c = 299792.458; for (int i = 0; i < specRes.Length; i++) { specRes.lambs[i] = this.lambs[i] + this.lambs[i] * rv / c; specRes.norm_intes[i] = norm_intes[i]; specRes.cont[i] = cont[i]; } return(specRes); }
private void btnStart_Click(object sender, EventArgs e) { int oo, ox, grading_step; try { oo = int.Parse(txtOrderO.Text, System.Globalization.CultureInfo.InvariantCulture); ox = int.Parse(txtOrderX.Text, System.Globalization.CultureInfo.InvariantCulture); grading_step = int.Parse(txtGradingStep.Text, System.Globalization.CultureInfo.InvariantCulture); } catch { MessageBox.Show("Some error in input parameters...", "Error..."); return; } if (this.lambds == null) { MessageBox.Show("Load observed spectra...", "Error..."); return; } this.cont = null; this.files = null; if (rbTemplate.Checked) { if (rbCompTwo.Checked) { double rv1, rv2; try { rv1 = double.Parse(txtRV1.Text.Replace(",", "."), System.Globalization.CultureInfo.InvariantCulture); rv2 = double.Parse(txtRV2.Text.Replace(",", "."), System.Globalization.CultureInfo.InvariantCulture); } catch { MessageBox.Show("Some error in RV1 or RV2 fields...", "Error..."); return; } try { tspec1 = new TempSpec(txtTemplate1.Text); } catch { MessageBox.Show("Cannot load Template 1 file...", "Error..."); return; } try { tspec2 = new TempSpec(txtTemplate2.Text); } catch { MessageBox.Show("Cannot load Template 2 file...", "Error..."); return; } tspec = TempSpec.Sum(tspec1, tspec2, rv1, rv2); } else { double rv; try { rv = double.Parse(txtRV1.Text.Replace(",", "."), System.Globalization.CultureInfo.InvariantCulture); } catch { MessageBox.Show("Some error in RV1 field...", "Error..."); return; } try { tspec1 = new TempSpec(txtTemplate1.Text); } catch { MessageBox.Show("Cannot load Template 1 file...", "Error..."); return; } tspec = tspec1.RVShift(rv); } } tellur = new Mask(Application.StartupPath + "\\telluric.txt"); double[][] mask = new double[tellur.Size() + cutMask.Size()][]; for (int i = 0; i < mask.Length; i++) { mask[i] = new double[2]; } for (int i = 0; i < tellur.Size(); i++) { mask[i][0] = tellur.GetLeftBound(i); mask[i][1] = tellur.GetRightBound(i); } for (int i = 0; i < cutMask.Size(); i++) { mask[i + tellur.Size()][0] = cutMask.GetLeftBound(i); mask[i + tellur.Size()][1] = cutMask.GetRightBound(i); } double[][] lambds1, fluxes1; double[][][] outmas = null; if (grading_step > 1) { outmas = SpectraGrading(grading_step); } lambds1 = outmas[0]; fluxes1 = outmas[1]; Normator norm = null; if (rbTemplate.Checked) { norm = new Normator(lambds1, fluxes1, tspec.Lambdas, tspec.NormFluxes, mask); } else { norm = new Normator(lambds1, fluxes1, mask); } norm.Norm1(oo, ox, 10); this.cont = new double[this.lambds.Length][]; for (int i = 0; i < this.cont.Length; i++) { this.cont[i] = new double[this.lambds[i].Length]; } for (int i = 0; i < this.cont.Length; i++) { Array.Reverse(lambds1[i]); Array.Reverse(norm.GetContinum[i]); LinInterpolator li = new LinInterpolator(lambds1[i], norm.GetContinum[i]); for (int j = 0; j < this.cont[i].Length; j++) { this.cont[i][j] = li.Interp(this.lambds[i][j]); } } }