public void TestFits()
        {
            string filename = TestFileSetup.GetTargetFilename("test.fits");

            using (FileStream fs = new FileStream(filename, FileMode.Open))
            {
                Fits f = new Fits(fs, false);

                Console.Out.WriteLine("FitsReader called.");

                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);
            }
        }
        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);

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

            hdr.AddValue("DATEOBS", timeStamp.Date.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture), m_DateObsComment);
            hdr.AddValue("TIMEOBS", timeStamp.ToString("HH:mm:ss.fff", CultureInfo.InvariantCulture), m_TimeObsComment);

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

            f.AddHDU(imageHDU);

            // Write a FITS file.
            using (BufferedFile bf = new BufferedFile(fileName, FileAccess.ReadWrite, FileShare.ReadWrite))
            {
                f.Write(bf);
                bf.Flush();
            }
        }
Exemplo n.º 3
0
        public void TestFitsCopy( /*String[] args*/ )
        {
            String file = "E:\\CSharpFITSIO\\AISCHV3_228_13637_0001_sv09-fd-int.fits" /*args[0]*/;

            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();
        }
Exemplo n.º 4
0
        public void TestBadHeader()
        {
            Fits f = null;

            try
            {
                f = new Fits(TestFileSetup.GetTargetFilename("ht1.fits"));
                ImageHDU hdu = (ImageHDU)f.GetHDU(0);
                Header   hdr = hdu.Header;
                Cursor   c   = hdr.GetCursor();

                c = hdr.GetCursor();
                c.MoveNext();
                c.MoveNext();
                c.Remove();
                bool thrown = false;
                try
                {
                    hdr.Rewrite();
                }
                catch (Exception e)
                {
                    thrown = true;
                }

                Assert.AreEqual(true, thrown);
            }
            finally
            {
                f.Close();
            }
        }
Exemplo n.º 5
0
        public void ReadByColumn()
        {
            Fits          f    = new Fits("at1.fits", FileAccess.Read);
            AsciiTableHDU hdu  = (AsciiTableHDU)f.GetHDU(1);
            AsciiTable    data = (AsciiTable)hdu.GetData();

            Object[] cols = GetSampleCols();

            Assertion.AssertEquals("Number of rows", data.NRows, 50);
            Assertion.AssertEquals("Number of columns", data.NCols, 5);

            for (int j = 0; j < data.NCols; j += 1)
            {
                Object col = data.GetColumn(j);
                if (j == 4)
                {
                    String[] st = (String[])col;
                    for (int i = 0; i < st.Length; i += 1)
                    {
                        st[i] = st[i].Trim();
                    }
                }
                Assertion.AssertEquals("Ascii Columns:" + j, true, ArrayFuncs.ArrayEquals(cols[j], col, Math.Pow(10, -6), Math.Pow(10, -14)));
            }
        }
Exemplo n.º 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));

            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();
        }
Exemplo n.º 7
0
        public void TestBadHeader()
        {
            Fits     f   = new Fits("testdocs\\ht1.fits");
            ImageHDU hdu = (ImageHDU)f.GetHDU(0);
            Header   hdr = hdu.Header;
            Cursor   c   = hdr.GetCursor();

            c = hdr.GetCursor();
            c.MoveNext();
            c.MoveNext();
            c.Remove();
            bool thrown = false;

            try
            {
                hdr.Rewrite();
            }
            catch (Exception)
            {
                thrown = true;
            }

            Assertion.AssertEquals("BITPIX delete", true, thrown);
            f.Close();
        }
Exemplo n.º 8
0
        public void TestFits()
        {
            String file = Path.GetTempFileName();
            File.Copy("..\\..\\testdocs\\ht1.fits", file, true);
            Fits f = new Fits(new FileStream(file,FileMode.Open),false);
            // Fits f = new Fits(new FileStream("E:\\CSharpFITSIO\\AISCHV3_228_13637_0001_sv09-fd-int.fits.gz",FileMode.Open),true);
             //Fits f = new Fits(new FileStream("E:\\CSharpFITSIO\\LAB-2.0kms.fits",FileMode.Open),false);
            // Fits f = new Fits("http://skyview.gsfc.nasa.gov/cgi-bin/images?position=180.0%2C8.0&survey=NEAT&pixels=300%2C300&sampler=Clip&size=0.3%2C0.3&projection=Tan&coordinates=J2000.0&return=FITS");
            // Fits f = new Fits(new FileStream("D:\\VOIndia\\Sample FITS files\\Previous\\swift_events.fits",FileMode.Open),false);

              //  String fits = "E:\\CSharpFITSIO\\AISCHV3_228_13637_0001_sv09-fd-int.fits.gz";
              //  Fits f = new Fits(fits);
            Console.Out.WriteLine("FitsReader called.");

            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);
        }
