コード例 #1
0
 private void getRegionGroups()
 {
     foreach (int code in activeStationCodes)
     {
         bool inside = false;
         //get the ref station details
         Station s = stations.Find(x => x.code == code);
         if (s == null)
         {
             s = new Station();
         }
         foreach (Region r in regions)
         {
             double[] lonlat = new double[] { s.longitude, s.latitude };
             if (MapTools.isPointInPolygon(lonlat, r.vertices))
             {
                 inside = true;
                 var group = stationsByRegion.Find(x => x.name == r.name);
                 group.stationcodes.Add(s.code);
                 //break;
             }
         }
         //for the ones that fall outside
         if (!inside)
         {
             var groupOut = stationsByRegion.Find(x => x.name == "outside");
             groupOut.stationcodes.Add(s.code);
             //break;
         }
     }
 }
コード例 #2
0
        private void getAllIDEAMRegionGroups()
        {
            foreach (Station s in stations)
            {
                bool inside = false;

                foreach (Region r in regions)
                {
                    double[] lonlat = new double[] { s.longitude, s.latitude };
                    if (MapTools.isPointInPolygon(lonlat, r.vertices))
                    {
                        inside = true;
                        var group = stationsByRegion.Find(x => x.name == r.name);
                        group.stationcodes.Add(s.code);
                        //break;
                    }
                }
                //for the ones that fall outside
                if (!inside)
                {
                    var groupOut = stationsByRegion.Find(x => x.name == "outside");
                    groupOut.stationcodes.Add(s.code);
                    //break;
                }
            }
        }
コード例 #3
0
        public void printCityRegionGroups()
        {
            db = MongoTools.connect("mongodb://localhost", "climaColombia");
            var coll = db.GetCollection <StationGroup>("cityRegionGroups");

            allRegionGroups = coll.Find(FilterDefinition <StationGroup> .Empty).ToList();
            StreamWriter sw = new StreamWriter("regiongroups.csv");

            foreach (StationGroup sg in allRegionGroups)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append(sg.name + ",");
                foreach (int code in sg.stationcodes)
                {
                    sb.Append(code + ",");
                }
                sw.WriteLine(sb.ToString());
            }
            sw.Close();
            cities = MapTools.readCities();


            stations = StationGrouping.getAllStationsFromDB(db);
            JSONout.writeGroup(allRegionGroups, @"C:\Users\Admin\Documents\projects\IAPP\climaColombiaOrg\tools\cityGroups\cityregiongroups.json", stations, cities);
        }
コード例 #4
0
        private async Task cityGroupGraphic(StationGroup cityGroup, List <string> weatherCollections, string filename)
        {
            List <City> cities = MapTools.readCities();
            var         c      = cities.Find(x => x.name == cityGroup.name);
            //start end dates

            //set the master pane
            ZedGraphControl zgc    = new ZedGraphControl();
            MasterPane      master = zgc.MasterPane;

            master.Rect = new RectangleF(0, 0, 2000, 666 * weatherCollections.Count);
            master.PaneList.Clear();
            master.Title.Text = "City: " + c.name +
                                " lat: " + Math.Round(c.location[1], 3) + " lon: " + Math.Round(c.location[0], 3) +
                                " alt: " + (int)(c.elevation);// + "\nDate range: " + startDate.Year + "_" + startDate.Month + " >> " + endDate.Year + "_" + endDate.Month;
            master.Title.FontSpec   = new FontSpec("Arial", 7.0f, Color.Black, false, false, false);
            master.Margin.All       = 5;
            master.Legend.IsVisible = false;
            int    stationcode = 0;
            string vname       = "";
            string source      = "";
            int    freq        = 0;

            foreach (string wc in weatherCollections)
            {
                ////create one scatter for each stationvariable
                if (!wc.Contains("Clean"))
                {
                    string[] parts = wc.Split('_');
                    stationcode = Convert.ToInt32(parts[1]);
                    vname       = parts[4];
                    source      = parts[2];
                    freq        = Convert.ToInt32(parts[5]);

                    VariableMeta  meta      = AnnualSummary.getVariableMetaFromDB(vname, source, db);
                    PointPairList pointpair = new PointPairList();
                    pointpair = await GenerateHourlyData(wc, meta);

                    if (pointpair.Count > 0)
                    {
                        AddChartToMaster(master, pointpair, wc, vname, meta, false);
                    }
                }
            }
            //save graphic
            // Refigure the axis ranges for the GraphPanes
            zgc.AxisChange();
            // Layout the GraphPanes using a default Pane Layout
            Bitmap b = new Bitmap(2000, 666 * weatherCollections.Count);

            using (Graphics g = Graphics.FromImage(b))
            {
                master.SetLayout(g, PaneLayout.SingleColumn);
            }
            master.GetImage().Save(@"C:\Users\Admin\Documents\projects\IAPP\piloto\Climate\IDEAM\DailyAnalysis\" + filename + ".jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);
        }
