예제 #1
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();
                }
            }
        }
예제 #2
0
 /// <summary>Given a Header return an appropriate datum.</summary>
 internal static Data DataFactory(Header hdr)
 {
     if (ImageHDU.IsHeader(hdr))
     {
         return(ImageHDU.ManufactureData(hdr));
     }
     else if (RandomGroupsHDU.IsHeader(hdr))
     {
         return(RandomGroupsHDU.ManufactureData(hdr));
     }
     else if (useAsciiTables && AsciiTableHDU.IsHeader(hdr))
     {
         return(AsciiTableHDU.ManufactureData(hdr));
     }
     else if (BinaryTableHDU.IsHeader(hdr))
     {
         return(BinaryTableHDU.ManufactureData(hdr));
     }
     else if (UndefinedHDU.IsHeader(hdr))
     {
         return(UndefinedHDU.ManufactureData(hdr));
     }
     else
     {
         throw new FitsException("Unrecognizable header in dataFactory");
     }
 }
예제 #3
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();
            }
        }
예제 #4
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();
                }
            }
        }
예제 #5
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)));
            }
        }
예제 #6
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)));
            }
        }
예제 #7
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]));
                }
            }
        }
예제 #8
0
        // change suggested in .99.5 version: Method made public from protected.
        /// <summary>Given an object, create the appropriate FITS header to describe it.</summary>
        /// <param name="o">The object to be described.</param>
        public static BasicHDU HDUFactory(Object o)
        {
            Data   d;
            Header h;

            if (ImageHDU.IsData(o))
            {
                d = ImageHDU.Encapsulate(o);
                h = ImageHDU.ManufactureHeader(d);
            }
            else if (RandomGroupsHDU.IsData(o))
            {
                d = RandomGroupsHDU.Encapsulate(o);
                h = RandomGroupsHDU.ManufactureHeader(d);
            }
            else if (useAsciiTables && AsciiTableHDU.IsData(o))
            {
                d = AsciiTableHDU.Encapsulate(o);
                h = AsciiTableHDU.ManufactureHeader(d);
            }
            else if (BinaryTableHDU.IsData(o))
            {
                d = BinaryTableHDU.Encapsulate(o);
                h = BinaryTableHDU.ManufactureHeader(d);
            }
            else if (UndefinedHDU.IsData(o))
            {
                d = UndefinedHDU.Encapsulate(o);
                h = UndefinedHDU.ManufactureHeader(d);
            }
            else
            {
                Console.WriteLine();
                throw new FitsException("Invalid data presented to HDUFactory");
            }

            return(HDUFactory(h, d));
        }
예제 #9
0
        public void ReadByRow()
        {
            Fits f = new Fits("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)
            {
                Assertion.AssertEquals("Rows:" + i, 50, data.NRows);
                Object[] row = (Object[])data.GetRow(i);
                Assertion.AssertEquals("Ascii Rows: float" + i, 1f, ((float[])cols[0])[i] / ((float[])row[0])[0], Math.Pow(10, -6));
                Assertion.AssertEquals("Ascii Rows: int" + i, ((int[])cols[1])[i], ((int[])row[1])[0]);
                Assertion.AssertEquals("Ascii Rows: long" + i, ((long[])cols[2])[i], ((long[])row[2])[0]);
                Assertion.AssertEquals("Ascii Rows: double" + i, 1f, ((double[])cols[3])[i] / ((double[])row[3])[0], Math.Pow(10, -14));
                String[] st = (String[])row[4];
                st[0] = st[0].Trim();
                Assertion.AssertEquals("Ascii Rows: Str" + i, ((String[])cols[4])[i], ((String[])row[4])[0]);
            }
        }
예제 #10
0
        public void ReadByColumn()
        {
            Fits f = null;

            try
            {
                f = new Fits(TestFileSetup.GetTargetFilename("at1.fits"), FileAccess.Read);
                AsciiTableHDU hdu  = (AsciiTableHDU)f.GetHDU(1);
                AsciiTable    data = (AsciiTable)hdu.GetData();
                Object[]      cols = GetSampleCols();

                Assert.AreEqual(data.NRows, 50);
                Assert.AreEqual(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();
                        }
                    }
                    Assert.AreEqual(true, ArrayFuncs.ArrayEquals(cols[j], col, Math.Pow(10, -6), Math.Pow(10, -14)));
                }
            }
            finally
            {
                if (f != null)
                {
                    f.Close();
                }
            }
        }
예제 #11
0
        public void ModifyTable()
        {
            Fits f = null;

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

                Object[] samp = GetSampleCols();

                AsciiTableHDU hdu  = (AsciiTableHDU)f.GetHDU(1);
                AsciiTable    data = (AsciiTable)hdu.GetData();
                float[]       f1   = (float[])data.GetColumn(0);
                float[]       f2   = (float[])f1.Clone();
                for (int i = 0; i < f2.Length; i += 1)
                {
                    f2[i] = 2 * f2[i];
                }

                data.SetColumn(0, f2);
                f1 = new float[] { 3.14159f };
                data.SetElement(3, 0, f1);

                hdu.SetNullString(0, "**INVALID**");
                data.SetNull(5, 0, true);
                data.SetNull(6, 0, true);

                Object[] row = new Object[5];
                row[0] = new float[] { 6.28f };
                row[1] = new int[] { 22 };
                row[2] = new long[] { 0 };
                row[3] = new double[] { -3 };
                row[4] = new String[] { "A string" };

                data.SetRow(5, row);

                data.SetElement(4, 2, new long[] { 54321 });

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

                f = new Fits(TestFileSetup.GetTargetFilename("at1x.fits"), FileAccess.Read);
                AsciiTable tab = (AsciiTable)f.GetHDU(1).Data;

                Object[] kern = (Object[])tab.Kernel;

                float[]  fx = (float[])kern[0];
                int[]    ix = (int[])kern[1];
                long[]   lx = (long[])kern[2];
                double[] dx = (double[])kern[3];
                String[] sx = (String[])kern[4];

                float[]  fy = (float[])samp[0];
                int[]    iy = (int[])samp[1];
                long[]   ly = (long[])samp[2];
                double[] dy = (double[])samp[3];
                String[] sy = (String[])samp[4];

                Assert.AreEqual(true, tab.IsNull(6, 0));
                Assert.AreEqual(false, tab.IsNull(5, 0));

                for (int i = 0; i < data.NRows; i += 1)
                {
                    if (i != 5)
                    {
                        if (i != 6)
                        {
                            // Null
                            Assert.AreEqual(1f, f2[i] / fx[i], Math.Pow(10, -6));
                        }
                        Assert.AreEqual(iy[i], ix[i]);

                        if (i == 4)
                        {
                            Assert.AreEqual(54321L, lx[i]);
                        }
                        else
                        {
                            Assert.AreEqual(ly[i], lx[i]);
                        }

                        Assert.AreEqual(1f, dy[i] / dx[i], Math.Pow(10, -14));
                        Assert.AreEqual(sy[i], sx[i].Trim());
                    }
                }
                Object[] r5 = (Object[])data.GetRow(5);
                String[] st = (String[])r5[4];
                st[0] = st[0].Trim();
                for (int i = 0; i < r5.Length; i++)
                {
                    Assert.AreEqual(true, ArrayFuncs.ArrayEquals(row[i], r5[i], Math.Pow(10, -6), Math.Pow(10, -14)));
                }
            }
            finally
            {
                if (f != null)
                {
                    f.Close();
                }
            }
        }