public static void BuildVSXCatalog(string directory) { string[] files = Directory.GetFiles(directory); int i = 0; var db = new StarCatalogContext(); foreach (string file in files) { StreamReader stream = File.OpenText(file); //int found = 0; //int notfound = 0; while (!stream.EndOfStream) { string entry = stream.ReadLine(); D_VSXEntry md = new D_VSXEntry(); FixedLengthReader flr = new FixedLengthReader(entry); flr.read(md); db.VSXEntries.Add(md); //string key = FindPPMXKey(md.RADeg, md.DEDeg); //if (key != null) //{ // found++; // _ppmdb.Put(WriteOptions.Default, key+".vsxinfo", entry); //} //else //{ // notfound++; // // Just use the closes match. // key = ConvertToKey(md.RADeg, md.DEDeg)[1]; // _ppmdb.Put(WriteOptions.Default, key + ".vsxinfo", entry); //} //if ((found+notfound)%100 == 0) // Console.Write(String.Format("\rFound: {0} Not Found: {1}", found, notfound)); if (i++ % 1000 == 0) { db.SaveChanges(); db.Dispose(); db = new StarCatalogContext(); } } Console.WriteLine(); Console.WriteLine("Completed loading catalog: " + file); } }
public static void GetFrameInfo(string directory, StarCatalogContext db) { string[] files = Directory.GetFiles(directory); foreach (string file in files) { string key = Path.GetFileName(file).Replace(".fit", ""); if (db.Frames.Where(x => x.File == key).Count() == 0) { D_Frame frame = new D_Frame() { File = key }; db.Frames.Add(frame); Fits f = new Fits(file); BasicHDU[] hdus = f.Read(); DateTime date = File.GetCreationTime(file); double jd = Math.Round(DateTimeToJulian(date), 5); for (int i = 0; i < hdus.Length; i += 1) { Header hdr = hdus[i].Header; date = DateTime.Parse(hdr.GetStringValue("DATE-OBS") + "Z"); jd = Math.Round(DateTimeToJulian(date), 5); frame.Time = jd; frame.Duration = (int)hdr.GetDoubleValue("EXPOSURE"); frame.ISO = (int)hdr.GetDoubleValue("GAIN"); frame.LocLat = GlobalVariables.LocLat; frame.LocLng = GlobalVariables.LocLng; frame.Camera = hdr.GetStringValue("INSTRUME"); frame.Reported = 0; } } } db.SaveChanges(); }
public static string GetAUID(D_VSXEntry entry) { using (var db = new StarCatalogContext()) { if (entry.AUID == null) { var html = GetHTML("http://www.aavso.org/vsx/index.php?view=detail.top&oid=" + entry.OID.Trim()); string pattern = @"\d+-\D+-\d+"; Regex rgx = new Regex(pattern, RegexOptions.IgnoreCase); MatchCollection matches = rgx.Matches(html); if (matches.Count > 0) { db.VSXEntries.Attach(entry); entry.AUID = matches[0].Value; } db.SaveChanges(); } return(entry.AUID); } }
public string LoadChart(string directory, StarCatalogContext db) { TextReader reader = File.OpenText(directory + "\\chart.csv"); var csv = new CsvReader(reader); csv.Configuration.Delimiter = "\t"; csv.ReadHeader(); string chartname = csv.FieldHeaders.GetValue(0).ToString(); if (db.ChartEntries.Where(x => x.Chart == chartname).Count() == 0) { csv.Read(); do { D_ChartEntry entry = new D_ChartEntry() { Chart = chartname, AUID = csv.GetField(0).ToString(), Label = csv.GetField(3).ToString(), Comments = csv.GetField(6).ToString() }; // prune off degree character entry.J2000_RA = GetCoord(csv.GetField(1).ToString()); entry.J2000_DEC = GetCoord(csv.GetField(2).ToString()); entry.VMag = GetValue(csv.GetField(4).ToString()); entry.BVColor = GetValue(csv.GetField(5).ToString()); db.ChartEntries.Add(entry); }while (csv.Read()); db.SaveChanges(); } csv.Dispose(); return(chartname); }
/// <summary> /// Load star-field specified in file /// </summary> /// <param name="filename">CSV file for star-field to load</param> /// <returns></returns> public void LoadStarField(string directory, string chartname, StarCatalogContext db) { // Load and parse csv. TextReader reader = File.OpenText(directory + "\\series_g.csv"); var csv = new CsvReader(reader); csv.Configuration.Delimiter = ";"; csv.ReadHeader(); // Load headers int fluxsample = 6; while (fluxsample < csv.FieldHeaders.Count()) { string filename = csv.FieldHeaders.GetValue(fluxsample++).ToString(); var match = db.Frames.Where(x => filename.Contains(x.File)).First(); match.Chart = chartname; frames.Add(match); } db.SaveChanges(); csv.Read(); csv.Read(); csv.Read(); int aperture = GetAperture(csv.GetField(6)); csv.Read(); // Pre-load all existing sample data for frames. List <F_Sample> existingsamples = new List <F_Sample>(); foreach (D_Frame d_frame in frames) { existingsamples.AddRange(db.Samples.Where(x => x.ID_Frame == d_frame.ID).ToList()); } int starcount = 0; Console.WriteLine(); do { // Create star if it doesn't exist. string name = csv.GetField(0); D_Star star = db.Stars.Where(x => x.Nameplate == name).FirstOrDefault(); if (star == null) { star = new D_Star() { Nameplate = name, J2000_RA = csv.GetField <double>(1), J2000_DEC = csv.GetField <double>(2) }; D_VSXEntry entry = StarCatalog.GetVSXEntry(star.J2000_RA, star.J2000_DEC); if (entry != null) { star.OID = Convert.ToInt32(entry.OID); } else { star.OID = -1; } db.Stars.Add(star); } stars.Add(star); ///// // Load flux samples. string parsedflux; fluxsample = 6; int frame = 0; int flag = csv.GetField <int>(3); while (csv.TryGetField(fluxsample++, out parsedflux)) { if (existingsamples.Where(x => x.ID_Frame == frames[frame].ID && x.ID_Star == star.ID).Count() == 0) { double flux = 0.0; double.TryParse(parsedflux, out flux); F_Sample sample = new F_Sample() { Star = star, ID_Frame = frames[frame].ID, Aperture = aperture, FluxV = flux }; // Save flux measurement as instrumental mag. samples.Add(sample); frame++; } } Console.Write("\rStars loaded: " + ++starcount); }while (csv.Read()); // Save stars db.SaveChanges(); // Supplement and persist sample data. if (samples.Count > 0) { foreach (F_Sample sample in samples) { // Set star ID. sample.ID_Star = sample.Star.ID; db.Samples.Add(sample); } LoadInstrumentalColorIndex(directory); LoadSNR(directory); db.SaveChanges(); } csv.Dispose(); }