コード例 #1
0
        public void LoadImage(string path)
        {
            Fits     fits     = new Fits(path);
            ImageHDU hdu      = GetImageHDU(fits);
            int      axis_num = 0;

            if (hdu.Axes.Length == 2)
            {
                axis_num          = 2;
                this.rowsCount    = hdu.Axes[0];
                this.columnsCount = hdu.Axes[1];
            }
            if (hdu.Axes.Length == 3)
            {
                axis_num          = 3;
                this.rowsCount    = hdu.Axes[1];
                this.columnsCount = hdu.Axes[2];
            }
            this.bscale = hdu.BScale;
            this.bzero  = hdu.BZero;
            this.vals   = new double[rowsCount][];
            for (int i = 0; i < rowsCount; i++)
            {
                this.vals[i] = new double[columnsCount];
            }
            GetImageData(hdu, axis_num);
            fits.Stream.Close();
        }
コード例 #2
0
        public void AddReadNoise(string biasImagePath)
        {
            var bias      = new Fits(biasImagePath);
            var hdus      = bias.Read();
            var fitsImage = hdus.OfType <ImageHDU>().Single();
            var height    = fitsImage.Axes[0];
            var width     = fitsImage.Axes[1];
            var data      = fitsImage.Data.DataArray as Array;
            var lines     = data.Cast <short[]>().ToList();

            for (var y = 0; y < Image.Height; y++)
            {
                for (var x = 0; x < Image.Width; x++)
                {
                    var value = Image.At <ushort>(y, x);
                    var noise = lines[y].ElementAt(x) + fitsImage.BZero;

                    var noised = ((double)(value + noise));

                    if (noised > ushort.MaxValue)
                    {
                        noised = ushort.MaxValue;
                    }

                    Image.Set <ushort>(y, x, (ushort)noised);
                }
            }
        }
コード例 #3
0
        public static double[] ReadFrequencies(string file)
        {
            Fits     f = new Fits(file);
            ImageHDU h = (ImageHDU)f.ReadHDU();

            return((double[])h.Kernel);
        }
コード例 #4
0
        public static Complex[,,] ReadVisibilities(string file, int fromBl, int toBl, int timessamplesCount, int channelsCount, double norm)
        {
            var f = new Fits(file);
            var h = (ImageHDU)f.ReadHDU();
            //Double cube Dimensions: baseline, time, channel, pol, complex_component
            var vis_raw = (Array[])h.Kernel;
            var length  = toBl - fromBl;

            var visibilities = new Complex[length, timessamplesCount, channelsCount];

            for (int i = fromBl; i < toBl; i++)
            {
                Array[] bl = (Array[])vis_raw[i];
                for (int j = 0; j < timessamplesCount; j++)
                {
                    Array[] times = (Array[])bl[j];
                    for (int k = 0; k < channelsCount; k++)
                    {
                        Array[]  channel = (Array[])times[k];
                        double[] pol_XX  = (double[])channel[0];
                        double[] pol_YY  = (double[])channel[3];

                        //add polarizations XX and YY together to form Intensity Visibilities only
                        visibilities[i - fromBl, j, k] = new Complex(
                            (pol_XX[0] + pol_YY[0]) / norm,
                            (pol_XX[1] + pol_YY[1]) / norm);
                    }
                }
            }
            return(visibilities);
        }
コード例 #5
0
        public static double[,,] ReadUVW(string file, int fromBl, int toBl)
        {
            var f = new Fits(file);
            var h = (ImageHDU)f.ReadHDU();

            // Double Cube Dimensions: baseline, time, uvw
            var uvw_raw      = (Array[])h.Kernel;
            var time_samples = uvw_raw[0].Length;
            var length       = toBl - fromBl;

            var uvw = new double[length, time_samples, 3];

            for (long i = fromBl; i < toBl; i++)
            {
                Array[] bl = (Array[])uvw_raw[i];
                for (int j = 0; j < time_samples; j++)
                {
                    double[] values = (double[])bl[j];
                    uvw[i - fromBl, j, 0] = values[0];  //u
                    uvw[i - fromBl, j, 1] = -values[1]; //v
                    uvw[i - fromBl, j, 2] = values[2];  //w
                }
            }
            return(uvw);
        }
コード例 #6
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);
                }
            }
        }