Exemplo n.º 9
0
        public void TestRewrite()
        {
            Fits f = null;

            try
            {
                // Should be rewriteable until we add enough cards to
                // start a new block.
                f = new Fits(TestFileSetup.GetTargetFilename("ht1.fits"));
                ImageHDU hdu = (ImageHDU)f.GetHDU(0);
                Header   hdr = hdu.Header;
                Cursor   c   = hdr.GetCursor();
                c.MoveNext();

                int nc = hdr.NumberOfCards;
                int nb = (nc - 1) / 36;

                while (hdr.Rewriteable)
                {
                    int nbx = (hdr.NumberOfCards - 1) / 36;
                    Assert.AreEqual(nb == nbx, hdr.Rewriteable);
                    c.Add(new HeaderCard("DUMMY" + nbx, null, null));
                }
            }
            finally
            {
                if (f != null)
                {
                    f.Close();
                }
            }
        }
Exemplo n.º 10
0
        public void CreateByColumn()
        {
            Fits f = MakeAsciiTable();

            WriteFile(f, "at1.fits");

            System.Console.Out.WriteLine("\n\n**** Create a table column by Column ****");

            f = new Fits("at1.fits", FileAccess.Read);
            AsciiTableHDU hdu = (AsciiTableHDU)f.GetHDU(1);

            Object[] inputs  = GetSampleCols();
            Object[] outputs = (Object[])hdu.Kernel;

            for (int i = 0; i < 50; i += 1)
            {
                ((String[])outputs[4])[i] = ((String[])outputs[4])[i].Trim();
            }

            for (int j = 0; j < 5; j += 1)
            {
                Assertion.AssertEquals("ByCol:" + j,
                                       true,
                                       ArrayFuncs.ArrayEquals(inputs[j], outputs[j], Math.Pow(10, -6), Math.Pow(10, -14)));
            }
        }
Exemplo n.º 11
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();
        }
Exemplo n.º 12
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();
        }
Exemplo n.º 13
0
        public void ReadByRow()
        {
            Fits f = null;

            try
            {
                f = new Fits(TestFileSetup.GetTargetFilename("at1.fits"), FileAccess.Read);
                Object[] cols = GetSampleCols();

                AsciiTableHDU hdu  = (AsciiTableHDU)f.GetHDU(1);
                AsciiTable    data = (AsciiTable)hdu.GetData();

                Console.WriteLine("Reading Table by Row");
                for (int i = 0; i < data.NRows; i += 1)
                {
                    Assert.AreEqual(50, data.NRows);
                    Object[] row = (Object[])data.GetRow(i);
                    Assert.AreEqual(1f, ((float[])cols[0])[i] / ((float[])row[0])[0], Math.Pow(10, -6));
                    Assert.AreEqual(((int[])cols[1])[i], ((int[])row[1])[0]);
                    Assert.AreEqual(((long[])cols[2])[i], ((long[])row[2])[0]);
                    Assert.AreEqual(1f, ((double[])cols[3])[i] / ((double[])row[3])[0], Math.Pow(10, -14));
                    String[] st = (String[])row[4];
                    st[0] = st[0].Trim();
                    Assert.AreEqual(((String[])cols[4])[i], ((String[])row[4])[0]);
                }
            }
            finally
            {
                if (f != null)
                {
                    f.Close();
                }
            }
        }
Exemplo n.º 14
0
        public void ReadByElement()
        {
            Fits f = null;

            try
            {
                f = new Fits(TestFileSetup.GetTargetFilename("at2.fits"), FileAccess.Read);
                AsciiTableHDU hdu  = (AsciiTableHDU)f.GetHDU(1);
                AsciiTable    data = (AsciiTable)hdu.GetData();

                for (int i = 0; i < data.NRows; i += 1)
                {
                    Object[] row = (Object[])data.GetRow(i);
                    for (int j = 0; j < data.NCols; j += 1)
                    {
                        Object val = data.GetElement(i, j);
                        Assert.AreEqual(true, ArrayFuncs.ArrayEquals(val, row[j]));
                    }
                }
            }
            finally
            {
                if (f != null)
                {
                    f.Close();
                }
            }
        }
Exemplo n.º 15
0
        // Read a FITS file
        public void ReadFile()
        {
            Initialize();

            Fits f = null;

            try
            {
                f = new Fits(TestFileSetup.GetTargetFilename("image1.fits"));
                BasicHDU[] hdus = f.Read();

                Assert.AreEqual(f.NumberOfHDUs, 8);
                Assert.AreEqual(true, ArrayFuncs.ArrayEquals(bimg, hdus[0].Data.Kernel));
                Assert.AreEqual(true, ArrayFuncs.ArrayEquals(simg, hdus[1].Data.Kernel));
                Assert.AreEqual(true, ArrayFuncs.ArrayEquals(iimg, hdus[2].Data.Kernel));
                Assert.AreEqual(true, ArrayFuncs.ArrayEquals(limg, hdus[3].Data.Kernel));
                Assert.AreEqual(true, ArrayFuncs.ArrayEquals(fimg, hdus[4].Data.Kernel));
                Assert.AreEqual(true, ArrayFuncs.ArrayEquals(dimg, hdus[5].Data.Kernel));
                Assert.AreEqual(true, ArrayFuncs.ArrayEquals(img3, hdus[6].Data.Kernel));
                Assert.AreEqual(true, ArrayFuncs.ArrayEquals(img1, hdus[7].Data.Kernel));
            }
            finally
            {
                if (f != null)
                {
                    f.Close();
                }
            }
        }
Exemplo n.º 16
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)));
            }
        }
