示例#1
0
        public static void Norm(double[][] orders, int polynom_degree, int order_1, int order_2)
        {
            poly_degree = polynom_degree;
            int orders_count = orders.Length;
            int pixels_count = orders[0].Length;

            OrdersNorm = new double[orders_count][];
            for (int i = 0; i < orders_count; i++)
            {
                OrdersNorm[i] = new double[pixels_count];
                for (int j = 0; j < pixels_count; j++)
                {
                    OrdersNorm[i][j] = 1.0;
                }
            }

            FitCurves = new double[orders_count][];
            for (int i = 0; i < orders_count; i++)
            {
                FitCurves[i] = new double[pixels_count];
                for (int j = 0; j < pixels_count; j++)
                {
                    FitCurves[i][j] = orders[i][j];
                }
            }

            double[][] orders1 = new double[orders_count][];
            for (int i = 0; i < orders_count; i++)
            {
                orders1[i] = new double[pixels_count];
                for (int j = 0; j < pixels_count; j++)
                {
                    orders1[i][j] = orders[i][j];
                }
            }



            double[] pixels = new double[pixels_count];
            for (int i = 0; i < pixels_count; i++)
            {
                pixels[i] = i;
            }

            double pix_max = pixels[pixels.Length - 1];
            double flx_max;

            for (int i = 0; i < pixels.Length; i++)
            {
                pixels[i] = pixels[i] / pix_max;
            }

            double[] coeffs;
            double[] sigmas = new double[pixels_count];

            for (int i = order_1; i <= order_2; i++)
            {
                flx_max = orders1[i].Max();
                for (int j = 0; j < pixels_count; j++)
                {
                    orders1[i][j] = orders1[i][j] / flx_max;
                }

                for (int j = 0; j < sigmas.Length; j++)
                {
                    sigmas[j] = orders1[i][j];
                    if (sigmas[j] <= 0)
                    {
                        sigmas[j] = 1;
                    }
                    //if (orders1[i][j] * flx_max > 1)
                    //{
                    //    sigmas[j] = Math.Sqrt(orders1[i][j]);
                    //}
                    //else
                    //{
                    //    sigmas[j] = 1;
                    //}
                }

                FitSVD fitterSVD = new FitSVD(pixels, orders1[i], sigmas, polynom, 1e-30);
                //Fitter fitter = new Fitter();
                fitterSVD.fit();
                //coeffs = fitter.WightedPolynom(pixels, orders1[i], sigmas, poly_degree);
                coeffs = fitterSVD.FittedCoeffs;

                for (int j = 0; j < pixels.Length; j++)
                {
                    double sum = 0;
                    for (int k = 0; k < polynom_degree + 1; k++)
                    {
                        sum += Math.Pow(pixels[j], k) * coeffs[k];
                    }
                    FitCurves[i][j]  = sum * flx_max;;
                    OrdersNorm[i][j] = orders[i][j] / FitCurves[i][j];
                }
            }
        }
示例#2
0
        public static void Norm(double[] lambdas, double[] order, double[] lambda0,
                                double[] inten0, int polynom_degree, double lower, double upper, int iterNum, string funcType)
        {
            func_type   = funcType;
            poly_degree = polynom_degree;
            int lambda_count = order.Length;

            OrderNorm = new double[lambda_count];

            linterp = new SN.LinInterpolator(lambda0, inten0);

            FitCurve = new double[lambda_count];

            double[] orders1 = new double[lambda_count];

            flx_max = order.Max();
            for (int j = 0; j < lambda_count; j++)
            {
                orders1[j] = order[j] / flx_max;
            }

            lambda_max = lambdas.Max();
            lambda_min = lambdas.Min();

            for (int i = 0; i < lambdas.Length; i++)
            {
                lambdas[i] = (2 * lambdas[i] -
                              (lambda_max + lambda_min)) / (lambda_max - lambda_min);
            }

            double[] sigmas = new double[lambda_count];

            for (int j = 0; j < sigmas.Length; j++)
            {
                sigmas[j] = orders1[j];
                if (orders1[j] * flx_max > 1)
                {
                    sigmas[j] = Math.Sqrt(orders1[j]);
                    //sigmas[j] = 1;
                }
                else
                {
                    sigmas[j] = 1;
                }
            }

            lambdaRej = new double[lambda_count];

            fluxRej = new double[lambda_count];

            int count_rej = 0;

            FitSVD fitterSVD = null;

            for (int i = 0; i < iterNum; i++)
            {
                if (funcType == "chebyshev")
                {
                    fitterSVD = new FitSVD(lambdas, orders1, sigmas, chebyshev, 1e-14);
                }
                if (funcType == "simple")
                {
                    fitterSVD = new FitSVD(lambdas, orders1, sigmas, polynom, 1e-14);
                }

                fitterSVD.fit();

                coeffs = fitterSVD.FittedCoeffs;

                stddev = 0;
                for (int j = 0; j < lambdas.Length; j++)
                {
                    double sum = 0;
                    //for (int k = 0; k < polynom_degree + 1; k++)
                    //{
                    //    sum += Math.Pow(lambdas[j], k) * coeffs[k];
                    //}
                    if (func_type == "simple")
                    {
                        sum = simple_calc(coeffs, lambdas[j]);
                    }
                    if (func_type == "chebyshev")
                    {
                        sum = chebyshev_calc(coeffs, lambdas[j]);
                    }

                    FitCurve[j]  = sum;
                    OrderNorm[j] = orders1[j] / FitCurve[j];
                    stddev      += Math.Pow(OrderNorm[j] - inten0[j], 2);
                }

                stddev = Math.Sqrt(stddev / lambdas.Length);
                int count = 0;

                if (i < iterNum - 1)
                {
                    for (int j = 0; j < lambdas.Length; j++)
                    {
                        if ((OrderNorm[j] - inten0[j]) <= upper * stddev &&
                            (inten0[j] - OrderNorm[j]) <= lower * stddev)
                        {
                            lambdas[count] = lambdas[j];
                            orders1[count] = orders1[j];
                            count++;
                        }
                        else
                        {
                            lambdaRej[count_rej] = 0.5 * (lambdas[j] * (lambda_max - lambda_min)
                                                          + (lambda_max + lambda_min));
                            fluxRej[count_rej] = orders1[j] * flx_max;
                            count_rej++;
                        }
                    }
                }

                Array.Resize(ref lambdas, count);
                Array.Resize(ref orders1, count);
            }
            Array.Resize(ref lambdaRej, count_rej);
            Array.Resize(ref fluxRej, count_rej);
        }