コード例 #1
0
        /// <summary>
        /// Re-read results when it's simulated again.
        /// </summary>
        /// <param name="modelType"></param>
        public void reReadResults(SWATModelType modelType, SWATResultIntervalType interval)
        {
            ScenarioResult result = getModelResult(modelType, interval);

            if (result != null)
            {
                _results[getResultID(modelType, interval)] =
                    new ScenarioResult(
                        _modelfolder + @"\" + ScenarioResultStructure.getDatabaseName(modelType, interval), this, modelType, interval);
            }
        }
コード例 #2
0
        private void loadModelStructure()
        {
            _structure = new ScenarioResultStructure(this);

            _units.Clear();
            _unitIds.Clear();

            //subbasin first and then HRUs to add hru to subbasin
            _subbasins  = readUnitBasicInfo(SWATUnitType.SUB);
            _hrus       = readUnitBasicInfo(SWATUnitType.HRU);
            _reaches    = readUnitBasicInfo(SWATUnitType.RCH);
            _reservoirs = readUnitBasicInfo(SWATUnitType.RES);
            _watershed  = new Watershed(this);

            //check HRU area percentage in subbasin and watershed
            double watershedPercent = 0.0;

            foreach (HRU hru in _hrus.Values)
            {
                watershedPercent += hru.AreaFractionWatershed;
            }
            if (Math.Abs(watershedPercent - 1.0) > 0.01)
            {
                string msg = "The area of HRUs is not correct in result " + ModelType.ToString() +
                             ". They are not added to 1. The total is " + watershedPercent.ToString("F4") + ".Please check .hru files.";
                System.Diagnostics.Debug.WriteLine(msg);
                //SWAT_SQLite.showInformationWindow(msg);
            }


            foreach (Subbasin sub in _subbasins.Values)
            {
                double subbasinPercent = 0.0;
                foreach (HRU hru in sub.HRUs.Values)
                {
                    subbasinPercent += hru.AreaFractionSub;
                }
                if (Math.Abs(subbasinPercent - 1.0) > 0.01)
                {
                    string msg = "The area of HRUs is not correct for subbasin " + sub.ID.ToString() +
                                 " in result " + ModelType.ToString() + ". The total is " + subbasinPercent.ToString("F4") + ". Please check .hru files.";
                    System.Diagnostics.Debug.WriteLine(msg);
                    //SWAT_SQLite.showInformationWindow(msg); seems for swat2009 models there are too many warnings, just comment it. Or could just give one combined message. This is intent to give user some warning mesage.
                }
            }
        }
コード例 #3
0
        public Scenario(string f, Project prj)
            : base(f)
        {
            if (IsValid)
            {
                _prj         = prj;
                _modelfolder = Folder + DEFAULT_TXTINOUT_NAME;
                if (!Directory.Exists(_modelfolder))
                {
                    _modelfolder = null;
                    _isValid     = false;
                    _error       = _modelfolder + " doesn't exist!";
                    return;
                }
                _name = (new DirectoryInfo(Folder)).Name;

                //Regular SWAT and CanSWAT could run one a same model
                _hasResults = false;
                for (int i = Convert.ToInt32(ArcSWAT.SWATModelType.SWAT_488); i <= Convert.ToInt32(ArcSWAT.SWATModelType.CanSWAT); i++)
                {
                    SWATModelType modelType = (SWATModelType)i;
                    for (int j = Convert.ToInt32(SWATResultIntervalType.MONTHLY); j <= Convert.ToInt32(SWATResultIntervalType.YEARLY); j++)
                    {
                        SWATResultIntervalType interval = (SWATResultIntervalType)j;
                        ScenarioResult         result   = new ScenarioResult(
                            _modelfolder + @"\" + ScenarioResultStructure.getDatabaseName(modelType, interval),
                            this, modelType, interval);
                        if (result.Status == ScenarioResultStatus.NORMAL)
                        {
                            _hasResults = true;
                        }
                        _results.Add(getResultID(modelType, interval), result);
                    }
                }
            }
        }
コード例 #4
0
        protected override void read()
        {
            if (_table != null)
            {
                return;
            }

            //check the column name
            if (!_result.Columns.Contains(_col))
            {
                _table = new DataTable();
            }

            //add codes to output reading time for test
            DateTime readStartTime = DateTime.Now;

            //only use year parameter for daily
            int year = _year;

            if (_result.Interval != SWATResultIntervalType.DAILY &&
                _result.Interval != SWATResultIntervalType.MONTHLY)
            {
                year = -1;
            }

            //get return columns based on interval
            string cols = ScenarioResultStructure.getDateColumns(_result.Interval);

            if (cols.Length > 0)
            {
                cols += ",";
            }
            cols += _col;
            if (HasLanduseColumn)
            {
                cols += "," + ScenarioResultStructure.COLUMN_NAME_HRU_LANDUSE;
            }
            if (HasMgtOperationColumn)
            {
                cols += "," + ScenarioResultStructure.COLUMN_NAME_HRU_MGT_OPERATION + "," +
                        ScenarioResultStructure.COLUMN_NAME_HRU_MGT_LANDUSE;
            }

            //get year condition
            string yearCondition = "";

            if (year >= _result.Unit.Scenario.StartYear && year <= _result.Unit.Scenario.EndYear)
            {
                yearCondition = string.Format("({0}={1} or {0}={2})", ScenarioResultStructure.COLUMN_NAME_YEAR, year - 1, year); //read two years of data to consider hydrological year
            }
            //get id condition
            string idCondition = "";

            if (_result.Unit.Type != SWATUnitType.WSHD)
            {
                idCondition = string.Format("{0}={1}", _result.Unit.Type.ToString(), _result.Unit.ID);
            }

            string condition = idCondition;

            if (condition.Length > 0 && yearCondition.Length > 0)
            {
                condition += " and " + yearCondition;
            }
            if (condition.Length == 0 && yearCondition.Length > 0)
            {
                condition = yearCondition;
            }

            if (condition.Length > 0)
            {
                condition = " where " + condition;
            }

            DataTable dt = _result.Unit.Scenario.GetDataTable(
                string.Format("select {2} from {0} {1}",
                              _result.Name, condition, cols));

            //output reading time for test
            System.Diagnostics.Debug.WriteLine(string.Format("Reading {0}_{1}_{2}: {3} ms",
                                                             UnitResult.Unit.Type, Column, Year, DateTime.Now.Subtract(readStartTime).TotalMilliseconds));

            //add datetime column and calculate the date
            if (dt.Rows.Count > 0 && _result.Interval != SWATResultIntervalType.UNKNOWN)
            {
                dt.Columns.Add(SWATUnitResult.COLUMN_NAME_DATE, typeof(DateTime));
                foreach (DataRow r in dt.Rows)
                {
                    calculateDate(r);
                }
            }

            _table = dt;
        }