예제 #1
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();
        }
예제 #2
0
        // Make FITS file
        public void MakeFile()
        {
            Initialize();

            Fits f = new Fits();

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

            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();
        }
        internal void SaveFitsFrame(string fileName, int width, int height, uint[] framePixels, DateTime timeStamp, float exposureSeconds)
        {
            Fits f = new Fits();

            object data = SaveImageData(width, height, framePixels);

            BasicHDU imageHDU = Fits.MakeHDU(data);

            nom.tam.fits.Header hdr = imageHDU.Header;
            hdr.AddValue("SIMPLE", "T", null);

            hdr.AddValue("BITPIX", 32, null);

            hdr.AddValue("NAXIS", 2, null);
            hdr.AddValue("NAXIS1", width, null);
            hdr.AddValue("NAXIS2", height, null);

            hdr.AddValue("NOTES", m_Note, null);

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

            hdr.AddValue("DATE-OBS", timeStamp.ToString("yyyy-MM-ddTHH:mm:ss.fff", CultureInfo.InvariantCulture), m_DateObsComment);

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

            f.AddHDU(imageHDU);

            // Write a FITS file.
            using (BufferedFile bf = new BufferedFile(fileName, FileAccess.ReadWrite, FileShare.ReadWrite))
            {
                f.Write(bf);
                bf.Flush();
            }
        }
예제 #4
0
        void WriteFile(Fits f, String name)
        {
            BufferedFile bf = new BufferedFile(name, FileAccess.ReadWrite, FileShare.ReadWrite);

            f.Write(bf);
            bf.Flush();
            bf.Close();
        }
예제 #5
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();
        }
예제 #6
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();
        }
예제 #7
0
        internal static void SaveDarkOrFlatFrame(string fileName, int width, int height, string notes, float[,] averagedData, float exposureSeconds, int numFrames)
        {
            Fits f = new Fits();

            object data = SaveImageData(width, height, averagedData);

            BasicHDU imageHDU = Fits.MakeHDU(data);

            nom.tam.fits.Header hdr = imageHDU.Header;
            hdr.AddValue("SIMPLE", "T", null);

            hdr.AddValue("BITPIX", -32 /* Floating Point Data*/, null);
            hdr.AddValue("NAXIS", 2, null);
            hdr.AddValue("NAXIS1", width, null);
            hdr.AddValue("NAXIS2", height, null);


            if (notes.Length > HeaderCard.MAX_VALUE_LENGTH)
            {
                notes = notes.Substring(0, HeaderCard.MAX_VALUE_LENGTH);
            }
            hdr.AddValue("NOTES", notes, null);

            if (exposureSeconds > 0)
            {
                hdr.AddValue("EXPOSURE", exposureSeconds.ToString("0.000", CultureInfo.InvariantCulture), null);
                hdr.AddValue("EXPTIME", exposureSeconds.ToString("0.000", CultureInfo.InvariantCulture), null);
            }

            hdr.AddValue("SNAPSHOT", numFrames.ToString(), null);
            hdr.AddValue("TANGRAVE", string.Format("{0} v{1}", VersionHelper.AssemblyProduct, VersionHelper.AssemblyFileVersion), null);
            if (TangraConfig.Settings.Generic.ReverseGammaCorrection)
            {
                hdr.AddValue("TANGAMMA", TangraConfig.Settings.Photometry.EncodingGamma.ToString("0.0000", CultureInfo.InvariantCulture), null);
            }
            if (TangraConfig.Settings.Generic.ReverseCameraResponse)
            {
                hdr.AddValue("TANCMRSP", ((int)TangraConfig.Settings.Photometry.KnownCameraResponse).ToString(CultureInfo.InvariantCulture), null);
            }

            f.AddHDU(imageHDU);

            // Write a FITS file.
            using (BufferedFile bf = new BufferedFile(fileName, FileAccess.ReadWrite, FileShare.ReadWrite))
            {
                f.Write(bf);
                bf.Flush();
            }
        }