Exemplo n.º 17
0
        public void CreateByColumn()
        {
            Fits f = MakeAsciiTable();
            WriteFile(f, "at1.fits");

            System.Console.Out.WriteLine("\n\n**** Create a table column by Column ****");

            f = new Fits("at1.fits", FileAccess.Read);
            AsciiTableHDU hdu = (AsciiTableHDU)f.GetHDU(1);

            Object[] inputs = GetSampleCols();
            Object[] outputs = (Object[])hdu.Kernel;

            for (int i = 0; i < 50; i += 1)
            {
                ((String[])outputs[4])[i] = ((String[])outputs[4])[i].Trim();
            }

            for (int j = 0; j < 5; j += 1)
            {
                Assertion.AssertEquals("ByCol:" + j,
                                        true,
                                         ArrayFuncs.ArrayEquals(inputs[j], outputs[j], Math.Pow(10, -6), Math.Pow(10, -14)));
            }
        }
Exemplo n.º 18
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();
        }
Exemplo n.º 19
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();
        }
Exemplo n.º 20
0
        public void CreateByColumn()
        {
            Fits f = null;

            try
            {
                f = MakeAsciiTable();
                WriteFile(f, TestFileSetup.GetTargetFilename("at1.fits"));

                System.Console.Out.WriteLine("\n\n**** Create a table column by Column ****");

                f = new Fits(TestFileSetup.GetTargetFilename("at1.fits"), FileAccess.Read);
                AsciiTableHDU hdu = (AsciiTableHDU)f.GetHDU(1);

                Object[] inputs  = GetSampleCols();
                Object[] outputs = (Object[])hdu.Kernel;

                for (int i = 0; i < 50; i += 1)
                {
                    ((String[])outputs[4])[i] = ((String[])outputs[4])[i].Trim();
                }

                for (int j = 0; j < 5; j += 1)
                {
                    Assert.AreEqual(true,
                                    ArrayFuncs.ArrayEquals(inputs[j], outputs[j], Math.Pow(10, -6), Math.Pow(10, -14)));
                }
            }
            finally
            {
                f.Close();
            }
        }
Exemplo n.º 21
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 = new Fits();

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

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

            f = new Fits("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);
        }
Exemplo n.º 22
0
        void WriteFile(Fits f, String name)
        {
            BufferedFile bf = new BufferedFile(name, FileAccess.ReadWrite, FileShare.ReadWrite);

            f.Write(bf);
            bf.Flush();
            bf.Close();
        }
Exemplo n.º 23
0
        public void CreateByRow()
        {
            Fits f = null;

            try
            {
                f = new Fits();
                AsciiTable data = new AsciiTable();
                Object[]   row  = new Object[4];

                System.Console.Out.WriteLine("\n\n**** Create a table column by Row ****");

                for (int i = 0; i < 50; i += 1)
                {
                    data.AddRow(GetRow(i));
                }

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

                WriteFile(f, TestFileSetup.GetTargetFilename("at2.fits"));
                f.Close();

                // Read it back.
                f = new Fits(TestFileSetup.GetTargetFilename("at2.fits"), FileAccess.Read);

                Object[] output = (Object[])f.GetHDU(1).Kernel;
                Object[] input  = GetRowBlock(50);

                for (int i = 0; i < 50; i += 1)
                {
                    String[] str  = (String[])output[2];
                    String[] istr = (String[])input[2];
                    int      len1 = str[1].Length;
                    str[i] = str[i].Trim();
                    // The first row would have set the length for all the
                    // remaining rows...
                    if (istr[i].Length > len1)
                    {
                        istr[i] = istr[i].Substring(0, len1);
                    }
                }

                for (int j = 0; j < 3; j += 1)
                {
                    Assert.AreEqual(true,
                                    ArrayFuncs.ArrayEquals(input[j], output[j], Math.Pow(10, -6), Math.Pow(10, -14)));
                }
            }
            finally
            {
                if (f != null)
                {
                    f.Close();
                }
            }
        }
Exemplo n.º 24
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();
        }
Exemplo n.º 25
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();
                }
            }
        }
Exemplo n.º 26
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);
        }
Exemplo n.º 27
0
        Fits MakeAsciiTable()
        {
            Object[] obj = GetSampleCols();

            // Create new AsciiTable
            Fits f = new Fits();

            f.AddHDU(Fits.MakeHDU(obj));
            return(f);
        }
Exemplo n.º 28
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();
        }
Exemplo n.º 29
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();
        }
