Beispiel #1
0
        public static void Locate(ref Image im, int polynom_degree)
        {
            double[] order_centers = new double[2];
            int      wing          = 2;
            int      middle        = im.NAXIS2 / 2;
            Image    slice         = new Image(im.NAXIS1, 1 + 2 * wing);

            for (int i = 0; i < slice.NAXIS1; i++)
            {
                for (int j = 0; j < slice.NAXIS2; j++)
                {
                    slice[i, j] = im[i, middle - wing + j];
                }
            }

            double[] aver_column = new double[im.NAXIS1];

            for (int i = 0; i < aver_column.Length; i++)
            {
                aver_column[i] = Statistics.Median(slice.GetRow(i));
            }

            StreamWriter sw = new StreamWriter((string)Init.Value("DIR_MAIN") + "\\Slice.txt");

            for (int i = 0; i < aver_column.Length - 1; i++)
            {
                sw.WriteLine("{0}\t{1}", i, aver_column[i].ToString());
            }
            sw.Close();

            // Search for orders locations in cetral slit;

            double[] xmax_0       = new double[5000];
            int      orders_count = 0;

            int dist = 5; // for ZTSh

            EcheData.LoadOrdMidPos("OrdPos.dat", (int)Init.Value("TRIM_COL1"));

            double[] xmax = new double[EcheData.ord_mid_pos.Length];
            for (int i = 0; i < xmax.Length; i++)
            {
                xmax[i] = (double)EcheData.ord_mid_pos[i];
            }

            for (int i = 0; i < xmax.Length; i++)
            {
                int x1 = (int)xmax[i] - dist;
                int x2 = (int)xmax[i] + dist;
                if (x1 < 0)
                {
                    x1 = 0;
                }
                if (x2 > aver_column.Length - 1)
                {
                    x2 = aver_column.Length - 1;
                }
                int    xm  = x1;
                double max = aver_column[x1];
                for (int j = x1 + 1; j <= x2; j++)
                {
                    if (aver_column[j] > max)
                    {
                        max = aver_column[j];
                        xm  = j;
                    }
                }
                xmax[i] = xm;
            }

            orders_count = xmax.Length;

            // Orders Tracing;

            pos_ord = new double[orders_count][];
            for (int i = 0; i < pos_ord.Length; i++)
            {
                pos_ord[i] = new double[im.NAXIS2];
            }

            for (int i = 0; i < pos_ord.Length; i++)
            {
                pos_ord[i][middle] = xmax[i];
            }

            int nwin = 8;
            int o1 = 0, o2 = 0;

            for (int i = middle - 1; i >= 0; i--)
            {
                for (int n = o1; n < orders_count + o2; n++)
                {
                    int    n1  = (int)pos_ord[n][i + 1] - nwin;
                    int    n2  = (int)pos_ord[n][i + 1] + nwin;
                    double max = 0;
                    for (int k = n1; k <= n2; k++)
                    {
                        if (im[k, i] > max)
                        {
                            pos_ord[n][i] = k;
                            max           = im[k, i];
                        }
                    }
                }
            }

            for (int i = middle + 1; i < im.NAXIS2; i++)
            {
                for (int n = o1; n < orders_count + o2; n++)
                {
                    int    n1  = (int)pos_ord[n][i - 1] - nwin;
                    int    n2  = (int)pos_ord[n][i - 1] + nwin;
                    double max = 0;
                    for (int k = n1; k <= n2; k++)
                    {
                        if (im[k, i] > max)
                        {
                            pos_ord[n][i] = k;
                            max           = im[k, i];
                        }
                    }
                }
            }

            pos_min = new double[pos_ord.Length + 1][];
            for (int i = 0; i < pos_min.Length; i++)
            {
                pos_min[i] = new double[im.NAXIS2];
            }

            for (int i = 0; i < im.NAXIS2; i++)
            {
                for (int n = 1; n < pos_min.Length - 1; n++)
                {
                    int    n1  = (int)pos_ord[n - 1][i];
                    int    n2  = (int)pos_ord[n][i];
                    double min = double.MaxValue;
                    for (int k = n1; k <= n2; k++)
                    {
                        if (im[k, i] < min)
                        {
                            pos_min[n][i] = k;
                            min           = im[k, i];
                        }
                    }
                }
            }


            for (int i = 0; i < im.NAXIS2; i++)
            {
                pos_min[0][i] = pos_min[1][i] - (pos_min[2][i] - pos_min[1][i]);
                if (pos_min[0][i] < 0)
                {
                    pos_min[0][i] = 0;
                }
            }


            for (int i = 0; i < im.NAXIS2; i++)
            {
                pos_min[pos_min.Length - 1][i] = pos_min[pos_min.Length - 2][i] +
                                                 (pos_min[pos_min.Length - 2][i] - pos_min[pos_min.Length - 3][i]);
                if (pos_min[pos_min.Length - 1][i] > aver_column.Length - 1)
                {
                    pos_min[pos_min.Length - 1][i] = aver_column.Length - 1;
                }
            }


            Saver.SaveOrderedDistribution(pos_min, (string)Init.Value("DIR_MAIN") + "\\trace_min.txt");

            Saver.SaveColumn(xmax, (string)Init.Value("DIR_MAIN") + "\\orders_ident.dat");

            double[] pixels_x = new double[im.NAXIS2];
            for (int i = 0; i < pixels_x.Length; i++)
            {
                pixels_x[i] = i;
            }

            GravImprove(im, ref pos_min, ref pos_ord);
            Saver.SaveOrderedDistribution(pos_ord, (string)Init.Value("DIR_MAIN") + "\\trace.txt");

            for (int i = 0; i < pos_ord.Length; i++)
            {
                ImproveTraces(pixels_x, ref pos_ord[i], polynom_degree);
            }

            for (int i = 0; i < pos_min.Length; i++)
            {
                ImproveTraces(pixels_x, ref pos_min[i], polynom_degree);
            }

            Saver.SaveOrderedDistribution(pos_ord, (string)Init.Value("DIR_MAIN") + "\\orders_impoved.dat");
            Saver.SaveOrderedDistribution(pos_min, (string)Init.Value("DIR_MAIN") + "\\mins_improved.dat");

            for (int i = 0; i < xmax.Length; i++)
            {
                xmax[i] = pos_ord[i][middle];
            }

            Saver.SaveColumn(xmax, (string)Init.Value("DIR_MAIN") + "\\Orders.txt");
        }