예제 #8
0
        internal void SaveFitsFrame(string fileName, Header header, int width, int height, object data)
        {
            Fits f = new Fits();

            BasicHDU imageHDU = Fits.MakeHDU(data);

            nom.tam.fits.Header hdr = imageHDU.Header;
            hdr.AddValue("SIMPLE", "T", null);

            hdr.AddValue("BZERO", 0, null);
            hdr.AddValue("BSCALE", 1, null);

            hdr.AddValue("NAXIS", 2, null);
            hdr.AddValue("NAXIS1", width, null);
            hdr.AddValue("NAXIS2", height, null);

            string[] RESERVED_KEYS = new string[] { "SIMPLE", "NAXIS", "NAXIS1", "NAXIS2", "BZERO", "BSCALE", "END" };

            var cursor = header.GetCursor();

            while (cursor.MoveNext())
            {
                HeaderCard card = header.FindCard((string)cursor.Key);
                if (card != null && !string.IsNullOrWhiteSpace(card.Key) && !RESERVED_KEYS.Contains(card.Key))
                {
                    hdr.AddValue(card.Key, card.Value, card.Comment);
                }
            }

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

            f.AddHDU(imageHDU);

            // Write a FITS file.
            using (BufferedFile bf = new BufferedFile(fileName, FileAccess.ReadWrite, FileShare.ReadWrite))
            {
                f.Write(bf);
                bf.Flush();
            }
        }
예제 #9
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 = null;

            try
            {
                f = new Fits();
                f.AddHDU(Fits.MakeHDU(data));
                BufferedFile ff = new BufferedFile(TestFileSetup.GetTargetFilename("bt8.fits"), FileAccess.ReadWrite,
                                                   FileShare.ReadWrite);
                f.Write(ff);
                ff.Flush();
                ff.Close();
                f.Close();

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

                Assert.AreEqual("e", bhdu.GetElement(4, data.Length - 1));
                Assert.AreEqual("", bhdu.GetElement(5, data.Length - 1));

                String[] col = (String[])bhdu.GetColumn(0);
                Assert.AreEqual("a", col[0]);
                Assert.AreEqual("f", col[5]);

                col = (String[])bhdu.GetColumn(3);
                Assert.AreEqual("", col[0]);
                Assert.AreEqual("", col[5]);

                col = (String[])bhdu.GetColumn(7);  // All nulls
                Assert.AreEqual("", col[0]);
                Assert.AreEqual("", col[5]);

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

                Assert.AreEqual("a", col[0]);
                Assert.AreEqual("", col[1]);
            }
            finally
            {
                if (f != null)
                {
                    f.Close();
                }
            }
        }
예제 #10
0
        public void BuildByRow()
        {
            Fits f = null;

            try
            {
                f = new Fits(
                    TestFileSetup.GetTargetFilename("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.Close();

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

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

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

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

                btab = (BinaryTable)f.GetHDU(1).Data;
                Assert.AreEqual(100, btab.NRows);

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

                Assert.AreEqual((float)0, (float)xftt[0]);

                xft  = (Array[])xf.GetValue(99);
                xftt = (float[])xft.GetValue(0);
                Assert.AreEqual((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;

                    Assert.AreEqual(true, ArrayFuncs.ArrayEquals(ba, vbool[trow])); // prob 1
                    Assert.AreEqual(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);
                Assert.AreEqual(0F, (float)xftt[0]);
                xft  = (Array[])xf.GetValue(99);
                xftt = (float[])xft.GetValue(0);
                Assert.AreEqual((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;

                    Assert.AreEqual(true, ArrayFuncs.ArrayEquals(ba, vbool[trow])); // prob 2
                    Assert.AreEqual(true, ArrayFuncs.ArrayEquals(fx, vf[trow]));
                }
            }
            finally
            {
                if (f != null)
                {
                    f.Close();
                }
            }
        }
예제 #11
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(
                TestFileSetup.GetTargetFilename("rg1.fits"),
                FileAccess.ReadWrite,
                FileShare.ReadWrite);

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

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

            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))];
            Console.Out.WriteLine("****** Write padding ******");
            bf.Write(padding);

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

            Fits f = null;

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

                data = (Object[][])hdus[0].Kernel;
                // data = hdus[0].Kernel;
                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)
                    {
                        Assert.AreEqual((float)(i + j), pa[j]);
                    }
                    for (int j = 0; j < fa.Length; j += 1)
                    {
                        // Assert.AreEqual("dataTest:" + i + " " + j, (float)(i * j), fa[j,j]);
                        Assert.AreEqual((float)(i * j), ((Array)tfa.GetValue(j)).GetValue(j));
                    }
                }

                f.Close();

                Console.Out.WriteLine("**** Create HDU from kernel *****");
                f = new Fits();

                // Generate a FITS HDU from the kernel.
                f.AddHDU(Fits.MakeHDU(data));
                bf = new BufferedFile(
                    TestFileSetup.GetTargetFilename("rg2.fits"),
                    FileAccess.ReadWrite,
                    FileShare.ReadWrite);

                Console.Out.WriteLine("**** Write new file *****");
                f.Write(bf);
                bf.Flush();
                bf.Close();
                bf.Dispose();
                f.Close();

                Console.Out.WriteLine("**** Read and check *****");
                f    = new Fits(TestFileSetup.GetTargetFilename("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)
                    {
                        Assert.AreEqual((float)(i + j), pa[j]);
                    }

                    for (int j = 0; j < fa.Length; j += 1)
                    {
                        //Assert.AreEqual("dataTest:" + i + " " + j, (float)(i * j), fa[j,j]);
                        Assert.AreEqual((float)(i * j), ((Array)tfa.GetValue(j)).GetValue(j));
                    }
                }
            }
            finally
            {
                if (f != null)
                {
                    f.Close();
                }
            }
        }
