public void TestReadBuffered()
        {
            string       filename = TestFileSetup.GetTargetFilename("test.fits");
            BufferedFile bf       =
                new BufferedFile(
                    filename,
                    FileAccess.Read,
                    FileShare.None);

            Header h = Header.ReadHeader(bf);

            long n        = h.DataSize;
            int  naxes    = h.GetIntValue("NAXIS");
            int  lastAxis = h.GetIntValue("NAXIS" + naxes);

            HeaderCard hnew = new HeaderCard("NAXIS", naxes - 1, "this is header card with naxes");

            h.AddCard(hnew);

            float[] line = new float[h.DataSize];

            for (int i = 0; i < lastAxis; i += 1)
            {
                Console.Out.WriteLine("read");
                bf.Read(line);
            }

            bf.Close();
            bf.Dispose();
        }
示例#2
0
        // Make FITS file
        public void MakeFile()
        {
            Initialize();

            Fits f = new Fits();

            // Make HDUs of various types.
            f.AddHDU(Fits.MakeHDU(bimg));
            f.AddHDU(Fits.MakeHDU(simg));
            f.AddHDU(Fits.MakeHDU(iimg));
            f.AddHDU(Fits.MakeHDU(limg));
            f.AddHDU(Fits.MakeHDU(fimg));
            f.AddHDU(Fits.MakeHDU(dimg));
            f.AddHDU(Fits.MakeHDU(img3));
            f.AddHDU(Fits.MakeHDU(img1));

            Assert.AreEqual(f.NumberOfHDUs, 8);

            // Write a FITS file.
            BufferedFile bf = new BufferedFile(
                TestFileSetup.GetTargetFilename("image1.fits"),
                FileAccess.ReadWrite,
                FileShare.ReadWrite);

            f.Write(bf);
            bf.Flush();
            bf.Close();
            bf.Dispose();
            f.Close();
        }
        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();
            }
        }
示例#4
0
        public void TestVar()
        {
            Object[] data = new Object[] { floats, vf, vs, vd, shorts, vbool };
            Fits     f    = new Fits();

            f.AddHDU(Fits.MakeHDU(data));

            //BufferedDataStream bdos = new BufferedDataStream(new FileStream("bt2.fits", FileMode.Open, FileAccess.ReadWrite));
            BufferedFile bdos = new BufferedFile("bt2.fits", FileAccess.ReadWrite, FileShare.ReadWrite);

            f.Write(bdos);
            bdos.Close();

            f = new Fits("bt2.fits", FileAccess.Read);
            f.Read();
            BinaryTableHDU bhdu = (BinaryTableHDU)f.GetHDU(1);
            Header         hdr  = bhdu.Header;

            Assertion.AssertEquals("var1", true, hdr.GetIntValue("PCOUNT") > 0);
            Assertion.AssertEquals("var2", 6, hdr.GetIntValue("TFIELDS"));

            for (int i = 0; i < data.Length; i += 1)
            {
                Assertion.AssertEquals("vardata(" + i + ")", true, ArrayFuncs.ArrayEquals(data[i], bhdu.GetColumn(i)));
            }
        }
示例#5
0
        public void TestFitsCopy(/*String[] args*/)
        {
            String file = Path.GetTempFileName();

            File.Copy("testdocs\\ht1.fits", file, true);
            Fits     f = new Fits(file);
            int      i = 0;
            BasicHDU h;

            do
            {
                h = f.ReadHDU();
                if (h != null)
                {
                    if (i == 0)
                    {
                        System.Console.Out.WriteLine("\n\nPrimary header:\n");
                    }
                    else
                    {
                        System.Console.Out.WriteLine("\n\nExtension " + i + ":\n");
                    }
                    i += 1;
                    h.Info();
                }
            } while (h != null);

            BufferedFile bf = new BufferedFile("gbfits3.fits" /*args[1]*/, FileAccess.ReadWrite, FileShare.ReadWrite);

            f.Write(bf);
            bf.Close();
        }
示例#6
0
        // Make FITS file
        public void MakeFile()
        {
            Initialize();

            Fits f = new Fits();

            // Make HDUs of various types.
            f.AddHDU(Fits.MakeHDU(bimg));
            f.AddHDU(Fits.MakeHDU(simg));
            f.AddHDU(Fits.MakeHDU(iimg));
            f.AddHDU(Fits.MakeHDU(limg));
            f.AddHDU(Fits.MakeHDU(fimg));
            f.AddHDU(Fits.MakeHDU(dimg));
            f.AddHDU(Fits.MakeHDU(img3));
            f.AddHDU(Fits.MakeHDU(img1));

            Assertion.AssertEquals("HDU count before", f.NumberOfHDUs, 8);


            // Write a FITS file.
            BufferedFile bf = new BufferedFile("image1.fits", FileAccess.ReadWrite, FileShare.ReadWrite);

            f.Write(bf);
            bf.Flush();
            bf.Close();
        }