Exemplo n.º 30
0
        public FitsData(Uri uri, bool isInterleave = false)
        {
            var fitsData = new nom.tam.fits.Fits(uri.OriginalString);

            PrimaryHdu = (ImageHDU)fitsData.ReadHDU();

            if (Axes.Length == 2)
            {
                Channels = 1;
                Width    = Axes[0];
                Height   = Axes[1];
            }
            else if (Axes.Length == 3)
            {
                Channels = Axes[0];
                Width    = Axes[1];
                Height   = Axes[2];
            }

            if (BufferSize > 4294967296)
            {
                throw new NotSupportedException("Image Size greater than 4GB aren't supported.");
            }

            IpcChannelDataType dataType;

            if (BitPix == 8 || BitPix == 16 || BitPix == 32)
            {
                dataType = IpcChannelDataType.UInt;
            }
            else if (BitPix == -32 || BitPix == -64)
            {
                dataType = IpcChannelDataType.Float;
            }
            else
            {
                throw new NotSupportedException("Bitpix field in pix is not 8,16,32,-32 or 64. BitSize " + BitPix + " is an unsupported value.");
            }

            BitsPerPixel  = Math.Abs(BitPix);
            BytesPerPixel = BitsPerPixel / 8;

            IpcPixelFormat = isInterleave ?
                             IpcPixelFormats.GetMatchingFormat(Channels, BitsPerPixel, dataType) :
                             IpcPixelFormats.GetMatchingFormat(1, BitsPerPixel, dataType);

            //Construct header card dictionary.
            foreach (DictionaryEntry card in PrimaryHdu.Header)
            {
                HeaderCardDictionary.Add((HeaderCard)card.Value);
            }
        }
Exemplo n.º 31
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();
                }
            }
        }
Exemplo n.º 32
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();
        }
Exemplo n.º 33
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();
                }
            }
        }
Exemplo n.º 34
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();
                }
            }
        }
Exemplo n.º 35
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();
                }
            }
        }
Exemplo n.º 36
0
        public void ReadByElement()
        {
            Fits          f    = new Fits("at2.fits", FileAccess.Read);
            AsciiTableHDU hdu  = (AsciiTableHDU)f.GetHDU(1);
            AsciiTable    data = (AsciiTable)hdu.GetData();


            for (int i = 0; i < data.NRows; i += 1)
            {
                Object[] row = (Object[])data.GetRow(i);
                for (int j = 0; j < data.NCols; j += 1)
                {
                    Object val = data.GetElement(i, j);
                    Assertion.AssertEquals("Ascii readElement", true, ArrayFuncs.ArrayEquals(val, row[j]));
                }
            }
        }
Exemplo n.º 37
0
        public void CreateByRow()
        {
            Fits f = new Fits();
            AsciiTable data = new AsciiTable();
            Object[] row = new Object[4];

            System.Console.Out.WriteLine("\n\n**** Create a table column by Row ****");

            for (int i = 0; i < 50; i += 1)
            {
                data.AddRow(GetRow(i));
            }

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

            WriteFile(f, "at2.fits");

            // Read it back.
            f = new Fits("at2.fits", FileAccess.Read);

            Object[] output = (Object[])f.GetHDU(1).Kernel;
            Object[] input = GetRowBlock(50);

            for (int i = 0; i < 50; i += 1)
            {
                String[] str = (String[])output[2];
                String[] istr = (String[])input[2];
                int len1 = str[1].Length;
                str[i] = str[i].Trim();
                // The first row would have set the length for all the
                // remaining rows...
                if (istr[i].Length > len1)
                {
                    istr[i] = istr[i].Substring(0, len1);
                }
            }

            for (int j = 0; j < 3; j += 1)
            {
                Assertion.AssertEquals("ByRow:" + j, true, ArrayFuncs.ArrayEquals(input[j], output[j], Math.Pow(10, -6), Math.Pow(10, -14)));
            }
        }
Exemplo n.º 38
0
        public void Save(Exposure exposure, string filename, Dictionary<string, object> metadata)
        {
            Fits fits = new Fits();
            int[] dimensions = new[] { exposure.Height, exposure.Width };

            // choose the type from calculating the bitness from the exposure maxdepth
            long a = 0, bits = -1;
            while (a < exposure.MaxDepth)
                a = (int)Math.Pow(2.0, ++bits);

            Array pixels;
            if (bits <= 16)
            {
                pixels = ConvertToShort(exposure.Pixels);
            }
            else
            {
                pixels = exposure.Pixels;
            }

            var data = ArrayFuncs.Curl(pixels, dimensions);
            var hdu = FitsFactory.HDUFactory(data);

            // Write the headers.

            BuildHeader(hdu.Header, exposure, metadata, a);

            fits.AddHDU(hdu);

            if (!filename.EndsWith(".fits"))
                filename += ".fits";

            BufferedFile bf = new BufferedFile(filename, FileAccess.ReadWrite, FileShare.None);
            fits.Write(bf);
            bf.Close();
        }
Exemplo n.º 39
0
        public void TestBadHeader()
        {
            Fits f = new Fits("ht1.fits");
            ImageHDU hdu = (ImageHDU)f.GetHDU(0);
            Header hdr = hdu.Header;
            Cursor c = hdr.GetCursor();

            c = hdr.GetCursor();
            c.MoveNext();
            c.MoveNext();
            c.Remove();
            bool thrown = false;
            try
            {
                hdr.Rewrite();
            }
            catch (Exception )
            {
                thrown = true;
            }

            Assertion.AssertEquals("BITPIX delete", true, thrown);
            f.Close();
        }
Exemplo n.º 40
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();
        }
Exemplo n.º 41
0
        public void TestRewrite()
        {
            // Should be rewriteable until we add enough cards to
            // start a new block.

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

            int nc = hdr.NumberOfCards;
            int nb = (nc - 1) / 36;

            while (hdr.Rewriteable)
            {
                int nbx = (hdr.NumberOfCards - 1) / 36;
                Assertion.AssertEquals("Rewrite:" + nbx, nb == nbx, hdr.Rewriteable);
                c.Add(new HeaderCard("DUMMY" + nbx, null, null));
            }
            f.Close();
        }
