Exemple #1
0
 protected virtual void OnDataCubedLoaded(DataCube <float> e)
 {
     if (DataCubeLoaded != null)
     {
         DataCubeLoaded(this, e);
     }
 }
Exemple #2
0
        public MapPlot(DataCube aDataCube, Panel aDestinationPanel, Renderer aRenderer,
                       ColorMap aColorMap, ParallelCoordinatesPlot aPcPlot, GMSDocument aDoc)
        {
            iDataCube = aDataCube;
            iPanel    = aDestinationPanel;
            renderer  = aRenderer;
            iColorMap = aColorMap;

            iPcPlot         = aPcPlot;
            iDoc            = aDoc;
            iLegendColorMap = iDoc.iFilteredSelectedColorMap;

            SetupMapLayers();

            //Get country names
            iCountryNames = iDoc.GetFilteredCountryNames();

            //Prepare tooltip
            iToolTip            = new GavToolTip(iPanel);
            iToolTip.FadeEnable = true;
            iToolTip.FadeTime   = TOOLTIP_FADE_DELAY;
            iToolTip.Show(new Point(0, 0));
            iToolTip.Hide();

            iMouseHoverControl           = new MouseHoverController(iPanel, TOOLTIP_SENSITIVITY, TIMER_DELAY);
            iMouseHoverControl.Hover    += new EventHandler(iMouseHoverControl_Hover);
            iMouseHoverControl.HoverEnd += new EventHandler(iMouseHoverControl_HoverEnd);

            iDoc.Picked          += new EventHandler <IndexesPickedEventArgs>(DocumentPicked);
            iDoc.ColorMapChanged += new EventHandler <EventArgs>(DocumentColorMapChanged);
        }
        public void Export(string dbfile, string ascfile, int nrow, int ncol, int cellsize, float xcorner, float ycorner, float nodatavalue = -999)
        {
            DBFReader        dbf        = new DBFReader(dbfile);
            int              act_index  = dbf.GetFiledNameIndex("active");
            int              row_index  = dbf.GetFiledNameIndex("row");
            int              col_index  = dbf.GetFiledNameIndex("col");
            int              elev_index = dbf.GetFiledNameIndex("elev");
            DataCube <float> mat        = new DataCube <float>(1, nrow, ncol);
            int              nact       = 0;

            for (int n = 0; n < dbf.RecordCount; n++)
            {
                var obj = dbf.NextRecord();
                int row = int.Parse(obj[row_index].ToString());
                int col = int.Parse(obj[col_index].ToString());
                int act = int.Parse(obj[act_index].ToString());
                if (act > 0)
                {
                    mat[0, row - 1, col - 1] = float.Parse(obj[elev_index].ToString());
                    nact++;
                }
                else
                {
                    mat[0, row - 1, col - 1] = nodatavalue;
                }
            }

            dbf.Close();
            //  this.Save<float>(ascfile, Value, nrow, ncol, cellsize, xcorner, ycorner, nodatavalue);
        }