示例#7
0
        public void TestDegenerate()
        {
            String[] sa = new String[10];
            int[,] ia = new int[10, 0];
            Fits f = new Fits();

            for (int i = 0; i < sa.Length; i += 1)
            {
                sa[i] = "";
            }

            Object[]       data = new Object[] { sa, ia };
            BinaryTableHDU bhdu = (BinaryTableHDU)Fits.MakeHDU(data);
            Header         hdr  = bhdu.Header;

            f.AddHDU(bhdu);
            BufferedFile bf = new BufferedFile("bt7.fits", FileAccess.ReadWrite, FileShare.ReadWrite);

            f.Write(bf);
            bf.Close();

            Assertion.AssertEquals("degen1", 2, hdr.GetIntValue("TFIELDS"));
            Assertion.AssertEquals("degen2", 10, hdr.GetIntValue("NAXIS2"));
            Assertion.AssertEquals("degen3", 0, hdr.GetIntValue("NAXIS1"));

            f    = new Fits("bt7.fits");
            bhdu = (BinaryTableHDU)f.GetHDU(1);

            hdr = bhdu.Header;
            Assertion.AssertEquals("degen4", 2, hdr.GetIntValue("TFIELDS"));
            Assertion.AssertEquals("degen5", 10, hdr.GetIntValue("NAXIS2"));
            Assertion.AssertEquals("degen6", 0, hdr.GetIntValue("NAXIS1"));
            f.Close();
        }
示例#8
0
        void WriteFile(Fits f, String name)
        {
            BufferedFile bf = new BufferedFile(name, FileAccess.ReadWrite, FileShare.ReadWrite);

            f.Write(bf);
            bf.Flush();
            bf.Close();
        }
示例#9
0
        public void TestObj()
        {
            FitsFactory.UseAsciiTables = false;

            /*** Create a binary table from an Object[][] array */
            Object[][] x = new Object[5][];
            for (int i = 0; i < 5; i += 1)
            {
                x[i] = new Object[3];

                x[i][0] = new float[] { i };

                string temp = string.Concat("AString", i);
                x[i][1] = new string[] { temp };

                int[][] t = new int[2][];
                for (int j = 0; j < 2; j++)
                {
                    t[j]    = new int[2];
                    t[j][0] = j * i;
                    t[j][1] = (j + 2) * i;
                }
                x[i][2] = t;
            }

            Fits     f   = new Fits();
            BasicHDU hdu = Fits.MakeHDU(x);

            f.AddHDU(hdu);
            BufferedFile bf = new BufferedFile("bt5.fits", FileAccess.ReadWrite, FileShare.ReadWrite);

            f.Write(bf);
            bf.Close();


            /* Now get rid of some columns */
            BinaryTableHDU xhdu = (BinaryTableHDU)hdu;

            // First column
            Assertion.AssertEquals("delcol1", 3, xhdu.NCols);
            xhdu.DeleteColumnsIndexOne(1, 1);
            Assertion.AssertEquals("delcol2", 2, xhdu.NCols);

            xhdu.DeleteColumnsIndexZero(1, 1);
            Assertion.AssertEquals("delcol3", 1, xhdu.NCols);

            bf = new BufferedFile("bt6.fits", FileAccess.ReadWrite, FileShare.ReadWrite);
            f.Write(bf);
            bf.Close();

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

            xhdu = (BinaryTableHDU)f.GetHDU(1);
            Assertion.AssertEquals("delcol4", 1, xhdu.NCols);
            f.Close();
        }