コード例 #7
0
        public static Image <Gray, UInt16> ReadFITSFile(String ImagePath)
        {
            try
            {
                Fits     f = new Fits(ImagePath);
                ImageHDU h = (ImageHDU)f.ReadHDU();

                System.Array[] img = (System.Array[])h.Kernel;
                f.Close();
                int Width  = img.Count();
                int Height = img.GetLength(0);

                UInt16[][]           ImgConverted   = new UInt16[Width][];
                Image <Gray, UInt16> LastestImageCV = new Image <Gray, UInt16>(Width, Height);
                Int16 MaxNumber = Int16.MaxValue;

                for (int i = 0; i < Width; i++)
                {
                    ImgConverted[i] = new UInt16[Height];
                    for (int j = 0; j < Height; j++)
                    {
                        int Data = MaxNumber + (Int16)img[i].GetValue(j) + 1;
                        ImgConverted[i][j]           = (UInt16)Data;
                        LastestImageCV.Data[i, j, 0] = (UInt16)Data;
                    }
                }

                return(LastestImageCV);
            }
            catch
            {
                return(null);
            }
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: Gonen09/swastronomia
        public static void forma1()
        {
            /*Lectura parcial y automatica de parte de cabezera*/

            Fits f = new Fits("cubo_ing_comp.fits");

            BasicHDU[] hdus = f.Read();

            Console.WriteLine("Longitud: " + hdus.Length);

            for (int i = 0; i < hdus.Length; i += 1)
            {
                hdus[i].Info();
            }
            try {
            } catch {
            }

            ImageData datos = (ImageData)hdus[0].Kernel;

            float[,,] cubo = (float[, , ])datos.DataArray;

            Console.WriteLine("cubo: " + cubo[0, 0, 0]);

            f.Close();
        }
コード例 #9
0
        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();
            }
        }
コード例 #10
0
ファイル: Program.cs プロジェクト: rbliu/galaxymorphology
        private static double[,] GetImage(String fileName)
        {
            Fits     fits = new Fits(fileName);
            ImageHDU hdu  = GetImageHDU(fits);

            double[,] pixelValues = GetImageData(hdu);
            return(pixelValues);
        }
コード例 #11
0
        public static WarpImage16 Warp16FitsRead(string fname)
        {
            Fits imFit;

            imFit = new Fits(fname);

            return(new WarpImage16());
        }
コード例 #12
0
ファイル: ItemSlot.cs プロジェクト: Ellpeck/AnimalTownGame
 public ItemSlot(ItemInterface iface, Vector2 position, Item[] items, int index, Fits fits = null) : base(iface)
 {
     this.Items     = items;
     this.Index     = index;
     this.Interface = iface;
     this.Position  = position;
     this.fits      = fits;
 }
コード例 #13
0
ファイル: Program.cs プロジェクト: goodwink/sxASCOM
        private static void readImage(string fileName, out Int16[][] img, out Header hdr)
        {
            Fits f = new Fits(fileName);

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

            hdr = h.Header;

            Int32 height = h.Axes[0];
            Int32 width  = h.Axes[1];

            Int16 [][] inImg = new Int16[height][];
            int        x, y;

            img = new Int16[height][];

            object[] rows = (System.Array[])h.Kernel;

            for (y = 0; y < height / 2; y++)
            {
                inImg[y] = new Int16[2 * width];
                for (x = 0; x < width; x++)
                {
                    inImg[y][x]         = (Int16)((Int16[])rows[2 * y])[x];
                    inImg[y][x + width] = (Int16)((Int16[])rows[2 * y + 1])[x];
                }
            }

            for (y = 0; y < height; y++)
            {
                img[y] = new Int16[width];
                for (x = 0; x < width; x++)
                {
                    img[y][x] = (Int16)((Int16[])rows[y])[x];
                }
            }

#if false
            for (y = 0; y < height; y += 2)
            {
                int inX = 0;
                int inY = y / 2;

                img[y]     = new Int16[width];
                img[y + 1] = new Int16[width];

                for (x = 0; x < width; x += 2)
                {
                    img[y][x]         = inImg[inY][inX++];
                    img[y + 1][x]     = inImg[inY][inX++];
                    img[y + 1][x + 1] = inImg[inY][inX++];
                    img[y][x + 1]     = inImg[inY][inX++];
                }
            }
#endif
        }
コード例 #14
0
        public FitsFile(Fits nomTamFits, string filepath, string name, string molecule)
        {
            NomTamFits = nomTamFits;
            Filepath   = filepath;
            Name       = name;
            Molecule   = molecule;
            HDUS       = new List <HDU>();

            EvaluateHDUS();
        }
