Beispiel #1
0
        /// <summary>
        /// Computes the headers for a new FITS image.
        /// </summary>
        /// <param name="Core">Header values.</param>
        /// <returns>A HeaderTable instance for the new FITS image.</returns>
        public static HeaderTable GetHeader(FICHV Core)
        {
            Dictionary <string, string> records = (Core.WCS == null ? GetHeaderWithoutTransform(Core) : GetHeaderWithTransform(Core, true));
            HeaderTable het = records.ToDictionary((x) => x.Key, (x) => (MetadataRecord) new FITSMetadataRecord(x.Key, x.Value));

            return(het);
        }
Beispiel #2
0
        /// <summary>Computes the headers when the input image has no WCS information.</summary>
        static Dictionary <string, string> GetHeaderWithoutTransform(FICHV Core)
        {
            Dictionary <string, string> records = new Dictionary <string, string>()
            {
                { "SIMPLE", "   T" }, { "BITPIX", "   " + Core.BitPix.ToString() }, { "NAXIS", " 2" }, { "NAXIS1", "  " + Core.Width.ToString() }, { "NAXIS2", "  " + Core.Height.ToString() }
            };

            return(records);
        }
Beispiel #3
0
        /// <summary>
        /// Creates a shallow clone of the FICHV, except for the header table, which is regenerated.
        /// </summary>
        /// <param name="Original">Header to clone.</param>
        public FICHV CloneCore(FICHV Original)
        {
            FICHV f = new FICHV()
            {
                BitPix = Original.BitPix, Height = Original.Height, Width = Original.Width, WCS = Original.WCS
            };

            f.Header = FitsBuilder.GetHeader(f);
            return(f);
        }
Beispiel #4
0
        /// <summary>
        /// Creates a deep copy of the image's shallow header (FICHV defined headers).
        /// </summary>
        public FICHV CopyHeader()
        {
            int   BitPix = Header["BITPIX"].Int;
            FICHV f      = new FICHV()
            {
                BitPix = BitPix, Width = Width, Height = Height, WCS = Transform, ImageNumber = ImageNumber
            };

            return(f);
        }
Beispiel #5
0
        /// <summary>Computes the headers when the input image has WCS coordinates.</summary>
        static Dictionary <string, string> GetHeaderWithTransform(FICHV Core, bool RAFirst)
        {
            WCS.WCSViaProjection Transform = (WCS.WCSViaProjection)Core.WCS;
            string AlgName = Transform.ProjectionTransform.Name;

            Transform.ProjectionTransform.GetReferencePoints(out double RA, out double Dec);
            string T1 = " '" + (RAFirst ? "RA---" : "DEC--") + AlgName + "'";
            string T2 = " '" + (RAFirst ? "DEC--" : "RA---") + AlgName + "'";
            string V1 = "  " + ((RAFirst ? RA : Dec) * 180 / Math.PI).ToString("0.000000000000E+00");
            string V2 = "  " + ((RAFirst ? Dec : RA) * 180 / Math.PI).ToString("0.000000000000E+00");

            double[] Matrix = Transform.LinearTransform.Matrix;
            Dictionary <string, string> records = new Dictionary <string, string>()
            {
                { "SIMPLE", "   T" }, { "BITPIX", "   " + Core.BitPix.ToString() }, { "NAXIS", " 2" }, { "NAXIS1", "  " + Core.Width.ToString() }, { "NAXIS2", "  " + Core.Height.ToString() },
                { "CTYPE1", T1 }, { "CTYPE2", T2 }, { "CUNIT1", " 'deg     '" }, { "CUNIT2", " 'deg     '" }, { "CRVAL1", V1 }, { "CRVAL2", V2 },
                { "CRPIX1", "  " + (RAFirst?Matrix[4]:Matrix[5]).ToString("0.000000000000E+00") }, { "CRPIX2", "  " + (RAFirst?Matrix[5]:Matrix[4]).ToString("0.000000000000E+00") },
                { "CD1_1", "  " + (RAFirst?Matrix[0]:Matrix[2]).ToString("0.000000000000E+00") }, { "CD1_2", "  " + (RAFirst?Matrix[1]:Matrix[3]).ToString("0.000000000000E+00") },
                { "CD2_1", "  " + (RAFirst?Matrix[2]:Matrix[0]).ToString("0.000000000000E+00") }, { "CD2_2", "  " + (RAFirst?Matrix[3]:Matrix[1]).ToString("0.000000000000E+00") }
            };

            return(records);
        }
Beispiel #6
0
        /// <summary>
        /// Parses a <see cref="FICHV"/> out of the raw header table.
        /// </summary>
        /// <returns>The <see cref="FICHV"/> header table.</returns>
        /// <param name="ImageNumber">Image's number in the file.</param>
        /// <param name="Header">Image's raw header.</param>
        /// <param name="SkipWCS">If set to <c>true</c>, skip reading the WCS.</param>
        public static FICHV ParseHeaderTable(int ImageNumber, HeaderTable Header, bool SkipWCS)
        {
            FICHV data = new FICHV();

            data.Header      = Header;
            data.ImageNumber = ImageNumber;
            try
            {
                /* Parse image size */
                data.Width  = (uint)Header["NAXIS1"].Int;
                data.Height = (uint)Header["NAXIS2"].Int;
                if (data.Width > MaxSize || data.Height > MaxSize)
                {
                    throw new FITSFormatException("Image too large for Umbrella2.");
                }

                data.WCS = SkipWCS ? null : ParseWCS(Header);

                /* Computes BytesPerPixel and selects reading/writing functions */
                data.BitPix = Header["BITPIX"].Int;
            }
            catch (Exception ex) { throw new FITSFormatException("Cannot understand FITS file.", ex); }
            return(data);
        }
Beispiel #7
0
 /// <summary>Expansion of FICHV to pass-through constructor.</summary>
 protected FitsImage(FICHV data) : base(data)
 {
     ImageLock = new RWLockArea();
 }