Exemplo n.º 42
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();
        }
Exemplo n.º 43
0
        public void TestCursor()
        {
            Fits f = new Fits("ht1.fits");
            ImageHDU hdu = (ImageHDU)f.GetHDU(0);
            Header hdr = hdu.Header;
            Cursor c = hdr.GetCursor();

            c.Key = "XXX";
            c.Add("CTYPE1", new HeaderCard("CTYPE1", "GLON-CAR", "Galactic Longitude"));
            c.Add("CTYPE2", new HeaderCard("CTYPE2", "GLAT-CAR", "Galactic Latitude"));

            c.Key = "CTYPE1";  // Move before CTYPE1
            c.Add("CRVAL1", new HeaderCard("CRVAL1", 0f, "Longitude at reference"));

            c.Key = "CTYPE2"; // Move before CTYPE2
            c.Add("CRVAL2", new HeaderCard("CRVAL2", -90f, "Latitude at reference"));

            c.Key = "CTYPE1";  // Just practicing moving around!!
            c.Add("CRPIX1", new HeaderCard("CRPIX1", 150.0, "Reference Pixel X"));

            c.Key = "CTYPE2";
            c.Add("CRPIX2", new HeaderCard("CRPIX2", 0f, "Reference pixel Y"));
            c.Add("INV2", new HeaderCard("INV2", true, "Invertible axis"));
            c.Add("SYM2", new HeaderCard("SYM2", "YZ SYMMETRIC", "Symmetries..."));

            Assertion.AssertEquals("CTYPE1", "GLON-CAR", hdr.GetStringValue("CTYPE1"));
            Assertion.AssertEquals("CRPIX2", 0f, hdr.GetDoubleValue("CRPIX2", -2f));

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

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

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

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

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

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

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

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

            hdr.FindCard("CRPIX1");
            hdr.AddValue("INTVAL1", 1, "An integer value");
            hdr.AddValue("LOG1", true, "A true value");
            hdr.AddValue("LOGB1", false, "A false value");
            hdr.AddValue("FLT1", 1.34, "A float value");
            hdr.AddValue("FLT2", -1.234567890e-134, "A very long float");
            hdr.AddValue("COMMENT", null, "Comment after flt2");

            c.Key = "INTVAL1";

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

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

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

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

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

            c.MoveNext(); // Skip comment
            hc = (HeaderCard)((DictionaryEntry)c.Current).Value;
            c.MoveNext();
            Assertion.AssertEquals("CRPIX1x", "CRPIX1", hc.Key);

            Assertion.AssertEquals("FLT1", 1.34, hdr.GetDoubleValue("FLT1", 0));

            c.Key = "FLT1";
            c.Remove();
            Assertion.AssertEquals("FLT1", 0f, hdr.GetDoubleValue("FLT1", 0));

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

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

            hc = (HeaderCard)((DictionaryEntry)c.Current).Value;
            Assertion.AssertEquals("AftDel3", "Comment after flt2", hc.Comment);
            c.MoveNext();

            f.Close();
        }
Exemplo n.º 44
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();
        }
Exemplo n.º 45
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();
        }
Exemplo n.º 46
0
        public void BuildByRow()
        {
            Fits f = new Fits("bt2.fits", FileAccess.Read);
            f.Read();
            BinaryTableHDU bhdu = (BinaryTableHDU)f.GetHDU(1);
            Header hdr = bhdu.Header;
            BinaryTable btab = (BinaryTable)bhdu.Data;
            for (int i = 0; i < 50; i += 1)
            {
                Object[] row = (Object[])btab.GetRow(i);
                float[] qx = (float[])row[1];
                Array[] p = (Array[])row[0];
                float[] pt = (float[])p.GetValue(0);
                pt[0] = (float)(i * Math.Sin(i));
                btab.AddRow(row);
            }

            f = new Fits();
            f.AddHDU(Fits.MakeHDU(btab));
            BufferedFile bf = new BufferedFile("bt4.fits", FileAccess.ReadWrite, FileShare.ReadWrite);
            f.Write(bf);
            bf.Flush();
            bf.Close();

               f = new Fits("bt4.fits", FileAccess.Read);

            btab = (BinaryTable)f.GetHDU(1).Data;
            Assertion.AssertEquals("row1", 100, btab.nRow);

            // Try getting data before we Read in the table.

            Array[] xf = (Array[])btab.GetColumn(0);
            Array[] xft = (Array[])xf.GetValue(50);
            float[] xftt = (float[])xft.GetValue(0);
            Assertion.AssertEquals("row2", (float)0, (float)xftt[0]);
            xft = (Array[])xf.GetValue(99);
            xftt = (float[])xft.GetValue(0);
            Assertion.AssertEquals("row3", (float)(49 * Math.Sin(49)), (float)xftt[0]);

            for (int i = 0; i < xf.Length; i += 3)
            {
                bool[] ba = (bool[])btab.GetElement(i, 5);
                float[] fx = (float[])btab.GetElement(i, 1);

                int trow = i % 50;

                Assertion.AssertEquals("row4", true, ArrayFuncs.ArrayEquals(ba, vbool[trow])); // prob 1
                Assertion.AssertEquals("row6", true, ArrayFuncs.ArrayEquals(fx, vf[trow]));
            }
            // Fill the table.
            Data data = f.GetHDU(1).Data;

            xf = (Array[])btab.GetColumn(0);
            xft = (Array[])xf.GetValue(50);
            xftt = (float[])xft.GetValue(0);
            Assertion.AssertEquals("row7", 0F, (float)xftt[0]);
            xft = (Array[])xf.GetValue(99);
            xftt = (float[])xft.GetValue(0);
            Assertion.AssertEquals("row8", (float)(49 * Math.Sin(49)), (float)xftt[0]);

            for (int i = 0; i < xf.Length; i += 3)
            {
                bool[] ba = (bool[])btab.GetElement(i, 5);
                float[] fx = (float[])btab.GetElement(i, 1);

                int trow = i % 50;

                Assertion.AssertEquals("row9", true, ArrayFuncs.ArrayEquals(ba, vbool[trow])); // prob 2
                Assertion.AssertEquals("row11", true, ArrayFuncs.ArrayEquals(fx, vf[trow]));
            }
            f.Close();
        }