コード例 #15
0
        public static int CountBaselines(string file)
        {
            var f = new Fits(file);
            var h = (ImageHDU)f.ReadHDU();

            // Double Cube Dimensions: baseline, time, uvw
            var uvw_raw   = (Array[])h.Kernel;
            var baselines = uvw_raw.Length;

            return(baselines);
        }
コード例 #16
0
ファイル: Program.cs プロジェクト: goodwink/sxASCOM
        private static void xreadImage(string fileName, out Int16[][] img, out Header hdr)
        {
            Fits f = new Fits(fileName);

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

            hdr = h.Header;

            Int32 height = h.Axes[0];
            Int32 width  = h.Axes[1];

            object[] rows  = (System.Array[])h.Kernel;
            Int16[]  inImg = new Int16[height * width];

            int x, y;
            int idx = 0;

            for (y = 0; y < height; y++)
            {
                Int16[] row = (Int16[])rows[y];

                for (x = 0; x < width; x++)
                {
                    inImg[idx++] = row[x];
                }
            }

            Int16 [] outImg = new Int16[height * width];

            int srcIdx, destIdx;

            for (srcIdx = 0, destIdx = 0, y = 0; y < height / 2; y++)
            {
                for (x = 0; x < width / 2; x++)
                {
                    outImg[destIdx]           = inImg[srcIdx++];
                    outImg[width + destIdx++] = inImg[srcIdx++];
                    outImg[width + destIdx]   = inImg[srcIdx++];
                    outImg[destIdx++]         = inImg[srcIdx++];
                }
                destIdx += width;
            }

            img = new Int16[height][];
            for (srcIdx = 0, y = 0; y < height; y++)
            {
                img[y] = new Int16[width];

                for (x = 0; x < width; x++)
                {
                    img[y][x] = outImg[srcIdx++];
                }
            }
        }
コード例 #17
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);
        }
コード例 #18
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();
                }
            }
        }
コード例 #19
0
        public static ImageHDU GetImageHDU(Fits fits)
        {
            int i = 0;

            for (BasicHDU hdu = fits.getHDU(i); hdu != null; ++i)
            {
                if (hdu is ImageHDU)
                {
                    return((ImageHDU)hdu);
                }
            }

            return(null);
        }
コード例 #20
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();
            }
        }
コード例 #21
0
ファイル: FitsFileInfo.cs プロジェクト: Jusas/fits-archive
        public FitsFileInfo(string filePath)
        {
            FilePath = filePath;
            Fits f    = new Fits(filePath);
            var  hdus = f.Read();

            var headers = hdus.Where(hdu => hdu is ImageHDU).Select(hdu => hdu.Header);

            headers.ToList().ForEach(header =>
            {
                var cur        = header.GetCursor();
                object cardPtr = null;
                // return (HeaderCard) ((DictionaryEntry) this.cursor.Current).Value;
                while ((cardPtr = cur.Current) != null)
                {
                    var card = (HeaderCard)((DictionaryEntry)cardPtr).Value;
                    cur.MoveNext();
                    IList <HeaderKeyValue> keyValues = null;
                    keyValues         = _header.ContainsKey(card.Key) ? _header[card.Key] : new List <HeaderKeyValue>();
                    _header[card.Key] = keyValues;
                    var val           = card.IsStringValue ? new HeaderKeyValue(card.Key, card.Value, card.Comment) : ConvertType(card);
                    keyValues.Add(val);
                }
            });
            f.Close();

            //FileStream s = null;
            //using (s = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
            //{
            //    var md5 = MD5.Create();
            //    var hashBytes = md5.ComputeHash(s);
            //    FileHash = Convert.ToBase64String(hashBytes);
            //}
            // Instead of reading the whole file for hash (which will be slow, especially with large
            // files and there can be thousands to read per batch) we just read the headers,
            // and calculate a hash from them. We only care about the indexed headers anyway,
            // if they don't change, nothing in the index needs to change.

            var md5       = MD5.Create();
            var hashBytes = md5.ComputeHash(HeadersToBytes());

            FileHash = Convert.ToBase64String(hashBytes);
            FileInfo finfo = new FileInfo(filePath);

            FileSize = finfo.Length;
        }
