コード例 #1
0
        public void LoadMatFromASC()
        {
            string dic     = @"E:\Heihe\HRB\GeoData\GBHM\IHRB\上游模型集成数据_qy151228\3.merge_soil\";
            string ascfile = dic + "soil_200001.asc";
            // string acfile = @"C:\Users\Administrator\Documents\GBHM\GBHM\result\sm_month_2000-2012_gbhm.ac";
            AscReader        asc   = new AscReader();
            AcFile           ac    = new AcFile();
            var              vec   = asc.LoadSerial(ascfile, _ProjectService.Project.Model.Grid as IRegularGrid);
            int              nfeat = vec.Length;
            DataCube <float> mat   = new DataCube <float>(1, 156, nfeat);

            int i = 0;

            for (int y = 2000; y < 2013; y++)
            {
                for (int m = 1; m < 13; m++)
                {
                    string fn = dic + "soil_" + y + m.ToString("00") + ".asc";
                    vec = asc.LoadSerial(fn, _ProjectService.Project.Model.Grid as IRegularGrid);
                    var buf = vec;
                    for (int c = 0; c < buf.Length; c++)
                    {
                        if (buf[c] < 0)
                        {
                            buf[c] = 0;
                        }
                    }
                    mat[0, i.ToString(), ":"] = buf;
                    i++;
                }
            }
            // ac.Save(acfile, mat, new string[] { "Monthly Soil Moisture" });
        }
コード例 #2
0
        public static void Extract2AcFile(float[][][] matrix, int[] indexes, string varName, int varIndex, string acfile)
        {
            int steps = matrix[0].Length;
            int nfea  = indexes.Length;

            float[][][] ac = new float[1][][];
            ac[0] = new float[steps][];
            for (int s = 0; s < steps; s++)
            {
                ac[0][s] = new float[nfea];
            }
            for (int s = 0; s < steps; s++)
            {
                for (int i = 0; i < nfea; i++)
                {
                    ac[0][s][i] = matrix[varIndex][s][indexes[i]];
                }
            }
            AcFile acf = new AcFile();

            acf.Save(acfile, ac, new string[] { varName });
            ac = null;
        }
コード例 #3
0
        /// <summary>
        /// extract subset from the given matrix and save it to a ac file
        /// </summary>
        /// <param name="serialMatrix">2D serial matrix</param>
        /// <param name="indexes">indexes of subset</param>
        /// <param name="varName">name of variable</param>
        /// <param name="acfile">ac filename</param>
        public static void Extract2AcFile(MatrixCube <float> serialMatrix, int[] indexes, string varName, string acfile)
        {
            int steps = serialMatrix.LayeredSerialValue.Length;
            int nfea  = indexes.Length;

            float[][][] ac = new float[1][][];
            ac[0] = new float[steps][];
            for (int s = 0; s < steps; s++)
            {
                ac[0][s] = new float[nfea];
            }
            for (int s = 0; s < steps; s++)
            {
                for (int i = 0; i < nfea; i++)
                {
                    ac[0][s][i] = serialMatrix.LayeredSerialValue[s][indexes[i]];
                }
            }
            AcFile acf = new AcFile();

            acf.Save(acfile, ac, new string[] { varName });
            ac = null;
        }