internal void SaveFitsFrame(string fileName, int width, int height, uint[] framePixels, DateTime timeStamp, float exposureSeconds)
        {
            Fits f = new Fits();

            object data = SaveImageData(width, height, framePixels);

            BasicHDU imageHDU = Fits.MakeHDU(data);

            nom.tam.fits.Header hdr = imageHDU.Header;
            hdr.AddValue("SIMPLE", "T", null);

            hdr.AddValue("BITPIX", 32, null);

            hdr.AddValue("NAXIS", 2, null);
            hdr.AddValue("NAXIS1", width, null);
            hdr.AddValue("NAXIS2", height, null);

            hdr.AddValue("NOTES", m_Note, null);

            hdr.AddValue("EXPOSURE", exposureSeconds.ToString("0.000", CultureInfo.InvariantCulture), "Exposure, seconds");

            hdr.AddValue("DATE-OBS", timeStamp.ToString("yyyy-MM-ddTHH:mm:ss.fff", CultureInfo.InvariantCulture), m_DateObsComment);

            hdr.AddValue("TANGRAVE", string.Format("{0} v{1}", VersionHelper.AssemblyProduct, VersionHelper.AssemblyFileVersion), "Tangra version");
            hdr.AddValue("END", null, null);

            f.AddHDU(imageHDU);

            // Write a FITS file.
            using (BufferedFile bf = new BufferedFile(fileName, FileAccess.ReadWrite, FileShare.ReadWrite))
            {
                f.Write(bf);
                bf.Flush();
            }
        }
Example #2
0
        private void BuildHeader(Header header, Exposure exposure, Dictionary<string, object> metadata, long maxValue)
        {
            // Set BZERO to half of bitness (32768 for 16-bit)
            header.AddValue("BZERO", 0.5 * maxValue, "");
            header.AddValue("BSCALE", (double)1, "");
            header.AddValue("DATAMIN", 0.0, "");
            header.AddValue("DATAMAX", (double)exposure.MaxDepth, "");
            header.AddValue("CBLACK", (double)exposure.PixelMinValue, "");
            header.AddValue("CWHITE", (double)exposure.PixelMaxValue, "");
            header.AddValue("SWCREATE", "DSImager", "");

            if (metadata != null)
            {
                foreach (var entry in metadata)
                {
                    if (entry.Value is int)
                        header.AddValue(entry.Key, (int)entry.Value, "");
                    if (entry.Value is bool)
                        header.AddValue(entry.Key, (bool)entry.Value, "");
                    if (entry.Value is double)
                        header.AddValue(entry.Key, (double)entry.Value, "");
                    if (entry.Value is string)
                        header.AddValue(entry.Key, (string)entry.Value, "");
                    if (entry.Value is long)
                        header.AddValue(entry.Key, (long)entry.Value, "");
                }
            }
        }
Example #3
0
        internal void SaveFitsFrame(string fileName, Header header, int width, int height, object data)
        {
            Fits f = new Fits();

            BasicHDU imageHDU = Fits.MakeHDU(data);

            nom.tam.fits.Header hdr = imageHDU.Header;
            hdr.AddValue("SIMPLE", "T", null);

            hdr.AddValue("BZERO", 0, null);
            hdr.AddValue("BSCALE", 1, null);

            hdr.AddValue("NAXIS", 2, null);
            hdr.AddValue("NAXIS1", width, null);
            hdr.AddValue("NAXIS2", height, null);

            string[] RESERVED_KEYS = new string[] { "SIMPLE", "NAXIS", "NAXIS1", "NAXIS2", "BZERO", "BSCALE", "END" };

            var cursor = header.GetCursor();

            while (cursor.MoveNext())
            {
                HeaderCard card = header.FindCard((string)cursor.Key);
                if (card != null && !string.IsNullOrWhiteSpace(card.Key) && !RESERVED_KEYS.Contains(card.Key))
                {
                    hdr.AddValue(card.Key, card.Value, card.Comment);
                }
            }

            hdr.AddValue("NOTES", m_Note, null);
            hdr.AddValue("TANGRAVE", string.Format("{0} v{1}", VersionHelper.AssemblyProduct, VersionHelper.AssemblyFileVersion), "Tangra version");
            hdr.AddValue("END", null, null);

            f.AddHDU(imageHDU);

            // Write a FITS file.
            using (BufferedFile bf = new BufferedFile(fileName, FileAccess.ReadWrite, FileShare.ReadWrite))
            {
                f.Write(bf);
                bf.Flush();
            }
        }