Beispiel #2
0
        public static void IdentOrders(ref double[][] pos_ord, ref double[][] pos_min, int column)
        {
            double[][] pos_ord_1 = new double[ord_mid_pos.Length][];
            for (int i = 0; i < pos_ord_1.Length; i++)
            {
                pos_ord_1[i] = new double[pos_ord[0].Length];
            }

            double[][] pos_min_1 = new double[ord_mid_pos.Length + 1][];
            for (int i = 0; i < pos_min_1.Length; i++)
            {
                pos_min_1[i] = new double[pos_min[0].Length];
            }

            int shift = 0;

            int ident_orders_count = 0;

            for (int i = 0; i < pos_ord_1.Length; i++)
            {
                int    k_min    = 0;
                double diff_min = double.MaxValue;
                double diff;
                for (int j = 0; j < pos_ord.Length; j++)
                {
                    diff = Math.Abs(pos_ord[j][column] - ord_mid_pos[i]);
                    if (diff < diff_min)
                    {
                        k_min    = j;
                        diff_min = diff;
                        if (i == 0)
                        {
                            shift = j;
                        }
                    }
                }
                if (i > 0)
                {
                    if (pos_ord[k_min][column] == pos_ord_1[i - 1][column])
                    {
                        break;
                    }
                }
                ident_orders_count++;
                for (int j = 0; j < pos_ord_1[i].Length; j++)
                {
                    pos_ord_1[i][j] = pos_ord[k_min][j];
                }
            }

            Array.Resize(ref pos_ord_1, ident_orders_count);
            Array.Resize(ref pos_min_1, ident_orders_count + 1);

            for (int i = 0; i < pos_min_1.Length; i++)
            {
                for (int j = 0; j < pos_min_1[i].Length; j++)
                {
                    pos_min_1[i][j] = pos_min[i + shift - 1][j];
                }
            }

            pos_min = pos_min_1;
            pos_ord = pos_ord_1;

            double[] pos_ord_slice = new double[pos_ord.Length];
            for (int i = 0; i < pos_ord_slice.Length; i++)
            {
                pos_ord_slice[i] = pos_ord[i][column];
            }
            double[] pos_min_slice = new double[pos_min.Length];
            for (int i = 0; i < pos_min_slice.Length; i++)
            {
                pos_min_slice[i] = pos_min[i][column];
            }

            Saver.SaveColumn(pos_ord_slice, InitFile.DirectoryMain + "\\orders_ident.dat");
            Saver.SaveColumn(pos_min_slice, InitFile.DirectoryMain + "\\minima_ident.dat");
        }