Exemplo n.º 47
0
        // Read a FITS file
        public void ReadFile()
        {
            Initialize();

            Fits f = new Fits("image1.fits");
            BasicHDU[] hdus = f.Read();

            Assertion.AssertEquals("HDU count after", f.NumberOfHDUs, 8);
            Assertion.AssertEquals("byte image", true, ArrayFuncs.ArrayEquals(bimg, hdus[0].Data.Kernel));
            Assertion.AssertEquals("short image", true, ArrayFuncs.ArrayEquals(simg, hdus[1].Data.Kernel));
            Assertion.AssertEquals("int image", true, ArrayFuncs.ArrayEquals(iimg, hdus[2].Data.Kernel));
            Assertion.AssertEquals("long image", true, ArrayFuncs.ArrayEquals(limg, hdus[3].Data.Kernel));
            Assertion.AssertEquals("float image", true, ArrayFuncs.ArrayEquals(fimg, hdus[4].Data.Kernel));
            Assertion.AssertEquals("double image", true, ArrayFuncs.ArrayEquals(dimg, hdus[5].Data.Kernel));
            Assertion.AssertEquals("int3 image", true, ArrayFuncs.ArrayEquals(img3, hdus[6].Data.Kernel));
            Assertion.AssertEquals("double1 image", true, ArrayFuncs.ArrayEquals(img1, hdus[7].Data.Kernel));
        }
Exemplo n.º 48
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)));
            }
        }
Exemplo n.º 49
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();
        }
Exemplo n.º 50
0
        public void TestSet()
        {
            Fits f = new Fits("bt2.fits", FileAccess.Read);
            f.Read();
            BinaryTableHDU bhdu = (BinaryTableHDU)f.GetHDU(1);
            Header hdr = bhdu.Header;

            // Check the various set methods on variable length data.
            float[] dta = (float[])bhdu.GetElement(4, 1);
            dta = new float[] { 22, 21, 20 };
            bhdu.SetElement(4, 1, dta);

            // BufferedDataStream bdos = new BufferedDataStream(new FileStream("bt2a.fits",FileMode.Open));
            BufferedFile bdos = new BufferedFile("bt2a.fits", FileAccess.ReadWrite, FileShare.ReadWrite);
            f.Write(bdos);
            bdos.Close();

            f = new Fits("bt2a.fits");
            bhdu = (BinaryTableHDU)f.GetHDU(1);
            float[] xdta = (float[])bhdu.GetElement(4, 1);

            Assertion.AssertEquals("ts1", true, ArrayFuncs.ArrayEquals(dta, xdta));
            Assertion.AssertEquals("ts2", true, ArrayFuncs.ArrayEquals(bhdu.GetElement(3, 1), vf[3]));
            Assertion.AssertEquals("ts5", true, ArrayFuncs.ArrayEquals(bhdu.GetElement(5, 1), vf[5]));

            Assertion.AssertEquals("ts4", true, ArrayFuncs.ArrayEquals(bhdu.GetElement(4, 1), dta));

            float[] tvf = new float[] { 101, 102, 103, 104 };
            vf[4] = tvf;

            bhdu.SetColumn(1, vf);
            Assertion.AssertEquals("ts6", true, ArrayFuncs.ArrayEquals(bhdu.GetElement(3, 1), vf[3]));
            Assertion.AssertEquals("ts7", true, ArrayFuncs.ArrayEquals(bhdu.GetElement(4, 1), vf[4]));
            Assertion.AssertEquals("ts8", true, ArrayFuncs.ArrayEquals(bhdu.GetElement(5, 1), vf[5]));

            // bdos = new BufferedDataStream(new FileStream("bt2b.fits",FileMode.Open));
            bdos = new BufferedFile("bt2b.fits", FileAccess.ReadWrite, FileShare.ReadWrite);
            f.Write(bdos);
            bdos.Close();
            f.Close();

            f = new Fits("bt2b.fits");
            bhdu = (BinaryTableHDU)f.GetHDU(1);
            Assertion.AssertEquals("ts9", true, ArrayFuncs.ArrayEquals(bhdu.GetElement(3, 1), vf[3]));
            Assertion.AssertEquals("ts10", true, ArrayFuncs.ArrayEquals(bhdu.GetElement(4, 1), vf[4]));
            Assertion.AssertEquals("ts11", true, ArrayFuncs.ArrayEquals(bhdu.GetElement(5, 1), vf[5]));

            Object[] rw = (Object[])bhdu.GetRow(4);

            float[] trw = new float[] { -1, -2, -3, -4, -5, -6 };
            rw[1] = trw;

            bhdu.SetRow(4, rw);
            Assertion.AssertEquals("ts12", true, ArrayFuncs.ArrayEquals(bhdu.GetElement(3, 1), vf[3]));
            Assertion.AssertEquals("ts13", false, ArrayFuncs.ArrayEquals(bhdu.GetElement(4, 1), vf[4]));
            Assertion.AssertEquals("ts14", true, ArrayFuncs.ArrayEquals(bhdu.GetElement(4, 1), trw));
            Assertion.AssertEquals("ts15", true, ArrayFuncs.ArrayEquals(bhdu.GetElement(5, 1), vf[5]));

            // bdos = new BufferedDataStream(new FileStream("bt2c.fits",FileMode.Open));
            bdos = new BufferedFile("bt2c.fits", FileAccess.ReadWrite, FileShare.ReadWrite);
            f.Write(bdos);
            bdos.Close();
            f.Close();

            f = new Fits("bt2c.fits");
            bhdu = (BinaryTableHDU)f.GetHDU(1);
            Assertion.AssertEquals("ts16", true, ArrayFuncs.ArrayEquals(bhdu.GetElement(3, 1), vf[3]));
            Assertion.AssertEquals("ts17", false, ArrayFuncs.ArrayEquals(bhdu.GetElement(4, 1), vf[4]));
            Assertion.AssertEquals("ts18", true, ArrayFuncs.ArrayEquals(bhdu.GetElement(4, 1), trw));
            Assertion.AssertEquals("ts19", true, ArrayFuncs.ArrayEquals(bhdu.GetElement(5, 1), vf[5]));
            f.Close();
        }