Example #4
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");
        }
Example #5
0
        internal static void SaveDarkOrFlatFrame(string fileName, int width, int height, string notes, float[,] averagedData, float exposureSeconds, int numFrames)
        {
            Fits f = new Fits();

            object data = SaveImageData(width, height, averagedData);

            BasicHDU imageHDU = Fits.MakeHDU(data);

            nom.tam.fits.Header hdr = imageHDU.Header;
            hdr.AddValue("SIMPLE", "T", null);

            hdr.AddValue("BITPIX", -32 /* Floating Point Data*/, null);
            hdr.AddValue("NAXIS", 2, null);
            hdr.AddValue("NAXIS1", width, null);
            hdr.AddValue("NAXIS2", height, null);


            if (notes.Length > HeaderCard.MAX_VALUE_LENGTH)
            {
                notes = notes.Substring(0, HeaderCard.MAX_VALUE_LENGTH);
            }
            hdr.AddValue("NOTES", notes, null);

            if (exposureSeconds > 0)
            {
                hdr.AddValue("EXPOSURE", exposureSeconds.ToString("0.000", CultureInfo.InvariantCulture), null);
                hdr.AddValue("EXPTIME", exposureSeconds.ToString("0.000", CultureInfo.InvariantCulture), null);
            }

            hdr.AddValue("SNAPSHOT", numFrames.ToString(), null);
            hdr.AddValue("TANGRAVE", string.Format("{0} v{1}", VersionHelper.AssemblyProduct, VersionHelper.AssemblyFileVersion), null);
            if (TangraConfig.Settings.Generic.ReverseGammaCorrection)
            {
                hdr.AddValue("TANGAMMA", TangraConfig.Settings.Photometry.EncodingGamma.ToString("0.0000", CultureInfo.InvariantCulture), null);
            }
            if (TangraConfig.Settings.Generic.ReverseCameraResponse)
            {
                hdr.AddValue("TANCMRSP", ((int)TangraConfig.Settings.Photometry.KnownCameraResponse).ToString(CultureInfo.InvariantCulture), null);
            }

            f.AddHDU(imageHDU);

            // Write a FITS file.
            using (BufferedFile bf = new BufferedFile(fileName, FileAccess.ReadWrite, FileShare.ReadWrite))
            {
                f.Write(bf);
                bf.Flush();
            }
        }
        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], "");
        }
Example #7
0
 // .99.1 changes:
 /// <summary> Update the header after a deletion.</summary>
 public void UpdateAfterDelete(int oldNcol, Header hdr)
 {
     hdr.AddValue("NAXIS1", rowLen, "Bytes per row");
 }
Example #8
0
        /// <summary> Update a FITS header to reflect the current state of the data.</summary>
        internal override void FillHeader(Header h)
        {
            try
            {
                h.Xtension = "BINTABLE";
                h.Bitpix = 8;
                h.Naxes = 2;
                h.SetNaxis(1, rowLen);
                h.SetNaxis(2, nRow);
                h.AddValue("PCOUNT", heap.Size, null);
                h.AddValue("GCOUNT", 1, null);
                Cursor c = h.GetCursor();
                c.Key = "GCOUNT";
                c.MoveNext();
                c.Add("TFIELDS", new HeaderCard("TFIELDS", modelRow.Length, null));

                for(int i = 0; i < modelRow.Length; i += 1)
                {
                    if(i > 0)
                    {
                        h.PositionAfterIndex("TFORM", i);
                    }
                    FillForColumn(h, i, c);
                }
            }
            catch(HeaderCardException)
            {
                Console.Error.WriteLine("Impossible exception");
            }
        }