示例#10
0
        public void TestRowDelete()
        {
            Fits f = null;

            try
            {
                f = new Fits(
                    TestFileSetup.GetTargetFilename(
                        TestFileSetup.GetTargetFilename("bt1.fits")));
                f.Read();

                BinaryTableHDU thdu = (BinaryTableHDU)f.GetHDU(1);

                Assert.AreEqual(50, thdu.NRows);
                thdu.DeleteRows(10, 20);
                Assert.AreEqual(30, thdu.NRows);

                double[] dbl = (double[])thdu.GetColumn(6);
                Assert.AreEqual(dbl[9], doubles[9]);
                Assert.AreEqual(dbl[10], doubles[30]);

                BufferedFile bf =
                    new BufferedFile(
                        TestFileSetup.GetTargetFilename("bt1x.fits"),
                        FileAccess.ReadWrite,
                        FileShare.ReadWrite);

                f.Write(bf);
                bf.Close();
                bf.Dispose();
                f.Close();

                f = new Fits(TestFileSetup.GetTargetFilename("bt1x.fits"));
                f.Read();
                thdu = (BinaryTableHDU)f.GetHDU(1);
                dbl  = (double[])thdu.GetColumn(6);
                Assert.AreEqual(30, thdu.NRows);
                Assert.AreEqual(9, thdu.NCols);
                Assert.AreEqual(dbl[9], doubles[9]);
                Assert.AreEqual(dbl[10], doubles[30]);

                thdu.DeleteRows(20);
                Assert.AreEqual(20, thdu.NRows);
                dbl = (double[])thdu.GetColumn(6);
                Assert.AreEqual(20, dbl.Length);
                Assert.AreEqual(dbl[0], doubles[0]);
                Assert.AreEqual(dbl[19], doubles[39]);
            }
            finally
            {
                if (f != null)
                {
                    f.Close();
                }
            }
        }
示例#11
0
        public void TestSimpleIO()
        {
            FitsFactory.UseAsciiTables = false;

            Fits f = new Fits();

            Object[] data = new Object[] { bytes, bits, bools, shorts, ints,
                                           floats, doubles, longs, strings };
            f.AddHDU(Fits.MakeHDU(data));

            BinaryTableHDU bhdu = (BinaryTableHDU)f.GetHDU(1);

            bhdu.SetColumnName(0, "bytes", null);
            bhdu.SetColumnName(1, "bits", "bits later on");
            bhdu.SetColumnName(6, "doubles", null);
            bhdu.SetColumnName(5, "floats", "4 x 4 array");

            BufferedFile bf = new BufferedFile("bt1.fits", FileAccess.ReadWrite, FileShare.ReadWrite);

            f.Write(bf);
            bf.Flush();
            bf.Close();

            f = new Fits("bt1.fits");
            f.Read();

            Assertion.AssertEquals("NHDU", 2, f.NumberOfHDUs);


            BinaryTableHDU thdu = (BinaryTableHDU)f.GetHDU(1);
            Header         hdr  = thdu.Header;

            Assertion.AssertEquals("HDR1", 9, hdr.GetIntValue("TFIELDS"));
            Assertion.AssertEquals("HDR2", 2, hdr.GetIntValue("NAXIS"));
            Assertion.AssertEquals("HDR3", 8, hdr.GetIntValue("BITPIX"));
            Assertion.AssertEquals("HDR4", "BINTABLE", hdr.GetStringValue("XTENSION"));
            Assertion.AssertEquals("HDR5", "bytes", hdr.GetStringValue("TTYPE1"));
            Assertion.AssertEquals("HDR6", "doubles", hdr.GetStringValue("TTYPE7"));

            for (int i = 0; i < data.Length; i += 1)
            {
                Object col = thdu.GetColumn(i);
                if (i == 8)
                {
                    String[] st = (String[])col;

                    for (int j = 0; j < st.Length; j += 1)
                    {
                        st[j] = st[j].Trim();
                    }
                }
                Assertion.AssertEquals("Data" + i, true, ArrayFuncs.ArrayEquals(data[i], col));
            }
            f.Close();
        }