コード例 #5
0
        private void defineCityRegionGroups()
        {
            var coll = db.GetCollection <StationGroup>("regionGroups");

            allRegionGroups = coll.Find(FilterDefinition <StationGroup> .Empty).ToList();
            cities          = MapTools.readCities();
            regions         = MapTools.readRegions();

            stations = StationGrouping.getAllStationsFromDB(db);
            setCityRegionGroups();
            //insertManyRecord("cityRegionGroups", cityRegionGroup);
        }
コード例 #6
0
        public void getData()
        {
            cities  = MapTools.readCities();
            regions = MapTools.readRegions();
            //get the city's region
            getCityRegionName();
            //gets all the stations for which we have data
            getActiveStations();

            //getStationsFromDB(db);//this is the annula summary
            //gets the full list of meta data for all stations NOAA and IDEAM
            stations = getAllStationsFromDB(db);
        }
コード例 #7
0
        public void printCityMeta()
        {
            var cityGroups = db.GetCollection <StationGroup>("cityGroups");
            List <StationGroup> stationgroups = cityGroups.Find(FilterDefinition <StationGroup> .Empty).ToList();
            List <City>         cities        = MapTools.readCities();
            StreamWriter        sw            = new StreamWriter(@"C: \Users\Admin\Documents\projects\clusterColombia\climacolombia\cities.csv", false, Encoding.UTF8);

            foreach (StationGroup sg in stationgroups)
            {
                var c = cities.Find(x => x.name == sg.name);
                sw.WriteLine(c.name + "," + c.location[1] + "," + c.location[0] + "," + (int)c.elevation);
            }
            sw.Close();
        }
コード例 #8
0
 private void getCityRegionName()
 {
     foreach (City c in cities)
     {
         foreach (Region r in regions)
         {
             if (MapTools.isPointInPolygon(c.location, r.vertices))
             {
                 //add the region group name to city
                 c.regionName = r.name;
                 break;
             }
         }
     }
 }
コード例 #9
0
        private string findRegion(City c)
        {
            string region = "undefined";

            foreach (Region r in regions)
            {
                if (MapTools.isPointInPolygon(c.location, r.vertices))
                {
                    //add the region group name to city
                    region = r.name;
                    break;
                }
            }
            return(region);
        }
コード例 #10
0
        public void readSythYearFromDB()
        {
            stations = StationGrouping.getAllStationsFromDB(db);
            //for the regional fix use:
            //var coll = db.GetCollection<StationGroup>("cityRegionGroups");
            //for the city groups use:
            var coll          = db.GetCollection <StationGroup>("cityGroups");
            var allCityGroups = coll.Find(FilterDefinition <StationGroup> .Empty).ToList();

            this.addLineToLogFile("INFO: preparing to read synthYearsFromDB");
            foreach (StationGroup sg in allCityGroups)
            {
                var city = sg.name;
                //the good from the city groups
                //city == "SANTA FE DE BOGOTÁ" || city == "BARRANQUILLA" || city == "CARTAGENA"||city == "LETICIA"
                if (city == "LETICIA")
                {
                    List <City> cities  = MapTools.readCities();
                    City        current = cities.Find(c => c.name == city);
                    writeEPW(current.name, current.location[1], current.location[0], current.elevation);
                }
            }
        }
