Ejemplo n.º 1
0
            public PngOutputStream(Stream outputStream, int imageWidth, int imageHeight, CompressionLevel compressionLevel, bool leaveOpen, int bufferSize)
            {
                if (!outputStream.CanWrite)
                {
                    throw new ArgumentException("inputStream must be writable");
                }

                if (imageWidth < 1)
                {
                    throw new ArgumentException("Width must be greater than zero");
                }

                if (imageWidth < 1)
                {
                    throw new ArgumentException("Width must be greater than zero");
                }

                _compressionOutputStream = new BufferedDataStream();

                _outputStream          = outputStream;
                _leaveOutputStreamOpen = leaveOpen;
                _imageWidth            = imageWidth;
                _imageHeight           = imageHeight;
                _totalLength           = Math.BigMul(imageWidth, imageHeight * _BytesPerPixel);
                _bufferSize            = bufferSize;

                _compressionStream = new ZlibAlgorithm()
                                     .CreateCompressor(new CompressionOptions(Api.CompressionType.Zlib, compressionLevel))
                                     .CreateOutputStream(_compressionOutputStream, true, _bufferSize);

                InitializePng();
                WriteHeader();
            }
Ejemplo n.º 2
0
        public static void  BuffStreamSimpleTest(System.String filename, int numIts, int[] in_Renamed, int[] in2)
        {
            System.Console.Out.WriteLine("New libraries:  nom.tam.BufferedDataXXputStream");
            System.Console.Out.WriteLine("                Using non-array I/O");
            BufferedDataStream f = new BufferedDataStream(new FileStream(filename, FileMode.Create), 32768);

            ResetTime();
            int dim = in_Renamed.Length;

            for (int j = 0; j < numIts; j += 1)
            {
                for (int i = 0; i < dim; i += 1)
                {
                    f.Write(in_Renamed[i]);
                }
            }
            f.Flush();
            f.Close();
            System.Console.Out.WriteLine("  BDS Int write: " + (4 * dim * numIts) / (1000 * DeltaTime()));

            BufferedDataStream is_Renamed = new BufferedDataStream(new BufferedStream(new FileStream(filename, FileMode.Open, FileAccess.Read), 32768));

            ResetTime();
            for (int j = 0; j < numIts; j += 1)
            {
                for (int i = 0; i < dim; i += 1)
                {
                    in2[i] = is_Renamed.ReadInt32();
                }
            }
            System.Console.Out.WriteLine("  BDS Int read:  " + (4 * dim * numIts) / (1000 * DeltaTime()));
        }
Ejemplo n.º 3
0
        /// <summary>Add some data to the heap.</summary>
        internal virtual int PutData(Object data)
        {
            int size = ArrayFuncs.ComputeSize(data);

            ExpandHeap(size);
            MemoryStream bo = new MemoryStream(size);

            try
            {
                BufferedDataStream o = new BufferedDataStream(bo);
                o.WriteArray(data);
                o.Flush();
                o.Close();
            }
            catch (IOException)
            {
                throw new FitsException("Unable to write variable column length data");
            }

            Array.Copy(bo.ToArray(), 0, heap, heapSize, size);
            int oldOffset = heapSize;

            heapSize += size;

            // change suggested in .99.1 version:
            heapOffset = heapSize;

            return(oldOffset);
        }
        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);
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>Get data from the heap.</summary>
        /// <param name="offset">The offset at which the data begins.</param>
        /// <param name="array"> The array to be extracted.</param>
        public virtual void GetData(int offset, Object array)
        {
            // Can we reuse the existing byte stream?
            try
            {
                if (bstr == null || heapOffset > offset)
                {
                    heapOffset = 0;
                    bstr       = new BufferedDataStream(new MemoryStream(heap));
                }

                //System.IO.BinaryReader temp_BinaryReader;
                System.Int64 temp_Int64;
                //temp_BinaryReader = bstr;
                temp_Int64 = bstr.Position;                               //temp_BinaryReader.BaseStream.Position;
                temp_Int64 = bstr.Seek(offset - heapOffset) - temp_Int64; //temp_BinaryReader.BaseStream.Seek(offset - heapOffset, System.IO.SeekOrigin.Current) - temp_Int64;
                int generatedAux = (int)temp_Int64;
                heapOffset  = offset;
                heapOffset += bstr.ReadArray(array);
            }
            catch (IOException e)
            {
                throw new FitsException("Error decoding heap area at offset=" + offset + ".  Exception: Exception " + e);
            }
        }