示例#12
0
        public void TestSimpleImages()
        {
            float[][] img = new float[300][];
            for (int i = 0; i < 300; i++)
            {
                img[i] = new float[300];
            }

            Fits f = new Fits();

            ImageHDU hdu = (ImageHDU)Fits.MakeHDU(img);

            BufferedFile bf = new BufferedFile("ht1.fits", FileAccess.ReadWrite, FileShare.ReadWrite);

            f.AddHDU(hdu);
            f.Write(bf);
            bf.Close();

            f   = new Fits("ht1.fits");
            hdu = (ImageHDU)f.GetHDU(0);
            Header hdr = hdu.Header;

            Assertion.AssertEquals("NAXIS", 2, hdr.GetIntValue("NAXIS"));
            Assertion.AssertEquals("NAXIS1", 300, hdr.GetIntValue("NAXIS1"));
            Assertion.AssertEquals("NAXIS2", 300, hdr.GetIntValue("NAXIS2"));
            Assertion.AssertEquals("NAXIS2a", 300, hdr.GetIntValue("NAXIS2", -1));
            Assertion.AssertEquals("NAXIS3", -1, hdr.GetIntValue("NAXIS3", -1));

            Assertion.AssertEquals("BITPIX", -32, hdr.GetIntValue("BITPIX"));


            Cursor c = hdr.GetCursor();

            c.MoveNext();
            HeaderCard hc = (HeaderCard)((DictionaryEntry)c.Current).Value;

            Assertion.AssertEquals("SIMPLE_1", "SIMPLE", hc.Key);

            c.MoveNext();
            hc = (HeaderCard)((DictionaryEntry)c.Current).Value;
            Assertion.AssertEquals("BITPIX_2", "BITPIX", hc.Key);

            c.MoveNext();
            hc = (HeaderCard)((DictionaryEntry)c.Current).Value;
            Assertion.AssertEquals("NAXIS_3", "NAXIS", hc.Key);

            c.MoveNext();
            hc = (HeaderCard)((DictionaryEntry)c.Current).Value;
            Assertion.AssertEquals("NAXIS1_4", "NAXIS1", hc.Key);

            c.MoveNext();
            hc = (HeaderCard)((DictionaryEntry)c.Current).Value;
            Assertion.AssertEquals("NAXIS2_5", "NAXIS2", hc.Key);
            f.Close();
        }
示例#13
0
        public void forma2()
        {
            /*Lectura mayor y manual de parte de cabezera*/
            string       salida = "";
            BufferedFile bf     = new BufferedFile("cubo_ing_comp.fits", FileAccess.Read, FileShare.None);
            Header       h      = Header.ReadHeader(bf);

            Console.WriteLine(h.GetCard(155)); //Obtener las propiedades des header numericamente
            Console.WriteLine("HEADER SIZE: " + h.DataSize);

            Console.WriteLine("SIMPLE: " + h.GetBooleanValue("SIMPLE"));
            Console.WriteLine("BITPIX: " + h.GetIntValue("BITPIX"));

            int naxes = h.GetIntValue("NAXIS");

            Console.WriteLine("NAXIS: " + naxes);

            for (int i = 1; i <= naxes; i++)
            {
                salida = "NAXIS" + i;
                Console.WriteLine(salida + " : " + h.GetIntValue(salida));
            }

            Console.WriteLine("DATAMIN: " + h.GetFloatValue("DATAMIN"));
            Console.WriteLine("DATAMAX: " + h.GetFloatValue("DATAMAX"));
            Console.WriteLine("ORIGIN: " + h.GetStringValue("ORIGIN"));
            Console.WriteLine("DATE: " + h.GetStringValue("DATE"));
            Console.WriteLine("NEXTEND: " + h.GetFloatValue("NEXTEND"));
            Console.WriteLine("FILENAME: " + h.GetStringValue("FILENAME"));
            Console.WriteLine("OBJECT: " + h.GetStringValue("OBJECT"));
            Console.WriteLine("EXPTIME: " + h.GetFloatValue("EXPTIME"));
            Console.WriteLine("DARKTIME: " + h.GetFloatValue("DARKTIME"));
            Console.WriteLine("PREFLASH: " + h.GetStringValue("PREFLASH"));
            Console.WriteLine("RADECSYS: " + h.GetStringValue("RADECSYS"));
            Console.WriteLine("RADECEQ: " + h.GetFloatValue("RADECEQ"));
            Console.WriteLine("RA: " + h.GetStringValue("RA"));
            Console.WriteLine("DEC: " + h.GetStringValue("DEC"));
            Console.WriteLine("TIMESYS: " + h.GetStringValue("TIMESYS"));
            Console.WriteLine("DATE-OBS: " + h.GetStringValue("DATE-OBS"));
            Console.WriteLine("TIME-OBS: " + h.GetStringValue("TIME-OBS"));
            Console.WriteLine("MJD-OBS: " + h.GetFloatValue("MJD-OBS"));
            Console.WriteLine("MJDHDR: " + h.GetFloatValue("MJDHDR"));
            Console.WriteLine("LSTHDR: " + h.GetStringValue("LSTHDR"));
            Console.WriteLine("OBSERVAT: " + h.GetStringValue("OBSERVAT"));
            Console.WriteLine("TELESCOP: " + h.GetStringValue("TELESCOP"));
            Console.WriteLine("INSTRUME: " + h.GetStringValue("INSTRUME"));
            Console.WriteLine("TELRADEC: " + h.GetStringValue("TELRADEC"));
            Console.WriteLine("IMAGENUM: " + h.GetStringValue("IMAGENUM"));
            Console.WriteLine("TELEQUIN: " + h.GetStringValue("TELEQUIN"));
            Console.WriteLine("...");
            Console.WriteLine("FLATFILE: " + h.GetStringValue("FLATFILE"));

            bf.Close();
        }