Exemple #4
0
 public override bool Load(ICancelProgressHandler progress)
 {
     if (File.Exists(FileName))
     {
         int          num  = 0;
         StreamReader sr   = new StreamReader(FileName);
         string       line = sr.ReadLine();
         var          strs = TypeConverterEx.Split <string>(line);
         num = int.Parse(strs[0]);
         var mat = new DataCube <int>(1, 3, num);
         for (int i = 0; i < num; i++)
         {
             line = sr.ReadLine();
             var buf = TypeConverterEx.Split <int>(line, 3);
             mat[0, 0, i] = buf[0];
             mat[0, 1, i] = buf[1];
             mat[0, 2, i] = buf[2];
         }
         sr.Close();
         GagingInfo = mat;
         OnLoaded(progress);
         return(true);
     }
     else
     {
         OnLoadFailed("Failed to load " + this.Name, progress);
         return(false);
     }
 }
    /// <summary>
    /// Computes the average data point of specified pixel block locations and plots spectral data.
    /// </summary>
    /// <param name="x"> The specified unity X coordinate used to retrieve DataCube row </param>
    /// <param name="z"> The specified unity Z coordinate used to retrieve DataCube col</param>
    public void AveragePixelBlocks(float x, float z)
    {
        Vector2 selectedXZ = new Vector2(x, z);

        if (rowcolSet == null)
        {
            rowcolSet = new HashSet <Vector2>();
        }

        Vector2 currentRowCol = DataCube.getColRowFromUnityXZ(x, z);

        //adds currentRowcol to the rowcol set if it is unique
        if (rowcolSet.Add(currentRowCol))
        {
            InstantiateNewPixelBlock(selectedXZ);

            //Compute average of all the vector rowcols in the list:
            float colSum = 0f;
            float rowSum = 0f;
            foreach (Vector2 rowcol in rowcolSet)
            {
                colSum += rowcol.x;
                rowSum += rowcol.y;
            }
            Vector2 averageRowCol = new Vector2(colSum / rowcolSet.Count, rowSum / rowcolSet.Count);

            // Clear graph and plot the result
            spectralPlotter.ResetPixels();
            spectralPlotter.PlotData(Mathf.RoundToInt(averageRowCol.x), Mathf.RoundToInt(averageRowCol.y), Color.white);
            spectralPlotter.ApplyPixels();
        }
    }
        public void ComputeHorizontal(DataCube <float> cbc, int dim1, int dim2)
        {
            //cbc.Value
            int steps = cbc.Size[1];
            int nfea  = cbc.Size[2];

            Direction = new DataCube <float>(1, steps, nfea);
            Metric    = new DataCube <float>(1, steps, nfea);

            for (int s = 0; s < steps; s++)
            {
                for (int i = 0; i < nfea; i++)
                {
                    var r = Math.Sqrt(cbc[dim1, steps, i] * cbc[dim1, steps, i]
                                      + cbc[dim2, steps, i] * cbc[dim2, steps, i]);
                    if (r == 0)
                    {
                        r = 1;
                    }
                    if (r < 0)
                    {
                        r = 1;
                    }
                    Direction[0, s, i] = (float)(Math.Asin(cbc[dim2, steps, i] / r)); //* 57.29578
                    Metric[0, s, i]    = (float)r;
                }
            }
        }
        public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler)
        {
            StreamReader sr   = new StreamReader(DataFileName);
            var          line = sr.ReadLine();

            line = sr.ReadLine();
            var buf       = TypeConverterEx.Split <string>(line);
            int ncell     = int.Parse(buf[1]);
            int nvar      = int.Parse(buf[3]);
            var variables = new string[nvar + 2];

            variables[0] = "x";
            variables[1] = "y";
            for (int i = 0; i < nvar; i++)
            {
                variables[i + 2] = buf[4 + i];
            }
            var mat_out = new DataCube <float>(nvar + 2, 1, ncell);

            mat_out.Name      = OutputDataCube;
            mat_out.Variables = variables;
            for (int i = 0; i < ncell; i++)
            {
                line = sr.ReadLine().Trim();
                var vec = TypeConverterEx.Split <float>(line);
                for (int j = 0; j < nvar + 2; j++)
                {
                    mat_out[j, 0, i] = vec[j];
                }
            }
            sr.Close();
            Workspace.Add(mat_out);
            cancelProgressHandler.Progress("Package_Tool", 100, "Finished");
            return(true);
        }
        public DataCube <float> Load(string filename, DataCube <float> ibound)
        {
            Variables = new string[] { Path.GetFileNameWithoutExtension(filename) };
            FileName  = filename;

            StreamReader sr   = new StreamReader(FileName);
            List <float> list = new List <float>();
            string       line = "";

            for (int i = 0; i < ibound.Size[0]; i++)
            {
                line = sr.ReadLine();
                var buf = TypeConverterEx.Split <float>(line);
                for (int j = 0; j < ibound.Size[1]; j++)
                {
                    if (ibound[i, j, 0] != 0)
                    {
                        list.Add(buf[j]);
                    }
                }
            }
            var array = new DataCube <float>(1, 1, list.Count);

            array[0, "0", ":"] = list.ToArray();
            list.Clear();
            sr.Close();
            return(array);
        }
