コード例 #1
0
        private FitsHeader  ReadFits(string Filename)
        {
/*            double RA;
 *          double DEC;
 *          float[][] imageData;
 *          string LocalDate;
 *          double SiteLong;
 *          double SiteLat; */
            FitsHeader fitsheader = new FitsHeader();


            try
            {
                Fits f = new Fits(Filename);

                ImageHDU h = (ImageHDU)f.ReadHDU();


                //other things we might want:
                // IMAGETYP= 'LIGHT'
                // NAXIS1  =                 7380 /
                // NAXIS2 = 4908
                // EXPTIME =                  6.0 / [s] Exposure duration
                // DATE-LOC= '2020-10-07T01:28:55.164' / Time of observation (local)
                //     GAIN    =                 1208 / Sensor gain
                //     XPIXSZ  =                 4.88 / [um] Pixel X axis size
                // YPIXSZ = 4.88 / [um] Pixel Y axis size
                //     SITELAT =     47.6077777777778 / [deg] Observation site latitude
                // SITELONG = -122.335 / [deg] Observation site longitude]

                fitsheader.ImageType = h.Header.GetStringValue("IMAGETYP");
                fitsheader.NAXIS1    = h.Header.GetIntValue("NAXIS1");
                fitsheader.NAXIS2    = h.Header.GetIntValue("NAXIS2");
                fitsheader.DecDeg    = h.Header.GetDoubleValue("DEC");
                fitsheader.RaDeg     = h.Header.GetDoubleValue("RA") / 15;
                fitsheader.Exposure  = h.Header.GetFloatValue("EXPOSURE");


                fitsheader.LocalDate = DateTime.ParseExact(h.Header.GetStringValue("DATE-LOC"), "yyyy-MM-ddTHH:mm:ss.fff", CultureInfo.InvariantCulture);
                fitsheader.UTCDate   = DateTime.ParseExact(h.Header.GetStringValue("DATE-OBS"), "yyyy-MM-ddTHH:mm:ss.fff", CultureInfo.InvariantCulture);

                fitsheader.SiteLat     = h.Header.GetDoubleValue("SITELAT");
                fitsheader.SiteLong    = h.Header.GetDoubleValue("SITELONG");
                fitsheader.PixelPitch  = h.Header.GetFloatValue("XPIXSZ");
                fitsheader.Gain        = h.Header.GetIntValue("GAIN");
                fitsheader.SensorTempC = h.Header.GetFloatValue("CCD-TEMP");
                fitsheader.FocalLength = h.Header.GetFloatValue("FOCALLEN");
                fitsheader.Object      = h.Header.GetStringValue("OBJECT");


                /*RA = h.Header.GetDoubleValue("RA") / 15;
                 * DEC = h.Header.GetDoubleValue("DEC");
                 * LocalDate = h.Header.GetStringValue("DATE-LOC");
                 * SiteLat = h.Header.GetDoubleValue("SITELAT");
                 * SiteLong = h.Header.GetDoubleValue("SITELAT");
                 *
                 *
                 * //imageData = (float[][])h.Kernel; */

                f.Close();
            }
            catch { Console.WriteLine("Error opening fits.."); return(fitsheader); }

            return(fitsheader);
        }
コード例 #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);
                    }