示例#14
0
        public void BuildByColumn()
        {
            Fits f = null;

            try
            {
                BinaryTable btab = new BinaryTable();

                btab.AddColumn(floats);
                btab.AddColumn(vf);
                btab.AddColumn(strings);
                btab.AddColumn(vbool);
                btab.AddColumn(ints);

                f = new Fits();
                f.AddHDU(Fits.MakeHDU(btab));

                BufferedFile bdos =
                    new BufferedFile(
                        TestFileSetup.GetTargetFilename("bt3.fits"),
                        FileAccess.ReadWrite,
                        FileShare.ReadWrite);
                f.Write(bdos);
                bdos.Close();
                bdos.Dispose();
                f.Close();

                f = new Fits(TestFileSetup.GetTargetFilename("bt3.fits"));
                BinaryTableHDU bhdu = (BinaryTableHDU)f.GetHDU(1);
                btab = (BinaryTable)bhdu.Data;

                Assert.AreEqual(true, ArrayFuncs.ArrayEquals(floats, bhdu.GetColumn(0)));
                Assert.AreEqual(true, ArrayFuncs.ArrayEquals(vf, bhdu.GetColumn(1))); // problem is here only

                String[] col = (String[])bhdu.GetColumn(2);
                for (int i = 0; i < col.Length; i += 1)
                {
                    col[i] = col[i].Trim();
                }

                Assert.AreEqual(true, ArrayFuncs.ArrayEquals(strings, col));
                Assert.AreEqual(true, ArrayFuncs.ArrayEquals(vbool, bhdu.GetColumn(3)));
                Assert.AreEqual(true, ArrayFuncs.ArrayEquals(ints, bhdu.GetColumn(4)));
            }
            finally
            {
                if (f != null)
                {
                    f.Close();
                }
            }
        }
示例#15
0
        public void Delete()
        {
            Fits f = null;

            try
            {
                f = new Fits(TestFileSetup.GetTargetFilename("at1.fits"), FileAccess.ReadWrite);

                TableHDU th = (TableHDU)f.GetHDU(1);
                Assert.AreEqual(50, th.NRows);

                th.DeleteRows(2, 2);
                Assert.AreEqual(48, th.NRows);

                BufferedFile bf = new BufferedFile(TestFileSetup.GetTargetFilename("at1y.fits"), FileAccess.ReadWrite,
                                                   FileShare.ReadWrite);
                f.Write(bf);
                bf.Close();
                bf.Dispose();
                f.Close();

                f  = new Fits(TestFileSetup.GetTargetFilename("at1y.fits"));
                th = (TableHDU)f.GetHDU(1);
                Assert.AreEqual(48, th.NRows);

                Assert.AreEqual(5, th.NCols);
                th.DeleteColumnsIndexZero(3, 2);
                Assert.AreEqual(3, th.NCols);

                th.DeleteColumnsIndexZero(0, 2);
                Assert.AreEqual(1, th.NCols);
                bf = new BufferedFile(TestFileSetup.GetTargetFilename("at1z.fits"), FileAccess.ReadWrite,
                                      FileShare.ReadWrite);

                f.Write(bf);
                bf.Close();
                bf.Dispose();
                f.Close();

                f  = new Fits(TestFileSetup.GetTargetFilename("at1z.fits"));
                th = (TableHDU)f.GetHDU(1);
                Assert.AreEqual(1, th.NCols);
            }
            finally
            {
                if (f != null)
                {
                    f.Close();
                }
            }
        }
