Exemplo n.º 1
0
        private PlateSolveResult ReadAstapOutput(string outputfile)
        {
            var result = new PlateSolveResult()
            {
                Success = false
            };
            var dict = File.ReadLines(outputfile)
                       .Where(line => !string.IsNullOrWhiteSpace(line))
                       .Select(line => line.Split(new char[] { '=' }, 2, 0))
                       .ToDictionary(parts => parts[0], parts => parts[1]);

            //dict.TryGetValue("PLTSOLVD", out var solve_result);
            if (Convert.ToString(dict["PLTSOLVD"]) == "F")
            {
                return(result);
            }

            dict.TryGetValue("WARNING", out var warning);

            result.RaDeg = double.Parse(dict["CRVAL1"]) / 15;

            result.DecDeg      = double.Parse(dict["CRVAL2"]);
            result.Orientation = double.Parse(dict["CROTA2"]);
            //result.Orientation = double.Parsedict["CRVAL2"]);


            return(result);
        }
Exemplo n.º 2
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            string baseDirectory = InputFileTextBox.Text;

            IEnumerable <string> filesToSolve = Enumerable.Empty <string>();

            try
            {
                filesToSolve = System.IO.Directory.EnumerateFiles(baseDirectory, "*.fits", SearchOption.AllDirectories)
                               .Union(System.IO.Directory.EnumerateFiles(baseDirectory, "*.cr2", SearchOption.AllDirectories))
                               .Union(System.IO.Directory.EnumerateFiles(baseDirectory, "*.tif", SearchOption.AllDirectories));

                /*var directory = new DirectoryInfo(baseDirectory);
                 * var masks = new[] { "*.cr2", "*.fits" };
                 * filesToSolve =  masks.SelectMany(directory.EnumerateFiles); */
            }
            catch (IOException ex)
            {
                Console.WriteLine("Error enumerating path" + ex);
            }

            string outputcsv_log = Path.Combine(baseDirectory, "gofits-4.csv");
            var    csvWriter     = new ChoCSVWriter <FitsRecord>(outputcsv_log).WithFirstLineHeader();
            object WriteLock     = new object();


            ParallelOptions options = new ParallelOptions {
                MaxDegreeOfParallelism = 8
            };

            //foreach (var imageFilePath in filesToSolve)
            Parallel.ForEach(filesToSolve, options, imageFilePath =>
            {
                try
                {
                    //string outputFilePath = GetOutputPath(imageFilePath);
                    Console.Write(imageFilePath);
                    FitsHeader fitsheader = new FitsHeader();

                    if (Path.GetExtension(imageFilePath) == "fits")
                    {
                        fitsheader = ReadFits(imageFilePath);
                    }
                    Console.Write(",Input Ra (degrees): " + fitsheader.RaDeg);
                    Console.Write(",Input Dec (degrees):" + fitsheader.DecDeg);


                    PlateSolveResult platesolveresults = new PlateSolveResult();
                    //platesolveresults = ExecuteAstap(imageFilePath);


                    Console.Write(",Output Ra:  " + platesolveresults.RaDeg);
                    Console.Write(",Output Dec:  " + platesolveresults.DecDeg);
                    Console.WriteLine(",Output orientation:  " + platesolveresults.Orientation);

                    string AnalyzeFilename = Path.Combine(Path.GetDirectoryName(imageFilePath), Path.GetFileNameWithoutExtension(imageFilePath)) + ".csv";
                    ExecuteAnalyze(imageFilePath);

                    MakeThumbNails(imageFilePath, fitsheader.NAXIS1, fitsheader.NAXIS2);

                    lock (WriteLock)
                    {
                        FitsRecord fitsrecord        = new FitsRecord();
                        fitsrecord.Filename          = imageFilePath;
                        fitsrecord.RequestedDecDeg   = fitsheader.DecDeg;
                        fitsrecord.RequestedRaDeg    = fitsheader.RaDeg;
                        fitsrecord.SolvedDecDeg      = platesolveresults.DecDeg;
                        fitsrecord.SolvedRaDeg       = platesolveresults.RaDeg;
                        fitsrecord.SolvedOrientation = platesolveresults.Orientation;


                        fitsrecord.ImageType = fitsheader.ImageType;
                        fitsrecord.NAXIS1    = fitsheader.NAXIS1;
                        fitsrecord.NAXIS2    = fitsheader.NAXIS2;
                        fitsrecord.Exposure  = fitsheader.Exposure;

                        fitsrecord.LocalDate = fitsheader.LocalDate;
                        fitsrecord.UTCDate   = fitsheader.UTCDate;

                        fitsrecord.SiteLat     = fitsheader.SiteLat;
                        fitsrecord.SiteLong    = fitsheader.SiteLong;
                        fitsrecord.PixelPitch  = fitsheader.PixelPitch;
                        fitsrecord.Gain        = fitsheader.Gain;
                        fitsrecord.SensorTempC = fitsheader.SensorTempC;
                        fitsrecord.FocalLength = fitsheader.FocalLength;
                        fitsrecord.Object      = fitsheader.Object;

                        //                        public (double Alt, double Az) ConvertAltAz(double Lat, double Long, double RaHours, double DecHours, DateTime Date)

                        (fitsrecord.AltCalculated, fitsrecord.AzCalculated) = ConvertAltAz(fitsheader.SiteLat, fitsheader.SiteLong, fitsheader.RaDeg, fitsheader.DecDeg, fitsheader.LocalDate);
                        //    (fitsheader.LocalDate;);


                        if (File.Exists(AnalyzeFilename))
                        {
                            foreach (var rec in new ChoCSVReader <AnalyzeResult>(AnalyzeFilename).WithDelimiter(";"))
                            {
                                fitsrecord.FWHM       = rec.FWHM;
                                fitsrecord.RND        = rec.RND;
                                fitsrecord.background = rec.background;
                                fitsrecord.SNR        = rec.SNR;
                                fitsrecord.StarCount  = rec.StarCount;
                                fitsrecord.Collim     = rec.Collim;
                                fitsrecord.Unknown0   = rec.Unknown0;
                            }
                        }

                        csvWriter.Write(fitsrecord);
                    }