Exemplo n.º 51
0
        public void TestRandomGroup()
        {
            //float[,] fa = new float[20,20];
            float[][] fa = new float[20][];
            for (int i = 0; i < fa.Length; i++)
                fa[i] = new float[20];
            float[] pa = new float[3];

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

            Object[][] data = new Object[1][];
            data[0] = new Object[2];
            data[0][0] = pa;
            data[0][1] = fa;

            System.Console.Out.WriteLine("***** Write header ******");
            BasicHDU hdu = Fits.MakeHDU(data);
            Header hdr = hdu.Header;

            // Change the number of groups
            hdr.AddValue("GCOUNT", 20, "Number of groups");
            hdr.Write(bf);

            System.Console.Out.WriteLine("***** Write data group by group ******");
            for (int i = 0; i < 20; i += 1)
            {

                for (int j = 0; j < pa.Length; j += 1)
                {
                    pa[j] = i + j;
                }
                for (int j = 0; j < fa.GetLength(0); j += 1)
                {
                    try
                    {
                        //  fa[j, j] = i * j;
                        fa[j][j] = i * j;
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message); ;
                        Console.WriteLine("i ,j value:" + i + "   " + j);
                    }
                }
                // Write a group
                bf.WriteArray(data);
            }

            byte[] padding = new byte[FitsUtil.Padding(20 * ArrayFuncs.ComputeSize(data))];
            System.Console.Out.WriteLine("****** Write padding ******");
            bf.Write(padding);

            bf.Flush();
            bf.Close();

            System.Console.Out.WriteLine("****** Read data back in ******");
            Fits f = new Fits("rg1.fits");
            BasicHDU[] hdus = f.Read();

            data = (Object[][])hdus[0].Kernel;
            // data = hdus[0].Kernel;
            System.Console.Out.WriteLine("**** Check parameter and data info *****");
            for (int i = 0; i < data.Length; i += 1)
            {

                pa = (float[])data[i][0];
                // fa = (float[,]) data[i,1];
                Array[] tfa = (Array[])data[i][1];
                for (int j = 0; j < pa.Length; j += 1)
                {
                    Assertion.AssertEquals("paramTest:" + i + " " + j, (float)(i + j), pa[j]);
                }
                for (int j = 0; j < fa.Length; j += 1)
                {
                    // Assertion.AssertEquals("dataTest:" + i + " " + j, (float)(i * j), fa[j,j]);
                    Assertion.AssertEquals("dataTest:" + i + " " + j, (float)(i * j), ((Array)tfa.GetValue(j)).GetValue(j));
                }
            }

            f = new Fits();

            System.Console.Out.WriteLine("**** Create HDU from kernel *****");

            // Generate a FITS HDU from the kernel.
            f.AddHDU(Fits.MakeHDU(data));
            bf = new BufferedFile("rg2.fits", FileAccess.ReadWrite, FileShare.ReadWrite);
            System.Console.Out.WriteLine("**** Write new file *****");
            f.Write(bf);

            bf.Flush();
            bf.Close();

            System.Console.Out.WriteLine("**** Read and check *****");
            f = new Fits("rg2.fits");
            data = (Object[][])f.Read()[0].Kernel;
            for (int i = 0; i < data.Length; i += 1)
            {

                pa = (float[])data[i][0];
                //   fa = (float[,]) data[i,1];
                Array[] tfa = (Array[])data[i][1];
                for (int j = 0; j < pa.Length; j += 1)
                {
                    Assertion.AssertEquals("paramTest:" + i + " " + j, (float)(i + j), pa[j]);
                }
                for (int j = 0; j < fa.Length; j += 1)
                {
                    //Assertion.AssertEquals("dataTest:" + i + " " + j, (float)(i * j), fa[j,j]);
                    Assertion.AssertEquals("dataTest:" + i + " " + j, (float)(i * j), ((Array)tfa.GetValue(j)).GetValue(j));
                }
            }
        }