示例#16
0
        public void TestDegenerate()
        {
            Fits f = null;

            try
            {
                String[] sa = new String[10];
                int[,] ia = new int[10, 0];

                f = new Fits();

                for (int i = 0; i < sa.Length; i += 1)
                {
                    sa[i] = "";
                }

                Object[]       data = new Object[] { sa, ia };
                BinaryTableHDU bhdu = (BinaryTableHDU)Fits.MakeHDU(data);
                Header         hdr  = bhdu.Header;
                f.AddHDU(bhdu);

                BufferedFile bf =
                    new BufferedFile(
                        TestFileSetup.GetTargetFilename("bt7.fits"),
                        FileAccess.ReadWrite,
                        FileShare.ReadWrite);
                f.Write(bf);
                bf.Close();
                bf.Dispose();

                Assert.AreEqual(2, hdr.GetIntValue("TFIELDS"));
                Assert.AreEqual(10, hdr.GetIntValue("NAXIS2"));
                Assert.AreEqual(0, hdr.GetIntValue("NAXIS1"));

                f.Close();

                f    = new Fits(TestFileSetup.GetTargetFilename("bt7.fits"));
                bhdu = (BinaryTableHDU)f.GetHDU(1);
                hdr  = bhdu.Header;
                Assert.AreEqual(2, hdr.GetIntValue("TFIELDS"));
                Assert.AreEqual(10, hdr.GetIntValue("NAXIS2"));
                Assert.AreEqual(0, hdr.GetIntValue("NAXIS1"));
            }
            finally
            {
                if (f != null)
                {
                    f.Close();
                }
            }
        }
示例#17
0
        public void TestDegen2()
        {
            FitsFactory.UseAsciiTables = false;

            Object[] data = new Object[] {
                new String[] { "a", "b", "c", "d", "e", "f" },
                new int[]   { 1, 2, 3, 4, 5, 6 },
                new float[] { 1f, 2f, 3f, 4f, 5f, 6f },
                new String[] { "", "", "", "", "", "" },
                new String[] { "a", "", "c", "", "e", "f" },
                new String[] { "", "b", "c", "d", "e", "f" },
                new String[] { "a", "b", "c", "d", "e", "" },
                new String[] { null, null, null, null, null, null },
                new String[] { "a", null, "c", null, "e", "f" },
                new String[] { null, "b", "c", "d", "e", "f" },
                new String[] { "a", "b", "c", "d", "e", null }
            };

            Fits f = new Fits();

            f.AddHDU(Fits.MakeHDU(data));
            BufferedFile ff = new BufferedFile("bt8.fits", FileAccess.ReadWrite, FileShare.ReadWrite);

            f.Write(ff);
            ff.Flush();
            ff.Close();

            f = new Fits("bt8.fits");
            BinaryTableHDU bhdu = (BinaryTableHDU)f.GetHDU(1);

            Assertion.AssertEquals("deg21", "e", bhdu.GetElement(4, data.Length - 1));
            Assertion.AssertEquals("deg22", "", bhdu.GetElement(5, data.Length - 1));

            String[] col = (String[])bhdu.GetColumn(0);
            Assertion.AssertEquals("deg23", "a", col[0]);
            Assertion.AssertEquals("deg24", "f", col[5]);

            col = (String[])bhdu.GetColumn(3);
            Assertion.AssertEquals("deg25", "", col[0]);
            Assertion.AssertEquals("deg26", "", col[5]);

            col = (String[])bhdu.GetColumn(7);  // All nulls
            Assertion.AssertEquals("deg27", "", col[0]);
            Assertion.AssertEquals("deg28", "", col[5]);

            col = (String[])bhdu.GetColumn(8);

            Assertion.AssertEquals("deg29", "a", col[0]);
            Assertion.AssertEquals("deg210", "", col[1]);
            f.Close();
        }
示例#18
0
        public void test()
        {
            float[][] data = new float[300][];
            for (int i = 0; i < 300; i++)
            {
                data[i] = new float[300];
            }

            for (int i = 0; i < 300; i += 1)
            {
                for (int j = 0; j < 300; j += 1)
                {
                    data[i][j] = 1000 * i + j;
                }
            }

            Fits f = null;

            try
            {
                f = new Fits();

                BufferedFile bf = new BufferedFile(TestFileSetup.GetTargetFilename("tiler1.fits"), FileAccess.ReadWrite,
                                                   FileShare.ReadWrite);
                f.AddHDU(Fits.MakeHDU(data));
                f.Write(bf);
                bf.Close();
                bf.Dispose();
                f.Close();

                f = new Fits(TestFileSetup.GetTargetFilename("tiler1.fits"));
                ImageHDU h = (ImageHDU)f.ReadHDU();

                ImageTiler t = h.Tiler;
                doTile("t1", data, t, 200, 200, 50, 50);
                doTile("t2", data, t, 133, 133, 72, 26);

                Object o = h.Data.Kernel;
                doTile("t3", data, t, 200, 200, 50, 50);
                doTile("t4", data, t, 133, 133, 72, 26);
            }
            finally
            {
                if (f != null)
                {
                    f.Close();
                }
            }
        }
示例#19
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();
            }
        }
示例#20
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));
            }
        }