コード例 #22
0
        /// <summary>
        /// Считывание заголовка HDU-блока
        /// </summary>
        /// <param name="file">имя файла</param>
        /// <param name="index">порядковый номер HDU-блока</param>
        /// <param name="table">список параметров из заголовка HDU-блока</param>
        /// <param name="hasImage">наличие изображения после заголовка</param>
        /// <returns></returns>
        public bool ReadHeader(string file, int index, out List <string[]> table, out bool hasImage)
        {
            fits = new Fits(file, FileAccess.Read);
            hdus = fits.Read();
            if (hdus == null)
            {
                table    = null;
                hasImage = false;
            }
            // Построчное считывание и сохранение параметров из заголовка: ключевое слово-значение-комментарий
            // сохранение в список table
            table = new List <string[]> {
            };
            var hdr = hdus[index].Header;

            for (int j = 0; j < hdr.NumberOfCards; j++)
            {
                var hc = new HeaderCard(hdr.GetCard(j));
                var sa = new string[3] {
                    hc.Key, hc.Value, hc.Comment
                };
                table.Add(sa);
            }

            // Кол-во осей в data unit
            int naxis = 0;

            if (hdr.ContainsKey("SIMPLE"))
            {
                // Для первого HDU
                if (hdr.ContainsKey("NAXIS"))
                {
                    naxis = hdr.GetIntValue("NAXIS");
                }
            }
            else if (hdr.ContainsKey("XTENSION"))
            {
                // Для остальных HDU-расширений
                if (hdr.ContainsKey("ZNAXIS"))
                {
                    naxis = hdr.GetIntValue("ZNAXIS");
                }
            }
            hasImage = (naxis == 2);
            return(table.Count != 0);
        }
コード例 #23
0
        // Make FITS file
        public void MakeFile(string FileName, float[][] ImgArray)
        {
            //Create a FITS file from an image:
            Fits f = new Fits();
            //BasicHDU h = FitsFactory.HDUFactory(ImgArray);
            BasicHDU h   = Fits.MakeHDU(ImgArray);
            Header   hdr = h.Header;

            //添加关键字
            hdr.AddValue("OBS2", "hss", "Observer");
            f.AddHDU(h);
            BufferedDataStream bf = new BufferedDataStream(new FileStream(FileName, FileMode.Create));

            f.Write(bf);
            bf.Flush();
            bf.Close();
        }
コード例 #24
0
ファイル: Program.cs プロジェクト: rbliu/galaxymorphology
        private static void SaveFITSAsImage(String inputFilename, String outputFilename)
        {
            Fits     fits   = new Fits(inputFilename);
            ImageHDU hdu    = GetImageHDU(fits);
            int      bitpix = hdu.BitPix;
            double   bZero  = hdu.BZero;
            double   bScale = hdu.BScale;
            double   min    = hdu.MinimumValue;
            double   max    = hdu.MaximumValue;

            double[,] a = GetImageData(hdu);

            for (int x = 0; x < a.GetLength(0); ++x)
            {
                for (int y = 0; y < a.GetLength(1); ++y)
                {
                    min = Math.Min(min, a[x, y]);
                    max = Math.Max(max, a[x, y]);
                }
            }

            Console.Out.WriteLine("Bitpix = " + bitpix + " bzero = " + bZero + " bscale = " + bScale +
                                  " min = " + min + " max = " + max);
            Bitmap bmp = new Bitmap(a.GetLength(0), a.GetLength(1));

            double nBins             = Math.Pow(2.0, 16.0) - 1.0;
            double linearScaleFactor = nBins / (max - min);
            double logScaleFactor    = nBins / Math.Log10(nBins);
            double byteScaleFactor   = 255.0 / nBins;
            double val = Double.NaN;

            for (int x = 0; x < a.GetLength(0); ++x)
            {
                for (int y = 0; y < a.GetLength(1); ++y)
                {
                    val  = a[x, y] - min;
                    val  = Math.Max(0.0, Math.Min(val, max - min));
                    val  = val <= 0.0 ? 0.0 : (Math.Log10(val * linearScaleFactor) * logScaleFactor);
                    val *= byteScaleFactor;
                    bmp.SetPixel(x, y, Color.FromArgb((int)val, (int)val, (int)val));
                }
            }

            bmp.Save(outputFilename, System.Drawing.Imaging.ImageFormat.Png);
        }
コード例 #25
0
        public static double[,] ReadImageDouble(string file)
        {
            Fits     f      = new Fits(file);
            ImageHDU h      = (ImageHDU)f.ReadHDU();
            var      imgRaw = (Array[])h.Kernel;

            var output = new double[imgRaw.Length, imgRaw[0].Length];

            for (int i = 0; i < imgRaw.Length; i++)
            {
                var row = (double[])imgRaw[i];
                for (int j = 0; j < row.Length; j++)
                {
                    output[i, j] = row[j];
                }
            }
            return(output);
        }