コード例 #11
0
        private void epwHourlyData()
        {
            int    year     = 0;
            int    month    = 1;
            double pressure = MapTools.getStandardPressure(synthYear.info.elevation);
            int    hour     = 1;
            int    day      = 1;

            //loop all the time stamps in the first variable
            for (int i = 0; i < synthYear.variables[0].records.Count; i++)//should be 8760 hourly data lists
            {
                //{ "dbTemp", "rHumid", "wDir", "wSpeed", "diffuseHorizRad", "normDirectRad", "skyCover", "liquidPrecipDepth" };
                DateTime currentHr      = synthYear.variables[0].records[i].time;
                DateTime localcurrentHr = currentHr.ToLocalTime();
                if (localcurrentHr.DayOfYear == 67)
                {
                    var b = 0;
                }
                year  = localcurrentHr.Year;
                month = localcurrentHr.Month;
                day   = localcurrentHr.Day;
                hour  = localcurrentHr.Hour + 1;
                StringBuilder line = new StringBuilder();
                line.Append(year + ",");                                           // N1, \field Year
                line.Append(month.ToString() + ",");                               //N2, \field Month
                line.Append(day.ToString() + ",");                                 //N3, \field Day
                line.Append(hour.ToString() + ",");                                //N4, \field Hour
                line.Append("60,");                                                //N5, \field Minute
                line.Append(",");                                                  // A1, \field Data Source and Uncertainty Flags
                                                                                   //\note Initial day of weather file is checked by EnergyPlus for validity(as shown below)
                                                                                   //\note Each field is checked for "missing" as shown below.Reasonable values, calculated
                                                                                   //\note values or the last "good" value is substituted.

                line.Append(getValue("TS", currentHr) + ",");                      //N6, \field Dry Bulb Temperature\units C\minimum > -70\maximum < 70\missing 99.9
                line.Append(calcDewPoint(currentHr).ToString() + ",");             //N7, \field Dew Point Temperature\units C\minimum > -70\maximum < 70\missing 99.9
                line.Append(getValue("HR", currentHr) + ",");                      // N8, \field Relative Humidity\missing 999.\minimum 0\maximum 110
                line.Append(pressure.ToString() + ",");                            // N9, \field Atmospheric Station Pressure\units Pa\missing 999999.\minimum > 31000\maximum < 120000
                line.Append(extraterrestrialHorizRad(currentHr).ToString() + ","); //N10, \field Extraterrestrial Horizontal Radiation\units Wh / m2\missing 9999.\minimum 0
                line.Append("9999.,");                                             //N11, \field Extraterrestrial Direct Normal Radiation\units Wh / m2\missing 9999.\minimum 0
                line.Append("9999.,");                                             //N12, \field Horizontal Infrared Radiation Intensity\units Wh / m2\missing 9999.\minimum 0
                line.Append(getValue("RS", currentHr) + ",");                      //N13, \field Global Horizontal Radiation \units Wh / m2\missing 9999.\minimum 0
                line.Append(directRadiation(currentHr).ToString() + ",");          //N14, \field Direct Normal Radiation \units Wh / m2\missing 9999.\minimum 0
                line.Append(diffuseRadiation(currentHr).ToString() + ",");         //N15, \field Diffuse Horizontal Radiation\units Wh / m2\missing 9999.\minimum 0
                line.Append("999999.,");                                           //N16, \field Global Horizontal Illuminance\units lux\missing 999999.\note will be missing if > = 999900\minimum 0
                line.Append("999999.,");                                           //N17, \field Direct Normal Illuminance\units lux\missing 999999.\note will be missing if > = 999900\minimum 0
                line.Append("999999.,");                                           //N18, \field Diffuse Horizontal Illuminance\units lux\missing 999999.\note will be missing if > = 999900\minimum 0
                line.Append("9999.,");                                             //N19, \field Zenith Luminance\units Cd / m2\missing 9999.\note will be missing if > = 9999\minimum 0
                line.Append(getValue("DV", currentHr) + ",");                      //N20, \field Wind Direction\units degrees\missing 999.\minimum 0\maximum 360
                line.Append(getValue("VV", currentHr) + ",");                      //N21, \field Wind Speed\units m / s\missing 999.\minimum 0\maximum 40
                line.Append(getValue("NUB", currentHr) + ",");                     //N22, \field Total Sky Cover\missing 99\minimum 0\maximum 10
                line.Append("99,");                                                //N23, \field Opaque Sky Cover (used if Horizontal IR Intensity missing)\missing 99\minimum 0\maximum 10
                line.Append("9999,");                                              //N24, \field Visibility\units km\missing 9999
                line.Append("99999,");                                             //N25, \field Ceiling Height\units m\missing 99999
                line.Append(",");                                                  //N26, \field Present Weather Observation
                line.Append(",");                                                  // N27, \field Present Weather Codes
                line.Append("999,");                                               //N28, \field Precipitable Water\units mm\missing 999
                line.Append(".999,");                                              //N29, \field Aerosol Optical Depth\units thousandths\missing .999
                line.Append("999,");                                               //N30, \field Snow Depth\units cm\missing 999
                line.Append("99,");                                                //N31, \field Days Since Last Snowfall\missing 99
                line.Append("999,");                                               //N32, \field Albedo\missing 999
                line.Append(getValue("PR", currentHr) + ",");                      //N33, \field Liquid Precipitation Depth\units mm\missing 999
                line.Append("99");                                                 //N34; \field Liquid Precipitation Quantityunits hr\missing 99
                this.epw.WriteLine(line);
                line.Clear();
            }
        }