示例#21
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();
            }
        }
示例#22
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);
        }
示例#23
0
        public void TestReadBuffered()
        {
            String file = Path.GetTempFileName();

            File.Copy("testdocs\\ht1.fits", file, true);
            BufferedFile bf = new BufferedFile(file, FileAccess.Read, FileShare.None);

            Header     h        = Header.ReadHeader(bf);
            long       n        = h.DataSize;
            int        naxes    = h.GetIntValue("NAXIS");
            int        lastAxis = h.GetIntValue("NAXIS" + naxes);
            HeaderCard hnew     = new HeaderCard("NAXIS", naxes - 1, "this is header card with naxes");

            h.AddCard(hnew);
            float[] line = new float[h.DataSize];
            for (int i = 0; i < lastAxis; i += 1)
            {
                Console.Out.WriteLine("read");
                bf.Read(line);
            }
        }
示例#24
0
        public void TestRowDelete()
        {
            Fits f = new Fits("testdocs\\bt1.fits");

            f.Read();

            BinaryTableHDU thdu = (BinaryTableHDU)f.GetHDU(1);

            Assertion.AssertEquals("Del1", 50, thdu.NRows);
            thdu.DeleteRows(10, 20);
            Assertion.AssertEquals("Del2", 30, thdu.NRows);

            double[] dbl = (double[])thdu.GetColumn(6);
            Assertion.AssertEquals("del3", dbl[9], doubles[9]);
            Assertion.AssertEquals("del4", dbl[10], doubles[30]);

            BufferedFile bf = new BufferedFile("bt1x.fits", FileAccess.ReadWrite, FileShare.ReadWrite);

            f.Write(bf);
            bf.Close();
            f.Close();

            f = new Fits("bt1x.fits");
            f.Read();
            thdu = (BinaryTableHDU)f.GetHDU(1);
            dbl  = (double[])thdu.GetColumn(6);
            Assertion.AssertEquals("del5", 30, thdu.NRows);
            Assertion.AssertEquals("del6", 9, thdu.NCols);
            Assertion.AssertEquals("del7", dbl[9], doubles[9]);
            Assertion.AssertEquals("del8", dbl[10], doubles[30]);

            thdu.DeleteRows(20);
            Assertion.AssertEquals("del9", 20, thdu.NRows);
            dbl = (double[])thdu.GetColumn(6);
            Assertion.AssertEquals("del10", 20, dbl.Length);
            Assertion.AssertEquals("del11", dbl[0], doubles[0]);
            Assertion.AssertEquals("del12", dbl[19], doubles[39]);
            f.Close();
        }
示例#25
0
        public void TestVar()
        {
            Fits f = null;

            try
            {
                Object[] data = new Object[] { floats, vf, vs, vd, shorts, vbool };
                f = new Fits();
                f.AddHDU(Fits.MakeHDU(data));

                BufferedFile bdos =
                    new BufferedFile(
                        TestFileSetup.GetTargetFilename("bt2.fits"),
                        FileAccess.ReadWrite,
                        FileShare.ReadWrite);

                f.Write(bdos);
                bdos.Close();
                bdos.Dispose();
                f.Close();

                f = new Fits(TestFileSetup.GetTargetFilename("bt2.fits"), FileAccess.Read);
                f.Read();
                BinaryTableHDU bhdu = (BinaryTableHDU)f.GetHDU(1);
                Header         hdr  = bhdu.Header;

                Assert.AreEqual(true, hdr.GetIntValue("PCOUNT") > 0);
                Assert.AreEqual(6, hdr.GetIntValue("TFIELDS"));

                for (int i = 0; i < data.Length; i += 1)
                {
                    Assert.AreEqual(true, ArrayFuncs.ArrayEquals(data[i], bhdu.GetColumn(i)));
                }
            }
            finally
            {
                f.Close();
            }
        }
示例#26
0
        public static FitsType GetFitsType(string fileName)
        {
            Fits fitsFile = new Fits();

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

                BasicHDU imageHDU = fitsFile.GetHDU(0);
                if (fitsFile.NumberOfHDUs == 1 && imageHDU.Axes.Length == 3 && imageHDU.Axes[0] == 3)
                {
                    return(FitsType.RGBFrames);
                }

                if (fitsFile.NumberOfHDUs == 1 && imageHDU.Axes.Length == 2)
                {
                    return(FitsType.SingleFrame);
                }
            }

            return(FitsType.Invalid);
        }