Ejemplo n.º 6
0
        /// <summary>Write a Fits Object to an external Stream.  The stream is left open.</summary>
        /// <param name="dos">A DataOutput stream</param>
        public virtual void Write(Stream os)
        {
            ArrayDataIO obs;
            bool        newOS = false;

            if (os is ArrayDataIO)
            {
                obs = (ArrayDataIO)os;
            }
            else
            {
                newOS = true;
                obs   = new BufferedDataStream(os);
            }

            BasicHDU hh;

            for (int i = 0; i < NumberOfHDUs; i += 1)
            {
                try
                {
                    hh = (BasicHDU)hduList[i];
                    hh.Write(obs);
                }
                catch (IndexOutOfRangeException e)
                {
                    SupportClass.WriteStackTrace(e, Console.Error);
                    throw new FitsException("Internal Error: Vector Inconsistency" + e);
                }
            }

            if (newOS)
            {
                try
                {
                    obs.Flush();
                    obs.Close();
                }
                catch (IOException)
                {
                    Console.Error.WriteLine("Warning: error closing FITS output stream");
                }
            }

            // change suggested in .99 version
            try
            {
                if (obs is BufferedFile)
                {
                    ((BufferedFile)obs).SetLength(((BufferedFile)obs).FilePointer);
                }
            }
            catch (IOException e)
            {
                System.Console.Out.WriteLine("Exception occured while Writing BufferedFile: \n\t" + e.Message);
                // Ignore problems...
            }
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
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.º 10
0
        /// <summary>Write a Fits Object to an external Stream.  The stream is left open.</summary>
        /// <param name="dos">A DataOutput stream</param>
        public virtual void Write(Stream os)
        {
            ArrayDataIO obs;

//			bool newOS = false;

            if (os is ArrayDataIO)
            {
                obs = (ArrayDataIO)os;
            }
            else
            {
//				newOS = true;
                obs = new BufferedDataStream(os);
            }

            BasicHDU hh;

            for (int i = 0; i < NumberOfHDUs; i += 1)
            {
                try
                {
                    hh = (BasicHDU)hduList[i];
                    hh.Write(obs);
                }
                catch (IndexOutOfRangeException e)
                {
                    SupportClass.WriteStackTrace(e, Console.Error);
                    throw new FitsException("Internal Error: Vector Inconsistency" + e);
                }
            }
            obs.Flush();
            #region oldCrap

            /*
             *                if(newOS)
             *                {
             *                        try
             *                        {
             *                                obs.Flush();
             *                                obs.Close();
             *                        }
             *                        catch(IOException)
             *                        {
             *                                Console.Error.WriteLine("Warning: error closing FITS output stream");
             *                        }
             *                }
             */
            #endregion
        }
Ejemplo n.º 11
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();
        }
Ejemplo n.º 12
0
        /// <summary>Check if the Heap can accommodate a given requirement. If not expand the heap.</summary>
        internal virtual void ExpandHeap(int need)
        {
            // change suggested in .99.1 version:
            // Invalidate any existing input stream to the heap.
            bstr = null;

            if (heapSize + need > heap.Length)
            {
                // change suggested in .99.1 version:
                expanded = true;

                int newlen = (heapSize + need) * 2;
                if (newlen < 16384)
                {
                    newlen = 16384;
                }
                byte[] newHeap = new byte[newlen];
                Array.Copy(heap, 0, newHeap, 0, heapSize);
                heap = newHeap;
            }
        }
Ejemplo n.º 13
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);
                    }
                }
            }
Ejemplo n.º 14
0
        /// <summary>Read the heap</summary>
        public virtual void Read(ArrayDataIO str)
        {
            if (str is RandomAccess)
            {
                fileOffset = FitsUtil.FindOffset(str);
                input      = str;
            }

            if (heap != null)
            {
                try
                {
                    str.Read(heap, 0, heapSize);
                }
                catch (IOException e)
                {
                    throw new FitsException("Error reading heap:" + e);
                }
            }

            // change suggested in .99.1 version:
            bstr = null;
        }
        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);
            }
        }
        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);
            }
        }
