Ejemplo n.º 1
0
        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();
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>Fill header with keywords that describe image data.</summary>
        /// <param name="head">The FITS header</param>
        /// <exception cref="FitsException"> FitsException if the object does not contain valid image data.</exception>
        internal override void FillHeader(Header head)
        {
            if (dataArray == null)
            {
                head.NullImage();
                return;
            }

            Type classname = ArrayFuncs.GetBaseClass(dataArray);

            int[] dimens = ArrayFuncs.GetDimensions(dataArray);

            if (dimens == null || dimens.Length == 0)
            {
                throw new FitsException("Image data object not array. ");
            }


            int bitpix;

            // Changed from classname[dimens.Length] to classname[classname.IndexOf(".") + 1]

            switch (classname.ToString())
            {
            case "System.Byte":
                bitpix = 8;
                break;

            case "System.Int16":
                bitpix = 16;
                break;

            case "System.Int32":
                bitpix = 32;
                break;

            case "System.Int64":
                bitpix = 64;
                break;

            case "System.Single":
                bitpix = -32;
                break;

            case "System.Double":
                bitpix = -64;
                break;

            default:
                throw new FitsException("Invalid Object Type for FITS data:" +
                                        classname.ToString());
            }

            // if this is neither a primary header nor an image extension,
            // make it a primary header
            head.Simple = true;
            head.Bitpix = bitpix;
            head.Naxes  = dimens.Length;

            for (int i = 1; i <= dimens.Length; i += 1)
            {
                if (dimens[i - 1] == -1)
                {
                    throw new FitsException("Unfilled array for dimension: " + i);
                }
                head.SetNaxis(i, dimens[dimens.Length - i]);
            }

            // suggested in .97 version: EXTEND keyword added before PCOUNT and GCOUNT.
            head.AddValue("EXTEND", true, "Extension permitted"); // Just in case!
            head.AddValue("PCOUNT", 0, "No extra parameters");
            head.AddValue("GCOUNT", 1, "One group");
        }
Ejemplo n.º 3
0
        internal override void FillHeader(Header h)
        {
            //int[] dims = ArrayFuncs.GetDimensions(dataArray);
            int[] dims = ArrayFuncs.GetDimensions(dataArray.GetValue(0));

            //if (dataArray.Length <= 0 || dataArray[0].Length != 2)
            if (dims.Length != 2)
            {
                throw new FitsException("Data not conformable to Random Groups");
            }

            int gcount = dataArray.Length;
            //Object paraSamp = dataArray[0][0];
            //Object dataSamp = dataArray[0][1];
            Object paraSamp = ((Array)dataArray.GetValue(0)).GetValue(0);
            Object dataSamp = ((Array)dataArray.GetValue(0)).GetValue(1);

            Type pbase = ArrayFuncs.GetBaseClass(paraSamp);
            Type dbase = ArrayFuncs.GetBaseClass(dataSamp);

            if (pbase != dbase)
            {
                throw new FitsException("Data and parameters do not agree in type for random group");
            }

            int[] pdims = ArrayFuncs.GetDimensions(paraSamp);
            int[] ddims = ArrayFuncs.GetDimensions(dataSamp);

            if (pdims.Length != 1)
            {
                throw new FitsException("Parameters are not 1 d array for random groups");
            }

            // Got the information we need to build the header.

            h.Simple = true;
            if (dbase == typeof(byte))
            {
                h.Bitpix = 8;
            }
            else if (dbase == typeof(short))
            {
                h.Bitpix = 16;
            }
            else if (dbase == typeof(int))
            {
                h.Bitpix = 32;
            }
            else if (dbase == typeof(long))
            {
                // Non-standard
                h.Bitpix = 64;
            }
            else if (dbase == typeof(float))
            {
                h.Bitpix = -32;
            }
            else if (dbase == typeof(double))
            {
                h.Bitpix = -64;
            }
            else
            {
                throw new FitsException("Data type:" + dbase + " not supported for random groups");
            }

            h.Naxes = ddims.Length + 1;
            h.AddValue("NAXIS1", 0, "");
            for (int i = 2; i <= ddims.Length + 1; i += 1)
            {
                h.AddValue("NAXIS" + i, ddims[i - 2], "");
            }

            h.AddValue("GROUPS", true, "");
            h.AddValue("GCOUNT", dataArray.Length, "");
            h.AddValue("PCOUNT", pdims[0], "");
        }
Ejemplo n.º 4
0
        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();
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>Fill header with keywords that describe image data.</summary>
        /// <param name="head">The FITS header</param>
        /// <exception cref=""> FitsException if the object does not contain valid image data.</exception>
        internal override void FillHeader(Header head)
        {
            if (dataArray == null)
            {
                head.NullImage();
                return;
            }

            System.String classname = dataArray.GetType().FullName;

            int[] dimens = ArrayFuncs.GetDimensions(dataArray);

            if (dimens == null || dimens.Length == 0)
            {
                throw new FitsException("Image data object not array");
            }


            int bitpix;

            switch (classname[dimens.Length])
            {
            case 'B':
                bitpix = 8;
                break;

            case 'S':
                bitpix = 16;
                break;

            case 'I':
                bitpix = 32;
                break;

            case 'J':
                bitpix = 64;
                break;

            case 'F':
                bitpix = -32;
                break;

            case 'D':
                bitpix = -64;
                break;

            default:
                throw new FitsException("Invalid Object Type for FITS data:" + classname[dimens.Length]);
            }

            // if this is neither a primary header nor an image extension,
            // make it a primary header
            head.Simple = true;
            head.Bitpix = bitpix;
            head.Naxes  = dimens.Length;

            for (int i = 1; i <= dimens.Length; i += 1)
            {
                if (dimens[i - 1] == -1)
                {
                    throw new FitsException("Unfilled array for dimension: " + i);
                }
                head.SetNaxis(i, dimens[dimens.Length - i]);
            }
            head.AddValue("EXTEND", true, "Extension permitted");             // Just in case!
            head.AddValue("PCOUNT", 0, "No extra parameters");
            head.AddValue("GCOUNT", 1, "One group");
        }