コード例 #12
0
        private void groupMonthBarChart(List <StationMonthly> group, string groupname)
        {
            List <Station> stations = StationGrouping.getAllStationsFromDB(db);
            List <City>    cities   = MapTools.readCities();
            var            c        = cities.Find(x => x.name == groupname);
            //find the first month and year of all monthlytotals
            //generate yaxis titles

            int startYear  = 0;
            int startMonth = 0;

            getGroupFirstMonth(group, ref startYear, ref startMonth);
            int endYear  = 0;
            int endMonth = 0;

            getGroupLastMonth(group, ref endYear, ref endMonth);
            DateTime startDate = new DateTime();

            if (startYear != 10000)
            {
                startDate = new DateTime(startYear, startMonth, 1);
            }
            else
            {
                startDate = new DateTime(1985, 1, 1);
            }
            DateTime endDate = new DateTime();

            if (endYear != 0)
            {
                endDate = new DateTime(endYear, endMonth, 1);
            }
            else
            {
                startDate = new DateTime(2018, 8, 1);
            }

            int monthsSpan = (int)Math.Round((endDate - startDate).Days / 30.0, 1);
            //set the master pane
            ZedGraphControl zgc    = new ZedGraphControl();
            MasterPane      master = zgc.MasterPane;

            master.Rect = new RectangleF(0, 0, 2000, 666 * group.Count);
            master.PaneList.Clear();
            master.Title.IsVisible = true;
            master.Title.Text      = "City: " + c.name +
                                     " lat: " + Math.Round(c.location[1], 3) + " lon: " + Math.Round(c.location[0], 3) +
                                     " alt: " + (int)(c.elevation) + "\nDate range: " + startDate.Year + "_" + startDate.Month + " >> " + endDate.Year + "_" + endDate.Month;
            master.Title.FontSpec   = new FontSpec("Arial", 7.0f, Color.Black, false, false, false);
            master.Margin.All       = 5;
            master.Legend.IsVisible = false;
            foreach (StationMonthly sm in group)
            {
                var       s     = stations.Find(x => x.code == sm.code);
                GraphPane pane1 = new GraphPane();
                pane1.BarSettings.Type = BarType.Stack;
                pane1.Border.IsVisible = false;
                pane1.Title.Text       = sm.code.ToString() + " " + s.name +
                                         " lat: " + Math.Round(s.latitude, 3) + " lon: " + Math.Round(s.longitude, 3) +
                                         " alt: " + (int)(s.elevation);
                //only show the first
                pane1.Legend.IsVisible = true;

                //pane1.YAxis.Title.Text = "n records";
                pane1.XAxis.Scale.Max           = monthsSpan;
                pane1.XAxis.Scale.MajorStep     = 12.0;
                pane1.XAxis.Scale.MinorStep     = 1.0;
                pane1.XAxis.MajorTic.Size       = 10;
                pane1.XAxis.MajorGrid.IsVisible = true;
                foreach (VariableMonthly vm in sm.variablesMonthly)
                {
                    List <double> xvalues = new List <double>();
                    for (int m = 0; m <= monthsSpan + 1; m++)
                    {
                        xvalues.Add(0);
                    }
                    Color col;
                    switch (vm.variableName)
                    {
                    case "VV":
                        col = Color.Red;
                        break;

                    case "DV":
                        col = Color.DodgerBlue;
                        break;

                    case "NUB":
                        col = Color.ForestGreen;
                        break;

                    case "RS":
                        col = Color.BlueViolet;
                        break;

                    case "TS":
                        col = Color.YellowGreen;
                        break;

                    case "HR":
                        col = Color.LawnGreen;
                        break;

                    case "PR":
                        col = Color.Orchid;
                        break;

                    default:
                        col = Color.Black;
                        break;
                    }
                    foreach (MonthTotal mt in vm.monthlytotals)
                    {
                        if (mt.month == 0 || mt.year == 0)
                        {
                            continue;
                        }
                        DateTime date = new DateTime(mt.year, mt.month, 1);

                        int datediff = (int)Math.Round((date - startDate).TotalDays / 30.0, 1);
                        if (vm.interval == 10)
                        {
                            xvalues[datediff] = mt.total / 6;
                        }
                        else
                        {
                            xvalues[datediff] = mt.total;
                        }
                    }
                    double[] x = xvalues.ToArray();

                    BarItem myBar = pane1.AddBar(vm.variableName, null, x, col);
                    myBar.Bar.Fill             = new Fill(col, col, col);
                    myBar.Bar.Border.IsVisible = false;
                }
                pane1.AxisChange();
                master.Add(pane1);
            }
            // Refigure the axis ranges for the GraphPanes
            zgc.AxisChange();
            // Layout the GraphPanes using a default Pane Layout
            Bitmap b = new Bitmap(2000, 666 * group.Count);

            using (Graphics g = Graphics.FromImage(b))
            {
                master.SetLayout(g, PaneLayout.SingleColumn);
            }
            master.GetImage().Save(@"C:\Users\Admin\Documents\projects\IAPP\piloto\Climate\groupMonthlyBarCharts\" + groupname + ".jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);
        }