コード例 #26
0
ファイル: Fits.cs プロジェクト: evstigneevigorv/FitsAnalyzer
        public bool ReadHeader(string file, int index, out List <string[]> table, out bool hasImage)
        {
            fits = new Fits(file, FileAccess.Read);
            hdus = fits.Read();

            if (hdus == null)
            {
                table = null; hasImage = false; return(false);
            }

            table = new List <string[]> {
            };
            var hdr = hdus[index].Header;

            for (int j = 0; j < hdr.NumberOfCards; j++)
            {
                var hc = new HeaderCard(hdr.GetCard(j));
                var sa = new string[3] {
                    hc.Key, hc.Value, hc.Comment
                };
                table.Add(sa);
            }

            int naxis = 0;

            if (hdr.ContainsKey("SIMPLE"))
            {
                // Простой HDU
                if (hdr.ContainsKey("NAXIS"))
                {
                    naxis = hdr.GetIntValue("NAXIS");
                }
            }
            else if (hdr.ContainsKey("XTENSION"))
            {
                // HDU-расширение
                if (hdr.ContainsKey("ZNAXIS"))
                {
                    naxis = hdr.GetIntValue("ZNAXIS");
                }
            }
            hasImage = (naxis == 2);
            return(table.Count != 0);
        }
コード例 #27
0
        private static bool LoadFitsFileInternal <TData>(
            string fileName, IFITSTimeStampReader timeStampReader,
            out TData[,] pixels, out TData medianValue, out Type pixelDataType, out float frameExposure, out bool hasNegativePixels, out short minRawValue, out uint maxVal,
            CheckOpenedFitsFileCallback callback, LoadFitsDataCallback <TData> loadDataCallback)
        {
            Fits fitsFile = new Fits();

            using (BufferedFile bf = new BufferedFile(fileName, FileAccess.Read, FileShare.ReadWrite))
            {
                fitsFile.Read(bf);

                BasicHDU imageHDU    = fitsFile.GetHDU(0);
                Array    pixelsArray = (Array)imageHDU.Data.DataArray;
                return(LoadFitsDataInternal <TData>(
                           imageHDU, pixelsArray, fileName, timeStampReader,
                           out pixels, out medianValue, out pixelDataType, out frameExposure, out hasNegativePixels, out minRawValue, out maxVal,
                           callback, loadDataCallback));
            }
        }
コード例 #28
0
        public static double[,] ReadBeam(string file)
        {
            var f = new Fits(file);
            var h = (ImageHDU)f.ReadHDU();

            var raw = (Array[])h.Kernel;
            var img = new double[raw.Length, raw.Length];

            for (int i = 0; i < raw.Length; i++)
            {
                var col = (double[])raw[i];
                for (int j = 0; j < col.Length; j++)
                {
                    img[i, j] = col[j];
                }
            }

            return(img);
        }
コード例 #29
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();
            }
        }
コード例 #30
0
        public static ThreeAxisFITSCubeFrameStream OpenFile(string fileName, VideoController videoController)
        {
            var fitsFile     = new Fits();
            var bufferedFile = new BufferedFile(fileName, FileAccess.Read, FileShare.ReadWrite);

            fitsFile.Read(bufferedFile);

            var imageHDU = fitsFile.GetHDU(0);
            ThreeAxisFITSCubeFrameStream fitsStream = null;

            videoController.SetCursor(Cursors.WaitCursor);

            try
            {
                var hasher = new SHA1CryptoServiceProvider();
                hasher.Initialize();
                byte[] combinedFileNamesBytes = Encoding.UTF8.GetBytes(fileName);
                var    hash         = hasher.ComputeHash(combinedFileNamesBytes, 0, combinedFileNamesBytes.Length);
                var    fitsFileHash = Convert.ToBase64String(hash);

                var frm = new frmDefineFitsCube3D(imageHDU, fitsFileHash, videoController);
                if (videoController.ShowDialog(frm) == DialogResult.OK)
                {
                    videoController.SetFlipSettings(frm.FlipVertically, frm.FlipHorizontally);

                    fitsStream = new ThreeAxisFITSCubeFrameStream(
                        fileName, fitsFile, bufferedFile, imageHDU, frm.TimeStampReader,
                        frm.WidthIndex, frm.HeightIndex, frm.FrameIndex,
                        frm.MinPixelValue, frm.MaxPixelValue, frm.BitPix, frm.NegPixCorrection);
                }
            }
            finally
            {
                if (fitsStream == null)
                {
                    bufferedFile.Dispose();
                }
            }

            return(fitsStream);
        }