public void ByDistanceFromLatLong(double[] lonlat, double ele) { stations = StationGrouping.getAllStationsFromDB(db); var siteCoord = new GeoCoordinate(lonlat[1], lonlat[0]); double dist = 0; double eleDiff = 0; StationGroup sg = new StationGroup(); sg.name = "sumapaz"; foreach (int actScode in activeStationCodes) { //get the ref station details //find within radius altitude if (stations.Exists(x => x.code == actScode)) { Station s = stations.Find(x => x.code == actScode); var sCoord = new GeoCoordinate(s.latitude, s.longitude); dist = siteCoord.GetDistanceTo(sCoord); eleDiff = ele - s.elevation; if (dist < 20000)//&& Math.Abs(eleDiff) < 100 { sg.stationcodes.Add(s.code); } } } CityYearBuilder cyb = new CityYearBuilder(); cyb.prepOneGroup(sg); cyb.makeSynthYear(sg, "medianHour"); }
private List <string> getStationsColNames(StationGroup cityGroup) { List <string> collections = MongoTools.collectionNames(db); string vname = ""; int scode = 0; string source = ""; int freq = 0; List <string> stationCollections = new List <string>(); foreach (string col in collections) { if (col[0] == 's') { string[] parts = col.Split('_'); try { scode = Convert.ToInt32(parts[1]); vname = parts[4]; source = parts[2]; freq = Convert.ToInt32(parts[5]); } catch (Exception e) { this.addLineToLogFile("WARN: error finding collection: " + col + "for city group:" + cityGroup.name); } foreach (int code in cityGroup.stationcodes) { if (scode == code) { stationCollections.Add(col); } } } } return(stationCollections); }
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); }
private void setCityGroups() { StationGroup sg = new StationGroup(); foreach (City c in cities) { sg = new StationGroup(); sg.name = c.name; stationsByCity.Add(sg); } }
public async Task makeSynthYear(StationGroup sg, string method) { List <IMongoCollection <RecordMongo> > stationData = new List <IMongoCollection <RecordMongo> >(); try { var stationCollNames = getStationsColNames(sg); await index60Minutes(stationCollNames); //ignore 10min collections stationData = getTheStationData(stationCollNames.FindAll(s => s.Contains("60"))); this.addLineToLogFile("INFO: found ref data for " + sg.name + " synth year"); } catch { this.addLineToLogFile("WARN: no ref data found for " + sg.name + " synth year"); } SyntheticYear synthYear = new SyntheticYear(); synthYear.name = sg.name; try { await getDaysForVariables(synthYear, stationData, method); this.addLineToLogFile("INFO: calculated data for " + sg.name + " synth year"); } catch { this.addLineToLogFile("WARN: error in calculating values for " + sg.name + " synth year"); } try { holeFiller(holeFinder(ref synthYear), ref synthYear); this.addLineToLogFile("INFO: hole filling succeeded for " + sg.name + " synth year"); } catch { this.addLineToLogFile("WARN: hole filling failed for " + sg.name + " synth year"); } try { insertSytheticYear(sg.name + "_" + method, synthYear); this.addLineToLogFile("INFO: " + sg.name + " synth year was stored in DB"); } catch { this.addLineToLogFile("WARN: " + sg.name + " synth year was not stored in DB"); } }
public async Task prepOneGroup(StationGroup sg) { try { var stationCollNames = getStationsColNames(sg); averageTenMinute(ref stationCollNames); await index60Minutes(stationCollNames); this.addLineToLogFile("INFO: " + sg.name + " data prep completed"); } catch { this.addLineToLogFile("WARN: " + sg.name + " data prep failed"); } }
private void setRegionalGroups() { //set up regional groups StationGroup sg = new StationGroup(); foreach (Region r in regions) { sg = new StationGroup(); sg.name = r.name; stationsByRegion.Add(sg); } //extra group for those outside sg = new StationGroup(); sg.name = "outside"; stationsByRegion.Add(sg); }
private void cityMonthlyGraphs(StationGroup cityGroup) { List <string> allVars = getIncludedVariables(); for (int m = 1; m < 13; m++) { foreach (string variable in allVars) { int chartCount = 0; foreach (string wc in weatherCollections) { if (wc.Contains(variable) && wc.Contains("Clean")) { chartCount++; } } monthsPerVariable(cityGroup.name, variable, m, chartCount); } } }
private void setCityRegionGroups() { StationGroup sg = new StationGroup(); foreach (City c in cities) { if (neededData.Exists(n => n.name == c.name)) { c.regionName = findRegion(c); sg = new StationGroup(); sg.name = c.name; cityRegionGroup.Add(sg); StationGroup regionStations = allRegionGroups.Find(rg => rg.name == c.regionName); foreach (int scode in regionStations.stationcodes) { Station s = stations.Find(p => p.code == scode); if (Math.Abs(s.elevation - c.elevation) < 100) { sg.stationcodes.Add(scode); } } } } }
private List <string> getStationsColNames(StationGroup cityGroup) { List <string> collections = MongoTools.collectionNames(db); List <string> stationCollections = new List <string>(); int scode = 0; foreach (string col in collections) { if (col[0] == 's') { string[] parts = col.Split('_'); scode = Convert.ToInt32(parts[1]); foreach (int code in cityGroup.stationcodes) { if (scode == code) { stationCollections.Add(col); } } } } return(stationCollections); }