示例#27
0
        public static FitsCubeType GetFitsCubeType(string fileName)
        {
            Fits fitsFile = new Fits();

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

                BasicHDU imageHDU = fitsFile.GetHDU(0);
                if (fitsFile.NumberOfHDUs == 1 && imageHDU.Axes.Length == 3)
                {
                    return(FitsCubeType.ThreeAxisCube);
                }

                if (fitsFile.NumberOfHDUs > 1 && imageHDU.Axes.Length == 2)
                {
                    return(FitsCubeType.MultipleHDUsCube);
                }
            }

            return(FitsCubeType.NotACube);
        }
示例#28
0
        public void BuildByColumn()
        {
            BinaryTable btab = new BinaryTable();

            btab.AddColumn(floats);
            btab.AddColumn(vf);
            btab.AddColumn(strings);
            btab.AddColumn(vbool);
            btab.AddColumn(ints);

            Fits f = new Fits();

            f.AddHDU(Fits.MakeHDU(btab));

            // BufferedDataStream bdos = new BufferedDataStream(new FileStream("bt3.fits",FileMode.Open));
            BufferedFile bdos = new BufferedFile("bt3.fits", FileAccess.ReadWrite, FileShare.ReadWrite);

            f.Write(bdos);
            bdos.Close();

            f = new Fits("bt3.fits");
            BinaryTableHDU bhdu = (BinaryTableHDU)f.GetHDU(1);

            btab = (BinaryTable)bhdu.Data;

            Assertion.AssertEquals("col1", true, ArrayFuncs.ArrayEquals(floats, bhdu.GetColumn(0)));
            Assertion.AssertEquals("col2", true, ArrayFuncs.ArrayEquals(vf, bhdu.GetColumn(1))); // problem is here only

            String[] col = (String[])bhdu.GetColumn(2);
            for (int i = 0; i < col.Length; i += 1)
            {
                col[i] = col[i].Trim();
            }
            Assertion.AssertEquals("coi3", true, ArrayFuncs.ArrayEquals(strings, col));

            Assertion.AssertEquals("col4", true, ArrayFuncs.ArrayEquals(vbool, bhdu.GetColumn(3)));
            Assertion.AssertEquals("col5", true, ArrayFuncs.ArrayEquals(ints, bhdu.GetColumn(4)));
            f.Close();
        }
示例#29
0
        public void Delete()
        {
            Fits f = new Fits("at1.fits", FileAccess.ReadWrite);

            TableHDU th = (TableHDU)f.GetHDU(1);

            Assertion.AssertEquals("delrBef", 50, th.NRows);

            th.DeleteRows(2, 2);
            Assertion.AssertEquals("delrAft", 48, th.NRows);

            BufferedFile bf = new BufferedFile("at1y.fits", FileAccess.ReadWrite, FileShare.ReadWrite);

            f.Write(bf);
            bf.Close();
            f.Close();

            f  = new Fits("at1y.fits");
            th = (TableHDU)f.GetHDU(1);
            Assertion.AssertEquals("delrAft2", 48, th.NRows);

            Assertion.AssertEquals("delcBef", 5, th.NCols);
            th.DeleteColumnsIndexZero(3, 2);
            Assertion.AssertEquals("delcAft1", 3, th.NCols);

            th.DeleteColumnsIndexZero(0, 2);
            Assertion.AssertEquals("delcAft2", 1, th.NCols);
            bf = new BufferedFile("at1z.fits", FileAccess.ReadWrite, FileShare.ReadWrite);

            f.Write(bf);
            bf.Close();
            f.Close();

            f  = new Fits("at1z.fits");
            th = (TableHDU)f.GetHDU(1);
            Assertion.AssertEquals("delcAft3", 1, th.NCols);
            f.Close();
        }
        public void TestFitsCopy()
        {
            String file = TestFileSetup.GetTargetFilename("test_dup.fits");

            Fits     f = new Fits(file);
            int      i = 0;
            BasicHDU h;

            do
            {
                h = f.ReadHDU();
                if (h != null)
                {
                    if (i == 0)
                    {
                        Console.Out.WriteLine("\n\nPrimary header:\n");
                    }
                    else
                    {
                        Console.Out.WriteLine("\n\nExtension " + i + ":\n");
                    }
                    i += 1;
                    h.Info();
                }
            } while (h != null);

            BufferedFile bf = new BufferedFile(
                TestFileSetup.GetTargetFilename("gbfits3.fits"),
                FileAccess.ReadWrite,
                FileShare.ReadWrite);

            f.Write(bf);
            bf.Close();
            bf.Dispose();
            f.Close();
        }