Exemple #9
0
        public DataCube <float> ExtractTo(IEnumerable <IObservationsSite> wells, int selectedLayerIndex)
        {
            int nwell            = wells.Count();
            var mfgrid           = Owner.Grid as MFGrid;
            int step             = DataCube.Size[1];
            DataCube <float> mat = new DataCube <float>(1, step, wells.Count())
            {
                Name           = "HOB_Output",
                TimeBrowsable  = true,
                AllowTableEdit = false
            };

            mat.DateTimes = new DateTime[step];

            for (int n = 0; n < nwell; n++)
            {
                var site  = wells.ElementAt(n);
                var well  = site as HeadObservation;
                var index = mfgrid.Topology.CellID2CellIndex[well.CellID];
                site.SpatialIndex = index;
                for (int t = 0; t < step; t++)
                {
                    mat[0, t, n] = DataCube[selectedLayerIndex, t, index];;
                }
            }
            for (int i = 0; i < step; i++)
            {
                mat.DateTimes[i] = TimeService.IOTimeline[i];
            }
            mat.Variables = new string[] { Variables[selectedLayerIndex] };
            return(mat);
        }
 public override bool Load(int var_index, ICancelProgressHandler progress)
 {
     _ProgressHandler = progress;
     if (File.Exists(FileName))
     {
         var grid = Owner.Grid as MFGrid;
         if (DataCube == null || DataCube.Size[1] != StepsToLoad)
         {
             DataCube = new DataCube <float>(Variables.Length, StepsToLoad, grid.ActiveCellCount)
             {
                 Name           = "vert_dis",
                 TimeBrowsable  = true,
                 AllowTableEdit = false
             };
         }
         DataCube.Topology = (this.Grid as RegularGrid).Topology;
         FHDFile fhd = new FHDFile(FileName, grid);
         fhd.Variables       = this.Variables;
         fhd.Variables       = this.Variables;
         fhd.MaxTimeStep     = this.MaxTimeStep;
         fhd.NumTimeStep     = this.NumTimeStep;
         fhd.DataCube        = this.DataCube;
         fhd.Loading        += fhd_Loading;
         fhd.DataCubeLoaded += fhd_DataCubeLoaded;
         fhd.LoadFailed     += fhd_LoadFailed;
         fhd.LoadVertDis(var_index);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemple #11
0
        public void LoadComparingValues()
        {
            OnLoading(0);
            var grid     = Owner.Grid as MFGrid;
            int nstep    = _nsite;
            int progress = 0;

            if (File.Exists(FileName))
            {
                StreamReader sr = new StreamReader(FileName);
                ComparingValues = new DataCube <float>(2, 1, _nsite);
                ComparingValues.Allocate(0, 1, _nsite);
                ComparingValues.Allocate(1, 1, _nsite);
                string line = sr.ReadLine();
                for (int i = 0; i < _nsite; i++)
                {
                    line = sr.ReadLine();
                    if (!TypeConverterEx.IsNull(line))
                    {
                        var vv = TypeConverterEx.Split <float>(line);
                        ComparingValues[0, 0, i] = vv[0];
                        ComparingValues[1, 0, i] = vv[1];
                    }
                    progress = Convert.ToInt32(i * 100 / nstep);
                    OnLoading(progress);
                }
                if (progress < 100)
                {
                    OnLoading(100);
                }
                ComparingValues.DateTimes = new DateTime[] { TimeService.Timeline[0] };
                OnLoaded(_ProgressHandler);
                sr.Close();
            }
        }
        public DataCube <float> LoadSerial(string filename, int nrow, int ncol)
        {
            Variables = new string[] { Path.GetFileNameWithoutExtension(filename) };
            FileName  = filename;
            StreamReader sr   = new StreamReader(FileName);
            List <float> list = new List <float>();
            string       line = "";

            for (int i = 0; i < nrow; i++)
            {
                line = sr.ReadLine();
                var buf = TypeConverterEx.Split <float>(line);
                for (int j = 0; j < ncol; j++)
                {
                    if (buf[j] != NoDataValue)
                    {
                        list.Add(buf[j]);
                    }
                }
            }
            var array = new DataCube <float>(1, 1, list.Count);

            array[0, "0", ":"] = list.ToArray();
            list.Clear();
            sr.Close();
            return(array);
        }
        public void Constant(float ppt = 0.15f, float tmax = 15, float tmin = 5, float pet = 0.1f)
        {
            var grid             = this.Grid as MFGrid;
            DataCube <float> mat = new DataCube <float>(1, this.TimeService.NumTimeStep, grid.ActiveCellCount);

            mat.Variables             = new string[] { "hru_ppt" };
            mat.DateTimes             = this.TimeService.Timeline.ToArray();
            mat.ILArrays[0][":", ":"] = 0.1f;

            MMSDataFile data = new MMSDataFile(MasterPackage.PrecipitationFile);

            data.Save(mat);

            mat.Variables[0]          = "hru_tmax";
            mat.ILArrays[0][":", ":"] = UnitConversion.Celsius2Fahrenheit(15);
            data = new MMSDataFile(MasterPackage.TempMaxFile);
            data.Save(mat);

            mat.Variables[0]          = "hru_tmin";
            mat.ILArrays[0][":", ":"] = UnitConversion.Celsius2Fahrenheit(5);
            data = new MMSDataFile(MasterPackage.TempMinFile);
            data.Save(mat);

            mat.Variables[0]          = "hru_pet";
            mat.ILArrays[0][":", ":"] = 0.15f;
            data = new MMSDataFile(MasterPackage.PETFile);
            data.Save(mat);
        }
Exemple #14
0
        protected override void ProcessData()
        {
            if (ForceRetransformation || _firstTime)
            {
                _dataCube = new DataCube();

                float[, ,] inputData = _input.GetDataCube().DataArray;

                _outputData = replaceNaNPlaceholder(inputData);

                if (UseInterpolation)
                {
                    _untouchedData          = (float[, , ])_outputData.Clone();
                    _outputData             = interpolateDataVariables(_outputData);
                    _interpolatedOutputData = (float[, , ])_outputData.Clone();
                }

                _firstTime = false;
            }
            else
            {
                if (UseInterpolation)
                {
                    _outputData = (float[, , ])_interpolatedOutputData.Clone();
                }
                else
                {
                    _outputData = (float[, , ])_untouchedData.Clone();
                }
            }

            _dataCube.DataArray = _outputData;
        }
        protected override void ProcessData()
        {
            float[, ,] inputData = _input.GetDataCube().DataArray;

            if (VarIndex >= inputData.GetLength(1))
            {
                return;
            }

            DataCube outputCube = new DataCube();

            float[, ,] outputData = new float[inputData.GetLength(2), inputData.GetLength(1), 1];

            for (int y = 0; y < inputData.GetLength(1); y++)
            {
                for (int z = 0; z < inputData.GetLength(2); z++)
                {
                    outputData[z, y, 0] = inputData[VarIndex, y, z];
                }
            }

            outputCube.DataArray = outputData;

            _dataCube = outputCube;
        }
        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" });
        }
        /// <summary>
        /// write 3d mat for given variable
        /// </summary>
        /// <param name="sw">stream writer</param>
        /// <param name="mat">the layout of the mat is [nvar][nrow][ncol]</param>
        /// <param name="var_index"></param>
        /// <param name="format"></param>
        /// <param name="comment"></param>
        public void WriteRegularArray <T>(StreamWriter sw, DataCube <T> mat, int var_index, string format, string comment)
        {
            if (mat.Flags[var_index, 0] == TimeVarientFlag.Constant)
            {
                string line = string.Format("CONSTANT\t{0}\t{1}", mat.Constants[var_index, 0], comment);
                sw.WriteLine(line);
            }
            else if (mat.Flags[var_index, 0] == TimeVarientFlag.Repeat)
            {
            }
            else if (mat.Flags[var_index, 0] == TimeVarientFlag.Individual)
            {
                string line = string.Format("INTERNAL\t{0}\t(FREE)\t{1}\t{2}", mat.Multipliers[var_index, 0], mat.IPRN[var_index, 0], comment);
                var    grid = Owner.Grid as MFGrid;
                int    row  = grid.RowCount;
                int    col  = grid.ColumnCount;

                sw.WriteLine(line);
                for (int r = 0; r < row; r++)
                {
                    line = string.Join(StreamReaderSequence.stab, mat[var_index, r.ToString(), ":"]);
                    sw.WriteLine(line);
                }
            }
        }
Exemple #18
0
        public void Export(string ac_filename, string[] dbffiles, int[] index)
        {
            int steps = dbffiles.Length;
            DBFReader dbf = new DBFReader(dbffiles[0]);
            int nfeature = dbf.RecordCount;
            var buf = new DataCube<float>(index.Length, steps, nfeature);
            string[] field = new string[index.Length];
            for (int i = 0; i < index.Length; i++)
            {
                field[i] = dbf.Fields[index[i]].Name;
            }
              
            dbf.Close();

            for (int t = 0; t < steps; t++)
            {
                dbf = new DBFReader(dbffiles[t]);
                for (int n = 0; n < dbf.RecordCount; n++)
                {
                    var obj = dbf.NextRecord();
                    for (int i = 0; i < index.Length; i++)
                    {
                        buf[i, t, n] = float.Parse(obj[index[i]].ToString());
                    }
                }
                dbf.Close();
            }
            buf.Variables = field;
            DataCubeStreamWriter ac = new DataCubeStreamWriter(ac_filename);
            ac.WriteAll(buf);
        }
Exemple #19
0
        /// <summary>
        /// Export Mike SHP Results to AC file
        /// </summary>
        /// <param name="grid"></param>
        /// <param name="ac_filename"></param>
        /// <param name="shpfiles"></param>
        /// <param name="field"></param>
        public void Export(ITriangularGrid grid, string ac_filename, string[] shpfiles, string field)
        {
            int steps = shpfiles.Length;
            int nfeature = grid.VertexCount;
            var buf = new DataCube<float>(1, steps, nfeature);

            for (int i = 0; i < steps; i++)
            {
                var fs = FeatureSet.Open(shpfiles[i]);
                var vec = (from dr in fs.DataTable.AsEnumerable() select (float)dr.Field<double>(field)).ToArray();
                for (int k = 0; k < grid.VertexCount; k++)
                {
                    var cells = grid.Topology.NodeConnectedCells[k];
                    float temp = 0;
                    for (int c = 0; c < cells.Length; c++)
                    {
                        temp += vec[cells[c]];
                    }
                    temp /= cells.Length;
                    buf[0, i, k] = temp;
                }
                fs.Close();
            }
            buf.Variables = new string[] { field };
            DataCubeStreamWriter ac = new DataCubeStreamWriter(ac_filename);
            ac.WriteAll(buf);
        }
        protected override void ProcessData()
        {
            float[, ,] inputData = _input.GetDataCube().DataArray;

            if (Slice >= inputData.GetLength(2))
            {
                return;
            }

            DataCube outputCube = new DataCube();

            float[, ,] outputData = new float[inputData.GetLength(0), inputData.GetLength(1), 1];

            for (int x = 0; x < inputData.GetLength(0); x++)
            {
                for (int y = 0; y < inputData.GetLength(1); y++)
                {
                    outputData[x, y, 0] = inputData[x, y, Slice];
                }
            }

            outputCube.DataArray = outputData;

            _dataCube = outputCube;
        }
 public SaveDcxForm(DataCube <float> mat)
 {
     InitializeComponent();
     _Mat = mat;
     for (int i = 0; i < _Mat.Size[0]; i++)
     {
         checkedListBox1.Items.Add(_Mat.Variables[i], _Mat[i] != null);
     }
 }
Exemple #22
0
        public override void LoadDataCube()
        {
            if (MaxTimeStep <= 0 || NumTimeStep == 0)
            {
                Scan();
                MaxTimeStep = NumTimeStep;
            }
            FileStream   fs        = new FileStream(_FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            BinaryReader br        = new BinaryReader(fs);
            int          nstep     = StepsToLoad;
            float        vv        = 0;
            long         layerbyte = _Grid.RowCount * _Grid.ColumnCount * 4;

            fs = new FileStream(_FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            br = new BinaryReader(fs);


            DataCube = new DataCube <float>(Variables.Length, nstep, _Grid.ActiveCellCount);

            for (int s = 0; s < NumTimeStep; s++)
            {
                for (int v = 0; v < Variables.Length; v++)
                {
                    fs.Seek(4 * 2, SeekOrigin.Current);
                    var vn = new string(br.ReadChars(16)).Trim();
                    fs.Seek(4 * 3, SeekOrigin.Current);
                    for (int l = 0; l < _Grid.ActualLayerCount; l++)
                    {
                        if (l == Layer)
                        {
                            int index = 0;
                            var buf   = new float[_Grid.ActiveCellCount];
                            for (int r = 0; r < _Grid.RowCount; r++)
                            {
                                for (int c = 0; c < _Grid.ColumnCount; c++)
                                {
                                    vv = br.ReadSingle();
                                    if (_Grid.IBound[Layer, r, c] != 0)
                                    {
                                        buf[index] = vv;
                                        index++;
                                    }
                                }
                            }
                            DataCube.ILArrays[v][s, ":"] = buf;
                        }
                        else
                        {
                            fs.Seek(layerbyte, SeekOrigin.Current);
                        }
                    }
                }
            }

            br.Close();
            fs.Close();
        }
Exemple #23
0
        /// <summary>
        /// Sorts the data by Country name and adds the data to the K-Means filter
        /// and the regular Data Cube
        /// </summary>
        public void SetupSortedData()
        {
            iSortedColorMap = CreateColorMap(
                Color.FromArgb(0x0051a87b)
                , Color.FromArgb(0x00bad97a)
                , Color.FromArgb(0x00f0e978)
                , Color.FromArgb(0x00d07c59)
                );

            iSortedCountryNames = new Hashtable();
            List <object[]> filteredCountries = new List <object[]>();
            ArrayList       sortedCountries   = new ArrayList(iDb.countries.Values);

            sortedCountries.Sort(new CountryComparer());

            //Dynamically allocate memory for the data
            uint i = 0;

            iSortedCountryNames.Clear();
            foreach (Country country in sortedCountries)
            {
                // if any albums were release in that country
                if (country.releases.Count != 0)
                {
                    filteredCountries.Add(new object[5] {
                        i,
                        country.medianAge,
                        Math.Log(country.releases.Count, 2),
                        //country.releases.Count,
                        country.unemploymentRate,
                        country.gdbPerCapita
                    });

                    string countryTitleCase = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(country.name);
                    iSortedCountryNames.Add(i++, countryTitleCase);
                }
            }

            //Allocate memory for the datacube data
            iSortedData = new object[5, filteredCountries.Count];
            i           = 0;
            foreach (object[] obj in filteredCountries)
            {
                // copy every attribute
                for (int j = 0; j < 5; j++)
                {
                    iSortedData[j, i] = obj[j];
                }
                ++i;
            }

            iSortedDataCube = new DataCube();
            iSortedDataCube.SetData(iSortedData);
            iSortedColorMap.Input = iSortedDataCube;
            iSortedColorMap.Index = 1;
            //kMeansFilter.Input = dataCube;
        }
Exemple #24
0
        private void Load2Mat4d()
        {
            if (File.Exists(FileName))
            {
                var          grid = this.Grid as MFGrid;
                int          np   = TimeService.StressPeriods.Count;
                StreamReader sr   = new StreamReader(FileName);
                var          line = ReadComment(sr);
                var          ss   = TypeConverterEx.Split <float>(line, 2);
                MXACTW = (int)ss[0];
                IWELCB = (int)ss[1];

                FluxRates                = new DataCube <float>(np, 1, MXACTW, true);
                FluxRates.DateTimes      = new System.DateTime[np];
                FluxRates.TimeBrowsable  = true;
                FluxRates.AllowTableEdit = false;

                for (int n = 0; n < np; n++)
                {
                    FluxRates.Variables[n] = "Flux Rate" + (n + 1);
                    ss = TypeConverterEx.Split <float>(sr.ReadLine(), 2);
                    int nwel = (int)ss[0];
                    if (nwel > 0)
                    {
                        FluxRates.AllocateSpaceDim(n, 0, nwel);
                        FluxRates.Flags[n, 0]       = TimeVarientFlag.Individual;
                        FluxRates.Multipliers[n, 0] = ss[1];
                        FluxRates.IPRN[n, 0]        = -1;
                        for (int i = 0; i < nwel; i++)
                        {
                            var vv = TypeConverterEx.Split <float>(sr.ReadLine());
                            FluxRates[n, 0, i] = vv[3];
                        }
                    }
                    else if (nwel == 0)
                    {
                        FluxRates.Flags[n, 0]       = TimeVarientFlag.Constant;
                        FluxRates.Multipliers[n, 0] = 1;
                        FluxRates.IPRN[n, 0]        = -1;
                    }
                    else
                    {
                        FluxRates.Flags[n, 0]       = TimeVarientFlag.Repeat;
                        FluxRates.Multipliers[n, 0] = ss[1];
                        FluxRates.IPRN[n, 0]        = -1;
                        var size = FluxRates.GetVariableSize(n - 1);
                        var buf  = new float[size[1]];
                        FluxRates[n - 1, "0", ":"].CopyTo(buf, 0);
                        FluxRates[n, "0", ":"] = buf;
                    }
                }

                sr.Close();
                BuilTopology();
            }
        }
 public void WriteStep(int varnum, int feaNum, DataCube <float> data)
 {
     for (int s = 0; s < feaNum; s++)
     {
         for (int v = 0; v < varnum; v++)
         {
             _BinaryWriter.Write(data[v, 0, s]);
         }
     }
 }
Exemple #26
0
        public override bool Load(ICancelProgressHandler progresshandler)
        {
            var cbcpck = CBCPackage;

            if (cbcpck.DataCube != null)
            {
                var cbc   = cbcpck.DataCube;
                int steps = cbc.Size[1];
                int nfea  = cbc.Size[2];
                OnLoading(0);
                int progress = 0;
                if (DataCube == null || DataCube.Size[1] != steps)
                {
                    DataCube           = new DataCube <float>(2, steps, nfea);
                    DataCube.DateTimes = new DateTime[steps];
                }

                if (cbc.IsAllocated(DimX) && cbc.IsAllocated(DimY))
                {
                    for (int s = 0; s < steps; s++)
                    {
                        for (int i = 0; i < nfea; i++)
                        {
                            var r = Math.Sqrt(cbc[DimX, s, i] * cbc[DimX, s, i]
                                              + cbc[DimY, s, i] * cbc[DimY, s, i]);
                            if (r == 0)
                            {
                                r = 1;
                            }
                            if (r < 0)
                            {
                                r = 1;
                            }
                            DataCube[0, s, i] = (float)r;
                            DataCube[1, s, i] = (float)(Math.Asin(cbc[DimY, s, i] / r)); //* 57.29578
                        }
                        progress = Convert.ToInt32(s * 100 / steps);
                        OnLoading(progress);
                    }
                }
                for (int s = 0; s < steps; s++)
                {
                    DataCube.DateTimes[s] = TimeService.Timeline[s];
                }
                DataCube.Variables     = this.Variables;
                DataCube.Topology      = (Grid as RegularGrid).Topology;
                DataCube.TimeBrowsable = true;
                OnLoaded(progresshandler);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #27
0
        /// <summary>
        /// Create a Datacube accoring to the Filter provided as input (filename).
        /// NOTE: The data will be sorted according to the way it is described
        /// in the Europe Map
        /// </summary>
        /// <param name="aFilterFileName">filter filename</param>
        public void SetupFilteredData(string aFilterFileName)
        {
            iFilteredColorMap = CreateColorMap(
                Color.FromArgb(0x0051a87b)
                , Color.FromArgb(0x00bad97a)
                , Color.FromArgb(0x00f0e978)
                , Color.FromArgb(0x00d07c59)
                );

            iFilteredSelectedColorMap = CreateColorMap(
                OverOperator(Color.FromArgb(0x0051a87b))
                , OverOperator(Color.FromArgb(0x00bad97a))
                , OverOperator(Color.FromArgb(0x00f0e978))
                , OverOperator(Color.FromArgb(0x00d07c59))
                );
            iFilteredCountryNames = new List <string>();
            iFilteredAcronyms     = ParseCountryFilter(KGeoDataPath + aFilterFileName);

            //Hashtable flagfiles = ParseFlagNames(KFlagDataPath + "flags.txt");
            //iFilteredFlagFiles = new List<string>();

            int numOfElements = 5;

            iFilteredData = new object[numOfElements, iFilteredAcronyms.Count];

            //Filter the countries
            uint counter = 0;

            foreach (string filteredCountry in iFilteredAcronyms)
            {
                Country country = (Country)iDb.countries[filteredCountry];

                //NOTE: numOfElements
                iFilteredData[0, counter] = counter;
                iFilteredData[1, counter] = country.medianAge;
                iFilteredData[2, counter] = (Math.Log(country.releases.Count, 2) > 0)? Math.Log(country.releases.Count, 2):0;
                iFilteredData[3, counter] = country.unemploymentRate;
                iFilteredData[4, counter] = country.gdbPerCapita;

                string countryTitleCase = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(country.name);
                countryTitleCase = ClipCountryName(countryTitleCase);

                iFilteredCountryNames.Add(countryTitleCase);
//                iFilteredFlagFiles.Add( (string)flagfiles[countryTitleCase]);
                counter++;
            }
            iFilteredDataCube = new DataCube();
            iFilteredDataCube.SetData(iFilteredData);

            iFilteredColorMap.Input = iFilteredDataCube;
            iFilteredColorMap.Index = 1;

            iFilteredSelectedColorMap.Input = iFilteredDataCube;
            iFilteredSelectedColorMap.Index = 1;
        }
        public override bool Load(int var_index, ICancelProgressHandler progress)
        {
            _ProgressHandler = progress;
            var full_file = Path.Combine(ModelService.WorkDirectory, _FileNames[var_index]);
            var grid      = Owner.Grid as MFGrid;

            _SelectedIndex = var_index;

            DataCube                = new DataCube <float>(Variables.Length, StepsToLoad, grid.ActiveCellCount, true);
            DataCube.Name           = "clm_input";
            DataCube.Variables      = this.Variables;
            DataCube.Topology       = (Owner.Grid as RegularGrid).Topology;
            DataCube.TimeBrowsable  = true;
            DataCube.AllowTableEdit = false;

            if (MasterPackage.ClimateInputFormat == FileFormat.Text)
            {
                MMSDataFile data = new MMSDataFile(full_file);
                data.NumTimeStep     = this.NumTimeStep;
                data.MaxTimeStep     = this.MaxTimeStep;
                data.DataCube        = this.DataCube;
                data.Loading        += stream_LoadingProgressChanged;
                data.DataCubeLoaded += data_DataCubeLoaded;
                data.LoadFailed     += data_LoadFailed;
                if (MasterPackage.UseGridClimate)
                {
                    data.Load(_GridHruMapping, var_index);
                }
                else
                {
                    data.LoadDataCube(var_index);
                }
            }
            else
            {
                DataCubeStreamReader stream = new DataCubeStreamReader(full_file);
                stream.NumTimeStep     = this.NumTimeStep;
                stream.MaxTimeStep     = this.MaxTimeStep;
                stream.DataCube        = this.DataCube;
                stream.Scale           = (float)this.ScaleFactor;
                stream.Loading        += stream_LoadingProgressChanged;
                stream.DataCubeLoaded += data_DataCubeLoaded;
                if (MasterPackage.UseGridClimate)
                {
                    stream.LoadDataCubeSingle(_GridHruMapping, var_index);
                }
                else
                {
                    stream.LoadDataCubeSingle(var_index);
                }
            }

            return(true);
        }
Exemple #29
0
        public DataCube <double> LoadTimeSeries()
        {
            DataCube <double> ts = null;
            var provider         = FileProviderFactory.GetProvider(FullPath);

            if (provider is ITimeSeriesFileProvider)
            {
                ts = (provider as ITimeSeriesFileProvider).Load();
            }
            return(ts);
        }
Exemple #30
0
        public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler)
        {
            StreamReader sr   = new StreamReader(DataFileName);
            string       line = sr.ReadLine();

            line = sr.ReadLine();
            var buf      = TypeConverterEx.Split <string>(line.Trim());
            int ncell    = int.Parse(buf[1]);
            var var_name = buf[0];

            line = sr.ReadLine();
            int nstep    = 0;
            int progress = 0;
            int count    = 1;

            while (!sr.EndOfStream)
            {
                line = sr.ReadLine();
                if (!TypeConverterEx.IsNull(line))
                {
                    nstep++;
                }
            }
            sr.Close();

            var mat_out = new DataCube <float>(1, nstep, ncell);

            mat_out.Name      = OutputMatrix;
            mat_out.Variables = new string[] { var_name };
            sr = new StreamReader(DataFileName);
            mat_out.DateTimes = new DateTime[nstep];
            for (int i = 0; i < 3; i++)
            {
                sr.ReadLine();
            }

            for (int t = 0; t < nstep; t++)
            {
                line = sr.ReadLine();
                var vec = TypeConverterEx.SkipSplit <float>(line, 6);
                mat_out[0, t.ToString(), ":"] = vec;
                var dd = TypeConverterEx.Split <int>(line, 3);
                mat_out.DateTimes [t] = new DateTime(dd[0], dd[1], dd[2]);
                progress = t * 100 / nstep;
                if (progress > count)
                {
                    cancelProgressHandler.Progress("Package_Tool", progress, "Processing step:" + (t + 1));
                    count++;
                }
            }
            Workspace.Add(mat_out);
            return(true);
        }