예제 #12
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();
                }
            }
        }
예제 #13
0
        internal void SaveFitsFrame(int frameNo, string fileName, int width, int height, uint[] framePixels, DateTime timeStamp, float exposureSeconds)
        {
            Fits f = new Fits();

            object data = m_ExportAs8BitFloat
                ? (object)SaveNormalizedFloatImageData(width, height, framePixels)
                : (object)SaveImageData(width, height, framePixels);

            BasicHDU imageHDU = Fits.MakeHDU(data);

            nom.tam.fits.Header hdr = imageHDU.Header;
            hdr.AddValue("SIMPLE", "T", null);

            hdr.AddValue("BITPIX", m_ExportAs8BitFloat ? -32 : 32, null);

            hdr.AddValue("BZERO", 0, null);
            hdr.AddValue("BSCALE", 1, null);

            hdr.AddValue("NAXIS", 2, null);
            hdr.AddValue("NAXIS1", width, null);
            hdr.AddValue("NAXIS2", height, null);

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

            hdr.AddValue("DATE-OBS", timeStamp.ToString("yyyy-MM-ddTHH:mm:ss.fff", CultureInfo.InvariantCulture), m_DateObsComment);

            hdr.AddValue("CAMERA", m_VideoCamera, "Video camera model (observer specified)");

            hdr.AddValue("FILENAME", m_VideoController.FileName, null);
            hdr.AddValue("FRAMENO", frameNo, null);

            if (m_VideoFormat == VideoFileFormat.AAV || m_VideoFormat == VideoFileFormat.AAV2)
            {
                hdr.AddValue("NOTES", "No instrumental delay has been applied to DATE-OBS.", null);

                if (m_ExportAs8BitFloat)
                {
                    hdr.AddValue("VIDEOFMT", m_NativeFormat, "Native analogue video format");
                    if (m_IntegrationRate > 0)
                    {
                        hdr.AddValue("INTGRRTE", m_IntegrationRate.ToString(), "Integration rate in video frames");
                    }
                }
            }
            else
            {
                hdr.AddValue("NOTES", string.Format("Converted from {0} file.", m_VideoFormat), null);
            }

            foreach (var kvp in m_AdditionalFileHeaders)
            {
                hdr.AddValue(kvp.Key, kvp.Value.Item1, kvp.Value.Item2);
            }

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

            f.AddHDU(imageHDU);

            // Write a FITS file.
            using (BufferedFile bf = new BufferedFile(fileName, FileAccess.ReadWrite, FileShare.ReadWrite))
            {
                f.Write(bf);
                bf.Flush();
            }
        }
예제 #14
0
        public static void  BufferedFileTest(System.String filename, int numIts, double[] db, double[] db2, float[] fl, float[] fl2, long[] ln, long[] ln2, int[] in_Renamed, int[] in2, short[] sh, short[] sh2, char[] ch, char[] ch2, byte[] by, byte[] by2, bool[] bl, bool[] bl2, int[][][][] multi, int[][][][] multi2)
        {
            int dim = db.Length;

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

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

            BufferedFile f = new BufferedFile(filename, FileAccess.ReadWrite);

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

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

            f.WriteArray(multi);
            f.Flush();
            f.Seek(0, SeekOrigin.Begin);

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

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

            // Now read only pieces of the multidimensional array.
            for (int i = 0; i < 5; i += 1)
            {
                // Skip the odd initial indices and read the evens.
                System.Int64 temp_Int64;
                temp_Int64 = f.Position;
                temp_Int64 = f.Seek(4000) - temp_Int64;
                int generatedAux27 = (int)temp_Int64;
                f.ReadArray(multi2[2 * i + 1]);
            }

            f.Close();

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

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

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

            System.Console.Out.WriteLine("  Multi: odd rows should match");
            for (int i = 0; i < 10; i += 1)
            {
                System.Console.Out.WriteLine("      " + i + " " + multi[i][i][i][i] + " " + multi2[i][i][i][i]);
            }
            System.Console.Out.WriteLine("Done BufferedFile Tests");
        }