コード例 #1
0
        public static void Write(double[,,] img, string file = "Outputfile")
        {
            for (int k = 0; k < img.GetLength(0); k++)
            {
                var img2 = new double[img.GetLength(1)][];
                for (int i = 0; i < img2.Length; i++)
                {
                    var gg2 = new double[img.GetLength(2)];
                    img2[i] = gg2;
                    for (int j = 0; j < img.GetLength(2); j++)
                    {
                        gg2[j] = img[k, i, j];
                    }
                }

                var f    = new Fits();
                var hhdu = FitsFactory.HDUFactory(img2);
                f.AddHDU(hhdu);

                using (BufferedDataStream fstream = new BufferedDataStream(new FileStream(file + k + ".fits", FileMode.Create)))
                {
                    f.Write(fstream);
                }
            }
        }
コード例 #2
0
ファイル: IpcImageFits.cs プロジェクト: gsonnenf/Gstc.Imaging
        public static void ExportFits(float[][] imageData)   //TODO: Check if this works
        {
            var f = new nom.tam.fits.Fits();
            var h = FitsFactory.HDUFactory(imageData);

            f.AddHDU(h);
            var bufferedDataStream = new BufferedDataStream(new FileStream("Outputfile", FileMode.Create));

            f.Write(bufferedDataStream);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: goodwink/sxASCOM
        static void writeImage(string fileName, Int16[][] img, Header header)
        {
            Fits f = new Fits();
            BufferedDataStream s = new BufferedDataStream(new FileStream(fileName, FileMode.Create));
            //BufferedFile s = new BufferedFile(fileName, FileAccess.ReadWrite, FileShare.ReadWrite);
            BasicHDU h   = FitsFactory.HDUFactory(img);
            Header   hdr = h.Header;

            f.AddHDU(h);

            f.Write(s);
        }
コード例 #4
0
ファイル: fitsHeader.cs プロジェクト: mtodman/Nite-Opps
        public void saveImageToFitsForSolveOnly(string path, imageInfo image, Array imgArray)
        {
            var          imageData = (Array)ArrayFuncs.Flatten(imgArray);
            const double bZero     = 0;
            const double bScale    = 1.0;

            if (image.MaxADU <= 65535)
            {
                //bZero = 32768;
                //imageData = (ushort[])ArrayFuncs.ConvertArray(imageData, typeof(ushort));
            }
            int[] dims = ArrayFuncs.GetDimensions(imgArray);

            // put the image data in a basic HDU of the fits
            BasicHDU imageHdu = FitsFactory.HDUFactory(ArrayFuncs.Curl(imageData, dims));

            // Add the other fits fields to the HDU
            imageHdu.AddValue("BZERO", bZero, "");
            imageHdu.AddValue("BSCALE", bScale, "");
            imageHdu.AddValue("DATAMIN", 0.0, "");      // should this reflect the actual data values
            imageHdu.AddValue("DATAMAX", image.MaxADU, "pixel values above this level are considered saturated.");
            imageHdu.AddValue("DATE-OBS", image.LastExposureStartTime, "");
            imageHdu.AddValue("XPIXSZ", image.PixelSizeX * image.BinX, "physical X dimension of the sensor's pixels in microns"); //  (present only if the information is provided by the camera driver). Includes binning.
            imageHdu.AddValue("YPIXSZ", image.PixelSizeY * image.BinY, "physical Y dimension of the sensor's pixels in microns"); //  (present only if the information is provided by the camera driver). Includes binning.
            imageHdu.AddValue("XBINNING", image.BinX, "");
            imageHdu.AddValue("YBINNING", image.BinY, "");
            imageHdu.AddValue("OBJCTRA", image.RA, "Approximate Right Ascension of image centre");
            imageHdu.AddValue("OBJCTDEC", image.Dec, "Approximate Declination of image centre");

            // save it
            var fitsImage = new Fits();

            fitsImage.AddHDU(imageHdu); //Adds the actual image data (the header info already exists in imageHDU)
            FileStream fs = null;

            try
            {
                fs = new FileStream(path, FileMode.Create);
                using (var bds = new BufferedDataStream(fs))
                {
                    fs = null;
                    fitsImage.Write(bds);
                }
            }
            finally
            {
                if (fs != null)
                {
                    fs.Dispose();
                }
            }
        }
コード例 #5
0
            public void WriteFrameImpl(IntPtr intPtr, int p, RawFrameInfo info)
            {
                object   data = MarshalToCLR(intPtr, p);
                Fits     fits = new Fits();
                BasicHDU hdu  = FitsFactory.HDUFactory(data);

                if ((data is short[][] || data is short[][][]) && _significantBitDepth > 8)
                {
                    hdu.AddValue("BZERO", 32768.0, "");
                }

                AddMetadataToFrame(info, hdu);

                fits.AddHDU(hdu);
                using (FileStream fs = File.Create(Path.GetTempFileName()))
                {
                    using (BufferedDataStream f = new BufferedDataStream(fs))
                    {
                        fits.Write(f);
                    }
                }
            }
コード例 #6
0
        public static void Save(string strFile)
        {
            float[][] x = new float[30][];
            for (int i = 0; i < x.Length; i++)
            {
                x[i] = new float[30];
                for (int j = 0; j < x[i].Length; j++)
                {
                    x[i][j] = 3;
                }
            }

            bool t = typeof(Array).Equals(x.GetType());

            Fits   f   = new Fits();
            Header hdr = new Header();

            hdr.Bitpix = 8;
            hdr.Simple = true;
            hdr.Naxes  = 2;
            hdr.AddValue("NAXIS1", 30, "");
            hdr.AddValue("NAXIS2", 30, "");

            FitsFactory.UseAsciiTables = false;

            Data d = FitsFactory.DataFactory(hdr);



            BasicHDU h = FitsFactory.HDUFactory(x);



            f.addHDU(h);

            FileStream os = new FileStream(strFile, FileMode.Create);

            f.Write(os);
        }
コード例 #7
0
        public static void Write <T>(T[,] img, string file = "Outputfile.fits")
        {
            var img2 = new T[img.GetLength(0)][];

            for (int i = 0; i < img2.Length; i++)
            {
                var row = new T[img.GetLength(1)];
                img2[i] = row;
                for (int j = 0; j < img.GetLength(1); j++)
                {
                    row[j] = img[i, j];
                }
            }

            var f    = new Fits();
            var hhdu = FitsFactory.HDUFactory(img2);

            f.AddHDU(hhdu);

            using (BufferedDataStream fstream = new BufferedDataStream(new FileStream(file, FileMode.Create)))
            {
                f.Write(fstream);
            }
        }
コード例 #8
0
        public static void WriteImag(Complex[,] img, string file = "Outputfile_imag.fits")
        {
            var img2 = new double[img.GetLength(0)][];

            for (int i = 0; i < img2.Length; i++)
            {
                var gg2 = new double[img.GetLength(1)];
                img2[i] = gg2;
                for (int j = 0; j < img.GetLength(1); j++)
                {
                    gg2[j] = img[i, j].Imaginary;
                }
            }

            var f    = new Fits();
            var hhdu = FitsFactory.HDUFactory(img2);

            f.AddHDU(hhdu);

            using (BufferedDataStream fstream = new BufferedDataStream(new FileStream(file, FileMode.Create)))
            {
                f.Write(fstream);
            }
        }
コード例 #9
0
ファイル: fitsHeader.cs プロジェクト: mtodman/Nite-Opps
        public void saveImageToFits(string path, clsSharedData sd)
        {
            var          imageData = (Array)ArrayFuncs.Flatten(sd.imgArray);
            const double bZero     = 0;
            const double bScale    = 1.0;

            if (sd.theImage.MaxADU <= 65535)
            {
                //bZero = 32768;
                //imageData = (ushort[])ArrayFuncs.ConvertArray(imageData, typeof(ushort));
            }
            int[] dims = ArrayFuncs.GetDimensions(sd.imgArray);
            //Array image = ArrayFuncs.Curl(imageData, dims);

            // put the image data in a basic HDU of the fits
            BasicHDU imageHdu = FitsFactory.HDUFactory(ArrayFuncs.Curl(imageData, dims));

            // put the other data in the HDU
            imageHdu.AddValue("BZERO", bZero, "");
            imageHdu.AddValue("BSCALE", bScale, "");
            imageHdu.AddValue("DATAMIN", 0.0, "");      // should this reflect the actual data values
            imageHdu.AddValue("DATAMAX", sd.theImage.MaxADU, "pixel values above this level are considered saturated.");
            imageHdu.AddValue("INSTRUME", sd.theImage.Description, "");
            imageHdu.AddValue("EXPTIME", sd.theImage.LastExposureDuration, "duration of exposure in seconds.");
            imageHdu.AddValue("DATE-OBS", sd.theImage.LastExposureStartTime, "");
            imageHdu.AddValue("XPIXSZ", sd.theImage.PixelSizeX * sd.theImage.BinX, "physical X dimension of the sensor's pixels in microns"); //  (present only if the information is provided by the camera driver). Includes binning.
            imageHdu.AddValue("YPIXSZ", sd.theImage.PixelSizeY * sd.theImage.BinY, "physical Y dimension of the sensor's pixels in microns"); //  (present only if the information is provided by the camera driver). Includes binning.
            imageHdu.AddValue("XBINNING", sd.theImage.BinX, "");
            imageHdu.AddValue("YBINNING", sd.theImage.BinY, "");
            imageHdu.AddValue("XORGSUBF", sd.theImage.StartX, "subframe origin on X axis in binned pixels");
            imageHdu.AddValue("YORGSUBF", sd.theImage.StartY, "subframe origin on Y axis in binned pixels");
            imageHdu.AddValue("CBLACK", (double)sd.theImage.Min, "");
            imageHdu.AddValue("CWHITE", (double)sd.theImage.Max, "");
            imageHdu.AddValue("SWCREATE", "Nite Ops", "string indicating the software used to create the file");
            imageHdu.AddValue("OBJCTRA", sd.theImage.RA, "Approximate Right Ascension of image centre");
            imageHdu.AddValue("OBJCTDEC", sd.theImage.Dec, "Approximate Declination of image centre");
            imageHdu.AddValue("OBJCTALT", sd.theImage.Alt, "Approximate Altitude of image centre");
            imageHdu.AddValue("OBJCTAZ", sd.theImage.Az, "Approximate Azimuth of image centre");


            // extensions as specified by SBIG
            try
            {
                imageHdu.AddValue("CCD_TEMP", sd.theImage.CCDTemperature, "sensor temperature in degrees C");      // TODO sate this at the start of exposure . Absent if temperature is not available.
            }
            catch (Exception)
            {
                imageHdu.Info();
            }
            if (sd.theImage.CanSetCCDTemperature)
            {
                imageHdu.AddValue("SET-TEMP", sd.theImage.SetCCDTemperature, "CCD temperature setpoint in degrees C");
            }
            if (sd.theImage.objectName != "")
            {
                imageHdu.AddValue("OBJECT", sd.theImage.objectName, "The name of the object");
            }
            else
            {
                imageHdu.AddValue("OBJECT", "Unknown", "The name of the object");
            }
            imageHdu.AddValue("TELESCOP", Properties.Settings.Default.imaging_telescope, "Telescope used to acquire this image"); // user-entered information about the telescope used.
            imageHdu.AddValue("OBSERVER", Properties.Settings.Default.your_name, "Name of the observer");                         // user-entered information; the observer’s name.

            //DARKTIME – dark current integration time, if recorded. May be longer than exposure time.
            imageHdu.AddValue("IMAGETYP", sd.theImage.frameType + " Frame", "Type of image");
            //ISOSPEED – ISO camera setting, if camera uses ISO speeds.
            //JD_GEO – records the geocentric Julian Day of the start of exposure.
            //JD_HELIO – records the Heliocentric Julian Date at the exposure midpoint.
            //NOTES – user-entered information; free-form notes.
            //READOUTM – records the selected Readout Mode (if any) for the camera.

            //imageHdu.AddValue("SBSTDVER", "SBFITSEXT Version 1.0", "version of the SBIG FITS extensions supported");

            // save it
            var fitsImage = new Fits();

            fitsImage.AddHDU(imageHdu); //Adds the actual image data (the header info already exists in imageHDU)
            FileStream fs = null;

            try
            {
                fs = new FileStream(path, FileMode.Create);
                using (var bds = new BufferedDataStream(fs))
                {
                    fs = null;
                    fitsImage.Write(bds);
                }
            }
            finally
            {
                if (fs != null)
                {
                    fs.Dispose();
                }
            }
        }