Ejemplo n.º 17
0
        public static void  BufferedStreamTest(System.String filename, int numIts, double[] db, double[] db2, float[] fl, float[] fl2, long[] ln, long[] ln2, int[] in_Renamed, int[] in2, short[] sh, short[] sh2, char[] ch, char[] ch2, byte[] by, byte[] by2, bool[] bl, bool[] bl2, int[][][][] multi, int[][][][] multi2)
        {
            int dim = db.Length;

            double ds = SupportClass.Random.NextDouble() - 0.5;
            double ds2;
            float  fs = (float)(SupportClass.Random.NextDouble() - 0.5);
            float  fs2;
            int    is_Renamed = (int)(1000000 * (SupportClass.Random.NextDouble() - 500000));
            int    is2;
            long   ls = (long)(100000000000L * (SupportClass.Random.NextDouble() - 50000000000L));
            long   ls2;
            short  ss = (short)(60000 * (SupportClass.Random.NextDouble() - 30000));
            short  ss2;
            char   cs = (char)(60000 * SupportClass.Random.NextDouble());
            char   cs2;
            byte   bs = (byte)(256 * SupportClass.Random.NextDouble() - 128);
            byte   bs2;
            bool   bls = (SupportClass.Random.NextDouble() > 0.5);
            bool   bls2;

            System.Console.Out.WriteLine("New libraries: nom.tam.util.BufferedDataXXputStream");
            System.Console.Out.WriteLine("               Using array I/O methods");

            {
                BufferedDataStream f = new BufferedDataStream(new FileStream(filename, FileMode.Create));

                ResetTime();
                for (int i = 0; i < numIts; i += 1)
                {
                    f.WriteArray(db);
                }
                System.Console.Out.WriteLine("  BDS Dbl write: " + (8 * dim * numIts) / (1000 * DeltaTime()));
                for (int i = 0; i < numIts; i += 1)
                {
                    f.WriteArray(fl);
                }
                System.Console.Out.WriteLine("  BDS Flt write: " + (4 * dim * numIts) / (1000 * DeltaTime()));
                for (int i = 0; i < numIts; i += 1)
                {
                    f.WriteArray(in_Renamed);
                }
                System.Console.Out.WriteLine("  BDS Int write: " + (4 * dim * numIts) / (1000 * DeltaTime()));
                for (int i = 0; i < numIts; i += 1)
                {
                    f.WriteArray(ln);
                }
                System.Console.Out.WriteLine("  BDS Lng write: " + (8 * dim * numIts) / (1000 * DeltaTime()));
                for (int i = 0; i < numIts; i += 1)
                {
                    f.WriteArray(sh);
                }
                System.Console.Out.WriteLine("  BDS Sht write: " + (2 * dim * numIts) / (1000 * DeltaTime()));
                for (int i = 0; i < numIts; i += 1)
                {
                    f.WriteArray(ch);
                }
                System.Console.Out.WriteLine("  BDS Chr write: " + (2 * dim * numIts) / (1000 * DeltaTime()));
                for (int i = 0; i < numIts; i += 1)
                {
                    f.WriteArray((byte[])by);
                }
                System.Console.Out.WriteLine("  BDS Byt write: " + (1 * dim * numIts) / (1000 * DeltaTime()));
                for (int i = 0; i < numIts; i += 1)
                {
                    f.WriteArray(bl);
                }
                System.Console.Out.WriteLine("  BDS Boo write: " + (1 * dim * numIts) / (1000 * DeltaTime()));

                f.Write((byte)bs);
                f.Write((System.Char)cs);
                f.Write((System.Int16)ss);
                f.Write(is_Renamed);
                f.Write(ls);
                f.Write(fs);
                f.Write(ds);
                f.Write(bls);

                f.WriteArray(multi);
                f.Flush();
                f.Close();
            }

            {
                BufferedDataStream f = new BufferedDataStream(new FileStream(filename, FileMode.Open, FileAccess.Read));

                ResetTime();
                for (int i = 0; i < numIts; i += 1)
                {
                    f.ReadArray(db2);
                }
                System.Console.Out.WriteLine("  BDS Dbl read:  " + (8 * dim * numIts) / (1000 * DeltaTime()));
                for (int i = 0; i < numIts; i += 1)
                {
                    f.ReadArray(fl2);
                }
                System.Console.Out.WriteLine("  BDS Flt read:  " + (4 * dim * numIts) / (1000 * DeltaTime()));
                for (int i = 0; i < numIts; i += 1)
                {
                    f.ReadArray(in2);
                }
                System.Console.Out.WriteLine("  BDS Int read:  " + (4 * dim * numIts) / (1000 * DeltaTime()));
                for (int i = 0; i < numIts; i += 1)
                {
                    f.ReadArray(ln2);
                }
                System.Console.Out.WriteLine("  BDS Lng read:  " + (8 * dim * numIts) / (1000 * DeltaTime()));
                for (int i = 0; i < numIts; i += 1)
                {
                    f.ReadArray(sh2);
                }
                System.Console.Out.WriteLine("  BDS Sht read:  " + (2 * dim * numIts) / (1000 * DeltaTime()));
                for (int i = 0; i < numIts; i += 1)
                {
                    f.ReadArray(ch2);
                }
                System.Console.Out.WriteLine("  BDS Chr read:  " + (2 * dim * numIts) / (1000 * DeltaTime()));
                for (int i = 0; i < numIts; i += 1)
                {
                    f.ReadArray((byte[])by2);
                }
                System.Console.Out.WriteLine("  BDS Byt read:  " + (1 * dim * numIts) / (1000 * DeltaTime()));
                for (int i = 0; i < numIts; i += 1)
                {
                    f.ReadArray(bl2);
                }
                System.Console.Out.WriteLine("  BDS Boo read:  " + (1 * dim * numIts) / (1000 * DeltaTime()));

                bs2  = (byte)f.ReadByte();
                cs2  = f.ReadChar();
                ss2  = f.ReadInt16();
                is2  = f.ReadInt32();
                ls2  = f.ReadInt64();
                fs2  = f.ReadSingle();
                ds2  = f.ReadDouble();
                bls2 = f.ReadBoolean();

                for (int i = 0; i < 10; i += 1)
                {
                    multi2[i][i][i][i] = 0;
                }

                // Now read only pieces of the multidimensional array.
                for (int i = 0; i < 5; i += 1)
                {
                    System.Console.Out.WriteLine("Multiread:" + i);
                    // Skip the odd initial indices and
                    // read the evens.
                    //BinaryReader temp_BinaryReader;
                    System.Int64 temp_Int64;
                    //temp_BinaryReader = f;
                    temp_Int64 = f.Position;                      //temp_BinaryReader.BaseStream.Position;
                    temp_Int64 = f.Seek(4000) - temp_Int64;       //temp_BinaryReader.BaseStream.Seek(4000, SeekOrigin.Current) - temp_Int64;
                    int generatedAux28 = (int)temp_Int64;
                    f.ReadArray(multi2[2 * i + 1]);
                }
                f.Close();
            }

            System.Console.Out.WriteLine("Stream Verification:");
            System.Console.Out.WriteLine("  An error should be reported for double and float NaN's");
            System.Console.Out.WriteLine("  Arrays:");

            for (int i = 0; i < dim; i += 1)
            {
                if (db[i] != db2[i] && !Double.IsNaN(db[i]) && !Double.IsNaN(db2[i]))
                {
                    System.Console.Out.WriteLine("     Double error at " + i + " " + db[i] + " " + db2[i]);
                }
                if (fl[i] != fl2[i] && !Single.IsNaN(fl[i]) && !Single.IsNaN(fl2[i]))
                {
                    System.Console.Out.WriteLine("     Float error at " + i + " " + fl[i] + " " + fl2[i]);
                }
                if (in_Renamed[i] != in2[i])
                {
                    System.Console.Out.WriteLine("     Int error at " + i + " " + in_Renamed[i] + " " + in2[i]);
                }
                if (ln[i] != ln2[i])
                {
                    System.Console.Out.WriteLine("     Long error at " + i + " " + ln[i] + " " + ln2[i]);
                }
                if (sh[i] != sh2[i])
                {
                    System.Console.Out.WriteLine("     Short error at " + i + " " + sh[i] + " " + sh2[i]);
                }
                if (ch[i] != ch2[i])
                {
                    System.Console.Out.WriteLine("     Char error at " + i + " " + (int)ch[i] + " " + (int)ch2[i]);
                }
                if (by[i] != by2[i])
                {
                    System.Console.Out.WriteLine("     Byte error at " + i + " " + by[i] + " " + by2[i]);
                }
                if (bl[i] != bl2[i])
                {
                    System.Console.Out.WriteLine("     Bool error at " + i + " " + bl[i] + " " + bl2[i]);
                }
            }

            System.Console.Out.WriteLine("  Scalars:");
            // Check the scalars.
            if (bls != bls2)
            {
                System.Console.Out.WriteLine("     Bool Scalar mismatch:" + bls + " " + bls2);
            }
            if (bs != bs2)
            {
                System.Console.Out.WriteLine("     Byte Scalar mismatch:" + bs + " " + bs2);
            }
            if (cs != cs2)
            {
                System.Console.Out.WriteLine("     Char Scalar mismatch:" + (int)cs + " " + (int)cs2);
            }
            if (ss != ss2)
            {
                System.Console.Out.WriteLine("     Short Scalar mismatch:" + ss + " " + ss2);
            }
            if (is_Renamed != is2)
            {
                System.Console.Out.WriteLine("     Int Scalar mismatch:" + is_Renamed + " " + is2);
            }
            if (ls != ls2)
            {
                System.Console.Out.WriteLine("     Long Scalar mismatch:" + ls + " " + ls2);
            }
            if (fs != fs2)
            {
                System.Console.Out.WriteLine("     Float Scalar mismatch:" + fs + " " + fs2);
            }
            if (ds != ds2)
            {
                System.Console.Out.WriteLine("     Double Scalar mismatch:" + ds + " " + ds2);
            }

            System.Console.Out.WriteLine("  Multi: odd rows should match");
            for (int i = 0; i < 10; i += 1)
            {
                System.Console.Out.WriteLine("      " + i + " " + multi[i][i][i][i] + " " + multi2[i][i][i][i]);
            }
            System.Console.Out.WriteLine("Done BufferedStream Tests");
        }
Ejemplo n.º 18
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();
                }
            }
        }