Exemplo n.º 52
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();
        }
Exemplo n.º 53
0
        public void MakeDataFile()
        {
            string pathToCorr = "";
            if (GlobalVariables.LocalPlateSolve)
                pathToCorr = @"c:\cygwin\home\astro\solve.corr";
            else
                pathToCorr = GlobalVariables.Path2 + "\\corr.fits";
                
           // Fits f = new Fits(GlobalVariables.Path2 + "\\corr.fits"); // original
           Fits f = new Fits(pathToCorr);
            BinaryTableHDU h = (BinaryTableHDU)f.GetHDU(1);

            //   Object[] row23 = h.GetRow(23);
            Object col_x = h.GetColumn(0);
            Object col_y = h.GetColumn(1);
            Object col_ra = h.GetColumn(2);
            Object col_dec = h.GetColumn(3);
            float[] x = new float[h.NRows];
            float[] y = new float[h.NRows];
            float[] ra = new float[h.NRows];
            float[] dec = new float[h.NRows];
            GlobalVariables.CorrFileLines = h.NRows;
            int i = 0;
            foreach (float item in (dynamic)col_x)
            {
                x[i] = (dynamic)(item);
                i++;
            }
            i = 0;
            foreach (float item2 in (dynamic)col_y)
            {
                y[i] = (dynamic)(item2);
                i++;
            }
            i = 0;
            foreach (float item in (dynamic)col_ra)
            {
                ra[i] = (dynamic)(item)/15;
                i++;
            }
            i = 0;
            foreach (float item2 in (dynamic)col_dec)
            {
                dec[i] = (dynamic)(item2);
                i++;
            }
           
            using (StreamWriter sr = new StreamWriter(GlobalVariables.Path2 + "\\corr2text.txt"))
            {
                // sr.WriteLine("   x   " + "         y   ");
                for (i = 0; i < x.Length; i++)
                {
                    sr.WriteLine(x[i] + "    \t" + y[i] + "    \t" + ra[i] + "    \t" + dec[i]);

                }
                
                sr.Dispose();
            }
            Log("Corr2text file complete in " + GlobalVariables.Path2);
           
        }
Exemplo n.º 54
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();
        }
Exemplo n.º 55
0
        /// <summary>
        /// writes the header to fits file
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="filename"></param>
        /// <param name="writeMode"></param>
        /// <param name="stringTruncationLength"></param>
        /// <param name="padStringsLeft"></param>
        /// <param name="stringPadChar"></param>
        public static void Write(IDataReader reader, String filename,
                                StreamedBinaryTableHDU.StringWriteMode writeMode, int stringTruncationLength,
                                bool padStringsLeft, char stringPadChar)
        {
            Header header = new Header();
              header.Simple = true;
              header.Bitpix = 8;
              header.Naxes = 0;

              Cursor c = header.GetCursor();
              // move to the end of the header cards
              for(c.MoveNext(); c.MoveNext(););
              // we know EXTEND isn't there yet
              c.Add("EXTEND", new HeaderCard("EXTEND", true, null));

              ImageHDU hdu1 = new ImageHDU(header, null);

              StreamedBinaryTableHDU hdu2 =
            new StreamedBinaryTableHDU(new DataReaderAdapter(reader), 4096,
            writeMode, stringTruncationLength, padStringsLeft, stringPadChar);

              Fits fits = new Fits();
              fits.AddHDU(hdu1);
              fits.AddHDU(hdu2);

              Stream s = null;
              try
              {
            s = new FileStream(filename, FileMode.Create);
            fits.Write(s);
            s.Close();
              }
              catch(Exception e)
              {
            s.Close();
            throw(e);
              }
        }
Exemplo n.º 56
0
        public void TestRowDelete()
        {
            Fits f = new Fits("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();
        }
Exemplo n.º 57
0
 void WriteFile(Fits f, String name)
 {
     BufferedFile bf = new BufferedFile(name, FileAccess.ReadWrite, FileShare.ReadWrite);
     f.Write(bf);
     bf.Flush();
     bf.Close();
 }
Exemplo n.º 58
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);
                    }
                }
            }
Exemplo n.º 59
0
 public FitsImporter(string filePath)
 {
     _filePath = filePath;
     _fits = new Fits(filePath);
 }
Exemplo n.º 60
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();
        }