Example #9
0
        internal void SaveFitsFrame(int frameNo, string fileName, int width, int height, uint[] framePixels, DateTime timeStamp, float exposureSeconds)
        {
            Fits f = new Fits();

            object data = m_ExportAs8BitFloat
                ? (object)SaveNormalizedFloatImageData(width, height, framePixels)
                : (object)SaveImageData(width, height, framePixels);

            BasicHDU imageHDU = Fits.MakeHDU(data);

            nom.tam.fits.Header hdr = imageHDU.Header;
            hdr.AddValue("SIMPLE", "T", null);

            hdr.AddValue("BITPIX", m_ExportAs8BitFloat ? -32 : 32, null);

            hdr.AddValue("BZERO", 0, null);
            hdr.AddValue("BSCALE", 1, null);

            hdr.AddValue("NAXIS", 2, null);
            hdr.AddValue("NAXIS1", width, null);
            hdr.AddValue("NAXIS2", height, null);

            hdr.AddValue("EXPOSURE", exposureSeconds.ToString("0.000", CultureInfo.InvariantCulture), "Exposure, seconds");

            hdr.AddValue("DATE-OBS", timeStamp.ToString("yyyy-MM-ddTHH:mm:ss.fff", CultureInfo.InvariantCulture), m_DateObsComment);

            hdr.AddValue("CAMERA", m_VideoCamera, "Video camera model (observer specified)");

            hdr.AddValue("FILENAME", m_VideoController.FileName, null);
            hdr.AddValue("FRAMENO", frameNo, null);

            if (m_VideoFormat == VideoFileFormat.AAV || m_VideoFormat == VideoFileFormat.AAV2)
            {
                hdr.AddValue("NOTES", "No instrumental delay has been applied to DATE-OBS.", null);

                if (m_ExportAs8BitFloat)
                {
                    hdr.AddValue("VIDEOFMT", m_NativeFormat, "Native analogue video format");
                    if (m_IntegrationRate > 0)
                    {
                        hdr.AddValue("INTGRRTE", m_IntegrationRate.ToString(), "Integration rate in video frames");
                    }
                }
            }
            else
            {
                hdr.AddValue("NOTES", string.Format("Converted from {0} file.", m_VideoFormat), null);
            }

            foreach (var kvp in m_AdditionalFileHeaders)
            {
                hdr.AddValue(kvp.Key, kvp.Value.Item1, kvp.Value.Item2);
            }

            hdr.AddValue("TANGRAVE", string.Format("{0} v{1}", VersionHelper.AssemblyProduct, VersionHelper.AssemblyFileVersion), "Tangra version");
            hdr.AddValue("END", null, null);

            f.AddHDU(imageHDU);

            // Write a FITS file.
            using (BufferedFile bf = new BufferedFile(fileName, FileAccess.ReadWrite, FileShare.ReadWrite))
            {
                f.Write(bf);
                bf.Flush();
            }
        }
Example #10
0
 /// <summary>Fill header with keywords that describe data.
 /// </summary>
 /// <param name="head">The FITS header
 /// 
 /// </param>
 internal override void FillHeader(Header head)
 {
     try
     {
         head.Xtension = "UNKNOWN";
         head.Bitpix = 8;
         head.Naxes = 1;
         head.AddValue("NAXIS1", byteSize, " Number of Bytes ");
         head.AddValue("PCOUNT", 0, null);
         head.AddValue("GCOUNT", 1, null);
         head.AddValue("EXTEND", true, "Extensions are permitted"); // Just in case!
     }
     catch (HeaderCardException e)
     {
         System.Console.Error.WriteLine("Unable to create unknown header:" + e);
     }
 }
Example #11
0
        /// .99.1 changes
        /// <summary>
        /// This is called after we delete columns.  The HDU
        /// doesn't know how to update the TBCOL entries.
        /// </summary>
        public virtual void UpdateAfterDelete(int oldNCol, Header hdr)
        {
            int offset = 0;
            for (int i=0; i<nFields; i += 1)
            {
                offsets[i] = offset;

                // .99.2 changes:
                // Fixed offsets in columns after column was deleted.
                // hdr.AddValue("TBCOL"+(i+1), offset, " Column offset ")
                hdr.AddValue("TBCOL"+(i+1), offset+1, " Column offset ");

                offset += lengths[i] + 1;
            }
            for (int i=nFields; i<oldNCol; i += 1)
            {
                hdr.DeleteKey("TBCOL"+(i+1));
            }

            hdr.AddValue("NAXIS1", rowLen, "Size of row in bytes");
        }